-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcallout68k.h
182 lines (148 loc) · 6.33 KB
/
callout68k.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* Copyright (c) 2023 Elliot Nunn */
/* Licensed under the MIT license */
#pragma once
// Use some modern GCC constructs to make calling 68k procedures less of a pain
// A better macro than Interfaces' SIZE_CODE() for building in a Mixed Mode routine descriptor,
// because it correctly returns zero as the code for void
#define _MMTYPESIZE_(T) (__builtin_types_compatible_p(T, void) ? 0 : sizeof(T)>=4 ? 3 : sizeof(T))
#if GENERATINGCFM // PowerPC or CFM-68k
#define CALL0(ret, proc) \
(ret)CallUniversalProc((void *)proc, \
kCStackBased \
| RESULT_SIZE(_MMTYPESIZE_(ret)))
#define CALL1(ret, proc, t1, v1) \
(ret)CallUniversalProc((void *)proc, \
kCStackBased \
| RESULT_SIZE(_MMTYPESIZE_(ret)) \
| STACK_ROUTINE_PARAMETER(1, _MMTYPESIZE_(t1)), \
v1)
#define CALL2(ret, proc, t1, v1, t2, v2) \
(ret)CallUniversalProc((void *)proc, \
kCStackBased \
| RESULT_SIZE(_MMTYPESIZE_(ret)) \
| STACK_ROUTINE_PARAMETER(1, _MMTYPESIZE_(t1)) \
| STACK_ROUTINE_PARAMETER(2, _MMTYPESIZE_(t2)), \
v1, v2)
#define CALL3(ret, proc, t1, v1, t2, v2, t3, v3) \
(ret)CallUniversalProc((void *)proc, \
kCStackBased \
| RESULT_SIZE(_MMTYPESIZE_(ret)) \
| STACK_ROUTINE_PARAMETER(1, _MMTYPESIZE_(t1)) \
| STACK_ROUTINE_PARAMETER(2, _MMTYPESIZE_(t2)) \
| STACK_ROUTINE_PARAMETER(3, _MMTYPESIZE_(t3)), \
v1, v2, v3)
#define CALL4(ret, proc, t1, v1, t2, v2, t3, v3, t4, v4) \
(ret)CallUniversalProc((void *)proc, \
kCStackBased \
| RESULT_SIZE(_MMTYPESIZE_(ret)) \
| STACK_ROUTINE_PARAMETER(1, _MMTYPESIZE_(t1)) \
| STACK_ROUTINE_PARAMETER(2, _MMTYPESIZE_(t2)) \
| STACK_ROUTINE_PARAMETER(3, _MMTYPESIZE_(t3)) \
| STACK_ROUTINE_PARAMETER(4, _MMTYPESIZE_(t4)), \
v1, v2, v3, v4)
#define CALL5(ret, proc, t1, v1, t2, v2, t3, v3, t4, v4, t5, v5) \
(ret)CallUniversalProc((void *)proc, \
kCStackBased \
| RESULT_SIZE(_MMTYPESIZE_(ret)) \
| STACK_ROUTINE_PARAMETER(1, _MMTYPESIZE_(t1)) \
| STACK_ROUTINE_PARAMETER(2, _MMTYPESIZE_(t2)) \
| STACK_ROUTINE_PARAMETER(3, _MMTYPESIZE_(t3)) \
| STACK_ROUTINE_PARAMETER(4, _MMTYPESIZE_(t4)) \
| STACK_ROUTINE_PARAMETER(5, _MMTYPESIZE_(t5)), \
v1, v2, v3, v4, v5)
#define CALL6(ret, proc, t1, v1, t2, v2, t3, v3, t4, v4, t5, v5, t6, v6) \
(ret)CallUniversalProc((void *)proc, \
kCStackBased \
| RESULT_SIZE(_MMTYPESIZE_(ret)) \
| STACK_ROUTINE_PARAMETER(1, _MMTYPESIZE_(t1)) \
| STACK_ROUTINE_PARAMETER(2, _MMTYPESIZE_(t2)) \
| STACK_ROUTINE_PARAMETER(3, _MMTYPESIZE_(t3)) \
| STACK_ROUTINE_PARAMETER(4, _MMTYPESIZE_(t4)) \
| STACK_ROUTINE_PARAMETER(5, _MMTYPESIZE_(t5)) \
| STACK_ROUTINE_PARAMETER(6, _MMTYPESIZE_(t6)), \
v1, v2, v3, v4, v5, v6)
#define CALLPASCAL0(ret, proc) \
(ret)CallUniversalProc((void *)proc, \
kPascalStackBased \
| RESULT_SIZE(_MMTYPESIZE_(ret)))
#define CALLPASCAL1(ret, proc, t1, v1) \
(ret)CallUniversalProc((void *)proc, \
kPascalStackBased \
| RESULT_SIZE(_MMTYPESIZE_(ret)) \
| STACK_ROUTINE_PARAMETER(1, _MMTYPESIZE_(t1)), \
v1)
#define CALLPASCAL2(ret, proc, t1, v1, t2, v2) \
(ret)CallUniversalProc((void *)proc, \
kPascalStackBased \
| RESULT_SIZE(_MMTYPESIZE_(ret)) \
| STACK_ROUTINE_PARAMETER(1, _MMTYPESIZE_(t1)) \
| STACK_ROUTINE_PARAMETER(2, _MMTYPESIZE_(t2)), \
v1, v2)
#define CALLPASCAL3(ret, proc, t1, v1, t2, v2, t3, v3) \
(ret)CallUniversalProc((void *)proc, \
kPascalStackBased \
| RESULT_SIZE(_MMTYPESIZE_(ret)) \
| STACK_ROUTINE_PARAMETER(1, _MMTYPESIZE_(t1)) \
| STACK_ROUTINE_PARAMETER(2, _MMTYPESIZE_(t2)) \
| STACK_ROUTINE_PARAMETER(3, _MMTYPESIZE_(t3)), \
v1, v2, v3)
#define CALLPASCAL4(ret, proc, t1, v1, t2, v2, t3, v3, t4, v4) \
(ret)CallUniversalProc((void *)proc, \
kPascalStackBased \
| RESULT_SIZE(_MMTYPESIZE_(ret)) \
| STACK_ROUTINE_PARAMETER(1, _MMTYPESIZE_(t1)) \
| STACK_ROUTINE_PARAMETER(2, _MMTYPESIZE_(t2)) \
| STACK_ROUTINE_PARAMETER(3, _MMTYPESIZE_(t3)) \
| STACK_ROUTINE_PARAMETER(4, _MMTYPESIZE_(t4)), \
v1, v2, v3, v4)
#define CALLPASCAL5(ret, proc, t1, v1, t2, v2, t3, v3, t4, v4, t5, v5) \
(ret)CallUniversalProc((void *)proc, \
kPascalStackBased \
| RESULT_SIZE(_MMTYPESIZE_(ret)) \
| STACK_ROUTINE_PARAMETER(1, _MMTYPESIZE_(t1)) \
| STACK_ROUTINE_PARAMETER(2, _MMTYPESIZE_(t2)) \
| STACK_ROUTINE_PARAMETER(3, _MMTYPESIZE_(t3)) \
| STACK_ROUTINE_PARAMETER(4, _MMTYPESIZE_(t4)) \
| STACK_ROUTINE_PARAMETER(5, _MMTYPESIZE_(t5)), \
v1, v2, v3, v4, v5)
#define CALLPASCAL6(ret, proc, t1, v1, t2, v2, t3, v3, t4, v4, t5, v5, t6, v6) \
(ret)CallUniversalProc((void *)proc, \
kPascalStackBased \
| RESULT_SIZE(_MMTYPESIZE_(ret)) \
| STACK_ROUTINE_PARAMETER(1, _MMTYPESIZE_(t1)) \
| STACK_ROUTINE_PARAMETER(2, _MMTYPESIZE_(t2)) \
| STACK_ROUTINE_PARAMETER(3, _MMTYPESIZE_(t3)) \
| STACK_ROUTINE_PARAMETER(4, _MMTYPESIZE_(t4)) \
| STACK_ROUTINE_PARAMETER(5, _MMTYPESIZE_(t5)) \
| STACK_ROUTINE_PARAMETER(6, _MMTYPESIZE_(t6)), \
v1, v2, v3, v4, v5, v6)
#else // classic 68k
#define CALL0(ret, proc) \
((typeof(ret (*)(void)))proc)()
#define CALL1(ret, proc, t1, v1) \
((typeof(ret (*)(t1)))proc)(v1)
#define CALL2(ret, proc, t1, v1, t2, v2) \
((typeof(ret (*)(t1, t2)))proc)(v1, v2)
#define CALL3(ret, proc, t1, v1, t2, v2, t3, v3) \
((typeof(ret (*)(t1, t2, t3)))proc)(v1, v2, v3)
#define CALL4(ret, proc, t1, v1, t2, v2, t3, v3, t4, v4) \
((typeof(ret (*)(t1, t2, t3, t4)))proc)(v1, v2, v3, v4)
#define CALL5(ret, proc, t1, v1, t2, v2, t3, v3, t4, v4, t5, v5) \
((typeof(ret (*)(t1, t2, t3, t4, t5)))proc)(v1, v2, v3, v4, v5)
#define CALL6(ret, proc, t1, v1, t2, v2, t3, v3, t4, v4, t5, v5, t6, v6) \
((typeof(ret (*)(t1, t2, t3, t4, t5, t6)))proc)(v1, v2, v3, v4, v5, v6)
#define CALLPASCAL0(ret, proc) \
((typeof(pascal ret (*)(void)))proc)()
#define CALLPASCAL1(ret, proc, t1, v1) \
((typeof(pascal ret (*)(t1)))proc)(v1)
#define CALLPASCAL2(ret, proc, t1, v1, t2, v2) \
((typeof(pascal ret (*)(t1, t2)))proc)(v1, v2)
#define CALLPASCAL3(ret, proc, t1, v1, t2, v2, t3, v3) \
((typeof(pascal ret (*)(t1, t2, t3)))proc)(v1, v2, v3)
#define CALLPASCAL4(ret, proc, t1, v1, t2, v2, t3, v3, t4, v4) \
((typeof(pascal ret (*)(t1, t2, t3, t4)))proc)(v1, v2, v3, v4)
#define CALLPASCAL5(ret, proc, t1, v1, t2, v2, t3, v3, t4, v4, t5, v5) \
((typeof(pascal ret (*)(t1, t2, t3, t4, t5)))proc)(v1, v2, v3, v4, v5)
#define CALLPASCAL6(ret, proc, t1, v1, t2, v2, t3, v3, t4, v4, t5, v5, t6, v6) \
((typeof(pascal ret (*)(t1, t2, t3, t4, t5, t6)))proc)(v1, v2, v3, v4, v5, v6)
#endif