Adds chainloader.nix that can be used to build the chainloader as a 32bit elf binary. This required cross platform support for the dependencies and that libcxx was built against the right musl version, so this PR fixes that as well.
As a bonus, services can now use includeos.stdenv from the overlay and get the right build environment. includeos.libraries contains correct paths to libcxx, libcxxabi, libc, libunwind.
I've tested that the chainloader produced by nix-build ./chainloader.nix is able to boot the binary produced by nix-build ./example.nix using the command qemu-system-x86_64 -kernel ./chainloader -initrd ./hello_includeos.elf.bin -nographic.
Note that this takes a long time to build the first time as it needs to rebuild the toolchain in both 32-bit (for chainloader) and 64-bit (for example).
More specific changes:
libcxx is now recompiled against the right musl version, but without patches
a new overlay scope is created for constructing the includeos stdenv
uses gnu binutils instead of llvm to fix linking issues with chainloader
includeos.libraries attribute-set with paths to libraries can be used by services
simplify example.nix and chainloader.nix to use includeos.libraries
fixes chainloader install target
removes hardening options from musl (they are now set in stdenv)
Output from qemu-system-x86_64 -kernel ./chainloader -initrd ./hello_includeos.elf.bin -nographic:
SeaBIOS (version 1.16.3-debian-1.16.3-2)
iPXE (https://ipxe.org) 00:03.0 CA00 PCI2.10 PnP PMM+06FCAE00+06F0AE00 CA00
Booting from ROM..* Multiboot begin: 0x9500
* Multiboot cmdline @ 0x23002a: ./chainloader
* Multiboot end: 0x230039
* Module list @ 0x230000
* Module @ 0x231000
* Args: ./hello_includeos.elf.bin
* End: 0x3c9a08
* Multiboot end: 0x3c9a08
<Multiboot>Booted with multiboot
* Boot flags: 0x24f
* Valid memory (130559 Kib):
0x00000000 - 0x0009fbff (639 Kib)
0x00100000 - 0x07fdffff (129920 Kib)
* Booted with parameters @ 0x23002a: ./chainloader
* Multiboot provided memory map (7 entries @ 0x9000)
0x0000000000 - 0x000009fbff FREE (639 Kb.)
0x000009fc00 - 0x000009ffff RESERVED (1 Kb.)
0x00000f0000 - 0x00000fffff RESERVED (64 Kb.)
0x0000100000 - 0x0007fdffff FREE (129920 Kb.)
0x0007fe0000 - 0x0007ffffff RESERVED (128 Kb.)
0x00fffc0000 - 0x00ffffffff RESERVED (256 Kb.)
0x0000000000 - 0x00ffffffff RESERVED (0 Kb.)
<Multiboot>OS loaded with 1 modules
* ./hello_includeos.elf.bin @ 0x231000 - 0x3c9a08, size: 1673736b
* Multiboot begin: 0x9500
* Multiboot end: 0x331c40
[x86_64 PC] constructor
[ Machine ] Initializing heap
[ Machine ] Main memory detected as 130735936 b
[ Machine ] Reserving 1048576 b for machine use
================================================================================
#include<os> // Literally
================================================================================
[ Kernel ] Stack: 0x1ffbb8
[ Kernel ] Boot magic: 0x2badb002, addr: 0x9500
[ x86_64 ] Initializing paging
* Supported page sizes: 4.000_KiB, 2.000_MiB
* Adding 512 1GiB entries @ 0x0 -> 0x8000000000
* Identity mapping 0 -> 0, size 16.000_GiB, flags 0x83 (8192 pages á 2.000_MiB)
* Marking page 0 as not present
* Allowing execute on 0x201000 -> 0x2ce830
* Passing page tables to CPU
<Multiboot>Booted with multiboot
* Boot flags: 0x24f
* Valid memory (130559 Kib):
0x00000000 - 0x0009fbff (639 Kib)
0x00100000 - 0x07fdffff (129920 Kib)
* Booted with parameters @ 0x8000: ./hello_includeos.elf.bin
* Multiboot provided memory map (7 entries @ 0x9000)
0x0000000000 - 0x000009fbff FREE (639 Kb.)
0x000009fc00 - 0x000009ffff RESERVED (1 Kb.)
0x00000f0000 - 0x00000fffff RESERVED (64 Kb.)
0x0000100000 - 0x0007fdffff FREE (129920 Kb.)
0x0007fe0000 - 0x0007ffffff RESERVED (128 Kb.)
0x00fffc0000 - 0x00ffffffff RESERVED (256 Kb.)
0xfd00000000 - 0xffffffffff RESERVED (12582912 Kb.)
[ Kernel ] Total memory detected as 95.645_MiB
Assigning fixed memory ranges (Memory map)
* Assigning heap 0x333000 -> 0x5fa4fff
[ Kernel ] Virtual memory map
0x0000001000 - 0x0000007fff, 28.000_KiB (100.0 %) Page tables
0x0000010000 - 0x000009d3ff, 565.000_KiB (100.0 %) Stack
0x000009fc00 - 0x000009ffff, 1.000_KiB (100.0 %) Reserved (Multiboot)
0x00000f0000 - 0x00000fffff, 64.000_KiB (100.0 %) Reserved (Multiboot)
0x0000201000 - 0x00002cefff, 824.000_KiB (100.0 %) ELF .text
0x0000333000 - 0x0005fa4fff, 92.445_MiB (0.456 %) Dynamic memory
0x0007fe0000 - 0x0007ffffff, 128.000_KiB (100.0 %) Reserved (Multiboot)
0x00fffc0000 - 0x00ffffffff, 256.000_KiB (100.0 %) Reserved (Multiboot)
0xfd00000000 - 0xffffffffff, 12.000_GiB (100.0 %) Reserved (Multiboot)
[ ACPI ] Reading headers
OEM: BOCHS Rev. 0
[ ACPI ] Reading APIC information
LAPIC base: 0xfee00000 (flags: 0x1)
I/O APIC 0 ADDR 0xfec00000 INTR 0x0
IRQ redirect for bus 0 from IRQ 0 to VEC 2
IRQ redirect for bus 0 from IRQ 5 to VEC 5
IRQ redirect for bus 0 from IRQ 9 to VEC 9
IRQ redirect for bus 0 from IRQ 10 to VEC 10
IRQ redirect for bus 0 from IRQ 11 to VEC 11
[ SMP ] Found 1 APs
[ x86 ] Setting up GDT, TLS, IST
[ x86 ] Initializing CPU 0
[ I/O APIC ] Initializing ID=0
Addr: 0xfec00000 Version: 0x20 Intr: 0 Entries: 24
[ xAPIC ] Enabling xAPIC
ID: 0 Ver: 50014
[ x86 ] Enabling interrupts
[ x86 ] Setting up kernel clock sources
[ CMOS ] Enabling regular clock sync for CMOS clock
[ x86 ] CMOS clock initialized
[ CMOS ] Estimating CPU-frequency
|
+--(18 samples, 0.000100 sec. interval)
|
Enabled redirected entry 2 ioapic 0 -> 0 on apic 0
+--> 4691.649617 MHz
[ APIC ] Measuring APIC timer...
Initializing drivers
[ PCI Manager ] Probing PCI bus
|
+--[ Bridge device, Intel (0x1237) ]
+--[ Bridge device, Intel (0x7000) ]
+--[ Storage controller, Intel (0x7010) ]
+--[ Bridge device, Intel (0x7113) ]
+--[ Display controller, Unknown vendor (0x1111) ]
+--[ Network controller, Intel (0x100e) ]
o
|- Initializing Storage controller
|--[ Storage controller, Intel (0x8086:0x7010) ]
| +-x Driver not found
o
|- Initializing Network controller
|--[ Network controller, Intel, Ethernet (0x8086:0x100e) ]
| +-x Driver not found
o
[ Machine ] Listing registered devices
|
o
[ SystemLog ] Initializing System Log
Created @ 0x1fffffff0000 (63 kB)
Data @ 0x1fffffff0028 (65496 bytes)
[ Kernel ] Initializing RNG
[ Kernel ] Initializing plugins
[ Kernel ] Running service constructors
--------------------------------------------------------------------------------
================================================================================
IncludeOS VERY_DIRTY (x86_64 / 64-bit)
+--> Running [ Hello world - OS included ]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+--> WARNING: No good random source found: RDRAND/RDSEED instructions not available.
+--> FATAL: Random source check failed. Terminating.
+--> To disable this check, re-run cmake with "-DFOR_PRODUCTION=OFF".
[ Kernel ] Stopping service
[ Kernel ] Powering off
Adds
chainloader.nix
that can be used to build the chainloader as a 32bit elf binary. This required cross platform support for the dependencies and that libcxx was built against the right musl version, so this PR fixes that as well.As a bonus, services can now use
includeos.stdenv
from the overlay and get the right build environment.includeos.libraries
contains correct paths to libcxx, libcxxabi, libc, libunwind.I've tested that the chainloader produced by
nix-build ./chainloader.nix
is able to boot the binary produced bynix-build ./example.nix
using the commandqemu-system-x86_64 -kernel ./chainloader -initrd ./hello_includeos.elf.bin -nographic
.Note that this takes a long time to build the first time as it needs to rebuild the toolchain in both 32-bit (for chainloader) and 64-bit (for example).
More specific changes:
Output from
qemu-system-x86_64 -kernel ./chainloader -initrd ./hello_includeos.elf.bin -nographic
: