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

Comparing SheepShaver/src/BeOS/main_beos.cpp (file contents):
Revision 1.2 by gbeauche, 2002-04-21T15:07:08Z vs.
Revision 1.13 by gbeauche, 2004-07-03T10:39:05Z

# Line 1 | Line 1
1   /*
2   *  main_beos.cpp - Emulation core, BeOS implementation
3   *
4 < *  SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig
4 > *  SheepShaver (C) 1997-2004 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 88 | Line 88
88   #include "macos_util.h"
89   #include "rom_patches.h"
90   #include "user_strings.h"
91 + #include "thunks.h"
92  
93   #include "sheep_driver.h"
94  
# Line 116 | Line 117 | const char KERNEL_AREA2_NAME[] = "Macint
117   const char RAM_AREA_NAME[] = "Macintosh RAM";
118   const char ROM_AREA_NAME[] = "Macintosh ROM";
119   const char DR_CACHE_AREA_NAME[] = "Macintosh DR Cache";
120 <
121 < const uint32 ROM_AREA_SIZE = 0x500000;          // Size of ROM area
121 <
122 < const uint32 KERNEL_DATA_BASE = 0x68ffe000;     // Address of Kernel Data
123 < const uint32 KERNEL_DATA2_BASE = 0x5fffe000;// Alternate address of Kernel Data
124 < const uint32 KERNEL_AREA_SIZE = 0x2000;         // Size of Kernel Data area
120 > const char DR_EMULATOR_AREA_NAME[] = "Macintosh DR Emulator";
121 > const char SHEEP_AREA_NAME[] = "SheepShaver Virtual Stack";
122  
123   const uint32 SIG_STACK_SIZE = 8192;                     // Size of signal stack
124  
125   const uint32 MSG_START = 'strt';                        // Emulator start message
126  
127  
131 // Emulator Data
132 struct EmulatorData {
133        uint32 v[0x400];        
134 };
135
136
137 // Kernel Data
138 struct KernelData {
139        uint32 v[0x400];
140        EmulatorData ed;
141 };
142
143
128   // Application object
129   class SheepShaver : public BApplication {
130   public:
# Line 159 | Line 143 | public:
143                  // Initialize other variables
144                  sheep_fd = -1;
145                  emulator_data = NULL;
146 <                kernel_area = kernel_area2 = rom_area = ram_area = dr_cache_area = -1;
146 >                kernel_area = kernel_area2 = rom_area = ram_area = dr_cache_area = dr_emulator_area = -1;
147                  emul_thread = nvram_thread = tick_thread = -1;
148                  ReadyForSignals = false;
149                  AllowQuitting = true;
# Line 207 | Line 191 | private:
191          area_id rom_area;               // ROM area ID
192          area_id ram_area;               // RAM area ID
193          area_id dr_cache_area;  // DR Cache area ID
194 +        area_id dr_emulator_area;       // DR Emulator area ID
195  
196          struct sigaction sigusr1_action;        // Interrupt signal (of emulator thread)
197          struct sigaction sigsegv_action;        // Data access exception signal (of emulator thread)
# Line 230 | Line 215 | uint32 RAMSize;                        // Size of Mac RAM
215   uint32 KernelDataAddr;  // Address of Kernel Data
216   uint32 BootGlobsAddr;   // Address of BootGlobs structure at top of Mac RAM
217   uint32 DRCacheAddr;             // Address of DR Cache
218 + uint32 DREmulatorAddr;  // Address of DR Emulator
219   uint32 PVR;                             // Theoretical PVR
220   int64 CPUClockSpeed;    // Processor clock speed (Hz)
221   int64 BusClockSpeed;    // Bus clock speed (Hz)
222 + int64 TimebaseSpeed;    // Timebase clock speed (Hz)
223   system_info SysInfo;    // System information
224  
225   static void *sig_stack = NULL;          // Stack for signal handlers
226   static void *extra_stack = NULL;        // Stack for SIGSEGV inside interrupt handler
227 + uint32  SheepMem::page_size;            // Size of a native page
228 + uintptr SheepMem::zero_page = 0;        // Address of ro page filled in with zeros
229 + uintptr SheepMem::base;                         // Address of SheepShaver data
230 + uintptr SheepMem::top;                          // Top of SheepShaver data (stack like storage)
231 + static area_id SheepMemArea;            // SheepShaver data area ID
232  
233  
234   // Prototypes
# Line 308 | Line 300 | void SheepShaver::ReadyToRun(void)
300          }
301          CPUClockSpeed = SysInfo.cpu_clock_speed;
302          BusClockSpeed = SysInfo.bus_clock_speed;
303 +        TimebaseSpeed = BusClockSpeed / 4;
304  
305          // Delete old areas
306          area_id old_kernel_area = find_area(KERNEL_AREA_NAME);
# Line 325 | Line 318 | void SheepShaver::ReadyToRun(void)
318          area_id old_dr_cache_area = find_area(DR_CACHE_AREA_NAME);
319          if (old_dr_cache_area > 0)
320                  delete_area(old_dr_cache_area);
321 +        area_id old_dr_emulator_area = find_area(DR_EMULATOR_AREA_NAME);
322 +        if (old_dr_emulator_area > 0)
323 +                delete_area(old_dr_emulator_area);
324  
325          // Read preferences
326          int argc = 0;
# Line 372 | Line 368 | void SheepShaver::MessageReceived(BMessa
368   void SheepShaver::StartEmulator(void)
369   {
370          char str[256];
371 +        int16 i16;
372  
373          // Open sheep driver and remap low memory
374          sheep_fd = open("/dev/sheep", 0);
# Line 412 | Line 409 | void SheepShaver::StartEmulator(void)
409          }
410          D(bug("Kernel Data 2 area %ld at %p\n", kernel_area2, kernel_data2));
411  
412 +        // Create area for SheepShaver data
413 +        if (!SheepMem::Init()) {
414 +                sprintf(str, GetString(STR_NO_SHEEP_MEM_AREA_ERR), strerror(SheepMemArea), SheepMemArea);
415 +                ErrorAlert(str);
416 +                PostMessage(B_QUIT_REQUESTED);
417 +                return;
418 +        }
419 +        
420          // Create area for Mac RAM
421          RAMSize = PrefsFindInt32("ramsize") & 0xfff00000;       // Round down to 1MB boundary
422          if (RAMSize < 8*1024*1024) {
# Line 461 | Line 466 | void SheepShaver::StartEmulator(void)
466          }
467          D(bug("DR Cache area %ld at %p\n", dr_cache_area, DRCacheAddr));
468  
469 +        // Create area for DR Emulator
470 +        DREmulatorAddr = DR_EMULATOR_BASE;
471 +        dr_emulator_area = create_area(DR_EMULATOR_AREA_NAME, (void **)&DREmulatorAddr, B_EXACT_ADDRESS, DR_EMULATOR_SIZE, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
472 +        if (dr_emulator_area < 0) {
473 +                sprintf(str, GetString(STR_NO_KERNEL_DATA_ERR), strerror(dr_emulator_area), dr_emulator_area);
474 +                ErrorAlert(str);
475 +                PostMessage(B_QUIT_REQUESTED);
476 +                return;
477 +        }
478 +        D(bug("DR Emulator area %ld at %p\n", dr_emulator_area, DREmulatorAddr));
479 +
480          // Load NVRAM
481          XPRAMInit();
482  
483          // Set boot volume
484 <        drive = PrefsFindInt32("bootdrive");
484 >        i16 = PrefsFindInt32("bootdrive");
485          XPRAM[0x1378] = i16 >> 8;
486          XPRAM[0x1379] = i16 & 0xff;
487 <        driver = PrefsFindInt32("bootdriver");
487 >        i16 = PrefsFindInt32("bootdriver");
488          XPRAM[0x137a] = i16 >> 8;
489          XPRAM[0x137b] = i16 & 0xff;
490  
# Line 481 | Line 497 | void SheepShaver::StartEmulator(void)
497          boot_globs[1] = htonl(RAMSize);
498          boot_globs[2] = htonl((uint32)-1);                              // End of bank table
499  
500 +        // Init thunks
501 +        if (!InitThunks()) {
502 +                PostMessage(B_QUIT_REQUESTED);
503 +                return;
504 +        }
505 +
506          // Init drivers
507          SonyInit();
508          DiskInit();
# Line 577 | Line 599 | void SheepShaver::StartEmulator(void)
599          WriteMacInt32(XLM_PVR, PVR);                                                                    // Theoretical PVR
600          WriteMacInt32(XLM_BUS_CLOCK, BusClockSpeed);                                    // For DriverServicesLib patch
601          WriteMacInt16(XLM_EXEC_RETURN_OPCODE, M68K_EXEC_RETURN);                // For Execute68k() (RTS from the executed 68k code will jump here and end 68k mode)
602 +        WriteMacInt32(XLM_ZERO_PAGE, SheepMem::ZeroPage());                             // Pointer to read-only page with all bits set to 0
603   #if !EMULATED_PPC
604          WriteMacInt32(XLM_TOC, (uint32)TOC);                                                    // TOC pointer of emulator
605          WriteMacInt32(XLM_ETHER_INIT, *(uint32 *)InitStreamModule);             // DLPI ethernet driver functions
# Line 673 | Line 696 | void SheepShaver::Quit(void)
696          DiskExit();
697          SonyExit();
698  
699 +        // Delete thunks
700 +        ThunksExit();
701 +
702 +        // Delete SheepShaver globals
703 +        SheepMem::Exit();
704 +
705 +        // Delete DR Emulator area
706 +        if (dr_emulator_area >= 0)
707 +                delete_area(dr_emulator_area);
708 +
709          // Delete DR Cache area
710          if (dr_cache_area >= 0)
711                  delete_area(dr_cache_area);
# Line 717 | Line 750 | void SheepShaver::Quit(void)
750  
751   void SheepShaver::init_rom(void)
752   {
753 +        // Size of a native page
754 +        page_size = B_PAGE_SIZE;
755 +
756          // Create area for ROM
757          void *rom_addr = (void *)ROM_BASE;
758          rom_area = create_area(ROM_AREA_NAME, &rom_addr, B_EXACT_ADDRESS, ROM_AREA_SIZE, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
# Line 1261 | Line 1297 | void Execute68kTrap(uint16 trap, M68kReg
1297  
1298  
1299   /*
1264 *  Execute PPC code from EMUL_OP routine (real mode switch)
1265 */
1266
1267 void ExecutePPC(void (*func)())
1268 {
1269        RoutineDescriptor desc = BUILD_PPC_ROUTINE_DESCRIPTOR(0, func);
1270        M68kRegisters r;
1271        Execute68k((uint32)&desc, &r);
1272 }
1273
1274
1275 /*
1300   *  Quit emulator (must only be called from main thread)
1301   */
1302  
# Line 1327 | Line 1351 | void MakeExecutable(int dummy, void *sta
1351  
1352   void PatchAfterStartup(void)
1353   {
1354 <        ExecutePPC(VideoInstallAccel);
1354 >        ExecuteNative(NATIVE_VIDEO_INSTALL_ACCEL);
1355          InstallExtFS();
1356   }
1357  
# Line 1336 | Line 1360 | void PatchAfterStartup(void)
1360   *  NVRAM watchdog thread (saves NVRAM every minute)
1361   */
1362  
1363 < static status_t SheepShaver::nvram_func(void *arg)
1363 > status_t SheepShaver::nvram_func(void *arg)
1364   {
1365          SheepShaver *obj = (SheepShaver *)arg;
1366  
# Line 1575 | Line 1599 | void SheepShaver::sigusr1_handler(vregs
1599                                          if (InterruptFlags & INTFLAG_VIA) {
1600                                                  ClearInterruptFlag(INTFLAG_VIA);
1601                                                  ADBInterrupt();
1602 <                                                ExecutePPC(VideoVBL);
1602 >                                                ExecuteNative(NATIVE_VIDEO_VBL);
1603                                          }
1604                                  }
1605   #endif
# Line 2070 | Line 2094 | rti:
2094   }
2095  
2096  
2097 + /*
2098 + *  Helpers to share 32-bit addressable data with MacOS
2099 + */
2100 +
2101 + bool SheepMem::Init(void)
2102 + {
2103 +        // Delete old area
2104 +        area_id old_sheep_area = find_area(SHEEP_AREA_NAME);
2105 +        if (old_sheep_area > 0)
2106 +                delete_area(old_sheep_area);
2107 +
2108 +        // Create area for SheepShaver data
2109 +        base = 0x60000000;
2110 +        SheepMemArea = create_area(SHEEP_AREA_NAME, (void **)&base, B_BASE_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
2111 +        if (SheepMemArea < 0)
2112 +                return false;
2113 +
2114 +        // Create read-only area with all bits set to 0
2115 +        static const uint8 const_zero_page[4096] = {0,};
2116 +        zero_page = const_zero_page;
2117 +
2118 +        D(bug("SheepShaver area %ld at %p\n", SheepMemArea, base));
2119 +        top = base + size;
2120 +        return true;
2121 + }
2122 +
2123 + void SheepMem::Exit(void)
2124 + {
2125 +        if (SheepMemArea >= 0)
2126 +                delete_area(SheepMemArea);
2127 + }
2128 +
2129 +
2130   /*
2131   *  Display error alert
2132   */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines