Compare commits
No commits in common. "master" and "master" have entirely different histories.
|
@ -44,7 +44,7 @@
|
||||||
use core::mem;
|
use core::mem;
|
||||||
use stack::Stack;
|
use stack::Stack;
|
||||||
|
|
||||||
pub const STACK_ALIGNMENT: usize = 4096;
|
pub const STACK_ALIGNMENT: usize = 16;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
|
@ -159,12 +159,6 @@ pub unsafe fn swap(arg: usize, new_sp: StackPointer,
|
||||||
// Just pass a dummy pointer if we aren't linking the stack
|
// Just pass a dummy pointer if we aren't linking the stack
|
||||||
&mut dummy
|
&mut dummy
|
||||||
};
|
};
|
||||||
let stack_limit = if let Some(new_stack) = new_stack {
|
|
||||||
new_stack.limit() as *mut usize
|
|
||||||
} else {
|
|
||||||
// Stack should not reach all the way to address 0
|
|
||||||
0 as *mut usize
|
|
||||||
};
|
|
||||||
|
|
||||||
#[naked]
|
#[naked]
|
||||||
unsafe extern "C" fn trampoline() {
|
unsafe extern "C" fn trampoline() {
|
||||||
|
@ -174,15 +168,12 @@ 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
|
||||||
|
|
||||||
# Perform environment call to modify the PMP regions
|
|
||||||
ecall
|
|
||||||
|
|
||||||
# Link the call stacks together by writing the current stack bottom
|
# Link the call stacks together by writing the current stack bottom
|
||||||
# address to the CFA slot in the new stack.
|
# address to the CFA slot in the new stack.
|
||||||
sw sp, 0(a3)
|
sw sp, 0(a3)
|
||||||
|
@ -191,12 +182,13 @@ 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, 4(sp)
|
lw fp, -12(sp)
|
||||||
lw ra, 0(sp)
|
lw ra, -16(sp)
|
||||||
addi sp, sp, 16
|
|
||||||
|
|
||||||
# Return into the new context.
|
# Return into the new context.
|
||||||
jr ra
|
jr ra
|
||||||
|
@ -217,7 +209,6 @@ pub unsafe fn swap(arg: usize, new_sp: StackPointer,
|
||||||
"{a0}" (arg)
|
"{a0}" (arg)
|
||||||
"{a2}" (new_sp.0)
|
"{a2}" (new_sp.0)
|
||||||
"{a3}" (new_cfa)
|
"{a3}" (new_cfa)
|
||||||
"{a7}" (stack_limit)
|
|
||||||
:/*"zero",*/"ra",/*"sp","gp","tp",*/"t0","t1","t2",
|
:/*"zero",*/"ra",/*"sp","gp","tp",*/"t0","t1","t2",
|
||||||
/*"fp",*/"s1",/*"a0", "a1"*/"a2", "a3", "a4", "a5",
|
/*"fp",*/"s1",/*"a0", "a1"*/"a2", "a3", "a4", "a5",
|
||||||
"a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7",
|
"a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7",
|
||||||
|
|
Loading…
Reference in New Issue