History log of /haiku/src/system/boot/loader/elf.cpp
Revision Date Author Comments
# a8555ee7 09-Nov-2023 Alexander von Gluck IV <kallisti5@unixzen.com>

loader/elf: Add missing PT_RISCV_ATTRIBUTES Page Table type

* llvm project called out when adding this to llvm:
"There is no real-world use case yet"
* https://sourceware.org/pipermail/binutils/2021-June/117182.html

Change-Id: I882b31db7a054d42f1045dd438cc9678ea4de50c
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7098
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# cc6365c7 06-Aug-2023 Augustin Cavalier <waddlesplash@gmail.com>

bootloader: Don't issue warnings upon encountering PT_EH_FRAME.

The kernel already does the same thing.


# c2dcf106 29-Sep-2022 Alexander von Gluck IV <kallisti5@unixzen.com>

Revert "boot/efi/x86: enable support for 64-bit ELF"

This reverts commit 5897f7b6235d36a58582513ad5db270d9b1ce926.

See #17961 for additional information. This breaks the official
builds by growing the bios_ia32 loader too much.

Change-Id: I63bc0c95839ef681a260efdd6ddf527d6699c1f4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5704
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 5897f7b6 22-Sep-2022 David Karoly <karolyd577@gmail.com>

boot/efi/x86: enable support for 64-bit ELF

Change-Id: Id3b207444b55041dc83ee1afdd61b467ce13ff70
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5665
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>


# ef894353 16-Sep-2022 David Karoly <karolyd577@gmail.com>

boot/x86: unify KERNEL_LOAD_ADDRESS for BIOS and EFI

Change-Id: Ia3157c7c0908698da94c1aa85cb6366fb00fb7f1
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5670
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
Reviewed-by: Fredrik Holmqvist <fredrik.holmqvist@gmail.com>


# 6117e0c2 18-Dec-2021 David Karoly <karolyd577@gmail.com>

boot/loader: relocate kernel to virtual address space on 32-bit architectures

Change-Id: Ic86ca6874f358df8755a0c691cccb155d145e06c
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4675
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Fredrik Holmqvist <fredrik.holmqvist@gmail.com>


# 235aa994 17-Dec-2021 David Karoly <karolyd577@gmail.com>

boot: rework 32-bit/64-bit kernel load base selection

Change-Id: I0aed05c0ef2ff1a162581e4f988bf24ed1e521e0
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4816
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
Reviewed-by: Fredrik Holmqvist <fredrik.holmqvist@gmail.com>


# f1fa58bf 25-Jul-2021 X512 <danger_mail@list.ru>

haiku_loader.efi: update for riscv64

* Added MMU page table generation.
* Added optional FDT device detection and passing to kernel.
* Add platform address translation stubs to bios_ia32
to drop EFI ifdefs

Change-Id: I89257c93c84404fd988f621b29f927ed0df3c3b1
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4304
Reviewed-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>


# 185e6809 30-Dec-2020 PulkoMandy <pulkomandy@pulkomandy.tk>

sparc: Build fixes

- Wrong printf format in bootloader elf panic call
- Missing functions for sparc

Change-Id: I4715a8d6d3d864d379b8386dc3958e0a2c1962e7
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3571
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 9a846343 30-Dec-2020 PulkoMandy <pulkomandy@pulkomandy.tk>

bootloader elf: fix misaligned access

The elf region structure is packed. So it's not possible to use a
pointer to one of its fields on sparc. Use a temporary variable that's
properly aligned.

Change-Id: I9dd9b9f2b1d14821e34bc2f5b3da661086ef3fef
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3567
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 2ef7fd71 30-Dec-2020 PulkoMandy <pulkomandy@pulkomandy.tk>

bootloader elf: fix elf64 loading for non-x86 platforms

Some code was enabled only for EFI, but is in fact correct for all
platforms except BIOS. Switch the defines around to have the correct
code enabled by default.

Change-Id: I58b1d17a78dcf273ceee88318338b4770b500bb3
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3566
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 85b4ce61 30-Dec-2020 PulkoMandy <pulkomandy@pulkomandy.tk>

bootloader elf: fix tracing for 64bit

Change-Id: I59f22c5768ed245cfd937be3f60127672d6ffc61
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3565
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# a9f4ce45 14-Jan-2019 Augustin Cavalier <waddlesplash@gmail.com>

bootloader: Obey "load_symbols" kernel setting.


# 82dcc316 22-Oct-2014 Henry Harrington <henry.harrington@gmail.com>

bootloader: Translate kernel args before adding them to kernel_args_range.

Chunks may be physically contiguous, but virtually disjoint. Adding
physical addresses may cause ranges to be merged incorrectly.

Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>


# b3215a62 21-Oct-2014 Henry Harrington <henry.harrington@gmail.com>

EFI: preliminary support for starting the kernel.

Enough to let the kernel to print hello, but not much beyond that.

Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>


# 211483cb 14-Apr-2016 Fredrik Holmqvist <fredrik.holmqvist@gmail.com>

EFI: Initial test EFI application

* Only set HAIKU_BOOT_PLATFORM to bios_ia32 if not defined
* Add gnuefi build feature
* Introduce BOOT_LDFLAGS, and move options for passing to linker
into ArchitectureSetup
* x86_64 compile fixes for warnings in boot loader
* loader/elf.cpp: don't include ELF32 support when targeting EFI
* relocation_func.cpp: copy of the relocation code from gnuefi
to make _relocate extern "C", and avoid including <efilib.h>
* boot_loader_efi.ld: copy of gnuefi's elf_x86_64_efi.lds,
modified to include support for C++ constructors, etc. Keep in
sync with the gnuefi package

Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>


# 8efb6db7 06-Aug-2016 Adrien Destugues <pulkomandy@gmail.com>

elf.h: rename ELF_MAGIC to ELFMAG

- This is how it is named in other versions of elf.h (Linux, glibc, possibly more)
- ELF_MAGIC is used by libelf for the same thing, and the defines conflicts,
breaking libelf build on Haiku.


# 73ef47f7 06-Nov-2015 François Revol <revol@free.fr>

loader: TRACE undefined symbols

While the kernel shouldn't have any, it happens on platforms missing new features.

Make it explicit.


# 75c31ae2 26-Oct-2015 Simon South <ssouth@simonsouth.com>

system: Build using public elf.h header

Reduce duplication of code by

* Removing from elf_common.h definitions available in os/kernel/elf.h
* Deleting elf32.h and elf64.h
* Renaming elf_common.h to elf_private.h
* Updating source to build using public and private ELF header files
together

Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>


# ece6f8ba 06-Sep-2014 Paweł Dziepak <pdziepak@quarnos.org>

boot: remove check against large gaps between elf segments

As discussed on the ML the limitation of the gap between segments
imposed by this check is completely artifical and pointless.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>


# 5de8dca2 02-Sep-2014 PulkoMandy <pulkomandy@pulkomandy.tk>

Bootloader: fix loading of ARM ELF files

* Let the loader know about PT_ARM_UNWIND (and ignore it)
* Allow up to 32K of space between sections of an ELF files as ARM ones
need that.


# ad5bdbdf 30-Aug-2014 Ithamar R. Adema <ithamar@upgrade-android.com>

ELF: enlarge the allowed padding between sections

Turns out the padding on ARM is slightly larger, and prevented
the kernel add-ons from being loaded.


# 5f08555a 26-Apr-2013 Jérôme Duval <jerome.duval@gmail.com>

GCC 4.7.x doesn't allow writes in a referenced packed struct.

* error: cannot bind packed field 'image->preloaded_elf64_image::elf_header'
to 'ELFLoader<ELF64Class>::EhdrType& {aka Elf64_Ehdr&}'


# 9f629ef3 17-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

Rename KERNEL_LOAD_BASE_64BIT to KERNEL_LOAD_BASE_64_BIT for consistency.


# 15feb603 06-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

A few improvements suggested by Ingo.


# a820f129 26-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Style fixes to elf.cpp.


# 6f6d78e8 25-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Cleaned up ELF64 address handling.

* platform_allocate_elf_region() is removed, it is implemented in platform-
independent code now (ELF*Class::AllocateRegion). For ELF64 it is now
assumed that 64-bit addresses are mapped in the loader's 32-bit address space
as (address - KERNEL_BASE_64BIT + KERNEL_BASE).
* mapped_delta field from preloaded_*_image removed, now handled compile-time
using the ELF*Class::Map method.
* Also link the kernel with -z max-page-size=0x1000, removes the need for
2MB alignment on the data segment (not going to map the kernel with large
pages for the time being).


