libfringe/src/init.s

37 lines
830 B
ArmAsm
Raw Normal View History

2015-03-27 15:31:02 +08:00
/// 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
2015-03-27 15:31:02 +08:00
// save the function pointer, data pointer, and stack limit, respectively
pushq %rsi
pushq %rdx
pushq %rcx
2015-03-27 15:31:02 +08:00
// save the return address, control flow continues at label 1
call 1f
2015-03-27 15:31:02 +08:00
// we arrive here once this context is reactivated (see swap.s)
2015-03-27 15:31:02 +08:00
// restore the stack limit, data pointer, and function pointer, respectively
popq %fs:0x70
popq %rdi
popq %rax
2015-03-27 15:31:02 +08:00
// initialise the frame pointer
movq $$0, %rbp
2015-03-27 15:31:02 +08:00
// call the function pointer with the data pointer (rdi is the first argument)
call *%rax
2015-03-27 15:31:02 +08:00
// crash if it ever returns
ud2
1:
2015-03-27 15:31:02 +08:00
// save our neatly-setup new stack
xchg %rsp, %rdi
2015-03-27 15:31:02 +08:00
// back into Rust-land we go