rust/src/rt/arch/x86_64/context.cpp
Jon Morton 632a4c9326 Refactor includes structure, getting rid of rust_internal.h
Many changes to code structure are included:
- removed TIME_SLICE_IN_MS
- removed sychronized_indexed_list
- removed region_owned
- kernel_owned move to kernel.h, task_owned moved to task.h
- global configs moved to rust_globals.h
- changed #pragma once to standard guard in rust_upcall.h
- got rid of memory.h
2012-04-03 16:02:38 -07:00

37 lines
855 B
C++

#include "context.h"
#include "../../rust_globals.h"
extern "C" void CDECL swap_registers(registers_t *oregs,
registers_t *regs)
asm ("swap_registers");
context::context()
{
assert((void*)&regs == (void*)this);
}
void context::swap(context &out)
{
swap_registers(&out.regs, &regs);
}
void context::call(void *f, void *arg, void *stack) {
// Get the current context, which we will then modify to call the
// given function.
swap(*this);
// set up the stack
uint64_t *sp = (uint64_t *)stack;
sp = align_down(sp);
// The final return address. 0 indicates the bottom of the stack
*--sp = 0;
regs.data[RUSTRT_ARG0] = (uint64_t)arg;
regs.data[RUSTRT_RSP] = (uint64_t)sp;
regs.data[RUSTRT_IP] = (uint64_t)f;
// Last base pointer on the stack should be 0
regs.data[RUSTRT_RBP] = 0;
}