Fix vm_acquire_mac() fallback to non 33-bit addressing mode. Support 33-bit

addressing in REAL_ADDRESSING mode. Only support platforms with proper
linker scripts to map the whole Mac memory from address 0. Warning fix.

NOTE: when compiled with --enable-addressing=real on Linux {x86,x86_64},
you can not address up to 1.5 GB in Basilisk II.
This commit is contained in:
gbeauche 2006-02-27 00:15:39 +00:00
parent 2ef9d6e708
commit 93d918097b

View File

@ -229,13 +229,25 @@ char *strdup(const char *s)
void *vm_acquire_mac(size_t size) void *vm_acquire_mac(size_t size)
{ {
void *m = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_33BIT); void *m = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_33BIT);
if (m == NULL) { if (m == VM_MAP_FAILED) {
printf("WARNING: Cannot acquire memory in 33-bit address space (%s)\n", strerror(errno));
ThirtyThreeBitAddressing = false; ThirtyThreeBitAddressing = false;
m = vm_acquire(size); m = vm_acquire(size);
} }
return m; return m;
} }
static int vm_acquire_mac_fixed(void *addr, size_t size)
{
int ret = vm_acquire_fixed(addr, size, VM_MAP_DEFAULT | VM_MAP_33BIT);
if (ret < 0) {
printf("WARNING: Cannot acquire fixed memory in 33-bit address space (%s)\n", strerror(errno));
ThirtyThreeBitAddressing = false;
ret = vm_acquire_fixed(addr, size);
}
return ret;
}
/* /*
* SIGSEGV handler * SIGSEGV handler
@ -520,27 +532,33 @@ int main(int argc, char **argv)
// Initialize VM system // Initialize VM system
vm_init(); vm_init();
#ifdef USE_33BIT_ADDRESSING
// Speculatively enables 33-bit addressing
ThirtyThreeBitAddressing = true;
#endif
#if REAL_ADDRESSING #if REAL_ADDRESSING
// Flag: RAM and ROM are contigously allocated from address 0 // Flag: RAM and ROM are contigously allocated from address 0
bool memory_mapped_from_zero = false; bool memory_mapped_from_zero = false;
// Under Solaris/SPARC and NetBSD/m68k, Basilisk II is known to crash // Make sure to map RAM & ROM at address 0 only on platforms that
// when trying to map a too big chunk of memory starting at address 0 // supports linker scripts to relocate the Basilisk II executable
#if defined(OS_solaris) || defined(OS_netbsd) || defined(PAGEZERO_HACK) // above 0x70000000
const bool can_map_all_memory = false; #if HAVE_LINKER_SCRIPT
#else
const bool can_map_all_memory = true; const bool can_map_all_memory = true;
#else
const bool can_map_all_memory = false;
#endif #endif
// Try to allocate all memory from 0x0000, if it is not known to crash // Try to allocate all memory from 0x0000, if it is not known to crash
if (can_map_all_memory && (vm_acquire_fixed(0, RAMSize + 0x100000) == 0)) { if (can_map_all_memory && (vm_acquire_mac_fixed(0, RAMSize + 0x100000) == 0)) {
D(bug("Could allocate RAM and ROM from 0x0000\n")); D(bug("Could allocate RAM and ROM from 0x0000\n"));
memory_mapped_from_zero = true; memory_mapped_from_zero = true;
} }
#ifndef PAGEZERO_HACK #ifndef PAGEZERO_HACK
// Otherwise, just create the Low Memory area (0x0000..0x2000) // Otherwise, just create the Low Memory area (0x0000..0x2000)
else if (vm_acquire_fixed(0, 0x2000) == 0) { else if (vm_acquire_mac_fixed(0, 0x2000) == 0) {
D(bug("Could allocate the Low Memory globals\n")); D(bug("Could allocate the Low Memory globals\n"));
lm_area_mapped = true; lm_area_mapped = true;
} }
@ -563,10 +581,6 @@ int main(int argc, char **argv)
else else
#endif #endif
{ {
#ifdef USE_33BIT_ADDRESSING
// Speculatively enables 33-bit addressing
ThirtyThreeBitAddressing = true;
#endif
uint8 *ram_rom_area = (uint8 *)vm_acquire_mac(RAMSize + 0x100000); uint8 *ram_rom_area = (uint8 *)vm_acquire_mac(RAMSize + 0x100000);
if (ram_rom_area == VM_MAP_FAILED) { if (ram_rom_area == VM_MAP_FAILED) {
ErrorAlert(STR_NO_MEM_ERR); ErrorAlert(STR_NO_MEM_ERR);
@ -593,8 +607,8 @@ int main(int argc, char **argv)
ROMBaseMac = Host2MacAddr(ROMBaseHost); ROMBaseMac = Host2MacAddr(ROMBaseHost);
#endif #endif
#if REAL_ADDRESSING #if REAL_ADDRESSING
RAMBaseMac = (uint32)RAMBaseHost; RAMBaseMac = Host2MacAddr(RAMBaseHost);
ROMBaseMac = (uint32)ROMBaseHost; ROMBaseMac = Host2MacAddr(ROMBaseHost);
#endif #endif
D(bug("Mac RAM starts at %p (%08x)\n", RAMBaseHost, RAMBaseMac)); D(bug("Mac RAM starts at %p (%08x)\n", RAMBaseHost, RAMBaseMac));
D(bug("Mac ROM starts at %p (%08x)\n", ROMBaseHost, ROMBaseMac)); D(bug("Mac ROM starts at %p (%08x)\n", ROMBaseHost, ROMBaseMac));