1
The list of CPUs and platforms TRAMPOLINE has been ported to can be found
2
at the top of file trampoline.c.
4
To port TRAMPOLINE to a new platform, three issues may have to be resolved:
5
A. a new CPU - how to build the trampoline?
6
B. a new OS - how to make code in malloc'ed memory executable?
7
C. a new CPU or OS - how to flush the instruction cache?
10
A. a new CPU - how to build the trampoline?
12
The trampoline is a short sequence of machine instructions which puts
13
the constant <data> into <variable>, then jumps to <address>. The only
14
registers that are allowed to be modified are call-used-registers. No
15
stack manipulations are allowed since the trampoline has to pass its
16
arguments along to the function at <address>.
18
1. To find out which instructions are available for "move"/"store" and
19
"jump", compile proto.c for your CPU:
21
make -f Makefile.devel proto-${CPU}.s
23
gcc -O2 -fomit-frame-pointer -S proto.c -o proto-${CPU}.s
25
2. Write down the instructions for the trampoline in a file tramp-${CPU}.s,
26
using constants for <data>, <variable>, <address>. Assemble it:
30
Verify that the jump actually goes to <address>. (Beware: Some CPUs have
31
program-counter relative jumps.)
36
3. Take a hex dump of tramp-${CPU}.o
38
hexdump -e '"%06.6_ax " 16/1 " %02X" "\n"' < tramp-${CPU}.o
40
od -tx1 -Ax < tramp-${CPU}.o
42
od -x +x < tramp-${CPU}.o
44
Look out for the magic numbers you used for <data>, <variable> and
47
4. Write the code which builds up a trampoline in memory, in trampoline.c.
54
6. Write the is_tramp() macro and the tramp_xxx() accessor macros
63
B. a new OS - how to make code in malloc'ed memory executable?
65
`configure' will find out whether code stored in malloc'ed memory is
66
executable, or whether virtual memory protections have to be set in order
67
to allow this. (The test is pretty simple: it copies a small function
68
to malloc'ed memory and tries to executed it. The test could also fail
69
because the compiler produced non-position-independent code or because
72
To set virtual memory protections on a page of memory, your system should
73
provide the mprotect() and getpagesize() functions. If it does not, find
77
C. a new CPU or OS - how to flush the instruction cache?
79
CPUs which have separate data and instruction caches need to flush
80
(part of) the instruction cache when alloc_trampoline() is called.
81
(There may have been an old trampoline at the same location, and the
82
instruction cache is not updated when the new trampoline is built.
83
The effect can be that when the new trampoline is called, the old one
84
will still be executed.)
86
To flush the instruction cache, some CPUs have special instruction which
87
can be put into gcc "asm" statements. On some CPUs these instructions are
88
privileged, you therefore need to call some system or library function.
89
On other CPUs, the only way to flush the instruction cache is to execute
90
a long sequence of "nop" or "jump" instructions. This is hairy.
93
When you are done with porting to a new platform, or even if TRAMPOLINE
94
passes the "make check" out of the box without modifications, please report
95
your results to the author of TRAMPOLINE, for inclusion in the next release.