]> git.proxmox.com Git - rustc.git/blob - src/rt/arch/arm/context.cpp
Imported Upstream version 0.7
[rustc.git] / src / rt / arch / arm / context.cpp
1 // xfail-license
2
3 #include "context.h"
4 #include "../../rust_globals.h"
5
6 extern "C" void CDECL swap_registers(registers_t *oregs,
7 registers_t *regs)
8 asm ("swap_registers");
9
10 context::context()
11 {
12 assert((void*)&regs == (void*)this);
13 memset(&regs, 0, sizeof(regs));
14 }
15
16 void context::swap(context &out)
17 {
18 swap_registers(&out.regs, &regs);
19 }
20
21 void context::call(void *f, void *arg, void *stack)
22 {
23 // Get the current context, which we will then modify to call the
24 // given function.
25 swap(*this);
26
27 // set up the stack
28 uint32_t *sp = ( uint32_t *)stack;
29 sp = align_down(sp);
30 // The final return address. 0 indicates the bottom of the stack
31 // sp of arm eabi is 8-byte aligned
32 sp -= 2;
33 *sp = 0;
34
35 regs.data[0] = ( uint32_t )arg; // r0
36 regs.data[13] = ( uint32_t )sp; //#52 sp, r13
37 regs.data[14] = ( uint32_t )f; //#60 pc, r15 --> lr,
38 // Last base pointer on the stack should be 0
39 }