document the assembly
This commit is contained in:
parent
a39493d740
commit
884496c6b9
21
src/init.s
21
src/init.s
|
@ -1,17 +1,36 @@
|
||||||
|
/// initialise a new context
|
||||||
|
/// arguments: rdi: stack pointer,
|
||||||
|
/// rsi: function pointer,
|
||||||
|
/// rdx, data pointer
|
||||||
|
/// rcx, stack limit
|
||||||
|
|
||||||
|
// switch to the fresh stack
|
||||||
xchg %rsp, %rdi
|
xchg %rsp, %rdi
|
||||||
|
|
||||||
|
// save the function pointer, data pointer, and stack limit, respectively
|
||||||
pushq %rsi
|
pushq %rsi
|
||||||
pushq %rdx
|
pushq %rdx
|
||||||
pushq %rcx
|
pushq %rcx
|
||||||
call 1f
|
|
||||||
|
|
||||||
|
// save the return address, control flow continues at label 1
|
||||||
|
call 1f
|
||||||
|
// we arrive here once this context is reactivated (see swap.s)
|
||||||
|
|
||||||
|
// restore the stack limit, data pointer, and function pointer, respectively
|
||||||
popq %fs:0x70
|
popq %fs:0x70
|
||||||
popq %rdi
|
popq %rdi
|
||||||
popq %rax
|
popq %rax
|
||||||
|
|
||||||
|
// initialise the frame pointer
|
||||||
movq $$0, %rbp
|
movq $$0, %rbp
|
||||||
|
|
||||||
|
// call the function pointer with the data pointer (rdi is the first argument)
|
||||||
call *%rax
|
call *%rax
|
||||||
|
|
||||||
|
// crash if it ever returns
|
||||||
ud2
|
ud2
|
||||||
|
|
||||||
1:
|
1:
|
||||||
|
// save our neatly-setup new stack
|
||||||
xchg %rsp, %rdi
|
xchg %rsp, %rdi
|
||||||
|
// back into Rust-land we go
|
||||||
|
|
22
src/swap.s
22
src/swap.s
|
@ -1,17 +1,37 @@
|
||||||
|
/// switch to a new context
|
||||||
|
/// arguments: rdi: stack pointer pointer
|
||||||
|
|
||||||
|
// make sure we leave the red zone alone
|
||||||
sub $$128, %rsp
|
sub $$128, %rsp
|
||||||
|
|
||||||
|
// save the Rust stack limit and the frame pointer, respectively
|
||||||
pushq %fs:0x70
|
pushq %fs:0x70
|
||||||
pushq %rbp
|
pushq %rbp
|
||||||
call 1f
|
|
||||||
|
|
||||||
|
// save the return address to the stack, control flow continues at label 1
|
||||||
|
call 1f
|
||||||
|
// we arrive here once this context is reactivated
|
||||||
|
|
||||||
|
// restore the frame pointer and the Rust stack limit, respectively
|
||||||
popq %rbp
|
popq %rbp
|
||||||
popq %fs:0x70
|
popq %fs:0x70
|
||||||
|
|
||||||
|
// give back the red zone
|
||||||
add $$128, %rsp
|
add $$128, %rsp
|
||||||
|
|
||||||
|
// and we merrily go on our way, back into Rust-land
|
||||||
jmp 2f
|
jmp 2f
|
||||||
|
|
||||||
1:
|
1:
|
||||||
|
// retrieve the new stack pointer
|
||||||
movq (%rdi), %rax
|
movq (%rdi), %rax
|
||||||
|
// save the old stack pointer
|
||||||
movq %rsp, (%rdi)
|
movq %rsp, (%rdi)
|
||||||
|
// switch to the new stack pointer
|
||||||
movq %rax, %rsp
|
movq %rax, %rsp
|
||||||
|
|
||||||
|
// jump into the new context (return to the call point)
|
||||||
popq %rax
|
popq %rax
|
||||||
jmpq *%rax
|
jmpq *%rax
|
||||||
|
|
||||||
2:
|
2:
|
||||||
|
|
Loading…
Reference in New Issue