[Git][cmucl/cmucl][issue-97-define-ud2-inst] 2 commits: Use TRAP_CODE to insert the desired traps

Raymond Toy gitlab at common-lisp.net
Fri Apr 9 21:16:21 UTC 2021



Raymond Toy pushed to branch issue-97-define-ud2-inst at cmucl / cmucl


Commits:
40fff139 by Raymond Toy at 2021-04-09T14:14:52-07:00
Use TRAP_CODE to insert the desired traps

- - - - -
3adaeb13 by Raymond Toy at 2021-04-09T14:15:50-07:00
Correctly extract the trap code from the instruction stream.

The code is in the low 6 bits.  Need to ignore everything else when
extracting it.

Verified that function end breakpoints now work again instead of
getting a sigill error because of an unknown code.

- - - - -


2 changed files:

- src/lisp/x86-arch.c
- src/lisp/x86-assem.S


Changes:

=====================================
src/lisp/x86-arch.c
=====================================
@@ -369,7 +369,12 @@ sigill_handler(HANDLER_ARGS)
      * trap code?
      */
     if (*(unsigned short *) SC_PC(context) == 0xb90f) {
-        trap = *(((char *)SC_PC(context)) + 2);
+        /*
+         * This must match what the lisp code is doing.  The trap
+         * number is placed in the low 6-bits of the 3rd byte of the
+         * instruction.
+         */
+        trap = *(((char *)SC_PC(context)) + 2) & 63;
     } else {
         abort();
     }


=====================================
src/lisp/x86-assem.S
=====================================
@@ -18,6 +18,16 @@
 #include "internals.h"
 #include "lispregs.h"
 
+/*
+ * Emit the appropriate instruction used for implementing traps.
+ * Currently, this is the UD1 instruction.  However, it make it
+ * easy to add the trap code, use a sequence of bytes.  The code
+ * is smashed into the mod r/m byte with the mod bits set to
+ * #b11.  This MUST be coordinated with the Lisp code and the C
+ * code.
+ *
+ * Also, clang doesn't recognize the ud1 instruction.
+ */
 #define TRAP_CODE(code) \
 	.byte 0x0f		; \
 	.byte 0xb9		; \
@@ -249,10 +259,7 @@ ENDFUNC(sse_restore)
  * The undefined-function trampoline.
  */
 FUNCDEF(undefined_tramp)
-	# UD1
-	.byte	0x0f
-	.byte	0xb9
-	.byte	trap_Error
+	TRAP_CODE(trap_Error)
         /* Number of argument bytes */
         .byte   2
 	.byte	UNDEFINED_SYMBOL_ERROR
@@ -300,40 +307,28 @@ GNAME(function_end_breakpoint_trap):
 	.byte	0xb9
 	.byte 	0xc0 + trap_PendingInterrupt
 	*/
-	# UD1
-	.byte	0x0f
-	.byte	0xb9
-	.byte 	0xc0 + trap_FunctionEndBreakpoint
+	TRAP_CODE(trap_FunctionEndBreakpoint)
 	hlt			# Should never return here.
+ENDFUNC(function_end_breakpoint_trap)
 
 	.globl GNAME(function_end_breakpoint_end)
 GNAME(function_end_breakpoint_end):
 
-
 FUNCDEF(do_pending_interrupt)
-	# UD1
-	.byte	0x0f
-	.byte	0xb9
-	.byte 	trap_PendingInterrupt
+	TRAP_CODE(trap_PendingInterrupt)
 	ret
 ENDFUNC(do_pending_interrupt)
 	
 #ifdef trap_DynamicSpaceOverflowError
 FUNCDEF(do_dynamic_space_overflow_error)
-	# UD1
-	.byte	0x0f
-	.byte	0xb9
-	.byte 	trap_DynamicSpaceOverflowError
+	TRAP_CODE(trap_DynamicSpaceOverflowError)
 	ret
 ENDFUNC(do_dynamic_space_overflow_error)
 #endif				
 	
 #ifdef trap_DynamicSpaceOverflowWarning
 FUNCDEF(do_dynamic_space_overflow_warning)
-	# UD1
-	.byte	0x0f
-	.byte	0xb9
-	.byte 	trap_DynamicSpaceOverflowWarning
+	TRAP_CODE(trap_DynamicSpaceOverflowWarning)
 	ret
 ENDFUNC(do_dynamic_space_overflow_warning)
 #endif				
@@ -515,10 +510,7 @@ FUNCDEF(undefined_foreign_symbol_trap)
         movl 8(%ebp),%eax
 
 	/* Now trap to Lisp */
-	# UD1
-	.byte	0x0f
-	.byte	0xb9
-	.byte	trap_Error
+	TRAP_CODE(trap_Error)
         /* Number of argument bytes */
         .byte   2
 	.byte	UNDEFINED_FOREIGN_SYMBOL_ERROR



View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/93d7cf02396314c79a176f1a2c4208d5f3a52e21...3adaeb13b3579385af2d7b06781a9b920b32b6c5

-- 
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/93d7cf02396314c79a176f1a2c4208d5f3a52e21...3adaeb13b3579385af2d7b06781a9b920b32b6c5
You're receiving this email because of your account on gitlab.common-lisp.net.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cmucl-cvs/attachments/20210409/517b2146/attachment-0001.html>


More information about the cmucl-cvs mailing list