~ubuntu-branches/ubuntu/feisty/basilisk2/feisty

« back to all changes in this revision

Viewing changes to src/Unix/main_unix.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2006-06-01 01:11:16 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060601011116-xjhegbgyfsxag5fl
Tags: 0.9.20060529-1
* New upstream CVS snapshot.
* Update local cdbs snippet copyright-check.mk:
  + Broaden scan to also look for "(c)" by default.
  + Make egrep options configurable.
  + Ignore auto-tools files.
* Bump up standards-version to 3.7.2 (no changes needed).
* Let dh_strip do the stripping (not the make install target).

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
#include "main.h"
87
87
#include "vm_alloc.h"
88
88
#include "sigsegv.h"
 
89
#include "rpc.h"
89
90
 
90
91
#if USE_JIT
91
 
extern void flush_icache_range(uint32 start, uint32 size); // from compemu_support.cpp
 
92
extern void flush_icache_range(uint8 *start, uint32 size); // from compemu_support.cpp
92
93
#endif
93
94
 
94
95
#ifdef ENABLE_MON
192
193
static bool lm_area_mapped = false;     // Flag: Low Memory area mmap()ped
193
194
#endif
194
195
 
 
196
static rpc_connection_t *gui_connection = NULL; // RPC connection to the GUI
 
197
static const char *gui_connection_path = NULL;  // GUI connection identifier
 
198
 
195
199
 
196
200
// Prototypes
197
201
static void *xpram_func(void *arg);
223
227
 
224
228
 
225
229
/*
226
 
 *  Map memory that can be accessed from the Mac side
 
230
 *  Helpers to map memory that can be accessed from the Mac side
227
231
 */
228
232
 
 
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)
230
235
{
231
236
        void *m = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_33BIT);
232
 
        if (m == NULL) {
 
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);
235
242
        }
 
243
#endif
236
244
        return m;
237
245
}
238
246
 
 
247
static int vm_acquire_mac_fixed(void *addr, size_t size)
 
248
{
 
249
        int ret = vm_acquire_fixed(addr, size, VM_MAP_DEFAULT | VM_MAP_33BIT);
 
250
#ifdef USE_33BIT_ADDRESSING
 
251
        if (ret < 0) {
 
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);
 
255
        }
 
256
#endif
 
257
        return ret;
 
258
}
 
259
 
239
260
 
240
261
/*
241
262
 *  SIGSEGV handler
396
417
                        if (i < argc)
397
418
                                x_display_name = strdup(argv[i]);
398
419
#endif
 
420
                } else if (strcmp(argv[i], "--gui-connection") == 0) {
 
421
                        argv[i++] = NULL;
 
422
                        if (i < argc) {
 
423
                                gui_connection_path = argv[i];
 
424
                                argv[i] = NULL;
 
425
                        }
399
426
                } else if (strcmp(argv[i], "--break") == 0) {
400
427
                        argv[i++] = NULL;
401
428
                        if (i < argc) {
429
456
                }
430
457
        }
431
458
 
 
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");
 
463
                        return 1;
 
464
                }
 
465
        }
 
466
 
432
467
#ifdef ENABLE_GTK
 
468
        if (!gui_connection) {
433
469
#ifdef HAVE_GNOMEUI
434
 
        // Init GNOME/GTK
435
 
        char version[16];
436
 
        sprintf(version, "%d.%d", VERSION_MAJOR, VERSION_MINOR);
437
 
        gnome_init("Basilisk II", version, argc, argv);
 
470
                // Init GNOME/GTK
 
471
                char version[16];
 
472
                sprintf(version, "%d.%d", VERSION_MAJOR, VERSION_MINOR);
 
473
                gnome_init("Basilisk II", version, argc, argv);
438
474
#else
439
 
        // Init GTK
440
 
        gtk_set_locale();
441
 
        gtk_init(&argc, &argv);
 
475
                // Init GTK
 
476
                gtk_set_locale();
 
477
                gtk_init(&argc, &argv);
442
478
#endif
 
479
        }
443
480
#endif
444
481
 
445
482
        // Read preferences
492
529
        SysInit();
493
530
 
494
531
        // Show preferences editor
495
 
        if (!PrefsFindBool("nogui"))
 
532
        if (!gui_connection && !PrefsFindBool("nogui"))
496
533
                if (!PrefsEditor())
497
534
                        QuitEmulator();
498
535
 
512
549
                WarningAlert(GetString(STR_SMALL_RAM_WARN));
513
550
                RAMSize = 1024*1024;
514
551
        }
 
552
        if (RAMSize > 1023*1024*1024)                                           // Cap to 1023MB (APD crashes at 1GB)
 
553
                RAMSize = 1023*1024*1024;
515
554
 
516
555
#if REAL_ADDRESSING || DIRECT_ADDRESSING
517
556
        RAMSize = RAMSize & -getpagesize();                                     // Round down to page boundary
520
559
        // Initialize VM system
521
560
        vm_init();
522
561
 
 
562
#ifdef USE_33BIT_ADDRESSING
 
563
        // Speculatively enables 33-bit addressing
 
564
        ThirtyThreeBitAddressing = true;
 
565
#endif
 
566
 
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;
526
 
        
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)
 
570
 
 
571
        // Make sure to map RAM & ROM at address 0 only on platforms that
 
572
        // supports linker scripts to relocate the Basilisk II executable
 
573
        // above 0x70000000
 
574
#if HAVE_LINKER_SCRIPT
 
575
        const bool can_map_all_memory = true;
 
576
#else
530
577
        const bool can_map_all_memory = false;
531
 
#else
532
 
        const bool can_map_all_memory = true;
533
578
#endif
534
579
        
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;
539
584
        }
540
585
        
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;
546
591
        }
563
608
        else
564
609
#endif
565
610
        {
566
 
#ifdef USE_33BIT_ADDRESSING
567
 
                // Speculatively enables 33-bit addressing
568
 
                ThirtyThreeBitAddressing = true;
569
 
#endif
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);
578
619
 
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);
584
625
                QuitEmulator();
593
634
        ROMBaseMac = Host2MacAddr(ROMBaseHost);
594
635
#endif
595
636
#if REAL_ADDRESSING
596
 
        RAMBaseMac = (uint32)RAMBaseHost;
597
 
        ROMBaseMac = (uint32)ROMBaseHost;
 
637
        RAMBaseMac = Host2MacAddr(RAMBaseHost);
 
638
        ROMBaseMac = Host2MacAddr(ROMBaseHost);
598
639
#endif
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);
886
927
#endif
887
928
 
 
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);
 
933
        }
 
934
 
888
935
        exit(0);
889
936
}
890
937
 
898
945
{
899
946
#if USE_JIT
900
947
    if (UseJIT)
901
 
                flush_icache_range((uintptr)start, size);
 
948
                flush_icache_range((uint8 *)start, size);
902
949
#endif
903
950
#if !EMULATED_68K && defined(__NetBSD__)
904
951
        m68k_sync_icache(start, size);
1525
1572
 
1526
1573
void ErrorAlert(const char *text)
1527
1574
{
 
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)
 
1578
                        return;
 
1579
        }
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);
1544
1596
 
1545
1597
void WarningAlert(const char *text)
1546
1598
{
 
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)
 
1602
                        return;
 
1603
        }
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);