ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/main_unix.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/main_unix.cpp (file contents):
Revision 1.16 by cebix, 2000-07-22T18:12:34Z vs.
Revision 1.23 by cebix, 2000-10-10T18:54:34Z

# Line 30 | Line 30
30   # include <pthread.h>
31   #endif
32  
33 < #if defined(USE_MAPPED_MEMORY) || REAL_ADDRESSING
33 > #if defined(USE_MAPPED_MEMORY) || REAL_ADDRESSING || DIRECT_ADDRESSING
34   # include <sys/mman.h>
35   #endif
36  
# Line 133 | Line 133 | static struct sigaction sigirq_sa;     // Vi
133   static struct sigaction sigill_sa;      // Illegal instruction
134   static void *sig_stack = NULL;          // Stack for signal handlers
135   uint16 EmulatedSR;                                      // Emulated bits of SR (supervisor bit and interrupt mask)
136 < uint32 ScratchMem = NULL;                       // Scratch memory for Mac ROM writes
136 > #endif
137 >
138 > #if USE_SCRATCHMEM_SUBTERFUGE
139 > uint8 *ScratchMem = NULL;                       // Scratch memory for Mac ROM writes
140   #endif
141  
142   static struct sigaction timer_sa;       // sigaction used for timer
# Line 150 | Line 153 | static void sigint_handler(...);
153  
154   #if REAL_ADDRESSING
155   static bool lm_area_mapped = false;     // Flag: Low Memory area mmap()ped
156 + static bool memory_mapped_from_zero = false; // Flag: Could allocate RAM area from 0
157 + #endif
158 +
159 + #if REAL_ADDRESSING || DIRECT_ADDRESSING
160 + static uint32 mapped_ram_rom_size;              // Total size of mmap()ed RAM/ROM area
161   #endif
162  
163   #ifdef USE_MAPPED_MEMORY
# Line 260 | Line 268 | int main(int argc, char **argv)
268                  RAMSize = 1024*1024;
269          }
270  
271 + #if REAL_ADDRESSING || DIRECT_ADDRESSING
272 +        const uint32 page_size = getpagesize();
273 +        const uint32 page_mask = page_size - 1;
274 +        const uint32 aligned_ram_size = (RAMSize + page_mask) & ~page_mask;
275 +        mapped_ram_rom_size = aligned_ram_size + 0x100000;
276 + #endif
277 +
278   #if REAL_ADDRESSING
279 +        // Try to allocate the complete address space from zero
280 +        // gb-- the Solaris manpage about mmap(2) states that using MAP_FIXED
281 +        // implies undefined behaviour for further use of sbrk(), malloc(), etc.
282 +        // cebix-- on NetBSD/m68k, this causes a segfault
283 + #if defined(OS_solaris) || defined(OS_netbsd)
284 +        // Anyway, it doesn't work...
285 +        if (0) {
286 + #else
287 +        if (mmap((caddr_t)0x0000, mapped_ram_rom_size, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE, zero_fd, 0) != MAP_FAILED) {
288 + #endif
289 +                D(bug("Could allocate RAM and ROM from 0x0000\n"));
290 +                memory_mapped_from_zero = true;
291 +        }
292          // Create Low Memory area (0x0000..0x2000)
293 <        if (mmap((char *)0x0000, 0x2000, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE, zero_fd, 0) == (void *)-1) {
293 >        else if (mmap((char *)0x0000, 0x2000, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE, zero_fd, 0) != MAP_FAILED) {
294 >                D(bug("Could allocate the Low Memory globals\n"));
295 >                lm_area_mapped = true;
296 >        }
297 >        // Exit on error
298 >        else {
299                  sprintf(str, GetString(STR_LOW_MEM_MMAP_ERR), strerror(errno));
300                  ErrorAlert(str);
301                  QuitEmulator();
302          }
270        lm_area_mapped = true;
303   #endif
304  
305 < #if !EMULATED_68K
305 > #if USE_SCRATCHMEM_SUBTERFUGE
306          // Allocate scratch memory
307 <        ScratchMem = (uint32)malloc(SCRATCH_MEM_SIZE);
307 >        ScratchMem = (uint8 *)malloc(SCRATCH_MEM_SIZE);
308          if (ScratchMem == NULL) {
309                  ErrorAlert(GetString(STR_NO_MEM_ERR));
310                  QuitEmulator();
# Line 300 | Line 332 | int main(int argc, char **argv)
332          mmap(good_address_map + i, 4096, PROT_READ, MAP_FIXED | MAP_PRIVATE, good_address_fd, 0);
333      for (int i=0; i<0x80000; i+=4096)
334          mmap(good_address_map + i + 0x00400000, 4096, PROT_READ, MAP_FIXED | MAP_PRIVATE, good_address_fd, 0);
335 + #elif REAL_ADDRESSING || DIRECT_ADDRESSING
336 +        // gb-- Overkill, needs to be cleaned up. Probably explode it for either
337 +        // real or direct addressing mode.
338 + #if REAL_ADDRESSING
339 +        if (memory_mapped_from_zero) {
340 +                RAMBaseHost = (uint8 *)0;
341 +                ROMBaseHost = RAMBaseHost + aligned_ram_size;
342 +        }
343 +        else
344 + #endif
345 +        {
346 +                RAMBaseHost = (uint8 *)mmap(0, mapped_ram_rom_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, zero_fd, 0);
347 +                if (RAMBaseHost == (uint8 *)MAP_FAILED) {
348 +                        ErrorAlert(GetString(STR_NO_MEM_ERR));
349 +                        QuitEmulator();
350 +                }
351 +                ROMBaseHost = RAMBaseHost + aligned_ram_size;
352 +        }
353   #else
354 <        RAMBaseHost = new uint8[RAMSize];
355 <        ROMBaseHost = new uint8[0x100000];
354 >        RAMBaseHost = (uint8 *)malloc(RAMSize);
355 >        ROMBaseHost = (uint8 *)malloc(0x100000);
356 >        if (RAMBaseHost == NULL || ROMBaseHost == NULL) {
357 >                ErrorAlert(GetString(STR_NO_MEM_ERR));
358 >                QuitEmulator();
359 >        }
360 > #endif
361 >
362 > #if DIRECT_ADDRESSING
363 >        // Initialize MEMBaseDiff now so that Host2MacAddr in the Video module
364 >        // will return correct results
365 >        RAMBaseMac = 0;
366 >        ROMBaseMac = RAMBaseMac + aligned_ram_size;
367 >        InitMEMBaseDiff(RAMBaseHost, RAMBaseMac);
368   #endif
369 < #if REAL_ADDRESSING && !EMULATED_68K
369 > #if REAL_ADDRESSING // && !EMULATED_68K
370          RAMBaseMac = (uint32)RAMBaseHost;
371          ROMBaseMac = (uint32)ROMBaseHost;
372   #endif
373          D(bug("Mac RAM starts at %p (%08x)\n", RAMBaseHost, RAMBaseMac));
374          D(bug("Mac ROM starts at %p (%08x)\n", ROMBaseHost, ROMBaseMac));
375 <
375 >        
376          // Get rom file path from preferences
377          const char *rom_path = PrefsFindString("rom");
378  
# Line 422 | Line 484 | int main(int argc, char **argv)
484   #ifdef ENABLE_MON
485          // Setup SIGINT handler to enter mon
486          sigemptyset(&sigint_sa.sa_mask);
487 <        sigint_sa.sa_handler = sigint_handler;
487 >        sigint_sa.sa_handler = (void (*)(int))sigint_handler;
488          sigint_sa.sa_flags = 0;
489          sigaction(SIGINT, &sigint_sa, NULL);
490   #endif
# Line 431 | Line 493 | int main(int argc, char **argv)
493  
494          // POSIX.4 timers and real-time signals available, start 60Hz timer
495          sigemptyset(&timer_sa.sa_mask);
496 <        timer_sa.sa_sigaction = one_tick;
496 >        timer_sa.sa_sigaction = (void (*)(int, siginfo_t *, void *))one_tick;
497          timer_sa.sa_flags = SA_SIGINFO | SA_RESTART;
498          if (sigaction(SIG_TIMER, &timer_sa, NULL) < 0) {
499                  sprintf(str, GetString(STR_SIG_INSTALL_ERR), "SIG_TIMER", strerror(errno));
# Line 560 | Line 622 | void QuitEmulator(void)
622          // Deinitialize everything
623          ExitAll();
624  
625 <        // Delete ROM area
626 <        delete[] ROMBaseHost;
627 <
628 <        // Delete RAM area
629 <        delete[] RAMBaseHost;
625 >        // Free ROM/RAM areas
626 > #if REAL_ADDRESSING
627 >        if (memory_mapped_from_zero)
628 >                munmap((caddr_t)0x0000, mapped_ram_rom_size);
629 >        else
630 > #endif
631 > #if REAL_ADDRESSING || DIRECT_ADDRESSING
632 >        if (RAMBaseHost != (uint8 *)MAP_FAILED) {
633 >                munmap((caddr_t)RAMBaseHost, mapped_ram_rom_size);
634 >                RAMBaseHost = NULL;
635 >        }
636 > #else
637 >        if (ROMBaseHost) {
638 >                free(ROMBaseHost);
639 >                ROMBaseHost = NULL;
640 >        }
641 >        if (RAMBaseHost) {
642 >                free(RAMBaseHost);
643 >                RAMBaseHost = NULL;
644 >        }
645 > #endif
646  
647 < #if !EMULATED_68K
647 > #if USE_SCRATCHMEM_SUBTERFUGE
648          // Delete scratch memory area
649 <        if (ScratchMem)
649 >        if (ScratchMem) {
650                  free((void *)(ScratchMem - SCRATCH_MEM_SIZE/2));
651 +                ScratchMem = NULL;
652 +        }
653   #endif
654  
655   #if REAL_ADDRESSING
# Line 621 | Line 701 | static void sigint_handler(...)
701          extern void m68k_dumpstate(uaecptr *nextpc);
702          m68k_dumpstate(&nextpc);
703   #else
704 <        char *arg[2] = {"rmon", NULL};
705 <        mon(1, arg);
704 >        char *arg[4] = {"mon", "-m", "-r", NULL};
705 >        mon(3, arg);
706          QuitEmulator();
707   #endif
708   }
# Line 668 | Line 748 | void TriggerInterrupt(void)
748          raise(SIG_IRQ);
749   #endif
750   }
751 +
752 + void TriggerNMI(void)
753 + {
754 +        // not yet supported
755 + }
756   #endif
757  
758  
# Line 705 | Line 790 | static void one_second(void)
790          // Pseudo Mac 1Hz interrupt, update local time
791          WriteMacInt32(0x20c, TimerDateTime());
792  
793 <        SetInterruptFlag(INTFLAG_60HZ);
793 >        SetInterruptFlag(INTFLAG_1HZ);
794          TriggerInterrupt();
795  
796   #ifndef HAVE_PTHREADS
# Line 1081 | Line 1166 | ill:           printf("SIGILL num %d, code %d\n",
1166                                  printf("  a%d %08x\n", i, state->ss_frame.f_regs[i+8]);
1167  
1168   #ifdef ENABLE_MON
1169 <                        char *arg[2] = {"rmon", NULL};
1170 <                        mon(1, arg);
1169 >                        char *arg[4] = {"mon", "-m", "-r", NULL};
1170 >                        mon(3, arg);
1171   #endif
1172                          QuitEmulator();
1173                          break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines