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.14 by gbeauche, 2004-11-13T14:09:15Z vs.
Revision 1.18 by gbeauche, 2005-06-30T10:17:58Z

# Line 1 | Line 1
1   /*
2   *  main_beos.cpp - Emulation core, BeOS implementation
3   *
4 < *  SheepShaver (C) 1997-2004 Christian Bauer and Marc Hellwig
4 > *  SheepShaver (C) 1997-2005 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 74 | Line 74
74   #include "xpram.h"
75   #include "timer.h"
76   #include "adb.h"
77 #include "sony.h"
78 #include "disk.h"
79 #include "cdrom.h"
80 #include "scsi.h"
77   #include "video.h"
82 #include "audio.h"
83 #include "ether.h"
84 #include "serial.h"
85 #include "clip.h"
86 #include "extfs.h"
78   #include "sys.h"
79   #include "macos_util.h"
80   #include "rom_patches.h"
81   #include "user_strings.h"
91 #include "thunks.h"
82  
83   #include "sheep_driver.h"
84  
# Line 229 | Line 219 | static void *extra_stack = NULL;       // Stac
219   uint32  SheepMem::page_size;            // Size of a native page
220   uintptr SheepMem::zero_page = 0;        // Address of ro page filled in with zeros
221   uintptr SheepMem::base;                         // Address of SheepShaver data
222 < uintptr SheepMem::top;                          // Top of SheepShaver data (stack like storage)
222 > uintptr SheepMem::proc;                         // Bottom address of SheepShave procedures
223 > uintptr SheepMem::data;                         // Top of SheepShaver data (stack like storage)
224   static area_id SheepMemArea;            // SheepShaver data area ID
225  
226  
# Line 370 | Line 361 | void SheepShaver::MessageReceived(BMessa
361   void SheepShaver::StartEmulator(void)
362   {
363          char str[256];
373        int16 i16;
364  
365          // Open sheep driver and remap low memory
366          sheep_fd = open("/dev/sheep", 0);
# Line 480 | Line 470 | void SheepShaver::StartEmulator(void)
470          }
471          D(bug("DR Emulator area %ld at %p\n", dr_emulator_area, DREmulatorAddr));
472  
473 <        // Load NVRAM
474 <        XPRAMInit();
485 <
486 <        // Set boot volume
487 <        i16 = PrefsFindInt32("bootdrive");
488 <        XPRAM[0x1378] = i16 >> 8;
489 <        XPRAM[0x1379] = i16 & 0xff;
490 <        i16 = PrefsFindInt32("bootdriver");
491 <        XPRAM[0x137a] = i16 >> 8;
492 <        XPRAM[0x137b] = i16 & 0xff;
493 <
494 <        // Create BootGlobs at top of Mac memory
495 <        memset((void *)(RAMBase + RAMSize - 4096), 0, 4096);
496 <        BootGlobsAddr = RAMBase + RAMSize - 0x1c;
497 <        uint32 *boot_globs = (uint32 *)BootGlobsAddr;
498 <        boot_globs[-5] = htonl(RAMBase + RAMSize);              // MemTop
499 <        boot_globs[0] = htonl(RAMBase);                                 // First RAM bank
500 <        boot_globs[1] = htonl(RAMSize);
501 <        boot_globs[2] = htonl((uint32)-1);                              // End of bank table
502 <
503 <        // Init thunks
504 <        if (!InitThunks()) {
505 <                PostMessage(B_QUIT_REQUESTED);
506 <                return;
507 <        }
508 <
509 <        // Init drivers
510 <        SonyInit();
511 <        DiskInit();
512 <        CDROMInit();
513 <        SCSIInit();
514 <
515 <        // Init external file system
516 <        ExtFSInit();
517 <
518 <        // Init audio
519 <        AudioInit();
520 <
521 <        // Init network
522 <        EtherInit();
523 <
524 <        // Init serial ports
525 <        SerialInit();
526 <
527 <        // Init Time Manager
528 <        TimerInit();
529 <
530 <        // Init clipboard
531 <        ClipInit();
532 <
533 <        // Init video
534 <        if (!VideoInit()) {
535 <                PostMessage(B_QUIT_REQUESTED);
536 <                return;
537 <        }
538 <
539 <        // Install ROM patches
540 <        if (!PatchROM()) {
541 <                ErrorAlert(GetString(STR_UNSUPPORTED_ROM_TYPE_ERR));
473 >        // Initialize everything
474 >        if (!InitAll()) {
475                  PostMessage(B_QUIT_REQUESTED);
476                  return;
477          }
478 +        D(bug("Initialization complete\n"));
479  
480          // Clear caches (as we loaded and patched code) and write protect ROM
481   #if !EMULATED_PPC
# Line 549 | Line 483 | void SheepShaver::StartEmulator(void)
483   #endif
484          set_area_protection(rom_area, B_READ_AREA);
485  
552        // Initialize Kernel Data
553        memset(kernel_data, 0, sizeof(KernelData));
554        if (ROMType == ROMTYPE_NEWWORLD) {
555                static uint32 of_dev_tree[4] = {0, 0, 0, 0};
556                static uint8 vector_lookup_tbl[128];
557                static uint8 vector_mask_tbl[64];
558                memset((uint8 *)kernel_data + 0xb80, 0x3d, 0x80);
559                memset(vector_lookup_tbl, 0, 128);
560                memset(vector_mask_tbl, 0, 64);
561                kernel_data->v[0xb80 >> 2] = htonl(ROM_BASE);
562                kernel_data->v[0xb84 >> 2] = htonl((uint32)of_dev_tree);        // OF device tree base
563                kernel_data->v[0xb90 >> 2] = htonl((uint32)vector_lookup_tbl);
564                kernel_data->v[0xb94 >> 2] = htonl((uint32)vector_mask_tbl);
565                kernel_data->v[0xb98 >> 2] = htonl(ROM_BASE);                           // OpenPIC base
566                kernel_data->v[0xbb0 >> 2] = htonl(0);                                          // ADB base
567                kernel_data->v[0xc20 >> 2] = htonl(RAMSize);
568                kernel_data->v[0xc24 >> 2] = htonl(RAMSize);
569                kernel_data->v[0xc30 >> 2] = htonl(RAMSize);
570                kernel_data->v[0xc34 >> 2] = htonl(RAMSize);
571                kernel_data->v[0xc38 >> 2] = htonl(0x00010020);
572                kernel_data->v[0xc3c >> 2] = htonl(0x00200001);
573                kernel_data->v[0xc40 >> 2] = htonl(0x00010000);
574                kernel_data->v[0xc50 >> 2] = htonl(RAMBase);
575                kernel_data->v[0xc54 >> 2] = htonl(RAMSize);
576                kernel_data->v[0xf60 >> 2] = htonl(PVR);
577                kernel_data->v[0xf64 >> 2] = htonl(CPUClockSpeed);
578                kernel_data->v[0xf68 >> 2] = htonl(BusClockSpeed);
579                kernel_data->v[0xf6c >> 2] = htonl(CPUClockSpeed);
580        } else {
581                kernel_data->v[0xc80 >> 2] = htonl(RAMSize);
582                kernel_data->v[0xc84 >> 2] = htonl(RAMSize);
583                kernel_data->v[0xc90 >> 2] = htonl(RAMSize);
584                kernel_data->v[0xc94 >> 2] = htonl(RAMSize);
585                kernel_data->v[0xc98 >> 2] = htonl(0x00010020);
586                kernel_data->v[0xc9c >> 2] = htonl(0x00200001);
587                kernel_data->v[0xca0 >> 2] = htonl(0x00010000);
588                kernel_data->v[0xcb0 >> 2] = htonl(RAMBase);
589                kernel_data->v[0xcb4 >> 2] = htonl(RAMSize);
590                kernel_data->v[0xf80 >> 2] = htonl(PVR);
591                kernel_data->v[0xf84 >> 2] = htonl(CPUClockSpeed);
592                kernel_data->v[0xf88 >> 2] = htonl(BusClockSpeed);
593                kernel_data->v[0xf8c >> 2] = htonl(CPUClockSpeed);
594        }
595
486          // Initialize extra low memory
487 <        D(bug("Initializing Low Memory...\n"));
598 <        memset(NULL, 0, 0x3000);
599 <        WriteMacInt32(XLM_SIGNATURE, 'Baah');                                                   // Signature to detect SheepShaver
600 <        WriteMacInt32(XLM_KERNEL_DATA, (uint32)kernel_data);                    // For trap replacement routines
487 >        D(bug("Initializing extra Low Memory...\n"));
488          WriteMacInt32(XLM_SHEEP_OBJ, (uint32)this);                                             // Pointer to SheepShaver object
489 <        WriteMacInt32(XLM_PVR, PVR);                                                                    // Theoretical PVR
603 <        WriteMacInt32(XLM_BUS_CLOCK, BusClockSpeed);                                    // For DriverServicesLib patch
604 <        WriteMacInt16(XLM_EXEC_RETURN_OPCODE, M68K_EXEC_RETURN);                // For Execute68k() (RTS from the executed 68k code will jump here and end 68k mode)
605 <        WriteMacInt32(XLM_ZERO_PAGE, SheepMem::ZeroPage());                             // Pointer to read-only page with all bits set to 0
606 < #if !EMULATED_PPC
607 <        WriteMacInt32(XLM_TOC, (uint32)TOC);                                                    // TOC pointer of emulator
608 <        WriteMacInt32(XLM_ETHER_INIT, *(uint32 *)InitStreamModule);             // DLPI ethernet driver functions
609 <        WriteMacInt32(XLM_ETHER_TERM, *(uint32 *)TerminateStreamModule);
610 <        WriteMacInt32(XLM_ETHER_OPEN, *(uint32 *)ether_open);
611 <        WriteMacInt32(XLM_ETHER_CLOSE, *(uint32 *)ether_close);
612 <        WriteMacInt32(XLM_ETHER_WPUT, *(uint32 *)ether_wput);
613 <        WriteMacInt32(XLM_ETHER_RSRV, *(uint32 *)ether_rsrv);
614 <        WriteMacInt32(XLM_VIDEO_DOIO, *(uint32 *)VideoDoDriverIO);
615 < #endif
616 <        D(bug("Low Memory initialized\n"));
489 >        D(bug("Extra Low Memory initialized\n"));
490  
491          // Disallow quitting with Alt-Q from now on
492          AllowQuitting = false;
# Line 669 | Line 542 | void SheepShaver::Quit(void)
542          if (emul_thread > 0)
543                  wait_for_thread(emul_thread, &l);
544  
545 <        // Save NVRAM
546 <        XPRAMExit();
674 <
675 <        // Exit clipboard
676 <        ClipExit();
677 <
678 <        // Exit Time Manager
679 <        TimerExit();
680 <
681 <        // Exit serial
682 <        SerialExit();
683 <
684 <        // Exit network
685 <        EtherExit();
686 <
687 <        // Exit audio
688 <        AudioExit();
689 <
690 <        // Exit video
691 <        VideoExit();
692 <
693 <        // Exit external file system
694 <        ExtFSExit();
695 <
696 <        // Exit drivers
697 <        SCSIExit();
698 <        CDROMExit();
699 <        DiskExit();
700 <        SonyExit();
701 <
702 <        // Delete thunks
703 <        ThunksExit();
545 >        // Deinitialize everything
546 >        ExitAll();
547  
548          // Delete SheepShaver globals
549          SheepMem::Exit();
# Line 1349 | Line 1192 | void MakeExecutable(int dummy, uint32 st
1192  
1193  
1194   /*
1352 *  Patch things after system startup (gets called by disk driver accRun routine)
1353 */
1354
1355 void PatchAfterStartup(void)
1356 {
1357        ExecuteNative(NATIVE_VIDEO_INSTALL_ACCEL);
1358        InstallExtFS();
1359 }
1360
1361
1362 /*
1195   *  NVRAM watchdog thread (saves NVRAM every minute)
1196   */
1197  
# Line 1416 | Line 1248 | status_t SheepShaver::tick_func(void *ar
1248  
1249   void TriggerInterrupt(void)
1250   {
1251 +        idle_resume();
1252   #if 0
1253          WriteMacInt32(0x16a, ReadMacInt32(0x16a) + 1);
1254   #else
# Line 2109 | Line 1942 | bool SheepMem::Init(void)
1942                  delete_area(old_sheep_area);
1943  
1944          // Create area for SheepShaver data
1945 <        base = 0x60000000;
1945 >        proc = base = 0x60000000;
1946          SheepMemArea = create_area(SHEEP_AREA_NAME, (void **)&base, B_BASE_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
1947          if (SheepMemArea < 0)
1948                  return false;
# Line 2119 | Line 1952 | bool SheepMem::Init(void)
1952          zero_page = const_zero_page;
1953  
1954          D(bug("SheepShaver area %ld at %p\n", SheepMemArea, base));
1955 <        top = base + size;
1955 >        data = base + size;
1956          return true;
1957   }
1958  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines