サイトマップ 連絡先 トップに戻る 最初に戻る
$Date: 2018-07-07 06:49:13 +0900 (2018/07/07 (土)) $
$Revision: 1347 $

アセンブラ on Windows ドライバ

Sources

USER_C_FLAGS=$(USER_C_FLAGS) /Fa
I386_SOURCES	= i386\my_cpuid.asm
AMD64_SOURCES	= amd64\my_cpuid.asm

__cpuid

void __cpuid(
   int CPUInfo[4],
   int InfoType
)
{
	_asm {
		mov ECX, InfoType
		cpuid
		mov CPUInfo[0], EAX
		mov CPUInfo[1], EBX
		mov CPUInfo[2], ECX
		mov CPUInfo[3], EDX
	};
}

i386/my_cpuid.asm

	.686P
	.XMM
	.model	flat

INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES

PUBLIC	my_cpuid
_TEXT	SEGMENT
_CPUInfo$  = 8						; size = 4
_InfoType$ = 12						; size = 4
my_cpuid PROC						; COMDAT
	push	ebp
	mov		ebp, esp
	push	ebx
	mov		ecx, DWORD PTR _InfoType$[ebp]
	cpuid
	mov		DWORD PTR _CPUInfo$[ebp  ], eax
	mov		DWORD PTR _CPUInfo$[ebp+1], ebx
	mov		DWORD PTR _CPUInfo$[ebp+2], ecx
	mov		DWORD PTR _CPUInfo$[ebp+3], edx
	pop		ebx
	pop		ebp
	ret		8
my_cpuid ENDP				; __cpuid
_TEXT	ENDS
END

amd64/my_cpuid.asm

INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES

;	void my_cpuid(
;	   int CPUInfo[4],
;	   int InfoType
;	)
;
;	Parameter Passing 
;		First 4 parameters - RCX, RDX, R8, R9
;	http://msdn.microsoft.com/en-us/library/zthk2dkh%28v=VS.80%29.aspx
;
;	Caller/Callee Saved Registers
;		The registers RAX, RCX, RDX, R8, R9, R10, R11 are considered volatile 
;		and must be considered destroyed on function calls (unless otherwise 
;		safety-provable by analysis such as whole program optimization).
;		
;		The registers RBX, RBP, RDI, RSI, R12, R13, R14, and R15 are considered 
;		nonvolatile and must be saved and restored by a function that uses them.
;	http://msdn.microsoft.com/en-us/library/6t169e9c%28v=VS.80%29.aspx
;
PUBLIC	my_cpuid
_TEXT	SEGMENT
my_cpuid PROC						; COMDAT
	mov		r9,  rbx				; save rbx
	mov		r8,  rcx				; save rcx (CPUInfo)
	mov		eax, edx				; set paramter to cpuid (InfoType)
	cpuid
	mov		DWORD PTR [r8   ], eax
	mov		DWORD PTR [r8+ 4], ebx
	mov		DWORD PTR [r8+ 8], ecx
	mov		DWORD PTR [r8+12], edx
	mov		rbx,  r9				; restore rbx
	ret		0
my_cpuid ENDP
END