192
193
static bool lm_area_mapped = false; // Flag: Low Memory area mmap()ped
196
static rpc_connection_t *gui_connection = NULL; // RPC connection to the GUI
197
static const char *gui_connection_path = NULL; // GUI connection identifier
197
201
static void *xpram_func(void *arg);
226
* Map memory that can be accessed from the Mac side
230
* Helpers to map memory that can be accessed from the Mac side
233
// NOTE: VM_MAP_33BIT is only used when compiling a 64-bit JIT on specific platforms
229
234
void *vm_acquire_mac(size_t size)
231
236
void *m = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_33BIT);
237
#ifdef USE_33BIT_ADDRESSING
238
if (m == VM_MAP_FAILED) {
239
printf("WARNING: Cannot acquire memory in 33-bit address space (%s)\n", strerror(errno));
233
240
ThirtyThreeBitAddressing = false;
234
241
m = vm_acquire(size);
247
static int vm_acquire_mac_fixed(void *addr, size_t size)
249
int ret = vm_acquire_fixed(addr, size, VM_MAP_DEFAULT | VM_MAP_33BIT);
250
#ifdef USE_33BIT_ADDRESSING
252
printf("WARNING: Cannot acquire fixed memory in 33-bit address space (%s)\n", strerror(errno));
253
ThirtyThreeBitAddressing = false;
254
ret = vm_acquire_fixed(addr, size);
241
262
* SIGSEGV handler
397
418
x_display_name = strdup(argv[i]);
420
} else if (strcmp(argv[i], "--gui-connection") == 0) {
423
gui_connection_path = argv[i];
399
426
} else if (strcmp(argv[i], "--break") == 0) {
400
427
argv[i++] = NULL;
459
// Connect to the external GUI
460
if (gui_connection_path) {
461
if ((gui_connection = rpc_init_client(gui_connection_path)) == NULL) {
462
fprintf(stderr, "Failed to initialize RPC client connection to the GUI\n");
432
467
#ifdef ENABLE_GTK
468
if (!gui_connection) {
433
469
#ifdef HAVE_GNOMEUI
436
sprintf(version, "%d.%d", VERSION_MAJOR, VERSION_MINOR);
437
gnome_init("Basilisk II", version, argc, argv);
472
sprintf(version, "%d.%d", VERSION_MAJOR, VERSION_MINOR);
473
gnome_init("Basilisk II", version, argc, argv);
441
gtk_init(&argc, &argv);
477
gtk_init(&argc, &argv);
445
482
// Read preferences
512
549
WarningAlert(GetString(STR_SMALL_RAM_WARN));
513
550
RAMSize = 1024*1024;
552
if (RAMSize > 1023*1024*1024) // Cap to 1023MB (APD crashes at 1GB)
553
RAMSize = 1023*1024*1024;
516
555
#if REAL_ADDRESSING || DIRECT_ADDRESSING
517
556
RAMSize = RAMSize & -getpagesize(); // Round down to page boundary
520
559
// Initialize VM system
562
#ifdef USE_33BIT_ADDRESSING
563
// Speculatively enables 33-bit addressing
564
ThirtyThreeBitAddressing = true;
523
567
#if REAL_ADDRESSING
524
568
// Flag: RAM and ROM are contigously allocated from address 0
525
569
bool memory_mapped_from_zero = false;
527
// Under Solaris/SPARC and NetBSD/m68k, Basilisk II is known to crash
528
// when trying to map a too big chunk of memory starting at address 0
529
#if defined(OS_solaris) || defined(OS_netbsd) || defined(PAGEZERO_HACK)
571
// Make sure to map RAM & ROM at address 0 only on platforms that
572
// supports linker scripts to relocate the Basilisk II executable
574
#if HAVE_LINKER_SCRIPT
575
const bool can_map_all_memory = true;
530
577
const bool can_map_all_memory = false;
532
const bool can_map_all_memory = true;
535
580
// Try to allocate all memory from 0x0000, if it is not known to crash
536
if (can_map_all_memory && (vm_acquire_fixed(0, RAMSize + 0x100000) == 0)) {
581
if (can_map_all_memory && (vm_acquire_mac_fixed(0, RAMSize + 0x100000) == 0)) {
537
582
D(bug("Could allocate RAM and ROM from 0x0000\n"));
538
583
memory_mapped_from_zero = true;
541
586
#ifndef PAGEZERO_HACK
542
587
// Otherwise, just create the Low Memory area (0x0000..0x2000)
543
else if (vm_acquire_fixed(0, 0x2000) == 0) {
588
else if (vm_acquire_mac_fixed(0, 0x2000) == 0) {
544
589
D(bug("Could allocate the Low Memory globals\n"));
545
590
lm_area_mapped = true;
566
#ifdef USE_33BIT_ADDRESSING
567
// Speculatively enables 33-bit addressing
568
ThirtyThreeBitAddressing = true;
570
611
uint8 *ram_rom_area = (uint8 *)vm_acquire_mac(RAMSize + 0x100000);
571
612
if (ram_rom_area == VM_MAP_FAILED) {
572
613
ErrorAlert(STR_NO_MEM_ERR);
579
620
#if USE_SCRATCHMEM_SUBTERFUGE
580
621
// Allocate scratch memory
581
ScratchMem = (uint8 *)vm_acquire(SCRATCH_MEM_SIZE);
622
ScratchMem = (uint8 *)vm_acquire_mac(SCRATCH_MEM_SIZE);
582
623
if (ScratchMem == VM_MAP_FAILED) {
583
624
ErrorAlert(STR_NO_MEM_ERR);
593
634
ROMBaseMac = Host2MacAddr(ROMBaseHost);
595
636
#if REAL_ADDRESSING
596
RAMBaseMac = (uint32)RAMBaseHost;
597
ROMBaseMac = (uint32)ROMBaseHost;
637
RAMBaseMac = Host2MacAddr(RAMBaseHost);
638
ROMBaseMac = Host2MacAddr(ROMBaseHost);
599
640
D(bug("Mac RAM starts at %p (%08x)\n", RAMBaseHost, RAMBaseMac));
600
641
D(bug("Mac ROM starts at %p (%08x)\n", ROMBaseHost, ROMBaseMac));
885
926
XCloseDisplay(x_display);
929
// Notify GUI we are about to leave
930
if (gui_connection) {
931
if (rpc_method_invoke(gui_connection, RPC_METHOD_EXIT, RPC_TYPE_INVALID) == RPC_ERROR_NO_ERROR)
932
rpc_method_wait_for_reply(gui_connection, RPC_TYPE_INVALID);
901
flush_icache_range((uintptr)start, size);
948
flush_icache_range((uint8 *)start, size);
903
950
#if !EMULATED_68K && defined(__NetBSD__)
904
951
m68k_sync_icache(start, size);
1526
1573
void ErrorAlert(const char *text)
1575
if (gui_connection) {
1576
if (rpc_method_invoke(gui_connection, RPC_METHOD_ERROR_ALERT, RPC_TYPE_STRING, text, RPC_TYPE_INVALID) == RPC_ERROR_NO_ERROR &&
1577
rpc_method_wait_for_reply(gui_connection, RPC_TYPE_INVALID) == RPC_ERROR_NO_ERROR)
1528
1580
#if defined(ENABLE_GTK) && !defined(USE_SDL_VIDEO)
1529
1581
if (PrefsFindBool("nogui") || x_display == NULL) {
1530
1582
printf(GetString(STR_SHELL_ERROR_PREFIX), text);
1545
1597
void WarningAlert(const char *text)
1599
if (gui_connection) {
1600
if (rpc_method_invoke(gui_connection, RPC_METHOD_WARNING_ALERT, RPC_TYPE_STRING, text, RPC_TYPE_INVALID) == RPC_ERROR_NO_ERROR &&
1601
rpc_method_wait_for_reply(gui_connection, RPC_TYPE_INVALID) == RPC_ERROR_NO_ERROR)
1547
1604
#if defined(ENABLE_GTK) && !defined(USE_SDL_VIDEO)
1548
1605
if (PrefsFindBool("nogui") || x_display == NULL) {
1549
1606
printf(GetString(STR_SHELL_WARNING_PREFIX), text);