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.3 by gbeauche, 2004-01-07T18:24:44Z vs.
Revision 1.7 by gbeauche, 2004-04-18T23:03:50Z

# 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                  +------------+--------------------------+--+----------+------------+
# Line 53 | Line 57 | uint32 NativeOpcode(int selector)
57          switch (selector) {
58          case NATIVE_DISABLE_INTERRUPT:
59          case NATIVE_ENABLE_INTERRUPT:
60 +        case NATIVE_CHECK_LOAD_INVOC:
61                  opcode = POWERPC_NATIVE_OP(0, selector);
62                  break;
63          case NATIVE_PATCH_NAME_REGISTRY:
# Line 79 | Line 84 | uint32 NativeOpcode(int selector)
84          case NATIVE_GET_1_IND_RESOURCE:
85          case NATIVE_R_GET_RESOURCE:
86          case NATIVE_MAKE_EXECUTABLE:
87 +        case NATIVE_SYNC_HOOK:
88 +        case NATIVE_BITBLT_HOOK:
89 +        case NATIVE_FILLRECT_HOOK:
90 +        case NATIVE_BITBLT:
91 +        case NATIVE_INVRECT:
92 +        case NATIVE_FILLRECT_8:
93 +        case NATIVE_FILLRECT_32:
94                  opcode = POWERPC_NATIVE_OP(1, selector);
95                  break;
96          default:
# Line 90 | Line 102 | uint32 NativeOpcode(int selector)
102  
103  
104   /*
105 + *  Generate PowerPC thunks for GetResource() replacements
106 + */
107 +
108 + #if EMULATED_PPC
109 + static uint32 get_resource_func;
110 + static uint32 get_1_resource_func;
111 + static uint32 get_ind_resource_func;
112 + static uint32 get_1_ind_resource_func;
113 + static uint32 r_get_resource_func;
114 +
115 + static void generate_powerpc_thunks(void)
116 + {
117 +        static uint32 get_resource_template[] = {
118 +                PL(0x7c0802a6),         // mflr    r0
119 +                PL(0x90010008),         // stw     r0,8(r1)
120 +                PL(0x9421ffbc),         // stwu    r1,-68(r1)
121 +                PL(0x90610038),         // stw     r3,56(r1)
122 +                PL(0x9081003c),         // stw     r4,60(r1)
123 +                PL(0x00000000),         // lwz     r0,XLM_GET_RESOURCE(r0)
124 +                PL(0x80402834),         // lwz     r2,XLM_RES_LIB_TOC(r0)
125 +                PL(0x7c0903a6),         // mtctr   r0
126 +                PL(0x4e800421),         // bctrl
127 +                PL(0x90610040),         // stw     r3,64(r1)
128 +                PL(0x80610038),         // lwz     r3,56(r1)
129 +                PL(0xa881003e),         // lha     r4,62(r1)
130 +                PL(0x80a10040),         // lwz     r5,64(r1)
131 +                PL(0x00000001),         // <check_load_invoc>
132 +                PL(0x80610040),         // lwz     r3,64(r1)
133 +                PL(0x8001004c),         // lwz     r0,76(r1)
134 +                PL(0x7c0803a6),         // mtlr    r0
135 +                PL(0x38210044),         // addi    r1,r1,68
136 +                PL(0x4e800020)          // blr
137 +        };
138 +        const uint32 get_resource_template_size = sizeof(get_resource_template);
139 +
140 +        int xlm_index = -1, check_load_invoc_index = -1;
141 +        for (int i = 0; i < get_resource_template_size/4; i++) {
142 +                uint32 opcode = ntohl(get_resource_template[i]);
143 +                switch (opcode) {
144 +                case 0x00000000:
145 +                        xlm_index = i;
146 +                        break;
147 +                case 0x00000001:
148 +                        check_load_invoc_index = i;
149 +                        break;
150 +                }
151 +        }
152 +        assert(xlm_index != -1 && check_load_invoc_index != -1);
153 +
154 +        uint32 check_load_invoc_opcode = NativeOpcode(NATIVE_CHECK_LOAD_INVOC);
155 +        uintptr base;
156 +
157 +        // GetResource()
158 +        get_resource_func = base = SheepMem::Reserve(get_resource_template_size);
159 +        Host2Mac_memcpy(base, get_resource_template, get_resource_template_size);
160 +        WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_RESOURCE);
161 +        WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode);
162 +
163 +        // Get1Resource()
164 +        get_1_resource_func = base = SheepMem::Reserve(get_resource_template_size);
165 +        Host2Mac_memcpy(base, get_resource_template, get_resource_template_size);
166 +        WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_1_RESOURCE);
167 +        WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode);
168 +
169 +        // GetIndResource()
170 +        get_ind_resource_func = base = SheepMem::Reserve(get_resource_template_size);
171 +        Host2Mac_memcpy(base, get_resource_template, get_resource_template_size);
172 +        WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_IND_RESOURCE);
173 +        WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode);
174 +
175 +        // Get1IndResource()
176 +        get_1_ind_resource_func = base = SheepMem::Reserve(get_resource_template_size);
177 +        Host2Mac_memcpy(base, get_resource_template, get_resource_template_size);
178 +        WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_GET_1_IND_RESOURCE);
179 +        WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode);
180 +
181 +        // RGetResource()
182 +        r_get_resource_func = base = SheepMem::Reserve(get_resource_template_size);
183 +        Host2Mac_memcpy(base, get_resource_template, get_resource_template_size);
184 +        WriteMacInt32(base + xlm_index * 4, 0x80000000 | XLM_R_GET_RESOURCE);
185 +        WriteMacInt32(base + check_load_invoc_index * 4, check_load_invoc_opcode);
186 + }
187 + #endif
188 +
189 +
190 + /*
191   *  Initialize the thunks system
192   */
193  
# Line 111 | Line 209 | bool ThunksInit(void)
209                  native_op[i].tvect = base;
210                  native_op[i].func  = base + 8;
211          }
212 + #if POWERPC_GET_RESOURCE_THUNKS
213 +        generate_powerpc_thunks();
214 +        native_op[NATIVE_GET_RESOURCE].func = get_resource_func;
215 +        native_op[NATIVE_GET_1_RESOURCE].func = get_1_resource_func;
216 +        native_op[NATIVE_GET_IND_RESOURCE].func = get_ind_resource_func;
217 +        native_op[NATIVE_GET_1_IND_RESOURCE].func = get_1_ind_resource_func;
218 +        native_op[NATIVE_R_GET_RESOURCE].func = r_get_resource_func;
219 + #endif
220   #else
221 < #if defined(__linux__)
221 > #if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
222   #define DEFINE_NATIVE_OP(ID, FUNC) do {                         \
223                  uintptr base = SheepMem::Reserve(8);            \
224                  WriteMacInt32(base + 0, (uint32)FUNC);          \
# Line 128 | Line 234 | bool ThunksInit(void)
234   #else
235   #error "FIXME: define NativeOp for your platform"
236   #endif
237 +        // FIXME: add GetResource() and friends for completeness
238          DEFINE_NATIVE_OP(NATIVE_PATCH_NAME_REGISTRY, DoPatchNameRegistry);
239          DEFINE_NATIVE_OP(NATIVE_VIDEO_INSTALL_ACCEL, VideoInstallAccel);
240          DEFINE_NATIVE_OP(NATIVE_VIDEO_VBL, VideoVBL);
# Line 147 | Line 254 | bool ThunksInit(void)
254          DEFINE_NATIVE_OP(NATIVE_SERIAL_STATUS, SerialStatus);
255          DEFINE_NATIVE_OP(NATIVE_SERIAL_CLOSE, SerialClose);
256          DEFINE_NATIVE_OP(NATIVE_MAKE_EXECUTABLE, MakeExecutable);
257 +        DEFINE_NATIVE_OP(NATIVE_SYNC_HOOK, NQD_sync_hook);
258 +        DEFINE_NATIVE_OP(NATIVE_BITBLT_HOOK, NQD_bitblt_hook);
259 + //      DEFINE_NATIVE_OP(NATIVE_FILLRECT_HOOK, NQD_fillrect_hook);
260 +        DEFINE_NATIVE_OP(NATIVE_BITBLT, NQD_bitblt);
261 + //      DEFINE_NATIVE_OP(NATIVE_INVRECT, NQD_invrect);
262 + //      DEFINE_NATIVE_OP(NATIVE_FILLRECT_8, NQD_fillrect8);
263 + //      DEFINE_NATIVE_OP(NATIVE_FILLRECT_32, NQD_fillrect32);
264   #undef DEFINE_NATIVE_OP
265   #endif
266  
267 <        // Initialize routine descriptors
268 <        for (int i = 0; i < NATIVE_OP_MAX; i++)
269 <                native_op[i].desc = new SheepRoutineDescriptor(0, NativeTVECT(i));
267 >        // Initialize routine descriptors (if TVECT exists)
268 >        for (int i = 0; i < NATIVE_OP_MAX; i++) {
269 >                uint32 tvect = native_op[i].tvect;
270 >                if (tvect)
271 >                        native_op[i].desc = new SheepRoutineDescriptor(0, tvect);
272 >        }
273  
274          return true;
275   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines