⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpu.h

📁 小型操作系统,以VC为开发环境,需要boachs调试
💻 H
字号:
/***************************************************************************
**     File name   : cpu.h
**     Author      : x.cheng
**     Create date :
**
**	  Comments:
**		CPU features....
**	
**     Revisions:
**     $Log: cpu.h,v $
**     Revision 1.1  2005/08/05 15:07:03  x.cheng
**     add into repositories
**
**
***************************************************************************/
#ifndef __CPU_H__
#define __CPU_H__

//! CPUID operations.
enum
{
	GET_CPU_VENDOR	= 0,	// Get the cpu vendor string.
	GET_CPU_INFO	= 1,	// Get cpu informations.
	GET_CPU_CACHE	= 2,	// Get cpu cache informations.
		// Check if the brand string is available.
	CPU_BRAND_STRING_IS_AVAILABLE	= 0x80000000,
		// Get 1st part of the brand string.
	CPU_GET_BRAND_STRING1		= 0x80000002,	
		// Get 1st part of the brand string.
	CPU_GET_BRAND_STRING2		= 0x80000003,
		// Get 1st part of the brand string.
	CPU_GET_BRAND_STRING3		= 0x80000004,
};

// The CPU flags mask in register EDX after a CPUID instruction.
typedef struct CpuFlagsEDX_Struct
{
	unsigned long fpu	: 1;	//!< Floating-point unit on-chip.
	unsigned long vme	: 1;	//!< Virtual mode extension.
	unsigned long de 	: 1;	//!< Debugging extension.
	unsigned long pse	: 1;	//!< Page size extension.
	unsigned long tsc	: 1;	//!< Time stamp counter.
	unsigned long msr	: 1;	//!< Model specific register.
	unsigned long pae	: 1;	//!< Physical address extension.
	unsigned long mce	: 1;	//!< Machine check exception.
	unsigned long cx8	: 1;	//!< cmpxchg8 instruction supported.
	unsigned long apic	: 1;	//!< On-chip APIC hardware support.
	unsigned long _res0	: 1;	//!< Reserved.
	unsigned long sep	: 1;	//!< Fast system call.
	unsigned long mtrr	: 1;	//!< Memory type range register.
	unsigned long pge	: 1;	//!< Page Global enable.
	unsigned long mca	: 1;	//!< Machine check architecture.
	unsigned long cmov	: 1;	//!< Conditional move instruction.
	unsigned long pat	: 1;	//!< Page attribute table.
	unsigned long pse_36	: 1;	//!< 36-bit page size extension.
	unsigned long psn	: 1;	//!< Processor serial number present.
	unsigned long clfsh	: 1;	//!< clflush instruction supported.
	unsigned long _res1	: 1;	//!< Reserved.
	unsigned long ds	: 1;	//!< Debug store.
	unsigned long acpi	: 1;	//!< Thermal monitor and controlled clock support.
	unsigned long mmx	: 1;	//!< MMX technology support.
	unsigned long fxsr	: 1;	//!< Fast floating point save and restore.
	unsigned long sse	: 1;	//!< Streaming SIMD extension support.
	unsigned long sse2	: 1;	//!< Streaming SIMD extension 2 support.
	unsigned long ss	: 1;	//!< Self-snoop.
	unsigned long htt	: 1;	//!< Hyper-threading technology.
	unsigned long tm	: 1;	//!< Thermal monitor supported.
	unsigned long _res2	: 1;	//!< Reserved.
	unsigned long sbf	: 1;	//!< Signal break on ferr.
} __attribute__ ((packed)) ts_CpuFlagsEdx;

//! The CPU flags mask in register ECX after a CPUID instruction.
typedef struct ts_CpuFlagsECX_Struct
{
	unsigned long _res0	: 7;	//!< Reserved.
	unsigned long tm2	: 1;	//!< Thermal monitor 2.
	unsigned long est	: 1;	//!< Enhanced Speedstep technology.
	unsigned long _res1	: 1;	//!< Reserved.
	unsigned long cid	: 1;	//!< Context ID.
	unsigned long _res2	: 21;	//!< Reserved.
} __attribute__ ((packed)) ts_CpuFlagsEcx;

//! The CPU signature mask.
typedef struct CpuSignature_Struct
{
	unsigned long stepping	: 4;	//! Stepping ID.
	unsigned long model 	: 4;	//! Model.
	unsigned long family 	: 4;	//! Family.
	unsigned long type 		: 2;	//! Processor type.
	unsigned long _res0 	: 2;	//! Reserved.
	unsigned long ext_model	: 4;	//! Extended Model.
	unsigned long ext_family: 8;	//! Extended Family.
	unsigned long _res1	: 4;	//! Reserved.
} __attribute__ ((packed)) ts_CpuSignature;

//! All the CPU informations.
typedef struct CpuInfo_Struct
{
	//! The name of the CPU.
	char szName[64];
	//! The frequency in kHz.
	unsigned long ulFrequency;
	//! How many loops the CPU does in a clock tick.
	unsigned long ulLoopsPerTick;
	//! Vendor string.
	union
	{
		unsigned long aulNum[4];
		char szString[16];
	} unVendor;
	//! CPU signature.
	union
	{
		unsigned long ulNum;
		ts_CpuSignature stFlags;
	} unSignature;
	//! Feature flags.
	union
	{
		unsigned long aulNum[2];
		struct {
			ts_CpuFlagsEcx stEcx;
			ts_CpuFlagsEdx stEdx;
		} stFlags;
	} unFeature;
	//! Brand ID.
	union
	{
		unsigned long ulNum;
		unsigned long ulId: 8;
	} unBrand;
} ts_CpuInfo;

//! Intel CPU names.
typedef struct CpuName_Struct
{
	int iFamily;
	char *aszModelNames[16];
} ts_CpuName;

//! The structure for the cache string informations.
typedef struct CacheInfo_Struct
{
	unsigned char ucIndex;
	char* szString;
} ts_CacheInfo;

//! CPUID detection flag.
#define EFLAGS_ID	0x00200000

//! Alignement check bit.
#define EFLAGS_AC	0x00040000

// --- Prototypes ----------------------------------------------------- //

void CpuShowInfo();
void CpuInitialize();

#endif /* end of  __CPU_H__ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -