Made it possible to build the bootloader when targetting x86_64.

* x86_64 is using the existing *_ia32 boot platforms.
* Special flags are required when compiling the loader to get GCC to compile
  32-bit code. This adds a new set of rules for compiling boot code rather
  than using the kernel rules, which compile using the necessary flags.
* Some x86_64 private headers have been stubbed by #include'ing the x86
  versions. These will be replaced later.
This commit is contained in:
Alex Smith
2012-05-26 21:47:27 +01:00
parent d6e724d549
commit 65ad1ba320
48 changed files with 420 additions and 66 deletions
+129
View File
@@ -0,0 +1,129 @@
rule SetupBoot
{
# Usage SetupBoot <sources_or_objects> : <extra_cc_flags> : <include_private_headers> ;
#
# <sources_or_objects> - Ideally sources, otherwise HDRSEARCH can not be
# set for the sources and the sources some header
# dependencies might be missing.
local sources = [ FGristFiles $(1) ] ;
local objects = $(sources:S=$(SUFOBJ)) ;
# add private kernel headers
if $(3) != false {
SourceSysHdrs $(sources) : $(TARGET_PRIVATE_KERNEL_HEADERS) ;
}
local object ;
for object in $(objects) {
# add boot flags for the object
ObjectCcFlags $(object) : $(TARGET_BOOT_CCFLAGS) $(2) ;
ObjectC++Flags $(object) : $(TARGET_BOOT_C++FLAGS) $(2) ;
ObjectDefines $(object) : $(TARGET_KERNEL_DEFINES) ;
ASFLAGS on $(object) = $(TARGET_BOOT_CCFLAGS) ;
# override warning flags
TARGET_WARNING_CCFLAGS on $(object) = $(TARGET_KERNEL_WARNING_CCFLAGS) ;
TARGET_WARNING_C++FLAGS on $(object)
= $(TARGET_KERNEL_WARNING_C++FLAGS) ;
}
}
rule BootObjects
{
SetupBoot $(1) : $(2) ;
Objects $(1) ;
}
rule BootLd
{
# BootLd <name> : <objs> : <linkerscript> : <args> ;
LINK on $(1) = $(TARGET_LD) ;
LINKFLAGS on $(1) = $(4) ;
if $(3) { LINKFLAGS on $(1) += --script=$(3) ; }
# Remove any preset LINKLIBS, but link against libgcc.a. Linking against
# libsupc++ is opt-out.
local libs ;
if ! [ on $(1) return HAIKU_NO_LIBSUPC++ ] {
libs += $(TARGET_BOOT_LIBSUPC++) ;
}
LINKLIBS on $(1) = $(libs) $(TARGET_BOOT_LIBGCC) ;
# TODO: Do we really want to invoke SetupBoot here? The objects should
# have been compiled with BootObjects anyway, so we're doing that twice.
SetupBoot $(2) ;
# Show that we depend on the libraries we need
LocalClean clean : $(1) ;
LocalDepends all : $(1) ;
Depends $(1) : $(2) ;
MakeLocateDebug $(1) ;
on $(1) XRes $(1) : $(RESFILES) ;
if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] {
SetType $(1) ;
MimeSet $(1) ;
SetVersion $(1) ;
}
}
actions BootLd bind VERSION_SCRIPT
{
$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) \
--version-script=$(VERSION_SCRIPT)
}
rule BootMergeObject
{
# BootMergeObject <name> : <sources> : <extra CFLAGS> : <other objects> ;
# Compiles source files and merges the object files to an object file.
# <name>: Name of the object file to create. No grist will be added.
# <sources>: Sources to be compiled. Grist will be added.
# <extra CFLAGS>: Additional flags for compilation.
# <other objects>: Object files or static libraries to be merged. No grist
# will be added.
#
SetupBoot $(2) : $(3) ;
Objects $(2) ;
MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(4) ;
LINKFLAGS on $(1) += $(TARGET_BOOT_LINKFLAGS) ;
}
rule BootStaticLibrary
{
# Usage BootStaticLibrary <name> : <sources> : <extra cc flags> ;
# This is designed to take a set of sources and libraries and create
# a file called lib<name>.a
SetupBoot $(2) : $(3) : false ;
Library $(1) : $(2) ;
}
rule BootStaticLibraryObjects
{
# Usage BootStaticLibrary <name> : <sources> ;
# This is designed to take a set of sources and libraries and create
# a file called <name>
# Show that we depend on the libraries we need
SetupBoot $(2) ;
LocalClean clean : $(1) ;
LocalDepends all : $(1) ;
Depends $(1) : $(2) ;
MakeLocateDebug $(1) ;
}
actions BootStaticLibraryObjects
{
# Force recreation of the archive to avoid build errors caused by
# stale dependencies after renaming or deleting object files.
$(RM) "$(1)"
$(HAIKU_AR) -r "$(1)" "$(2)" ;
}
+23 -1
View File
@@ -159,10 +159,13 @@ if $(HAIKU_GCC_VERSION[1]) = 2 {
HAIKU_C++ ?= $(HAIKU_CC) ;
HAIKU_LINK = $(HAIKU_CC) ;
HAIKU_LINKFLAGS = $(HAIKU_GCC_BASE_FLAGS) ;
HAIKU_BOOT_LINKFLAGS = ;
HAIKU_HDRS = [ FStandardHeaders ] ;
HAIKU_KERNEL_CCFLAGS = $(HAIKU_CCFLAGS) $(HAIKU_GCC_BASE_FLAGS) ;
HAIKU_KERNEL_C++FLAGS = $(HAIKU_C++FLAGS) $(HAIKU_GCC_BASE_FLAGS) ;
HAIKU_BOOT_CCFLAGS = $(HAIKU_CCFLAGS) $(HAIKU_GCC_BASE_FLAGS) ;
HAIKU_BOOT_C++FLAGS = $(HAIKU_C++FLAGS) $(HAIKU_GCC_BASE_FLAGS) ;
HAIKU_CCFLAGS += $(HAIKU_GCC_BASE_FLAGS) -nostdinc ;
HAIKU_C++FLAGS += $(HAIKU_GCC_BASE_FLAGS) -nostdinc ;
HAIKU_DEFINES = __HAIKU__ ;
@@ -249,7 +252,6 @@ switch $(HAIKU_CPU) {
}
case x86_64 :
{
HAIKU_DEFINES += __x86_64__ ;
HAIKU_BOOT_PLATFORM = bios_ia32 ;
HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 2880 ; # in kB
# offset in floppy image (>= sizeof(haiku_loader))
@@ -329,6 +331,8 @@ HAIKU_ASFLAGS = ;
HAIKU_KERNEL_CCFLAGS += -finline -fno-builtin ;
HAIKU_KERNEL_C++FLAGS += -finline -fno-builtin -fno-exceptions ;
HAIKU_KERNEL_DEFINES += _KERNEL_MODE ;
HAIKU_BOOT_CCFLAGS += -finline -fno-builtin ;
HAIKU_BOOT_C++FLAGS += -finline -fno-builtin -fno-exceptions ;
if $(HAIKU_GCC_VERSION[1]) >= 3 {
HAIKU_KERNEL_C++FLAGS += -fno-use-cxa-atexit ;
@@ -340,6 +344,8 @@ if $(HAIKU_GCC_VERSION[1]) >= 4 {
if $(HAIKU_GCC_VERSION[2]) >= 3 {
HAIKU_KERNEL_CCFLAGS += -ffreestanding ;
HAIKU_KERNEL_C++FLAGS += -ffreestanding ;
HAIKU_BOOT_CCFLAGS += -ffreestanding ;
HAIKU_BOOT_C++FLAGS += -ffreestanding ;
}
}
@@ -377,6 +383,15 @@ switch $(HAIKU_ARCH) {
}
case x86_64 :
{
# Kernel lives in the top 2GB of the address space, use kernel code model.
HAIKU_KERNEL_CCFLAGS += -mcmodel=kernel ;
HAIKU_KERNEL_C++FLAGS += -mcmodel=kernel ;
# Bootloader is 32-bit.
HAIKU_BOOT_LINKFLAGS += -m elf_i386_haiku ;
HAIKU_BOOT_CCFLAGS += -m32 ;
HAIKU_BOOT_C++FLAGS += -m32 ;
# Enable use of the gcc built-in atomic functions instead of atomic_*().
# The former are inlined and have thus less overhead.
HAIKU_DEFINES += B_USE_BUILTIN_ATOMIC_FUNCTIONS ;
@@ -962,6 +977,7 @@ local buildVars =
KERNEL_CCFLAGS KERNEL_C++FLAGS
KERNEL_PIC_CCFLAGS KERNEL_PIC_LINKFLAGS
BOOT_CCFLAGS BOOT_C++FLAGS BOOT_LINKFLAGS
WARNING_CCFLAGS WARNING_C++FLAGS
KERNEL_WARNING_CCFLAGS KERNEL_WARNING_C++FLAGS
@@ -998,6 +1014,9 @@ if $(TARGET_PLATFORM) = haiku {
TARGET_GCC_LIBGCC = $(HAIKU_GCC_LIBGCC) ;
TARGET_GCC_LIBGCC_OBJECTS = $(HAIKU_GCC_LIBGCC_OBJECTS) ;
TARGET_BOOT_LIBGCC = $(HAIKU_BOOT_LIBGCC) ;
TARGET_BOOT_LIBSUPC++ = $(HAIKU_BOOT_LIBSUPC++) ;
TARGET_BOOT_PLATFORM ?= $(HAIKU_BOOT_PLATFORM) ;
TARGET_BOOT_BOARD ?= $(HAIKU_BOOT_BOARD) ;
@@ -1014,6 +1033,9 @@ if $(TARGET_PLATFORM) = haiku {
TARGET_GCC_LIBGCC = ;
TARGET_GCC_LIBGCC_OBJECTS = ;
TARGET_BOOT_LIBGCC = ;
TARGET_BOOT_LIBSUPC++ = ;
TARGET_BOOT_PLATFORM = ;
TARGET_BOOT_BOARD = ;