Compare commits

..

1 Commits

Author SHA1 Message Date
morgan 53a964a63d riscv32::swap: fix stack push/pop asm 2024-05-23 15:30:27 +08:00
1 changed files with 5 additions and 6 deletions

View File

@ -174,9 +174,9 @@ pub unsafe fn swap(arg: usize, new_sp: StackPointer,
# from the stack; unwinder uses them to find the CFA of the caller, # from the stack; unwinder uses them to find the CFA of the caller,
# and so they have to have the correct value immediately after the # and so they have to have the correct value immediately after the
# call instruction that invoked the trampoline. # call instruction that invoked the trampoline.
sw fp, -12(sp)
sw ra, -16(sp)
addi sp, sp, -16 addi sp, sp, -16
sw fp, 4(sp)
sw ra, 0(sp)
.cfi_offset fp, 4 .cfi_offset fp, 4
.cfi_offset ra, 0 .cfi_offset ra, 0
@ -191,13 +191,12 @@ pub unsafe fn swap(arg: usize, new_sp: StackPointer,
or a1, zero, sp or a1, zero, sp
# Load stack pointer of the new context. # Load stack pointer of the new context.
or sp, zero, a2 or sp, zero, a2
# Deallocate the 16 bytes
addi sp, sp, 16
# Restore frame pointer and link register of the new context. # Restore frame pointer and link register of the new context.
# Load frame and instruction pointers of the new context. # Load frame and instruction pointers of the new context.
lw fp, -12(sp) lw fp, 4(sp)
lw ra, -16(sp) lw ra, 0(sp)
addi sp, sp, 16
# Return into the new context. # Return into the new context.
jr ra jr ra