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.15 by gbeauche, 2005-07-03T22:43:11Z vs.
Revision 1.16 by gbeauche, 2006-05-03T21:45:14Z

# Line 56 | Line 56 | uint32 NativeOpcode(int selector)
56          uint32 opcode;
57          switch (selector) {
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:
# Line 85 | 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_SYNC_HOOK:
93          case NATIVE_BITBLT_HOOK:
# Line 112 | Line 115 | static uint32 get_1_resource_func;
115   static uint32 get_ind_resource_func;
116   static uint32 get_1_ind_resource_func;
117   static uint32 r_get_resource_func;
118 + static uint32 get_named_resource_func;
119 + static uint32 get_1_named_resource_func;
120  
121   static void generate_powerpc_thunks(void)
122   {
123 +        // check_load_invoc() thunk
124 +        uint32 check_load_invoc_opcode = NativeOpcode(NATIVE_CHECK_LOAD_INVOC);
125 +        uint32 base;
126 +
127          static uint32 get_resource_template[] = {
128                  PL(0x7c0802a6),         // mflr    r0
129                  PL(0x90010008),         // stw     r0,8(r1)
# Line 152 | Line 161 | static void generate_powerpc_thunks(void
161          }
162          assert(xlm_index != -1 && check_load_invoc_index != -1);
163  
155        uint32 check_load_invoc_opcode = NativeOpcode(NATIVE_CHECK_LOAD_INVOC);
156        uint32 base;
157
164          // GetResource()
165          get_resource_func = base = SheepMem::Reserve(get_resource_template_size);
166          Host2Mac_memcpy(base, get_resource_template, get_resource_template_size);
# Line 184 | Line 190 | static void generate_powerpc_thunks(void
190          Host2Mac_memcpy(base, get_resource_template, get_resource_template_size);
191          WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_R_GET_RESOURCE);
192          WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode);
193 +
194 +        // named_check_load_invoc() thunk
195 +        check_load_invoc_opcode = NativeOpcode(NATIVE_NAMED_CHECK_LOAD_INVOC);
196 +
197 +        static uint32 get_named_resource_template[] = {
198 +                PL(0x7c0802a6),         // mflr    r0
199 +                PL(0x90010008),         // stw     r0,8(r1)
200 +                PL(0x9421ffbc),         // stwu    r1,-68(r1)
201 +                PL(0x90610038),         // stw     r3,56(r1)
202 +                PL(0x9081003c),         // stw     r4,60(r1)
203 +                PL(0x00000000),         // lwz     r0,XLM_GET_NAMED_RESOURCE(r0)
204 +                PL(0x80402834),         // lwz     r2,XLM_RES_LIB_TOC(r0)
205 +                PL(0x7c0903a6),         // mtctr   r0
206 +                PL(0x4e800421),         // bctrl
207 +                PL(0x90610040),         // stw     r3,64(r1)
208 +                PL(0x80610038),         // lwz     r3,56(r1)
209 +                PL(0x8081003c),         // lwz     r4,60(r1)
210 +                PL(0x80a10040),         // lwz     r5,64(r1)
211 +                PL(0x00000001),         // <named_check_load_invoc>
212 +                PL(0x80610040),         // lwz     r3,64(r1)
213 +                PL(0x8001004c),         // lwz     r0,76(r1)
214 +                PL(0x7c0803a6),         // mtlr    r0
215 +                PL(0x38210044),         // addi    r1,r1,68
216 +                PL(0x4e800020)          // blr
217 +        };
218 +        const uint32 get_named_resource_template_size = sizeof(get_named_resource_template);
219 +
220 +        xlm_index = -1, check_load_invoc_index = -1;
221 +        for (int i = 0; i < get_resource_template_size/4; i++) {
222 +                uint32 opcode = ntohl(get_resource_template[i]);
223 +                switch (opcode) {
224 +                case 0x00000000:
225 +                        xlm_index = i;
226 +                        break;
227 +                case 0x00000001:
228 +                        check_load_invoc_index = i;
229 +                        break;
230 +                }
231 +        }
232 +        assert(xlm_index != -1 && check_load_invoc_index != -1);
233 +
234 +        // GetNamedResource()
235 +        get_named_resource_func = base = SheepMem::Reserve(get_named_resource_template_size);
236 +        Host2Mac_memcpy(base, get_named_resource_template, get_named_resource_template_size);
237 +        WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_NAMED_RESOURCE);
238 +        WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode);
239 +
240 +        // Get1NamedResource()
241 +        get_1_named_resource_func = base = SheepMem::Reserve(get_named_resource_template_size);
242 +        Host2Mac_memcpy(base, get_named_resource_template, get_named_resource_template_size);
243 +        WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_1_NAMED_RESOURCE);
244 +        WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode);
245   }
246   #endif
247  
# Line 217 | Line 275 | bool ThunksInit(void)
275          native_op[NATIVE_GET_IND_RESOURCE].func = get_ind_resource_func;
276          native_op[NATIVE_GET_1_IND_RESOURCE].func = get_1_ind_resource_func;
277          native_op[NATIVE_R_GET_RESOURCE].func = r_get_resource_func;
278 +        native_op[NATIVE_GET_NAMED_RESOURCE].func = get_named_resource_func;
279 +        native_op[NATIVE_GET_1_NAMED_RESOURCE].func = get_1_named_resource_func;
280   #endif
281   #else
282   #if defined(__linux__) || defined(__NetBSD__) || (defined(__APPLE__) && defined(__MACH__))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines