PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/vm/os-macosx-x86.32.hpp

http://github.com/abeaumont/factor
C++ Header | 78 lines | 52 code | 16 blank | 10 comment | 0 complexity | 982561db45234e0b5f03f06dd678a78a MD5 | raw file
 1#include <sys/ucontext.h>
 2
 3namespace factor
 4{
 5
 6/* Fault handler information.  MacOSX version.
 7Copyright (C) 1993-1999, 2002-2003  Bruno Haible <clisp.org at bruno>
 8Copyright (C) 2003  Paolo Bonzini <gnu.org at bonzini>
 9
10Used under BSD license with permission from Paolo Bonzini and Bruno Haible,
112005-03-10:
12
13http://sourceforge.net/mailarchive/message.php?msg_name=200503102200.32002.bruno%40clisp.org
14
15Modified for Factor by Slava Pestov */
16#define MACH_EXC_STATE_TYPE i386_exception_state_t
17#define MACH_EXC_STATE_FLAVOR i386_EXCEPTION_STATE
18#define MACH_EXC_STATE_COUNT i386_EXCEPTION_STATE_COUNT
19
20#define MACH_EXC_INTEGER_DIV EXC_I386_DIV
21
22#define MACH_THREAD_STATE_TYPE i386_thread_state_t
23#define MACH_THREAD_STATE_FLAVOR i386_THREAD_STATE
24#define MACH_THREAD_STATE_COUNT i386_THREAD_STATE_COUNT
25
26#define MACH_FLOAT_STATE_TYPE i386_float_state_t
27#define MACH_FLOAT_STATE_FLAVOR i386_FLOAT_STATE
28#define MACH_FLOAT_STATE_COUNT i386_FLOAT_STATE_COUNT
29
30#if __DARWIN_UNIX03
31	#define MACH_EXC_STATE_FAULT(exc_state) (exc_state)->__faultvaddr
32	#define MACH_STACK_POINTER(thr_state) (thr_state)->__esp
33	#define MACH_PROGRAM_COUNTER(thr_state) (thr_state)->__eip
34
35	#define UAP_SS(ucontext) &(((ucontext_t *)(ucontext))->uc_mcontext->__ss)
36	#define UAP_FS(ucontext) &(((ucontext_t *)(ucontext))->uc_mcontext->__fs)
37
38	#define MXCSR(float_state) (float_state)->__fpu_mxcsr
39	#define X87SW(float_state) (float_state)->__fpu_fsw
40#else
41	#define MACH_EXC_STATE_FAULT(exc_state) (exc_state)->faultvaddr
42	#define MACH_STACK_POINTER(thr_state) (thr_state)->esp
43	#define MACH_PROGRAM_COUNTER(thr_state) (thr_state)->eip
44
45	#define UAP_SS(ucontext) &(((ucontext_t *)(ucontext))->uc_mcontext->ss)
46	#define UAP_FS(ucontext) &(((ucontext_t *)(ucontext))->uc_mcontext->fs)
47
48	#define MXCSR(float_state) (float_state)->fpu_mxcsr
49	#define X87SW(float_state) (float_state)->fpu_fsw
50#endif
51
52#define UAP_PROGRAM_COUNTER(ucontext) \
53	MACH_PROGRAM_COUNTER(UAP_SS(ucontext))
54
55inline static unsigned int mach_fpu_status(i386_float_state_t *float_state)
56{
57	unsigned short x87sw;
58	memcpy(&x87sw, &X87SW(float_state), sizeof(x87sw));
59	return MXCSR(float_state) | x87sw;
60}
61
62inline static unsigned int uap_fpu_status(void *uap)
63{
64	return mach_fpu_status(UAP_FS(uap));
65}
66
67inline static void mach_clear_fpu_status(i386_float_state_t *float_state)
68{
69	MXCSR(float_state) &= 0xffffffc0;
70	memset(&X87SW(float_state), 0, sizeof(X87SW(float_state)));
71}
72
73inline static void uap_clear_fpu_status(void *uap)
74{
75	mach_clear_fpu_status(UAP_FS(uap));
76}
77
78}