/[cmucl]/src/lisp/FreeBSD-os.c
ViewVC logotype

Diff of /src/lisp/FreeBSD-os.c

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

revision 1.23.4.2 by rtoy, Fri Dec 19 01:31:34 2008 UTC revision 1.23.4.3 by agoncharov, Wed May 13 02:53:40 2009 UTC
# Line 37  Line 37 
37  #endif  #endif
38    
39  vm_size_t os_vm_page_size;  vm_size_t os_vm_page_size;
   
40    
41  void  void
42  os_init(void)  os_init(void)
# Line 49  unsigned long * Line 48  unsigned long *
48  os_sigcontext_reg(ucontext_t *scp, int index)  os_sigcontext_reg(ucontext_t *scp, int index)
49  {  {
50      __register_t *rv;      __register_t *rv;
51    
52      switch (index) {      switch (index) {
53      case 0:        case 0:
54          rv = &scp->uc_mcontext.mc_eax;          rv = &scp->uc_mcontext.mc_eax;
55          break;          break;
56      case 2:        case 2:
57          rv = &scp->uc_mcontext.mc_ecx;          rv = &scp->uc_mcontext.mc_ecx;
58          break;          break;
59      case 4:        case 4:
60          rv = &scp->uc_mcontext.mc_edx;          rv = &scp->uc_mcontext.mc_edx;
61          break;          break;
62      case 6:        case 6:
63          rv = &scp->uc_mcontext.mc_ebx;          rv = &scp->uc_mcontext.mc_ebx;
64          break;          break;
65      case 8:        case 8:
66          rv = &scp->uc_mcontext.mc_esp;          rv = &scp->uc_mcontext.mc_esp;
67          break;          break;
68      case 10:        case 10:
69          rv = &scp->uc_mcontext.mc_ebp;          rv = &scp->uc_mcontext.mc_ebp;
70          break;          break;
71      case 12:        case 12:
72          rv = &scp->uc_mcontext.mc_esi;          rv = &scp->uc_mcontext.mc_esi;
73          break;          break;
74      case 14:        case 14:
75          rv = &scp->uc_mcontext.mc_edi;          rv = &scp->uc_mcontext.mc_edi;
76          break;          break;
77      default:        default:
78          rv = NULL;          rv = NULL;
79      }      }
80    
81      /* Pre-cast to (void *), to avoid the compiler warning:      /* Pre-cast to (void *), to avoid the compiler warning:
82       * FreeBSD-os.c:72: warning: dereferencing type-punned pointer will break strict-aliasing rules       * dereferencing type-punned pointer will break strict-aliasing rules
83       */       */
84      return (unsigned long *) (void *) rv;      return (unsigned long *) (void *) rv;
85  }  }
86    
87  unsigned long *  unsigned long *
# Line 98  os_sigcontext_fpu_reg(ucontext_t *scp, i Line 98  os_sigcontext_fpu_reg(ucontext_t *scp, i
98      unsigned char *reg = NULL;      unsigned char *reg = NULL;
99    
100      switch (fpformat) {      switch (fpformat) {
101      case _MC_FPFMT_XMM:        case _MC_FPFMT_XMM:
102           reg = sv->sv_xmm.sv_fp[index].fp_acc.fp_bytes;            reg = sv->sv_xmm.sv_fp[index].fp_acc.fp_bytes;
103           break;            break;
104      case _MC_FPFMT_387:        case _MC_FPFMT_387:
105           reg = sv->sv_87.sv_ac[index].fp_bytes;            reg = sv->sv_87.sv_ac[index].fp_bytes;
106           break;            break;
107      case _MC_FPFMT_NODEV:        case _MC_FPFMT_NODEV:
108           reg = NULL;            reg = NULL;
109           break;            break;
110      }      }
111      return reg;      return reg;
112  }  }
# Line 115  unsigned int Line 115  unsigned int
115  os_sigcontext_fpu_modes(ucontext_t *scp)  os_sigcontext_fpu_modes(ucontext_t *scp)
116  {  {
117      unsigned int modes;      unsigned int modes;
118    
119      union savefpu *sv = (union savefpu *) scp->uc_mcontext.mc_fpstate;      union savefpu *sv = (union savefpu *) scp->uc_mcontext.mc_fpstate;
120      int fpformat = scp->uc_mcontext.mc_fpformat;      int fpformat = scp->uc_mcontext.mc_fpformat;
121      struct env87 *env_87 = &sv->sv_87.sv_env;      struct env87 *env_87 = &sv->sv_87.sv_env;
# Line 129  os_sigcontext_fpu_modes(ucontext_t *scp) Line 129  os_sigcontext_fpu_modes(ucontext_t *scp)
129      } else if (fpformat == _MC_FPFMT_387) {      } else if (fpformat == _MC_FPFMT_387) {
130          cw = env_87->en_cw & 0xffff;          cw = env_87->en_cw & 0xffff;
131          sw = env_87->en_sw & 0xffff;          sw = env_87->en_sw & 0xffff;
132      } else {  /* _MC_FPFMT_NODEV */      } else { /* _MC_FPFMT_NODEV */
133          cw = 0;          cw = 0;
134          sw = 0x3f;          sw = 0x3f;
135      }      }
# Line 137  os_sigcontext_fpu_modes(ucontext_t *scp) Line 137  os_sigcontext_fpu_modes(ucontext_t *scp)
137      modes = ((cw & 0x3f) << 7) | (sw & 0x3f);      modes = ((cw & 0x3f) << 7) | (sw & 0x3f);
138    
139  #ifdef FEATURE_SSE2  #ifdef FEATURE_SSE2
140      if (arch_support_sse2()) {      if (fpu_mode == SSE2) {
141          u_int32_t mxcsr = env_xmm->en_mxcsr;          u_int32_t mxcsr = env_xmm->en_mxcsr;
142          DPRINTF(0, (stderr, "SSE2 modes = %08x\n", (int) mxcsr));  
143            DPRINTF(0, (stderr, "SSE2 modes = %08x\n", (int)mxcsr));
144          modes |= mxcsr;          modes |= mxcsr;
145      }      }
146  #endif  #endif
# Line 147  os_sigcontext_fpu_modes(ucontext_t *scp) Line 148  os_sigcontext_fpu_modes(ucontext_t *scp)
148      return modes;      return modes;
149  }  }
150    
151  os_vm_address_t os_validate(os_vm_address_t addr, os_vm_size_t len)  os_vm_address_t
152    os_validate(os_vm_address_t addr, os_vm_size_t len)
153  {  {
154      int flags = MAP_PRIVATE | MAP_ANON;      int flags = MAP_PRIVATE | MAP_ANON;
155    
# Line 207  in_range_p(os_vm_address_t a, lispobj sb Line 209  in_range_p(os_vm_address_t a, lispobj sb
209      return adr >= beg && adr < end;      return adr >= beg && adr < end;
210  }  }
211    
212  boolean valid_addr(os_vm_address_t addr)  boolean
213    valid_addr(os_vm_address_t addr)
214  {  {
215      os_vm_address_t newaddr;      os_vm_address_t newaddr;
216    
# Line 227  boolean valid_addr(os_vm_address_t addr) Line 230  boolean valid_addr(os_vm_address_t addr)
230    
231    
232  static void  static void
233  sigbus_handler(int signal, siginfo_t *info, ucontext_t *context)  protection_violation_handler(HANDLER_ARGS)
234  {  {
235  #ifdef RED_ZONE_HIT  #ifdef RED_ZONE_HIT
236      if (os_control_stack_overflow(info->si_addr, context))      if (os_control_stack_overflow(code->si_addr, context))
237          return;          return;
238  #endif  #endif
239    
240  #if defined GENCGC  #if defined GENCGC
241      if (info->si_code == PROTECTION_VIOLATION_CODE) {      if (code->si_code == PROTECTION_VIOLATION_CODE) {
242          if (gc_write_barrier(info->si_addr)) {          if (gc_write_barrier(code->si_addr)) {
243              return;              return;
244          }          }
245      }      }
246  #endif /* GENCGC */  #endif
247    
248      interrupt_handle_now(signal, info, context);      interrupt_handle_now(signal, code, context);
249  }  }
250    
251  /*  /*
# Line 253  sigbus_handler(int signal, siginfo_t *in Line 256  sigbus_handler(int signal, siginfo_t *in
256   * if the subcode is FPE_FLTUND.   * if the subcode is FPE_FLTUND.
257   */   */
258  static void  static void
259  sigfpe_handler(int signal, siginfo_t *info, ucontext_t *context)  sigfpe_handler(HANDLER_ARGS)
260  {  {
261       union savefpu *sv = (union savefpu *) context->uc_mcontext.mc_fpstate;      ucontext_t *ucontext = (ucontext_t *) context;
262       int fpformat = context->uc_mcontext.mc_fpformat;      union savefpu *sv = (union savefpu *) ucontext->uc_mcontext.mc_fpstate;
263       int code = info->si_code;      int fpformat = ucontext->uc_mcontext.mc_fpformat;
264       unsigned char trap = 0;      unsigned char trap = 0;
265    
266       switch (code) {      switch (code->si_code) {
267       case FPE_FLTDIV:  /* ZE */        case FPE_FLTDIV:          /* ZE */
268            trap = 0x04;            trap = 0x04;
269            break;            break;
270       case FPE_FLTOVF:  /* OE */        case FPE_FLTOVF:          /* OE */
271            trap = 0x08;            trap = 0x08;
272            break;            break;
273       case FPE_FLTUND:  /* DE or UE */        case FPE_FLTUND:          /* DE or UE */
274            trap = 0x10;            trap = 0x10;
275            break;            break;
276       case FPE_FLTRES:  /* PE */        case FPE_FLTRES:          /* PE */
277            trap = 0x20;            trap = 0x20;
278            break;            break;
279       case FPE_FLTINV:  /* IE */        case FPE_FLTINV:          /* IE */
280            trap = 0x01;            trap = 0x01;
281            break;            break;
282       }      }
283       switch (fpformat) {  
284       case _MC_FPFMT_XMM:      switch (fpformat) {
285          case _MC_FPFMT_XMM:
286            sv->sv_xmm.sv_env.en_sw |= trap;            sv->sv_xmm.sv_env.en_sw |= trap;
287            break;            break;
288       case _MC_FPFMT_387:        case _MC_FPFMT_387:
289            sv->sv_87.sv_env.en_sw |= trap;            sv->sv_87.sv_env.en_sw |= trap;
290            break;            break;
291       }      }
292       interrupt_handle_now(signal, info, context);      interrupt_handle_now(signal, code, context);
293  }  }
294    
295  void  void
296  os_install_interrupt_handlers(void)  os_install_interrupt_handlers(void)
297  {  {
298      interrupt_install_low_level_handler      interrupt_install_low_level_handler(PROTECTION_VIOLATION_SIGNAL,
299          (PROTECTION_VIOLATION_SIGNAL, sigbus_handler);                                          protection_violation_handler);
300      interrupt_install_low_level_handler(SIGFPE, sigfpe_handler);      interrupt_install_low_level_handler(SIGFPE, sigfpe_handler);
301  }  }
302    
# Line 305  os_dlsym(const char *sym_name, lispobj l Line 309  os_dlsym(const char *sym_name, lispobj l
309          for (lib_list_head = lib_list;          for (lib_list_head = lib_list;
310               lib_list_head != NIL; lib_list_head = CONS(lib_list_head)->cdr) {               lib_list_head != NIL; lib_list_head = CONS(lib_list_head)->cdr) {
311              struct cons *lib_cons = CONS(CONS(lib_list_head)->car);              struct cons *lib_cons = CONS(CONS(lib_list_head)->car);
312              struct sap *dlhandle = (struct sap *) PTR(lib_cons->car);              struct sap *dlhandle = (struct sap *)PTR(lib_cons->car);
313              void *sym_addr = dlsym((void *) dlhandle->pointer, sym_name);              void *sym_addr = dlsym((void *)dlhandle->pointer, sym_name);
314    
315              if (sym_addr)              if (sym_addr)
316                  return sym_addr;                  return sym_addr;
# Line 329  restore_fpu(ucontext_t *scp) Line 333  restore_fpu(ucontext_t *scp)
333          cw = env_xmm->en_cw;          cw = env_xmm->en_cw;
334      } else if (fpformat == _MC_FPFMT_387) {      } else if (fpformat == _MC_FPFMT_387) {
335          cw = env_87->en_cw & 0xffff;          cw = env_87->en_cw & 0xffff;
336      } else {  /* _MC_FPFMT_NODEV */      } else { /* _MC_FPFMT_NODEV */
337          return;          return;
338      }      }
339      DPRINTF(0, (stderr, "restore_fpu:  cw = %08x\n", (int) cw));      DPRINTF(0, (stderr, "restore_fpu:  cw = %08x\n", (int)cw));
340      __asm__ __volatile__ ("fldcw %0" : : "m" (*&cw));      __asm__ __volatile__ ("fldcw %0"::"m"(*&cw));
341    
342  #ifdef FEATURE_SSE2  #ifdef FEATURE_SSE2
343      if (arch_support_sse2()) {      if (arch_support_sse2()) {
344          u_int32_t mxcsr = env_xmm->en_mxcsr;          u_int32_t mxcsr = env_xmm->en_mxcsr;
345          DPRINTF(0, (stderr, "restore_fpu:  mxcsr (raw) = %04x\n", mxcsr));  
346          __asm__ __volatile__ ("ldmxcsr %0" :: "m" (*&mxcsr));          DPRINTF(0, (stderr, "restore_fpu:  mxcsr (raw) = %04x\n", mxcsr));
347            __asm__ __volatile__ ("ldmxcsr %0"::"m"(*&mxcsr));
348      }      }
349  #endif  #endif
350  }  }

Legend:
Removed from v.1.23.4.2  
changed lines
  Added in v.1.23.4.3

  ViewVC Help
Powered by ViewVC 1.1.5