/[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.12.1 by rtoy, Mon Nov 2 14:29:46 2009 UTC revision 1.11 by rtoy, Mon Nov 2 15:05:07 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"
 #define __USE_GNU  
15  #include "lispregs.h"  #include "lispregs.h"
16  #include "signal.h"  #include "signal.h"
17  #include "alloc.h"  #include "alloc.h"
# Line 40  arch_init(fpu_mode_t mode) Line 39  arch_init(fpu_mode_t mode)
39   */   */
40    
41  void  void
42  arch_skip_instruction(os_context_t *context)  arch_skip_instruction(struct sigcontext *context)
43  {  {
44      int vlen, code;      int vlen, code;
45    
46      DPRINTF(0, (stderr, "[arch_skip_inst at %x>]\n", SC_PC(context)));      DPRINTF(0, (stderr, "[arch_skip_inst at %x>]\n", context->sc_pc));
47    
48      /* Get and skip the lisp error code. */      /* Get and skip the lisp error code. */
49      code = *(char *) SC_PC(context)++;      code = *(char *) context->sc_pc++;
50      switch (code) {      switch (code) {
51        case trap_Error:        case trap_Error:
52        case trap_Cerror:        case trap_Cerror:
53            /* Lisp error arg vector length */            /* Lisp error arg vector length */
54            vlen = *(char *) SC_PC(context)++;            vlen = *(char *) context->sc_pc++;
55            /* Skip lisp error arg data bytes */            /* Skip lisp error arg data bytes */
56            while (vlen-- > 0)            while (vlen-- > 0)
57                SC_PC(context)++;                ((char *) context->sc_pc)++;
58            break;            break;
59    
60        case trap_Breakpoint:        case trap_Breakpoint:
# Line 72  arch_skip_instruction(os_context_t *cont Line 71  arch_skip_instruction(os_context_t *cont
71            break;            break;
72      }      }
73    
74      DPRINTF(0, (stderr, "[arch_skip_inst resuming at %x>]\n", SC_PC(context)));      DPRINTF(0, (stderr, "[arch_skip_inst resuming at %x>]\n", context->sc_pc));
75  }  }
76    
77  unsigned char *  unsigned char *
78  arch_internal_error_arguments(os_context_t *context)  arch_internal_error_arguments(struct sigcontext *context)
79  {  {
80      return (unsigned char *) (SC_PC(context) + 1);      return (unsigned char *) (context->sc_pc + 1);
81  }  }
82    
83  boolean  boolean
84  arch_pseudo_atomic_atomic(os_context_t *context)  arch_pseudo_atomic_atomic(struct sigcontext *context)
85  {  {
86      return SymbolValue(PSEUDO_ATOMIC_ATOMIC);      return SymbolValue(PSEUDO_ATOMIC_ATOMIC);
87  }  }
88    
89  void  void
90  arch_set_pseudo_atomic_interrupted(os_context_t *context)  arch_set_pseudo_atomic_interrupted(struct sigcontext *context)
91  {  {
92      SetSymbolValue(PSEUDO_ATOMIC_INTERRUPTED, make_fixnum(1));      SetSymbolValue(PSEUDO_ATOMIC_INTERRUPTED, make_fixnum(1));
93  }  }
# Line 129  unsigned int single_step_save3; Line 128  unsigned int single_step_save3;
128  #endif  #endif
129    
130  void  void
131  arch_do_displaced_inst(os_context_t *context, unsigned long orig_inst)  arch_do_displaced_inst(struct sigcontext *context, unsigned long orig_inst)
132  {  {
133      unsigned int *pc = (unsigned int *) SC_PC(context);      unsigned int *pc = (unsigned int *) context->sc_pc;
134    
135      /*      /*
136       * Put the original instruction back.       * Put the original instruction back.
# Line 140  arch_do_displaced_inst(os_context_t *con Line 139  arch_do_displaced_inst(os_context_t *con
139      *((char *) pc) = orig_inst & 0xff;      *((char *) pc) = orig_inst & 0xff;
140      *((char *) pc + 1) = (orig_inst & 0xff00) >> 8;      *((char *) pc + 1) = (orig_inst & 0xff00) >> 8;
141    
142  #ifdef SC_EFLAGS  #ifdef __linux__
143      SC_EFLAGS(context) |= 0x100;      context->eflags |= 0x100;
144  #else  #else
145    
146      /*      /*
# Line 160  arch_do_displaced_inst(os_context_t *con Line 159  arch_do_displaced_inst(os_context_t *con
159      single_stepping = (unsigned int *) pc;      single_stepping = (unsigned int *) pc;
160    
161  #ifndef __linux__  #ifndef __linux__
162      (unsigned int *) SC_PC(context) = (char *) pc - 9;      (unsigned int *) context->sc_pc = (char *) pc - 9;
163  #endif  #endif
164  }  }
165    
# Line 170  sigtrap_handler(HANDLER_ARGS) Line 169  sigtrap_handler(HANDLER_ARGS)
169  {  {
170      unsigned int trap;      unsigned int trap;
171    
172    #ifdef __linux__
173        GET_CONTEXT
174    #endif
175  #if 0  #if 0
176          fprintf(stderr, "x86sigtrap: %8x %x\n",          fprintf(stderr, "x86sigtrap: %8x %x\n",
177                  SC_PC(context), *(unsigned char *) (SC_PC(context) - 1));                  context->sc_pc, *(unsigned char *) (context->sc_pc - 1));
178      fprintf(stderr, "sigtrap(%d %d %x)\n", signal, code, context);      fprintf(stderr, "sigtrap(%d %d %x)\n", signal, code, context);
179  #endif  #endif
180    
# Line 181  sigtrap_handler(HANDLER_ARGS) Line 183  sigtrap_handler(HANDLER_ARGS)
183          fprintf(stderr, "* Single step trap %x\n", single_stepping);          fprintf(stderr, "* Single step trap %x\n", single_stepping);
184  #endif  #endif
185    
186  #ifdef SC_EFLAGS  #ifndef __linux__
         /* Disable single-stepping */  
         SC_EFLAGS(context) ^= 0x100;  
 #else  
187          /* Un-install single step helper instructions. */          /* Un-install single step helper instructions. */
188          *(single_stepping - 3) = single_step_save1;          *(single_stepping - 3) = single_step_save1;
189          *(single_stepping - 2) = single_step_save2;          *(single_stepping - 2) = single_step_save2;
190          *(single_stepping - 1) = single_step_save3;          *(single_stepping - 1) = single_step_save3;
191    #else
192            context->eflags ^= 0x100;
193  #endif  #endif
194    
195          /*          /*
196           * Re-install the breakpoint if possible.           * Re-install the breakpoint if possible.
197           */           */
198    
199          if ((int) SC_PC(context) == (int) single_stepping + 1)          if ((int) context->sc_pc == (int) single_stepping + 1)
200              fprintf(stderr, "* Breakpoint not re-install\n");              fprintf(stderr, "* Breakpoint not re-install\n");
201          else {          else {
202              char *ptr = (char *) single_stepping;              char *ptr = (char *) single_stepping;
# Line 209  sigtrap_handler(HANDLER_ARGS) Line 210  sigtrap_handler(HANDLER_ARGS)
210      }      }
211    
212      /* 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 */
213      current_control_stack_pointer = (unsigned long *) SC_SP(context);      current_control_stack_pointer = (unsigned long *) context->sc_sp;
214    
215    #if defined(__linux__) && (defined(i386) || defined(__x86_64))
216        /*
217         * Restore the FPU control word, setting the rounding mode to nearest.
218         */
219    
220        if (contextstruct.fpstate)
221    #if defined(__x86_64)
222            setfpucw(contextstruct.fpstate->cwd & ~0xc00);
223    #else
224            setfpucw(contextstruct.fpstate->cw & ~0xc00);
225    #endif
226    #endif
227    
     RESTORE_FPU(context);  
228      /*      /*
229       * 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
230       * '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 219  sigtrap_handler(HANDLER_ARGS) Line 232  sigtrap_handler(HANDLER_ARGS)
232       * arguments to follow.       * arguments to follow.
233       */       */
234    
235      trap = *(unsigned char *) (SC_PC(context));      trap = *(unsigned char *) (context->sc_pc);
236    
237      switch (trap) {      switch (trap) {
238        case trap_PendingInterrupt:        case trap_PendingInterrupt:
# Line 248  sigtrap_handler(HANDLER_ARGS) Line 261  sigtrap_handler(HANDLER_ARGS)
261        case trap_Error:        case trap_Error:
262        case trap_Cerror:        case trap_Cerror:
263            DPRINTF(0, (stderr, "<trap Error %d>\n", code));            DPRINTF(0, (stderr, "<trap Error %d>\n", code));
264            interrupt_internal_error(signal, code, context, CODE(code) == trap_Cerror);  #ifdef __linux__
265              interrupt_internal_error(signal, contextstruct, code == trap_Cerror);
266    #else
267              interrupt_internal_error(signal, code, context, code == trap_Cerror);
268    #endif
269            break;            break;
270    
271        case trap_Breakpoint:        case trap_Breakpoint:
272  #if 0  #if 0
273            fprintf(stderr, "*C break\n");            fprintf(stderr, "*C break\n");
274  #endif  #endif
275            SC_PC(context) -= 1;            (char *) context->sc_pc -= 1;
276            handle_breakpoint(signal, CODE(code), context);            handle_breakpoint(signal, code, context);
277  #if 0  #if 0
278            fprintf(stderr, "*C break return\n");            fprintf(stderr, "*C break return\n");
279  #endif  #endif
280            break;            break;
281    
282        case trap_FunctionEndBreakpoint:        case trap_FunctionEndBreakpoint:
283            SC_PC(context) -= 1;            (char *) context->sc_pc -= 1;
284            SC_PC(context) =            context->sc_pc =
285                (int) handle_function_end_breakpoint(signal, code, context);                (int) handle_function_end_breakpoint(signal, code, context);
286            break;            break;
287    
# Line 286  sigtrap_handler(HANDLER_ARGS) Line 303  sigtrap_handler(HANDLER_ARGS)
303            DPRINTF(0,            DPRINTF(0,
304                    (stderr, "[C--trap default %d %d %x]\n", signal, code,                    (stderr, "[C--trap default %d %d %x]\n", signal, code,
305                     context));                     context));
306    #ifdef __linux__
307              interrupt_handle_now(signal, contextstruct);
308    #else
309            interrupt_handle_now(signal, code, context);            interrupt_handle_now(signal, code, context);
310    #endif
311            break;            break;
312      }      }
313  }  }

Legend:
Removed from v.1.9.12.1  
changed lines
  Added in v.1.11

  ViewVC Help
Powered by ViewVC 1.1.5