minimal-bootstrap.stage0-posix: replace runBareCommand with raw derivation

This commit is contained in:
Emily Trau 2023-04-25 17:09:37 +10:00
parent d0594d2f42
commit b390cba84b
4 changed files with 72 additions and 55 deletions

View file

@ -6,11 +6,6 @@
lib.makeScope newScope (self: with self; {
callPackage = self.callPackage;
runBareCommand = pname: builder: args: derivation {
inherit system builder args;
name = "${pname}-${version}";
};
inherit (callPackage ./sources.nix { }) version bootstrap-seeds-src m2-mesoplanet-src m2-planet-src m2libc mescc-tools-src mescc-tools-extra-src stage0-posix-x86-src;
hex0 = callPackage ./hex0.nix { };

View file

@ -1,6 +1,6 @@
{ runBareCommand
, system
{ system
, bootstrap-seeds-src
, version
}:
let
throwSystem = throw "Unsupported system: ${system}";
@ -11,4 +11,12 @@ let
seed = "${bootstrap-seeds-src}/POSIX/${arch}/hex0-seed";
src = "${bootstrap-seeds-src}/POSIX/${arch}/hex0_${arch}.hex0";
in
runBareCommand "hex0" seed [ src (placeholder "out") ]
derivation {
inherit system;
name = "hex0-${version}";
builder = seed;
args = [
src
(placeholder "out")
];
}

View file

@ -1,7 +1,7 @@
{ runBareCommand
, system
{ system
, bootstrap-seeds-src
, hex0
, version
}:
let
throwSystem = throw "Unsupported system: ${system}";
@ -11,4 +11,13 @@ let
src = "${bootstrap-seeds-src}/POSIX/${arch}/kaem-minimal.hex0";
in
runBareCommand "kaem-minimal" hex0 [ src (placeholder "out") ]
derivation {
inherit system;
name = "kaem-minimal-${version}";
builder = hex0;
args = [
src
(placeholder "out")
];
}

View file

@ -4,22 +4,27 @@
# Warning all binaries prior to the use of blood-elf will not be readable by
# Objdump, you may need to use ndism or gdb to view the assembly in the binary.
{ runBareCommand
, system
{ system
, hex0
, stage0-posix-x86-src
, m2libc
, m2-planet-src
, mescc-tools-src
, version
}:
rec {
out = placeholder "out";
run = pname: builder: args: derivation {
inherit system builder args;
name = "${pname}-${version}";
};
################################
# Phase-1 Build hex1 from hex0 #
################################
hex1 = runBareCommand "hex1" hex0 ["${stage0-posix-x86-src}/hex1_x86.hex0" out];
hex1 = run "hex1" hex0 ["${stage0-posix-x86-src}/hex1_x86.hex0" out];
# hex1 adds support for single character labels and is available in various forms
# in mescc-tools/x86_bootstrap to allow you various ways to verify correctness
@ -28,7 +33,7 @@ rec {
# Phase-2 Build hex2 from hex1 #
################################
hex2-0 = runBareCommand "hex2" hex1 ["${stage0-posix-x86-src}/hex2_x86.hex1" out];
hex2-0 = run "hex2" hex1 ["${stage0-posix-x86-src}/hex2_x86.hex1" out];
# hex2 adds support for long labels and absolute addresses thus allowing it
# to function as an effective linker for later stages of the bootstrap
@ -39,7 +44,7 @@ rec {
# Phase-2b Build catm from hex2 #
#################################
catm = runBareCommand "catm" hex2-0 ["${stage0-posix-x86-src}/catm_x86.hex2" out];
catm = run "catm" hex2-0 ["${stage0-posix-x86-src}/catm_x86.hex2" out];
# catm removes the need for cat or shell support for redirection by providing
# equivalent functionality via catm output_file input1 input2 ... inputN
@ -48,8 +53,8 @@ rec {
# Phase-3 Build M0 from hex2 #
##############################
M0_hex2 = runBareCommand "M0.hex2" catm [out "${stage0-posix-x86-src}/ELF-i386.hex2" "${stage0-posix-x86-src}/M0_x86.hex2"];
M0 = runBareCommand "M0" hex2-0 [M0_hex2 out];
M0_hex2 = run "M0.hex2" catm [out "${stage0-posix-x86-src}/ELF-i386.hex2" "${stage0-posix-x86-src}/M0_x86.hex2"];
M0 = run "M0" hex2-0 [M0_hex2 out];
# M0 is the architecture specific version of M1 and is by design single
# architecture only and will be replaced by the C code version of M1
@ -58,15 +63,15 @@ rec {
# Phase-4 Build cc_x86 from M0 #
################################
cc_x86-0_hex2 = runBareCommand "cc_x86-0.hex2" M0 ["${stage0-posix-x86-src}/cc_x86.M1" out];
cc_x86-1_hex2 = runBareCommand "cc_x86-1.hex2" catm [out "${stage0-posix-x86-src}/ELF-i386.hex2" cc_x86-0_hex2];
cc_x86 = runBareCommand "cc_x86" hex2-0 [cc_x86-1_hex2 out];
cc_x86-0_hex2 = run "cc_x86-0.hex2" M0 ["${stage0-posix-x86-src}/cc_x86.M1" out];
cc_x86-1_hex2 = run "cc_x86-1.hex2" catm [out "${stage0-posix-x86-src}/ELF-i386.hex2" cc_x86-0_hex2];
cc_x86 = run "cc_x86" hex2-0 [cc_x86-1_hex2 out];
#######################################
# Phase-5 Build M2-Planet from cc_x86 #
#######################################
M2-0_c = runBareCommand "M2-0.c" catm [
M2-0_c = run "M2-0.c" catm [
out
"${m2libc}/x86/linux/bootstrap.c"
"${m2-planet-src}/cc.h"
@ -79,17 +84,17 @@ rec {
"${m2-planet-src}/cc_macro.c"
"${m2-planet-src}/cc.c"
];
M2-0_M1 = runBareCommand "M2-0.M1" cc_x86 [M2-0_c out];
M2-0-0_M1 = runBareCommand "M2-0-0.M1" catm [out "${stage0-posix-x86-src}/x86_defs.M1" "${stage0-posix-x86-src}/libc-core.M1" M2-0_M1];
M2-0_hex2 = runBareCommand "M2-0.hex2" M0 [M2-0-0_M1 out];
M2-0-0_hex2 = runBareCommand "M2-0-0.hex2" catm [out "${stage0-posix-x86-src}/ELF-i386.hex2" M2-0_hex2];
M2 = runBareCommand "M2" hex2-0 [M2-0-0_hex2 out];
M2-0_M1 = run "M2-0.M1" cc_x86 [M2-0_c out];
M2-0-0_M1 = run "M2-0-0.M1" catm [out "${stage0-posix-x86-src}/x86_defs.M1" "${stage0-posix-x86-src}/libc-core.M1" M2-0_M1];
M2-0_hex2 = run "M2-0.hex2" M0 [M2-0-0_M1 out];
M2-0-0_hex2 = run "M2-0-0.hex2" catm [out "${stage0-posix-x86-src}/ELF-i386.hex2" M2-0_hex2];
M2 = run "M2" hex2-0 [M2-0-0_hex2 out];
############################################
# Phase-6 Build blood-elf-0 from C sources #
############################################
blood-elf-0_M1 = runBareCommand "blood-elf-0.M1" M2 [
blood-elf-0_M1 = run "blood-elf-0.M1" M2 [
"--architecture" "x86"
"-f" "${m2libc}/x86/linux/bootstrap.c"
"-f" "${m2libc}/bootstrappable.c"
@ -99,10 +104,10 @@ rec {
"-o" out
];
blood-elf-0-0_M1 = runBareCommand "blood-elf-0-0.M1" catm [out "${m2libc}/x86/x86_defs.M1" "${m2libc}/x86/libc-core.M1" blood-elf-0_M1];
blood-elf-0_hex2 = runBareCommand "blood-elf-0.hex2" M0 [blood-elf-0-0_M1 out];
blood-elf-0-0_hex2 = runBareCommand "blood-elf-0-0.hex2" catm [out "${m2libc}/x86/ELF-x86.hex2" blood-elf-0_hex2];
blood-elf-0 = runBareCommand "blood-elf-0" hex2-0 [blood-elf-0-0_hex2 out];
blood-elf-0-0_M1 = run "blood-elf-0-0.M1" catm [out "${m2libc}/x86/x86_defs.M1" "${m2libc}/x86/libc-core.M1" blood-elf-0_M1];
blood-elf-0_hex2 = run "blood-elf-0.hex2" M0 [blood-elf-0-0_M1 out];
blood-elf-0-0_hex2 = run "blood-elf-0-0.hex2" catm [out "${m2libc}/x86/ELF-x86.hex2" blood-elf-0_hex2];
blood-elf-0 = run "blood-elf-0" hex2-0 [blood-elf-0-0_hex2 out];
# This is the last stage where the binaries will not have debug info
# and the last piece built that isn't part of the output binaries
@ -111,7 +116,7 @@ rec {
# Phase-7 Build M1-0 from C sources #
#####################################
M1-macro-0_M1 = runBareCommand "M1-macro-0.M1" M2 [
M1-macro-0_M1 = run "M1-macro-0.M1" M2 [
"--architecture" "x86"
"-f" "${m2libc}/x86/linux/bootstrap.c"
"-f" "${m2libc}/bootstrappable.c"
@ -122,11 +127,11 @@ rec {
"-o" out
];
M1-macro-0-footer_M1 = runBareCommand "M1-macro-0-footer.M1" blood-elf-0 ["-f" M1-macro-0_M1 "--little-endian" "-o" out];
M1-macro-0-0_M1 = runBareCommand "M1-macro-0-0.M1" catm [out "${m2libc}/x86/x86_defs.M1" "${m2libc}/x86/libc-core.M1" M1-macro-0_M1 M1-macro-0-footer_M1];
M1-macro-0_hex2 = runBareCommand "M1-macro-0.hex2" M0 [M1-macro-0-0_M1 out];
M1-macro-0-0_hex2 = runBareCommand "M1-macro-0-0.hex2" catm [out "${m2libc}/x86/ELF-x86-debug.hex2" M1-macro-0_hex2];
M1-0 = runBareCommand "M1-0" hex2-0 [M1-macro-0-0_hex2 out];
M1-macro-0-footer_M1 = run "M1-macro-0-footer.M1" blood-elf-0 ["-f" M1-macro-0_M1 "--little-endian" "-o" out];
M1-macro-0-0_M1 = run "M1-macro-0-0.M1" catm [out "${m2libc}/x86/x86_defs.M1" "${m2libc}/x86/libc-core.M1" M1-macro-0_M1 M1-macro-0-footer_M1];
M1-macro-0_hex2 = run "M1-macro-0.hex2" M0 [M1-macro-0-0_M1 out];
M1-macro-0-0_hex2 = run "M1-macro-0-0.hex2" catm [out "${m2libc}/x86/ELF-x86-debug.hex2" M1-macro-0_hex2];
M1-0 = run "M1-0" hex2-0 [M1-macro-0-0_hex2 out];
# This is the last stage where catm will need to be used and the last stage where
# M0 is used, as we will being using it's much more powerful and cross-platform
@ -136,7 +141,7 @@ rec {
# Phase-8 Build hex2-1 from C sources #
#######################################
hex2_linker-0_M1 = runBareCommand "hex2_linker-0.M1" M2 [
hex2_linker-0_M1 = run "hex2_linker-0.M1" M2 [
"--architecture" "x86"
"-f" "${m2libc}/sys/types.h"
"-f" "${m2libc}/stddef.h"
@ -156,9 +161,9 @@ rec {
"-o" out
];
hex2_linker-0-footer_M1 = runBareCommand "hex2_linker-0-footer.M1" blood-elf-0 ["-f" hex2_linker-0_M1 "--little-endian" "-o" out];
hex2_linker-0-footer_M1 = run "hex2_linker-0-footer.M1" blood-elf-0 ["-f" hex2_linker-0_M1 "--little-endian" "-o" out];
hex2_linker-0_hex2 = runBareCommand "hex2_linker-0.hex2" M1-0 [
hex2_linker-0_hex2 = run "hex2_linker-0.hex2" M1-0 [
"--architecture" "x86"
"--little-endian"
"-f" "${m2libc}/x86/x86_defs.M1"
@ -168,9 +173,9 @@ rec {
"-o" out
];
hex2_linker-0-0_hex2 = runBareCommand "hex2_linker-0-0.hex2" catm [out "${m2libc}/x86/ELF-x86-debug.hex2" hex2_linker-0_hex2];
hex2_linker-0-0_hex2 = run "hex2_linker-0-0.hex2" catm [out "${m2libc}/x86/ELF-x86-debug.hex2" hex2_linker-0_hex2];
hex2-1 = runBareCommand "hex2-1" hex2-0 [hex2_linker-0-0_hex2 out];
hex2-1 = run "hex2-1" hex2-0 [hex2_linker-0-0_hex2 out];
# This is the last stage where we will be using the handwritten hex2 and instead
# be using the far more powerful, cross-platform version with a bunch more goodies
@ -179,7 +184,7 @@ rec {
# Phase-9 Build M1 from C sources #
###################################
M1-macro-1_M1 = runBareCommand "M1-macro-1.M1" M2 [
M1-macro-1_M1 = run "M1-macro-1.M1" M2 [
"--architecture" "x86"
"-f" "${m2libc}/sys/types.h"
"-f" "${m2libc}/stddef.h"
@ -197,9 +202,9 @@ rec {
"-o" out
];
M1-macro-1-footer_M1 = runBareCommand "M1-macro-1-footer.M1" blood-elf-0 ["-f" M1-macro-1_M1 "--little-endian" "-o" out];
M1-macro-1-footer_M1 = run "M1-macro-1-footer.M1" blood-elf-0 ["-f" M1-macro-1_M1 "--little-endian" "-o" out];
M1-macro-1_hex2 = runBareCommand "M1-macro-1.hex2" M1-0 [
M1-macro-1_hex2 = run "M1-macro-1.hex2" M1-0 [
"--architecture" "x86"
"--little-endian"
"-f" "${m2libc}/x86/x86_defs.M1"
@ -209,7 +214,7 @@ rec {
"-o" out
];
M1 = runBareCommand "M1" hex2-1 [
M1 = run "M1" hex2-1 [
"--architecture" "x86"
"--little-endian"
"--base-address" "0x8048000"
@ -222,7 +227,7 @@ rec {
# Phase-10 Build hex2 from C sources #
######################################
hex2_linker-2_M1 = runBareCommand "hex2_linker-2.M1" M2 [
hex2_linker-2_M1 = run "hex2_linker-2.M1" M2 [
"--architecture" "x86"
"-f" "${m2libc}/sys/types.h"
"-f" "${m2libc}/stddef.h"
@ -242,9 +247,9 @@ rec {
"-o" out
];
hex2_linker-2-footer_M1 = runBareCommand "hex2_linker-2-footer.M1" blood-elf-0 ["-f" hex2_linker-2_M1 "--little-endian" "-o" out];
hex2_linker-2-footer_M1 = run "hex2_linker-2-footer.M1" blood-elf-0 ["-f" hex2_linker-2_M1 "--little-endian" "-o" out];
hex2_linker-2_hex2 = runBareCommand "hex2_linker-2.hex2" M1 [
hex2_linker-2_hex2 = run "hex2_linker-2.hex2" M1 [
"--architecture" "x86"
"--little-endian"
"-f" "${m2libc}/x86/x86_defs.M1"
@ -254,7 +259,7 @@ rec {
"-o" out
];
hex2 = runBareCommand "hex2" hex2-1 [
hex2 = run "hex2" hex2-1 [
"--architecture" "x86"
"--little-endian"
"--base-address" "0x8048000"
@ -267,7 +272,7 @@ rec {
# Phase-11 Build kaem from C sources #
######################################
kaem_M1 = runBareCommand "kaem.M1" M2 [
kaem_M1 = run "kaem.M1" M2 [
"--architecture" "x86"
"-f" "${m2libc}/sys/types.h"
"-f" "${m2libc}/stddef.h"
@ -287,9 +292,9 @@ rec {
"-o" out
];
kaem-footer_M1 = runBareCommand "kaem-footer.M1" blood-elf-0 ["-f" kaem_M1 "--little-endian" "-o" out];
kaem-footer_M1 = run "kaem-footer.M1" blood-elf-0 ["-f" kaem_M1 "--little-endian" "-o" out];
kaem_hex2 = runBareCommand "kaem.hex2" M1 [
kaem_hex2 = run "kaem.hex2" M1 [
"--architecture" "x86"
"--little-endian"
"-f" "${m2libc}/x86/x86_defs.M1"
@ -299,7 +304,7 @@ rec {
"-o" out
];
kaem-unwrapped = runBareCommand "kaem-unwrapped" hex2 [
kaem-unwrapped = run "kaem-unwrapped" hex2 [
"--architecture" "x86"
"--little-endian"
"-f" "${m2libc}/x86/ELF-x86-debug.hex2"