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