1 |
|
/* |
2 |
|
* macos_util.cpp - MacOS definitions/utility functions |
3 |
|
* |
4 |
< |
* SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig |
4 |
> |
* SheepShaver (C) 1997-2004 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 |
42 |
|
} |
43 |
|
typedef int16 (*gsl_ptr)(char *, uint32, uint32, uint32 *, void **, char *); |
44 |
|
static uint32 gsl_tvect = 0; |
45 |
< |
static inline int16 GetSharedLibrary(char *arg1, uint32 arg2, uint32 arg3, uint32 *arg4, void **arg5, char *arg6) |
45 |
> |
static inline int16 GetSharedLibrary(uintptr arg1, uint32 arg2, uint32 arg3, uintptr arg4, uintptr arg5, uintptr arg6) |
46 |
|
{ |
47 |
< |
return (int16)CallMacOS6(gsl_ptr, gsl_tvect, arg1, arg2, arg3, arg4, arg5, arg6); |
47 |
> |
return (int16)CallMacOS6(gsl_ptr, gsl_tvect, (char *)arg1, arg2, arg3, (uint32 *)arg4, (void **)arg5, (char *)arg6); |
48 |
|
} |
49 |
|
typedef int16 (*fs_ptr)(uint32, char *, void **, uint32 *); |
50 |
|
static uint32 fs_tvect = 0; |
51 |
< |
static inline int16 FindSymbol(uint32 arg1, char *arg2, void **arg3, uint32 *arg4) |
51 |
> |
static inline int16 FindSymbol(uint32 arg1, uintptr arg2, uintptr arg3, uintptr arg4) |
52 |
|
{ |
53 |
< |
return (int16)CallMacOS4(fs_ptr, fs_tvect, arg1, arg2, arg3, arg4); |
53 |
> |
return (int16)CallMacOS4(fs_ptr, fs_tvect, arg1, (char *)arg2, (void **)arg3, (uint32 **)arg4); |
54 |
|
} |
55 |
|
typedef int16 (*cc_ptr)(uint32 *); |
56 |
|
static uint32 cc_tvect = 0; |
58 |
|
{ |
59 |
|
return (int16)CallMacOS1(cc_ptr, cc_tvect, arg1); |
60 |
|
} |
61 |
+ |
typedef void *(*nps_ptr)(uint32); |
62 |
+ |
static uint32 nps_tvect = 0; |
63 |
+ |
static inline void *NewPtrSys(uint32 arg1) |
64 |
+ |
{ |
65 |
+ |
return (void *)CallMacOS1(nps_ptr, nps_tvect, arg1); |
66 |
+ |
} |
67 |
+ |
typedef void (*d_ptr)(void *); |
68 |
+ |
static uint32 d_tvect = 0; |
69 |
+ |
static inline void DisposePtr(void *arg1) |
70 |
+ |
{ |
71 |
+ |
CallMacOS1(d_ptr, d_tvect, arg1); |
72 |
+ |
} |
73 |
|
|
74 |
|
|
75 |
|
/* |
181 |
|
M68kRegisters r; |
182 |
|
|
183 |
|
// Find shared library |
184 |
< |
static const uint8 proc1[] = { |
185 |
< |
0x55, 0x8f, // subq.l #2,a7 |
186 |
< |
0x2f, 0x08, // move.l a0,-(a7) |
187 |
< |
0x2f, 0x3c, 0x70, 0x77, 0x70, 0x63, // move.l #'pwpc',-(a7) |
188 |
< |
0x2f, 0x3c, 0x00, 0x00, 0x00, 0x01, // move.l #kReferenceCFrag,-(a7) |
189 |
< |
0x2f, 0x09, // move.l a1,-(a7) |
190 |
< |
0x2f, 0x0a, // move.l a2,-(a7) |
191 |
< |
0x2f, 0x0b, // move.l a3,-(a7) |
192 |
< |
0x3f, 0x3c, 0x00, 0x01, // (GetSharedLibrary) |
193 |
< |
0xaa, 0x5a, // CFMDispatch |
194 |
< |
0x30, 0x1f, // move.w (a7)+,d0 |
195 |
< |
M68K_RTS >> 8, M68K_RTS & 0xff |
184 |
> |
static const uint16 proc1[] = { |
185 |
> |
PW(0x558f), // subq.l #2,a7 |
186 |
> |
PW(0x2f08), // move.l a0,-(a7) |
187 |
> |
PW(0x2f3c), PW(0x7077), PW(0x7063), // move.l #'pwpc',-(a7) |
188 |
> |
PW(0x2f3c), PW(0x0000), PW(0x0001), // move.l #kReferenceCFrag,-(a7) |
189 |
> |
PW(0x2f09), // move.l a1,-(a7) |
190 |
> |
PW(0x2f0a), // move.l a2,-(a7) |
191 |
> |
PW(0x2f0b), // move.l a3,-(a7) |
192 |
> |
PW(0x3f3c), PW(0x0001), // (GetSharedLibrary) |
193 |
> |
PW(0xaa5a), // CFMDispatch |
194 |
> |
PW(0x301f), // move.w (a7)+,d0 |
195 |
> |
PW(M68K_RTS) |
196 |
|
}; |
197 |
|
r.a[0] = lib.addr(); |
198 |
|
r.a[1] = conn_id.addr(); |
199 |
|
r.a[2] = main_addr.addr(); |
200 |
|
r.a[3] = err.addr(); |
201 |
< |
Execute68k((uint32)proc1, &r); |
201 |
> |
Execute68k(Host2MacAddr((uint8 *)proc1), &r); |
202 |
|
D(bug(" GetSharedLibrary: ret %d, connection ID %ld, main %p\n", (int16)r.d[0], conn_id.value(), main_addr.value())); |
203 |
|
if (r.d[0]) |
204 |
|
return NULL; |
205 |
|
|
206 |
|
// Find symbol |
207 |
< |
static const uint8 proc2[] = { |
208 |
< |
0x55, 0x8f, // subq.l #2,a7 |
209 |
< |
0x2f, 0x00, // move.l d0,-(a7) |
210 |
< |
0x2f, 0x08, // move.l a0,-(a7) |
211 |
< |
0x2f, 0x09, // move.l a1,-(a7) |
212 |
< |
0x2f, 0x0a, // move.l a2,-(a7) |
213 |
< |
0x3f, 0x3c, 0x00, 0x05, // (FindSymbol) |
214 |
< |
0xaa, 0x5a, // CFMDispatch |
215 |
< |
0x30, 0x1f, // move.w (a7)+,d0 |
216 |
< |
M68K_RTS >> 8, M68K_RTS & 0xff |
207 |
> |
static const uint16 proc2[] = { |
208 |
> |
PW(0x558f), // subq.l #2,a7 |
209 |
> |
PW(0x2f00), // move.l d0,-(a7) |
210 |
> |
PW(0x2f08), // move.l a0,-(a7) |
211 |
> |
PW(0x2f09), // move.l a1,-(a7) |
212 |
> |
PW(0x2f0a), // move.l a2,-(a7) |
213 |
> |
PW(0x3f3c), PW(0x0005), // (FindSymbol) |
214 |
> |
PW(0xaa5a), // CFMDispatch |
215 |
> |
PW(0x301f), // move.w (a7)+,d0 |
216 |
> |
PW(M68K_RTS) |
217 |
|
}; |
218 |
|
r.d[0] = conn_id.value(); |
219 |
|
r.a[0] = sym.addr(); |
220 |
|
r.a[1] = sym_addr.addr(); |
221 |
|
r.a[2] = sym_class.addr(); |
222 |
< |
Execute68k((uint32)proc2, &r); |
222 |
> |
Execute68k(Host2MacAddr((uint8 *)proc2), &r); |
223 |
|
D(bug(" FindSymbol1: ret %d, sym_addr %p, sym_class %ld\n", (int16)r.d[0], sym_addr.value(), sym_class.value())); |
224 |
|
//!! CloseConnection()? |
225 |
|
if (r.d[0]) |
234 |
|
return 0; |
235 |
|
} |
236 |
|
int16 res; |
237 |
< |
res = GetSharedLibrary(lib.value(), FOURCC('p','w','p','c'), 1, (uint32 *)conn_id.addr(), (void **)main_addr.addr(), (char *)err.addr()); |
237 |
> |
res = GetSharedLibrary(lib.addr(), FOURCC('p','w','p','c'), 1, conn_id.addr(), main_addr.addr(), err.addr()); |
238 |
|
D(bug(" GetSharedLibrary: ret %d, connection ID %ld, main %p\n", res, conn_id.value(), main_addr.value())); |
239 |
|
if (res) |
240 |
|
return NULL; |
241 |
< |
res = FindSymbol(conn_id.value(), sym.value(), (void **)sym_addr.addr(), (uint32 *)sym_class.addr()); |
241 |
> |
res = FindSymbol(conn_id.value(), sym.addr(), sym_addr.addr(), sym_class.addr()); |
242 |
|
D(bug(" FindSymbol: ret %d, sym_addr %p, sym_class %ld\n", res, sym_addr.value(), sym_class.value())); |
243 |
|
//!!?? CloseConnection(&conn_id); |
244 |
|
if (res) |
282 |
|
printf("FATAL: Can't find CloseConnection()\n"); |
283 |
|
QuitEmulator(); |
284 |
|
} |
285 |
+ |
|
286 |
+ |
nps_tvect = (uint32)FindLibSymbol("\014InterfaceLib", "\011NewPtrSys"); |
287 |
+ |
D(bug("NewPtrSys TVECT at %08lx\n", nps_tvect)); |
288 |
+ |
if (nps_tvect == 0) { |
289 |
+ |
printf("FATAL: Can't find NewPtrSys()\n"); |
290 |
+ |
QuitEmulator(); |
291 |
+ |
} |
292 |
+ |
|
293 |
+ |
d_tvect = (uint32)FindLibSymbol("\014InterfaceLib", "\012DisposePtr"); |
294 |
+ |
D(bug("DisposePtr TVECT at %08lx\n", d_tvect)); |
295 |
+ |
if (d_tvect == 0) { |
296 |
+ |
printf("FATAL: Can't find DisposePtr()\n"); |
297 |
+ |
QuitEmulator(); |
298 |
+ |
} |
299 |
|
} |
300 |
|
|
301 |
|
|
335 |
|
uint32 days = local->tm_yday + 365 * (local->tm_year - 4) + intervening_leap_days; |
336 |
|
return local->tm_sec + 60 * (local->tm_min + 60 * (local->tm_hour + 24 * days)); |
337 |
|
} |
338 |
+ |
|
339 |
+ |
|
340 |
+ |
/* |
341 |
+ |
* Memory allocators in MacOS system heap zone |
342 |
+ |
*/ |
343 |
+ |
|
344 |
+ |
void *Mac_sysalloc(uint32 size) |
345 |
+ |
{ |
346 |
+ |
return NewPtrSys(size); |
347 |
+ |
} |
348 |
+ |
|
349 |
+ |
void Mac_sysfree(void *p) |
350 |
+ |
{ |
351 |
+ |
DisposePtr(p); |
352 |
+ |
} |