[Michael Schmitt]

Attached is a patch to SheepShaver to fix memory allocation problems when OS X 10.5 is the host. It also relaxes the 512 MB RAM limit on OS X hosts.


Problem
-------
Some users have been unable to run SheepShaver on OS X 10.5 (Leopard) hosts. The symptom is error "ERROR: Cannot map RAM: File already exists".

SheepShaver allocates RAM at fixed addresses. If it is running in "Real" addressing mode, and can't allocate at address 0, then it was hard-coded to allocate the RAM area at 0x20000000. The ROM area as allocated at 0x40800000.

The normal configuration is for SheepShaver to run under SDL, which is a Cocoa wrapper. By the time SheepShaver does its memory allocations, the Cocoa application has already started. The result is the SheepShaver memory address space already contains libraries, fonts, Input Managers, and IOKit areas.

On Leopard hosts these areas can land on the same addresses SheepShaver needs, so SheepShaver's memory allocation fails.


Solution
--------
The approach is to change SheepShaver (on Unix & OS X hosts) to allocate the RAM area anywhere it can find the space, rather than at a fixed address.

This could result in the RAM allocated higher than the ROM area, which causes a crash. To prevent this from occurring, the RAM and ROM areas are allocated contiguously.

Previously the ROM starting address was a constant ROM_BASE, which was used throughout the source files. The ROM start address is now a variable ROMBase. ROMBase is allocated and set by main_*.cpp just like RAMBase.

A side-effect of this change is that it lifts the 512 MB RAM limit for OS X hosts. The limit was because the fixed RAM and ROM addresses were such that the RAM could only be 512 MB before it overlapped the ROM area.


Impact
------
The change to make ROMBase a variable is throughout all hosts & addressing modes.

The RAM and ROM areas will only shift when run on Unix & OS X hosts, otherwise the same fixed allocation address is used as before.

This change is limited to "Real" addressing mode. Unlike Basilisk II, SheepShaver *pre-calculates* the offset for "Direct" addressing mode; the offset is compiled into the program. If the RAM address were allowed to shift, it could result in the RAM area wrapping around address 0.


Changes to main_unix.cpp
------------------------
1. Real addressing mode no longer defines a RAM_BASE constant.

2. The base address of the Mac ROM (ROMBase) is defined and exported by this program.

3. Memory management helper vm_mac_acquire is renamed to vm_mac_acquire_fixed. Added a new memory management helper vm_mac_acquire, which allocates memory at any address.

4. Changed and rearranged the allocation of RAM and ROM areas.

Before it worked like this:

  - Allocate ROM area
  - If can, attempt to allocate RAM at address zero
  - If RAM not allocated at 0, allocate at fixed address

We still want to try allocating the RAM at zero, and if using DIRECT addressing we're still going to use the fixed addresses. So we don't know where the ROM should be until after we do the RAM. The new logic is:

  - If can, attempt to allocate RAM at address zero
  - If RAM not allocated at 0
      if REAL addressing
         allocate RAM and ROM together. The ROM address is aligned to a 1 MB boundary
      else (direct addressing)
         allocate RAM at fixed address
  - If ROM hasn't been allocated yet, allocate at fixed address

5. Calculate ROMBase and ROMBaseHost based on where the ROM was loaded.

6. There is a crash if the RAM is allocated too high. To try and catch this, check if it was allocated higher than the kernel data address.

7. Change subsequent code from using constant ROM_BASE to variable ROMBase.


Changes to Other Programs
-------------------------
emul_op.cpp, main.cpp, name_registery.cpp, rom_patches.cpp, rsrc_patches.cpp, emul_ppc.cpp, sheepshaver_glue.cpp, ppc-translate-cpp:
Change from constant ROM_BASE to variable ROMBase.

ppc_asm.S: It was setting register to a hard-coded literal address: 0x40b0d000. Changed to set it to ROMBase + 0x30d000.

ppc_asm.tmpl: It defined a macro ASM_LO16 but it assumed that the macro would always be used with operands that included a register specification. This is not true. Moved the register specification from the macro to the macro invocations.

main_beos.cpp, main_windows.cpp: Since the subprograms are all expecting a variable ROMBase, all the main_*.cpp pgrams have to define and export it. The ROM_BASE constant is moved here for consistency. The mains for beos and windows just allocate the ROM at the same fixed address as before, set ROMBaseHost and ROMBase to that address, and then use ROMBase for the subsequent code.

cpu_emulation.h: removed ROM_BASE constant. This value is moved to the main_*.cpp modules, to be consistent with RAM_BASE.

user_strings_unix.cpp, user_strings_unix.h: Added new error messages related to errors that occur when the RAM and ROM are allocated anywhere.
This commit is contained in:
asvitkine 2009-08-18 18:26:11 +00:00
parent 3867b28037
commit b3b5db5456
16 changed files with 192 additions and 145 deletions

View File