# 88461898 24-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Handle 64-bit load addresses for ELF64 images in the bootloader.

The ELF loader now uses a new platform function, platform_allocate_elf_region,
which returns 2 addresses: the real load address and an address where the
region is mapped in the loader's address space. All of the ELF loading code
has been changed to access the load region through the mapped address rather
than the addresses contained in the ELF image. The ELF64 version of
platform_allocate_elf_region on x86 uses the existing MMU code, which maps
everything at 0x80000000, but returns the correct 64-bit address. The long
mode switch code will just set up the 64-bit address space with everything
remapped at the correct address.


# c2656eb9 24-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Improved elf_load_image() a bit.

After enabling BOOT_SUPPORT_ELF64 on x86 the x86 kernel could no longer be
booted because too many kernel_args allocations were taking place and filling
kernel_args_ranges. This was because for each image load it would check if
the image is ELF64, fail and fall back to ELF32 (each ELF64 check allocated
a preloaded_image). Changed elf_load_image() so that it only tries both when
loading the kernel image, and then for modules it will only try the same ELF
class as the kernel image.


# ccadfaee 22-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Changed the boot ELF code to use templates and added ELF64 support.

The actual implementation of the ELF loading methods have been put into
an ELFLoader template class that takes a single template parameter, which
is a structure containing all the necessary ELF typedefs. It's a bit
verbose, but I thought it was a neater solution than using a bunch of
standalone functions with a huge number of template parameters. There is
no change to code outside of elf.cpp, the ELF32/ELF64 differences are
handled internally.


# f1244978 22-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Added an ELF64 version of preloaded_image.

* There is now 2 structures, preloaded_elf32_image and preloaded_elf64_image,
which both inherit from preloaded_image.
* For now I've just hardcoded in use of preloaded_elf32_image, but the
bootloader ELF code will shortly be converted to use templates which use
the appropriate structure. The kernel will be changed later when I add
ELF64 support to it.
* All kernel_args data is now compatible between 32-bit and 64-bit kernels.


# 9a3d05d7 02-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Check return value of fstat() (CID 2513). Cannot really fail in the boot
loader, but the check doesn't harm either.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40066 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3069ca96 30-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Enable loading debug symbols again. The approach to use the driver settings
is broken.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34825 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 118fa893 15-Dec-2009 Fredrik Holmqvist <fredrik.holmqvist@gmail.com>

Make sure settings isn't null. Not my finest day apparently.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34679 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0f6b7a8c 15-Dec-2009 Fredrik Holmqvist <fredrik.holmqvist@gmail.com>

Unload driver settings as well.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34678 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d403ff62 15-Dec-2009 Fredrik Holmqvist <fredrik.holmqvist@gmail.com>

Style fix:
* static variables should start with s.
* function blocks should start on new line.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34668 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5e972c0f 15-Dec-2009 Fredrik Holmqvist <fredrik.holmqvist@gmail.com>

Implemented TODO about not loading symbols at boot.
This saves ~0.5s of boot time here, but I suspect it might be better for CD.
Enabled loadSymbols in kernel settings so the behavior should be the same as before this change.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34666 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ea2abd11 02-Aug-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Renamed the ROUNDOWN macro to ROUNDDOWN. Also changed the implementation of
ROUNDUP to use '*' and '/' -- the compiler will optimize that for powers of
two anyway and this implementation works for other numbers as well.
* The thread::fault_handler use in C[++] code was broken with gcc 4. At least
when other functions were invoked. Trying to trick the compiler wasn't a
particularly good idea anyway, since the next compiler version could break
the trick again. So the general policy is to use the fault handlers only in
assembly code where we have full control. Changed that for x86 (save for the
vm86 mode, which has a similar mechanism), but not for the other
architectures.
* Introduced fault_handler, fault_handler_stack_pointer, and fault_jump_buffer
fields in the cpu_ent structure, which must be used instead of
thread::fault_handler in the kernel debugger. Consequently user_memcpy() must
not be used in the kernel debugger either. Introduced a debug_memcpy()
instead.
* Introduced debug_call_with_fault_handler() function which calls a function
in a setjmp() and fault handler context. The architecture specific backend
arch_debug_call_with_fault_handler() has only been implemented for x86 yet.
* Introduced debug_is_kernel_memory_accessible() for use in the kernel
debugger. It determines whether a range of memory can be accessed in the
way specified. The architecture specific back end
arch_vm_translation_map_is_kernel_page_accessible() has only been implemented
for x86 yet.
* Added arch_debug_unset_current_thread() (only implemented for x86) to unset
the current thread pointer in the kernel debugger. When entering the kernel
debugger we do some basic sanity checks of the currently set thread structure
and unset it, if they fail. This allows certain commands (most importantly
the stack trace command) to avoid accessing the thread structure.
* x86: When handling a double fault, we do now install a special handler for
page faults. This allows us to gracefully catch faulting commands, even if
e.g. the thread structure is toast.

