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.
This commit is contained in:
Michael Lotz 2014-10-22 20:55:52 +02:00
parent b137575c46
commit e9922e775f
5 changed files with 14 additions and 3 deletions

View File

@ -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

View File

@ -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)

View File

@ -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).

View File

@ -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

View File

@ -9,9 +9,6 @@
#include <arch/x86/descriptors.h>
#define BOOT_GDT_SEGMENT_COUNT (USER_DATA_SEGMENT + 1)
#ifndef _ASSEMBLER