$NetBSD: patch-af,v 1.4 2006/03/28 21:35:27 gavan Exp $

--- src/runtime/mach-dep/signal-sysdep.h.orig	2002-10-10 19:20:04.000000000 +0100
+++ src/runtime/mach-dep/signal-sysdep.h
@@ -147,7 +147,7 @@ extern void SetFSR(int);
   /* disable all FP exceptions */
 #  define SIG_InitFPE()    SetFSR(0)
 
-#  if defined(OPSYS_SUNOS)
+#  if defined(OPSYS_SUNOS) || defined(OPSYS_NETBSD)
     /** SPARC, SUNOS **/
 #    define USE_ZERO_LIMIT_PTR_FN
 #    define SIG_FAULT1		SIGFPE
@@ -318,6 +318,19 @@ extern void SetFSR();
 
 #    define SIG_Flags           0
 
+#  elif (defined(TARGET_PPC) && defined(OPSYS_NETBSD))
+    /* PPC, NetBSD */
+
+#    define SIG_FAULT1          SIGTRAP
+
+#    define INT_DIVZERO(s, c)           ((s) == SIGTRAP)
+#    define INT_OVFLW(s, c)             ((s) == SIGTRAP)
+#    define SIG_GetPC(scp)              ((scp)->sc_frame.srr0)
+#    define SIG_SetPC(scp, addr)        { (scp)->sc_frame.srr0 = (long)(addr); }
+#    define SIG_ZeroLimitPtr(scp)       { ((scp)->sc_frame.fixreg[15] = 0); } /* limitptr = 15 (see src/runtime/mach-dep/PPC.prim.asm) */
+#    define SIG_GetCode(info,scp)       (info)
+     typedef void SigReturn_t;
+
 
 #  endif /* HOST_RS6000/HOST_PPC */
 
@@ -463,35 +476,15 @@ extern Addr_t *ML_X86Frame;   /* used to
 
 #  elif defined(OPSYS_NETBSD)
     /** x86, NetBSD **/
-/* NetBSD (including versions 1.0 and 1.1) generates SIGBUS rather
-   than SIGFPE for overflows.  The real fix is a trivial change to
-   kernel sources, which has already been reported (NetBSD internal
-   problem identification "port-i386/1833"). 
-
-   If you want to fix this on your NetBSD system.  Edit machdep.c in
-   directory /sys/arch/i386/i386, and find the line
-
-        setgate(&idt[  4], &IDTVEC(ofl),     0, SDT_SYS386TGT, SEL_KPL);
-
-   Change SEL_KPL to SEL_UPL.  With SEL_KPL, the int overflow trap is
-   not accessible at user level, and a protection fault occurs instead
-   (thus the seg fault).  SEL_UPL will allow user processes to generate
-   this trap.
-
-   For the change to take effect, recompile your kernel, install it
-   and reboot. */
-#    define SIG_FAULT1		SIGFPE
-#    define SIG_FAULT2		SIGBUS
-#    define INT_DIVZERO(s, c)	0
-#    define INT_OVFLW(s, c)	(((s) == SIGFPE) || ((s) == SIGBUS))
-
-#    define SIG_GetCode(info, scp)	(info)
-#    define SIG_GetPC(scp)		((scp)->sc_pc)
-#    define SIG_SetPC(scp, addr)	{ (scp)->sc_pc = (long)(addr); }
+#    define SIG_FAULT1			SIGFPE
+#    define INT_DIVZERO(s, c)		((s) == SIGFPE)
+#    define INT_OVFLW(s, c)		((s) == SIGFPE)
+
+#    define SIG_GetCode(info, scp)	(0)
+#    define SIG_GetPC(scp)		((scp)->uc_mcontext.__gregs[_REG_EIP])
+#    define SIG_SetPC(scp, addr)	{(scp)->uc_mcontext.__gregs[_REG_EIP] = (long)(addr); }
 #    define SIG_ZeroLimitPtr(scp)	{ ML_X86Frame[LIMITPTR_X86OFFSET] = 0; }
 
-     typedef void SigReturn_t;
-
 #  elif defined(OPSYS_SOLARIS)
      /** x86, Solaris */
 
