00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #include <arch/cpu.h>
00036 #include <arch/cpuid.h>
00037 #include <arch/pm.h>
00038
00039 #include <arch.h>
00040 #include <arch/types.h>
00041 #include <print.h>
00042 #include <typedefs.h>
00043 #include <fpu_context.h>
00044
00045
00046
00047
00048
00049 #define AMD_CPUID_EBX 0x68747541
00050 #define AMD_CPUID_ECX 0x444d4163
00051 #define AMD_CPUID_EDX 0x69746e65
00052
00053 #define INTEL_CPUID_EBX 0x756e6547
00054 #define INTEL_CPUID_ECX 0x6c65746e
00055 #define INTEL_CPUID_EDX 0x49656e69
00056
00057
00058 enum vendor {
00059 VendorUnknown=0,
00060 VendorAMD,
00061 VendorIntel
00062 };
00063
00064 static char *vendor_str[] = {
00065 "Unknown Vendor",
00066 "AuthenticAMD",
00067 "GenuineIntel"
00068 };
00069
00070
00077 void cpu_setup_fpu(void)
00078 {
00079 __asm__ volatile (
00080 "movq %%cr0, %%rax;"
00081 "btsq $1, %%rax;"
00082 "btrq $2, %%rax;"
00083 "movq %%rax, %%cr0;"
00084
00085 "movq %%cr4, %%rax;"
00086 "bts $9, %%rax;"
00087 "movq %%rax, %%cr4;"
00088 :
00089 :
00090 :"%rax"
00091 );
00092 }
00093
00100 void fpu_disable(void)
00101 {
00102 __asm__ volatile (
00103 "mov %%cr0,%%rax;"
00104 "bts $3,%%rax;"
00105 "mov %%rax,%%cr0;"
00106 :
00107 :
00108 :"%rax"
00109 );
00110 }
00111
00112 void fpu_enable(void)
00113 {
00114 __asm__ volatile (
00115 "mov %%cr0,%%rax;"
00116 "btr $3,%%rax;"
00117 "mov %%rax,%%cr0;"
00118 :
00119 :
00120 :"%rax"
00121 );
00122 }
00123
00124 void cpu_arch_init(void)
00125 {
00126 CPU->arch.tss = tss_p;
00127 CPU->arch.tss->iomap_base = &CPU->arch.tss->iomap[0] - ((__u8 *) CPU->arch.tss);
00128 CPU->fpu_owner = NULL;
00129 }
00130
00131 void cpu_identify(void)
00132 {
00133 cpu_info_t info;
00134
00135 CPU->arch.vendor = VendorUnknown;
00136 if (has_cpuid()) {
00137 cpuid(0, &info);
00138
00139
00140
00141
00142 if (info.cpuid_ebx==AMD_CPUID_EBX && info.cpuid_ecx==AMD_CPUID_ECX && info.cpuid_edx==AMD_CPUID_EDX) {
00143 CPU->arch.vendor = VendorAMD;
00144 }
00145
00146
00147
00148
00149 if (info.cpuid_ebx==INTEL_CPUID_EBX && info.cpuid_ecx==INTEL_CPUID_ECX && info.cpuid_edx==INTEL_CPUID_EDX) {
00150 CPU->arch.vendor = VendorIntel;
00151 }
00152
00153 cpuid(1, &info);
00154 CPU->arch.family = (info.cpuid_eax>>8)&0xf;
00155 CPU->arch.model = (info.cpuid_eax>>4)&0xf;
00156 CPU->arch.stepping = (info.cpuid_eax>>0)&0xf;
00157 }
00158 }
00159
00160 void cpu_print_report(cpu_t* m)
00161 {
00162 printf("cpu%d: (%s family=%d model=%d stepping=%d) %dMHz\n",
00163 m->id, vendor_str[m->arch.vendor], m->arch.family, m->arch.model, m->arch.stepping,
00164 m->frequency_mhz);
00165 }
00166