File: initctxtalpha.c

package info (click to toggle)
tra 20020816-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 1,696 kB
  • ctags: 2,623
  • sloc: ansic: 22,519; makefile: 406; asm: 269
file content (37 lines) | stat: -rw-r--r-- 723 bytes parent folder | download
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
#include "tra.h"

/*
  setlabel and gotolabel don't save and restore the argument
  registers, so we pass fn and arg on the stack as the seventh and
  eigth arguments to a trampoline.  We could also use the assembler.
*/

static void
tramp(int a0, int a1, int a2, int a3, int a4, int a5,
      void (*fn)(void*), void *arg)
{
	USED(a0); USED(a1); USED(a2);
	USED(a3); USED(a4); USED(a5);
	fn(arg);
	abort();
}

void
initctxt(Ctxt *l, void (*fn)(void*), void *arg)
{
	ulong *stk;
	int n;

	n = 2*sizeof(ulong);
	l->stk = emalloc(n);
	stk = (ulong*)((uchar*)l->stk + n);

	*--stk = (ulong)arg;
	*--stk = (ulong)fn;

	l->label.pc = (ulong)tramp+LABELDPC;
	l->label.sp = mainlabel.sp-n;
	l->label.pv = l->label.pc;

	return;
}