1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 8 #include <OS.h> 9 10 #include <boot/arch/x86/arch_cpu.h> 11 #include <boot/kernel_args.h> 12 #include <boot/platform.h> 13 #include <boot/stage2.h> 14 #include <boot/stdio.h> 15 16 #include <arch/x86/arch_cpu.h> 17 #include <arch_kernel.h> 18 #include <arch_system_info.h> 19 20 #include <string.h> 21 22 23 //#define TRACE_CPU 24 #ifdef TRACE_CPU 25 # define TRACE(x) dprintf x 26 #else 27 # define TRACE(x) ; 28 #endif 29 30 31 #define CPUID_EFLAGS (1UL << 21) 32 #define RDTSC_FEATURE (1UL << 4) 33 34 35 static status_t 36 check_cpu_features() 37 { 38 // check the eflags register to see if the cpuid instruction exists 39 if ((get_eflags() & CPUID_EFLAGS) == 0) { 40 // it's not set yet, but maybe we can set it manually 41 set_eflags(get_eflags() | CPUID_EFLAGS); 42 if ((get_eflags() & CPUID_EFLAGS) == 0) 43 return B_ERROR; 44 } 45 46 cpuid_info info; 47 if (get_current_cpuid(&info, 1, 0) != B_OK) 48 return B_ERROR; 49 50 if ((info.eax_1.features & RDTSC_FEATURE) == 0) { 51 // we currently require RDTSC 52 return B_ERROR; 53 } 54 55 return B_OK; 56 } 57 58 59 // #pragma mark - 60 61 62 void 63 cpu_init() 64 { 65 if (check_cpu_features() != B_OK) 66 panic("You need a Pentium or higher in order to boot!\n"); 67 68 determine_cpu_conversion_factor(0); 69 70 gKernelArgs.num_cpus = 1; 71 // this will eventually be corrected later on 72 } 73 74 75 extern "C" void 76 platform_load_ucode(BootVolume& volume) 77 { 78 arch_ucode_load(volume); 79 } 80