vm: fix indentation in Joe's changes

db4
Slava Pestov 2009-09-14 03:09:03 -05:00
parent 0cadfcd7eb
commit 83c992173e
11 changed files with 100 additions and 93 deletions

View File

@ -67,15 +67,15 @@ inline static unsigned int fpu_status(unsigned int status)
unsigned int r = 0; unsigned int r = 0;
if (status & 0x20000000) if (status & 0x20000000)
r |= FP_TRAP_INVALID_OPERATION; r |= FP_TRAP_INVALID_OPERATION;
if (status & 0x10000000) if (status & 0x10000000)
r |= FP_TRAP_OVERFLOW; r |= FP_TRAP_OVERFLOW;
if (status & 0x08000000) if (status & 0x08000000)
r |= FP_TRAP_UNDERFLOW; r |= FP_TRAP_UNDERFLOW;
if (status & 0x04000000) if (status & 0x04000000)
r |= FP_TRAP_ZERO_DIVIDE; r |= FP_TRAP_ZERO_DIVIDE;
if (status & 0x02000000) if (status & 0x02000000)
r |= FP_TRAP_INEXACT; r |= FP_TRAP_INEXACT;
return r; return r;
} }

View File

@ -53,17 +53,17 @@ inline static bool tail_call_site_p(cell return_address)
inline static unsigned int fpu_status(unsigned int status) inline static unsigned int fpu_status(unsigned int status)
{ {
unsigned int r = 0; unsigned int r = 0;
if (status & 0x01) if (status & 0x01)
r |= FP_TRAP_INVALID_OPERATION; r |= FP_TRAP_INVALID_OPERATION;
if (status & 0x04) if (status & 0x04)
r |= FP_TRAP_ZERO_DIVIDE; r |= FP_TRAP_ZERO_DIVIDE;
if (status & 0x08) if (status & 0x08)
r |= FP_TRAP_OVERFLOW; r |= FP_TRAP_OVERFLOW;
if (status & 0x10) if (status & 0x10)
r |= FP_TRAP_UNDERFLOW; r |= FP_TRAP_UNDERFLOW;
if (status & 0x20) if (status & 0x20)
r |= FP_TRAP_INEXACT; r |= FP_TRAP_INEXACT;
return r; return r;
} }

View File

@ -5,8 +5,8 @@ namespace factor
representations and vice versa */ representations and vice versa */
union double_bits_pun { union double_bits_pun {
double x; double x;
u64 y; u64 y;
}; };
inline static u64 double_bits(double x) inline static u64 double_bits(double x)
@ -24,8 +24,8 @@ inline static double bits_double(u64 y)
} }
union float_bits_pun { union float_bits_pun {
float x; float x;
u32 y; u32 y;
}; };
inline static u32 float_bits(float x) inline static u32 float_bits(float x)

View File

@ -70,11 +70,11 @@ inline static cell align8(cell a)
/* Constants used when floating-point trap exceptions are thrown */ /* Constants used when floating-point trap exceptions are thrown */
enum enum
{ {
FP_TRAP_INVALID_OPERATION = 1 << 0, FP_TRAP_INVALID_OPERATION = 1 << 0,
FP_TRAP_OVERFLOW = 1 << 1, FP_TRAP_OVERFLOW = 1 << 1,
FP_TRAP_UNDERFLOW = 1 << 2, FP_TRAP_UNDERFLOW = 1 << 2,
FP_TRAP_ZERO_DIVIDE = 1 << 3, FP_TRAP_ZERO_DIVIDE = 1 << 3,
FP_TRAP_INEXACT = 1 << 4, FP_TRAP_INEXACT = 1 << 4,
}; };
inline static bool immediate_p(cell obj) inline static bool immediate_p(cell obj)

View File

@ -13,26 +13,33 @@ inline static void *ucontext_stack_pointer(void *uap)
inline static unsigned int uap_fpu_status(void *uap) inline static unsigned int uap_fpu_status(void *uap)
{ {
ucontext_t *ucontext = (ucontext_t *)uap; ucontext_t *ucontext = (ucontext_t *)uap;
if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_387) { if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_387)
struct save87 *x87 = (struct save87 *)(&ucontext->uc_mcontext.mc_fpstate); {
return x87->sv_env.en_sw; struct save87 *x87 = (struct save87 *)(&ucontext->uc_mcontext.mc_fpstate);
} else if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM) { return x87->sv_env.en_sw;
struct savexmm *xmm = (struct savexmm *)(&ucontext->uc_mcontext.mc_fpstate); }
return xmm->sv_env.en_sw | xmm->sv_env.en_mxcsr; else if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM)
} else {
return 0; struct savexmm *xmm = (struct savexmm *)(&ucontext->uc_mcontext.mc_fpstate);
return xmm->sv_env.en_sw | xmm->sv_env.en_mxcsr;
}
else
return 0;
} }
inline static void uap_clear_fpu_status(void *uap) inline static void uap_clear_fpu_status(void *uap)
{ {
ucontext_t *ucontext = (ucontext_t *)uap; ucontext_t *ucontext = (ucontext_t *)uap;
if (uap->uc_mcontext.mc_fpformat == _MC_FPFMT_387) { if (uap->uc_mcontext.mc_fpformat == _MC_FPFMT_387)
struct save87 *x87 = (struct save87 *)(&ucontext->uc_mcontext.mc_fpstate); {
x87->sv_env.en_sw = 0; struct save87 *x87 = (struct save87 *)(&ucontext->uc_mcontext.mc_fpstate);
} else if (uap->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM) { x87->sv_env.en_sw = 0;
struct savexmm *xmm = (struct savexmm *)(&ucontext->uc_mcontext.mc_fpstate); }
xmm->sv_env.en_sw = 0; else if (uap->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM)
xmm->sv_env.en_mxcsr &= 0xffffffc0; {
struct savexmm *xmm = (struct savexmm *)(&ucontext->uc_mcontext.mc_fpstate);
xmm->sv_env.en_sw = 0;
xmm->sv_env.en_mxcsr &= 0xffffffc0;
} }
} }

View File

@ -13,20 +13,23 @@ inline static void *ucontext_stack_pointer(void *uap)
inline static unsigned int uap_fpu_status(void *uap) inline static unsigned int uap_fpu_status(void *uap)
{ {
ucontext_t *ucontext = (ucontext_t *)uap; ucontext_t *ucontext = (ucontext_t *)uap;
if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM) { if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM)
struct savexmm *xmm = (struct savexmm *)(&ucontext->uc_mcontext.mc_fpstate); {
return xmm->sv_env.en_sw | xmm->sv_env.en_mxcsr; struct savexmm *xmm = (struct savexmm *)(&ucontext->uc_mcontext.mc_fpstate);
} else return xmm->sv_env.en_sw | xmm->sv_env.en_mxcsr;
return 0; }
else
return 0;
} }
inline static void uap_clear_fpu_status(void *uap) inline static void uap_clear_fpu_status(void *uap)
{ {
ucontext_t *ucontext = (ucontext_t *)uap; ucontext_t *ucontext = (ucontext_t *)uap;
if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM) { if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM)
struct savexmm *xmm = (struct savexmm *)(&ucontext->uc_mcontext.mc_fpstate); {
xmm->sv_env.en_sw = 0; struct savexmm *xmm = (struct savexmm *)(&ucontext->uc_mcontext.mc_fpstate);
xmm->sv_env.en_mxcsr &= 0xffffffc0; xmm->sv_env.en_sw = 0;
xmm->sv_env.en_mxcsr &= 0xffffffc0;
} }
} }

View File

@ -54,27 +54,27 @@ Modified for Factor by Slava Pestov */
inline static unsigned int mach_fpu_status(ppc_float_state_t *float_state) inline static unsigned int mach_fpu_status(ppc_float_state_t *float_state)
{ {
return FPSCR(float_state); return FPSCR(float_state);
} }
inline static unsigned int uap_fpu_status(void *uap) inline static unsigned int uap_fpu_status(void *uap)
{ {
return mach_fpu_status(UAP_FS(uap)); return mach_fpu_status(UAP_FS(uap));
} }
inline static cell fix_stack_pointer(cell sp) inline static cell fix_stack_pointer(cell sp)
{ {
return sp; return sp;
} }
inline static void mach_clear_fpu_status(ppc_float_state_t *float_state) inline static void mach_clear_fpu_status(ppc_float_state_t *float_state)
{ {
FPSCR(float_state) &= 0x0007ffff; FPSCR(float_state) &= 0x0007ffff;
} }
inline static void uap_clear_fpu_status(void *uap) inline static void uap_clear_fpu_status(void *uap)
{ {
mach_clear_fpu_status(UAP_FS(uap)); mach_clear_fpu_status(UAP_FS(uap));
} }
} }

View File

@ -54,14 +54,14 @@ Modified for Factor by Slava Pestov */
inline static unsigned int mach_fpu_status(i386_float_state_t *float_state) inline static unsigned int mach_fpu_status(i386_float_state_t *float_state)
{ {
unsigned short x87sw; unsigned short x87sw;
memcpy(&x87sw, &X87SW(float_state), sizeof(x87sw)); memcpy(&x87sw, &X87SW(float_state), sizeof(x87sw));
return MXCSR(float_state) | x87sw; return MXCSR(float_state) | x87sw;
} }
inline static unsigned int uap_fpu_status(void *uap) inline static unsigned int uap_fpu_status(void *uap)
{ {
return mach_fpu_status(UAP_FS(uap)); return mach_fpu_status(UAP_FS(uap));
} }
inline static cell fix_stack_pointer(cell sp) inline static cell fix_stack_pointer(cell sp)
@ -77,7 +77,7 @@ inline static void mach_clear_fpu_status(i386_float_state_t *float_state)
inline static void uap_clear_fpu_status(void *uap) inline static void uap_clear_fpu_status(void *uap)
{ {
mach_clear_fpu_status(UAP_FS(uap)); mach_clear_fpu_status(UAP_FS(uap));
} }
} }

View File

