ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/thunks.cpp
(Generate patch)

Comparing SheepShaver/src/thunks.cpp (file contents):
Revision 1.4 by gbeauche, 2004-01-15T23:28:59Z vs.
Revision 1.17 by gbeauche, 2006-05-13T17:12:18Z

# Line 22 | Line 22
22   #include "thunks.h"
23   #include "emul_op.h"
24   #include "cpu_emulation.h"
25 + #include "xlowmem.h"
26  
27   // Native function declarations
28   #include "main.h"
# Line 31 | Line 32
32   #include "ether.h"
33   #include "macos_util.h"
34  
35 + // Generate PowerPC thunks for GetResource() replacements?
36 + #define POWERPC_GET_RESOURCE_THUNKS 1
37 +
38  
39   /*              NativeOp instruction format:
40 <                +------------+--------------------------+--+----------+------------+
41 <                |      6     |                          |FN|    OP    |      2     |
42 <                +------------+--------------------------+--+----------+------------+
43 <                 0         5 |6                       19 20 21      25 26        31
40 >                +------------+-------------------------+--+-----------+------------+
41 >                |      6     |                         |FN|    OP     |      2     |
42 >                +------------+-------------------------+--+-----------+------------+
43 >                 0         5 |6                      18 19 20      25 26        31
44   */
45  
46 < #define POWERPC_NATIVE_OP(LR, OP) \
47 <                (POWERPC_EMUL_OP | ((LR) << 11) | (((uint32)OP) << 6) | 2)
46 > #define POWERPC_NATIVE_OP(FN, OP) \
47 >                (POWERPC_EMUL_OP | ((FN) << 12) | (((uint32)OP) << 6) | 2)
48  
49   /*
50   *  Return the fake PowerPC opcode to handle specified native code
# Line 51 | Line 55 | uint32 NativeOpcode(int selector)
55   {
56          uint32 opcode;
57          switch (selector) {
58 <        case NATIVE_DISABLE_INTERRUPT:
59 <        case NATIVE_ENABLE_INTERRUPT:
58 >        case NATIVE_CHECK_LOAD_INVOC:
59 >        case NATIVE_NAMED_CHECK_LOAD_INVOC:
60                  opcode = POWERPC_NATIVE_OP(0, selector);
61                  break;
62          case NATIVE_PATCH_NAME_REGISTRY:
63          case NATIVE_VIDEO_INSTALL_ACCEL:
64          case NATIVE_VIDEO_VBL:
65          case NATIVE_VIDEO_DO_DRIVER_IO:
66 +        case NATIVE_ETHER_AO_GET_HWADDR:
67 +        case NATIVE_ETHER_AO_ADD_MULTI:
68 +        case NATIVE_ETHER_AO_DEL_MULTI:
69 +        case NATIVE_ETHER_AO_SEND_PACKET:
70          case NATIVE_ETHER_IRQ:
71          case NATIVE_ETHER_INIT:
72          case NATIVE_ETHER_TERM:
# Line 78 | Line 86 | uint32 NativeOpcode(int selector)
86          case NATIVE_GET_IND_RESOURCE:
87          case NATIVE_GET_1_IND_RESOURCE:
88          case NATIVE_R_GET_RESOURCE:
89 +        case NATIVE_GET_NAMED_RESOURCE:
90 +        case NATIVE_GET_1_NAMED_RESOURCE:
91          case NATIVE_MAKE_EXECUTABLE:
92 +        case NATIVE_NQD_SYNC_HOOK:
93 +        case NATIVE_NQD_BITBLT_HOOK:
94 +        case NATIVE_NQD_FILLRECT_HOOK:
95 +        case NATIVE_NQD_UNKNOWN_HOOK:
96 +        case NATIVE_NQD_BITBLT:
97 +        case NATIVE_NQD_INVRECT:
98 +        case NATIVE_NQD_FILLRECT:
99                  opcode = POWERPC_NATIVE_OP(1, selector);
100                  break;
101          default:
# Line 90 | Line 107 | uint32 NativeOpcode(int selector)
107  
108  
109   /*
110 + *  Generate PowerPC thunks for GetResource() replacements
111 + */
112 +
113 + #if EMULATED_PPC
114 + static uint32 get_resource_func;
115 + static uint32 get_1_resource_func;
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)
131 +                PL(0x9421ffbc),         // stwu    r1,-68(r1)
132 +                PL(0x90610038),         // stw     r3,56(r1)
133 +                PL(0x9081003c),         // stw     r4,60(r1)
134 +                PL(0x00000000),         // lwz     r0,XLM_GET_RESOURCE(r0)
135 +                PL(0x80402834),         // lwz     r2,XLM_RES_LIB_TOC(r0)
136 +                PL(0x7c0903a6),         // mtctr   r0
137 +                PL(0x4e800421),         // bctrl
138 +                PL(0x90610040),         // stw     r3,64(r1)
139 +                PL(0x80610038),         // lwz     r3,56(r1)
140 +                PL(0xa881003e),         // lha     r4,62(r1)
141 +                PL(0x80a10040),         // lwz     r5,64(r1)
142 +                PL(0x00000001),         // <check_load_invoc>
143 +                PL(0x80610040),         // lwz     r3,64(r1)
144 +                PL(0x8001004c),         // lwz     r0,76(r1)
145 +                PL(0x7c0803a6),         // mtlr    r0
146 +                PL(0x38210044),         // addi    r1,r1,68
147 +                PL(0x4e800020)          // blr
148 +        };
149 +        const uint32 get_resource_template_size = sizeof(get_resource_template);
150 +
151 +        int xlm_index = -1, check_load_invoc_index = -1;
152 +        for (int i = 0; i < get_resource_template_size/4; i++) {
153 +                uint32 opcode = ntohl(get_resource_template[i]);
154 +                switch (opcode) {
155 +                case 0x00000000:
156 +                        xlm_index = i;
157 +                        break;
158 +                case 0x00000001:
159 +                        check_load_invoc_index = i;
160 +                        break;
161 +                }
162 +        }
163 +        assert(xlm_index != -1 && check_load_invoc_index != -1);
164 +
165 +        // GetResource()
166 +        get_resource_func = base = SheepMem::Reserve(get_resource_template_size);
167 +        Host2Mac_memcpy(base, get_resource_template, get_resource_template_size);
168 +        WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_RESOURCE);
169 +        WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode);
170 +
171 +        // Get1Resource()
172 +        get_1_resource_func = base = SheepMem::Reserve(get_resource_template_size);
173 +        Host2Mac_memcpy(base, get_resource_template, get_resource_template_size);
174 +        WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_1_RESOURCE);
175 +        WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode);
176 +
177 +        // GetIndResource()
178 +        get_ind_resource_func = base = SheepMem::Reserve(get_resource_template_size);
179 +        Host2Mac_memcpy(base, get_resource_template, get_resource_template_size);
180 +        WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_IND_RESOURCE);
181 +        WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode);
182 +
183 +        // Get1IndResource()
184 +        get_1_ind_resource_func = base = SheepMem::Reserve(get_resource_template_size);
185 +        Host2Mac_memcpy(base, get_resource_template, get_resource_template_size);
186 +        WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_1_IND_RESOURCE);
187 +        WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode);
188 +
189 +        // RGetResource()
190 +        r_get_resource_func = base = SheepMem::Reserve(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 +
249 +
250 + /*
251   *  Initialize the thunks system
252   */
253  
# Line 111 | Line 269 | bool ThunksInit(void)
269                  native_op[i].tvect = base;
270                  native_op[i].func  = base + 8;
271          }
272 + #if POWERPC_GET_RESOURCE_THUNKS
273 +        generate_powerpc_thunks();
274 +        native_op[NATIVE_GET_RESOURCE].func = get_resource_func;
275 +        native_op[NATIVE_GET_1_RESOURCE].func = get_1_resource_func;
276 +        native_op[NATIVE_GET_IND_RESOURCE].func = get_ind_resource_func;
277 +        native_op[NATIVE_GET_1_IND_RESOURCE].func = get_1_ind_resource_func;
278 +        native_op[NATIVE_R_GET_RESOURCE].func = r_get_resource_func;
279 +        native_op[NATIVE_GET_NAMED_RESOURCE].func = get_named_resource_func;
280 +        native_op[NATIVE_GET_1_NAMED_RESOURCE].func = get_1_named_resource_func;
281 + #endif
282   #else
283 < #if defined(__linux__)
283 > #if defined(__linux__) || defined(__NetBSD__) || (defined(__APPLE__) && defined(__MACH__))
284   #define DEFINE_NATIVE_OP(ID, FUNC) do {                         \
285                  uintptr base = SheepMem::Reserve(8);            \
286                  WriteMacInt32(base + 0, (uint32)FUNC);          \
287 <                WriteMacInt32(base + 4, 0); /*Fake TVECT*/      \
287 >                WriteMacInt32(base + 4, (uint32)TOC);           \
288                  native_op[ID].tvect = base;                                     \
289                  native_op[ID].func  = (uint32)FUNC;                     \
290          } while (0)
# Line 133 | Line 301 | bool ThunksInit(void)
301          DEFINE_NATIVE_OP(NATIVE_VIDEO_INSTALL_ACCEL, VideoInstallAccel);
302          DEFINE_NATIVE_OP(NATIVE_VIDEO_VBL, VideoVBL);
303          DEFINE_NATIVE_OP(NATIVE_VIDEO_DO_DRIVER_IO, VideoDoDriverIO);
304 +        DEFINE_NATIVE_OP(NATIVE_ETHER_AO_GET_HWADDR, AO_get_ethernet_address);
305 +        DEFINE_NATIVE_OP(NATIVE_ETHER_AO_ADD_MULTI, AO_enable_multicast);
306 +        DEFINE_NATIVE_OP(NATIVE_ETHER_AO_DEL_MULTI, AO_disable_multicast);
307 +        DEFINE_NATIVE_OP(NATIVE_ETHER_AO_SEND_PACKET, AO_transmit_packet);
308          DEFINE_NATIVE_OP(NATIVE_ETHER_IRQ, EtherIRQ);
309          DEFINE_NATIVE_OP(NATIVE_ETHER_INIT, InitStreamModule);
310          DEFINE_NATIVE_OP(NATIVE_ETHER_TERM, TerminateStreamModule);
# Line 148 | Line 320 | bool ThunksInit(void)
320          DEFINE_NATIVE_OP(NATIVE_SERIAL_STATUS, SerialStatus);
321          DEFINE_NATIVE_OP(NATIVE_SERIAL_CLOSE, SerialClose);
322          DEFINE_NATIVE_OP(NATIVE_MAKE_EXECUTABLE, MakeExecutable);
323 +        DEFINE_NATIVE_OP(NATIVE_NQD_SYNC_HOOK, NQD_sync_hook);
324 +        DEFINE_NATIVE_OP(NATIVE_NQD_BITBLT_HOOK, NQD_bitblt_hook);
325 +        DEFINE_NATIVE_OP(NATIVE_NQD_FILLRECT_HOOK, NQD_fillrect_hook);
326 +        DEFINE_NATIVE_OP(NATIVE_NQD_UNKNOWN_HOOK, NQD_unknown_hook);
327 +        DEFINE_NATIVE_OP(NATIVE_NQD_BITBLT, NQD_bitblt);
328 +        DEFINE_NATIVE_OP(NATIVE_NQD_INVRECT, NQD_invrect);
329 +        DEFINE_NATIVE_OP(NATIVE_NQD_FILLRECT, NQD_fillrect);
330   #undef DEFINE_NATIVE_OP
331   #endif
332  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines