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

Commits:

1 changed file:

Changes:

  • src/lisp/x86-arch.c
    ... ... @@ -142,7 +142,7 @@ arch_skip_instruction(os_context_t * context)
    142 142
     {
    
    143 143
         int vlen, code;
    
    144 144
     
    
    145
    -    DPRINTF(0, (stderr, "[arch_skip_inst at %lx>]\n", SC_PC(context)));
    
    145
    +    DPRINTF(1, (stderr, "[arch_skip_inst at %lx>]\n", SC_PC(context)));
    
    146 146
     
    
    147 147
         /* Get and skip the lisp error code. */
    
    148 148
         char* pc = (char *) SC_PC(context);
    
    ... ... @@ -206,8 +206,8 @@ arch_set_pseudo_atomic_interrupted(os_context_t * context)
    206 206
     unsigned long
    
    207 207
     arch_install_breakpoint(void *pc)
    
    208 208
     {
    
    209
    -    char* ptr = (char *) pc;
    
    210
    -    unsigned long result = *(unsigned long *) pc;
    
    209
    +    unsigned char* ptr = (unsigned char *) pc;
    
    210
    +    unsigned long result = ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
    
    211 211
     
    
    212 212
         fprintf(stderr, "arch_install_breakpoint at %p, old code = 0x%lx\n",
    
    213 213
                 pc, result);
    
    ... ... @@ -227,8 +227,13 @@ arch_install_breakpoint(void *pc)
    227 227
     void
    
    228 228
     arch_remove_breakpoint(void *pc, unsigned long orig_inst)
    
    229 229
     {
    
    230
    -    *((char *) pc) = orig_inst & 0xff;
    
    231
    -    *((char *) pc + 1) = (orig_inst & 0xff00) >> 8;
    
    230
    +    fprintf(stderr, "arch_remove_breakpoint: %p orig %lx\n",
    
    231
    +            pc, orig_inst);
    
    232
    +    unsigned char *ptr = (unsigned char *) pc;
    
    233
    +    ptr[0] = orig_inst & 0xff;
    
    234
    +    ptr[1] = (orig_inst >> 8) & 0xff;
    
    235
    +    ptr[2] = (orig_inst >> 16) & 0xff;
    
    236
    +    ptr[3] = (orig_inst >> 24) & 0xff;
    
    232 237
     }
    
    233 238
     
    
    234 239
     
    
    ... ... @@ -249,14 +254,23 @@ unsigned int single_step_save3;
    249 254
     void
    
    250 255
     arch_do_displaced_inst(os_context_t * context, unsigned long orig_inst)
    
    251 256
     {
    
    252
    -    unsigned int *pc = (unsigned int *) SC_PC(context);
    
    257
    +    unsigned char *pc = (unsigned char *) SC_PC(context);
    
    253 258
     
    
    259
    +    fprintf(stderr, "arch_do_displaced_inst: pc %p orig_inst %lx\n",
    
    260
    +            pc, orig_inst);
    
    261
    +    
    
    254 262
         /*
    
    255 263
          * Put the original instruction back.
    
    256 264
          */
    
    257 265
     
    
    266
    +#if 0
    
    258 267
         *((char *) pc) = orig_inst & 0xff;
    
    259 268
         *((char *) pc + 1) = (orig_inst & 0xff00) >> 8;
    
    269
    +#else
    
    270
    +    pc[0] = orig_inst & 0xff;
    
    271
    +    pc[1] = (orig_inst >> 8) & 0xff;
    
    272
    +    pc[2] = (orig_inst >> 16) & 0xff;
    
    273
    +#endif
    
    260 274
     
    
    261 275
     #ifdef SC_EFLAGS
    
    262 276
         /* Enable single-stepping */
    
    ... ... @@ -319,8 +333,8 @@ sigill_handler(HANDLER_ARGS)
    319 333
         fprintf(stderr, "sigtrap(%d %d %p)\n", signal, CODE(code), os_context);
    
    320 334
     #endif
    
    321 335
     
    
    322
    -    if (single_stepping && (signal == SIGTRAP)) {
    
    323
    -#if 0
    
    336
    +    if (single_stepping && (signal == SIGILL)) {
    
    337
    +#if 1
    
    324 338
     	fprintf(stderr, "* Single step trap %p\n", single_stepping);
    
    325 339
     #endif
    
    326 340
     
    
    ... ... @@ -338,7 +352,9 @@ sigill_handler(HANDLER_ARGS)
    338 352
     	/*
    
    339 353
     	 * Re-install the breakpoint if possible.
    
    340 354
     	 */
    
    341
    -	if ((int) SC_PC(os_context) == (int) single_stepping + 1)
    
    355
    +        fprintf(stderr, "* Reinstall breakpoint at single_stepping %p\n", single_stepping);
    
    356
    +        
    
    357
    +	if ((int) SC_PC(os_context) >= (int) single_stepping + 3)
    
    342 358
     	    fprintf(stderr, "* Breakpoint not re-install\n");
    
    343 359
     	else {
    
    344 360
     	    char *ptr = (char *) single_stepping;
    
    ... ... @@ -460,10 +476,70 @@ sigill_handler(HANDLER_ARGS)
    460 476
         }
    
    461 477
     }
    
    462 478
     
    
    479
    +void
    
    480
    +sigtrap_handler(HANDLER_ARGS) 
    
    481
    +{
    
    482
    +    os_context_t* os_context = (os_context_t *) context;
    
    483
    +
    
    484
    +#if 1
    
    485
    +    fprintf(stderr,"sigtrap: fp=%lx sp=%lx pc=%lx { %x, %x, %x, %x, %x }\n",
    
    486
    +            SC_REG(context, reg_FP),
    
    487
    +            SC_REG(context, reg_SP),
    
    488
    +            SC_PC(context),
    
    489
    +            *(unsigned char*)(SC_PC(context) + 0), /* 0x0F */
    
    490
    +            *(unsigned char*)(SC_PC(context) + 1), /* 0x0B */
    
    491
    +            *(unsigned char*)(SC_PC(context) + 2),
    
    492
    +            *(unsigned char*)(SC_PC(context) + 3),
    
    493
    +            *(unsigned char*)(SC_PC(context) + 4));
    
    494
    +#endif    
    
    495
    +    if (single_stepping && (signal == SIGTRAP)) {
    
    496
    +#if 1
    
    497
    +	fprintf(stderr, "* Single step trap %p\n", single_stepping);
    
    498
    +#endif
    
    499
    +
    
    500
    +#ifdef SC_EFLAGS
    
    501
    +	/* Disable single-stepping */
    
    502
    +	SC_EFLAGS(os_context) ^= 0x100;
    
    503
    +#else
    
    504
    +	/* Un-install single step helper instructions. */
    
    505
    +	*(single_stepping - 3) = single_step_save1;
    
    506
    +	*(single_stepping - 2) = single_step_save2;
    
    507
    +	*(single_stepping - 1) = single_step_save3;
    
    508
    +        DPRINTF(0, (stderr, "Uninstalling helper instructions\n"));
    
    509
    +#endif
    
    510
    +
    
    511
    +	/*
    
    512
    +	 * Re-install the breakpoint if possible.
    
    513
    +	 */
    
    514
    +        fprintf(stderr, "* Maybe reinstall breakpoint for pc %p with single_stepping %p\n",
    
    515
    +                (void*) SC_PC(os_context), single_stepping);
    
    516
    +        
    
    517
    +	if ((unsigned long) SC_PC(os_context) <= (unsigned long) single_stepping + 3)
    
    518
    +	    fprintf(stderr, "* Breakpoint not re-install\n");
    
    519
    +	else {
    
    520
    +	    char *ptr = (char *) single_stepping;
    
    521
    +
    
    522
    +#if 0
    
    523
    +	    ptr[0] = BREAKPOINT_INST;	/* x86 INT3 */
    
    524
    +	    ptr[1] = trap_Breakpoint;
    
    525
    +#else
    
    526
    +            ptr[0] = 0x0f;
    
    527
    +            ptr[1] = 0x0b;
    
    528
    +            ptr[2] = trap_Breakpoint;
    
    529
    +#endif            
    
    530
    +	}
    
    531
    +
    
    532
    +	single_stepping = NULL;
    
    533
    +	return;
    
    534
    +    }
    
    535
    +}
    
    536
    +
    
    537
    +
    
    463 538
     void
    
    464 539
     arch_install_interrupt_handlers(void)
    
    465 540
     {
    
    466 541
         interrupt_install_low_level_handler(SIGILL, sigill_handler);
    
    542
    +    interrupt_install_low_level_handler(SIGTRAP, sigtrap_handler);
    
    467 543
     }
    
    468 544
     
    
    469 545