@ -52,30 +52,30 @@ Modified for Factor by Slava Pestov and Daniel Ehrenberg */
inline static unsigned int mach_fpu_status(x86_float_state64_t *float_state) inline static unsigned int mach_fpu_status(x86_float_state64_t *float_state)
{ {
unsigned short x87sw; unsigned short x87sw;
memcpy(&x87sw, &X87SW(float_state), sizeof(x87sw)); memcpy(&x87sw, &X87SW(float_state), sizeof(x87sw));
return MXCSR(float_state) | x87sw; return MXCSR(float_state) | x87sw;
} }
inline static unsigned int uap_fpu_status(void *uap) inline static unsigned int uap_fpu_status(void *uap)
{ {
return mach_fpu_status(UAP_FS(uap)); return mach_fpu_status(UAP_FS(uap));
} }
inline static cell fix_stack_pointer(cell sp) inline static cell fix_stack_pointer(cell sp)
{ {
return ((sp + 8) & ~15) - 8; return ((sp + 8) & ~15) - 8;
} }
inline static void mach_clear_fpu_status(x86_float_state64_t *float_state) inline static void mach_clear_fpu_status(x86_float_state64_t *float_state)
{ {
MXCSR(float_state) &= 0xffffffc0; MXCSR(float_state) &= 0xffffffc0;
memset(&X87SW(float_state), 0, sizeof(X87SW(float_state))); memset(&X87SW(float_state), 0, sizeof(X87SW(float_state)));
} }
inline static void uap_clear_fpu_status(void *uap) inline static void uap_clear_fpu_status(void *uap)
{ {
mach_clear_fpu_status(UAP_FS(uap)); mach_clear_fpu_status(UAP_FS(uap));
} }
} }

View File

@ -5,6 +5,4 @@ namespace factor
#define UAP_PROGRAM_COUNTER(uap) _UC_MACHINE_PC((ucontext_t *)uap) #define UAP_PROGRAM_COUNTER(uap) _UC_MACHINE_PC((ucontext_t *)uap)
#define DIRECTORY_P(file) ((file)->d_type == DT_DIR)
} }

View File

@ -21,40 +21,39 @@ FACTOR_STDCALL LONG exception_handler(PEXCEPTION_POINTERS pe)
else else
signal_callstack_top = NULL; signal_callstack_top = NULL;
switch (e->ExceptionCode) { switch (e->ExceptionCode)
case EXCEPTION_ACCESS_VIOLATION: {
case EXCEPTION_ACCESS_VIOLATION:
signal_fault_addr = e->ExceptionInformation[1]; signal_fault_addr = e->ExceptionInformation[1];
c->EIP = (cell)memory_signal_handler_impl; c->EIP = (cell)memory_signal_handler_impl;
break; break;
case EXCEPTION_FLT_DENORMAL_OPERAND: case EXCEPTION_FLT_DENORMAL_OPERAND:
case EXCEPTION_FLT_DIVIDE_BY_ZERO: case EXCEPTION_FLT_DIVIDE_BY_ZERO:
case EXCEPTION_FLT_INEXACT_RESULT: case EXCEPTION_FLT_INEXACT_RESULT:
case EXCEPTION_FLT_INVALID_OPERATION: case EXCEPTION_FLT_INVALID_OPERATION:
case EXCEPTION_FLT_OVERFLOW: case EXCEPTION_FLT_OVERFLOW:
case EXCEPTION_FLT_STACK_CHECK: case EXCEPTION_FLT_STACK_CHECK:
case EXCEPTION_FLT_UNDERFLOW: case EXCEPTION_FLT_UNDERFLOW:
/* XXX MxCsr is not available in CONTEXT structure on x86.32 */ /* XXX MxCsr is not available in CONTEXT structure on x86.32 */
signal_fpu_status = c->FloatSave.StatusWord; signal_fpu_status = c->FloatSave.StatusWord;
c->FloatSave.StatusWord = 0; c->FloatSave.StatusWord = 0;
c->EIP = (cell)fp_signal_handler_impl; c->EIP = (cell)fp_signal_handler_impl;
break; break;
case 0x40010006:
/* If the Widcomm bluetooth stack is installed, the BTTray.exe process /* If the Widcomm bluetooth stack is installed, the BTTray.exe
injects code into running programs. For some reason this results in process injects code into running programs. For some reason this
random SEH exceptions with this (undocumented) exception code being results in random SEH exceptions with this (undocumented)
raised. The workaround seems to be ignoring this altogether, since that exception code being raised. The workaround seems to be ignoring
is what happens if SEH is not enabled. Don't really have any idea what this altogether, since that is what happens if SEH is not
this exception means. */ enabled. Don't really have any idea what this exception means. */
case 0x40010006: break;
break; default:
default:
signal_number = e->ExceptionCode; signal_number = e->ExceptionCode;
c->EIP = (cell)misc_signal_handler_impl; c->EIP = (cell)misc_signal_handler_impl;
break; break;
} }
return EXCEPTION_CONTINUE_EXECUTION; return EXCEPTION_CONTINUE_EXECUTION;
} }
void c_to_factor_toplevel(cell quot) void c_to_factor_toplevel(cell quot)