/[cmucl]/src/lisp/amd64-arch.c
ViewVC logotype

Diff of /src/lisp/amd64-arch.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by agoncharov, Sun Dec 7 02:33:55 2008 UTC revision 1.10 by rtoy, Mon Nov 2 02:51:58 2009 UTC
# Line 12  Line 12 
12  #include "os.h"  #include "os.h"
13  #include "internals.h"  #include "internals.h"
14  #include "arch.h"  #include "arch.h"
15    #define __USE_GNU
16  #include "lispregs.h"  #include "lispregs.h"
17  #include "signal.h"  #include "signal.h"
18  #include "alloc.h"  #include "alloc.h"
# Line 39  arch_init(fpu_mode_t mode) Line 40  arch_init(fpu_mode_t mode)
40   */   */
41    
42  void  void
43  arch_skip_instruction(struct sigcontext *context)  arch_skip_instruction(os_context_t *context)
44  {  {
45      int vlen, code;      int vlen, code;
46    
47      DPRINTF(0, (stderr, "[arch_skip_inst at %x>]\n", context->sc_pc));      DPRINTF(0, (stderr, "[arch_skip_inst at %x>]\n", SC_PC(context)));
48    
49      /* Get and skip the lisp error code. */      /* Get and skip the lisp error code. */
50      code = *(char *) context->sc_pc++;      code = *(char *) SC_PC(context)++;
51      switch (code) {      switch (code) {
52        case trap_Error:        case trap_Error:
53        case trap_Cerror:        case trap_Cerror:
54            /* Lisp error arg vector length */            /* Lisp error arg vector length */
55            vlen = *(char *) context->sc_pc++;            vlen = *(char *) SC_PC(context)++;
56            /* Skip lisp error arg data bytes */            /* Skip lisp error arg data bytes */
57            while (vlen-- > 0)            while (vlen-- > 0)
58                ((char *) context->sc_pc)++;                SC_PC(context)++;
59            break;            break;
60    
61        case trap_Breakpoint:        case trap_Breakpoint:
# Line 71  arch_skip_instruction(struct sigcontext Line 72  arch_skip_instruction(struct sigcontext
72            break;            break;
73      }      }
74    
75      DPRINTF(0, (stderr, "[arch_skip_inst resuming at %x>]\n", context->sc_pc));      DPRINTF(0, (stderr, "[arch_skip_inst resuming at %x>]\n", SC_PC(context)));
76  }  }
77    
78  unsigned char *  unsigned char *
79  arch_internal_error_arguments(struct sigcontext *context)  arch_internal_error_arguments(os_context_t *context)
80  {  {
81      return (unsigned char *) (context->sc_pc + 1);      return (unsigned char *) (SC_PC(context) + 1);
82  }  }
83    
84  boolean  boolean
85  arch_pseudo_atomic_atomic(struct sigcontext *context)  arch_pseudo_atomic_atomic(os_context_t *context)
86  {  {
87      return SymbolValue(PSEUDO_ATOMIC_ATOMIC);      return SymbolValue(PSEUDO_ATOMIC_ATOMIC);
88  }  }
89    
90  void  void
91  arch_set_pseudo_atomic_interrupted(struct sigcontext *context)  arch_set_pseudo_atomic_interrupted(os_context_t *context)
92  {  {
93      SetSymbolValue(PSEUDO_ATOMIC_INTERRUPTED, make_fixnum(1));      SetSymbolValue(PSEUDO_ATOMIC_INTERRUPTED, make_fixnum(1));
94  }  }
# Line 128  unsigned int single_step_save3; Line 129  unsigned int single_step_save3;
129  #endif  #endif
130    
131  void  void
132  arch_do_displaced_inst(struct sigcontext *context, unsigned long orig_inst)  arch_do_displaced_inst(os_context_t *context, unsigned long orig_inst)
133  {  {
134      unsigned int *pc = (unsigned int *) context->sc_pc;      unsigned int *pc = (unsigned int *) SC_PC(context);
135    
136      /*      /*
137       * Put the original instruction back.       * Put the original instruction back.
# Line 139  arch_do_displaced_inst(struct sigcontext Line 140  arch_do_displaced_inst(struct sigcontext
140      *((char *) pc) = orig_inst & 0xff;      *((char *) pc) = orig_inst & 0xff;
141      *((char *) pc + 1) = (orig_inst & 0xff00) >> 8;      *((char *) pc + 1) = (orig_inst & 0xff00) >> 8;
142    
143  #ifdef __linux__  #ifdef SC_EFLAGS
144      context->eflags |= 0x100;      SC_EFLAGS(context) |= 0x100;
145  #else  #else
146    
147      /*      /*
# Line 159  arch_do_displaced_inst(struct sigcontext Line 160  arch_do_displaced_inst(struct sigcontext
160      single_stepping = (unsigned int *) pc;      single_stepping = (unsigned int *) pc;
161    
162  #ifndef __linux__  #ifndef __linux__
163      (unsigned int *) context->sc_pc = (char *) pc - 9;      (unsigned int *) SC_PC(context) = (char *) pc - 9;
164  #endif  #endif
165  }  }
166    
# Line 169  sigtrap_handler(HANDLER_ARGS) Line 170  sigtrap_handler(HANDLER_ARGS)
170  {  {
171      unsigned int trap;      unsigned int trap;
172    
 #ifdef __linux__  
     GET_CONTEXT  
 #endif  
173  #if 0  #if 0
174          fprintf(stderr, "x86sigtrap: %8x %x\n",          fprintf(stderr, "x86sigtrap: %8x %x\n",
175                  context->sc_pc, *(unsigned char *) (context->sc_pc - 1));                  SC_PC(context), *(unsigned char *) (SC_PC(context) - 1));
176      fprintf(stderr, "sigtrap(%d %d %x)\n", signal, code, context);      fprintf(stderr, "sigtrap(%d %d %x)\n", signal, code, context);
177  #endif  #endif
178    
# Line 183  sigtrap_handler(HANDLER_ARGS) Line 181  sigtrap_handler(HANDLER_ARGS)
181          fprintf(stderr, "* Single step trap %x\n", single_stepping);          fprintf(stderr, "* Single step trap %x\n", single_stepping);
182  #endif  #endif
183    
184  #ifndef __linux__  #ifdef SC_EFLAGS
185            /* Disable single-stepping */
186            SC_EFLAGS(context) ^= 0x100;
187    #else
188          /* Un-install single step helper instructions. */          /* Un-install single step helper instructions. */
189          *(single_stepping - 3) = single_step_save1;          *(single_stepping - 3) = single_step_save1;
190          *(single_stepping - 2) = single_step_save2;          *(single_stepping - 2) = single_step_save2;
191          *(single_stepping - 1) = single_step_save3;          *(single_stepping - 1) = single_step_save3;
 #else  
         context->eflags ^= 0x100;  
192  #endif  #endif
193    
194          /*          /*
195           * Re-install the breakpoint if possible.           * Re-install the breakpoint if possible.
196           */           */
197    
198          if ((int) context->sc_pc == (int) single_stepping + 1)          if ((int) SC_PC(context) == (int) single_stepping + 1)
199              fprintf(stderr, "* Breakpoint not re-install\n");              fprintf(stderr, "* Breakpoint not re-install\n");
200          else {          else {
201              char *ptr = (char *) single_stepping;              char *ptr = (char *) single_stepping;
# Line 210  sigtrap_handler(HANDLER_ARGS) Line 209  sigtrap_handler(HANDLER_ARGS)
209      }      }
210    
211      /* This is just for info in case monitor wants to print an approx */      /* This is just for info in case monitor wants to print an approx */
212      current_control_stack_pointer = (unsigned long *) context->sc_sp;      current_control_stack_pointer = (unsigned long *) SC_SP(context);
   
 #if defined(__linux__) && (defined(i386) || defined(__x86_64))  
     /*  
      * Restore the FPU control word, setting the rounding mode to nearest.  
      */  
   
     if (contextstruct.fpstate)  
 #if defined(__x86_64)  
         setfpucw(contextstruct.fpstate->cwd & ~0xc00);  
 #else  
         setfpucw(contextstruct.fpstate->cw & ~0xc00);  
 #endif  
 #endif  
213    
214        RESTORE_FPU(context);
215      /*      /*
216       * On entry %eip points just after the INT3 byte and aims at the       * On entry %eip points just after the INT3 byte and aims at the
217       * 'kind' value (eg trap_Cerror). For error-trap and Cerror-trap a       * 'kind' value (eg trap_Cerror). For error-trap and Cerror-trap a
# Line 232  sigtrap_handler(HANDLER_ARGS) Line 219  sigtrap_handler(HANDLER_ARGS)
219       * arguments to follow.       * arguments to follow.
220       */       */
221    
222      trap = *(unsigned char *) (context->sc_pc);      trap = *(unsigned char *) (SC_PC(context));
223    
224      switch (trap) {      switch (trap) {
225        case trap_PendingInterrupt:        case trap_PendingInterrupt:
# Line 261  sigtrap_handler(HANDLER_ARGS) Line 248  sigtrap_handler(HANDLER_ARGS)
248        case trap_Error:        case trap_Error:
249        case trap_Cerror:        case trap_Cerror:
250            DPRINTF(0, (stderr, "<trap Error %d>\n", code));            DPRINTF(0, (stderr, "<trap Error %d>\n", code));
251  #ifdef __linux__            interrupt_internal_error(signal, code, context, CODE(code) == trap_Cerror);
           interrupt_internal_error(signal, contextstruct, code == trap_Cerror);  
 #else  
           interrupt_internal_error(signal, code, context, code == trap_Cerror);  
 #endif  
252            break;            break;
253    
254        case trap_Breakpoint:        case trap_Breakpoint:
255  #if 0  #if 0
256            fprintf(stderr, "*C break\n");            fprintf(stderr, "*C break\n");
257  #endif  #endif
258            (char *) context->sc_pc -= 1;            SC_PC(context) -= 1;
259            handle_breakpoint(signal, code, context);            handle_breakpoint(signal, CODE(code), context);
260  #if 0  #if 0
261            fprintf(stderr, "*C break return\n");            fprintf(stderr, "*C break return\n");
262  #endif  #endif
263            break;            break;
264    
265        case trap_FunctionEndBreakpoint:        case trap_FunctionEndBreakpoint:
266            (char *) context->sc_pc -= 1;            SC_PC(context) -= 1;
267            context->sc_pc =            SC_PC(context) =
268                (int) handle_function_end_breakpoint(signal, code, context);                (int) handle_function_end_breakpoint(signal, code, context);
269            break;            break;
270    
# Line 303  sigtrap_handler(HANDLER_ARGS) Line 286  sigtrap_handler(HANDLER_ARGS)
286            DPRINTF(0,            DPRINTF(0,
287                    (stderr, "[C--trap default %d %d %x]\n", signal, code,                    (stderr, "[C--trap default %d %d %x]\n", signal, code,
288                     context));                     context));
 #ifdef __linux__  
           interrupt_handle_now(signal, contextstruct);  
 #else  
289            interrupt_handle_now(signal, code, context);            interrupt_handle_now(signal, code, context);
 #endif  
290            break;            break;
291      }      }
292  }  }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.5