added read_cpuid and MTRR support checking before trying to set them
[retrobench] / src / util_asm.s
1         .text
2
3         .equ F_ID,      0x200000
4
5         .globl _read_cpuid
6         .globl read_cpuid
7 _read_cpuid:
8 read_cpuid:
9         # determine if cpuid is available
10         pushf
11         pop %eax
12         mov %eax, %edx  # keep a copy of the original eflags in edx
13         xor $F_ID, %eax
14         push %eax
15         popf
16         pushf
17         pop %eax
18         cmp %eax, %edx
19         jnz 0f
20         # failed to flip ID bit, CPUID not supported
21         mov $-1, %eax
22         ret
23 0:
24         push %ebp
25         mov %esp, %ebp
26         push %ebx
27         push %edi
28         sub $8, %esp
29         mov 8(%ebp), %edi
30
31         xor %eax, %eax
32         mov %eax, (%esp)        # current index
33         cpuid
34
35         mov %eax, (%edi)
36         # clamp to the size of our cpuid_info structure
37         cmp $1, %eax
38         jbe 0f
39         mov $1, %eax
40 0:      mov %eax, 4(%esp)       # maximum index
41
42         mov %ebx, 4(%edi)
43         mov %edx, 8(%edi)
44         mov %ecx, 12(%edi)
45         add $16, %edi
46
47 cpuid_loop:
48         mov (%esp), %eax
49         inc %eax
50         cmp 4(%esp), %eax
51         ja cpuid_done
52         mov %eax, (%esp)
53         cpuid
54         mov %eax, (%edi)
55         mov %ebx, 4(%edi)
56         mov %edx, 8(%edi)
57         mov %ecx, 12(%edi)
58         add $16, %edi
59         jmp cpuid_loop
60
61 cpuid_done:
62         add $8, %esp
63         pop %edi
64         pop %ebx
65         pop %ebp
66         xor %eax, %eax
67         ret