4 * Test for an x86 FPU, and do any necessary setup.
7 #if __SIZEOF_POINTER__ == 4
8 #include <i386/x86_init_fpu.c>
9 #elif __SIZEOF_POINTER__ == 8
10 #include <x86_64/x86_init_fpu.c>
12 #error "Unable to build for to-be-defined architecture type"
18 static inline uint64_t get_cr0(void)
20 #if __SIZEOF_POINTER__ == 4
22 asm("movl %%cr0,%0":"=r"(v
));
23 #elif __SIZEOF_POINTER__ == 8
25 asm("movq %%cr0,%0":"=r"(v
));
27 #error "Unable to build for to-be-defined architecture type"
32 static inline void set_cr0(uint32_t v
)
34 #if __SIZEOF_POINTER__ == 4
35 asm volatile ("movl %0,%%cr0"::"r" (v
));
36 #elif __SIZEOF_POINTER__ == 8
37 asm volatile ("movq %0,%%cr0"::"r" ((uint64_t)v
));
39 #error "Unable to build for to-be-defined architecture type"
43 #define CR0_PE 0x00000001
44 #define CR0_MP 0x00000002
45 #define CR0_EM 0x00000004
46 #define CR0_TS 0x00000008
47 #define CR0_ET 0x00000010
48 #define CR0_NE 0x00000020
49 #define CR0_WP 0x00010000
50 #define CR0_AM 0x00040000
51 #define CR0_NW 0x20000000
52 #define CR0_CD 0x40000000
53 #define CR0_PG 0x80000000
55 int x86_init_fpu(void)
58 uint16_t fsw
= 0xffff;
59 uint16_t fcw
= 0xffff;
62 cr0
&= ~(CR0_EM
| CR0_TS
);
66 asm volatile ("fninit");
67 asm volatile ("fnstsw %0":"+m" (fsw
));
71 asm volatile ("fnstcw %0":"+m" (fcw
));
72 if ((fcw
& 0x103f) != 0x3f)
75 /* Techically, this could be a 386 with a 287. We could add a check