@ -110,6 +110,8 @@ const char DR_CACHE_AREA_NAME[] = "Macintosh DR Cache";
const char DR_EMULATOR_AREA_NAME[] = "Macintosh DR Emulator";
const char SHEEP_AREA_NAME[] = "SheepShaver Virtual Stack";
const uintptr ROM_BASE = 0x40800000; // Base address of ROM
const uint32 SIG_STACK_SIZE = 8192; // Size of signal stack
const uint32 MSG_START = 'strt'; // Emulator start message
@ -202,6 +204,7 @@ void *TOC; // TOC pointer
#endif
uint32 RAMBase; // Base address of Mac RAM
uint32 RAMSize; // Size of Mac RAM
uint32 ROMBase; // Base address of Mac ROM
uint32 KernelDataAddr; // Address of Kernel Data
uint32 BootGlobsAddr; // Address of BootGlobs structure at top of Mac RAM
uint32 DRCacheAddr; // Address of DR Cache
@ -600,10 +603,11 @@ void SheepShaver::init_rom(void)
page_size = B_PAGE_SIZE;
// Create area for ROM
ROMBaseHost = (uint8 *)ROM_BASE;
rom_area = create_area(ROM_AREA_NAME, (void **)&ROMBaseHost, B_EXACT_ADDRESS, ROM_AREA_SIZE, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
ROMBase = ROM_BASE;
rom_area = create_area(ROM_AREA_NAME, (void **)&ROMBase, B_EXACT_ADDRESS, ROM_AREA_SIZE, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
if (rom_area < 0)
throw area_error();
ROMBaseHost = (uint8 *)ROMBase;
D(bug("ROM area %ld at %p\n", rom_area, rom_addr));
// Load ROM
@ -631,7 +635,7 @@ void SheepShaver::load_rom(void)
uint8 *rom = new uint8[ROM_SIZE]; // Reading directly into the area doesn't work
ssize_t actual = read(sheep_fd, (void *)rom, ROM_SIZE);
if (actual == ROM_SIZE) {
memcpy((void *)ROM_BASE, rom, ROM_SIZE);
memcpy(ROMBaseHost, rom, ROM_SIZE);
delete[] rom;
return;
} else
@ -702,7 +706,7 @@ status_t SheepShaver::emul_func(void *arg)
// Jump to ROM boot routine
D(bug("Jumping to ROM\n"));
obj->jump_to_rom(ROM_BASE + 0x310000);
obj->jump_to_rom(ROMBase + 0x310000);
D(bug("Returned from ROM\n"));
// We're no longer ready to receive signals
@ -1185,7 +1189,7 @@ void Dump68kRegs(M68kRegisters *r)
void MakeExecutable(int dummy, uint32 start, uint32 length)
{
if ((start >= ROM_BASE) && (start < (ROM_BASE + ROM_SIZE)))
if ((start >= ROMBase) && (start < (ROMBase + ROM_SIZE)))
return;
clear_caches((void *)start, length, B_INVALIDATE_ICACHE | B_FLUSH_DCACHE);
}
@ -1400,9 +1404,9 @@ void SheepShaver::sigusr1_handler(vregs *r)
// Execute nanokernel interrupt routine (this will activate the 68k emulator)
atomic_add((int32 *)XLM_IRQ_NEST, 1);
if (ROMType == ROMTYPE_NEWWORLD)
ppc_interrupt(ROM_BASE + 0x312b1c);
ppc_interrupt(ROMBase + 0x312b1c);
else
ppc_interrupt(ROM_BASE + 0x312a3c);
ppc_interrupt(ROMBase + 0x312a3c);
}
break;
#endif
@ -1506,32 +1510,32 @@ static void sigsegv_handler(vregs *r)
uint32 imm = opcode & 0xffff;
// Fault in Mac ROM or RAM?
bool mac_fault = (r->pc >= ROM_BASE) && (r->pc < (ROM_BASE + ROM_AREA_SIZE)) || (r->pc >= RAMBase) && (r->pc < (RAMBase + RAMSize));
bool mac_fault = (r->pc >= ROMBase) && (r->pc < (ROMBase + ROM_AREA_SIZE)) || (r->pc >= RAMBase) && (r->pc < (RAMBase + RAMSize));
if (mac_fault) {
// "VM settings" during MacOS 8 installation
if (r->pc == ROM_BASE + 0x488160 && segv_r[20] == 0xf8000000) {
if (r->pc == ROMBase + 0x488160 && segv_r[20] == 0xf8000000) {
r->pc += 4;
segv_r[8] = 0;
goto rti;
// MacOS 8.5 installation
} else if (r->pc == ROM_BASE + 0x488140 && segv_r[16] == 0xf8000000) {
} else if (r->pc == ROMBase + 0x488140 && segv_r[16] == 0xf8000000) {
r->pc += 4;
segv_r[8] = 0;
goto rti;
// MacOS 8 serial drivers on startup
} else if (r->pc == ROM_BASE + 0x48e080 && (segv_r[8] == 0xf3012002 || segv_r[8] == 0xf3012000)) {
} else if (r->pc == ROMBase + 0x48e080 && (segv_r[8] == 0xf3012002 || segv_r[8] == 0xf3012000)) {
r->pc += 4;
segv_r[8] = 0;
goto rti;
// MacOS 8.1 serial drivers on startup
} else if (r->pc == ROM_BASE + 0x48c5e0 && (segv_r[20] == 0xf3012002 || segv_r[20] == 0xf3012000)) {
} else if (r->pc == ROMBase + 0x48c5e0 && (segv_r[20] == 0xf3012002 || segv_r[20] == 0xf3012000)) {
r->pc += 4;
goto rti;
} else if (r->pc == ROM_BASE + 0x4a10a0 && (segv_r[20] == 0xf3012002 || segv_r[20] == 0xf3012000)) {
} else if (r->pc == ROMBase + 0x4a10a0 && (segv_r[20] == 0xf3012002 || segv_r[20] == 0xf3012000)) {
r->pc += 4;
goto rti;
}
@ -1642,7 +1646,7 @@ static void sigsegv_handler(vregs *r)
}
// Ignore ROM writes
if (transfer_type == TYPE_STORE && addr >= ROM_BASE && addr < ROM_BASE + ROM_SIZE) {
if (transfer_type == TYPE_STORE && addr >= ROMBase && addr < ROMBase + ROM_SIZE) {
D(bug("WARNING: %s write access to ROM at %p, pc %p\n", transfer_size == SIZE_BYTE ? "Byte" : transfer_size == SIZE_HALFWORD ? "Halfword" : "Word", addr, r->pc));
if (addr_mode == MODE_U || addr_mode == MODE_UX)
segv_r[ra] = addr;
@ -1777,7 +1781,7 @@ static void sigill_handler(vregs *r)
uint32 imm = opcode & 0xffff;
// Fault in Mac ROM or RAM?
bool mac_fault = (r->pc >= ROM_BASE) && (r->pc < (ROM_BASE + ROM_AREA_SIZE)) || (r->pc >= RAMBase) && (r->pc < (RAMBase + RAMSize));
bool mac_fault = (r->pc >= ROMBase) && (r->pc < (ROMBase + ROM_AREA_SIZE)) || (r->pc >= RAMBase) && (r->pc < (RAMBase + RAMSize));
if (mac_fault) {
switch (primop) {

View File

@ -161,12 +161,14 @@
const char ROM_FILE_NAME[] = "ROM";
const char ROM_FILE_NAME2[] = "Mac OS ROM";
#if REAL_ADDRESSING
const uintptr RAM_BASE = 0x20000000; // Base address of RAM
#else
#if !REAL_ADDRESSING
// FIXME: needs to be >= 0x04000000
const uintptr RAM_BASE = 0x10000000; // Base address of RAM
#endif
const uintptr ROM_BASE = 0x40800000; // Base address of ROM
#if REAL_ADDRESSING
const uint32 ROM_ALIGNMENT = 0x100000; // ROM must be aligned to a 1MB boundary
#endif
const uint32 SIG_STACK_SIZE = 0x10000; // Size of signal stack
@ -177,6 +179,7 @@ void *R13 = NULL; // Pointer to .sdata section (r13 under Linux)
#endif
uint32 RAMBase; // Base address of Mac RAM
uint32 RAMSize; // Size of Mac RAM
uint32 ROMBase; // Base address of Mac ROM
uint32 KernelDataAddr; // Address of Kernel Data
uint32 BootGlobsAddr; // Address of BootGlobs structure at top of Mac RAM
uint32 DRCacheAddr; // Address of DR Cache
@ -337,7 +340,12 @@ int atomic_or(int *var, int v)
* Memory management helpers
*/
static inline int vm_mac_acquire(uint32 addr, uint32 size)
static inline uint8 *vm_mac_acquire(uint32 size)
{
return (uint8 *)vm_acquire(size);
}
static inline int vm_mac_acquire_fixed(uint32 addr, uint32 size)
{
return vm_acquire_fixed(Mac2HostAddr(addr), size);
}
@ -385,7 +393,7 @@ int main(int argc, char **argv)
uint32 rom_size, actual;
uint8 *rom_tmp;
time_t now, expire;
bool memory_mapped_from_zero;
bool memory_mapped_from_zero, ram_rom_areas_contiguous;
const char *vmdir = NULL;
#ifdef USE_SDL_VIDEO
@ -798,13 +806,13 @@ int main(int argc, char **argv)
D(bug("Emulator Data at %p (%08x)\n", emulator_data, KERNEL_DATA_BASE + offsetof(KernelData, ed)));
// Create area for DR Cache
if (vm_mac_acquire(DR_EMULATOR_BASE, DR_EMULATOR_SIZE) < 0) {
if (vm_mac_acquire_fixed(DR_EMULATOR_BASE, DR_EMULATOR_SIZE) < 0) {
sprintf(str, GetString(STR_DR_EMULATOR_MMAP_ERR), strerror(errno));
ErrorAlert(str);
goto quit;
}
dr_emulator_area_mapped = true;
if (vm_mac_acquire(DR_CACHE_BASE, DR_CACHE_SIZE) < 0) {
if (vm_mac_acquire_fixed(DR_CACHE_BASE, DR_CACHE_SIZE) < 0) {
sprintf(str, GetString(STR_DR_CACHE_MMAP_ERR), strerror(errno));
ErrorAlert(str);
goto quit;
@ -826,24 +834,7 @@ int main(int argc, char **argv)
ErrorAlert(str);
goto quit;
}
// Create area for Mac ROM
if (vm_mac_acquire(ROM_BASE, ROM_AREA_SIZE) < 0) {
sprintf(str, GetString(STR_ROM_MMAP_ERR), strerror(errno));
ErrorAlert(str);
goto quit;
}
ROMBaseHost = Mac2HostAddr(ROM_BASE);
#if !EMULATED_PPC
if (vm_protect(ROMBaseHost, ROM_AREA_SIZE, VM_PAGE_READ | VM_PAGE_WRITE | VM_PAGE_EXECUTE) < 0) {
sprintf(str, GetString(STR_ROM_MMAP_ERR), strerror(errno));
ErrorAlert(str);
goto quit;
}
#endif
rom_area_mapped = true;
D(bug("ROM area at %p (%08x)\n", ROMBaseHost, ROM_BASE));
// Create area for Mac RAM
RAMSize = PrefsFindInt32("ramsize");
if (RAMSize < 8*1024*1024) {
@ -851,31 +842,48 @@ int main(int argc, char **argv)
RAMSize = 8*1024*1024;
}
memory_mapped_from_zero = false;
ram_rom_areas_contiguous = false;
#if REAL_ADDRESSING && HAVE_LINKER_SCRIPT
if (vm_mac_acquire(0, RAMSize) == 0) {
if (vm_mac_acquire_fixed(0, RAMSize) == 0) {
D(bug("Could allocate RAM from 0x0000\n"));
RAMBase = 0;
RAMBaseHost = Mac2HostAddr(RAMBase);
memory_mapped_from_zero = true;
}
#endif
if (!memory_mapped_from_zero) {
#ifndef PAGEZERO_HACK
// Create Low Memory area (0x0000..0x3000)
if (vm_mac_acquire(0, 0x3000) < 0) {
if (vm_mac_acquire_fixed(0, 0x3000) < 0) {
sprintf(str, GetString(STR_LOW_MEM_MMAP_ERR), strerror(errno));
ErrorAlert(str);
goto quit;
}
lm_area_mapped = true;
#endif
if (vm_mac_acquire(RAM_BASE, RAMSize) < 0) {
#if REAL_ADDRESSING
// Allocate RAM at any address. Since ROM must be higher than RAM, allocate the RAM
// and ROM areas contiguously, plus a little extra to allow for ROM address alignment.
RAMBaseHost = vm_mac_acquire(RAMSize + ROM_AREA_SIZE + ROM_ALIGNMENT);
if (RAMBaseHost == VM_MAP_FAILED) {
sprintf(str, GetString(STR_RAM_ROM_MMAP_ERR), strerror(errno));
ErrorAlert(str);
goto quit;
}
RAMBase = Host2MacAddr(RAMBaseHost);
ROMBase = (RAMBase + RAMSize + ROM_ALIGNMENT -1) & -ROM_ALIGNMENT;
ROMBaseHost = Mac2HostAddr(ROMBase);
ram_rom_areas_contiguous = true;
#else
if (vm_mac_acquire_fixed(RAM_BASE, RAMSize) < 0) {
sprintf(str, GetString(STR_RAM_MMAP_ERR), strerror(errno));
ErrorAlert(str);
goto quit;
}
RAMBase = RAM_BASE;
RAMBaseHost = Mac2HostAddr(RAMBase);
#endif
}
RAMBaseHost = Mac2HostAddr(RAMBase);
#if !EMULATED_PPC
if (vm_protect(RAMBaseHost, RAMSize, VM_PAGE_READ | VM_PAGE_WRITE | VM_PAGE_EXECUTE) < 0) {
sprintf(str, GetString(STR_RAM_MMAP_ERR), strerror(errno));
@ -886,7 +894,32 @@ int main(int argc, char **argv)
ram_area_mapped = true;
D(bug("RAM area at %p (%08x)\n", RAMBaseHost, RAMBase));
if (RAMBase > ROM_BASE) {
if (RAMBase > KernelDataAddr) {
ErrorAlert(GetString(STR_RAM_AREA_TOO_HIGH_ERR));
goto quit;
}
// Create area for Mac ROM
if (!ram_rom_areas_contiguous) {
if (vm_mac_acquire_fixed(ROM_BASE, ROM_AREA_SIZE) < 0) {
sprintf(str, GetString(STR_ROM_MMAP_ERR), strerror(errno));
ErrorAlert(str);
goto quit;
}
ROMBase = ROM_BASE;
ROMBaseHost = Mac2HostAddr(ROMBase);
}
#if !EMULATED_PPC
if (vm_protect(ROMBaseHost, ROM_AREA_SIZE, VM_PAGE_READ | VM_PAGE_WRITE | VM_PAGE_EXECUTE) < 0) {
sprintf(str, GetString(STR_ROM_MMAP_ERR), strerror(errno));
ErrorAlert(str);
goto quit;
}
#endif
rom_area_mapped = true;
D(bug("ROM area at %p (%08x)\n", ROMBaseHost, ROMBase));
if (RAMBase > ROMBase) {
ErrorAlert(GetString(STR_RAM_HIGHER_THAN_ROM_ERR));
goto quit;
}
@ -927,7 +960,7 @@ int main(int argc, char **argv)
// Clear caches (as we loaded and patched code) and write protect ROM
#if !EMULATED_PPC
flush_icache_range(ROM_BASE, ROM_BASE + ROM_AREA_SIZE);
flush_icache_range(ROMBase, ROMBase + ROM_AREA_SIZE);
#endif
vm_protect(ROMBaseHost, ROM_AREA_SIZE, VM_PAGE_READ | VM_PAGE_EXECUTE);
@ -1042,7 +1075,7 @@ static void Quit(void)
// Delete ROM area
if (rom_area_mapped)
vm_mac_release(ROM_BASE, ROM_AREA_SIZE);
vm_mac_release(ROMBase, ROM_AREA_SIZE);
// Delete DR cache areas
if (dr_emulator_area_mapped)
@ -1161,9 +1194,9 @@ static void *emul_func(void *arg)
// Jump to ROM boot routine
D(bug("Jumping to ROM\n"));
#if EMULATED_PPC
jump_to_rom(ROM_BASE + 0x310000);
jump_to_rom(ROMBase + 0x310000);
#else
jump_to_rom(ROM_BASE + 0x310000, (uint32)emulator_data);
jump_to_rom(ROMBase + 0x310000, (uint32)emulator_data);
#endif
D(bug("Returned from ROM\n"));
@ -1249,7 +1282,7 @@ void Dump68kRegs(M68kRegisters *r)
void MakeExecutable(int dummy, uint32 start, uint32 length)
{
if ((start >= ROM_BASE) && (start < (ROM_BASE + ROM_SIZE)))
if ((start >= ROMBase) && (start < (ROMBase + ROM_SIZE)))
return;
#if EMULATED_PPC
FlushCodeCache(start, start + length);
@ -1592,9 +1625,9 @@ void sigusr2_handler(int sig, siginfo_t *sip, void *scp)
// Execute nanokernel interrupt routine (this will activate the 68k emulator)
DisableInterrupt();
if (ROMType == ROMTYPE_NEWWORLD)
ppc_interrupt(ROM_BASE + 0x312b1c, KernelDataAddr);
ppc_interrupt(ROMBase + 0x312b1c, KernelDataAddr);
else
ppc_interrupt(ROM_BASE + 0x312a3c, KernelDataAddr);
ppc_interrupt(ROMBase + 0x312a3c, KernelDataAddr);
// Reset normal stack
sigaltstack(&sig_stack, NULL);
@ -1680,32 +1713,32 @@ static void sigsegv_handler(int sig, siginfo_t *sip, void *scp)
num_segv++;
// Fault in Mac ROM or RAM or DR Cache?
bool mac_fault = (r->pc() >= ROM_BASE) && (r->pc() < (ROM_BASE + ROM_AREA_SIZE)) || (r->pc() >= RAMBase) && (r->pc() < (RAMBase + RAMSize)) || (r->pc() >= DR_CACHE_BASE && r->pc() < (DR_CACHE_BASE + DR_CACHE_SIZE));
bool mac_fault = (r->pc() >= ROMBase) && (r->pc() < (ROMBase + ROM_AREA_SIZE)) || (r->pc() >= RAMBase) && (r->pc() < (RAMBase + RAMSize)) || (r->pc() >= DR_CACHE_BASE && r->pc() < (DR_CACHE_BASE + DR_CACHE_SIZE));
if (mac_fault) {
// "VM settings" during MacOS 8 installation
if (r->pc() == ROM_BASE + 0x488160 && r->gpr(20) == 0xf8000000) {
if (r->pc() == ROMBase + 0x488160 && r->gpr(20) == 0xf8000000) {
r->pc() += 4;
r->gpr(8) = 0;
return;
// MacOS 8.5 installation
} else if (r->pc() == ROM_BASE + 0x488140 && r->gpr(16) == 0xf8000000) {
} else if (r->pc() == ROMBase + 0x488140 && r->gpr(16) == 0xf8000000) {
r->pc() += 4;
r->gpr(8) = 0;
return;
// MacOS 8 serial drivers on startup
} else if (r->pc() == ROM_BASE + 0x48e080 && (r->gpr(8) == 0xf3012002 || r->gpr(8) == 0xf3012000)) {
} else if (r->pc() == ROMBase + 0x48e080 && (r->gpr(8) == 0xf3012002 || r->gpr(8) == 0xf3012000)) {
r->pc() += 4;
r->gpr(8) = 0;
return;
// MacOS 8.1 serial drivers on startup
} else if (r->pc() == ROM_BASE + 0x48c5e0 && (r->gpr(20) == 0xf3012002 || r->gpr(20) == 0xf3012000)) {
} else if (r->pc() == ROMBase + 0x48c5e0 && (r->gpr(20) == 0xf3012002 || r->gpr(20) == 0xf3012000)) {
r->pc() += 4;
return;
} else if (r->pc() == ROM_BASE + 0x4a10a0 && (r->gpr(20) == 0xf3012002 || r->gpr(20) == 0xf3012000)) {
} else if (r->pc() == ROMBase + 0x4a10a0 && (r->gpr(20) == 0xf3012002 || r->gpr(20) == 0xf3012000)) {
r->pc() += 4;
return;
@ -1838,7 +1871,7 @@ static void sigsegv_handler(int sig, siginfo_t *sip, void *scp)
// Ignore ROM writes (including to the zero page, which is read-only)
if (transfer_type == TYPE_STORE &&
((addr >= ROM_BASE && addr < ROM_BASE + ROM_SIZE) ||
((addr >= ROMBase && addr < ROMBase + ROM_SIZE) ||
(addr >= SheepMem::ZeroPage() && addr < SheepMem::ZeroPage() + SheepMem::PageSize()))) {
// D(bug("WARNING: %s write access to ROM at %08lx, pc %08lx\n", transfer_size == SIZE_BYTE ? "Byte" : transfer_size == SIZE_HALFWORD ? "Halfword" : "Word", addr, r->pc()));
if (addr_mode == MODE_U || addr_mode == MODE_UX)
@ -1929,7 +1962,7 @@ static void sigill_handler(int sig, siginfo_t *sip, void *scp)
#endif
// Fault in Mac ROM or RAM?
bool mac_fault = (r->pc() >= ROM_BASE) && (r->pc() < (ROM_BASE + ROM_AREA_SIZE)) || (r->pc() >= RAMBase) && (r->pc() < (RAMBase + RAMSize));
bool mac_fault = (r->pc() >= ROMBase) && (r->pc() < (ROMBase + ROM_AREA_SIZE)) || (r->pc() >= RAMBase) && (r->pc() < (RAMBase + RAMSize));
if (mac_fault) {
// Get opcode and divide into fields
@ -2097,7 +2130,7 @@ bool SheepMem::Init(void)
// Allocate SheepShaver globals
proc = base;
if (vm_mac_acquire(base, size) < 0)
if (vm_mac_acquire_fixed(base, size) < 0)
return false;
// Allocate page with all bits set to 0, right in the middle
@ -2110,7 +2143,7 @@ bool SheepMem::Init(void)
#if EMULATED_PPC
// Allocate alternate stack for PowerPC interrupt routine
sig_stack = base + size;
if (vm_mac_acquire(sig_stack, SIG_STACK_SIZE) < 0)
if (vm_mac_acquire_fixed(sig_stack, SIG_STACK_SIZE) < 0)
return false;
#endif

View File

@ -489,8 +489,10 @@ C_SYMBOL_NAME(jump_to_rom):
stw r1,XLM_EMUL_RETURN_STACK(0)
// Preset registers for ROM boot routine
lis r3,0x40b0 // Pointer to ROM boot structure
ori r3,r3,0xd000
lis r3,ASM_HA16(C_SYMBOL_NAME(ROMBase)) // Pointer to ROM boot structure:
lwz r3,ASM_LO16(C_SYMBOL_NAME(ROMBase))(r3) // r3 = ROMBase + 0x30d000
addis r3,r3,ASM_HA16(0x30d000)
addi r3,r3,ASM_LO16(0x30d000)
// 68k emulator is now active
li r0,MODE_68K
@ -887,7 +889,7 @@ C_SYMBOL_NAME(ASM_MACRO_ARG0):
// Atomically increase stack_id
lis r19,ASM_HA16(ASM_MACRO_ARG2)
la r19,ASM_LO16(ASM_MACRO_ARG2,r19)
la r19,ASM_LO16(ASM_MACRO_ARG2)(r19)
li r4,1
mr r3,r19
bl C_SYMBOL_NAME(atomic_add)
@ -897,7 +899,7 @@ C_SYMBOL_NAME(ASM_MACRO_ARG0):
// ID was 0, we can use the local stack
lis r9,ASM_HA16(ASM_MACRO_ARG1)
lis r3,(SIG_STACK_SIZE>>16)
la r9,ASM_LO16(ASM_MACRO_ARG1,r9)
la r9,ASM_LO16(ASM_MACRO_ARG1)(r9)
addi r3,r3,((SIG_STACK_SIZE&0xffff)-64)
add r1,r9,r3

View File

@ -31,7 +31,7 @@
#define ASM_TYPE(NAME, TYPE) /* nothing */
#define ASM_ALIGN_2(EXP) EXP
#define ASM_HA16(VAR) ha16(VAR)
#define ASM_LO16(VAR, REG) lo16(VAR)(REG)
#define ASM_LO16(VAR) lo16(VAR)
#define ASM_MACRO_END .endmacro
#define ASM_MACRO_ARG_SEP ,
#define ASM_MACRO_ARG0_DEF /* nothing! */
@ -55,7 +55,7 @@
#define ASM_HA16(VAR) VAR@ha
#endif
#ifndef ASM_LO16
#define ASM_LO16(VAR, REG) VAR@l(REG)
#define ASM_LO16(VAR) VAR@l
#endif
#ifndef ASM_MACRO_START
#define ASM_MACRO_START .macro

View File

@ -38,6 +38,8 @@ user_string_def platform_strings[] = {
{STR_KD2_SHMAT_ERR, "Cannot map second Kernel Data area: %s."},
{STR_ROM_MMAP_ERR, "Cannot map ROM: %s."},
{STR_RAM_MMAP_ERR, "Cannot map RAM: %s."},
{STR_RAM_ROM_MMAP_ERR, "Cannot map area for RAM and ROM: %s."},
{STR_RAM_AREA_TOO_HIGH_ERR, "Cannot map usable RAM area. Try to decrease the MacOS RAM size."},
{STR_DR_CACHE_MMAP_ERR, "Cannot map DR Cache: %s."},
{STR_DR_EMULATOR_MMAP_ERR, "Cannot map DR Emulator: %s."},
{STR_SHEEP_MEM_MMAP_ERR, "Cannot map SheepShaver Data area: %s."},

View File

@ -29,6 +29,8 @@ enum {
STR_KD2_SHMAT_ERR,
STR_ROM_MMAP_ERR,
STR_RAM_MMAP_ERR,
STR_RAM_ROM_MMAP_ERR,
STR_RAM_AREA_TOO_HIGH_ERR,
STR_DR_CACHE_MMAP_ERR,
STR_DR_EMULATOR_MMAP_ERR,
STR_SHEEP_MEM_MMAP_ERR,

View File

@ -58,12 +58,15 @@
const char ROM_FILE_NAME[] = "ROM";
const char ROM_FILE_NAME2[] = "Mac OS ROM";
const uintptr ROM_BASE = 0x40800000; // Base address of ROM
const uint32 SIG_STACK_SIZE = 0x10000; // Size of signal stack
// Global variables (exported)
uint32 RAMBase; // Base address of Mac RAM
uint32 RAMSize; // Size of Mac RAM
uint32 ROMBase; // Base address of Mac ROM
uint32 KernelDataAddr; // Address of Kernel Data
uint32 BootGlobsAddr; // Address of BootGlobs structure at top of Mac RAM
uint32 DRCacheAddr; // Address of DR Cache
@ -297,9 +300,10 @@ int main(int argc, char **argv)
ErrorAlert(str);
goto quit;
}
ROMBaseHost = Mac2HostAddr(ROM_BASE);
ROMBase = ROM_BASE;
ROMBaseHost = Mac2HostAddr(ROMBase);
rom_area_mapped = true;
D(bug("ROM area at %p (%08x)\n", ROMBaseHost, ROM_BASE));
D(bug("ROM area at %p (%08x)\n", ROMBaseHost, ROMBase));
// Create area for Mac RAM
RAMSize = PrefsFindInt32("ramsize");
@ -317,7 +321,7 @@ int main(int argc, char **argv)
ram_area_mapped = true;
D(bug("RAM area at %p (%08x)\n", RAMBaseHost, RAMBase));
if (RAMBase > ROM_BASE) {
if (RAMBase > ROMBase) {
ErrorAlert(GetString(STR_RAM_HIGHER_THAN_ROM_ERR));
goto quit;
}
@ -383,7 +387,7 @@ int main(int argc, char **argv)
// Get my thread ID and jump to ROM boot routine
emul_thread = GetCurrentThread();
D(bug("Jumping to ROM\n"));
jump_to_rom(ROM_BASE + 0x310000);
jump_to_rom(ROMBase + 0x310000);
D(bug("Returned from ROM\n"));
quit:
@ -425,7 +429,7 @@ static void Quit(void)
// Delete ROM area
if (rom_area_mapped)
vm_mac_release(ROM_BASE, ROM_AREA_SIZE);
vm_mac_release(ROMBase, ROM_AREA_SIZE);
// Delete DR cache areas
if (dr_emulator_area_mapped)
@ -577,7 +581,7 @@ void Dump68kRegs(M68kRegisters *r)
void MakeExecutable(int dummy, uint32 start, uint32 length)
{
if ((start >= ROM_BASE) && (start < (ROM_BASE + ROM_SIZE)))
if ((start >= ROMBase) && (start < (ROMBase + ROM_SIZE)))
return;
FlushCodeCache(start, start + length);
}

View File

@ -290,7 +290,7 @@ void EmulOp(M68kRegisters *r, uint32 pc, int selector)
WriteMacInt32(KernelDataAddr + 0x17c4, DR_CACHE_SIZE);
WriteMacInt32(KernelDataAddr + 0x1b04, DR_CACHE_BASE);
WriteMacInt32(KernelDataAddr + 0x1b00, DR_EMULATOR_BASE);
memcpy((void *)DR_EMULATOR_BASE, (void *)(ROM_BASE + 0x370000), DR_EMULATOR_SIZE);
memcpy((void *)DR_EMULATOR_BASE, (void *)(ROMBase + 0x370000), DR_EMULATOR_SIZE);
MakeExecutable(0, DR_EMULATOR_BASE, DR_EMULATOR_SIZE);
}
break;

View File

@ -1496,7 +1496,7 @@ void init_emul_ppc(void)
cr = xer = 0;
fpscr = 0;
r[3] = ROM_BASE + 0x30d000;
r[3] = ROMBase + 0x30d000;
// Install SIGSEGV handler
sigemptyset(&sigsegv_action.sa_mask);

View File

@ -27,10 +27,8 @@
*/
// Constants
const uintptr ROM_BASE = 0x40800000; // Base address of ROM
const uint32 ROM_SIZE = 0x400000; // Size of ROM file
const uint32 ROM_AREA_SIZE = 0x500000; // Size of ROM area
const uintptr ROM_END = ROM_BASE + ROM_SIZE; // End of ROM
const uintptr DR_EMULATOR_BASE = 0x68070000; // Address of DR emulator code
const uint32 DR_EMULATOR_SIZE = 0x10000; // Size of DR emulator code
const uintptr DR_CACHE_BASE = 0x69000000; // Address of DR cache
@ -55,6 +53,8 @@ struct KernelData {
extern uint32 RAMBase; // Base address of Mac RAM
extern uint32 RAMSize; // Size address of Mac RAM
extern uint8 *RAMBaseHost; // Base address of Mac RAM (host address space)
extern uint32 ROMBase; // Base address of Mac ROM
extern uint8 *ROMBaseHost; // Base address of Mac ROM (host address space)
// Mac memory access functions

View File

@ -750,25 +750,25 @@ sigsegv_return_t sigsegv_handler(sigsegv_info_t *sip)
const uint32 pc = cpu->pc();
// Fault in Mac ROM or RAM?
bool mac_fault = (pc >= ROM_BASE) && (pc < (ROM_BASE + ROM_AREA_SIZE)) || (pc >= RAMBase) && (pc < (RAMBase + RAMSize)) || (pc >= DR_CACHE_BASE && pc < (DR_CACHE_BASE + DR_CACHE_SIZE));
bool mac_fault = (pc >= ROMBase) && (pc < (ROMBase + ROM_AREA_SIZE)) || (pc >= RAMBase) && (pc < (RAMBase + RAMSize)) || (pc >= DR_CACHE_BASE && pc < (DR_CACHE_BASE + DR_CACHE_SIZE));
if (mac_fault) {
// "VM settings" during MacOS 8 installation
if (pc == ROM_BASE + 0x488160 && cpu->gpr(20) == 0xf8000000)
if (pc == ROMBase + 0x488160 && cpu->gpr(20) == 0xf8000000)
return SIGSEGV_RETURN_SKIP_INSTRUCTION;
// MacOS 8.5 installation
else if (pc == ROM_BASE + 0x488140 && cpu->gpr(16) == 0xf8000000)
else if (pc == ROMBase + 0x488140 && cpu->gpr(16) == 0xf8000000)
return SIGSEGV_RETURN_SKIP_INSTRUCTION;
// MacOS 8 serial drivers on startup
else if (pc == ROM_BASE + 0x48e080 && (cpu->gpr(8) == 0xf3012002 || cpu->gpr(8) == 0xf3012000))
else if (pc == ROMBase + 0x48e080 && (cpu->gpr(8) == 0xf3012002 || cpu->gpr(8) == 0xf3012000))
return SIGSEGV_RETURN_SKIP_INSTRUCTION;
// MacOS 8.1 serial drivers on startup
else if (pc == ROM_BASE + 0x48c5e0 && (cpu->gpr(20) == 0xf3012002 || cpu->gpr(20) == 0xf3012000))
else if (pc == ROMBase + 0x48c5e0 && (cpu->gpr(20) == 0xf3012002 || cpu->gpr(20) == 0xf3012000))
return SIGSEGV_RETURN_SKIP_INSTRUCTION;
else if (pc == ROM_BASE + 0x4a10a0 && (cpu->gpr(20) == 0xf3012002 || cpu->gpr(20) == 0xf3012000))
else if (pc == ROMBase + 0x4a10a0 && (cpu->gpr(20) == 0xf3012002 || cpu->gpr(20) == 0xf3012000))
return SIGSEGV_RETURN_SKIP_INSTRUCTION;
// MacOS 8.6 serial drivers on startup (with DR Cache and OldWorld ROM)
@ -807,7 +807,7 @@ void init_emul_ppc(void)
// Initialize main CPU emulator
ppc_cpu = new sheepshaver_cpu();
ppc_cpu->set_register(powerpc_registers::GPR(3), any_register((uint32)ROM_BASE + 0x30d000));
ppc_cpu->set_register(powerpc_registers::GPR(3), any_register((uint32)ROMBase + 0x30d000));
ppc_cpu->set_register(powerpc_registers::GPR(4), any_register(KernelDataAddr + 0x1000));
WriteMacInt32(XLM_RUN_MODE, MODE_68K);
@ -951,9 +951,9 @@ void HandleInterrupt(powerpc_registers *r)
// Execute nanokernel interrupt routine (this will activate the 68k emulator)
DisableInterrupt();
if (ROMType == ROMTYPE_NEWWORLD)
ppc_cpu->interrupt(ROM_BASE + 0x312b1c);
ppc_cpu->interrupt(ROMBase + 0x312b1c);
else
ppc_cpu->interrupt(ROM_BASE + 0x312a3c);
ppc_cpu->interrupt(ROMBase + 0x312a3c);
}
break;
#endif

View File

@ -48,7 +48,7 @@
static inline bool is_read_only_memory(uintptr addr)
{
#ifdef SHEEPSHAVER
if ((addr - ROM_BASE) < ROM_AREA_SIZE)
if ((addr - ROMBase) < ROM_AREA_SIZE)
return true;
#endif
return false;

View File

@ -173,11 +173,11 @@ bool InitAll(const char *vmdir)
memset((uint8 *)kernel_data + 0xb80, 0x3d, 0x80);
Mac_memset(vector_lookup_tbl, 0, 128);
Mac_memset(vector_mask_tbl, 0, 64);
kernel_data->v[0xb80 >> 2] = htonl(ROM_BASE);
kernel_data->v[0xb80 >> 2] = htonl(ROMBase);
kernel_data->v[0xb84 >> 2] = htonl(of_dev_tree); // OF device tree base
kernel_data->v[0xb90 >> 2] = htonl(vector_lookup_tbl);
kernel_data->v[0xb94 >> 2] = htonl(vector_mask_tbl);
kernel_data->v[0xb98 >> 2] = htonl(ROM_BASE); // OpenPIC base
kernel_data->v[0xb98 >> 2] = htonl(ROMBase); // OpenPIC base
kernel_data->v[0xbb0 >> 2] = htonl(0); // ADB base
kernel_data->v[0xc20 >> 2] = htonl(RAMSize);
kernel_data->v[0xc24 >> 2] = htonl(RAMSize);

View File

@ -97,7 +97,7 @@ void DoPatchNameRegistry(void)
SheepRegEntryID aapl_rom;
if (!RegistryCStrEntryCreate(device_tree.addr(), "AAPL,ROM", aapl_rom.addr())) {
RegistryPropertyCreateStr(aapl_rom.addr(), "device_type", "rom");
SheepPair reg(ROM_BASE, ROM_SIZE);
SheepPair reg(ROMBase, ROM_SIZE);
RegistryPropertyCreate(aapl_rom.addr(), "reg", reg.addr(), 8);
}

View File

@ -224,9 +224,9 @@ static uint32 rsrc_ptr = 0;
// id = 4711 means "find any ID"
static uint32 find_rom_resource(uint32 s_type, int16 s_id = 4711, bool cont = false)
{
uint32 lp = ROM_BASE + 0x1a;
uint32 lp = ROMBase + 0x1a;
uint32 x = ReadMacInt32(lp);
uint32 header_size = ReadMacInt8(ROM_BASE + x + 5);
uint32 header_size = ReadMacInt8(ROMBase + x + 5);
if (!cont)
rsrc_ptr = x;
@ -234,14 +234,14 @@ static uint32 find_rom_resource(uint32 s_type, int16 s_id = 4711, bool cont = fa
return 0;
for (;;) {
lp = ROM_BASE + rsrc_ptr;
lp = ROMBase + rsrc_ptr;
rsrc_ptr = ReadMacInt32(lp);
if (rsrc_ptr == 0)
break;
rsrc_ptr += header_size;
lp = ROM_BASE + rsrc_ptr + 4;
lp = ROMBase + rsrc_ptr + 4;
uint32 data = ReadMacInt32(lp);
uint32 type = ReadMacInt32(lp + 4);
int16 id = ReadMacInt16(lp + 8);
@ -258,7 +258,7 @@ static uint32 find_rom_resource(uint32 s_type, int16 s_id = 4711, bool cont = fa
static uint32 find_rom_trap(uint16 trap)
{
uint32 lp = ROM_BASE + ReadMacInt32(ROM_BASE + 0x22);
uint32 lp = ROMBase + ReadMacInt32(ROMBase + 0x22);
if (trap > 0xa800)
return ReadMacInt32(lp + 4 * (trap & 0x3ff));
@ -759,10 +759,10 @@ static bool patch_nanokernel_boot(void)
lp[0x9c >> 2] = htonl(KernelDataAddr); // LA_InfoRecord
lp[0xa0 >> 2] = htonl(KernelDataAddr); // LA_KernelData
lp[0xa4 >> 2] = htonl(KernelDataAddr + 0x1000); // LA_EmulatorData
lp[0xa8 >> 2] = htonl(ROM_BASE + 0x480000); // LA_DispatchTable
lp[0xac >> 2] = htonl(ROM_BASE + 0x460000); // LA_EmulatorCode
lp[0xa8 >> 2] = htonl(ROMBase + 0x480000); // LA_DispatchTable
lp[0xac >> 2] = htonl(ROMBase + 0x460000); // LA_EmulatorCode
lp[0x360 >> 2] = htonl(0); // Physical RAM base (? on NewWorld ROM, this contains -1)
lp[0xfd8 >> 2] = htonl(ROM_BASE + 0x2a); // 68k reset vector
lp[0xfd8 >> 2] = htonl(ROMBase + 0x2a); // 68k reset vector
// Skip SR/BAT/SDR init
loc = 0x310000;
@ -775,7 +775,7 @@ static bool patch_nanokernel_boot(void)
if ((base = find_rom_data(0x3101b0, 0x3105b0, sr_init_dat, sizeof(sr_init_dat))) == 0) return false;
D(bug("sr_init %08lx\n", base));
lp = (uint32 *)(ROMBaseHost + loc + 8);
*lp = htonl(0x48000000 | ((base - loc - 8) & 0x3fffffc)); // b ROM_BASE+0x3101b0
*lp = htonl(0x48000000 | ((base - loc - 8) & 0x3fffffc)); // b ROMBase+0x3101b0
lp = (uint32 *)(ROMBaseHost + base);
*lp++ = htonl(0x80200000 + XLM_KERNEL_DATA); // lwz r1,(pointer to Kernel Data)
*lp++ = htonl(0x3da0dead); // lis r13,0xdead (start of kernel memory)
@ -1303,8 +1303,8 @@ dr_found:
D(bug(" patching absolute branch at %08x\n", loc));
*lp = htonl(0x48000000 + 0xf000 - (loc & 0xffff)); // b DR_CACHE_BASE+0x1f000
lp = (uint32 *)(ROMBaseHost + 0x37f000);
*lp++ = htonl(0x3c000000 + ((ROM_BASE + base) >> 16)); // lis r0,xxx
*lp++ = htonl(0x60000000 + ((ROM_BASE + base) & 0xffff)); // ori r0,r0,xxx
*lp++ = htonl(0x3c000000 + ((ROMBase + base) >> 16)); // lis r0,xxx
*lp++ = htonl(0x60000000 + ((ROMBase + base) & 0xffff)); // ori r0,r0,xxx
*lp++ = htonl(0x7c0803a6); // mtlr r0
*lp = htonl(POWERPC_BLR); // blr
}
@ -1428,14 +1428,14 @@ static bool patch_nanokernel(void)
while (ntohl(*lp) != 0x7d5a03a6) lp--;
*lp++ = htonl(0x7d4903a6); // mtctr r10
*lp++ = htonl(0x7daff120); // mtcr r13
*lp = htonl(0x48000000 + ((0x318000 - ((uintptr)lp - (uintptr)ROMBaseHost)) & 0x03fffffc)); // b ROM_BASE+0x318000
*lp = htonl(0x48000000 + ((0x318000 - ((uintptr)lp - (uintptr)ROMBaseHost)) & 0x03fffffc)); // b ROMBase+0x318000
uint32 npc = (uintptr)(lp + 1) - (uintptr)ROMBaseHost;
lp = (uint32 *)(ROMBaseHost + 0x318000);
*lp++ = htonl(0x81400000 + XLM_IRQ_NEST); // lwz r10,XLM_IRQ_NEST
*lp++ = htonl(0x394affff); // subi r10,r10,1
*lp++ = htonl(0x91400000 + XLM_IRQ_NEST); // stw r10,XLM_IRQ_NEST
*lp = htonl(0x48000000 + ((npc - 0x31800c) & 0x03fffffc)); // b ROM_BASE+0x312c2c
*lp = htonl(0x48000000 + ((npc - 0x31800c) & 0x03fffffc)); // b ROMBase+0x312c2c
// Patch FEOA opcode, selector 0x0A (virtual->physical page index)
static const uint8 fe0a_0a_dat[] = {0x55, 0x23, 0xa3, 0x3e, 0x4b};
@ -1480,7 +1480,7 @@ static bool patch_nanokernel(void)
/*
// Disable FE0A/FE06 opcodes
lp = (uint32 *)(ROM_BASE + 0x3144ac);
lp = (uint32 *)(ROMBase + 0x3144ac);
*lp++ = htonl(POWERPC_NOP);
*lp += 8;
*/
@ -1754,10 +1754,10 @@ static bool patch_68k(void)
static const uint8 ext_cache_dat[] = {0x4e, 0x7b, 0x00, 0x02};
if ((base = find_rom_data(0x1d0, 0x230, ext_cache_dat, sizeof(ext_cache_dat))) == 0) return false;
D(bug("ext_cache %08lx\n", base));
loc = ReadMacInt32(ROM_BASE + base + 6);
loc = ReadMacInt32(ROMBase + base + 6);
wp = (uint16 *)(ROMBaseHost + loc + base + 6);
*wp = htons(M68K_RTS);
loc = ReadMacInt32(ROM_BASE + base + 12);
loc = ReadMacInt32(ROMBase + base + 12);
wp = (uint16 *)(ROMBaseHost + loc + base + 12);
*wp = htons(M68K_RTS);
@ -1788,7 +1788,7 @@ static bool patch_68k(void)
for (;;) {
D(bug(" %08lx\n", (uintptr)lp - (uintptr)ROMBaseHost));
while ((ntohl(*lp) & 0xff000000) == 0xff000000) {
*lp = htonl((ntohl(*lp) & (ROM_SIZE-1)) + ROM_BASE);
*lp = htonl((ntohl(*lp) & (ROM_SIZE-1)) + ROMBase);
lp++;
}
while (!ntohl(*lp)) lp++;
@ -2068,12 +2068,12 @@ static bool patch_68k(void)
D(bug("scsi_mgr %08lx\n", base));
wp = (uint16 *)(ROMBaseHost + base);
*wp++ = htons(0x21fc); // move.l #xxx,0x624 (SCSIAtomic)
*wp++ = htons((ROM_BASE + base + 18) >> 16);
*wp++ = htons((ROM_BASE + base + 18) & 0xffff);
*wp++ = htons((ROMBase + base + 18) >> 16);
*wp++ = htons((ROMBase + base + 18) & 0xffff);
*wp++ = htons(0x0624);
*wp++ = htons(0x21fc); // move.l #xxx,0xe54 (SCSIDispatch)
*wp++ = htons((ROM_BASE + base + 22) >> 16);
*wp++ = htons((ROM_BASE + base + 22) & 0xffff);
*wp++ = htons((ROMBase + base + 22) >> 16);
*wp++ = htons((ROMBase + base + 22) & 0xffff);
*wp++ = htons(0x0e54);
*wp++ = htons(M68K_RTS);
*wp++ = htons(M68K_EMUL_OP_SCSI_ATOMIC);
@ -2142,8 +2142,8 @@ static bool patch_68k(void)
D(bug("check_load %08lx\n", base));
wp = (uint16 *)(ROMBaseHost + base);
*wp++ = htons(M68K_JMP);
*wp++ = htons((ROM_BASE + CHECK_LOAD_PATCH_SPACE) >> 16);
*wp = htons((ROM_BASE + CHECK_LOAD_PATCH_SPACE) & 0xffff);
*wp++ = htons((ROMBase + CHECK_LOAD_PATCH_SPACE) >> 16);
*wp = htons((ROMBase + CHECK_LOAD_PATCH_SPACE) & 0xffff);
wp = (uint16 *)(ROMBaseHost + CHECK_LOAD_PATCH_SPACE);
*wp++ = htons(0x2f03); // move.l d3,-(a7)
*wp++ = htons(0x2078); // move.l $07f0,a0
@ -2173,19 +2173,19 @@ static bool patch_68k(void)
memcpy((void *)(ROMBaseHost + sony_offset + 0x200), cdrom_driver, sizeof(cdrom_driver));
// Install serial drivers
gen_ain_driver( ROM_BASE + sony_offset + 0x300);
gen_aout_driver(ROM_BASE + sony_offset + 0x400);
gen_bin_driver( ROM_BASE + sony_offset + 0x500);
gen_bout_driver(ROM_BASE + sony_offset + 0x600);
gen_ain_driver( ROMBase + sony_offset + 0x300);
gen_aout_driver(ROMBase + sony_offset + 0x400);
gen_bin_driver( ROMBase + sony_offset + 0x500);
gen_bout_driver(ROMBase + sony_offset + 0x600);
// Copy icons to ROM
SonyDiskIconAddr = ROM_BASE + sony_offset + 0x800;
SonyDiskIconAddr = ROMBase + sony_offset + 0x800;
memcpy(ROMBaseHost + sony_offset + 0x800, SonyDiskIcon, sizeof(SonyDiskIcon));
SonyDriveIconAddr = ROM_BASE + sony_offset + 0xa00;
SonyDriveIconAddr = ROMBase + sony_offset + 0xa00;
memcpy(ROMBaseHost + sony_offset + 0xa00, SonyDriveIcon, sizeof(SonyDriveIcon));
DiskIconAddr = ROM_BASE + sony_offset + 0xc00;
DiskIconAddr = ROMBase + sony_offset + 0xc00;
memcpy(ROMBaseHost + sony_offset + 0xc00, DiskIcon, sizeof(DiskIcon));
CDROMIconAddr = ROM_BASE + sony_offset + 0xe00;
CDROMIconAddr = ROMBase + sony_offset + 0xe00;
memcpy(ROMBaseHost + sony_offset + 0xe00, CDROMIcon, sizeof(CDROMIcon));
// Patch driver install routine
@ -2269,7 +2269,7 @@ static bool patch_68k(void)
static const uint8 via_int_dat[] = {0x70, 0x7f, 0xc0, 0x29, 0x1a, 0x00, 0xc0, 0x29, 0x1c, 0x00};
if ((base = find_rom_data(0x13000, 0x1c000, via_int_dat, sizeof(via_int_dat))) == 0) return false;
D(bug("via_int %08lx\n", base));
uint32 level1_int = ROM_BASE + base;
uint32 level1_int = ROMBase + base;
wp = (uint16 *)(ROMBaseHost + base); // Level 1 handler
*wp++ = htons(0x7002); // moveq #2,d0 (60Hz interrupt)
*wp++ = htons(M68K_NOP);
@ -2301,9 +2301,9 @@ static bool patch_68k(void)
wp = (uint16 *)(ROMBaseHost + PUT_SCRAP_PATCH_SPACE);
*wp++ = htons(M68K_EMUL_OP_PUT_SCRAP);
*wp++ = htons(M68K_JMP);
*wp++ = htons((ROM_BASE + put_scrap) >> 16);
*wp++ = htons((ROM_BASE + put_scrap) & 0xffff);
base = ROM_BASE + ReadMacInt32(ROM_BASE + 0x22);
*wp++ = htons((ROMBase + put_scrap) >> 16);
*wp++ = htons((ROMBase + put_scrap) & 0xffff);
base = ROMBase + ReadMacInt32(ROMBase + 0x22);
WriteMacInt32(base + 4 * (0xa9fe & 0x3ff), PUT_SCRAP_PATCH_SPACE);
// Patch GetScrap() for clipboard exchange with host OS
@ -2311,9 +2311,9 @@ static bool patch_68k(void)
wp = (uint16 *)(ROMBaseHost + GET_SCRAP_PATCH_SPACE);
*wp++ = htons(M68K_EMUL_OP_GET_SCRAP);
*wp++ = htons(M68K_JMP);
*wp++ = htons((ROM_BASE + get_scrap) >> 16);
*wp++ = htons((ROM_BASE + get_scrap) & 0xffff);
base = ROM_BASE + ReadMacInt32(ROM_BASE + 0x22);
*wp++ = htons((ROMBase + get_scrap) >> 16);
*wp++ = htons((ROMBase + get_scrap) & 0xffff);
base = ROMBase + ReadMacInt32(ROMBase + 0x22);
WriteMacInt32(base + 4 * (0xa9fd & 0x3ff), GET_SCRAP_PATCH_SPACE);
// Patch SynchIdleTime()
@ -2336,7 +2336,7 @@ static bool patch_68k(void)
D(bug("Searching for sound components with type sdev in ROM\n"));
uint32 thing = find_rom_resource(FOURCC('t','h','n','g'));
while (thing) {
thing += ROM_BASE;
thing += ROMBase;
D(bug(" found %c%c%c%c %c%c%c%c\n", ReadMacInt8(thing), ReadMacInt8(thing + 1), ReadMacInt8(thing + 2), ReadMacInt8(thing + 3), ReadMacInt8(thing + 4), ReadMacInt8(thing + 5), ReadMacInt8(thing + 6), ReadMacInt8(thing + 7)));
if (ReadMacInt32(thing) == FOURCC('s','d','e','v') && ReadMacInt32(thing + 4) == FOURCC('s','i','n','g')) {
WriteMacInt32(thing + 4, FOURCC('a','w','g','c'));
@ -2394,13 +2394,13 @@ void InstallDrivers(void)
if (ROMType == ROMTYPE_NEWWORLD || ROMType == ROMTYPE_GOSSAMER) {
// Force installation of floppy driver with NewWorld and Gossamer ROMs
r.a[0] = ROM_BASE + sony_offset;
r.a[0] = ROMBase + sony_offset;
r.d[0] = (uint32)SonyRefNum;
Execute68kTrap(0xa43d, &r); // DrvrInstallRsrvMem()
r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~SonyRefNum * 4); // Get driver handle from Unit Table
Execute68kTrap(0xa029, &r); // HLock()
uint32 dce = ReadMacInt32(r.a[0]);
WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset);
WriteMacInt32(dce + dCtlDriver, ROMBase + sony_offset);
WriteMacInt16(dce + dCtlFlags, SonyDriverFlags);
}
@ -2412,13 +2412,13 @@ void InstallDrivers(void)
Execute68kTrap(0xa000, &r); // Open()
// Install disk driver
r.a[0] = ROM_BASE + sony_offset + 0x100;
r.a[0] = ROMBase + sony_offset + 0x100;
r.d[0] = (uint32)DiskRefNum;
Execute68kTrap(0xa43d, &r); // DrvrInstallRsrvMem()
r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~DiskRefNum * 4); // Get driver handle from Unit Table
Execute68kTrap(0xa029, &r); // HLock()
uint32 dce = ReadMacInt32(r.a[0]);
WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset + 0x100);
WriteMacInt32(dce + dCtlDriver, ROMBase + sony_offset + 0x100);
WriteMacInt16(dce + dCtlFlags, DiskDriverFlags);
// Open disk driver
@ -2431,13 +2431,13 @@ void InstallDrivers(void)
if (!PrefsFindBool("nocdrom")) {
// Install CD-ROM driver
r.a[0] = ROM_BASE + sony_offset + 0x200;
r.a[0] = ROMBase + sony_offset + 0x200;
r.d[0] = (uint32)CDROMRefNum;
Execute68kTrap(0xa43d, &r); // DrvrInstallRsrvMem()
r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~CDROMRefNum * 4); // Get driver handle from Unit Table
Execute68kTrap(0xa029, &r); // HLock()
dce = ReadMacInt32(r.a[0]);
WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset + 0x200);
WriteMacInt32(dce + dCtlDriver, ROMBase + sony_offset + 0x200);
WriteMacInt16(dce + dCtlFlags, CDROMDriverFlags);
// Open CD-ROM driver
@ -2448,39 +2448,39 @@ void InstallDrivers(void)
}
// Install serial drivers
r.a[0] = ROM_BASE + sony_offset + 0x300;
r.a[0] = ROMBase + sony_offset + 0x300;
r.d[0] = (uint32)-6;
Execute68kTrap(0xa43d, &r); // DrvrInstallRsrvMem()
r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~(-6) * 4); // Get driver handle from Unit Table
Execute68kTrap(0xa029, &r); // HLock()
dce = ReadMacInt32(r.a[0]);
WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset + 0x300);
WriteMacInt32(dce + dCtlDriver, ROMBase + sony_offset + 0x300);
WriteMacInt16(dce + dCtlFlags, 0x4d00);
r.a[0] = ROM_BASE + sony_offset + 0x400;
r.a[0] = ROMBase + sony_offset + 0x400;
r.d[0] = (uint32)-7;
Execute68kTrap(0xa43d, &r); // DrvrInstallRsrvMem()
r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~(-7) * 4); // Get driver handle from Unit Table
Execute68kTrap(0xa029, &r); // HLock()
dce = ReadMacInt32(r.a[0]);
WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset + 0x400);
WriteMacInt32(dce + dCtlDriver, ROMBase + sony_offset + 0x400);
WriteMacInt16(dce + dCtlFlags, 0x4e00);
r.a[0] = ROM_BASE + sony_offset + 0x500;
r.a[0] = ROMBase + sony_offset + 0x500;
r.d[0] = (uint32)-8;
Execute68kTrap(0xa43d, &r); // DrvrInstallRsrvMem()
r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~(-8) * 4); // Get driver handle from Unit Table
Execute68kTrap(0xa029, &r); // HLock()
dce = ReadMacInt32(r.a[0]);
WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset + 0x500);
WriteMacInt32(dce + dCtlDriver, ROMBase + sony_offset + 0x500);
WriteMacInt16(dce + dCtlFlags, 0x4d00);
r.a[0] = ROM_BASE + sony_offset + 0x600;
r.a[0] = ROMBase + sony_offset + 0x600;
r.d[0] = (uint32)-9;
Execute68kTrap(0xa43d, &r); // DrvrInstallRsrvMem()
r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~(-9) * 4); // Get driver handle from Unit Table
Execute68kTrap(0xa029, &r); // HLock()
dce = ReadMacInt32(r.a[0]);
WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset + 0x600);
WriteMacInt32(dce + dCtlDriver, ROMBase + sony_offset + 0x600);
WriteMacInt16(dce + dCtlFlags, 0x4e00);
}

View File

@ -929,7 +929,7 @@ void PatchNativeResourceManager(void)
// Patch native GetResource()
uint32 upp = ReadMacInt32(0x1480);
if ((upp & 0xffc00000) == ROM_BASE)
if ((upp & 0xffc00000) == ROMBase)
return;
uint32 tvec = ReadMacInt32(upp + 5 * 4);
D(bug(" GetResource() entry %08x, TOC %08x\n", ReadMacInt32(tvec), ReadMacInt32(tvec + 4)));