summaryrefslogtreecommitdiff
path: root/src/fp.s
blob: b1af5816cbd113f12dd4c9c9a1104ea0071df932 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
.global init_fp

init_fp:
	call init_sse
	push %eax
	call init_x87
	pop %ebx
	or %ebx, %eax
	ret

init_sse:
	mov $0x1, %eax
	cpuid
	test %edx, 1<<25
	jz no_sse

	mov %cr0, %eax
	and %ax, 0xFFFB
	or %ax, 0x2
	mov %eax, %cr0
	mov %cr4, %eax
	or %ax, 3<<9
	mov %eax, %cr4

	xor %eax, %eax
	ret

no_sse:
	mov $1, %eax
	ret

init_x87:
	mov %cr0, %eax
	and %eax, (-1) - ((1 << 3) + (1 << 4))
	mov %eax, %cr0
	fninit
	fnstsw (test)
	cmpw $0, (test)

	xor %eax, %eax
	ret

no_x87:
	mov $2, %eax
	ret

test: .word 0x55AA