Merge pull request #232329 from emilytrau/minimal-bootstrap-platforms

This commit is contained in:
Artturi 2023-09-13 06:01:25 +03:00 committed by GitHub
commit b2f31a0188
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 231 additions and 175 deletions

View file

@ -222,7 +222,6 @@ let
mkdir -p ''${out}/bin
${srcPost.bin}/bin/mes-m2 -e main ${srcPost.bin}/bin/mescc.scm -- \
--base-address 0x08048000 \
-L ''${srcPrefix}/lib \
-L ${libs}/lib \
-lc \

View file

@ -9,14 +9,6 @@ rec {
outputHashAlgo = "sha256";
outputHash = "sha256-FpMp7z+B3cR3LkQ+PooH/b1/NlxH8NHVJNWifaPWt4U=";
# This 256 byte seed is the only pre-compiled binary in the bootstrap chain.
hex0-seed = import <nix/fetchurl.nix> {
name = "hex0-seed-${version}";
url = "https://github.com/oriansj/bootstrap-seeds/raw/b1263ff14a17835f4d12539226208c426ced4fba/POSIX/x86/hex0-seed";
hash = "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8=";
executable = true;
};
/*
Since `make-minimal-bootstrap-sources` requires nixpkgs and nix it
will create a circular dependency if it is used in place of the

View file

@ -3,21 +3,23 @@
}:
lib.makeScope newScope (self: with self; {
inherit (self.callPackage ./bootstrap-sources.nix {})
version hex0-seed minimal-bootstrap-sources;
inherit (callPackage ./platforms.nix { }) platforms stage0Arch m2libcArch m2libcOS baseAddress;
inherit (self.callPackage ./bootstrap-sources.nix {}) version minimal-bootstrap-sources;
src = minimal-bootstrap-sources;
m2libc = src + "/M2libc";
hex0 = callPackage ./hex0.nix { };
inherit (self.hex0) hex0-seed;
kaem = callPackage ./kaem { };
kaem-minimal = callPackage ./kaem/minimal.nix { };
stage0-posix-x86 = callPackage ./stage0-posix-x86.nix { };
mescc-tools-boot = callPackage ./mescc-tools-boot.nix { };
inherit (self.stage0-posix-x86) blood-elf-0 hex2 kaem-unwrapped M1 M2;
inherit (self.mescc-tools-boot) blood-elf-0 hex2 kaem-unwrapped M1 M2;
mescc-tools = callPackage ./mescc-tools { };

View file

@ -1,15 +1,33 @@
{ lib
, derivationWithMeta
, hex0-seed
, hostPlatform
, src
, version
, platforms
, stage0Arch
}:
let
hash = {
"x86" = "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8=";
"AMD64" = "sha256-RCgK9oZRDQUiWLVkcIBSR2HeoB+Bh0czthrpjFEkCaY=";
}.${stage0Arch} or (throw "Unsupported system: ${hostPlatform.system}");
# Pinned from https://github.com/oriansj/stage0-posix/commit/3189b5f325b7ef8b88e3edec7c1cde4fce73c76c
# This 256 byte seed is the only pre-compiled binary in the bootstrap chain.
hex0-seed = import <nix/fetchurl.nix> {
name = "hex0-seed";
url = "https://github.com/oriansj/bootstrap-seeds/raw/b1263ff14a17835f4d12539226208c426ced4fba/POSIX/${stage0Arch}/hex0-seed";
executable = true;
inherit hash;
};
in
derivationWithMeta {
inherit version;
pname = "hex0";
builder = hex0-seed;
args = [
"${src}/x86/hex0_x86.hex0"
"${src}/${stage0Arch}/hex0_${stage0Arch}.hex0"
(placeholder "out")
];
@ -18,11 +36,13 @@ derivationWithMeta {
homepage = "https://github.com/oriansj/stage0-posix";
license = licenses.gpl3Plus;
maintainers = teams.minimal-bootstrap.members;
platforms = [ "i686-linux" ];
inherit platforms;
};
passthru = { inherit hex0-seed; };
# Ensure the untrusted hex0-seed binary produces a known-good hex0
outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8=";
outputHash = hash;
}

View file

@ -6,6 +6,7 @@
, mescc-tools
, mescc-tools-extra
, version
, platforms
}:
# Once mescc-tools-extra is available we can install kaem at /bin/kaem
@ -46,6 +47,6 @@ derivationWithMeta {
homepage = "https://github.com/oriansj/mescc-tools";
license = licenses.gpl3Plus;
maintainers = teams.minimal-bootstrap.members;
platforms = [ "i686-linux" ];
inherit platforms;
};
}

View file

@ -3,13 +3,15 @@
, src
, hex0
, version
, platforms
, stage0Arch
}:
derivationWithMeta {
inherit version;
pname = "kaem-minimal";
builder = hex0;
args = [
"${src}/x86/kaem-minimal.hex0"
"${src}/${stage0Arch}/kaem-minimal.hex0"
(placeholder "out")
];
@ -18,7 +20,7 @@ derivationWithMeta {
homepage = "https://github.com/oriansj/stage0-posix";
license = licenses.gpl3Plus;
maintainers = teams.minimal-bootstrap.members;
platforms = [ "i686-linux" ];
inherit platforms;
};
}

View file

@ -1,10 +1,3 @@
# This is a translation of stage0-posix/stage0-posix/x86/mescc-tools-mini-kaem.kaem to nix
# https://github.com/oriansj/stage0-posix-x86/blob/56e6b8df3e95f4bc04f8b420a4cd8c82c70b9efa/mescc-tools-mini-kaem.kaem
#
# We have access to mini-kaem at this point but it doesn't support substituting
# environment variables. Without variables there's no way of passing in store inputs,
# or the $out path, other than as command line arguments directly
# Mes --- Maxwell Equations of Software
# Copyright © 2017,2019 Jan Nieuwenhuizen <janneke@gnu.org>
# Copyright © 2017,2019 Jeremiah Orians
@ -24,19 +17,35 @@
# You should have received a copy of the GNU General Public License
# along with Mes. If not, see <http://www.gnu.org/licenses/>.
# This is a translation of stage0-posix/stage0-posix/x86/mescc-tools-mini-kaem.kaem to nix
# https://github.com/oriansj/stage0-posix-x86/blob/56e6b8df3e95f4bc04f8b420a4cd8c82c70b9efa/mescc-tools-mini-kaem.kaem
#
# We have access to mini-kaem at this point but it doesn't support substituting
# environment variables. Without variables there's no way of passing in store inputs,
# or the $out path, other than as command line arguments directly
# 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.
{ lib
, derivationWithMeta
, hostPlatform
, hex0
, m2libc
, src
, version
, platforms
, stage0Arch
, m2libcArch
, baseAddress
}:
rec {
out = placeholder "out";
endianFlag = if hostPlatform.isLittleEndian then "--little-endian" else "--big-endian";
bloodFlags = lib.optional hostPlatform.is64bit "--64";
run = pname: builder: args:
derivationWithMeta {
inherit pname version builder args;
@ -46,7 +55,7 @@ rec {
homepage = "https://github.com/oriansj/stage0-posix";
license = licenses.gpl3Plus;
maintainers = teams.minimal-bootstrap.members;
platforms = [ "i686-linux" ];
inherit platforms;
};
};
@ -54,7 +63,7 @@ rec {
# Phase-1 Build hex1 from hex0 #
################################
hex1 = run "hex1" hex0 ["${src}/x86/hex1_x86.hex0" out];
hex1 = run "hex1" hex0 ["${src}/${stage0Arch}/hex1_${stage0Arch}.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
@ -63,7 +72,7 @@ rec {
# Phase-2 Build hex2 from hex1 #
################################
hex2-0 = run "hex2" hex1 ["${src}/x86/hex2_x86.hex1" out];
hex2-0 = run "hex2" hex1 ["${src}/${stage0Arch}/hex2_${stage0Arch}.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
@ -74,7 +83,7 @@ rec {
# Phase-2b Build catm from hex2 #
#################################
catm = run "catm" hex2-0 ["${src}/x86/catm_x86.hex2" out];
catm = run "catm" hex2-0 ["${src}/${stage0Arch}/catm_${stage0Arch}.hex2" out];
# catm removes the need for cat or shell support for redirection by providing
# equivalent functionality via catm output_file input1 input2 ... inputN
@ -83,27 +92,27 @@ rec {
# Phase-3 Build M0 from hex2 #
##############################
M0_hex2 = run "M0.hex2" catm [out "${src}/x86/ELF-i386.hex2" "${src}/x86/M0_x86.hex2"];
M0_hex2 = run "M0.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}.hex2" "${src}/${stage0Arch}/M0_${stage0Arch}.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
################################
# Phase-4 Build cc_x86 from M0 #
# Phase-4 Build cc_arch from M0 #
################################
cc_x86-0_hex2 = run "cc_x86-0.hex2" M0 ["${src}/x86/cc_x86.M1" out];
cc_x86-1_hex2 = run "cc_x86-1.hex2" catm [out "${src}/x86/ELF-i386.hex2" cc_x86-0_hex2];
cc_x86 = run "cc_x86" hex2-0 [cc_x86-1_hex2 out];
cc_arch-0_hex2 = run "cc_arch-0.hex2" M0 ["${src}/${stage0Arch}/cc_${m2libcArch}.M1" out];
cc_arch-1_hex2 = run "cc_arch-1.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}.hex2" cc_arch-0_hex2];
cc_arch = run "cc_arch" hex2-0 [cc_arch-1_hex2 out];
#######################################
# Phase-5 Build M2-Planet from cc_x86 #
#######################################
########################################
# Phase-5 Build M2-Planet from cc_arch #
########################################
M2-0_c = run "M2-0.c" catm [
out
"${m2libc}/x86/linux/bootstrap.c"
"${m2libc}/${m2libcArch}/linux/bootstrap.c"
"${src}/M2-Planet/cc.h"
"${m2libc}/bootstrappable.c"
"${src}/M2-Planet/cc_globals.c"
@ -114,10 +123,10 @@ rec {
"${src}/M2-Planet/cc_macro.c"
"${src}/M2-Planet/cc.c"
];
M2-0_M1 = run "M2-0.M1" cc_x86 [M2-0_c out];
M2-0-0_M1 = run "M2-0-0.M1" catm [out "${src}/x86/x86_defs.M1" "${src}/x86/libc-core.M1" M2-0_M1];
M2-0_M1 = run "M2-0.M1" cc_arch [M2-0_c out];
M2-0-0_M1 = run "M2-0-0.M1" catm [out "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1" "${m2libc}/${m2libcArch}/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 "${src}/x86/ELF-i386.hex2" M2-0_hex2];
M2-0-0_hex2 = run "M2-0-0.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}.hex2" M2-0_hex2];
M2 = run "M2" hex2-0 [M2-0-0_hex2 out];
############################################
@ -125,8 +134,8 @@ rec {
############################################
blood-elf-0_M1 = run "blood-elf-0.M1" M2 [
"--architecture" "x86"
"-f" "${m2libc}/x86/linux/bootstrap.c"
"--architecture" m2libcArch
"-f" "${m2libc}/${m2libcArch}/linux/bootstrap.c"
"-f" "${m2libc}/bootstrappable.c"
"-f" "${src}/mescc-tools/stringify.c"
"-f" "${src}/mescc-tools/blood-elf.c"
@ -134,9 +143,9 @@ rec {
"-o" 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-0_M1 = run "blood-elf-0-0.M1" catm [out "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1" "${m2libc}/${m2libcArch}/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-0_hex2 = run "blood-elf-0-0.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}.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
@ -147,8 +156,8 @@ rec {
#####################################
M1-macro-0_M1 = run "M1-macro-0.M1" M2 [
"--architecture" "x86"
"-f" "${m2libc}/x86/linux/bootstrap.c"
"--architecture" m2libcArch
"-f" "${m2libc}/${m2libcArch}/linux/bootstrap.c"
"-f" "${m2libc}/bootstrappable.c"
"-f" "${src}/mescc-tools/stringify.c"
"-f" "${src}/mescc-tools/M1-macro.c"
@ -157,10 +166,10 @@ rec {
"-o" 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-footer_M1 = run "M1-macro-0-footer.M1" blood-elf-0 (bloodFlags ++ ["-f" M1-macro-0_M1 endianFlag "-o" out]);
M1-macro-0-0_M1 = run "M1-macro-0-0.M1" catm [out "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1" "${m2libc}/${m2libcArch}/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-macro-0-0_hex2 = run "M1-macro-0-0.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}-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
@ -172,13 +181,13 @@ rec {
#######################################
hex2_linker-0_M1 = run "hex2_linker-0.M1" M2 [
"--architecture" "x86"
"--architecture" m2libcArch
"-f" "${m2libc}/sys/types.h"
"-f" "${m2libc}/stddef.h"
"-f" "${m2libc}/x86/linux/unistd.c"
"-f" "${m2libc}/x86/linux/fcntl.c"
"-f" "${m2libc}/${m2libcArch}/linux/unistd.c"
"-f" "${m2libc}/${m2libcArch}/linux/fcntl.c"
"-f" "${m2libc}/fcntl.c"
"-f" "${m2libc}/x86/linux/sys/stat.c"
"-f" "${m2libc}/${m2libcArch}/linux/sys/stat.c"
"-f" "${m2libc}/stdlib.c"
"-f" "${m2libc}/stdio.h"
"-f" "${m2libc}/stdio.c"
@ -191,19 +200,19 @@ rec {
"-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-footer_M1 = run "hex2_linker-0-footer.M1" blood-elf-0 (bloodFlags ++ ["-f" hex2_linker-0_M1 endianFlag "-o" out]);
hex2_linker-0_hex2 = run "hex2_linker-0.hex2" M1-0 [
"--architecture" "x86"
"--little-endian"
"-f" "${m2libc}/x86/x86_defs.M1"
"-f" "${m2libc}/x86/libc-full.M1"
"--architecture" m2libcArch
endianFlag
"-f" "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1"
"-f" "${m2libc}/${m2libcArch}/libc-full.M1"
"-f" hex2_linker-0_M1
"-f" hex2_linker-0-footer_M1
"-o" out
];
hex2_linker-0-0_hex2 = run "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}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2" hex2_linker-0_hex2];
hex2-1 = run "hex2-1" hex2-0 [hex2_linker-0-0_hex2 out];
@ -215,12 +224,12 @@ rec {
###################################
M1-macro-1_M1 = run "M1-macro-1.M1" M2 [
"--architecture" "x86"
"--architecture" m2libcArch
"-f" "${m2libc}/sys/types.h"
"-f" "${m2libc}/stddef.h"
"-f" "${m2libc}/x86/linux/fcntl.c"
"-f" "${m2libc}/${m2libcArch}/linux/fcntl.c"
"-f" "${m2libc}/fcntl.c"
"-f" "${m2libc}/x86/linux/unistd.c"
"-f" "${m2libc}/${m2libcArch}/linux/unistd.c"
"-f" "${m2libc}/string.c"
"-f" "${m2libc}/stdlib.c"
"-f" "${m2libc}/stdio.h"
@ -232,23 +241,23 @@ rec {
"-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-footer_M1 = run "M1-macro-1-footer.M1" blood-elf-0 (bloodFlags ++ ["-f" M1-macro-1_M1 endianFlag "-o" out]);
M1-macro-1_hex2 = run "M1-macro-1.hex2" M1-0 [
"--architecture" "x86"
"--little-endian"
"-f" "${m2libc}/x86/x86_defs.M1"
"-f" "${m2libc}/x86/libc-full.M1"
"--architecture" m2libcArch
endianFlag
"-f" "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1"
"-f" "${m2libc}/${m2libcArch}/libc-full.M1"
"-f" M1-macro-1_M1
"-f" M1-macro-1-footer_M1
"-o" out
];
M1 = run "M1" hex2-1 [
"--architecture" "x86"
"--little-endian"
"--base-address" "0x8048000"
"-f" "${m2libc}/x86/ELF-x86-debug.hex2"
"--architecture" m2libcArch
endianFlag
"--base-address" baseAddress
"-f" "${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2"
"-f" M1-macro-1_hex2
"-o" out
];
@ -258,13 +267,13 @@ rec {
######################################
hex2_linker-2_M1 = run "hex2_linker-2.M1" M2 [
"--architecture" "x86"
"--architecture" m2libcArch
"-f" "${m2libc}/sys/types.h"
"-f" "${m2libc}/stddef.h"
"-f" "${m2libc}/x86/linux/unistd.c"
"-f" "${m2libc}/x86/linux/fcntl.c"
"-f" "${m2libc}/${m2libcArch}/linux/unistd.c"
"-f" "${m2libc}/${m2libcArch}/linux/fcntl.c"
"-f" "${m2libc}/fcntl.c"
"-f" "${m2libc}/x86/linux/sys/stat.c"
"-f" "${m2libc}/${m2libcArch}/linux/sys/stat.c"
"-f" "${m2libc}/stdlib.c"
"-f" "${m2libc}/stdio.h"
"-f" "${m2libc}/stdio.c"
@ -277,23 +286,23 @@ rec {
"-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-footer_M1 = run "hex2_linker-2-footer.M1" blood-elf-0 (bloodFlags ++ ["-f" hex2_linker-2_M1 endianFlag "-o" out]);
hex2_linker-2_hex2 = run "hex2_linker-2.hex2" M1 [
"--architecture" "x86"
"--little-endian"
"-f" "${m2libc}/x86/x86_defs.M1"
"-f" "${m2libc}/x86/libc-full.M1"
"--architecture" m2libcArch
endianFlag
"-f" "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1"
"-f" "${m2libc}/${m2libcArch}/libc-full.M1"
"-f" hex2_linker-2_M1
"-f" hex2_linker-2-footer_M1
"-o" out
];
hex2 = run "hex2" hex2-1 [
"--architecture" "x86"
"--little-endian"
"--base-address" "0x8048000"
"-f" "${m2libc}/x86/ELF-x86-debug.hex2"
"--architecture" m2libcArch
endianFlag
"--base-address" baseAddress
"-f" "${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2"
"-f" hex2_linker-2_hex2
"-o" out
];
@ -303,12 +312,12 @@ rec {
######################################
kaem_M1 = run "kaem.M1" M2 [
"--architecture" "x86"
"--architecture" m2libcArch
"-f" "${m2libc}/sys/types.h"
"-f" "${m2libc}/stddef.h"
"-f" "${m2libc}/string.c"
"-f" "${m2libc}/x86/linux/unistd.c"
"-f" "${m2libc}/x86/linux/fcntl.c"
"-f" "${m2libc}/${m2libcArch}/linux/unistd.c"
"-f" "${m2libc}/${m2libcArch}/linux/fcntl.c"
"-f" "${m2libc}/fcntl.c"
"-f" "${m2libc}/stdlib.c"
"-f" "${m2libc}/stdio.h"
@ -322,24 +331,24 @@ rec {
"-o" out
];
kaem-footer_M1 = run "kaem-footer.M1" blood-elf-0 ["-f" kaem_M1 "--little-endian" "-o" out];
kaem-footer_M1 = run "kaem-footer.M1" blood-elf-0 (bloodFlags ++ ["-f" kaem_M1 endianFlag "-o" out]);
kaem_hex2 = run "kaem.hex2" M1 [
"--architecture" "x86"
"--little-endian"
"-f" "${m2libc}/x86/x86_defs.M1"
"-f" "${m2libc}/x86/libc-full.M1"
"--architecture" m2libcArch
endianFlag
"-f" "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1"
"-f" "${m2libc}/${m2libcArch}/libc-full.M1"
"-f" kaem_M1
"-f" kaem-footer_M1
"-o" out
];
kaem-unwrapped = run "kaem-unwrapped" hex2 [
"--architecture" "x86"
"--little-endian"
"-f" "${m2libc}/x86/ELF-x86-debug.hex2"
"--architecture" m2libcArch
endianFlag
"-f" "${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2"
"-f" kaem_hex2
"--base-address" "0x8048000"
"--base-address" baseAddress
"-o" out
];
}

View file

@ -19,7 +19,7 @@
## You should have received a copy of the GNU General Public License
## along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
alias CC="${mescc-tools}/bin/M2-Mesoplanet --operating-system ${OPERATING_SYSTEM} --architecture ${ARCH} -f"
alias CC="${mescc-tools}/bin/M2-Mesoplanet --operating-system ${m2libcOS} --architecture ${m2libcArch} -f"
cd ${src}/mescc-tools-extra
# Create output folder

View file

@ -4,9 +4,12 @@
, mescc-tools
, src
, version
, platforms
, m2libcArch
, m2libcOS
}:
derivationWithMeta {
inherit version src mescc-tools;
inherit version src mescc-tools m2libcArch m2libcOS;
pname = "mescc-tools-extra";
builder = kaem-unwrapped;
args = [
@ -16,14 +19,11 @@ derivationWithMeta {
./build.kaem
];
ARCH = "x86";
OPERATING_SYSTEM = "linux";
meta = with lib; {
description = "Collection of tools written for use in bootstrapping";
homepage = "https://github.com/oriansj/mescc-tools-extra";
license = licenses.gpl3Plus;
maintainers = teams.minimal-bootstrap.members;
platforms = [ "i686-linux" ];
inherit platforms;
};
}

View file

@ -46,13 +46,13 @@ ${replace} \
# Phase-12 Build M2-Mesoplanet from M2-Planet #
###############################################
${M2} --architecture ${ARCH} \
${M2} --architecture ${m2libcArch} \
-f ${m2libc}/sys/types.h \
-f ${m2libc}/stddef.h \
-f ${m2libc}/${ARCH}/linux/fcntl.c \
-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
-f ${m2libc}/fcntl.c \
-f ${m2libc}/${ARCH}/linux/unistd.c \
-f ${m2libc}/${ARCH}/linux/sys/stat.c \
-f ${m2libc}/${m2libcArch}/linux/unistd.c \
-f ${m2libc}/${m2libcArch}/linux/sys/stat.c \
-f ${m2libc}/stdlib.c \
-f ${m2libc}/stdio.h \
-f ${m2libc}/stdio.c \
@ -69,20 +69,20 @@ ${M2} --architecture ${ARCH} \
--debug \
-o ./M2-Mesoplanet-1.M1
${blood-elf-0} ${ENDIAN_FLAG} ${BLOOD_FLAG} -f ./M2-Mesoplanet-1.M1 -o ./M2-Mesoplanet-1-footer.M1
${blood-elf-0} ${endianFlag} ${bloodFlag} -f ./M2-Mesoplanet-1.M1 -o ./M2-Mesoplanet-1-footer.M1
${M1} --architecture ${ARCH} \
${ENDIAN_FLAG} \
-f ${m2libc}/${ARCH}/${ARCH}_defs.M1 \
-f ${m2libc}/${ARCH}/libc-full.M1 \
${M1} --architecture ${m2libcArch} \
${endianFlag} \
-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
-f ${m2libc}/${m2libcArch}/libc-full.M1 \
-f ./M2-Mesoplanet-1.M1 \
-f ./M2-Mesoplanet-1-footer.M1 \
-o ./M2-Mesoplanet-1.hex2
${hex2} --architecture ${ARCH} \
${ENDIAN_FLAG} \
--base-address ${BASE_ADDRESS} \
-f ${m2libc}/${ARCH}/ELF-${ARCH}-debug.hex2 \
${hex2} --architecture ${m2libcArch} \
${endianFlag} \
--base-address ${baseAddress} \
-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
-f ./M2-Mesoplanet-1.hex2 \
-o ${out}/bin/M2-Mesoplanet
@ -90,12 +90,12 @@ ${hex2} --architecture ${ARCH} \
# Phase-13 Build final blood-elf from C sources #
#################################################
${M2} --architecture ${ARCH} \
${M2} --architecture ${m2libcArch} \
-f ${m2libc}/sys/types.h \
-f ${m2libc}/stddef.h \
-f ${m2libc}/${ARCH}/linux/fcntl.c \
-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
-f ${m2libc}/fcntl.c \
-f ${m2libc}/${ARCH}/linux/unistd.c \
-f ${m2libc}/${m2libcArch}/linux/unistd.c \
-f ${m2libc}/stdlib.c \
-f ${m2libc}/stdio.h \
-f ${m2libc}/stdio.c \
@ -105,19 +105,20 @@ ${M2} --architecture ${ARCH} \
--debug \
-o ./blood-elf-1.M1
${blood-elf-0} ${BLOOD_FLAG} ${ENDIAN_FLAG} -f ./blood-elf-1.M1 -o ./blood-elf-1-footer.M1
${M1} --architecture ${ARCH} \
${ENDIAN_FLAG} \
-f ${m2libc}/${ARCH}/${ARCH}_defs.M1 \
-f ${m2libc}/${ARCH}/libc-full.M1 \
${blood-elf-0} ${endianFlag} ${bloodFlag} -f ./blood-elf-1.M1 -o ./blood-elf-1-footer.M1
${M1} --architecture ${m2libcArch} \
${endianFlag} \
-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
-f ${m2libc}/${m2libcArch}/libc-full.M1 \
-f ./blood-elf-1.M1 \
-f ./blood-elf-1-footer.M1 \
-o ./blood-elf-1.hex2
${hex2} --architecture ${ARCH} \
${ENDIAN_FLAG} \
--base-address ${BASE_ADDRESS} \
-f ${m2libc}/${ARCH}/ELF-${ARCH}-debug.hex2 \
${hex2} --architecture ${m2libcArch} \
${endianFlag} \
--base-address ${baseAddress} \
-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
-f ./blood-elf-1.hex2 \
-o ${out}/bin/blood-elf
@ -129,11 +130,11 @@ ${hex2} --architecture ${ARCH} \
# Phase-14 Build get_machine from C sources #
#############################################
${M2} --architecture ${ARCH} \
${M2} --architecture ${m2libcArch} \
-f ${m2libc}/sys/types.h \
-f ${m2libc}/stddef.h \
-f ${m2libc}/${ARCH}/linux/unistd.c \
-f ${m2libc}/${ARCH}/linux/fcntl.c \
-f ${m2libc}/${m2libcArch}/linux/unistd.c \
-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
-f ${m2libc}/fcntl.c \
-f ${m2libc}/stdlib.c \
-f ${m2libc}/stdio.h \
@ -143,20 +144,20 @@ ${M2} --architecture ${ARCH} \
--debug \
-o get_machine.M1
${out}/bin/blood-elf ${BLOOD_FLAG} ${ENDIAN_FLAG} -f ./get_machine.M1 -o ./get_machine-footer.M1
${out}/bin/blood-elf ${endianFlag} ${bloodFlag} -f ./get_machine.M1 -o ./get_machine-footer.M1
${M1} --architecture ${ARCH} \
${ENDIAN_FLAG} \
-f ${m2libc}/${ARCH}/${ARCH}_defs.M1 \
-f ${m2libc}/${ARCH}/libc-full.M1 \
${M1} --architecture ${m2libcArch} \
${endianFlag} \
-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
-f ${m2libc}/${m2libcArch}/libc-full.M1 \
-f ./get_machine.M1 \
-f ./get_machine-footer.M1 \
-o ./get_machine.hex2
${hex2} --architecture ${ARCH} \
${ENDIAN_FLAG} \
--base-address ${BASE_ADDRESS} \
-f ${m2libc}/${ARCH}/ELF-${ARCH}-debug.hex2 \
${hex2} --architecture ${m2libcArch} \
${endianFlag} \
--base-address ${baseAddress} \
-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
-f ./get_machine.hex2 \
-o ${out}/bin/get_machine
@ -164,11 +165,11 @@ ${hex2} --architecture ${ARCH} \
# Phase-15 Build M2-Planet from M2-Planet #
############################################
${M2} --architecture ${ARCH} \
${M2} --architecture ${m2libcArch} \
-f ${m2libc}/sys/types.h \
-f ${m2libc}/stddef.h \
-f ${m2libc}/${ARCH}/linux/unistd.c \
-f ${m2libc}/${ARCH}/linux/fcntl.c \
-f ${m2libc}/${m2libcArch}/linux/unistd.c \
-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
-f ${m2libc}/fcntl.c \
-f ${m2libc}/stdlib.c \
-f ${m2libc}/stdio.h \
@ -185,20 +186,19 @@ ${M2} --architecture ${ARCH} \
--debug \
-o ./M2-1.M1
${out}/bin/blood-elf ${ENDIAN_FLAG} ${BLOOD_FLAG} -f ./M2-1.M1 -o ./M2-1-footer.M1
${out}/bin/blood-elf ${endianFlag} ${bloodFlag} -f ./M2-1.M1 -o ./M2-1-footer.M1
${M1} --architecture ${ARCH} \
${ENDIAN_FLAG} \
-f ${m2libc}/${ARCH}/${ARCH}_defs.M1 \
-f ${m2libc}/${ARCH}/libc-full.M1 \
${M1} --architecture ${m2libcArch} \
${endianFlag} \
-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
-f ${m2libc}/${m2libcArch}/libc-full.M1 \
-f ./M2-1.M1 \
-f ./M2-1-footer.M1 \
-o ./M2-1.hex2
${hex2} --architecture ${ARCH} \
${ENDIAN_FLAG} \
--base-address ${BASE_ADDRESS} \
-f ${m2libc}/${ARCH}/ELF-${ARCH}-debug.hex2 \
${hex2} --architecture ${m2libcArch} \
${endianFlag} \
--base-address ${baseAddress} \
-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
-f ./M2-1.hex2 \
-o ${out}/bin/M2-Planet

View file

@ -1,5 +1,6 @@
{ lib
, derivationWithMeta
, hostPlatform
, kaem-unwrapped
, M1
, M2
@ -8,13 +9,14 @@
, m2libc
, src
, version
, platforms
, m2libcArch
, baseAddress
}:
let
ARCH = "x86";
BLOOD_FLAG = " ";
BASE_ADDRESS = "0x8048000";
ENDIAN_FLAG = "--little-endian";
endianFlag = if hostPlatform.isLittleEndian then "--little-endian" else "--big-endian";
bloodFlag = if hostPlatform.is64bit then "--64" else " ";
# We need a few tools from mescc-tools-extra to assemble the output folder
buildMesccToolsExtraUtil = name:
@ -26,13 +28,13 @@ let
"--strict"
"--file"
(builtins.toFile "build-${name}.kaem" ''
''${M2} --architecture ''${ARCH} \
''${M2} --architecture ${m2libcArch} \
-f ''${m2libc}/sys/types.h \
-f ''${m2libc}/stddef.h \
-f ''${m2libc}/''${ARCH}/linux/fcntl.c \
-f ''${m2libc}/${m2libcArch}/linux/fcntl.c \
-f ''${m2libc}/fcntl.c \
-f ''${m2libc}/''${ARCH}/linux/unistd.c \
-f ''${m2libc}/''${ARCH}/linux/sys/stat.c \
-f ''${m2libc}/${m2libcArch}/linux/unistd.c \
-f ''${m2libc}/${m2libcArch}/linux/sys/stat.c \
-f ''${m2libc}/stdlib.c \
-f ''${m2libc}/stdio.h \
-f ''${m2libc}/stdio.c \
@ -42,25 +44,25 @@ let
--debug \
-o ${name}.M1
''${blood-elf-0} ''${ENDIAN_FLAG} -f ${name}.M1 -o ${name}-footer.M1
''${blood-elf-0} ${endianFlag} ${bloodFlag} -f ${name}.M1 -o ${name}-footer.M1
''${M1} --architecture ''${ARCH} \
''${ENDIAN_FLAG} \
-f ''${m2libc}/''${ARCH}/''${ARCH}_defs.M1 \
-f ''${m2libc}/''${ARCH}/libc-full.M1 \
''${M1} --architecture ${m2libcArch} \
${endianFlag} \
-f ''${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
-f ''${m2libc}/${m2libcArch}/libc-full.M1 \
-f ${name}.M1 \
-f ${name}-footer.M1 \
-o ${name}.hex2
''${hex2} --architecture ''${ARCH} \
''${ENDIAN_FLAG} \
-f ''${m2libc}/''${ARCH}/ELF-''${ARCH}-debug.hex2 \
''${hex2} --architecture ${m2libcArch} \
${endianFlag} \
-f ''${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
-f ${name}.hex2 \
--base-address ''${BASE_ADDRESS} \
--base-address ${baseAddress} \
-o ''${out}
'')
];
inherit version M1 M2 blood-elf-0 hex2 m2libc src ARCH BLOOD_FLAG BASE_ADDRESS ENDIAN_FLAG;
inherit version M1 M2 blood-elf-0 hex2 m2libc src;
};
mkdir = buildMesccToolsExtraUtil "mkdir";
cp = buildMesccToolsExtraUtil "cp";
@ -76,13 +78,13 @@ derivationWithMeta {
"--file"
./build.kaem
];
inherit version M1 M2 blood-elf-0 hex2 mkdir cp chmod replace m2libc src ARCH BLOOD_FLAG BASE_ADDRESS ENDIAN_FLAG;
inherit version M1 M2 blood-elf-0 hex2 mkdir cp chmod replace m2libc src m2libcArch baseAddress bloodFlag endianFlag;
meta = with lib; {
description = "Collection of tools written for use in bootstrapping";
homepage = "https://github.com/oriansj/mescc-tools";
license = licenses.gpl3Plus;
maintainers = teams.minimal-bootstrap.members;
platforms = [ "i686-linux" ];
inherit platforms;
};
}

View file

@ -0,0 +1,29 @@
# Platform specific constants
{ lib
, hostPlatform
}:
rec {
# meta.platforms
platforms = [
"i686-linux"
"x86_64-linux"
];
# system arch as used within the stage0 project
stage0Arch = {
"i686-linux" = "x86";
"x86_64-linux" = "AMD64";
}.${hostPlatform.system} or (throw "Unsupported system: ${hostPlatform.system}");
# lower-case form is widely used by m2libc
m2libcArch = lib.toLower stage0Arch;
# Passed to M2-Mesoplanet as --operating-system
m2libcOS = if hostPlatform.isLinux then "linux" else throw "Unsupported system: ${hostPlatform.system}";
baseAddress = {
"i686-linux" = "0x08048000";
"x86_64-linux" = "0x00600000";
}.${hostPlatform.system} or (throw "Unsupported system: ${hostPlatform.system}");
}