Subject: port-mac68k/10511: A-Line instructions in user mode don't raise SIGILL
To: None <gnats-bugs@gnats.netbsd.org>
From: None <Christian.Bauer@uni-mainz.de>
List: netbsd-bugs
Date: 07/05/2000 10:44:25
>Number:         10511
>Category:       port-mac68k
>Synopsis:       A-Line instructions in user mode don't raise SIGILL
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-mac68k-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 05 10:45:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Christian Bauer
>Release:        1.4.2
>Organization:
>Environment:
NetBSD down.physik.uni-mainz.de 1.4.2 NetBSD 1.4.2 (EARENDIL) #8: Wed Jul  5 19:13:09 CEST 2000     cbauer@down.physik.uni-mainz.de:/usr/src/sys/arch/mac68k/compile/EARENDIL mac68k

>Description:
A-Line instructions (opcode 0xA***) in user mode cause unpredictable
behaviour instead of raising a SIGILL as they do under other m68k
NetBSD versions. (I'm developing a program that lets MacOS applications
run as a process under NetBSD/m68k and for this I have to intercept
A-Line traps)

>How-To-Repeat:
#include <stdio.h>
int main(void)
{
    __asm __volatile(".word 0xa000");
    return 0;
}

This causes a segmentation fault (most of the time, sometimes it seems
to hang forever). Analyzing the core dump with gdb reveals that it
jumped to an illegal memory location.

>Fix:
Apply the following patch to arch/mac68k/mac68k/macromasm.s:

--- macromasm.s.orig    Wed Jul  5 19:29:01 2000
+++ macromasm.s Wed Jul  5 19:12:34 2000
@@ -37,6 +37,8 @@
 
 #include "opt_adb.h"
 #include "assym.h"
+#include <machine/asm.h>
+#include <machine/trap.h>
 
 
        /* Define this symbol as global with (v) value */
@@ -437,8 +439,9 @@
        movw    sp@(FR_HW + 4), d0      | retrieve status register
        andw    #PSL_S, d0      | supervisor state?
        bne     Lalnosup        | branch if supervisor
-       jbsr    _mrg_aline_user | user a-line trap
-       bra     Lalrts
+       addql   #4, sp          | pop frame ptr
+       movql   #T_ILLINST, d0  | user-mode fault
+       jra     _ASM_LABEL(fault)
 Lalnosup:
 #define FR_PC (FR_HW+2)
        movl    sp@(FR_PC + 4), a0      | retrieve PC

>Release-Note:
>Audit-Trail:
>Unformatted: