macemu/SheepShaver/src/name_registry.cpp

369 lines
14 KiB
C++
Raw Permalink Normal View History

2002-02-04 16:58:13 +00:00
/*
* name_registry.cpp - Name Registry handling
*
2010-02-21 09:59:14 +00:00
* SheepShaver (C) Christian Bauer and Marc Hellwig
2002-02-04 16:58:13 +00:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <string.h>
#include "sysdeps.h"
#include "name_registry.h"
#include "main.h"
#include "macos_util.h"
#include "user_strings.h"
#include "emul_op.h"
#include "thunks.h"
2002-02-04 16:58:13 +00:00
#define DEBUG 0
#include "debug.h"
// Function pointers
typedef int16 (*rcec_ptr)(const RegEntryID *, const char *, RegEntryID *);
static uint32 rcec_tvect = 0;
static inline int16 RegistryCStrEntryCreate(uintptr arg1, const char *arg2, uint32 arg3)
2002-02-04 16:58:13 +00:00
{
SheepString arg2str(arg2);
return (int16)CallMacOS3(rcec_ptr, rcec_tvect, (const RegEntryID *)arg1, arg2str.addr(), arg3);
2002-02-04 16:58:13 +00:00
}
typedef int16 (*rpc_ptr)(const RegEntryID *, const char *, const void *, uint32);
static uint32 rpc_tvect = 0;
static inline int16 RegistryPropertyCreate(uintptr arg1, const char *arg2, uintptr arg3, uint32 arg4)
2002-02-04 16:58:13 +00:00
{
SheepString arg2str(arg2);
return (int16)CallMacOS4(rpc_ptr, rpc_tvect, (const RegEntryID *)arg1, arg2str.addr(), (const void *)arg3, arg4);
}
static inline int16 RegistryPropertyCreateStr(uintptr arg1, const char *arg2, const char *arg3)
{
SheepString arg3str(arg3);
return RegistryPropertyCreate(arg1, arg2, arg3str.addr(), strlen(arg3) + 1);
2002-02-04 16:58:13 +00:00
}
// Video driver stub
static const uint8 video_driver[] = {
#include "VideoDriverStub.i"
};
// Ethernet driver stub
static const uint8 ethernet_driver[] = {
#ifdef USE_ETHER_FULL_DRIVER
#include "EthernetDriverFull.i"
#else
2002-02-04 16:58:13 +00:00
#include "EthernetDriverStub.i"
#endif
2002-02-04 16:58:13 +00:00
};
// Helper for RegEntryID
typedef SheepArray<sizeof(RegEntryID)> SheepRegEntryID;
// Helper for a <uint32, uint32> pair
struct SheepPair : public SheepArray<8> {
SheepPair(uint32 base, uint32 size) : SheepArray<8>()
{ WriteMacInt32(addr(), base); WriteMacInt32(addr() + 4, size); }
};
2002-02-04 16:58:13 +00:00
/*
* Patch Name Registry during startup
*/
void DoPatchNameRegistry(void)
2002-02-04 16:58:13 +00:00
{
SheepVar32 u32;
2002-02-04 16:58:13 +00:00
D(bug("Patching Name Registry..."));
// Create "device-tree"
SheepRegEntryID device_tree;
if (!RegistryCStrEntryCreate(0, "Devices:device-tree", device_tree.addr())) {
u32.set_value(BusClockSpeed);
RegistryPropertyCreate(device_tree.addr(), "clock-frequency", u32.addr(), 4);
RegistryPropertyCreateStr(device_tree.addr(), "model", "Power Macintosh");
2002-02-04 16:58:13 +00:00
// Create "AAPL,ROM"
SheepRegEntryID aapl_rom;
if (!RegistryCStrEntryCreate(device_tree.addr(), "AAPL,ROM", aapl_rom.addr())) {
RegistryPropertyCreateStr(aapl_rom.addr(), "device_type", "rom");
[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.
2009-08-18 18:26:11 +00:00
SheepPair reg(ROMBase, ROM_SIZE);
RegistryPropertyCreate(aapl_rom.addr(), "reg", reg.addr(), 8);
2002-02-04 16:58:13 +00:00
}
// Create "PowerPC,60x"
SheepRegEntryID power_pc;
2010-02-21 09:59:14 +00:00
const char *str;
2002-02-04 16:58:13 +00:00
switch (PVR >> 16) {
case 1: // 601
str = "PowerPC,601";
break;
case 3: // 603
str = "PowerPC,603";
break;
case 4: // 604
str = "PowerPC,604";
break;
case 6: // 603e
str = "PowerPC,603e";
break;
case 7: // 603ev
str = "PowerPC,603ev";
break;
case 8: // 750
str = "PowerPC,750";
break;
case 9: // 604e
str = "PowerPC,604e";
break;
case 10: // 604ev5
str = "PowerPC,604ev";
break;
case 50: // 821
str = "PowerPC,821";
break;
case 80: // 860
str = "PowerPC,860";
break;
2005-01-30 21:13:23 +00:00
case 12: // 7400, 7410, 7450, 7455, 7457
case 0x800c:
case 0x8000:
case 0x8001:
case 0x8002:
str = "PowerPC,G4";
break;
2002-02-04 16:58:13 +00:00
default:
str = "PowerPC,???";
break;
}
if (!RegistryCStrEntryCreate(device_tree.addr(), str, power_pc.addr())) {
u32.set_value(CPUClockSpeed);
RegistryPropertyCreate(power_pc.addr(), "clock-frequency", u32.addr(), 4);
u32.set_value(BusClockSpeed);
RegistryPropertyCreate(power_pc.addr(), "bus-frequency", u32.addr(), 4);
u32.set_value(TimebaseSpeed);
RegistryPropertyCreate(power_pc.addr(), "timebase-frequency", u32.addr(), 4);
u32.set_value(PVR);
RegistryPropertyCreate(power_pc.addr(), "cpu-version", u32.addr(), 4);
RegistryPropertyCreateStr(power_pc.addr(), "device_type", "cpu");
2002-02-04 16:58:13 +00:00
switch (PVR >> 16) {
case 1: // 601
u32.set_value(64);
RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
u32.set_value(0x8000);
RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
u32.set_value(64);
RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
u32.set_value(0x8000);
RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
u32.set_value(256);
RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
2002-02-04 16:58:13 +00:00
break;
case 3: // 603
u32.set_value(32);
RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
u32.set_value(64);
RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
u32.set_value(0x2000);
RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
u32.set_value(32);
RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
u32.set_value(64);
RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
u32.set_value(0x2000);
RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
u32.set_value(32);
RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
u32.set_value(64);
RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
2002-02-04 16:58:13 +00:00
break;
case 4: // 604
u32.set_value(32);
RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
u32.set_value(0x4000);
RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
u32.set_value(32);
RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
u32.set_value(0x4000);
RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
u32.set_value(64);
RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
2002-02-04 16:58:13 +00:00
break;
case 6: // 603e
case 7: // 603ev
u32.set_value(32);
RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
u32.set_value(0x4000);
RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
u32.set_value(32);
RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
u32.set_value(0x4000);
RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
u32.set_value(32);
RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
u32.set_value(64);
RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
2002-02-04 16:58:13 +00:00
break;
2004-06-29 20:25:55 +00:00
case 8: // 750, 750FX
case 0x7000:
u32.set_value(32);
RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
u32.set_value(256);
RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
u32.set_value(0x8000);
RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
u32.set_value(32);
RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
u32.set_value(256);
RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
u32.set_value(0x8000);
RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
u32.set_value(64);
RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
2002-02-04 16:58:13 +00:00
break;
case 9: // 604e
case 10: // 604ev5
u32.set_value(32);
RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
u32.set_value(256);
RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
u32.set_value(0x8000);
RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
u32.set_value(32);
RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
u32.set_value(256);
RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
u32.set_value(0x8000);
RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
u32.set_value(64);
RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
2002-02-04 16:58:13 +00:00
break;
2004-06-29 20:25:55 +00:00
case 12: // 7400, 7410, 7450, 7455, 7457
case 0x800c:
2004-06-29 20:25:55 +00:00
case 0x8000:
case 0x8001:
case 0x8002:
2004-01-31 11:10:49 +00:00
u32.set_value(32);
RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
2004-01-31 11:10:49 +00:00
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
2004-01-31 11:10:49 +00:00
u32.set_value(0x8000);
RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
2004-01-31 11:10:49 +00:00
u32.set_value(32);
RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
2004-01-31 11:10:49 +00:00
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
2004-01-31 11:10:49 +00:00
u32.set_value(0x8000);
RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
2004-01-31 11:10:49 +00:00
u32.set_value(64);
RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
2004-01-31 11:10:49 +00:00
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
2004-01-31 11:10:49 +00:00
break;
case 0x39: // 970
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
u32.set_value(0x8000);
RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
u32.set_value(128);
RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
u32.set_value(512);
RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
u32.set_value(0x10000);
RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
u32.set_value(256);
RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
u32.set_value(0x1000);
RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
break;
2002-02-04 16:58:13 +00:00
default:
break;
}
u32.set_value(32);
RegistryPropertyCreate(power_pc.addr(), "reservation-granularity", u32.addr(), 4);
SheepPair reg(0, 0);
RegistryPropertyCreate(power_pc.addr(), "reg", reg.addr(), 8);
2002-02-04 16:58:13 +00:00
}
// Create "memory"
SheepRegEntryID memory;
if (!RegistryCStrEntryCreate(device_tree.addr(), "memory", memory.addr())) {
SheepPair reg(RAMBase, RAMSize);
RegistryPropertyCreateStr(memory.addr(), "device_type", "memory");
RegistryPropertyCreate(memory.addr(), "reg", reg.addr(), 8);
2002-02-04 16:58:13 +00:00
}
// Create "video"
SheepRegEntryID video;
if (!RegistryCStrEntryCreate(device_tree.addr(), "video", video.addr())) {
RegistryPropertyCreateStr(video.addr(), "AAPL,connector", "monitor");
RegistryPropertyCreateStr(video.addr(), "device_type", "display");
SheepArray<sizeof(video_driver)> the_video_driver;
Host2Mac_memcpy(the_video_driver.addr(), video_driver, sizeof(video_driver));
RegistryPropertyCreate(video.addr(), "driver,AAPL,MacOS,PowerPC", the_video_driver.addr(), sizeof(video_driver));
RegistryPropertyCreateStr(video.addr(), "model", "SheepShaver Video");
2002-02-04 16:58:13 +00:00
}
// Create "ethernet"
SheepRegEntryID ethernet;
if (!RegistryCStrEntryCreate(device_tree.addr(), "ethernet", ethernet.addr())) {
RegistryPropertyCreateStr(ethernet.addr(), "AAPL,connector", "ethernet");
RegistryPropertyCreateStr(ethernet.addr(), "device_type", "network");
SheepArray<sizeof(ethernet_driver)> the_ethernet_driver;
Host2Mac_memcpy(the_ethernet_driver.addr(), ethernet_driver, sizeof(ethernet_driver));
RegistryPropertyCreate(ethernet.addr(), "driver,AAPL,MacOS,PowerPC", the_ethernet_driver.addr(), sizeof(ethernet_driver));
2002-02-04 16:58:13 +00:00
// local-mac-address
// max-frame-size 2048
}
}
D(bug("done.\n"));
}
void PatchNameRegistry(void)
{
// Find RegistryCStrEntryCreate() and RegistryPropertyCreate() TVECTs
rcec_tvect = FindLibSymbol("\017NameRegistryLib", "\027RegistryCStrEntryCreate");
2002-02-04 16:58:13 +00:00
D(bug("RegistryCStrEntryCreate TVECT at %08x\n", rcec_tvect));
rpc_tvect = FindLibSymbol("\017NameRegistryLib", "\026RegistryPropertyCreate");
2002-02-04 16:58:13 +00:00
D(bug("RegistryPropertyCreate TVECT at %08x\n", rpc_tvect));
if (rcec_tvect == 0 || rpc_tvect == 0) {
ErrorAlert(GetString(STR_NO_NAME_REGISTRY_ERR));
QuitEmulator();
}
// Main routine must be executed in PPC mode
ExecuteNative(NATIVE_PATCH_NAME_REGISTRY);
2002-02-04 16:58:13 +00:00
}