-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpuid.asm
More file actions
90 lines (76 loc) · 2.43 KB
/
cpuid.asm
File metadata and controls
90 lines (76 loc) · 2.43 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
section .bss ; $Revision: 1.6 $
vendor_id resd 12 ;reserve 12 bytes of memory
version resd 4
features resd 4
i resd 4
curfeat resd 4
section .text
global _start ;must be declared for linker (ld)
names db 'FPU VME DE PSE TSC MSR PAE MCE CX8 APIC RESV SEP MTRR PGE MCA CMOV PAT PSE3 PSN CLFS RESV DS ACPI MMX FXSR SSE SSE2 SS HTT TM RESV PBE '
newline db 0x0a
_start: ;tell linker entry point
mov eax,0
cpuid; get the vendor name
mov [vendor_id],ebx ; store the result in vendor_id
mov [vendor_id+4],edx
mov [vendor_id+8],ecx
;syscall(SYS_write, 0, str, sizeof(str)-1)
mov edx,12 ;message length
mov ecx,vendor_id ;message to write (msg is a pointer to the start of the string)
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel - i.e. run the system call
; Write out newline (\n)
mov edx, 1
mov ecx, newline
mov ebx,1
mov eax,4
int 0x80
mov eax,1
cpuid; Get Features
mov [version],eax
mov [features],edx
;Equivalent of for(i = 8; i != 0; i++)
mov eax,00000001h
mov [curfeat],eax
mov eax,-1
mov [i],eax
.loop:
;;--i
mov eax,[i]
inc eax; (i++)
cmp eax,31
jz .quitloop ;quit loop if reached limit
mov [i],eax ;put updated value on stack
;get current feature
mov ebx,[curfeat]
;test for feature - if feature exists ebx is non zero
and ebx,[features]
;left shift to test for next feature (will be used in next iteration of loop)
mov eax,[curfeat]
shl eax,1
mov [curfeat],eax
;jump if feaure not exist
cmp ebx,0
jz .loop ;check if zero flag is set - if it is it means that the feature didn't exist so we don't want to print anything out
;;otherwise this feature must exist lets print it out...
mov eax,[i] ;get value from stack 0x080480bf
mov edx,5 ;message length
mov ecx,names ;message to write (msg is a pointer to the start of the string
times 5 add ecx,eax
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write) 0x080480b7
int 0x80 ;call kernel 0x080480be
jmp .loop ; unconditional jump
;}
.quitloop:
; Write out newline (\n)
mov edx, 1
mov ecx, newline
mov ebx,1
mov eax,4
int 0x80
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov eax,1 ;system call number (sys_exit)
mov ebx,0 ;exit status 0 (if not used is 1 as set before) "echo $?" to check
int 0x80 ;call kernel