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

Comparing SheepShaver/src/emul_op.cpp (file contents):
Revision 1.4 by gbeauche, 2003-10-26T08:48:48Z vs.
Revision 1.24 by asvitkine, 2009-08-18T18:26:10Z

# Line 1 | Line 1
1   /*
2   *  emul_op.cpp - 68k opcodes for ROM patches
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
# Line 45 | Line 45
45   #include "name_registry.h"
46   #include "user_strings.h"
47   #include "emul_op.h"
48 + #include "thunks.h"
49  
50   #define DEBUG 0
51   #include "debug.h"
52  
53  
53 #if __BEOS__
54 #define PRECISE_TIMING 1
55 #else
56 #define PRECISE_TIMING 0
57 #endif
58
59
54   // TVector of MakeExecutable
55 < static uint32 *MakeExecutableTvec;
55 > static uint32 MakeExecutableTvec;
56  
57  
58   /*
# Line 258 | Line 252 | void EmulOp(M68kRegisters *r, uint32 pc,
252                          InstallDrivers();
253  
254                          // Patch MakeExecutable()
255 <                        MakeExecutableTvec = (uint32 *)FindLibSymbol("\023PrivateInterfaceLib", "\016MakeExecutable");
256 <                        D(bug("MakeExecutable TVECT at %p\n", MakeExecutableTvec));
257 < #if EMULATED_PPC
258 <                        MakeExecutableTvec[0] = htonl(POWERPC_NATIVE_OP_FUNC(NATIVE_MAKE_EXECUTABLE));
259 < #else
266 < #ifdef __BEOS__
267 <                        MakeExecutableTvec[0] = ((uint32 *)MakeExecutable)[0];
268 < #else
269 <                        MakeExecutableTvec[0] = (uint32)MakeExecutable;
270 < #endif
271 <                        MakeExecutableTvec[1] = (uint32)TOC;
255 >                        MakeExecutableTvec = FindLibSymbol("\023PrivateInterfaceLib", "\016MakeExecutable");
256 >                        D(bug("MakeExecutable TVECT at %08x\n", MakeExecutableTvec));
257 >                        WriteMacInt32(MakeExecutableTvec, NativeFunction(NATIVE_MAKE_EXECUTABLE));
258 > #if !EMULATED_PPC
259 >                        WriteMacInt32(MakeExecutableTvec + 4, (uint32)TOC);
260   #endif
261  
262                          // Patch DebugStr()
263 <                        static const uint8 proc[] = {
264 <                                M68K_EMUL_OP_DEBUG_STR >> 8, M68K_EMUL_OP_DEBUG_STR & 0xff,
263 >                        static const uint8 proc_template[] = {
264 >                                M68K_EMUL_OP_DEBUG_STR >> 8, M68K_EMUL_OP_DEBUG_STR,
265                                  0x4e, 0x74,                     // rtd  #4
266                                  0x00, 0x04
267                          };
268 <                        WriteMacInt32(0x1dfc, (uint32)proc);
268 >                        BUILD_SHEEPSHAVER_PROCEDURE(proc);
269 >                        WriteMacInt32(0x1dfc, proc);
270                          break;
271                  }
272  
# Line 292 | Line 281 | void EmulOp(M68kRegisters *r, uint32 pc,
281                          TimerReset();
282                          MacOSUtilReset();
283                          AudioReset();
284 < #if 0
285 <                        printf("DR activated\n");
286 <                        WriteMacInt32(KernelDataAddr + 0x17a0, 3);              // Prepare for DR emulator activation
287 <                        WriteMacInt32(KernelDataAddr + 0x17c0, DR_CACHE_BASE);
288 <                        WriteMacInt32(KernelDataAddr + 0x17c4, DR_CACHE_SIZE);
289 <                        WriteMacInt32(KernelDataAddr + 0x1b00, DR_CACHE_BASE + 0x10000);
290 <                        memcpy((void *)(DR_CACHE_BASE + 0x10000), (void *)(ROM_BASE + 0x370000), 0x10000);
291 <                        clear_caches((void *)(DR_CACHE_BASE + 0x10000), 0x10000, B_INVALIDATE_ICACHE | B_FLUSH_DCACHE);
292 < #endif
284 >
285 >                        // Enable DR emulator (disabled for now)
286 >                        if (PrefsFindBool("jit68k") && 0) {
287 >                                D(bug("DR activated\n"));
288 >                                WriteMacInt32(KernelDataAddr + 0x17a0, 3);              // Prepare for DR emulator activation
289 >                                WriteMacInt32(KernelDataAddr + 0x17c0, DR_CACHE_BASE);
290 >                                WriteMacInt32(KernelDataAddr + 0x17c4, DR_CACHE_SIZE);
291 >                                WriteMacInt32(KernelDataAddr + 0x1b04, DR_CACHE_BASE);
292 >                                WriteMacInt32(KernelDataAddr + 0x1b00, DR_EMULATOR_BASE);
293 >                                memcpy((void *)DR_EMULATOR_BASE, (void *)(ROMBase + 0x370000), DR_EMULATOR_SIZE);
294 >                                MakeExecutable(0, DR_EMULATOR_BASE, DR_EMULATOR_SIZE);
295 >                        }
296                          break;
297  
298                  case OP_IRQ:                    // Level 1 interrupt
# Line 312 | Line 304 | void EmulOp(M68kRegisters *r, uint32 pc,
304   #if !PRECISE_TIMING
305                                          TimerInterrupt();
306   #endif
315 #if EMULATED_PPC
307                                          ExecuteNative(NATIVE_VIDEO_VBL);
317 #else
318                                        ExecutePPC(VideoVBL);
319 #endif
308  
309                                          static int tick_counter = 0;
310                                          if (++tick_counter >= 60) {
# Line 334 | Line 322 | void EmulOp(M68kRegisters *r, uint32 pc,
322                                  }
323                                  if (InterruptFlags & INTFLAG_ETHER) {
324                                          ClearInterruptFlag(INTFLAG_ETHER);
337 #if EMULATED_PPC
325                                          ExecuteNative(NATIVE_ETHER_IRQ);
339 #else
340                                        ExecutePPC(EtherIRQ);
341 #endif
326                                  }
327                                  if (InterruptFlags & INTFLAG_TIMER) {
328                                          ClearInterruptFlag(INTFLAG_TIMER);
# Line 425 | Line 409 | void EmulOp(M68kRegisters *r, uint32 pc,
409                          r->d[0] = (uint32)-7887;
410                          break;
411  
412 +                case OP_CHECK_SYSV: {           // Check we are not using MacOS < 8.1 with a NewWorld ROM
413 +                        r->a[1] = r->d[1];
414 +                        r->a[0] = ReadMacInt32(r->d[1]);
415 +                        uint32 sysv = ReadMacInt16(r->a[0]);
416 +                        D(bug("Detected MacOS version %d.%d.%d\n", (sysv >> 8) & 0xf, (sysv >> 4) & 0xf, sysv & 0xf));
417 +                        if (ROMType == ROMTYPE_NEWWORLD && sysv < 0x0801)
418 +                                r->d[1] = 0;
419 +                        break;
420 +                }
421 +
422                  case OP_NTRB_17_PATCH:
423                          r->a[2] = ReadMacInt32(r->a[7]);
424                          r->a[7] += 4;
# Line 445 | Line 439 | void EmulOp(M68kRegisters *r, uint32 pc,
439                                  PatchNativeResourceManager();
440                          break;
441  
442 +                case OP_NTRB_17_PATCH4:
443 +                        r->d[0] = ReadMacInt16(r->a[7]);
444 +                        r->a[7] += 2;
445 +                        D(bug("%d %d\n", ReadMacInt16(r->a[2]), ReadMacInt16(r->a[2] + 6)));
446 +                        if (ReadMacInt16(r->a[2]) == 11 && ReadMacInt16(r->a[2] + 6) == 17)
447 +                                PatchNativeResourceManager();
448 +                        break;
449 +
450                  case OP_CHECKLOAD: {            // vCheckLoad() patch
451                          uint32 type = ReadMacInt32(r->a[7]);
452                          r->a[7] += 4;
# Line 469 | Line 471 | void EmulOp(M68kRegisters *r, uint32 pc,
471                          break;
472  
473                  case OP_IDLE_TIME:
472 #if __BEOS__
474                          // Sleep if no events pending
475 <                        if (ReadMacInt32(0x14c) == 0) {
476 <                                sleep(16667);
476 <                        }
477 < #endif
475 >                        if (ReadMacInt32(0x14c) == 0)
476 >                                idle_wait();
477                          r->a[0] = ReadMacInt32(0x2b6);
478                          break;
479  
480 +                case OP_IDLE_TIME_2:
481 +                        // Sleep if no events pending
482 +                        if (ReadMacInt32(0x14c) == 0)
483 +                                idle_wait();
484 +                        r->d[0] = (uint32)-2;
485 +                        break;
486 +
487                  default:
488                          printf("FATAL: EMUL_OP called with bogus selector %08x\n", selector);
489                          QuitEmulator();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines