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.10 by cebix, 2004-01-12T15:37:19Z

# 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 <
120 < 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 SHEEP_AREA_NAME[] = "SheepShaver Virtual Stack";
121  
122   const uint32 SIG_STACK_SIZE = 8192;                     // Size of signal stack
123  
124   const uint32 MSG_START = 'strt';                        // Emulator start message
125  
126  
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
127   // Application object
128   class SheepShaver : public BApplication {
129   public:
# Line 237 | Line 220 | system_info SysInfo;   // System informati
220  
221   static void *sig_stack = NULL;          // Stack for signal handlers
222   static void *extra_stack = NULL;        // Stack for SIGSEGV inside interrupt handler
223 + uintptr SheepMem::zero_page = 0;        // Address of ro page filled in with zeros
224 + uintptr SheepMem::base;                         // Address of SheepShaver data
225 + uintptr SheepMem::top;                          // Top of SheepShaver data (stack like storage)
226 + static area_id SheepMemArea;            // SheepShaver data area ID
227  
228  
229   // Prototypes
# Line 372 | Line 359 | void SheepShaver::MessageReceived(BMessa
359   void SheepShaver::StartEmulator(void)
360   {
361          char str[256];
362 +        int16 i16;
363  
364          // Open sheep driver and remap low memory
365          sheep_fd = open("/dev/sheep", 0);
# Line 412 | Line 400 | void SheepShaver::StartEmulator(void)
400          }
401          D(bug("Kernel Data 2 area %ld at %p\n", kernel_area2, kernel_data2));
402  
403 +        // Create area for SheepShaver data
404 +        if (!SheepMem::Init()) {
405 +                sprintf(str, GetString(STR_NO_SHEEP_MEM_AREA_ERR));
406 +                ErrorAlert(str);
407 +                PostMessage(B_QUIT_REQUESTED);
408 +                return;
409 +        }
410 +        
411          // Create area for Mac RAM
412          RAMSize = PrefsFindInt32("ramsize") & 0xfff00000;       // Round down to 1MB boundary
413          if (RAMSize < 8*1024*1024) {
# Line 465 | Line 461 | void SheepShaver::StartEmulator(void)
461          XPRAMInit();
462  
463          // Set boot volume
464 <        drive = PrefsFindInt32("bootdrive");
464 >        i16 = PrefsFindInt32("bootdrive");
465          XPRAM[0x1378] = i16 >> 8;
466          XPRAM[0x1379] = i16 & 0xff;
467 <        driver = PrefsFindInt32("bootdriver");
467 >        i16 = PrefsFindInt32("bootdriver");
468          XPRAM[0x137a] = i16 >> 8;
469          XPRAM[0x137b] = i16 & 0xff;
470  
# Line 481 | Line 477 | void SheepShaver::StartEmulator(void)
477          boot_globs[1] = htonl(RAMSize);
478          boot_globs[2] = htonl((uint32)-1);                              // End of bank table
479  
480 +        // Init thunks
481 +        if (!InitThunks()) {
482 +                PostMessage(B_QUIT_REQUESTED);
483 +                return;
484 +        }
485 +
486          // Init drivers
487          SonyInit();
488          DiskInit();
# Line 577 | Line 579 | void SheepShaver::StartEmulator(void)
579          WriteMacInt32(XLM_PVR, PVR);                                                                    // Theoretical PVR
580          WriteMacInt32(XLM_BUS_CLOCK, BusClockSpeed);                                    // For DriverServicesLib patch
581          WriteMacInt16(XLM_EXEC_RETURN_OPCODE, M68K_EXEC_RETURN);                // For Execute68k() (RTS from the executed 68k code will jump here and end 68k mode)
582 +        WriteMacInt32(XLM_ZERO_PAGE, SheepMem::ZeroPage());                             // Pointer to read-only page with all bits set to 0
583   #if !EMULATED_PPC
584          WriteMacInt32(XLM_TOC, (uint32)TOC);                                                    // TOC pointer of emulator
585          WriteMacInt32(XLM_ETHER_INIT, *(uint32 *)InitStreamModule);             // DLPI ethernet driver functions
# Line 673 | Line 676 | void SheepShaver::Quit(void)
676          DiskExit();
677          SonyExit();
678  
679 +        // Delete thunks
680 +        ThunksExit();
681 +
682 +        // Delete SheepShaver globals
683 +        SheepMem::Exit();
684 +
685          // Delete DR Cache area
686          if (dr_cache_area >= 0)
687                  delete_area(dr_cache_area);
# Line 1261 | Line 1270 | void Execute68kTrap(uint16 trap, M68kReg
1270  
1271  
1272   /*
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 /*
1273   *  Quit emulator (must only be called from main thread)
1274   */
1275  
# Line 1327 | Line 1324 | void MakeExecutable(int dummy, void *sta
1324  
1325   void PatchAfterStartup(void)
1326   {
1327 <        ExecutePPC(VideoInstallAccel);
1327 >        ExecuteNative(NATIVE_VIDEO_INSTALL_ACCEL);
1328          InstallExtFS();
1329   }
1330  
# Line 1336 | Line 1333 | void PatchAfterStartup(void)
1333   *  NVRAM watchdog thread (saves NVRAM every minute)
1334   */
1335  
1336 < static status_t SheepShaver::nvram_func(void *arg)
1336 > status_t SheepShaver::nvram_func(void *arg)
1337   {
1338          SheepShaver *obj = (SheepShaver *)arg;
1339  
# Line 1575 | Line 1572 | void SheepShaver::sigusr1_handler(vregs
1572                                          if (InterruptFlags & INTFLAG_VIA) {
1573                                                  ClearInterruptFlag(INTFLAG_VIA);
1574                                                  ADBInterrupt();
1575 <                                                ExecutePPC(VideoVBL);
1575 >                                                ExecuteNative(NATIVE_VIDEO_VBL);
1576                                          }
1577                                  }
1578   #endif
# Line 2070 | Line 2067 | rti:
2067   }
2068  
2069  
2070 + /*
2071 + *  Helpers to share 32-bit addressable data with MacOS
2072 + */
2073 +
2074 + bool SheepMem::Init(void)
2075 + {
2076 +        // Delete old area
2077 +        area_id old_sheep_area = find_area(SHEEP_AREA_NAME);
2078 +        if (old_sheep_area > 0)
2079 +                delete_area(old_sheep_area);
2080 +
2081 +        // Create area for SheepShaver data
2082 +        base = 0x60000000;
2083 +        SheepMemArea = create_area(SHEEP_AREA_NAME, (void **)&base, B_BASE_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
2084 +        if (SheepMemArea < 0)
2085 +                return false;
2086 +
2087 +        // Create read-only area with all bits set to 0
2088 +        static const uint8 const_zero_page[4096] = {0,};
2089 +        zero_page = const_zero_page;
2090 +
2091 +        D(bug("SheepShaver area %ld at %p\n", SheepMemArea, base));
2092 +        top = base + size;
2093 +        return true;
2094 + }
2095 +
2096 + void SheepMem::Exit(void)
2097 + {
2098 +        if (SheepMemArea >= 0)
2099 +                delete_area(SheepMemArea);
2100 + }
2101 +
2102 +
2103   /*
2104   *  Display error alert
2105   */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines