blob: 2c735e410fa4aa6b7fa24733634960119001a9fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
// xfail-license
#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*)®s == (void*)this);
memset(®s, 0, sizeof(regs));
}
void context::swap(context &out)
{
swap_registers(&out.regs, ®s);
}
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
uint32_t *sp = ( uint32_t *)stack;
//sp = align_down(sp);
// The final return address. 0 indicates the bottom of the stack
*--sp = 0;
regs.data[0] = ( uint32_t )arg; // r0
regs.data[13] = ( uint32_t )sp; //#52 sp, r13
regs.data[14] = ( uint32_t )f; //#60 pc, r15 --> lr,
// Last base pointer on the stack should be 0
}
|