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

📄 processor.h

📁 一个微型操作系统源码
💻 H
字号:
/* * OSV * Copyright (C) 2002 Ciprian DOSOFTEI <rocksoul@mail.com> * All rights reserved. *  * http://backster.free.fr/osv * * This file is part of the OSV project. OSV is free software, also known as * "open source"; you can redistribute it and/or modify it under the terms  * of the GNU General Public License (GPL), version 2, as published by the Free * Software Foundation (FSF). To explore alternate licensing terms, contact  * the author at rocksoul@mail.com or +40740649907. *  * OSV is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE.  See the GPL for more details.  You should have * received a copy of the GPL along with OSV; see the file COPYING.  If * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA. */#ifndef INCPROCESSOR#define INCPROCESSOR#include <asm/bitops.h>#include <asm/io.h>#include <string.h>/* Sample usage: CPU_FEATURE_P(cpu.x86_capability, FPU) */#define CPU_FEATURE_P(CAP, FEATURE) test_bit(CAP, X86_FEATURE_##FEATURE ##_BIT)#define NCAPINTS	4	/* Currently we have 4 32-bit words worth of info *//* Intel-defined CPU features, CPUID level 0x00000001, word 0 */#define X86_FEATURE_FPU		(0*32+ 0) /* Onboard FPU */#define X86_FEATURE_VME		(0*32+ 1) /* Virtual Mode Extensions */#define X86_FEATURE_DE		(0*32+ 2) /* Debugging Extensions */#define X86_FEATURE_PSE 	(0*32+ 3) /* Page Size Extensions */#define X86_FEATURE_TSC		(0*32+ 4) /* Time Stamp Counter */#define X86_FEATURE_MSR		(0*32+ 5) /* Model-Specific Registers, RDMSR, WRMSR */#define X86_FEATURE_PAE		(0*32+ 6) /* Physical Address Extensions */#define X86_FEATURE_MCE		(0*32+ 7) /* Machine Check Architecture */#define X86_FEATURE_CX8		(0*32+ 8) /* CMPXCHG8 instruction */#define X86_FEATURE_APIC	(0*32+ 9) /* Onboard APIC */#define X86_FEATURE_SEP		(0*32+11) /* SYSENTER/SYSEXIT */#define X86_FEATURE_MTRR	(0*32+12) /* Memory Type Range Registers */#define X86_FEATURE_PGE		(0*32+13) /* Page Global Enable */#define X86_FEATURE_MCA		(0*32+14) /* Machine Check Architecture */#define X86_FEATURE_CMOV	(0*32+15) /* CMOV instruction (FCMOVCC and FCOMI too if FPU present) */#define X86_FEATURE_PAT		(0*32+16) /* Page Attribute Table */#define X86_FEATURE_PSE36	(0*32+17) /* 36-bit PSEs */#define X86_FEATURE_PN		(0*32+18) /* Processor serial number */#define X86_FEATURE_CLFLSH	(0*32+19) /* Supports the CLFLUSH instruction */#define X86_FEATURE_DTES	(0*32+21) /* Debug Trace Store */#define X86_FEATURE_ACPI	(0*32+22) /* ACPI via MSR */#define X86_FEATURE_MMX		(0*32+23) /* Multimedia Extensions */#define X86_FEATURE_FXSR	(0*32+24) /* FXSAVE and FXRSTOR instructions (fast save and restore */				          /* of FPU context), and CR4.OSFXSR available */#define X86_FEATURE_XMM		(0*32+25) /* Streaming SIMD Extensions */#define X86_FEATURE_XMM2	(0*32+26) /* Streaming SIMD Extensions-2 */#define X86_FEATURE_SELFSNOOP	(0*32+27) /* CPU self snoop */#define X86_FEATURE_ACC		(0*32+29) /* Automatic clock control */#define X86_FEATURE_IA64	(0*32+30) /* IA-64 processor *//* AMD-defined CPU features, CPUID level 0x80000001, word 1 *//* Don't duplicate feature flags which are redundant with Intel! */#define X86_FEATURE_SYSCALL	(1*32+11) /* SYSCALL/SYSRET */#define X86_FEATURE_MMXEXT	(1*32+22) /* AMD MMX extensions */#define X86_FEATURE_LM		(1*32+29) /* Long Mode (x86-64) */#define X86_FEATURE_3DNOWEXT	(1*32+30) /* AMD 3DNow! extensions */#define X86_FEATURE_3DNOW	(1*32+31) /* 3DNow! *//* Transmeta-defined CPU features, CPUID level 0x80860001, word 2 */#define X86_FEATURE_RECOVERY	(2*32+ 0) /* CPU in recovery mode */#define X86_FEATURE_LONGRUN	(2*32+ 1) /* Longrun power control */#define X86_FEATURE_LRTI	(2*32+ 3) /* LongRun table interface *//* Other features, Linux-defined mapping, word 3 *//* This range is used for feature bits which conflict or are synthesized */#define X86_FEATURE_CXMMX	(3*32+ 0) /* Cyrix MMX extensions */#define X86_FEATURE_K6_MTRR	(3*32+ 1) /* AMD K6 nonstandard MTRRs */#define X86_FEATURE_CYRIX_ARR	(3*32+ 2) /* Cyrix ARRs (= MTRRs) */#define X86_FEATURE_CENTAUR_MCR	(3*32+ 3) /* Centaur MCRs (= MTRRs) */struct cpuinfo_x86 {	unsigned char	x86;		/* CPU family */	unsigned char	x86_vendor;	/* CPU vendor */	unsigned char	x86_model;	unsigned char	x86_mask;	char	wp_works_ok;	/* It doesn't on 386's */	char	hlt_works_ok;	/* Problems on some 486Dx4's and old 386's */	char	hard_math;	char	rfu;   	int		cpuid_level;		/* Maximum supported CPUID level, -1=no CPUID */	unsigned int	x86_capability[NCAPINTS];	char	x86_vendor_id[16];	char	x86_model_id[64];	int 	x86_cache_size;  /* in KB - valid for CPUS which support this call */	int		fdiv_bug;	int		f00f_bug;	int		coma_bug;};#define X86_VENDOR_INTEL 0#define X86_VENDOR_CYRIX 1#define X86_VENDOR_AMD 2#define X86_VENDOR_UMC 3#define X86_VENDOR_NEXGEN 4#define X86_VENDOR_CENTAUR 5#define X86_VENDOR_RISE 6#define X86_VENDOR_TRANSMETA 7#define X86_VENDOR_UNKNOWN 0xffextern struct cpuinfo_x86 boot_cpu_data;#define cpu_data &boot_cpu_data#define cpu_has_pge	 (test_bit(X86_FEATURE_PGE,  boot_cpu_data.x86_capability))#define cpu_has_pse	 (test_bit(X86_FEATURE_PSE,  boot_cpu_data.x86_capability))#define cpu_has_pae	 (test_bit(X86_FEATURE_PAE,  boot_cpu_data.x86_capability))#define cpu_has_tsc	 (test_bit(X86_FEATURE_TSC,  boot_cpu_data.x86_capability))#define cpu_has_de	 (test_bit(X86_FEATURE_DE,   boot_cpu_data.x86_capability))#define cpu_has_vme	 (test_bit(X86_FEATURE_VME,  boot_cpu_data.x86_capability))#define cpu_has_fxsr (test_bit(X86_FEATURE_FXSR, boot_cpu_data.x86_capability))#define cpu_has_xmm	 (test_bit(X86_FEATURE_XMM,  boot_cpu_data.x86_capability))#define cpu_has_fpu	 (test_bit(X86_FEATURE_FPU,  boot_cpu_data.x86_capability))#define X86_EFLAGS_CF	0x00000001 /* Carry Flag */#define X86_EFLAGS_PF	0x00000004 /* Parity Flag */#define X86_EFLAGS_AF	0x00000010 /* Auxillary carry Flag */#define X86_EFLAGS_ZF	0x00000040 /* Zero Flag */#define X86_EFLAGS_SF	0x00000080 /* Sign Flag */#define X86_EFLAGS_TF	0x00000100 /* Trap Flag */#define X86_EFLAGS_IF	0x00000200 /* Interrupt Flag */#define X86_EFLAGS_DF	0x00000400 /* Direction Flag */#define X86_EFLAGS_OF	0x00000800 /* Overflow Flag */#define X86_EFLAGS_IOPL	0x00003000 /* IOPL mask */#define X86_EFLAGS_NT	0x00004000 /* Nested Task */#define X86_EFLAGS_RF	0x00010000 /* Resume Flag */#define X86_EFLAGS_VM	0x00020000 /* Virtual Mode */#define X86_EFLAGS_AC	0x00040000 /* Alignment Check */#define X86_EFLAGS_VIF	0x00080000 /* Virtual Interrupt Flag */#define X86_EFLAGS_VIP	0x00100000 /* Virtual Interrupt Pending */#define X86_EFLAGS_ID	0x00200000 /* CPUID detection flag */#define CX86_CCR0 0xc0#define CX86_CCR1 0xc1#define CX86_CCR2 0xc2#define CX86_CCR3 0xc3#define CX86_CCR4 0xe8#define CX86_CCR5 0xe9#define CX86_CCR6 0xea#define CX86_DIR0 0xfe#define CX86_DIR1 0xff#define CX86_ARR_BASE 0xc4#define CX86_RCR_BASE 0xdc#define getCx86(reg) ({ outb((reg), 0x22); inb(0x23); })#define setCx86(reg, data) do { \	outb((reg), 0x22); \	outb((data), 0x23); \} while (0)extern inline void cpuid(int op, int *eax, int *ebx, int *ecx, int *edx){	__asm__("cpuid"		: "=a" (*eax),		  "=b" (*ebx),		  "=c" (*ecx),		  "=d" (*edx)		: "a" (op));}extern inline unsigned int cpuid_eax(unsigned int op){	unsigned int eax, ebx, ecx, edx;	__asm__("cpuid"		: "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)		: "a" (op));	return eax;}extern inline unsigned int cpuid_ebx(unsigned int op){	unsigned int eax, ebx, ecx, edx;	__asm__("cpuid"		: "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)		: "a" (op));	return ebx;}extern inline unsigned int cpuid_ecx(unsigned int op){	unsigned int eax, ebx, ecx, edx;	__asm__("cpuid"		: "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)		: "a" (op));	return ecx;}extern inline unsigned int cpuid_edx(unsigned int op){	unsigned int eax, ebx, ecx, edx;	__asm__("cpuid"		: "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)		: "a" (op));	return edx;}extern void printCPUInfo(struct cpuinfo_x86 *);extern void identifyCPU(struct cpuinfo_x86 *c);extern void displayCPUInfo(struct cpuinfo_x86 *c);#endif

⌨️ 快捷键说明

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