From 484c80abd02ab7892be0963aad8c7d81641ed59e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 14 Dec 2005 10:43:28 +0000 Subject: [PATCH] * Added missing prototypes for get_eflags() and set_eflags() to arch_system_info.h * The boot loader now checks the CPU for the cpuid and rdtsc features, which we currently both rely on. * Removed old and no longer used stage2_priv.h header git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15534 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/arch/x86/arch_system_info.h | 5 +- headers/private/kernel/arch/x86/stage2_priv.h | 51 ------------------- src/system/boot/platform/bios_ia32/cpu.cpp | 22 +++++++- 3 files changed, 25 insertions(+), 53 deletions(-) delete mode 100644 headers/private/kernel/arch/x86/stage2_priv.h diff --git a/headers/private/kernel/arch/x86/arch_system_info.h b/headers/private/kernel/arch/x86/arch_system_info.h index c49bae5afa..3575fe869c 100644 --- a/headers/private/kernel/arch/x86/arch_system_info.h +++ b/headers/private/kernel/arch/x86/arch_system_info.h @@ -1,5 +1,5 @@ /* - * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _KERNEL_ARCH_x86_SYSTEM_INFO_H @@ -14,6 +14,9 @@ extern "C" { #endif status_t get_current_cpuid(cpuid_info *info, uint32 eax); +uint32 get_eflags(void); +void set_eflags(uint32 value); + status_t _user_get_cpuid(cpuid_info *info, uint32 eax, uint32 cpu); #ifdef __cplusplus diff --git a/headers/private/kernel/arch/x86/stage2_priv.h b/headers/private/kernel/arch/x86/stage2_priv.h deleted file mode 100644 index 6b90f325e7..0000000000 --- a/headers/private/kernel/arch/x86/stage2_priv.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -** Copyright 2001, Travis Geiselbrecht. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ -#ifndef _STAGE2_PRIV_H -#define _STAGE2_PRIV_H - - -#include -#include - - -extern void clearscreen(void); -extern void kputs(const char *str); -extern int dprintf(const char *fmt, ...); -extern void spin(uint64 microseconds); -extern void execute_n_instructions(int count); -void system_time_setup(long a); -uint64 rdtsc(); -unsigned int get_eflags(void); -void set_eflags(uint32 val); -void cpuid(uint32 selector, uint32 *data); - -//void put_uint_dec(unsigned int a); -//void put_uint_hex(unsigned int a); -//void nmessage(const char *str1, unsigned int a, const char *str2); -//void nmessage2(const char *str1, unsigned int a, const char *str2, unsigned int b, const char *str3); - -#define ROUNDUP(a, b) (((a) + ((b) - 1)) & (~((b) - 1))) -#define ROUNDOWN(a, b) (((a) / (b)) * (b)) - -#define PAGE_SIZE 0x1000 -#define KERNEL_BASE 0x80000000 -#define KERNEL_ENTRY 0x80000080 -#define STACK_SIZE 2 -#define DEFAULT_PAGE_FLAGS (1 | 2) // present/rw -#define SCREEN_WIDTH 80 -#define SCREEN_HEIGHT 24 -#define ADDR_MASK 0xfffff000 - -struct gdt_idt_descr { - uint16 a; - uint32 *b; -} _PACKED; - -// SMP stuff -extern int smp_boot(kernel_args *ka, uint32 kernel_entry); -extern void smp_trampoline(void); -extern void smp_trampoline_end(void); - -#endif /* _STAGE2_PRIV_H */ diff --git a/src/system/boot/platform/bios_ia32/cpu.cpp b/src/system/boot/platform/bios_ia32/cpu.cpp index f4a5bffcc1..757148b271 100644 --- a/src/system/boot/platform/bios_ia32/cpu.cpp +++ b/src/system/boot/platform/bios_ia32/cpu.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -34,6 +35,9 @@ uint32 gTimeConversionFactor; #define TIMER_CLKNUM_HZ (14318180/12) +#define CPUID_EFLAGS (1UL << 21) +#define RDTSC_FEATURE (1UL << 4) + static void calculate_cpu_conversion_factor() @@ -213,7 +217,23 @@ not_so_quick_sample: static status_t check_cpu_features() { - // ToDo: for now + // check the eflags register to see if the cpuid instruction exists + if ((get_eflags() & CPUID_EFLAGS) == 0) { + // it's not set yet, but maybe we can set it manually + set_eflags(get_eflags() | CPUID_EFLAGS); + if ((get_eflags() & CPUID_EFLAGS) == 0) + return B_ERROR; + } + + cpuid_info info; + if (get_current_cpuid(&info, 1) != B_OK) + return B_ERROR; + + if ((info.eax_1.features & RDTSC_FEATURE) == 0) { + // we currently require RDTSC + return B_ERROR; + } + return B_OK; }