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 |
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 |
|
|
209 |
|
uint32 PVR; // Theoretical PVR |
210 |
|
int64 CPUClockSpeed; // Processor clock speed (Hz) |
211 |
|
int64 BusClockSpeed; // Bus clock speed (Hz) |
212 |
+ |
int64 TimebaseSpeed; // Timebase clock speed (Hz) |
213 |
|
system_info SysInfo; // System information |
214 |
+ |
uint8 *RAMBaseHost; // Base address of Mac RAM (host address space) |
215 |
+ |
uint8 *ROMBaseHost; // Base address of Mac ROM (host address space) |
216 |
|
|
217 |
|
static void *sig_stack = NULL; // Stack for signal handlers |
218 |
|
static void *extra_stack = NULL; // Stack for SIGSEGV inside interrupt handler |
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 |
|
|
293 |
|
} |
294 |
|
CPUClockSpeed = SysInfo.cpu_clock_speed; |
295 |
|
BusClockSpeed = SysInfo.bus_clock_speed; |
296 |
+ |
TimebaseSpeed = BusClockSpeed / 4; |
297 |
|
|
298 |
|
// Delete old areas |
299 |
|
area_id old_kernel_area = find_area(KERNEL_AREA_NAME); |
361 |
|
void SheepShaver::StartEmulator(void) |
362 |
|
{ |
363 |
|
char str[256]; |
369 |
– |
int16 i16; |
364 |
|
|
365 |
|
// Open sheep driver and remap low memory |
366 |
|
sheep_fd = open("/dev/sheep", 0); |
424 |
|
PostMessage(B_QUIT_REQUESTED); |
425 |
|
return; |
426 |
|
} |
427 |
< |
D(bug("RAM area %ld at %p\n", ram_area, RAMBase)); |
427 |
> |
RAMBaseHost = (uint8 *)RAMBase |
428 |
> |
D(bug("RAM area %ld at %p\n", ram_area, RAMBaseHost)); |
429 |
|
|
430 |
|
// Create area and load Mac ROM |
431 |
|
try { |
470 |
|
} |
471 |
|
D(bug("DR Emulator area %ld at %p\n", dr_emulator_area, DREmulatorAddr)); |
472 |
|
|
473 |
< |
// Load NVRAM |
474 |
< |
XPRAMInit(); |
480 |
< |
|
481 |
< |
// Set boot volume |
482 |
< |
i16 = PrefsFindInt32("bootdrive"); |
483 |
< |
XPRAM[0x1378] = i16 >> 8; |
484 |
< |
XPRAM[0x1379] = i16 & 0xff; |
485 |
< |
i16 = PrefsFindInt32("bootdriver"); |
486 |
< |
XPRAM[0x137a] = i16 >> 8; |
487 |
< |
XPRAM[0x137b] = i16 & 0xff; |
488 |
< |
|
489 |
< |
// Create BootGlobs at top of Mac memory |
490 |
< |
memset((void *)(RAMBase + RAMSize - 4096), 0, 4096); |
491 |
< |
BootGlobsAddr = RAMBase + RAMSize - 0x1c; |
492 |
< |
uint32 *boot_globs = (uint32 *)BootGlobsAddr; |
493 |
< |
boot_globs[-5] = htonl(RAMBase + RAMSize); // MemTop |
494 |
< |
boot_globs[0] = htonl(RAMBase); // First RAM bank |
495 |
< |
boot_globs[1] = htonl(RAMSize); |
496 |
< |
boot_globs[2] = htonl((uint32)-1); // End of bank table |
497 |
< |
|
498 |
< |
// Init thunks |
499 |
< |
if (!InitThunks()) { |
500 |
< |
PostMessage(B_QUIT_REQUESTED); |
501 |
< |
return; |
502 |
< |
} |
503 |
< |
|
504 |
< |
// Init drivers |
505 |
< |
SonyInit(); |
506 |
< |
DiskInit(); |
507 |
< |
CDROMInit(); |
508 |
< |
SCSIInit(); |
509 |
< |
|
510 |
< |
// Init external file system |
511 |
< |
ExtFSInit(); |
512 |
< |
|
513 |
< |
// Init audio |
514 |
< |
AudioInit(); |
515 |
< |
|
516 |
< |
// Init network |
517 |
< |
EtherInit(); |
518 |
< |
|
519 |
< |
// Init serial ports |
520 |
< |
SerialInit(); |
521 |
< |
|
522 |
< |
// Init Time Manager |
523 |
< |
TimerInit(); |
524 |
< |
|
525 |
< |
// Init clipboard |
526 |
< |
ClipInit(); |
527 |
< |
|
528 |
< |
// Init video |
529 |
< |
if (!VideoInit()) { |
530 |
< |
PostMessage(B_QUIT_REQUESTED); |
531 |
< |
return; |
532 |
< |
} |
533 |
< |
|
534 |
< |
// Install ROM patches |
535 |
< |
if (!PatchROM()) { |
536 |
< |
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 |
482 |
< |
clear_caches((void *)ROM_BASE, ROM_AREA_SIZE, B_INVALIDATE_ICACHE | B_FLUSH_DCACHE); |
482 |
> |
clear_caches(ROMBaseHost, ROM_AREA_SIZE, B_INVALIDATE_ICACHE | B_FLUSH_DCACHE); |
483 |
|
#endif |
484 |
|
set_area_protection(rom_area, B_READ_AREA); |
485 |
|
|
547 |
– |
// Initialize Kernel Data |
548 |
– |
memset(kernel_data, 0, sizeof(KernelData)); |
549 |
– |
if (ROMType == ROMTYPE_NEWWORLD) { |
550 |
– |
static uint32 of_dev_tree[4] = {0, 0, 0, 0}; |
551 |
– |
static uint8 vector_lookup_tbl[128]; |
552 |
– |
static uint8 vector_mask_tbl[64]; |
553 |
– |
memset((uint8 *)kernel_data + 0xb80, 0x3d, 0x80); |
554 |
– |
memset(vector_lookup_tbl, 0, 128); |
555 |
– |
memset(vector_mask_tbl, 0, 64); |
556 |
– |
kernel_data->v[0xb80 >> 2] = htonl(ROM_BASE); |
557 |
– |
kernel_data->v[0xb84 >> 2] = htonl((uint32)of_dev_tree); // OF device tree base |
558 |
– |
kernel_data->v[0xb90 >> 2] = htonl((uint32)vector_lookup_tbl); |
559 |
– |
kernel_data->v[0xb94 >> 2] = htonl((uint32)vector_mask_tbl); |
560 |
– |
kernel_data->v[0xb98 >> 2] = htonl(ROM_BASE); // OpenPIC base |
561 |
– |
kernel_data->v[0xbb0 >> 2] = htonl(0); // ADB base |
562 |
– |
kernel_data->v[0xc20 >> 2] = htonl(RAMSize); |
563 |
– |
kernel_data->v[0xc24 >> 2] = htonl(RAMSize); |
564 |
– |
kernel_data->v[0xc30 >> 2] = htonl(RAMSize); |
565 |
– |
kernel_data->v[0xc34 >> 2] = htonl(RAMSize); |
566 |
– |
kernel_data->v[0xc38 >> 2] = htonl(0x00010020); |
567 |
– |
kernel_data->v[0xc3c >> 2] = htonl(0x00200001); |
568 |
– |
kernel_data->v[0xc40 >> 2] = htonl(0x00010000); |
569 |
– |
kernel_data->v[0xc50 >> 2] = htonl(RAMBase); |
570 |
– |
kernel_data->v[0xc54 >> 2] = htonl(RAMSize); |
571 |
– |
kernel_data->v[0xf60 >> 2] = htonl(PVR); |
572 |
– |
kernel_data->v[0xf64 >> 2] = htonl(CPUClockSpeed); |
573 |
– |
kernel_data->v[0xf68 >> 2] = htonl(BusClockSpeed); |
574 |
– |
kernel_data->v[0xf6c >> 2] = htonl(CPUClockSpeed); |
575 |
– |
} else { |
576 |
– |
kernel_data->v[0xc80 >> 2] = htonl(RAMSize); |
577 |
– |
kernel_data->v[0xc84 >> 2] = htonl(RAMSize); |
578 |
– |
kernel_data->v[0xc90 >> 2] = htonl(RAMSize); |
579 |
– |
kernel_data->v[0xc94 >> 2] = htonl(RAMSize); |
580 |
– |
kernel_data->v[0xc98 >> 2] = htonl(0x00010020); |
581 |
– |
kernel_data->v[0xc9c >> 2] = htonl(0x00200001); |
582 |
– |
kernel_data->v[0xca0 >> 2] = htonl(0x00010000); |
583 |
– |
kernel_data->v[0xcb0 >> 2] = htonl(RAMBase); |
584 |
– |
kernel_data->v[0xcb4 >> 2] = htonl(RAMSize); |
585 |
– |
kernel_data->v[0xf80 >> 2] = htonl(PVR); |
586 |
– |
kernel_data->v[0xf84 >> 2] = htonl(CPUClockSpeed); |
587 |
– |
kernel_data->v[0xf88 >> 2] = htonl(BusClockSpeed); |
588 |
– |
kernel_data->v[0xf8c >> 2] = htonl(CPUClockSpeed); |
589 |
– |
} |
590 |
– |
|
486 |
|
// Initialize extra low memory |
487 |
< |
D(bug("Initializing Low Memory...\n")); |
593 |
< |
memset(NULL, 0, 0x3000); |
594 |
< |
WriteMacInt32(XLM_SIGNATURE, 'Baah'); // Signature to detect SheepShaver |
595 |
< |
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 |
598 |
< |
WriteMacInt32(XLM_BUS_CLOCK, BusClockSpeed); // For DriverServicesLib patch |
599 |
< |
WriteMacInt16(XLM_EXEC_RETURN_OPCODE, M68K_EXEC_RETURN); // For Execute68k() (RTS from the executed 68k code will jump here and end 68k mode) |
600 |
< |
WriteMacInt32(XLM_ZERO_PAGE, SheepMem::ZeroPage()); // Pointer to read-only page with all bits set to 0 |
601 |
< |
#if !EMULATED_PPC |
602 |
< |
WriteMacInt32(XLM_TOC, (uint32)TOC); // TOC pointer of emulator |
603 |
< |
WriteMacInt32(XLM_ETHER_INIT, *(uint32 *)InitStreamModule); // DLPI ethernet driver functions |
604 |
< |
WriteMacInt32(XLM_ETHER_TERM, *(uint32 *)TerminateStreamModule); |
605 |
< |
WriteMacInt32(XLM_ETHER_OPEN, *(uint32 *)ether_open); |
606 |
< |
WriteMacInt32(XLM_ETHER_CLOSE, *(uint32 *)ether_close); |
607 |
< |
WriteMacInt32(XLM_ETHER_WPUT, *(uint32 *)ether_wput); |
608 |
< |
WriteMacInt32(XLM_ETHER_RSRV, *(uint32 *)ether_rsrv); |
609 |
< |
WriteMacInt32(XLM_VIDEO_DOIO, *(uint32 *)VideoDoDriverIO); |
610 |
< |
#endif |
611 |
< |
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; |
542 |
|
if (emul_thread > 0) |
543 |
|
wait_for_thread(emul_thread, &l); |
544 |
|
|
545 |
< |
// Save NVRAM |
546 |
< |
XPRAMExit(); |
669 |
< |
|
670 |
< |
// Exit clipboard |
671 |
< |
ClipExit(); |
672 |
< |
|
673 |
< |
// Exit Time Manager |
674 |
< |
TimerExit(); |
675 |
< |
|
676 |
< |
// Exit serial |
677 |
< |
SerialExit(); |
678 |
< |
|
679 |
< |
// Exit network |
680 |
< |
EtherExit(); |
681 |
< |
|
682 |
< |
// Exit audio |
683 |
< |
AudioExit(); |
684 |
< |
|
685 |
< |
// Exit video |
686 |
< |
VideoExit(); |
687 |
< |
|
688 |
< |
// Exit external file system |
689 |
< |
ExtFSExit(); |
690 |
< |
|
691 |
< |
// Exit drivers |
692 |
< |
SCSIExit(); |
693 |
< |
CDROMExit(); |
694 |
< |
DiskExit(); |
695 |
< |
SonyExit(); |
696 |
< |
|
697 |
< |
// Delete thunks |
698 |
< |
ThunksExit(); |
545 |
> |
// Deinitialize everything |
546 |
> |
ExitAll(); |
547 |
|
|
548 |
|
// Delete SheepShaver globals |
549 |
|
SheepMem::Exit(); |
600 |
|
page_size = B_PAGE_SIZE; |
601 |
|
|
602 |
|
// Create area for ROM |
603 |
< |
void *rom_addr = (void *)ROM_BASE; |
604 |
< |
rom_area = create_area(ROM_AREA_NAME, &rom_addr, B_EXACT_ADDRESS, ROM_AREA_SIZE, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); |
603 |
> |
ROMBaseHost = (uint8 *)ROM_BASE; |
604 |
> |
rom_area = create_area(ROM_AREA_NAME, (void **)&ROMBaseHost, B_EXACT_ADDRESS, ROM_AREA_SIZE, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); |
605 |
|
if (rom_area < 0) |
606 |
|
throw area_error(); |
607 |
|
D(bug("ROM area %ld at %p\n", rom_area, rom_addr)); |
1183 |
|
* Make code executable |
1184 |
|
*/ |
1185 |
|
|
1186 |
< |
void MakeExecutable(int dummy, void *start, uint32 length) |
1186 |
> |
void MakeExecutable(int dummy, uint32 start, uint32 length) |
1187 |
|
{ |
1188 |
< |
if (((uint32)start >= ROM_BASE) && ((uint32)start < (ROM_BASE + ROM_SIZE))) |
1188 |
> |
if ((start >= ROM_BASE) && (start < (ROM_BASE + ROM_SIZE))) |
1189 |
|
return; |
1190 |
< |
clear_caches(start, length, B_INVALIDATE_ICACHE | B_FLUSH_DCACHE); |
1343 |
< |
} |
1344 |
< |
|
1345 |
< |
|
1346 |
< |
/* |
1347 |
< |
* Patch things after system startup (gets called by disk driver accRun routine) |
1348 |
< |
*/ |
1349 |
< |
|
1350 |
< |
void PatchAfterStartup(void) |
1351 |
< |
{ |
1352 |
< |
ExecuteNative(NATIVE_VIDEO_INSTALL_ACCEL); |
1353 |
< |
InstallExtFS(); |
1190 |
> |
clear_caches((void *)start, length, B_INVALIDATE_ICACHE | B_FLUSH_DCACHE); |
1191 |
|
} |
1192 |
|
|
1193 |
|
|
1248 |
|
|
1249 |
|
void TriggerInterrupt(void) |
1250 |
|
{ |
1251 |
+ |
idle_resume(); |
1252 |
|
#if 0 |
1253 |
|
WriteMacInt32(0x16a, ReadMacInt32(0x16a) + 1); |
1254 |
|
#else |
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; |
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 |
|
|