29 |
|
#include "name_registry.h" |
30 |
|
#include "serial.h" |
31 |
|
#include "ether.h" |
32 |
+ |
#include "macos_util.h" |
33 |
|
|
34 |
|
|
35 |
|
/* NativeOp instruction format: |
42 |
|
#define POWERPC_NATIVE_OP(LR, OP) \ |
43 |
|
(POWERPC_EMUL_OP | ((LR) << 11) | (((uint32)OP) << 6) | 2) |
44 |
|
|
45 |
< |
// Return the fake PowerPC opcode to handle specified native code |
45 |
> |
/* |
46 |
> |
* Return the fake PowerPC opcode to handle specified native code |
47 |
> |
*/ |
48 |
> |
|
49 |
|
#if EMULATED_PPC |
50 |
|
uint32 NativeOpcode(int selector) |
51 |
|
{ |
88 |
|
} |
89 |
|
#endif |
90 |
|
|
91 |
< |
// NativeOp -> { TVECT, function base } mappings |
91 |
> |
|
92 |
> |
/* |
93 |
> |
* Initialize the thunks system |
94 |
> |
*/ |
95 |
> |
|
96 |
|
struct native_op_t { |
97 |
|
uint32 tvect; |
98 |
|
uint32 func; |
99 |
+ |
SheepRoutineDescriptor *desc; |
100 |
|
}; |
101 |
|
static native_op_t native_op[NATIVE_OP_MAX]; |
102 |
|
|
94 |
– |
// Initialize the thunks system |
103 |
|
bool ThunksInit(void) |
104 |
|
{ |
105 |
|
#if EMULATED_PPC |
128 |
|
#else |
129 |
|
#error "FIXME: define NativeOp for your platform" |
130 |
|
#endif |
131 |
+ |
DEFINE_NATIVE_OP(NATIVE_PATCH_NAME_REGISTRY, DoPatchNameRegistry); |
132 |
+ |
DEFINE_NATIVE_OP(NATIVE_VIDEO_INSTALL_ACCEL, VideoInstallAccel); |
133 |
+ |
DEFINE_NATIVE_OP(NATIVE_VIDEO_VBL, VideoVBL); |
134 |
+ |
DEFINE_NATIVE_OP(NATIVE_VIDEO_DO_DRIVER_IO, VideoDoDriverIO); |
135 |
+ |
DEFINE_NATIVE_OP(NATIVE_ETHER_IRQ, EtherIRQ); |
136 |
+ |
DEFINE_NATIVE_OP(NATIVE_ETHER_INIT, InitStreamModule); |
137 |
+ |
DEFINE_NATIVE_OP(NATIVE_ETHER_TERM, TerminateStreamModule); |
138 |
+ |
DEFINE_NATIVE_OP(NATIVE_ETHER_OPEN, ether_open); |
139 |
+ |
DEFINE_NATIVE_OP(NATIVE_ETHER_CLOSE, ether_close); |
140 |
+ |
DEFINE_NATIVE_OP(NATIVE_ETHER_WPUT, ether_wput); |
141 |
+ |
DEFINE_NATIVE_OP(NATIVE_ETHER_RSRV, ether_rsrv); |
142 |
|
DEFINE_NATIVE_OP(NATIVE_SERIAL_NOTHING, SerialNothing); |
143 |
|
DEFINE_NATIVE_OP(NATIVE_SERIAL_OPEN, SerialOpen); |
144 |
|
DEFINE_NATIVE_OP(NATIVE_SERIAL_PRIME_IN, SerialPrimeIn); |
149 |
|
DEFINE_NATIVE_OP(NATIVE_MAKE_EXECUTABLE, MakeExecutable); |
150 |
|
#undef DEFINE_NATIVE_OP |
151 |
|
#endif |
152 |
+ |
|
153 |
+ |
// Initialize routine descriptors |
154 |
+ |
for (int i = 0; i < NATIVE_OP_MAX; i++) |
155 |
+ |
native_op[i].desc = new SheepRoutineDescriptor(0, NativeTVECT(i)); |
156 |
+ |
|
157 |
|
return true; |
158 |
|
} |
159 |
|
|
160 |
< |
// Return the native function descriptor (TVECT) |
160 |
> |
|
161 |
> |
/* |
162 |
> |
* Delete generated thunks |
163 |
> |
*/ |
164 |
> |
|
165 |
> |
void ThunksExit(void) |
166 |
> |
{ |
167 |
> |
for (int i = 0; i < NATIVE_OP_MAX; i++) { |
168 |
> |
SheepRoutineDescriptor *desc = native_op[i].desc; |
169 |
> |
if (desc) |
170 |
> |
delete desc; |
171 |
> |
} |
172 |
> |
} |
173 |
> |
|
174 |
> |
|
175 |
> |
/* |
176 |
> |
* Return the native function descriptor (TVECT) |
177 |
> |
*/ |
178 |
> |
|
179 |
|
uint32 NativeTVECT(int selector) |
180 |
|
{ |
181 |
|
assert(selector < NATIVE_OP_MAX); |
182 |
|
const uint32 tvect = native_op[selector].tvect; |
183 |
|
assert(tvect != 0); |
184 |
< |
return native_op[selector].tvect; |
184 |
> |
return tvect; |
185 |
|
} |
186 |
|
|
187 |
< |
// Return the native function address |
187 |
> |
|
188 |
> |
/* |
189 |
> |
* Return the native function address |
190 |
> |
*/ |
191 |
> |
|
192 |
|
uint32 NativeFunction(int selector) |
193 |
|
{ |
194 |
|
assert(selector < NATIVE_OP_MAX); |
195 |
|
const uint32 func = native_op[selector].func; |
196 |
|
assert(func != 0); |
197 |
< |
return native_op[selector].func; |
197 |
> |
return func; |
198 |
> |
} |
199 |
> |
|
200 |
> |
|
201 |
> |
/* |
202 |
> |
* Return the routine descriptor address of the native function |
203 |
> |
*/ |
204 |
> |
|
205 |
> |
uint32 NativeRoutineDescriptor(int selector) |
206 |
> |
{ |
207 |
> |
assert(selector < NATIVE_OP_MAX); |
208 |
> |
SheepRoutineDescriptor * const desc = native_op[selector].desc; |
209 |
> |
assert(desc != 0); |
210 |
> |
return desc->addr(); |
211 |
> |
} |
212 |
> |
|
213 |
> |
|
214 |
> |
/* |
215 |
> |
* Execute native code from EMUL_OP routine (real mode switch) |
216 |
> |
*/ |
217 |
> |
|
218 |
> |
void ExecuteNative(int selector) |
219 |
> |
{ |
220 |
> |
M68kRegisters r; |
221 |
> |
Execute68k(NativeRoutineDescriptor(selector), &r); |
222 |
|
} |