Changes to kernel_args to make it identical for x86 and x86_64.
* Added a FixedWidthPointer template class which uses 64-bit storage to hold a pointer. This is used in place of raw pointers in kernel_args. * Added __attribute__((packed)) to kernel_args and all structures contained within it. This is necessary due to different alignment behaviour for 32-bit and 64-bit compilation with GCC. * With these changes, kernel_args will now come out the same size for both the x86_64 kernel and the loader, excluding the preloaded_image structure which has not yet been changed. * Tested both an x86 GCC2 and GCC4 build, no problems caused by these changes.
This commit is contained in:
@@ -9,6 +9,10 @@
|
||||
# error This file is included from <boot/kernel_args.h> only
|
||||
#endif
|
||||
|
||||
|
||||
#include <util/FixedWidthPointer.h>
|
||||
|
||||
|
||||
#define MAX_BOOT_PTABLES 4
|
||||
|
||||
#define _PACKED __attribute__((packed))
|
||||
@@ -34,14 +38,13 @@ typedef struct {
|
||||
// smp stuff
|
||||
uint32 apic_time_cv_factor; // apic ticks per second
|
||||
uint32 apic_phys;
|
||||
uint32 *apic;
|
||||
FixedWidthPointer<void> apic;
|
||||
uint32 ioapic_phys;
|
||||
uint32 *ioapic;
|
||||
uint32 cpu_apic_id[MAX_BOOT_CPUS];
|
||||
uint32 cpu_apic_version[MAX_BOOT_CPUS];
|
||||
// hpet stuff
|
||||
uint32 hpet_phys;
|
||||
uint32 *hpet;
|
||||
} arch_kernel_args;
|
||||
FixedWidthPointer<void> hpet;
|
||||
} _PACKED arch_kernel_args;
|
||||
|
||||
#endif /* KERNEL_ARCH_x86_KERNEL_ARGS_H */
|
||||
|
||||
@@ -13,13 +13,13 @@
|
||||
typedef struct addr_range {
|
||||
uint64 start;
|
||||
uint64 size;
|
||||
} addr_range;
|
||||
} _PACKED addr_range;
|
||||
|
||||
|
||||
typedef struct phys_addr_range {
|
||||
phys_addr_t start;
|
||||
phys_size_t size;
|
||||
} phys_addr_range;
|
||||
} _PACKED phys_addr_range;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
#define KERNEL_BOOT_DRIVER_SETTINGS_H
|
||||
|
||||
|
||||
#include <util/FixedWidthPointer.h>
|
||||
#include <util/list.h>
|
||||
|
||||
|
||||
struct driver_settings_file {
|
||||
struct driver_settings_file *next;
|
||||
FixedWidthPointer<struct driver_settings_file> next;
|
||||
char name[B_OS_NAME_LENGTH];
|
||||
char *buffer;
|
||||
size_t size;
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
#include <boot/addr_range.h>
|
||||
#include <sys/stat.h>
|
||||
#include <elf_priv.h>
|
||||
#include <util/FixedWidthPointer.h>
|
||||
|
||||
|
||||
struct preloaded_image {
|
||||
struct preloaded_image *next;
|
||||
FixedWidthPointer<struct preloaded_image> next;
|
||||
char *name;
|
||||
elf_region text_region;
|
||||
elf_region data_region;
|
||||
@@ -37,7 +38,7 @@ struct preloaded_image {
|
||||
// the ID field will be filled out in the kernel
|
||||
bool is_module;
|
||||
// set by the module initialization code
|
||||
};
|
||||
} _PACKED;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
#include <platform_kernel_args.h>
|
||||
#include <arch_kernel_args.h>
|
||||
|
||||
#include <util/FixedWidthPointer.h>
|
||||
|
||||
|
||||
#define CURRENT_KERNEL_ARGS_VERSION 1
|
||||
#define MAX_KERNEL_ARGS_RANGE 20
|
||||
|
||||
@@ -42,7 +45,7 @@ typedef struct kernel_args {
|
||||
uint32 version;
|
||||
|
||||
struct preloaded_image kernel_image;
|
||||
struct preloaded_image *preloaded_images;
|
||||
FixedWidthPointer<struct preloaded_image> preloaded_images;
|
||||
|
||||
uint32 num_physical_memory_ranges;
|
||||
phys_addr_range physical_memory_range[MAX_PHYSICAL_MEMORY_RANGE];
|
||||
@@ -58,10 +61,10 @@ typedef struct kernel_args {
|
||||
addr_range cpu_kstack[MAX_BOOT_CPUS];
|
||||
|
||||
// boot volume KMessage data
|
||||
uint64 boot_volume;
|
||||
FixedWidthPointer<void> boot_volume;
|
||||
int32 boot_volume_size;
|
||||
|
||||
struct driver_settings_file *driver_settings;
|
||||
FixedWidthPointer<struct driver_settings_file> driver_settings;
|
||||
|
||||
struct {
|
||||
phys_addr_range physical_buffer;
|
||||
@@ -72,12 +75,12 @@ typedef struct kernel_args {
|
||||
bool enabled;
|
||||
} frame_buffer;
|
||||
|
||||
void *vesa_modes;
|
||||
FixedWidthPointer<void> vesa_modes;
|
||||
uint16 vesa_modes_size;
|
||||
uint8 vesa_capabilities;
|
||||
void *edid_info;
|
||||
FixedWidthPointer<void> edid_info;
|
||||
|
||||
void *debug_output;
|
||||
FixedWidthPointer<void> debug_output;
|
||||
uint32 debug_size;
|
||||
bool keep_debug_output_buffer;
|
||||
|
||||
@@ -85,8 +88,8 @@ typedef struct kernel_args {
|
||||
arch_kernel_args arch_args;
|
||||
|
||||
// bootsplash data
|
||||
uint8 *boot_splash;
|
||||
FixedWidthPointer<uint8> boot_splash;
|
||||
|
||||
} kernel_args;
|
||||
} _PACKED kernel_args;
|
||||
|
||||
#endif /* KERNEL_BOOT_KERNEL_ARGS_H */
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <arch/x86/apm.h>
|
||||
#include <bios_drive.h>
|
||||
#include <util/FixedWidthPointer.h>
|
||||
|
||||
|
||||
// must match SMP_MAX_CPUS in arch_smp.h
|
||||
@@ -25,9 +26,10 @@
|
||||
typedef struct {
|
||||
uint16 serial_base_ports[MAX_SERIAL_PORTS];
|
||||
|
||||
bios_drive *drives; // this does not contain the boot drive
|
||||
FixedWidthPointer<bios_drive> drives;
|
||||
// this does not contain the boot drive
|
||||
|
||||
apm_info apm;
|
||||
} platform_kernel_args;
|
||||
} _PACKED platform_kernel_args;
|
||||
|
||||
#endif /* KERNEL_BOOT_PLATFORM_BIOS_IA32_KERNEL_ARGS_H */
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright 2012, Alex Smith, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef KERNEL_UTIL_FIXED_WIDTH_POINTER_H
|
||||
#define KERNEL_UTIL_FIXED_WIDTH_POINTER_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
/*!
|
||||
\class FixedWidthPointer
|
||||
\brief Pointer class with fixed size (64-bit) storage.
|
||||
|
||||
This class is a pointer-like class that uses a fixed size 64-bit storage.
|
||||
This is used to make kernel_args compatible (i.e. the same size) for both
|
||||
32-bit and 64-bit kernels.
|
||||
*/
|
||||
template<typename Type>
|
||||
class FixedWidthPointer {
|
||||
public:
|
||||
operator Type*() const
|
||||
{
|
||||
return (Type *)(addr_t)fValue;
|
||||
}
|
||||
|
||||
operator addr_t() const
|
||||
{
|
||||
return (addr_t)fValue;
|
||||
}
|
||||
|
||||
Type &operator*() const
|
||||
{
|
||||
return *(Type *)*this;
|
||||
}
|
||||
|
||||
Type *operator->() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
FixedWidthPointer &operator=(const FixedWidthPointer &p)
|
||||
{
|
||||
fValue = p.fValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
FixedWidthPointer &operator=(Type *p)
|
||||
{
|
||||
fValue = (addr_t)p;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
Get the 64-bit pointer value.
|
||||
\return Pointer address.
|
||||
*/
|
||||
uint64 Get() const
|
||||
{
|
||||
return fValue;
|
||||
}
|
||||
|
||||
/*!
|
||||
Set the 64-bit pointer value.
|
||||
\param addr New address for the pointer.
|
||||
*/
|
||||
void SetTo(uint64 addr)
|
||||
{
|
||||
fValue = addr;
|
||||
}
|
||||
private:
|
||||
uint64 fValue;
|
||||
} _PACKED;
|
||||
|
||||
|
||||
// Specialization for void pointers, can be converted to another pointer type.
|
||||
template<>
|
||||
class FixedWidthPointer<void> {
|
||||
public:
|
||||
operator void*() const
|
||||
{
|
||||
return (void *)(addr_t)fValue;
|
||||
}
|
||||
|
||||
template<typename OtherType>
|
||||
operator OtherType*() const
|
||||
{
|
||||
return (OtherType *)(addr_t)fValue;
|
||||
}
|
||||
|
||||
operator addr_t() const
|
||||
{
|
||||
return (addr_t)fValue;
|
||||
}
|
||||
|
||||
FixedWidthPointer &operator=(const FixedWidthPointer &p)
|
||||
{
|
||||
fValue = p.fValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
FixedWidthPointer &operator=(void *p)
|
||||
{
|
||||
fValue = (addr_t)p;
|
||||
return *this;
|
||||
}
|
||||
|
||||
uint64 Get() const
|
||||
{
|
||||
return fValue;
|
||||
}
|
||||
|
||||
void SetTo(uint64 addr)
|
||||
{
|
||||
fValue = addr;
|
||||
}
|
||||
private:
|
||||
uint64 fValue;
|
||||
} _PACKED;
|
||||
|
||||
|
||||
#endif /* KERNEL_UTIL_FIXED_WIDTH_POINTER_H */
|
||||
Reference in New Issue
Block a user