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

Comparing SheepShaver/src/Unix/main_unix.cpp (file contents):
Revision 1.19 by gbeauche, 2003-12-05T12:41:19Z vs.
Revision 1.24 by gbeauche, 2004-01-07T18:24:45Z

# Line 132 | Line 132
132   #endif
133  
134  
135 + // Enable emulation of unaligned lmw/stmw?
136 + #define EMULATE_UNALIGNED_LOADSTORE_MULTIPLE 1
137 +
138   // Enable Execute68k() safety checks?
139   #define SAFE_EXEC_68K 0
140  
# Line 183 | Line 186 | int64 BusClockSpeed;   // Bus clock speed
186   // Global variables
187   char *x_display_name = NULL;                            // X11 display name
188   Display *x_display = NULL;                                      // X11 display handle
189 + #ifdef X11_LOCK_TYPE
190 + X11_LOCK_TYPE x_display_lock = X11_LOCK_INIT; // X11 display lock
191 + #endif
192  
193   static int zero_fd = 0;                                         // FD of /dev/zero
194   static bool lm_area_mapped = false;                     // Flag: Low Memory area mmap()ped
# Line 204 | Line 210 | static bool ready_for_signals = false;
210   static int64 num_segv = 0;                                      // Number of handled SEGV signals
211  
212   static struct sigaction sigusr2_action;         // Interrupt signal (of emulator thread)
213 < #if !EMULATED_PPC
213 > #if EMULATED_PPC
214 > static uintptr sig_stack = 0;                           // Stack for PowerPC interrupt routine
215 > #else
216   static struct sigaction sigsegv_action;         // Data access exception signal (of emulator thread)
217   static struct sigaction sigill_action;          // Illegal instruction signal (of emulator thread)
218   static void *sig_stack = NULL;                          // Stack for signal handlers
219   static void *extra_stack = NULL;                        // Stack for SIGSEGV inside interrupt handler
220   static bool emul_thread_fatal = false;          // Flag: MacOS thread crashed, tick thread shall dump debug output
221   static sigregs sigsegv_regs;                            // Register dump when crashed
222 + static const char *crash_reason = NULL;         // Reason of the crash (SIGSEGV, SIGBUS, SIGILL)
223   #endif
224  
225   uintptr SheepMem::zero_page = 0;                        // Address of ro page filled in with zeros
# Line 253 | Line 262 | extern void paranoia_check(void);
262  
263   #if EMULATED_PPC
264   /*
265 + *  Return signal stack base
266 + */
267 +
268 + uintptr SignalStackBase(void)
269 + {
270 +        return sig_stack + SIG_STACK_SIZE;
271 + }
272 +
273 +
274 + /*
275   *  Atomic operations
276   */
277  
# Line 589 | Line 608 | int main(int argc, char **argv)
608          // Init external file system
609          ExtFSInit();
610  
611 +        // Init ADB
612 +        ADBInit();
613 +
614          // Init audio
615          AudioInit();
616  
# Line 721 | Line 743 | int main(int argc, char **argv)
743   #endif
744  
745   #if !EMULATED_PPC
746 <        // Install SIGSEGV handler
746 >        // Install SIGSEGV and SIGBUS handlers
747          sigemptyset(&sigsegv_action.sa_mask);   // Block interrupts during SEGV handling
748          sigaddset(&sigsegv_action.sa_mask, SIGUSR2);
749          sigsegv_action.sa_handler = (__sighandler_t)sigsegv_handler;
# Line 732 | Line 754 | int main(int argc, char **argv)
754                  ErrorAlert(str);
755                  goto quit;
756          }
757 +        if (sigaction(SIGBUS, &sigsegv_action, NULL) < 0) {
758 +                sprintf(str, GetString(STR_SIGSEGV_INSTALL_ERR), strerror(errno));
759 +                ErrorAlert(str);
760 +                goto quit;
761 +        }
762  
763          // Install SIGILL handler
764          sigemptyset(&sigill_action.sa_mask);    // Block interrupts during ILL handling
# Line 795 | Line 822 | static void Quit(void)
822          }
823  
824   #if !EMULATED_PPC
825 <        // Uninstall SIGSEGV handler
825 >        // Uninstall SIGSEGV and SIGBUS handlers
826          sigemptyset(&sigsegv_action.sa_mask);
827          sigsegv_action.sa_handler = SIG_DFL;
828          sigsegv_action.sa_flags = 0;
829          sigaction(SIGSEGV, &sigsegv_action, NULL);
830 +        sigaction(SIGBUS, &sigsegv_action, NULL);
831  
832          // Uninstall SIGILL handler
833          sigemptyset(&sigill_action.sa_mask);
# Line 826 | Line 854 | static void Quit(void)
854          // Exit audio
855          AudioExit();
856  
857 +        // Exit ADB
858 +        ADBExit();
859 +
860          // Exit video
861          VideoExit();
862  
# Line 838 | Line 869 | static void Quit(void)
869          DiskExit();
870          SonyExit();
871  
872 +        // Delete thunks
873 +        ThunksExit();
874 +
875          // Delete SheepShaver globals
876          SheepMem::Exit();
877  
# Line 1077 | Line 1111 | static void *tick_func(void *arg)
1111                          // Yes, dump registers
1112                          pt_regs *r = (pt_regs *)&sigsegv_regs;
1113                          char str[256];
1114 <                        sprintf(str, "SIGSEGV\n"
1114 >                        if (crash_reason == NULL)
1115 >                                crash_reason = "SIGSEGV";
1116 >                        sprintf(str, "%s\n"
1117                                  "   pc %08lx     lr %08lx    ctr %08lx    msr %08lx\n"
1118                                  "  xer %08lx     cr %08lx  \n"
1119                                  "   r0 %08lx     r1 %08lx     r2 %08lx     r3 %08lx\n"
# Line 1088 | Line 1124 | static void *tick_func(void *arg)
1124                                  "  r20 %08lx    r21 %08lx    r22 %08lx    r23 %08lx\n"
1125                                  "  r24 %08lx    r25 %08lx    r26 %08lx    r27 %08lx\n"
1126                                  "  r28 %08lx    r29 %08lx    r30 %08lx    r31 %08lx\n",
1127 +                                crash_reason,
1128                                  r->nip, r->link, r->ctr, r->msr,
1129                                  r->xer, r->ccr,
1130                                  r->gpr[0], r->gpr[1], r->gpr[2], r->gpr[3],
# Line 1530 | Line 1567 | static void sigsegv_handler(int sig, sig
1567                                  transfer_type = TYPE_STORE; transfer_size = SIZE_HALFWORD; addr_mode = MODE_NORM; break;
1568                          case 45:        // sthu
1569                                  transfer_type = TYPE_STORE; transfer_size = SIZE_HALFWORD; addr_mode = MODE_U; break;
1570 + #if EMULATE_UNALIGNED_LOADSTORE_MULTIPLE
1571 +                        case 46:        // lmw
1572 +                                if (sig == SIGBUS) {
1573 +                                        uint32 ea = (ra == 0 ? 0 : r->gpr[ra]) + imm;
1574 +                                        D(bug("WARNING: unaligned lmw to EA=%08x from IP=%08x\n", ea, r->nip));
1575 +                                        for (int i = rd; i <= 31; i++) {
1576 +                                                r->gpr[i] = ReadMacInt32(ea);
1577 +                                                ea += 4;
1578 +                                        }
1579 +                                        r->nip += 4;
1580 +                                        goto rti;
1581 +                                }
1582 +                                break;
1583 +                        case 47:        // stmw
1584 +                                if (sig == SIGBUS) {
1585 +                                        uint32 ea = (ra == 0 ? 0 : r->gpr[ra]) + imm;
1586 +                                        D(bug("WARNING: unaligned stmw to EA=%08x from IP=%08x\n", ea, r->nip));
1587 +                                        for (int i = rd; i <= 31; i++) {
1588 +                                                WriteMacInt32(ea, r->gpr[i]);
1589 +                                                ea += 4;
1590 +                                        }
1591 +                                        r->nip += 4;
1592 +                                        goto rti;
1593 +                                }
1594 +                                break;
1595 + #endif
1596                  }
1597          
1598                  // Ignore ROM writes
# Line 1565 | Line 1628 | static void sigsegv_handler(int sig, sig
1628          }
1629  
1630          // For all other errors, jump into debugger (sort of...)
1631 +        crash_reason = (sig == SIGBUS) ? "SIGBUS" : "SIGSEGV";
1632          if (!ready_for_signals) {
1633 <                printf("SIGSEGV\n");
1633 >                printf("%s\n");
1634                  printf(" sigcontext %p, pt_regs %p\n", sc, r);
1635                  printf(
1636                          "   pc %08lx     lr %08lx    ctr %08lx    msr %08lx\n"
# Line 1579 | Line 1643 | static void sigsegv_handler(int sig, sig
1643                          "  r20 %08lx    r21 %08lx    r22 %08lx    r23 %08lx\n"
1644                          "  r24 %08lx    r25 %08lx    r26 %08lx    r27 %08lx\n"
1645                          "  r28 %08lx    r29 %08lx    r30 %08lx    r31 %08lx\n",
1646 +                        crash_reason,
1647                          r->nip, r->link, r->ctr, r->msr,
1648                          r->xer, r->ccr,
1649                          r->gpr[0], r->gpr[1], r->gpr[2], r->gpr[3],
# Line 1729 | Line 1794 | power_inst:            sprintf(str, GetString(STR_
1794          }
1795  
1796          // For all other errors, jump into debugger (sort of...)
1797 +        crash_reason = "SIGILL";
1798          if (!ready_for_signals) {
1799 <                printf("SIGILL\n");
1799 >                printf("%s\n");
1800                  printf(" sigcontext %p, pt_regs %p\n", sc, r);
1801                  printf(
1802                          "   pc %08lx     lr %08lx    ctr %08lx    msr %08lx\n"
# Line 1743 | Line 1809 | power_inst:            sprintf(str, GetString(STR_
1809                          "  r20 %08lx    r21 %08lx    r22 %08lx    r23 %08lx\n"
1810                          "  r24 %08lx    r25 %08lx    r26 %08lx    r27 %08lx\n"
1811                          "  r28 %08lx    r29 %08lx    r30 %08lx    r31 %08lx\n",
1812 +                        crash_reason,
1813                          r->nip, r->link, r->ctr, r->msr,
1814                          r->xer, r->ccr,
1815                          r->gpr[0], r->gpr[1], r->gpr[2], r->gpr[3],
# Line 1773 | Line 1840 | rti:;
1840  
1841   bool SheepMem::Init(void)
1842   {
1843 +        const int page_size = getpagesize();
1844 +
1845 +        // Allocate SheepShaver globals
1846          if (vm_acquire_fixed((char *)base, size) < 0)
1847                  return false;
1848  
1849 +        // Allocate page with all bits set to 0
1850          zero_page = base + size;
1780
1781        int page_size = getpagesize();
1851          if (vm_acquire_fixed((char *)zero_page, page_size) < 0)
1852                  return false;
1853          memset((char *)zero_page, 0, page_size);
1854          if (vm_protect((char *)zero_page, page_size, VM_PAGE_READ) < 0)
1855                  return false;
1856  
1857 + #if EMULATED_PPC
1858 +        // Allocate alternate stack for PowerPC interrupt routine
1859 +        sig_stack = zero_page + page_size;
1860 +        if (vm_acquire_fixed((char *)sig_stack, SIG_STACK_SIZE) < 0)
1861 +                return false;
1862 + #endif
1863 +
1864          top = base + size;
1865          return true;
1866   }
# Line 1792 | Line 1868 | bool SheepMem::Init(void)
1868   void SheepMem::Exit(void)
1869   {
1870          if (top) {
1871 <                // The zero page is next to SheepShaver globals
1872 <                vm_release((void *)base, size + getpagesize());
1871 >                const int page_size = getpagesize();
1872 >
1873 >                // Delete SheepShaver globals
1874 >                vm_release((void *)base, size);
1875 >
1876 >                // Delete zero page
1877 >                vm_release((void *)zero_page, page_size);
1878 >
1879 > #if EMULATED_PPC
1880 >                // Delete alternate stack for PowerPC interrupt routine
1881 >                vm_release((void *)sig_stack, SIG_STACK_SIZE);
1882 > #endif
1883          }
1884   }
1885  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines