Tested assembly language file for the pause example

This commit is contained in:
David Harris 2023-10-24 10:45:41 -07:00
parent eba346849c
commit 905c5da7a9
3 changed files with 37 additions and 0 deletions

1
.gitignore vendored
View File

@ -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

11
examples/asm/etc/Makefile Normal file
View File

@ -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

25
examples/asm/etc/pause.S Normal file
View File

@ -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