1 |
|
/* |
2 |
|
* thunks.h - 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 |
32 |
|
NATIVE_VIDEO_INSTALL_ACCEL, |
33 |
|
NATIVE_VIDEO_VBL, |
34 |
|
NATIVE_VIDEO_DO_DRIVER_IO, |
35 |
+ |
NATIVE_ETHER_AO_GET_HWADDR, |
36 |
+ |
NATIVE_ETHER_AO_ADD_MULTI, |
37 |
+ |
NATIVE_ETHER_AO_DEL_MULTI, |
38 |
+ |
NATIVE_ETHER_AO_SEND_PACKET, |
39 |
|
NATIVE_ETHER_IRQ, |
40 |
|
NATIVE_ETHER_INIT, |
41 |
|
NATIVE_ETHER_TERM, |
55 |
|
NATIVE_GET_IND_RESOURCE, |
56 |
|
NATIVE_GET_1_IND_RESOURCE, |
57 |
|
NATIVE_R_GET_RESOURCE, |
54 |
– |
NATIVE_DISABLE_INTERRUPT, |
55 |
– |
NATIVE_ENABLE_INTERRUPT, |
58 |
|
NATIVE_MAKE_EXECUTABLE, |
59 |
|
NATIVE_CHECK_LOAD_INVOC, |
60 |
+ |
NATIVE_NQD_SYNC_HOOK, |
61 |
+ |
NATIVE_NQD_BITBLT_HOOK, |
62 |
+ |
NATIVE_NQD_FILLRECT_HOOK, |
63 |
+ |
NATIVE_NQD_UNKNOWN_HOOK, |
64 |
+ |
NATIVE_NQD_BITBLT, |
65 |
+ |
NATIVE_NQD_INVRECT, |
66 |
+ |
NATIVE_NQD_FILLRECT, |
67 |
+ |
NATIVE_NAMED_CHECK_LOAD_INVOC, |
68 |
+ |
NATIVE_GET_NAMED_RESOURCE, |
69 |
+ |
NATIVE_GET_1_NAMED_RESOURCE, |
70 |
|
NATIVE_OP_MAX |
71 |
|
}; |
72 |
|
|
93 |
|
|
94 |
|
/* |
95 |
|
* Helpers to share 32-bit addressable data with MacOS |
96 |
+ |
* |
97 |
+ |
* There are two distinct allocatable regions: |
98 |
+ |
* |
99 |
+ |
* - The Data region is used to share data between MacOS and |
100 |
+ |
* SheepShaver. This is stack-like allocation since it is |
101 |
+ |
* meant to only hold temporary data which dies at the end |
102 |
+ |
* of the current function scope. |
103 |
+ |
* |
104 |
+ |
* - The Procedure region is used to hold permanent M68K or |
105 |
+ |
* PowerPC code to assist native routine implementations. |
106 |
+ |
* |
107 |
+ |
* - The Procedure region grows up whereas the Data region |
108 |
+ |
* grows down. They may intersect into the ZeroPage, which |
109 |
+ |
* is a read-only page with all bits set to zero. In practise, |
110 |
+ |
* the intersection is unlikely since the Procedure region is |
111 |
+ |
* static and the Data region is meant to be small (< 256 KB). |
112 |
|
*/ |
113 |
|
|
114 |
|
class SheepMem { |
117 |
|
static uint32 page_size; |
118 |
|
static uintptr zero_page; |
119 |
|
static uintptr base; |
120 |
< |
static uintptr top; |
121 |
< |
static const uint32 size = 0x40000; // 256 KB |
120 |
> |
static uintptr data; |
121 |
> |
static uintptr proc; |
122 |
> |
static const uint32 size = 0x80000; // 512 KB |
123 |
|
public: |
124 |
|
static bool Init(void); |
125 |
|
static void Exit(void); |
126 |
|
static uint32 PageSize(); |
127 |
< |
static uintptr ZeroPage(); |
128 |
< |
static uintptr Reserve(uint32 size); |
127 |
> |
static uint32 ZeroPage(); |
128 |
> |
static uint32 Reserve(uint32 size); |
129 |
|
static void Release(uint32 size); |
130 |
+ |
static uint32 ReserveProc(uint32 size); |
131 |
|
friend class SheepVar; |
132 |
|
}; |
133 |
|
|
142 |
|
return page_size; |
143 |
|
} |
144 |
|
|
145 |
< |
inline uintptr SheepMem::ZeroPage() |
145 |
> |
inline uint32 SheepMem::ZeroPage() |
146 |
|
{ |
147 |
|
return zero_page; |
148 |
|
} |
149 |
|
|
150 |
< |
inline uintptr SheepMem::Reserve(uint32 size) |
150 |
> |
inline uint32 SheepMem::Reserve(uint32 size) |
151 |
|
{ |
152 |
< |
top -= align(size); |
153 |
< |
assert(top >= base); |
154 |
< |
return top; |
152 |
> |
data -= align(size); |
153 |
> |
assert(data >= proc); |
154 |
> |
return data; |
155 |
|
} |
156 |
|
|
157 |
|
inline void SheepMem::Release(uint32 size) |
158 |
|
{ |
159 |
< |
top += align(size); |
159 |
> |
data += align(size); |
160 |
|
} |
161 |
|
|
162 |
+ |
inline uint32 SheepMem::ReserveProc(uint32 size) |
163 |
+ |
{ |
164 |
+ |
uint32 mproc = proc; |
165 |
+ |
proc += align(size); |
166 |
+ |
assert(proc < data); |
167 |
+ |
return mproc; |
168 |
+ |
} |
169 |
+ |
|
170 |
+ |
static inline uint32 SheepProc(const uint8 *proc, uint32 proc_size) |
171 |
+ |
{ |
172 |
+ |
uint32 mac_proc = SheepMem::ReserveProc(proc_size); |
173 |
+ |
Host2Mac_memcpy(mac_proc, proc, proc_size); |
174 |
+ |
return mac_proc; |
175 |
+ |
} |
176 |
+ |
|
177 |
+ |
#define BUILD_SHEEPSHAVER_PROCEDURE(PROC) \ |
178 |
+ |
static uint32 PROC = 0; \ |
179 |
+ |
if (PROC == 0) \ |
180 |
+ |
PROC = SheepProc(PROC##_template, sizeof(PROC##_template)) |
181 |
+ |
|
182 |
|
class SheepVar |
183 |
|
{ |
184 |
< |
uintptr m_base; |
185 |
< |
uint32 m_size; |
184 |
> |
uint32 m_base; |
185 |
> |
uint32 m_size; |
186 |
|
public: |
187 |
|
SheepVar(uint32 requested_size); |
188 |
|
~SheepVar() { SheepMem::Release(m_size); } |
189 |
< |
uintptr addr() const { return m_base; } |
140 |
< |
void *ptr() const { return (void *)addr(); } |
189 |
> |
uint32 addr() const { return m_base; } |
190 |
|
}; |
191 |
|
|
192 |
|
inline SheepVar::SheepVar(uint32 requested_size) |
197 |
|
|
198 |
|
// TODO: optimize for 32-bit platforms |
199 |
|
|
200 |
< |
template< int size > |
200 |
> |
template< int requested_size > |
201 |
|
struct SheepArray : public SheepVar |
202 |
|
{ |
203 |
< |
SheepArray() : SheepVar(size) { } |
155 |
< |
uint8 *ptr() const { return (uint8 *)addr(); } |
203 |
> |
SheepArray() : SheepVar(requested_size) { } |
204 |
|
}; |
205 |
|
|
206 |
|
struct SheepVar32 : public SheepVar |
209 |
|
SheepVar32(uint32 value) : SheepVar(4) { set_value(value); } |
210 |
|
uint32 value() const { return ReadMacInt32(addr()); } |
211 |
|
void set_value(uint32 v) { WriteMacInt32(addr(), v); } |
164 |
– |
uint32 *ptr() const { return (uint32 *)addr(); } |
212 |
|
}; |
213 |
|
|
214 |
|
struct SheepString : public SheepVar |
215 |
|
{ |
216 |
|
SheepString(const char *str) : SheepVar(strlen(str) + 1) |
217 |
< |
{ if (str) strcpy((char *)addr(), str); else WriteMacInt8(addr(), 0); } |
217 |
> |
{ if (str) strcpy(value(), str); else WriteMacInt8(addr(), 0); } |
218 |
|
char *value() const |
219 |
< |
{ return (char *)addr(); } |
173 |
< |
char *ptr() const |
174 |
< |
{ return (char *)addr(); } |
219 |
> |
{ return (char *)Mac2HostAddr(addr()); } |
220 |
|
}; |
221 |
|
|
222 |
|
#endif |