Raymond Toy pushed to branch issue-97-define-ud2-inst at cmucl / cmucl
Commits:
-
93d7cf02
by Raymond Toy at 2021-04-09T13:45:34-07:00
4 changed files:
- src/compiler/x86/insts.lisp
- src/compiler/x86/macros.lisp
- src/compiler/x86/system.lisp
- src/lisp/x86-assem.S
Changes:
| ... | ... | @@ -2062,12 +2062,13 @@ |
| 2062 | 2062 |
(code :field (byte 8 8)))
|
| 2063 | 2063 |
|
| 2064 | 2064 |
|
| 2065 |
-(disassem:define-instruction-format (ud1 24 :default-printer '(:name :tab code))
|
|
| 2066 |
- (op :fields (list (byte 8 0) (byte 8 8)) :value '(#xb00001111 #b10111001))
|
|
| 2067 |
- (code :field (byte 8 16)))
|
|
| 2068 |
- |
|
| 2069 |
-(define-emitter emit-ud1-inst 24
|
|
| 2070 |
- (byte 8 0) (byte 8 8) (byte 8 16))
|
|
| 2065 |
+(disassem:define-instruction-format
|
|
| 2066 |
+ (ud1 24 :default-printer '(:name :tab reg ", " reg/mem))
|
|
| 2067 |
+ (prefix :field (byte 8 0) :value #b00001111)
|
|
| 2068 |
+ (op :field (byte 8 8) :value #b10111001)
|
|
| 2069 |
+ (reg/mem :fields (list (byte 2 22) (byte 3 16))
|
|
| 2070 |
+ :type 'reg/mem)
|
|
| 2071 |
+ (reg :field (byte 3 19) :type 'word-reg))
|
|
| 2071 | 2072 |
|
| 2072 | 2073 |
(defun snarf-error-junk (sap offset &optional length-only)
|
| 2073 | 2074 |
(let* ((length (system:sap-ref-8 sap offset))
|
| ... | ... | @@ -2099,34 +2100,41 @@ |
| 2099 | 2100 |
(sc-offsets)
|
| 2100 | 2101 |
(lengths))))))))
|
| 2101 | 2102 |
|
| 2102 |
-(defun break-control (chunk inst stream dstate)
|
|
| 2103 |
+(defun ud1-control (chunk inst stream dstate)
|
|
| 2103 | 2104 |
(declare (ignore inst))
|
| 2104 | 2105 |
(flet ((nt (x) (if stream (disassem:note x dstate))))
|
| 2105 |
- (case (ud1-code chunk dstate)
|
|
| 2106 |
+ (case (ldb (byte 6 16) chunk)
|
|
| 2106 | 2107 |
(#.vm:error-trap
|
| 2107 |
- (nt "Error trap")
|
|
| 2108 |
+ (nt #.(format nil "Error trap: ~D" vm:error-trap))
|
|
| 2108 | 2109 |
(disassem:handle-break-args #'snarf-error-junk stream dstate))
|
| 2109 | 2110 |
(#.vm:cerror-trap
|
| 2110 |
- (nt "Cerror trap")
|
|
| 2111 |
+ (nt #.(format nil "Cerror trap: ~D" vm:cerror-trap))
|
|
| 2111 | 2112 |
(disassem:handle-break-args #'snarf-error-junk stream dstate))
|
| 2112 | 2113 |
(#.vm:breakpoint-trap
|
| 2113 |
- (nt "Breakpoint trap"))
|
|
| 2114 |
+ (nt #.(format nil "Breakpoint trap: ~D" vm:breakpoint-trap)))
|
|
| 2114 | 2115 |
(#.vm:pending-interrupt-trap
|
| 2115 |
- (nt "Pending interrupt trap"))
|
|
| 2116 |
+ (nt #.(format nil "Pending interrupt trap: ~D" vm:pending-interrupt-trap)))
|
|
| 2116 | 2117 |
(#.vm:halt-trap
|
| 2117 |
- (nt "Halt trap"))
|
|
| 2118 |
+ (nt #.(format nil "Halt trap: ~D" vm:halt-trap)))
|
|
| 2118 | 2119 |
(#.vm:function-end-breakpoint-trap
|
| 2119 |
- (nt "Function end breakpoint trap"))
|
|
| 2120 |
+ (nt #.(format nil "Function end breakpoint trap: ~D" vm:function-end-breakpoint-trap)))
|
|
| 2120 | 2121 |
)))
|
| 2121 | 2122 |
|
| 2122 |
-;; This is really the int3 instruction.
|
|
| 2123 |
-(define-instruction break (segment code)
|
|
| 2123 |
+;; The ud1 instruction where we smash the code (trap type) into the
|
|
| 2124 |
+;; mod r/m byte. We don't care about what that actually encodes to.
|
|
| 2125 |
+;; We just want the trap code in the third byte of the instruction.
|
|
| 2126 |
+(define-instruction ud1 (segment code)
|
|
| 2124 | 2127 |
(:declare (type (unsigned-byte 8) code))
|
| 2125 |
- (:printer ud1 ((op '(#b00001111 #b10111001)))
|
|
| 2126 |
- '(:name :tab code)
|
|
| 2127 |
- :control #'break-control)
|
|
| 2128 |
+ (:printer ud1 ((op #b10111001))
|
|
| 2129 |
+ :default
|
|
| 2130 |
+ :control #'ud1-control)
|
|
| 2128 | 2131 |
(:emitter
|
| 2129 |
- (emit-ud1-inst segment #b00001111 #b10111001 code)))
|
|
| 2132 |
+ (emit-byte segment #x0f)
|
|
| 2133 |
+ (emit-byte segment #xb9)
|
|
| 2134 |
+ (emit-mod-reg-r/m-byte segment
|
|
| 2135 |
+ #b11
|
|
| 2136 |
+ (ldb (byte 3 3) code)
|
|
| 2137 |
+ (ldb (byte 3 0) code))))
|
|
| 2130 | 2138 |
|
| 2131 | 2139 |
#+nil
|
| 2132 | 2140 |
(define-instruction ud2 (segment)
|
| ... | ... | @@ -246,7 +246,7 @@ |
| 246 | 246 |
`((let ((vop ,vop))
|
| 247 | 247 |
(when vop
|
| 248 | 248 |
(note-this-location vop :internal-error)))
|
| 249 |
- (inst break ,kind) ; eg trap_Xyyy
|
|
| 249 |
+ (inst ud1 ,kind) ; eg trap_Xyyy
|
|
| 250 | 250 |
(let ((,vector (make-array 8 :element-type '(unsigned-byte 8)
|
| 251 | 251 |
:fill-pointer 0 :adjustable t)))
|
| 252 | 252 |
(write-var-integer (error-number-or-lose ',code) ,vector)
|
| ... | ... | @@ -340,7 +340,7 @@ |
| 340 | 340 |
(- other-pointer-type)))
|
| 341 | 341 |
0)
|
| 342 | 342 |
(inst jmp :eq ,label)
|
| 343 |
- (inst break pending-interrupt-trap)
|
|
| 343 |
+ (inst ud1 pending-interrupt-trap)
|
|
| 344 | 344 |
(emit-label ,label)))))
|
| 345 | 345 |
|
| 346 | 346 |
|
| ... | ... | @@ -284,11 +284,11 @@ |
| 284 | 284 |
(:policy :fast-safe)
|
| 285 | 285 |
(:translate unix::do-pending-interrupt)
|
| 286 | 286 |
(:generator 1
|
| 287 |
- (inst break pending-interrupt-trap)))
|
|
| 287 |
+ (inst ud1 pending-interrupt-trap)))
|
|
| 288 | 288 |
|
| 289 | 289 |
(define-vop (halt)
|
| 290 | 290 |
(:generator 1
|
| 291 |
- (inst break halt-trap)))
|
|
| 291 |
+ (inst ud1 halt-trap)))
|
|
| 292 | 292 |
|
| 293 | 293 |
(defknown float-wait () (values))
|
| 294 | 294 |
(define-vop (float-wait)
|
| ... | ... | @@ -18,6 +18,11 @@ |
| 18 | 18 |
#include "internals.h"
|
| 19 | 19 |
#include "lispregs.h"
|
| 20 | 20 |
|
| 21 |
+#define TRAP_CODE(code) \
|
|
| 22 |
+ .byte 0x0f ; \
|
|
| 23 |
+ .byte 0xb9 ; \
|
|
| 24 |
+ .byte 0xc0 + code
|
|
| 25 |
+ |
|
| 21 | 26 |
/* Minimize conditionalization for different OS naming schemes */
|
| 22 | 27 |
#ifdef DARWIN
|
| 23 | 28 |
#define GNAME(var) _##var
|
| ... | ... | @@ -244,7 +249,9 @@ ENDFUNC(sse_restore) |
| 244 | 249 |
* The undefined-function trampoline.
|
| 245 | 250 |
*/
|
| 246 | 251 |
FUNCDEF(undefined_tramp)
|
| 247 |
- INT3
|
|
| 252 |
+ # UD1
|
|
| 253 |
+ .byte 0x0f
|
|
| 254 |
+ .byte 0xb9
|
|
| 248 | 255 |
.byte trap_Error
|
| 249 | 256 |
/* Number of argument bytes */
|
| 250 | 257 |
.byte 2
|
| ... | ... | @@ -286,8 +293,17 @@ multiple_value_return: |
| 286 | 293 |
|
| 287 | 294 |
.globl GNAME(function_end_breakpoint_trap)
|
| 288 | 295 |
GNAME(function_end_breakpoint_trap):
|
| 289 |
- UD2
|
|
| 290 |
- .byte trap_FunctionEndBreakpoint
|
|
| 296 |
+ /*
|
|
| 297 |
+ ud1 0(%ecx), %ecx
|
|
| 298 |
+ ud1 %ecx, %edx
|
|
| 299 |
+ .byte 0x0f
|
|
| 300 |
+ .byte 0xb9
|
|
| 301 |
+ .byte 0xc0 + trap_PendingInterrupt
|
|
| 302 |
+ */
|
|
| 303 |
+ # UD1
|
|
| 304 |
+ .byte 0x0f
|
|
| 305 |
+ .byte 0xb9
|
|
| 306 |
+ .byte 0xc0 + trap_FunctionEndBreakpoint
|
|
| 291 | 307 |
hlt # Should never return here.
|
| 292 | 308 |
|
| 293 | 309 |
.globl GNAME(function_end_breakpoint_end)
|
| ... | ... | @@ -295,14 +311,18 @@ GNAME(function_end_breakpoint_end): |
| 295 | 311 |
|
| 296 | 312 |
|
| 297 | 313 |
FUNCDEF(do_pending_interrupt)
|
| 298 |
- ud2
|
|
| 314 |
+ # UD1
|
|
| 315 |
+ .byte 0x0f
|
|
| 316 |
+ .byte 0xb9
|
|
| 299 | 317 |
.byte trap_PendingInterrupt
|
| 300 | 318 |
ret
|
| 301 | 319 |
ENDFUNC(do_pending_interrupt)
|
| 302 | 320 |
|
| 303 | 321 |
#ifdef trap_DynamicSpaceOverflowError
|
| 304 | 322 |
FUNCDEF(do_dynamic_space_overflow_error)
|
| 305 |
- ud2
|
|
| 323 |
+ # UD1
|
|
| 324 |
+ .byte 0x0f
|
|
| 325 |
+ .byte 0xb9
|
|
| 306 | 326 |
.byte trap_DynamicSpaceOverflowError
|
| 307 | 327 |
ret
|
| 308 | 328 |
ENDFUNC(do_dynamic_space_overflow_error)
|
| ... | ... | @@ -310,7 +330,9 @@ ENDFUNC(do_dynamic_space_overflow_error) |
| 310 | 330 |
|
| 311 | 331 |
#ifdef trap_DynamicSpaceOverflowWarning
|
| 312 | 332 |
FUNCDEF(do_dynamic_space_overflow_warning)
|
| 313 |
- ud2
|
|
| 333 |
+ # UD1
|
|
| 334 |
+ .byte 0x0f
|
|
| 335 |
+ .byte 0xb9
|
|
| 314 | 336 |
.byte trap_DynamicSpaceOverflowWarning
|
| 315 | 337 |
ret
|
| 316 | 338 |
ENDFUNC(do_dynamic_space_overflow_warning)
|
| ... | ... | @@ -493,7 +515,9 @@ FUNCDEF(undefined_foreign_symbol_trap) |
| 493 | 515 |
movl 8(%ebp),%eax
|
| 494 | 516 |
|
| 495 | 517 |
/* Now trap to Lisp */
|
| 496 |
- ud2
|
|
| 518 |
+ # UD1
|
|
| 519 |
+ .byte 0x0f
|
|
| 520 |
+ .byte 0xb9
|
|
| 497 | 521 |
.byte trap_Error
|
| 498 | 522 |
/* Number of argument bytes */
|
| 499 | 523 |
.byte 2
|