4 * Test for an x86 FPU, and do any necessary setup.
10 static inline uint64_t get_cr0(void)
13 asm("movl %%cr0,%0" : "=r" (v
));
17 static inline void set_cr0(uint32_t v
)
19 asm volatile("movl %0,%%cr0" : : "r" (v
));
22 #define CR0_PE 0x00000001
23 #define CR0_MP 0x00000002
24 #define CR0_EM 0x00000004
25 #define CR0_TS 0x00000008
26 #define CR0_ET 0x00000010
27 #define CR0_NE 0x00000020
28 #define CR0_WP 0x00010000
29 #define CR0_AM 0x00040000
30 #define CR0_NW 0x20000000
31 #define CR0_CD 0x40000000
32 #define CR0_PG 0x80000000
34 int x86_init_fpu(void)
37 uint16_t fsw
= 0xffff;
38 uint16_t fcw
= 0xffff;
41 cr0
&= ~(CR0_EM
|CR0_TS
);
45 asm volatile("fninit");
46 asm volatile("fnstsw %0" : "+m" (fsw
));
50 asm volatile("fnstcw %0" : "+m" (fcw
));
51 if ((fcw
& 0x103f) != 0x3f)
54 /* Techically, this could be a 386 with a 287. We could add a check