hrev48074 adds 1 changeset to branch 'master' old head: b137575c461be41cda4355aca3ff195ac92881e3 new head: e9922e775f2fbbffa4847ae797e5349542948f25 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=e9922e7+%5Eb137575 ---------------------------------------------------------------------------- e9922e7: haiku_loader: Fix wrong size of gBootGDT on x86_64. The BOOT_GDT_SEGMENT_COUNT was based on USER_DATA_SEGMENT on both x86 and x86_64. However, on x86_64 the order of the segments is different, leading to a too small gBootGDT array. Move the define to the arch specific headers so they can be setup correctly in either case. Also add a STATIC_ASSERT() to check that the descriptors fit into the array. Pointed out by CID 1210898. [ Michael Lotz <mmlr@xxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev48074 Commit: e9922e775f2fbbffa4847ae797e5349542948f25 URL: http://cgit.haiku-os.org/haiku/commit/?id=e9922e7 Author: Michael Lotz <mmlr@xxxxxxxx> Date: Wed Oct 22 18:55:52 2014 UTC ---------------------------------------------------------------------------- 5 files changed, 14 insertions(+), 3 deletions(-) headers/private/kernel/arch/x86/32/descriptors.h | 2 ++ headers/private/kernel/arch/x86/64/descriptors.h | 2 ++ src/system/boot/platform/bios_ia32/long.cpp | 5 +++++ src/system/boot/platform/bios_ia32/mmu.cpp | 5 +++++ src/system/boot/platform/bios_ia32/mmu.h | 3 --- ---------------------------------------------------------------------------- diff --git a/headers/private/kernel/arch/x86/32/descriptors.h b/headers/private/kernel/arch/x86/32/descriptors.h index 5308ce0..535c6a1 100644 --- a/headers/private/kernel/arch/x86/32/descriptors.h +++ b/headers/private/kernel/arch/x86/32/descriptors.h @@ -16,6 +16,8 @@ #define USER_CODE_SEGMENT 3 #define USER_DATA_SEGMENT 4 +#define BOOT_GDT_SEGMENT_COUNT (USER_DATA_SEGMENT + 1) + #define APM_CODE32_SEGMENT 5 #define APM_CODE16_SEGMENT 6 #define APM_DATA_SEGMENT 7 diff --git a/headers/private/kernel/arch/x86/64/descriptors.h b/headers/private/kernel/arch/x86/64/descriptors.h index c5a783a..e359741 100644 --- a/headers/private/kernel/arch/x86/64/descriptors.h +++ b/headers/private/kernel/arch/x86/64/descriptors.h @@ -13,6 +13,8 @@ #define USER_DATA_SEGMENT 3 #define USER_CODE_SEGMENT 4 +#define BOOT_GDT_SEGMENT_COUNT (USER_CODE_SEGMENT + 1) + #define KERNEL_CODE_SELECTOR ((KERNEL_CODE_SEGMENT << 3) | DPL_KERNEL) #define KERNEL_DATA_SELECTOR ((KERNEL_DATA_SEGMENT << 3) | DPL_KERNEL) diff --git a/src/system/boot/platform/bios_ia32/long.cpp b/src/system/boot/platform/bios_ia32/long.cpp index e558bae..2152f99 100644 --- a/src/system/boot/platform/bios_ia32/long.cpp +++ b/src/system/boot/platform/bios_ia32/long.cpp @@ -62,6 +62,11 @@ fix_address(FixedWidthPointer<Type>& p) static void long_gdt_init() { + STATIC_ASSERT(BOOT_GDT_SEGMENT_COUNT > KERNEL_CODE_SEGMENT + && BOOT_GDT_SEGMENT_COUNT > KERNEL_DATA_SEGMENT + && BOOT_GDT_SEGMENT_COUNT > USER_CODE_SEGMENT + && BOOT_GDT_SEGMENT_COUNT > USER_DATA_SEGMENT); + clear_segment_descriptor(&gBootGDT[0]); // Set up code/data segments (TSS segments set up later in the kernel). diff --git a/src/system/boot/platform/bios_ia32/mmu.cpp b/src/system/boot/platform/bios_ia32/mmu.cpp index e70929f..8cf746f 100644 --- a/src/system/boot/platform/bios_ia32/mmu.cpp +++ b/src/system/boot/platform/bios_ia32/mmu.cpp @@ -538,6 +538,11 @@ mmu_init_for_kernel(void) { TRACE("mmu_init_for_kernel\n"); + STATIC_ASSERT(BOOT_GDT_SEGMENT_COUNT > KERNEL_CODE_SEGMENT + && BOOT_GDT_SEGMENT_COUNT > KERNEL_DATA_SEGMENT + && BOOT_GDT_SEGMENT_COUNT > USER_CODE_SEGMENT + && BOOT_GDT_SEGMENT_COUNT > USER_DATA_SEGMENT); + // set up a new gdt // put standard segment descriptors in GDT diff --git a/src/system/boot/platform/bios_ia32/mmu.h b/src/system/boot/platform/bios_ia32/mmu.h index ca37354..7c338a4 100644 --- a/src/system/boot/platform/bios_ia32/mmu.h +++ b/src/system/boot/platform/bios_ia32/mmu.h @@ -9,9 +9,6 @@ #include <arch/x86/descriptors.h> -#define BOOT_GDT_SEGMENT_COUNT (USER_DATA_SEGMENT + 1) - - #ifndef _ASSEMBLER