]> gitweb.factorcode.org Git - factor.git/blob - vm/os-linux-x86.32.hpp
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / vm / os-linux-x86.32.hpp
1 #include <ucontext.h>
2
3 namespace factor
4 {
5
6 // glibc lies about the contents of the fpstate the kernel provides, hiding the FXSR
7 // environment
8 struct _fpstate {
9         /* Regular FPU environment */
10         unsigned long   cw;
11         unsigned long   sw;
12         unsigned long   tag;
13         unsigned long   ipoff;
14         unsigned long   cssel;
15         unsigned long   dataoff;
16         unsigned long   datasel;
17         struct _fpreg   _st[8];
18         unsigned short  status;
19         unsigned short  magic;          /* 0xffff = regular FPU data only */
20         
21         /* FXSR FPU environment */
22         unsigned long   _fxsr_env[6];   /* FXSR FPU env is ignored */
23         unsigned long   mxcsr;
24         unsigned long   reserved;
25         struct _fpxreg  _fxsr_st[8];    /* FXSR FPU reg data is ignored */
26         struct _xmmreg  _xmm[8];
27         unsigned long   padding[56];
28 };
29
30 #define X86_FXSR_MAGIC          0x0000
31
32 inline static unsigned int uap_fpu_status(void *uap)
33 {
34         ucontext_t *ucontext = (ucontext_t *)uap;
35         struct _fpstate *fpregs = (struct _fpstate *)ucontext->uc_mcontext.fpregs;
36         if (fpregs->magic == X86_FXSR_MAGIC)
37             return fpregs->sw | fpregs->mxcsr;
38         else
39             return fpregs->sw;
40 }
41
42 inline static void uap_clear_fpu_status(void *uap)
43 {
44         ucontext_t *ucontext = (ucontext_t *)uap;
45         struct _fpstate *fpregs = (struct _fpstate *)ucontext->uc_mcontext.fpregs;
46         fpregs->sw = 0;
47         if (fpregs->magic == X86_FXSR_MAGIC)
48             fpregs->mxcsr &= 0xffffffc0;
49 }
50
51
52 #define UAP_STACK_POINTER(ucontext) (((ucontext_t *)ucontext)->uc_mcontext.gregs[7])
53 #define UAP_PROGRAM_COUNTER(ucontext) (((ucontext_t *)ucontext)->uc_mcontext.gregs[14])
54 #define UAP_SET_TOC_POINTER(uap, ptr) (void)0
55
56 #define CODE_TO_FUNCTION_POINTER(code) (void)0
57 #define CODE_TO_FUNCTION_POINTER_CALLBACK(vm, code) (void)0
58 #define FUNCTION_CODE_POINTER(ptr) ptr
59 #define FUNCTION_TOC_POINTER(ptr) ptr
60
61 #define UAP_STACK_POINTER_TYPE greg_t
62 }