comparison dyncallback/dyncall_thunk_sparc64.c @ 189:b827c074b4da

- first impl of sparc64 thunks
author Tassilo Philipp
date Mon, 13 Mar 2017 14:13:26 +0100
parents 3e629dc19168
children 06ee88ce4962
comparison
equal deleted inserted replaced
188:44ae5b653086 189:b827c074b4da
26 26
27 #include "dyncall_thunk.h" 27 #include "dyncall_thunk.h"
28 28
29 void dcbInitThunk(DCThunk* p, void (*entry)()) 29 void dcbInitThunk(DCThunk* p, void (*entry)())
30 { 30 {
31 /* not yet implemented */ 31 /* example
32 ; put thunk pointer in g1
33 0: 03 00 00 00 sethi %hi(0), %g1
34 4: 82 10 60 00 or %g1, 0, %g1
35 8: 83 28 70 20 sllx %g1, 0x20, %g1
36 12: 21 00 00 00 sethi %hi(0), %l0
37 16: a0 14 20 00 or %l0, 0, %l0
38 20: 82 04 00 01 add %l0, %g1, %g1
39 ; use g2 for entry pointer and "call" it, b/c branch instructions can't handle 64bit addresses
40 24: 05 00 00 00 sethi %hi(0), %g2
41 28: 84 10 a0 00 or %g2, 0, %g2
42 32: 85 28 b0 20 sllx %g2, 0x20, %g2
43 36: 21 00 00 00 sethi %hi(0), %l0
44 40: a0 14 20 00 or %l0, 0, %l0
45 44: 84 04 00 02 add %l0, %g2, %g2
46 ; jump - write link to %g0, effectively discarding it; also nop for delay slot
47 48: 81 c0 80 00 jmpl %g2, %g0
48 52: 01 00 00 00 nop
49 */
50
51 union {
52 unsigned int x[2];
53 void* p;
54 } t, e;
55 t.p = p;
56 e.p = entry;
57
58 p->code[ 0] = 0x03000000 | (t.x[0] >> 10); /* sethi %hi(p), %g1 -- hi 22 bits */
59 p->code[ 1] = 0x82106000 | (t.x[0] & 0x3ff); /* or %g1, <p&0x3ff>, %g1 -- lo 10 bits */
60 p->code[ 2] = 0x83287020; /* sllx %g1, 0x20, %g1 */
61 p->code[ 3] = 0x21000000 | (t.x[1] >> 10); /* sethi %hi(p), %l0 */
62 p->code[ 4] = 0xa0142000 | (t.x[1] & 0x3ff); /* or %l0, <p&0x3ff>, %l0 */
63 p->code[ 5] = 0x82040001; /* add %l0, %g1, %g1 */
64 p->code[ 6] = 0x05000000 | (e.x[0] >> 10); /* sethi %hi(entry), %g2 */
65 p->code[ 7] = 0x8410a000 | (e.x[0] & 0x3ff); /* or %g2, <entry&0x3ff>, %g2 */
66 p->code[ 8] = 0x8528b020; /* sllx %g2, 0x20, %g2 */
67 p->code[ 9] = 0x21000000 | (e.x[1] >> 10); /* sethi %hi(entry), %l0 */
68 p->code[10] = 0xa0142000 | (e.x[1] & 0x3ff); /* or %l0, <entry&0x3ff>, %l0 */
69 p->code[11] = 0x84040002; /* add %l0, %g2, %g2 */
70 p->code[12] = 0x81c08000; /* jmpl %g2, %g0 -- discards link addr */
71 p->code[13] = 0x01000000; /* nop */
32 } 72 }
33 73