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 |
– |
uint8 *ScratchMem = NULL; // Scratch memory for Mac ROM writes |
136 |
|
#endif |
137 |
|
|
138 |
|
#if USE_SCRATCHMEM_SUBTERFUGE |
139 |
< |
uint8 *ScratchMem = 0; // Scratch memory for Mac ROM writes |
139 |
> |
uint8 *ScratchMem = NULL; // Scratch memory for Mac ROM writes |
140 |
|
#endif |
141 |
|
|
142 |
|
static struct sigaction timer_sa; // sigaction used for timer |
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 |
164 |
|
extern char *address_space, *good_address_map; |
165 |
|
#endif |
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 |
< |
const uint32 ram_rom_size = aligned_ram_size + 0x100000; |
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 |
< |
#if defined(OS_solaris) |
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, ram_rom_size, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE, zero_fd, 0) != MAP_FAILED) { |
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; |
302 |
|
} |
303 |
|
#endif |
304 |
|
|
305 |
< |
#if !EMULATED_68K || USE_SCRATCHMEM_SUBTERFUGE |
305 |
> |
#if USE_SCRATCHMEM_SUBTERFUGE |
306 |
|
// Allocate scratch memory |
307 |
|
ScratchMem = (uint8 *)malloc(SCRATCH_MEM_SIZE); |
308 |
|
if (ScratchMem == NULL) { |
343 |
|
else |
344 |
|
#endif |
345 |
|
{ |
346 |
< |
RAMBaseHost = (uint8 *)mmap(0, ram_rom_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, zero_fd, 0); |
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(); |
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 |
421 |
|
printf("WARNING: Cannot detect CPU type, assuming 68020\n"); |
422 |
|
CPUType = 2; |
423 |
|
} |
424 |
< |
FPUType = 0; //!! |
424 |
> |
FPUType = 1; // NetBSD has an FPU emulation, so the FPU ought to be available at all times |
425 |
|
TwentyFourBitAddressing = false; |
426 |
|
#endif |
427 |
|
|
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 |
622 |
|
// Deinitialize everything |
623 |
|
ExitAll(); |
624 |
|
|
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 |
621 |
– |
// Unmap ROM area |
622 |
– |
if (ROMBaseHost != (uint8 *)MAP_FAILED) { |
623 |
– |
munmap((caddr_t)ROMBaseHost, 0x100000); |
624 |
– |
ROMBaseHost = 0; |
625 |
– |
} |
626 |
– |
|
627 |
– |
//Unmap RAM area |
632 |
|
if (RAMBaseHost != (uint8 *)MAP_FAILED) { |
633 |
< |
const uint32 page_size = getpagesize(); |
634 |
< |
const uint32 page_mask = page_size - 1; |
631 |
< |
munmap((caddr_t)RAMBaseHost, ((RAMSize + page_mask) & ~page_mask)); |
633 |
> |
munmap((caddr_t)RAMBaseHost, mapped_ram_rom_size); |
634 |
> |
RAMBaseHost = NULL; |
635 |
|
} |
636 |
|
#else |
634 |
– |
// Delete ROM area |
637 |
|
if (ROMBaseHost) { |
638 |
|
free(ROMBaseHost); |
639 |
|
ROMBaseHost = NULL; |
640 |
|
} |
639 |
– |
|
640 |
– |
// Delete RAM area |
641 |
|
if (RAMBaseHost) { |
642 |
|
free(RAMBaseHost); |
643 |
|
RAMBaseHost = NULL; |
644 |
|
} |
645 |
|
#endif |
646 |
|
|
647 |
< |
#if !EMULATED_68K || USE_SCRATMEM_SUBTERFUGE |
647 |
> |
#if USE_SCRATCHMEM_SUBTERFUGE |
648 |
|
// Delete scratch memory area |
649 |
|
if (ScratchMem) { |
650 |
|
free((void *)(ScratchMem - SCRATCH_MEM_SIZE/2)); |
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 |
|
} |
748 |
|
raise(SIG_IRQ); |
749 |
|
#endif |
750 |
|
} |
751 |
+ |
|
752 |
+ |
void TriggerNMI(void) |
753 |
+ |
{ |
754 |
+ |
// not yet supported |
755 |
+ |
} |
756 |
|
#endif |
757 |
|
|
758 |
|
|
860 |
|
|
861 |
|
/* |
862 |
|
* Delay by specified number of microseconds (<1 second) |
863 |
< |
* (adapted from SDL_Delay() source) |
863 |
> |
* (adapted from SDL_Delay() source; this function is designed to provide |
864 |
> |
* the highest accuracy possible) |
865 |
|
*/ |
866 |
|
|
867 |
|
void Delay_usec(uint32 usec) |
868 |
|
{ |
869 |
|
int was_error; |
870 |
< |
#ifndef __linux__ // Non-Linux implementations need to calculate time left |
870 |
> |
|
871 |
> |
#if defined(linux) |
872 |
> |
struct timeval tv; |
873 |
> |
#elif defined(__FreeBSD__) || defined(sgi) |
874 |
> |
struct timespec elapsed, tv; |
875 |
> |
#else // Non-Linux implementations need to calculate time left |
876 |
|
uint64 then, now, elapsed; |
877 |
|
#endif |
867 |
– |
struct timeval tv; |
878 |
|
|
879 |
|
// Set the timeout interval - Linux only needs to do this once |
880 |
< |
#ifdef __linux__ |
880 |
> |
#if defined(linux) |
881 |
|
tv.tv_sec = 0; |
882 |
|
tv.tv_usec = usec; |
883 |
+ |
#elif defined(__FreeBSD__) |
884 |
+ |
elapsed.tv_sec = 0; |
885 |
+ |
elapsed.tv_nsec = usec * 1000; |
886 |
|
#else |
887 |
|
then = GetTicks_usec(); |
888 |
|
#endif |
889 |
|
do { |
890 |
|
errno = 0; |
891 |
< |
#ifndef __linux__ |
891 |
> |
#if !defined(linux) && !defined(__FreeBSD__) && !defined(sgi) |
892 |
|
/* Calculate the time interval left (in case of interrupt) */ |
893 |
|
now = GetTicks_usec(); |
894 |
|
elapsed = now - then; |
899 |
|
tv.tv_sec = 0; |
900 |
|
tv.tv_usec = usec; |
901 |
|
#endif |
902 |
+ |
#if defined(__FreeBSD__) || defined(sgi) |
903 |
+ |
tv.tv_sec = elapsed.tv_sec; |
904 |
+ |
tv.tv_nsec = elapsed.tv_nsec; |
905 |
+ |
was_error = nanosleep(&tv, &elapsed); |
906 |
+ |
#else |
907 |
|
was_error = select(0, NULL, NULL, NULL, &tv); |
908 |
+ |
#endif |
909 |
|
} while (was_error && (errno == EINTR)); |
910 |
|
} |
911 |
|
|
960 |
|
|
961 |
|
#define STORE_SR(v) \ |
962 |
|
scp->sc_ps = (v) & 0xff; \ |
963 |
< |
EmulatedSR = (v) & 0x2700; \ |
963 |
> |
EmulatedSR = (v) & 0xe700; \ |
964 |
|
if (((v) & 0x0700) == 0 && InterruptFlags) \ |
965 |
|
TriggerInterrupt(); |
966 |
|
|
1023 |
|
case 0x007c: { // ori #xxxx,sr |
1024 |
|
uint16 sr = GET_SR | pc[1]; |
1025 |
|
scp->sc_ps = sr & 0xff; // oring bits into the sr can't enable interrupts, so we don't need to call STORE_SR |
1026 |
< |
EmulatedSR = sr & 0x2700; |
1026 |
> |
EmulatedSR = sr & 0xe700; |
1027 |
|
INC_PC(4); |
1028 |
|
break; |
1029 |
|
} |
1100 |
|
} |
1101 |
|
|
1102 |
|
case 0xf327: // fsave -(sp) |
1103 |
< |
goto ill; //!! |
1103 |
> |
if (CPUIs68060) { |
1104 |
> |
regs->a[7] -= 4; |
1105 |
> |
WriteMacInt32(regs->a[7], 0x60000000); // Idle frame |
1106 |
> |
regs->a[7] -= 4; |
1107 |
> |
WriteMacInt32(regs->a[7], 0); |
1108 |
> |
regs->a[7] -= 4; |
1109 |
> |
WriteMacInt32(regs->a[7], 0); |
1110 |
> |
} else { |
1111 |
> |
regs->a[7] -= 4; |
1112 |
> |
WriteMacInt32(regs->a[7], 0x41000000); // Idle frame |
1113 |
> |
} |
1114 |
> |
scp->sc_sp = regs->a[7]; |
1115 |
> |
INC_PC(2); |
1116 |
> |
break; |
1117 |
|
|
1118 |
|
case 0xf35f: // frestore (sp)+ |
1119 |
< |
goto ill; //!! |
1119 |
> |
if (CPUIs68060) |
1120 |
> |
regs->a[7] += 12; |
1121 |
> |
else |
1122 |
> |
regs->a[7] += 4; |
1123 |
> |
scp->sc_sp = regs->a[7]; |
1124 |
> |
INC_PC(2); |
1125 |
> |
break; |
1126 |
|
|
1127 |
< |
case 0x4e73: { // rte (only handles format 0) |
1127 |
> |
case 0x4e73: { // rte |
1128 |
|
uint32 a7 = regs->a[7]; |
1129 |
|
uint16 sr = ReadMacInt16(a7); |
1130 |
|
a7 += 2; |
1131 |
|
scp->sc_ps = sr & 0xff; |
1132 |
< |
EmulatedSR = sr & 0x2700; |
1132 |
> |
EmulatedSR = sr & 0xe700; |
1133 |
|
scp->sc_pc = ReadMacInt32(a7); |
1134 |
< |
a7 += 6; |
1135 |
< |
scp->sc_sp = regs->a[7] = a7; |
1134 |
> |
a7 += 4; |
1135 |
> |
uint16 format = ReadMacInt16(a7) >> 12; |
1136 |
> |
a7 += 2; |
1137 |
> |
static const int frame_adj[16] = { |
1138 |
> |
0, 0, 4, 4, 8, 0, 0, 52, 50, 12, 24, 84, 16, 0, 0, 0 |
1139 |
> |
}; |
1140 |
> |
scp->sc_sp = regs->a[7] = a7 + frame_adj[format]; |
1141 |
|
break; |
1142 |
|
} |
1143 |
|
|
1144 |
|
case 0x4e7a: // movec cr,x |
1145 |
|
switch (pc[1]) { |
1103 |
– |
case 0x8801: // movec vbr,a0 |
1104 |
– |
regs->a[0] = 0; |
1105 |
– |
break; |
1106 |
– |
case 0x9801: // movec vbr,a1 |
1107 |
– |
regs->a[1] = 0; |
1108 |
– |
break; |
1146 |
|
case 0x0002: // movec cacr,d0 |
1147 |
|
regs->d[0] = 0x3111; |
1148 |
|
break; |
1150 |
|
regs->d[1] = 0x3111; |
1151 |
|
break; |
1152 |
|
case 0x0003: // movec tc,d0 |
1153 |
+ |
case 0x0004: // movec itt0,d0 |
1154 |
+ |
case 0x0005: // movec itt1,d0 |
1155 |
+ |
case 0x0006: // movec dtt0,d0 |
1156 |
+ |
case 0x0007: // movec dtt1,d0 |
1157 |
+ |
case 0x0806: // movec urp,d0 |
1158 |
+ |
case 0x0807: // movec srp,d0 |
1159 |
|
regs->d[0] = 0; |
1160 |
|
break; |
1161 |
+ |
case 0x1000: // movec sfc,d1 |
1162 |
+ |
case 0x1001: // movec dfc,d1 |
1163 |
|
case 0x1003: // movec tc,d1 |
1164 |
+ |
case 0x1801: // movec vbr,d1 |
1165 |
|
regs->d[1] = 0; |
1166 |
|
break; |
1167 |
+ |
case 0x8801: // movec vbr,a0 |
1168 |
+ |
regs->a[0] = 0; |
1169 |
+ |
break; |
1170 |
+ |
case 0x9801: // movec vbr,a1 |
1171 |
+ |
regs->a[1] = 0; |
1172 |
+ |
break; |
1173 |
|
default: |
1174 |
|
goto ill; |
1175 |
|
} |
1178 |
|
|
1179 |
|
case 0x4e7b: // movec x,cr |
1180 |
|
switch (pc[1]) { |
1181 |
+ |
case 0x1000: // movec d1,sfc |
1182 |
+ |
case 0x1001: // movec d1,dfc |
1183 |
|
case 0x0801: // movec d0,vbr |
1184 |
+ |
case 0x1801: // movec d1,vbr |
1185 |
|
break; |
1186 |
|
case 0x0002: // movec d0,cacr |
1187 |
|
case 0x1002: // movec d1,cacr |
1216 |
|
printf(" a%d %08x\n", i, state->ss_frame.f_regs[i+8]); |
1217 |
|
|
1218 |
|
#ifdef ENABLE_MON |
1219 |
< |
char *arg[2] = {"rmon", NULL}; |
1220 |
< |
mon(1, arg); |
1219 |
> |
char *arg[4] = {"mon", "-m", "-r", NULL}; |
1220 |
> |
mon(3, arg); |
1221 |
|
#endif |
1222 |
|
QuitEmulator(); |
1223 |
|
break; |