Mercurial > pub > dyncall > dyncall
annotate dyncallback/dyncall_thunk_mips.c @ 141:e63089fe5bef
- todo update
- removed some duped code for plain* tests
author | cslag |
---|---|
date | Sat, 20 Aug 2016 09:47:45 +0200 |
parents | 1ce60358fbad |
children | bbefb8b8e74c |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: dyncallback | |
5 File: dyncallback/dyncall_thunk_mips.c | |
6 Description: Thunk - Implementation for MIPS | |
7 License: | |
8 | |
9 Copyright (c) 2013-2015 Daniel Adler <dadler@uni-goettingen.de>, | |
10 Tassilo Philipp <tphilipp@potion-studios.com> | |
11 | |
12 Permission to use, copy, modify, and distribute this software for any | |
13 purpose with or without fee is hereby granted, provided that the above | |
14 copyright notice and this permission notice appear in all copies. | |
15 | |
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
23 | |
24 */ | |
25 | |
26 #include "dyncall_thunk.h" | |
27 | |
97 | 28 static unsigned short hi16(x) { return ( (unsigned short) (((unsigned int)x)>>16UL) ); } |
29 static unsigned short lo16(x) { return ( (unsigned short) ((unsigned int)x) ); } | |
0 | 30 |
31 void dcbInitThunk(DCThunk* p, void (*entry)()) | |
32 { | |
33 /* | |
34 | |
35 Thunk Register: $t4 ($12) | |
36 According to o32abi: $t9 | |
37 | |
101
1ce60358fbad
- mips related cleanup, mostly comments, cpp macro lib
cslag
parents:
97
diff
changeset
|
38 'The Linux/MIPS convention is that all PIC calls use t9 to hold the address of |
1ce60358fbad
- mips related cleanup, mostly comments, cpp macro lib
cslag
parents:
97
diff
changeset
|
39 the called function.' [See MIPS Run, p.413] |
0 | 40 |
41 mips thunk code: | |
42 lui $t4, %hi(p) | |
43 lui $t9, %hi(entry) | |
44 ori $t9, $t9, %lo(entry) | |
45 jr $t9 | |
97 | 46 ori $t4, $t4, %lo(p) ; branch delay slot |
0 | 47 |
48 thunk.o: file format elf32-tradbigmips | |
49 | |
50 | |
51 Disassembly of section .text: | |
52 | |
53 00000000 <thunk>: | |
54 0: 3c0c0000 lui t4,0x0 | |
55 4: 3c190000 lui t9,0x0 | |
56 8: 37390000 ori t9,t9,0x0 | |
57 c: 03200008 jr t9 | |
58 10: 00200825 move at,at | |
59 14: 358c0000 ori t4,t4,0x0 | |
60 18: 00200825 move at,at | |
61 1c: 00200825 move at,at | |
62 | |
63 */ | |
64 | |
65 #if defined(DC__Endian_BIG) | |
66 | |
67 p->data[0] = 0x3c0c; p->data[1] = hi16(p); /* lui $t4, hi(p) */ | |
68 p->data[2] = 0x3c19; p->data[3] = hi16(entry); /* lui $t9, hi(entry) */ | |
69 p->data[4] = 0x3739; p->data[5] = lo16(entry); /* ori $t9, $t9, lo(entry) */ | |
70 p->jump = 0x03200008; /* jr $t9 */ | |
71 p->bddt[0] = 0x358c; p->bddt[1] = lo16(p); /* ori $t4, $t4, lo(p) - branch delay slot */ | |
72 | |
73 #else /* defined(DC__Endian_LITTLE) */ | |
74 | |
75 p->data[1] = 0x3c0c; p->data[0] = hi16(p); /* lui $t4, hi(p) */ | |
76 p->data[3] = 0x3c19; p->data[2] = hi16(entry); /* lui $t9, hi(entry) */ | |
77 p->data[5] = 0x3739; p->data[4] = lo16(entry); /* ori $t9, $t9, lo(entry) */ | |
78 p->jump = 0x03200008; /* jr $t9 */ | |
79 p->bddt[1] = 0x358c; p->bddt[0] = lo16(p); /* ori $t4, $t4, lo(p) - branch delay slot */ | |
80 | |
81 #endif | |
82 | |
83 } | |
84 |