1 |
|
/* |
2 |
|
* thunks.cpp - Thunks to share data and code with MacOS |
3 |
|
* |
4 |
< |
* SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig |
4 |
> |
* SheepShaver (C) 1997-2008 Christian Bauer and Marc Hellwig |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
56 |
|
uint32 opcode; |
57 |
|
switch (selector) { |
58 |
|
case NATIVE_CHECK_LOAD_INVOC: |
59 |
+ |
case NATIVE_NAMED_CHECK_LOAD_INVOC: |
60 |
+ |
case NATIVE_NQD_SYNC_HOOK: |
61 |
+ |
case NATIVE_NQD_BITBLT_HOOK: |
62 |
+ |
case NATIVE_NQD_FILLRECT_HOOK: |
63 |
+ |
case NATIVE_NQD_UNKNOWN_HOOK: |
64 |
+ |
case NATIVE_NQD_BITBLT: |
65 |
+ |
case NATIVE_NQD_INVRECT: |
66 |
+ |
case NATIVE_NQD_FILLRECT: |
67 |
|
opcode = POWERPC_NATIVE_OP(0, selector); |
68 |
|
break; |
69 |
|
case NATIVE_PATCH_NAME_REGISTRY: |
70 |
|
case NATIVE_VIDEO_INSTALL_ACCEL: |
71 |
|
case NATIVE_VIDEO_VBL: |
72 |
|
case NATIVE_VIDEO_DO_DRIVER_IO: |
73 |
+ |
case NATIVE_ETHER_AO_GET_HWADDR: |
74 |
+ |
case NATIVE_ETHER_AO_ADD_MULTI: |
75 |
+ |
case NATIVE_ETHER_AO_DEL_MULTI: |
76 |
+ |
case NATIVE_ETHER_AO_SEND_PACKET: |
77 |
|
case NATIVE_ETHER_IRQ: |
78 |
|
case NATIVE_ETHER_INIT: |
79 |
|
case NATIVE_ETHER_TERM: |
93 |
|
case NATIVE_GET_IND_RESOURCE: |
94 |
|
case NATIVE_GET_1_IND_RESOURCE: |
95 |
|
case NATIVE_R_GET_RESOURCE: |
96 |
+ |
case NATIVE_GET_NAMED_RESOURCE: |
97 |
+ |
case NATIVE_GET_1_NAMED_RESOURCE: |
98 |
|
case NATIVE_MAKE_EXECUTABLE: |
85 |
– |
case NATIVE_SYNC_HOOK: |
86 |
– |
case NATIVE_BITBLT_HOOK: |
87 |
– |
case NATIVE_FILLRECT_HOOK: |
88 |
– |
case NATIVE_BITBLT: |
89 |
– |
case NATIVE_INVRECT: |
90 |
– |
case NATIVE_FILLRECT: |
99 |
|
opcode = POWERPC_NATIVE_OP(1, selector); |
100 |
|
break; |
101 |
|
default: |
116 |
|
static uint32 get_ind_resource_func; |
117 |
|
static uint32 get_1_ind_resource_func; |
118 |
|
static uint32 r_get_resource_func; |
119 |
+ |
static uint32 get_named_resource_func; |
120 |
+ |
static uint32 get_1_named_resource_func; |
121 |
|
|
122 |
|
static void generate_powerpc_thunks(void) |
123 |
|
{ |
124 |
+ |
// check_load_invoc() thunk |
125 |
+ |
uint32 check_load_invoc_opcode = NativeOpcode(NATIVE_CHECK_LOAD_INVOC); |
126 |
+ |
uint32 base; |
127 |
+ |
|
128 |
|
static uint32 get_resource_template[] = { |
129 |
|
PL(0x7c0802a6), // mflr r0 |
130 |
|
PL(0x90010008), // stw r0,8(r1) |
162 |
|
} |
163 |
|
assert(xlm_index != -1 && check_load_invoc_index != -1); |
164 |
|
|
151 |
– |
uint32 check_load_invoc_opcode = NativeOpcode(NATIVE_CHECK_LOAD_INVOC); |
152 |
– |
uintptr base; |
153 |
– |
|
165 |
|
// GetResource() |
166 |
|
get_resource_func = base = SheepMem::Reserve(get_resource_template_size); |
167 |
|
Host2Mac_memcpy(base, get_resource_template, get_resource_template_size); |
191 |
|
Host2Mac_memcpy(base, get_resource_template, get_resource_template_size); |
192 |
|
WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_R_GET_RESOURCE); |
193 |
|
WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode); |
194 |
+ |
|
195 |
+ |
// named_check_load_invoc() thunk |
196 |
+ |
check_load_invoc_opcode = NativeOpcode(NATIVE_NAMED_CHECK_LOAD_INVOC); |
197 |
+ |
|
198 |
+ |
static uint32 get_named_resource_template[] = { |
199 |
+ |
PL(0x7c0802a6), // mflr r0 |
200 |
+ |
PL(0x90010008), // stw r0,8(r1) |
201 |
+ |
PL(0x9421ffbc), // stwu r1,-68(r1) |
202 |
+ |
PL(0x90610038), // stw r3,56(r1) |
203 |
+ |
PL(0x9081003c), // stw r4,60(r1) |
204 |
+ |
PL(0x00000000), // lwz r0,XLM_GET_NAMED_RESOURCE(r0) |
205 |
+ |
PL(0x80402834), // lwz r2,XLM_RES_LIB_TOC(r0) |
206 |
+ |
PL(0x7c0903a6), // mtctr r0 |
207 |
+ |
PL(0x4e800421), // bctrl |
208 |
+ |
PL(0x90610040), // stw r3,64(r1) |
209 |
+ |
PL(0x80610038), // lwz r3,56(r1) |
210 |
+ |
PL(0x8081003c), // lwz r4,60(r1) |
211 |
+ |
PL(0x80a10040), // lwz r5,64(r1) |
212 |
+ |
PL(0x00000001), // <named_check_load_invoc> |
213 |
+ |
PL(0x80610040), // lwz r3,64(r1) |
214 |
+ |
PL(0x8001004c), // lwz r0,76(r1) |
215 |
+ |
PL(0x7c0803a6), // mtlr r0 |
216 |
+ |
PL(0x38210044), // addi r1,r1,68 |
217 |
+ |
PL(0x4e800020) // blr |
218 |
+ |
}; |
219 |
+ |
const uint32 get_named_resource_template_size = sizeof(get_named_resource_template); |
220 |
+ |
|
221 |
+ |
xlm_index = -1, check_load_invoc_index = -1; |
222 |
+ |
for (int i = 0; i < get_resource_template_size/4; i++) { |
223 |
+ |
uint32 opcode = ntohl(get_resource_template[i]); |
224 |
+ |
switch (opcode) { |
225 |
+ |
case 0x00000000: |
226 |
+ |
xlm_index = i; |
227 |
+ |
break; |
228 |
+ |
case 0x00000001: |
229 |
+ |
check_load_invoc_index = i; |
230 |
+ |
break; |
231 |
+ |
} |
232 |
+ |
} |
233 |
+ |
assert(xlm_index != -1 && check_load_invoc_index != -1); |
234 |
+ |
|
235 |
+ |
// GetNamedResource() |
236 |
+ |
get_named_resource_func = base = SheepMem::Reserve(get_named_resource_template_size); |
237 |
+ |
Host2Mac_memcpy(base, get_named_resource_template, get_named_resource_template_size); |
238 |
+ |
WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_NAMED_RESOURCE); |
239 |
+ |
WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode); |
240 |
+ |
|
241 |
+ |
// Get1NamedResource() |
242 |
+ |
get_1_named_resource_func = base = SheepMem::Reserve(get_named_resource_template_size); |
243 |
+ |
Host2Mac_memcpy(base, get_named_resource_template, get_named_resource_template_size); |
244 |
+ |
WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_1_NAMED_RESOURCE); |
245 |
+ |
WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode); |
246 |
|
} |
247 |
|
#endif |
248 |
|
|
262 |
|
{ |
263 |
|
#if EMULATED_PPC |
264 |
|
for (int i = 0; i < NATIVE_OP_MAX; i++) { |
265 |
< |
uintptr base = SheepMem::Reserve(12); |
265 |
> |
uintptr base = SheepMem::Reserve(16); |
266 |
|
WriteMacInt32(base + 0, base + 8); |
267 |
|
WriteMacInt32(base + 4, 0); // Fake TVECT |
268 |
|
WriteMacInt32(base + 8, NativeOpcode(i)); |
269 |
+ |
WriteMacInt32(base + 12, POWERPC_BLR); |
270 |
|
native_op[i].tvect = base; |
271 |
|
native_op[i].func = base + 8; |
272 |
|
} |
277 |
|
native_op[NATIVE_GET_IND_RESOURCE].func = get_ind_resource_func; |
278 |
|
native_op[NATIVE_GET_1_IND_RESOURCE].func = get_1_ind_resource_func; |
279 |
|
native_op[NATIVE_R_GET_RESOURCE].func = r_get_resource_func; |
280 |
+ |
native_op[NATIVE_GET_NAMED_RESOURCE].func = get_named_resource_func; |
281 |
+ |
native_op[NATIVE_GET_1_NAMED_RESOURCE].func = get_1_named_resource_func; |
282 |
|
#endif |
283 |
|
#else |
284 |
< |
#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) |
284 |
> |
#if defined(__linux__) || defined(__NetBSD__) || (defined(__APPLE__) && defined(__MACH__)) |
285 |
|
#define DEFINE_NATIVE_OP(ID, FUNC) do { \ |
286 |
|
uintptr base = SheepMem::Reserve(8); \ |
287 |
|
WriteMacInt32(base + 0, (uint32)FUNC); \ |
288 |
< |
WriteMacInt32(base + 4, 0); /*Fake TVECT*/ \ |
288 |
> |
WriteMacInt32(base + 4, (uint32)TOC); \ |
289 |
|
native_op[ID].tvect = base; \ |
290 |
|
native_op[ID].func = (uint32)FUNC; \ |
291 |
|
} while (0) |
302 |
|
DEFINE_NATIVE_OP(NATIVE_VIDEO_INSTALL_ACCEL, VideoInstallAccel); |
303 |
|
DEFINE_NATIVE_OP(NATIVE_VIDEO_VBL, VideoVBL); |
304 |
|
DEFINE_NATIVE_OP(NATIVE_VIDEO_DO_DRIVER_IO, VideoDoDriverIO); |
305 |
+ |
DEFINE_NATIVE_OP(NATIVE_ETHER_AO_GET_HWADDR, AO_get_ethernet_address); |
306 |
+ |
DEFINE_NATIVE_OP(NATIVE_ETHER_AO_ADD_MULTI, AO_enable_multicast); |
307 |
+ |
DEFINE_NATIVE_OP(NATIVE_ETHER_AO_DEL_MULTI, AO_disable_multicast); |
308 |
+ |
DEFINE_NATIVE_OP(NATIVE_ETHER_AO_SEND_PACKET, AO_transmit_packet); |
309 |
|
DEFINE_NATIVE_OP(NATIVE_ETHER_IRQ, EtherIRQ); |
310 |
|
DEFINE_NATIVE_OP(NATIVE_ETHER_INIT, InitStreamModule); |
311 |
|
DEFINE_NATIVE_OP(NATIVE_ETHER_TERM, TerminateStreamModule); |
321 |
|
DEFINE_NATIVE_OP(NATIVE_SERIAL_STATUS, SerialStatus); |
322 |
|
DEFINE_NATIVE_OP(NATIVE_SERIAL_CLOSE, SerialClose); |
323 |
|
DEFINE_NATIVE_OP(NATIVE_MAKE_EXECUTABLE, MakeExecutable); |
324 |
< |
DEFINE_NATIVE_OP(NATIVE_SYNC_HOOK, NQD_sync_hook); |
325 |
< |
DEFINE_NATIVE_OP(NATIVE_BITBLT_HOOK, NQD_bitblt_hook); |
326 |
< |
DEFINE_NATIVE_OP(NATIVE_FILLRECT_HOOK, NQD_fillrect_hook); |
327 |
< |
DEFINE_NATIVE_OP(NATIVE_BITBLT, NQD_bitblt); |
328 |
< |
DEFINE_NATIVE_OP(NATIVE_INVRECT, NQD_invrect); |
329 |
< |
DEFINE_NATIVE_OP(NATIVE_FILLRECT, NQD_fillrect); |
324 |
> |
DEFINE_NATIVE_OP(NATIVE_NQD_SYNC_HOOK, NQD_sync_hook); |
325 |
> |
DEFINE_NATIVE_OP(NATIVE_NQD_BITBLT_HOOK, NQD_bitblt_hook); |
326 |
> |
DEFINE_NATIVE_OP(NATIVE_NQD_FILLRECT_HOOK, NQD_fillrect_hook); |
327 |
> |
DEFINE_NATIVE_OP(NATIVE_NQD_UNKNOWN_HOOK, NQD_unknown_hook); |
328 |
> |
DEFINE_NATIVE_OP(NATIVE_NQD_BITBLT, NQD_bitblt); |
329 |
> |
DEFINE_NATIVE_OP(NATIVE_NQD_INVRECT, NQD_invrect); |
330 |
> |
DEFINE_NATIVE_OP(NATIVE_NQD_FILLRECT, NQD_fillrect); |
331 |
|
#undef DEFINE_NATIVE_OP |
332 |
|
#endif |
333 |
|
|