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

Commits:

3 changed files:

Changes:

  • src/code/x86-vm.lisp
    ... ... @@ -237,16 +237,19 @@
    237 237
       (with-alien ((scp (* unix:sigcontext) scp))
    
    238 238
         (let ((pc (sigcontext-program-counter scp)))
    
    239 239
           (declare (type system-area-pointer pc))
    
    240
    -      ;; The pc should point to the start of the UD1 instruction.  So we have something like:
    
    240
    +      ;; The pc should point to the start of the UD1 instruction.  So
    
    241
    +      ;; we have something like:
    
    242
    +      ;;
    
    241 243
           ;;   offset  contents
    
    242 244
           ;;   0       UD1 (contains the trap code)
    
    243 245
           ;;   3       length
    
    244
    -      ;;   4       bytes
    
    246
    +      ;;   4...    bytes
    
    245 247
           (let* ((length (sap-ref-8 pc 3))
    
    246 248
     	     (vector (make-array length :element-type '(unsigned-byte 8))))
    
    247 249
     	(declare (type (unsigned-byte 8) length)
    
    248 250
     		 (type (simple-array (unsigned-byte 8) (*)) vector))
    
    249
    -	;; Grab the length bytes after the length byte.
    
    251
    +	;; Grab bytes after the length byte where the number of bytes is
    
    252
    +	;; given by value of the length byte.
    
    250 253
     	(copy-from-system-area pc (* vm:byte-bits 4)
    
    251 254
     			       vector (* vm:word-bits
    
    252 255
     					 vm:vector-data-offset)
    

  • src/compiler/x86/insts.lisp
    ... ... @@ -2115,7 +2115,7 @@
    2115 2115
       (declare (ignore inst))
    
    2116 2116
       (flet ((nt (x) (if stream (disassem:note x dstate))))
    
    2117 2117
         (let ((code (ldb (byte 6 16) chunk)))
    
    2118
    -      (case code
    
    2118
    +      (ecase code
    
    2119 2119
     	(#.vm:error-trap
    
    2120 2120
     	 (nt #.(format nil "Trap ~D: Error trap" vm:error-trap))
    
    2121 2121
     	 (disassem:handle-break-args #'snarf-error-junk stream dstate))
    
    ... ... @@ -2128,9 +2128,7 @@
    2128 2128
     	 (nt #.(format nil "Trap ~D: Halt trap" vm:halt-trap)))
    
    2129 2129
     	(#.vm:function-end-breakpoint-trap
    
    2130 2130
     	 (nt #.(format nil "Trap ~D: Function end breakpoint trap"
    
    2131
    -		       vm:function-end-breakpoint-trap)))
    
    2132
    -	(t
    
    2133
    -	 (nt (format nil "Trap ~D: Unexpected trap type!!!!" code)))))))
    
    2131
    +		       vm:function-end-breakpoint-trap)))))))
    
    2134 2132
     
    
    2135 2133
     ;; The ud1 instruction where we smash the code (trap type) into the
    
    2136 2134
     ;; low 6 bits of the mod r/m byte.  The mod bits are set to #b11 to
    

  • src/lisp/x86-arch.c
    ... ... @@ -23,7 +23,12 @@
    23 23
     
    
    24 24
     #define BREAKPOINT_INST 0xcc	/* INT3 */
    
    25 25
     
    
    26
    -unsigned long fast_random_state = 1;
    
    26
    +/*
    
    27
    + * The first two bytes of the UD1 instruction.  The mod r/m byte isn't
    
    28
    + * included here.
    
    29
    + */
    
    30
    +static const unsigned char ud1[] = {0x0f, 0xb9};
    
    31
    +      
    
    27 32
     
    
    28 33
     /*
    
    29 34
      * Set to positive value to enabled debug prints related to the sigill
    
    ... ... @@ -153,8 +158,10 @@ arch_skip_instruction(os_context_t * context)
    153 158
         /* Get and skip the lisp error code. */
    
    154 159
         char* pc = (char *) SC_PC(context);
    
    155 160
         
    
    156
    -    /* Skip over the UD2 inst (0x0f, 0x0b) */
    
    157
    -    pc += 2;
    
    161
    +    /*
    
    162
    +     * Skip over the part of the UD1 inst (0x0f, 0xb9) so we can get to the mod r/m byte
    
    163
    +     */
    
    164
    +    pc += sizeof(ud1);
    
    158 165
     
    
    159 166
         code = *pc++;
    
    160 167
         SC_PC(context) = (unsigned long) pc;
    
    ... ... @@ -167,10 +174,7 @@ arch_skip_instruction(os_context_t * context)
    167 174
               SC_PC(context) = (unsigned long) pc;
    
    168 175
               
    
    169 176
     	  /* Skip lisp error arg data bytes */
    
    170
    -	  while (vlen-- > 0) {
    
    171
    -              pc++;
    
    172
    -              SC_PC(context) = (unsigned long) pc;
    
    173
    -          }
    
    177
    +          SC_PC(context) = (unsigned long) (pc + vlen);
    
    174 178
     	  break;
    
    175 179
     
    
    176 180
           case trap_Breakpoint:
    
    ... ... @@ -382,75 +386,75 @@ sigill_handler(HANDLER_ARGS)
    382 386
          * should call interrupt_handle_now, as we do below for an unknown
    
    383 387
          * trap code?
    
    384 388
          */
    
    385
    -    if (*(unsigned short *) SC_PC(context) == 0xb90f) {
    
    386
    -        /*
    
    387
    -         * This must match what the lisp code is doing.  The trap
    
    388
    -         * number is placed in the low 6-bits of the 3rd byte of the
    
    389
    -         * instruction.
    
    390
    -         */
    
    391
    -        trap = *(((char *)SC_PC(context)) + 2) & 63;
    
    392
    -    } else {
    
    393
    -        abort();
    
    394
    -    }
    
    389
    +    if (memcmp((void *)SC_PC(context), ud1, sizeof(ud1)) == 0) {
    
    390
    +      /*
    
    391
    +       * This must match what the lisp code is doing.  The trap
    
    392
    +       * number is placed in the low 6-bits of the 3rd byte of the
    
    393
    +       * instruction.
    
    394
    +       */
    
    395
    +      trap = *(((char *)SC_PC(context)) + 2) & 63;
    
    395 396
     
    
    396
    -    DPRINTF(debug_handlers, (stderr, "code = %x\n", trap));
    
    397
    +      DPRINTF(debug_handlers, (stderr, "code = %x\n", trap));
    
    397 398
     
    
    398
    -    switch (trap) {
    
    399
    +      switch (trap) {
    
    399 400
           case trap_PendingInterrupt:
    
    400
    -	  DPRINTF(debug_handlers, (stderr, "<trap Pending Interrupt.>\n"));
    
    401
    -	  arch_skip_instruction(os_context);
    
    402
    -	  interrupt_handle_pending(os_context);
    
    403
    -	  break;
    
    401
    +        DPRINTF(debug_handlers, (stderr, "<trap Pending Interrupt.>\n"));
    
    402
    +        arch_skip_instruction(os_context);
    
    403
    +        interrupt_handle_pending(os_context);
    
    404
    +        break;
    
    404 405
     
    
    405 406
           case trap_Halt:
    
    406
    -	  {
    
    407
    -              FPU_STATE(fpu_state);
    
    408
    -              save_fpu_state(fpu_state);
    
    407
    +        {
    
    408
    +          FPU_STATE(fpu_state);
    
    409
    +          save_fpu_state(fpu_state);
    
    409 410
     
    
    410
    -	      fake_foreign_function_call(os_context);
    
    411
    -	      lose("%%primitive halt called; the party is over.\n");
    
    412
    -	      undo_fake_foreign_function_call(os_context);
    
    411
    +          fake_foreign_function_call(os_context);
    
    412
    +          lose("%%primitive halt called; the party is over.\n");
    
    413
    +          undo_fake_foreign_function_call(os_context);
    
    413 414
     
    
    414
    -              restore_fpu_state(fpu_state);
    
    415
    -	      arch_skip_instruction(os_context);
    
    416
    -	      break;
    
    417
    -	  }
    
    415
    +          restore_fpu_state(fpu_state);
    
    416
    +          arch_skip_instruction(os_context);
    
    417
    +          break;
    
    418
    +        }
    
    418 419
     
    
    419 420
           case trap_Error:
    
    420 421
           case trap_Cerror:
    
    421
    -	  DPRINTF(debug_handlers, (stderr, "<trap Error %x>\n", CODE(code)));
    
    422
    -	  interrupt_internal_error(signal, code, os_context, CODE(code) == trap_Cerror);
    
    423
    -	  break;
    
    422
    +        DPRINTF(debug_handlers, (stderr, "<trap Error %x>\n", CODE(code)));
    
    423
    +        interrupt_internal_error(signal, code, os_context, CODE(code) == trap_Cerror);
    
    424
    +        break;
    
    424 425
     
    
    425 426
           case trap_Breakpoint:
    
    426
    -          lose("Unexpected breakpoint trap in sigill-hander.\n");
    
    427
    -	  break;
    
    427
    +        lose("Unexpected breakpoint trap in sigill-hander.\n");
    
    428
    +        break;
    
    428 429
     
    
    429 430
           case trap_FunctionEndBreakpoint:
    
    430
    -	  SC_PC(os_context) =
    
    431
    -	      (int) handle_function_end_breakpoint(signal, CODE(code), os_context);
    
    432
    -	  break;
    
    431
    +        SC_PC(os_context) =
    
    432
    +          (int) handle_function_end_breakpoint(signal, CODE(code), os_context);
    
    433
    +        break;
    
    433 434
     
    
    434 435
     #ifdef trap_DynamicSpaceOverflowWarning
    
    435 436
           case trap_DynamicSpaceOverflowWarning:
    
    436
    -	  interrupt_handle_space_overflow(SymbolFunction
    
    437
    -					  (DYNAMIC_SPACE_OVERFLOW_WARNING_HIT),
    
    438
    -					  os_context);
    
    439
    -	  break;
    
    437
    +        interrupt_handle_space_overflow(SymbolFunction
    
    438
    +                                        (DYNAMIC_SPACE_OVERFLOW_WARNING_HIT),
    
    439
    +                                        os_context);
    
    440
    +        break;
    
    440 441
     #endif
    
    441 442
     #ifdef trap_DynamicSpaceOverflowError
    
    442 443
           case trap_DynamicSpaceOverflowError:
    
    443
    -	  interrupt_handle_space_overflow(SymbolFunction
    
    444
    -					  (DYNAMIC_SPACE_OVERFLOW_ERROR_HIT),
    
    445
    -					  os_context);
    
    446
    -	  break;
    
    444
    +        interrupt_handle_space_overflow(SymbolFunction
    
    445
    +                                        (DYNAMIC_SPACE_OVERFLOW_ERROR_HIT),
    
    446
    +                                        os_context);
    
    447
    +        break;
    
    447 448
     #endif
    
    448 449
           default:
    
    449
    -	  DPRINTF(debug_handlers,
    
    450
    -		  (stderr, "[C--trap default %d %d %p]\n", signal, CODE(code),
    
    451
    -		   os_context));
    
    452
    -	  interrupt_handle_now(signal, code, os_context);
    
    453
    -	  break;
    
    450
    +        DPRINTF(debug_handlers,
    
    451
    +                (stderr, "[C--trap default %d %d %p]\n", signal, CODE(code),
    
    452
    +                 os_context));
    
    453
    +        interrupt_handle_now(signal, code, os_context);
    
    454
    +        break;
    
    455
    +      }
    
    456
    +    } else {
    
    457
    +      interrupt_handle_now(signal, code, os_context);
    
    454 458
         }
    
    455 459
     }
    
    456 460