From 905c5da7a9bfa44d25fa1a5978efcdb754422c57 Mon Sep 17 00:00:00 2001 From: David Harris Date: Tue, 24 Oct 2023 10:45:41 -0700 Subject: [PATCH] Tested assembly language file for the pause example --- .gitignore | 1 + examples/asm/etc/Makefile | 11 +++++++++++ examples/asm/etc/pause.S | 25 +++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 examples/asm/etc/Makefile create mode 100644 examples/asm/etc/pause.S diff --git a/.gitignore b/.gitignore index 04ae44109..b4223b50e 100644 --- a/.gitignore +++ b/.gitignore @@ -62,6 +62,7 @@ examples/fp/fpcalc/fpcalc examples/C/inline/inline examples/C/sum_mixed/sum_mixed examples/asm/trap/trap +examples/asm/etc/pause src/fma/fma16_testgen linux/devicetree/debug/* !linux/devicetree/debug/dump-dts.sh diff --git a/examples/asm/etc/Makefile b/examples/asm/etc/Makefile new file mode 100644 index 000000000..72f99e975 --- /dev/null +++ b/examples/asm/etc/Makefile @@ -0,0 +1,11 @@ +TARGET = pause + +$(TARGET).objdump: $(TARGET) + riscv64-unknown-elf-objdump -D $(TARGET) > $(TARGET).objdump + +pause: pause.S Makefile + riscv64-unknown-elf-gcc -o pause -march=rv32ia_zihintpause -mabi=ilp32 -mcmodel=medany \ + -nostartfiles -T../../link/link.ld pause.S + +clean: + rm -f $(TARGET) $(TARGET).objdump diff --git a/examples/asm/etc/pause.S b/examples/asm/etc/pause.S new file mode 100644 index 000000000..4e0aacfb4 --- /dev/null +++ b/examples/asm/etc/pause.S @@ -0,0 +1,25 @@ +.section .text.init +.globl rvtest_entry_point +rvtest_entry_point: + + +la a0, lock + +spinlock: # address of lock is in a0 + lr.w t0, (a0) # read the lock + bnez t0, retry # spin until free + li t1, 1 + sc.w t0, t1, (a0) # try to write a 1 to take lock + bnez t0, retry # spin until successful + ret # got the lock! +retry: # no lock yet + pause # pause hint to reduce spin power + j spinlock # try again + + +self_loop: + j self_loop + +.data +lock: + .word 1 \ No newline at end of file