We are now in much better shape to deal with double faults. Hopefully avoiding
the triple faults that some people have been experiencing on their hardware
and ideally even allowing to use the kernel debugger normally.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32073 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0dc4d1e5 26-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Reverted r27685, r27676, r27665, and r27664, the changes related to
letting the boot loader provide full paths for the pre-loaded images.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27753 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 18ee966f 22-Sep-2008 Axel Dörfler <axeld@pinc-software.de>

* The boot loader now replaces the first path component of all path names
passed to the kernel with "boot" instead of the volume name; the kernel
mounts the boot volume always as "/boot".
* This should fix #2757.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27685 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b34e395e 21-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

The boot loader does now set the names of the images it loads to the
full paths.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27665 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9a486099 21-Jul-2008 François Revol <revol@free.fr>

better english, tell about rela relocs.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26559 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1e5538f5 20-Jul-2008 François Revol <revol@free.fr>

silently skip PT_INTERP and PT_PHDR types as we can ignore them. This should make real unhandled types more obvious.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26535 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d0c63aaf 27-Mar-2008 Axel Dörfler <axeld@pinc-software.de>

* Fixed warnings due to the NULL change.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24608 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 957a1b17 30-Dec-2005 Ingo Weinhold <ingo_weinhold@gmx.de>

* Introduced new build system variables
{HAIKU,HOST,TARGET}_KERNEL_PIC_{CC,LINK}FLAGS which define the
compiler/linker flags specifying the kind of position independence
the kernel shall have. For x86 we had and still have -fno-pic, but the
PPC kernel has -fPIE (position independent executable) now, as we
need to relocate it.
* The boot loader relocates the kernel now. Mostly copied the relocation
code from the kernel ELF loader. Almost completely rewrote the PPC
specific relocation code, though. It's more correct and more complete now
(some things are still missing though).
* Added boot platform awareness to the kernel. Moved the generic
Open Firmware code (openfirmware.c/h) from the boot loader to the kernel.
* The kernel PPC serial debug output is sent to the console for the time
being.
* The PPC boot loader counts the CPUs now and allocates the kernel stacks
(made OF device iteration a bit more flexible on the way -- the search
can be restricted to subtree). Furthermore we really enter the kernel...
(Yay! :-) ... and crash in the first dprintf() (in the atomic_set()
called by acquire_spinlock()). kprintf() works, though.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15756 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c83d9dad 28-Dec-2005 Ingo Weinhold <ingo_weinhold@gmx.de>

