10장 CPUID, GCC Inline Assembly 이용해서 작성하기

CLKH64 OS/10장 2013. 1. 11. 20:09 Posted by 알 수 없는 사용자

 

코드로 남긴다.

더이상의 자세한 설명은 생략한다.

 

 

static inline void kCpuid(DWORD* eax, DWORD* ebx, DWORD* ecx, DWORD* edx);

void Main(void)
{
	DWORD eax, ebx, ecx, edx;
	char venderName[13] = { 0 };

	// 
	//  중간 생략
	// 
	// 
	
	// Check whether our cpu can support 64bit mode
	eax = 0x80000001;
	kCpuid(&eax, &ebx, &ecx, &edx);

	if ( edx & ( 1 << 29 ))
	{
		kPrintString(0, gScreenY++, "Check whether Cpu can provide 64-Bit Mode........[PASS]");
	}

	// Get Cpu vender name using cpuid instruction
	eax = 0x00000000;
	kCpuid(&eax, &ebx, &ecx, &edx);

	*((DWORD*) venderName + 0) =  ebx;
	*((DWORD*) venderName + 1) =  ecx;
	*((DWORD*) venderName + 2) =  edx;

	kPrintString(0, gScreenY++, venderName);


	while(TRUE);
}

static inline void kCpuid(DWORD* eax, DWORD* ebx, DWORD* ecx, DWORD* edx)
{
	__asm__ __volatile__ ("cpuid"
			:"=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx)
			:"a"(*eax) );
}

 

 

 

참고 -

http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html

http://wiki.osdev.org/Inline_Assembly/Examples#CPUID (OSDev 위키)

http://www.ibm.com/developerworks/kr/library/l-ia.html

http://blog.naver.com/PostView.nhn?blogId=ryutuna&logNo=100171884711&redirect=Dlog&widgetTypeCall=true

http://www.kernel.bz/mips/02/mips0201.htm

http://kldp.org/node/27805 

'CLKH64 OS > 10장' 카테고리의 다른 글

SwitchMode.o: Inline Assembly 버전 및 파이썬 스크립트 수정  (0) 2013.01.12
GCC AT&T Syntax  (0) 2013.01.12