File: cpuid_dll.s

package info (click to toggle)
win32-loader 0.10.6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 1,868 kB
  • sloc: ansic: 2,492; sh: 706; asm: 344; makefile: 338
file content (85 lines) | stat: -rw-r--r-- 2,067 bytes parent folder | download | duplicates (2)
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
/* Licensed under the zlib/libpng license (same as NSIS) */

/*
 CPUID hepler module for the Nullsoft Installer (NSIS).

 The exported cpuid_available and cpuid functions should be used
 with the cpuid.nsh header.
 */

.text
/*
 Check if CPUID opcode is available by toggling ID bit in EFLAGS register
 Returns a non-zero value if CPUID opcode is available otherwise 0.

 C function declaration:
 __declspec(dllexport) unsigned int __attribute__((__stdcall__))
 cpuid_available(void)
 */
.globl _cpuid_available@0
_cpuid_available@0:
	/* Transfer content of EFLAGS register into ECX via stack */
	pushfl
	popl	%ecx
	/* Save original content of EFLAGS register in EAX */
	movl	%ecx, %eax
	/* Toggle ID bit (bit number: 21) */
	xorl	$0x00200000, %ecx
	/* Update EFLAGS register with the contents of ECX and
	   read back EFLAGS into ECX */
	pushl	%ecx
	popfl
	pushfl
	popl	%ecx
	/* Restore original content of EFLAGS register */
	pushl	%eax
	popfl
	/* If ID bit could be modified in EFLAGS register then the
	   exclusive-or (XOR) operation leads to a non-zero value in EAX */
	xorl	%ecx, %eax
	ret

/*
 Invoke CPUID opcode
 Parameters:
   info - array of four 32 bit intergers getting the contents of the registers EAX, EBX, ECX and EDX
   id - query code

 C function declaration:
 __declspec(dllexport) void __attribute__((__stdcall__))
 cpuid(unsigned int info[4], unsigned int id)
 */
.globl _cpuid@8
_cpuid@8:
	pushl	%ebp
	movl	%esp, %ebp
	pushl	%esi
	pushl	%ebx
	movl	8(%ebp), %esi
	/* Write query code to EAX */
	movl	12(%ebp), %eax
	cpuid
	/* Save contents of the registers EAX, EBX, ECX and EDX
	   in the provided array */
	movl	%eax, (%esi)
	movl	%ebx, 4(%esi)
	movl	%ecx, 8(%esi)
	movl	%edx, 12(%esi)
	popl	%ebx
	popl	%esi
	popl	%ebp
	ret	$8

/*
 C function declaration:
 BOOL __attribute__((__stdcall__))
 DllEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 */
.globl _DllEntryPoint@12
_DllEntryPoint@12:
        movl    $1, %eax
        ret	$12

.section .drectve
.ascii " -export:\"cpuid@8\""
.ascii " -export:\"cpuid_available@0\""