* platform_allocate_region() has a new boolean parameter "exactAddress"
specifying whether only the exact supplied address is acceptable. If
false, the address is considered a hint only. It will be picked, if
available, otherwise a greater address is tried to be acquired, and
as last resort any address. This feature is only implemented for PPC.
It is needed since the preferred kernel text base address 0x80000000
might not be available (and actually isn't on my Mac mini).
* Fixed a bug in the PPC memory management code:
is_{virtual,physical}_allocated() were checking whether the given
range was completely contained by an existing range instead of
checking for intersection. As a consequence we could (and did) allocate
a range intersecting with already allocated ranges. The kernel segment
thus overwrote OF memory for instance.
* The ELF loader makes sure that it got both text and data segment of
the image to be loaded.

The PPC boot loader successfully loads kernel and modules now. Next
comes the hard part, I'm afraid.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15708 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e84b1633 14-Nov-2005 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed loading of modules whose text and data segments have a little
space inbetween. The segments can be in inverse order now, too.
The same should be done in the kernel, too.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14907 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5af32e75 13-Apr-2005 Axel Dörfler <axeld@pinc-software.de>

Renamed src/kernel to src/system.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12359 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ece6f8ba5d9b1cfc56ffaa2d74bcfbd697dd0f2d 06-Sep-2014 Paweł Dziepak <pdziepak@quarnos.org>

boot: remove check against large gaps between elf segments

As discussed on the ML the limitation of the gap between segments
imposed by this check is completely artifical and pointless.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>


# 5de8dca2e43ecd5e58fc02641bf9f0563c838399 02-Sep-2014 PulkoMandy <pulkomandy@pulkomandy.tk>

Bootloader: fix loading of ARM ELF files

* Let the loader know about PT_ARM_UNWIND (and ignore it)
* Allow up to 32K of space between sections of an ELF files as ARM ones
need that.


# ad5bdbdfd451c10975db51e141af4cc33f295de7 30-Aug-2014 Ithamar R. Adema <ithamar@upgrade-android.com>

ELF: enlarge the allowed padding between sections

Turns out the padding on ARM is slightly larger, and prevented
the kernel add-ons from being loaded.


# 5f08555a59523b2bcdd04bea9d14c497fc8ab01a 26-Apr-2013 Jérôme Duval <jerome.duval@gmail.com>

GCC 4.7.x doesn't allow writes in a referenced packed struct.

* error: cannot bind packed field 'image->preloaded_elf64_image::elf_header'
to 'ELFLoader<ELF64Class>::EhdrType& {aka Elf64_Ehdr&}'


# 9f629ef38e6655e1509dca6db587a2035243ccdb 17-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

Rename KERNEL_LOAD_BASE_64BIT to KERNEL_LOAD_BASE_64_BIT for consistency.


# 15feb60325be086823e80a3468f7aab2bfbc9f7d 06-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

A few improvements suggested by Ingo.


# a820f12943d570cfcb6dbb78781dc587f56e0da8 26-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Style fixes to elf.cpp.


# 6f6d78e877c1a485d98de60395854a6d6de61c0d 25-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Cleaned up ELF64 address handling.

* platform_allocate_elf_region() is removed, it is implemented in platform-
independent code now (ELF*Class::AllocateRegion). For ELF64 it is now
assumed that 64-bit addresses are mapped in the loader's 32-bit address space
as (address - KERNEL_BASE_64BIT + KERNEL_BASE).
* mapped_delta field from preloaded_*_image removed, now handled compile-time
using the ELF*Class::Map method.
* Also link the kernel with -z max-page-size=0x1000, removes the need for
2MB alignment on the data segment (not going to map the kernel with large
pages for the time being).


# 8846189866301c85683151a54ec88e809333ca7a 24-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Handle 64-bit load addresses for ELF64 images in the bootloader.

The ELF loader now uses a new platform function, platform_allocate_elf_region,
which returns 2 addresses: the real load address and an address where the
region is mapped in the loader's address space. All of the ELF loading code
has been changed to access the load region through the mapped address rather
than the addresses contained in the ELF image. The ELF64 version of
platform_allocate_elf_region on x86 uses the existing MMU code, which maps
everything at 0x80000000, but returns the correct 64-bit address. The long
mode switch code will just set up the 64-bit address space with everything
remapped at the correct address.


# c2656eb9bd735878c33f979c273ba59a1f96cc09 24-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Improved elf_load_image() a bit.

After enabling BOOT_SUPPORT_ELF64 on x86 the x86 kernel could no longer be
booted because too many kernel_args allocations were taking place and filling
kernel_args_ranges. This was because for each image load it would check if
the image is ELF64, fail and fall back to ELF32 (each ELF64 check allocated
a preloaded_image). Changed elf_load_image() so that it only tries both when
loading the kernel image, and then for modules it will only try the same ELF
class as the kernel image.


# ccadfaeeb577eb5f129adcc1441b92aaf9f5e443 22-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Changed the boot ELF code to use templates and added ELF64 support.

The actual implementation of the ELF loading methods have been put into
an ELFLoader template class that takes a single template parameter, which
is a structure containing all the necessary ELF typedefs. It's a bit
verbose, but I thought it was a neater solution than using a bunch of
standalone functions with a huge number of template parameters. There is
no change to code outside of elf.cpp, the ELF32/ELF64 differences are
handled internally.


# f1244978152350f9cc010e766d09c2e9ad34dfce 22-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Added an ELF64 version of preloaded_image.

* There is now 2 structures, preloaded_elf32_image and preloaded_elf64_image,
which both inherit from preloaded_image.
* For now I've just hardcoded in use of preloaded_elf32_image, but the
bootloader ELF code will shortly be converted to use templates which use
the appropriate structure. The kernel will be changed later when I add
ELF64 support to it.
* All kernel_args data is now compatible between 32-bit and 64-bit kernels.


# 9a3d05d79570eb47b00e90ccabd754ebf2be18b1 02-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Check return value of fstat() (CID 2513). Cannot really fail in the boot
loader, but the check doesn't harm either.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40066 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3069ca963efeab43764591ba5977796a3ebe9294 30-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Enable loading debug symbols again. The approach to use the driver settings
is broken.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34825 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 118fa8936e48581718ededd000252f35d8338053 15-Dec-2009 Fredrik Holmqvist <fredrik.holmqvist@gmail.com>

Make sure settings isn't null. Not my finest day apparently.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34679 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0f6b7a8cadd91c9c91ba9e003cb5a6e381da2fb3 15-Dec-2009 Fredrik Holmqvist <fredrik.holmqvist@gmail.com>

Unload driver settings as well.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34678 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d403ff624f7606c53adb941fe21f21f6f89d36b0 15-Dec-2009 Fredrik Holmqvist <fredrik.holmqvist@gmail.com>

Style fix:
* static variables should start with s.
* function blocks should start on new line.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34668 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5e972c0f3d2d525d5967f21960f7cf9ebfc6ff15 15-Dec-2009 Fredrik Holmqvist <fredrik.holmqvist@gmail.com>

Implemented TODO about not loading symbols at boot.
This saves ~0.5s of boot time here, but I suspect it might be better for CD.
Enabled loadSymbols in kernel settings so the behavior should be the same as before this change.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34666 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ea2abd110bd6a4518a954477562e2dd94a5fef9d 02-Aug-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Renamed the ROUNDOWN macro to ROUNDDOWN. Also changed the implementation of
ROUNDUP to use '*' and '/' -- the compiler will optimize that for powers of
two anyway and this implementation works for other numbers as well.
* The thread::fault_handler use in C[++] code was broken with gcc 4. At least
when other functions were invoked. Trying to trick the compiler wasn't a
particularly good idea anyway, since the next compiler version could break
the trick again. So the general policy is to use the fault handlers only in
assembly code where we have full control. Changed that for x86 (save for the
vm86 mode, which has a similar mechanism), but not for the other
architectures.
* Introduced fault_handler, fault_handler_stack_pointer, and fault_jump_buffer
fields in the cpu_ent structure, which must be used instead of
thread::fault_handler in the kernel debugger. Consequently user_memcpy() must
not be used in the kernel debugger either. Introduced a debug_memcpy()
instead.
* Introduced debug_call_with_fault_handler() function which calls a function
in a setjmp() and fault handler context. The architecture specific backend
arch_debug_call_with_fault_handler() has only been implemented for x86 yet.
* Introduced debug_is_kernel_memory_accessible() for use in the kernel
debugger. It determines whether a range of memory can be accessed in the
way specified. The architecture specific back end
arch_vm_translation_map_is_kernel_page_accessible() has only been implemented
for x86 yet.
* Added arch_debug_unset_current_thread() (only implemented for x86) to unset
the current thread pointer in the kernel debugger. When entering the kernel
debugger we do some basic sanity checks of the currently set thread structure
and unset it, if they fail. This allows certain commands (most importantly
the stack trace command) to avoid accessing the thread structure.
* x86: When handling a double fault, we do now install a special handler for
page faults. This allows us to gracefully catch faulting commands, even if
e.g. the thread structure is toast.

We are now in much better shape to deal with double faults. Hopefully avoiding
the triple faults that some people have been experiencing on their hardware
and ideally even allowing to use the kernel debugger normally.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32073 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0dc4d1e5ca08e5fe65c04f40f2628c29a9f4b5e0 26-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Reverted r27685, r27676, r27665, and r27664, the changes related to
letting the boot loader provide full paths for the pre-loaded images.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27753 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 18ee966f0a1f87ac1911c808b67f789c2b1c07b4 22-Sep-2008 Axel Dörfler <axeld@pinc-software.de>

* The boot loader now replaces the first path component of all path names
passed to the kernel with "boot" instead of the volume name; the kernel
mounts the boot volume always as "/boot".
* This should fix #2757.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27685 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b34e395eaf2875c4e87b31c8ac45ff0646920744 21-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

The boot loader does now set the names of the images it loads to the
full paths.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27665 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9a486099e85b90fc7ed82a3b53d9e6ffaa11b89a 21-Jul-2008 François Revol <revol@free.fr>

better english, tell about rela relocs.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26559 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1e5538f5e822fe87277a7288610acf08052b9b66 20-Jul-2008 François Revol <revol@free.fr>

silently skip PT_INTERP and PT_PHDR types as we can ignore them. This should make real unhandled types more obvious.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26535 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d0c63aafc22be8e5e95683ef931a15dca778343b 27-Mar-2008 Axel Dörfler <axeld@pinc-software.de>

* Fixed warnings due to the NULL change.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24608 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 957a1b17eb9d13d6dbf164145e82997e16742549 30-Dec-2005 Ingo Weinhold <ingo_weinhold@gmx.de>

* Introduced new build system variables
{HAIKU,HOST,TARGET}_KERNEL_PIC_{CC,LINK}FLAGS which define the
compiler/linker flags specifying the kind of position independence
the kernel shall have. For x86 we had and still have -fno-pic, but the
PPC kernel has -fPIE (position independent executable) now, as we
need to relocate it.
* The boot loader relocates the kernel now. Mostly copied the relocation
code from the kernel ELF loader. Almost completely rewrote the PPC
specific relocation code, though. It's more correct and more complete now
(some things are still missing though).
* Added boot platform awareness to the kernel. Moved the generic
Open Firmware code (openfirmware.c/h) from the boot loader to the kernel.
* The kernel PPC serial debug output is sent to the console for the time
being.
* The PPC boot loader counts the CPUs now and allocates the kernel stacks
(made OF device iteration a bit more flexible on the way -- the search
can be restricted to subtree). Furthermore we really enter the kernel...
(Yay! :-) ... and crash in the first dprintf() (in the atomic_set()
called by acquire_spinlock()). kprintf() works, though.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15756 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c83d9dad1c3cb1b0910f5db8c3f4645d3a206171 28-Dec-2005 Ingo Weinhold <ingo_weinhold@gmx.de>

* platform_allocate_region() has a new boolean parameter "exactAddress"
specifying whether only the exact supplied address is acceptable. If
false, the address is considered a hint only. It will be picked, if
available, otherwise a greater address is tried to be acquired, and
as last resort any address. This feature is only implemented for PPC.
It is needed since the preferred kernel text base address 0x80000000
might not be available (and actually isn't on my Mac mini).
* Fixed a bug in the PPC memory management code:
is_{virtual,physical}_allocated() were checking whether the given
range was completely contained by an existing range instead of
checking for intersection. As a consequence we could (and did) allocate
a range intersecting with already allocated ranges. The kernel segment
thus overwrote OF memory for instance.
* The ELF loader makes sure that it got both text and data segment of
the image to be loaded.

The PPC boot loader successfully loads kernel and modules now. Next
comes the hard part, I'm afraid.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15708 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e84b16339c00a23c38c7d8b5b20da2d2232068ee 14-Nov-2005 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed loading of modules whose text and data segments have a little
space inbetween. The segments can be in inverse order now, too.
The same should be done in the kernel, too.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14907 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5af32e752606778be5dd7379f319fe43cb3f6b8c 13-Apr-2005 Axel Dörfler <axeld@pinc-software.de>

Renamed src/kernel to src/system.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12359 a95241bf-73f2-0310-859d-f6bbb57e9c96