trusting-trust.stage0-posix: init at unstable-2023-04-16
This commit is contained in:
parent
95dc6a031b
commit
1b8e690824
14
pkgs/os-specific/linux/trusting-trust/default.nix
Normal file
14
pkgs/os-specific/linux/trusting-trust/default.nix
Normal file
|
@ -0,0 +1,14 @@
|
|||
{ lib
|
||||
, newScope
|
||||
, system
|
||||
}:
|
||||
|
||||
lib.makeScope newScope (self: with self; {
|
||||
callPackage = self.callPackage;
|
||||
|
||||
fetchurl = import ../../../build-support/fetchurl/boot.nix {
|
||||
inherit system;
|
||||
};
|
||||
|
||||
inherit (callPackage ./stage0-posix { }) kaem mkKaemDerivation m2libc mescc-tools mescc-tools-extra writeTextFile writeText;
|
||||
})
|
|
@ -0,0 +1,62 @@
|
|||
{ lib
|
||||
, system
|
||||
, newScope
|
||||
}:
|
||||
|
||||
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 { };
|
||||
|
||||
kaem-minimal = callPackage ./kaem-minimal.nix { };
|
||||
|
||||
inherit (callPackage ./stage0-posix-x86.nix { }) blood-elf-0 hex2 kaem-unwrapped M1 M2;
|
||||
|
||||
mkKaemDerivation0 = args@{
|
||||
name,
|
||||
script,
|
||||
...
|
||||
}:
|
||||
derivation ({
|
||||
inherit system name;
|
||||
builder = kaem-unwrapped;
|
||||
args = [
|
||||
"--verbose"
|
||||
"--strict"
|
||||
"--file"
|
||||
script
|
||||
];
|
||||
|
||||
ARCH = "x86";
|
||||
OPERATING_SYSTEM = "linux";
|
||||
BLOOD_FLAG = " ";
|
||||
BASE_ADDRESS = "0x8048000";
|
||||
ENDIAN_FLAG = "--little-endian";
|
||||
} // (builtins.removeAttrs args [ "name" "script" ]));
|
||||
|
||||
mescc-tools = callPackage ./mescc-tools { };
|
||||
|
||||
mescc-tools-extra = callPackage ./mescc-tools-extra { };
|
||||
|
||||
inherit (callPackage ./utils.nix { }) writeTextFile writeText mkKaemDerivation;
|
||||
|
||||
# Now that mescc-tools-extra is available we can install kaem at /bin/kaem
|
||||
# to make it findable in environments
|
||||
kaem = mkKaemDerivation0 {
|
||||
name = "kaem-${version}";
|
||||
script = builtins.toFile "kaem-wrapper.kaem" ''
|
||||
mkdir -p ''${out}/bin
|
||||
cp ''${kaem-unwrapped} ''${out}/bin/kaem
|
||||
chmod 555 ''${out}/bin/kaem
|
||||
'';
|
||||
PATH = lib.makeBinPath [ mescc-tools-extra ];
|
||||
inherit kaem-unwrapped;
|
||||
};
|
||||
})
|
14
pkgs/os-specific/linux/trusting-trust/stage0-posix/hex0.nix
Normal file
14
pkgs/os-specific/linux/trusting-trust/stage0-posix/hex0.nix
Normal file
|
@ -0,0 +1,14 @@
|
|||
{ runBareCommand
|
||||
, system
|
||||
, bootstrap-seeds-src
|
||||
}:
|
||||
let
|
||||
throwSystem = throw "Unsupported system: ${system}";
|
||||
arch = {
|
||||
i686-linux = "x86";
|
||||
}.${system} or throwSystem;
|
||||
|
||||
seed = "${bootstrap-seeds-src}/POSIX/${arch}/hex0-seed";
|
||||
src = "${bootstrap-seeds-src}/POSIX/${arch}/hex0_${arch}.hex0";
|
||||
in
|
||||
runBareCommand "hex0" seed [ src (placeholder "out") ]
|
|
@ -0,0 +1,14 @@
|
|||
{ runBareCommand
|
||||
, system
|
||||
, bootstrap-seeds-src
|
||||
, hex0
|
||||
}:
|
||||
let
|
||||
throwSystem = throw "Unsupported system: ${system}";
|
||||
arch = {
|
||||
i686-linux = "x86";
|
||||
}.${system} or throwSystem;
|
||||
|
||||
src = "${bootstrap-seeds-src}/POSIX/${arch}/kaem-minimal.hex0";
|
||||
in
|
||||
runBareCommand "kaem-minimal" hex0 [ src (placeholder "out") ]
|
|
@ -0,0 +1,20 @@
|
|||
# This is a modified version of mescc-tools-extra/mescc-tools-extra.kaem
|
||||
# https://github.com/oriansj/mescc-tools-extra/blob/ec53af69d6d2119b47b369cd0ec37ac806e7ad60/mescc-tools-extra.kaem
|
||||
|
||||
alias CC="${mescc-tools}/bin/M2-Mesoplanet --operating-system ${OPERATING_SYSTEM} --architecture ${ARCH} -f"
|
||||
|
||||
# Create output folder
|
||||
CC ${src}/mkdir.c -o ./mkdir
|
||||
./mkdir -p ${out}/bin
|
||||
|
||||
CC ${src}/sha256sum.c -o ${out}/bin/sha256sum
|
||||
CC ${src}/match.c -o ${out}/bin/match
|
||||
CC ${src}/mkdir.c -o ${out}/bin/mkdir
|
||||
CC ${src}/untar.c -o ${out}/bin/untar
|
||||
CC ${src}/ungz.c -o ${out}/bin/ungz
|
||||
CC ${src}/unbz2.c -o ${out}/bin/unbz2
|
||||
CC ${src}/catm.c -o ${out}/bin/catm
|
||||
CC ${src}/cp.c -o ${out}/bin/cp
|
||||
CC ${src}/chmod.c -o ${out}/bin/chmod
|
||||
CC ${src}/rm.c -o ${out}/bin/rm
|
||||
CC ${src}/replace.c -o ${out}/bin/replace
|
|
@ -0,0 +1,12 @@
|
|||
{ mkKaemDerivation0
|
||||
, mescc-tools-extra-src
|
||||
, mescc-tools
|
||||
, version
|
||||
}:
|
||||
mkKaemDerivation0 {
|
||||
name = "mescc-tools-extra-${version}";
|
||||
script = ./build.kaem;
|
||||
|
||||
src = mescc-tools-extra-src;
|
||||
inherit mescc-tools;
|
||||
}
|
|
@ -0,0 +1,184 @@
|
|||
# This is a modified version of stage0-posix/x86/mescc-tools-full-kaem.kaem
|
||||
# https://github.com/oriansj/stage0-posix-x86/blob/56e6b8df3e95f4bc04f8b420a4cd8c82c70b9efa/mescc-tools-full-kaem.kaem
|
||||
|
||||
${mkdir} -p ${out}/bin
|
||||
${cp} ${M2} ${out}/bin/M2
|
||||
${chmod} 0555 ${out}/bin/M2
|
||||
${cp} ${M1} ${out}/bin/M1
|
||||
${chmod} 0555 ${out}/bin/M1
|
||||
${cp} ${hex2} ${out}/bin/hex2
|
||||
${chmod} 0555 ${out}/bin/hex2
|
||||
|
||||
# M2-Mesoplanet searches for runtime dependencies in environment variables
|
||||
# We can hardcode them with the "replace" utility from mescc-tools-extra
|
||||
${replace} \
|
||||
--file ${m2-mesoplanet-src}/cc.c \
|
||||
--output ./cc_patched.c \
|
||||
--match-on "env_lookup(\"M2LIBC_PATH\")" \
|
||||
--replace-with "\"${m2libc}\""
|
||||
${replace} \
|
||||
--file ${m2-mesoplanet-src}/cc_spawn.c \
|
||||
--output ./cc_spawn_patched.c \
|
||||
--match-on "env_lookup(\"PATH\")" \
|
||||
--replace-with "\"${out}/bin:\""
|
||||
|
||||
###############################################
|
||||
# Phase-12 Build M2-Mesoplanet from M2-Planet #
|
||||
###############################################
|
||||
|
||||
${M2} --architecture ${ARCH} \
|
||||
-f ${m2libc}/sys/types.h \
|
||||
-f ${m2libc}/stddef.h \
|
||||
-f ${m2libc}/${ARCH}/linux/fcntl.c \
|
||||
-f ${m2libc}/fcntl.c \
|
||||
-f ${m2libc}/${ARCH}/linux/unistd.c \
|
||||
-f ${m2libc}/${ARCH}/linux/sys/stat.c \
|
||||
-f ${m2libc}/stdlib.c \
|
||||
-f ${m2libc}/stdio.h \
|
||||
-f ${m2libc}/stdio.c \
|
||||
-f ${m2libc}/string.c \
|
||||
-f ${m2libc}/bootstrappable.c \
|
||||
-f ${m2-mesoplanet-src}/cc.h \
|
||||
-f ${m2-mesoplanet-src}/cc_globals.c \
|
||||
-f ${m2-mesoplanet-src}/cc_env.c \
|
||||
-f ${m2-mesoplanet-src}/cc_reader.c \
|
||||
-f ./cc_spawn_patched.c \
|
||||
-f ${m2-mesoplanet-src}/cc_core.c \
|
||||
-f ${m2-mesoplanet-src}/cc_macro.c \
|
||||
-f ./cc_patched.c \
|
||||
--debug \
|
||||
-o ./M2-Mesoplanet-1.M1
|
||||
|
||||
${blood-elf-0} ${ENDIAN_FLAG} ${BLOOD_FLAG} -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 \
|
||||
-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 \
|
||||
-f ./M2-Mesoplanet-1.hex2 \
|
||||
-o ${out}/bin/M2-Mesoplanet
|
||||
|
||||
#################################################
|
||||
# Phase-13 Build final blood-elf from C sources #
|
||||
#################################################
|
||||
|
||||
${M2} --architecture ${ARCH} \
|
||||
-f ${m2libc}/sys/types.h \
|
||||
-f ${m2libc}/stddef.h \
|
||||
-f ${m2libc}/${ARCH}/linux/fcntl.c \
|
||||
-f ${m2libc}/fcntl.c \
|
||||
-f ${m2libc}/${ARCH}/linux/unistd.c \
|
||||
-f ${m2libc}/stdlib.c \
|
||||
-f ${m2libc}/stdio.h \
|
||||
-f ${m2libc}/stdio.c \
|
||||
-f ${m2libc}/bootstrappable.c \
|
||||
-f ${mescc-tools-src}/stringify.c \
|
||||
-f ${mescc-tools-src}/blood-elf.c \
|
||||
--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 \
|
||||
-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 \
|
||||
-f ./blood-elf-1.hex2 \
|
||||
-o ${out}/bin/blood-elf
|
||||
|
||||
# Now we have our shipping debuggable blood-elf, the rest will be down hill from
|
||||
# here as we have ALL of the core pieces of compiling and assembling debuggable
|
||||
# programs in a debuggable form with corresponding C source code.
|
||||
|
||||
#############################################
|
||||
# Phase-14 Build get_machine from C sources #
|
||||
#############################################
|
||||
|
||||
${M2} --architecture ${ARCH} \
|
||||
-f ${m2libc}/sys/types.h \
|
||||
-f ${m2libc}/stddef.h \
|
||||
-f ${m2libc}/${ARCH}/linux/unistd.c \
|
||||
-f ${m2libc}/${ARCH}/linux/fcntl.c \
|
||||
-f ${m2libc}/fcntl.c \
|
||||
-f ${m2libc}/stdlib.c \
|
||||
-f ${m2libc}/stdio.h \
|
||||
-f ${m2libc}/stdio.c \
|
||||
-f ${m2libc}/bootstrappable.c \
|
||||
-f ${mescc-tools-src}/get_machine.c \
|
||||
--debug \
|
||||
-o get_machine.M1
|
||||
|
||||
${out}/bin/blood-elf ${BLOOD_FLAG} ${ENDIAN_FLAG} -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 \
|
||||
-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 \
|
||||
-f ./get_machine.hex2 \
|
||||
-o ${out}/bin/get_machine
|
||||
|
||||
############################################
|
||||
# Phase-15 Build M2-Planet from M2-Planet #
|
||||
############################################
|
||||
|
||||
${M2} --architecture ${ARCH} \
|
||||
-f ${m2libc}/sys/types.h \
|
||||
-f ${m2libc}/stddef.h \
|
||||
-f ${m2libc}/${ARCH}/linux/unistd.c \
|
||||
-f ${m2libc}/${ARCH}/linux/fcntl.c \
|
||||
-f ${m2libc}/fcntl.c \
|
||||
-f ${m2libc}/stdlib.c \
|
||||
-f ${m2libc}/stdio.h \
|
||||
-f ${m2libc}/stdio.c \
|
||||
-f ${m2libc}/bootstrappable.c \
|
||||
-f ${m2-planet-src}/cc.h \
|
||||
-f ${m2-planet-src}/cc_globals.c \
|
||||
-f ${m2-planet-src}/cc_reader.c \
|
||||
-f ${m2-planet-src}/cc_strings.c \
|
||||
-f ${m2-planet-src}/cc_types.c \
|
||||
-f ${m2-planet-src}/cc_core.c \
|
||||
-f ${m2-planet-src}/cc_macro.c \
|
||||
-f ${m2-planet-src}/cc.c \
|
||||
--debug \
|
||||
-o ./M2-1.M1
|
||||
|
||||
${out}/bin/blood-elf ${ENDIAN_FLAG} ${BLOOD_FLAG} -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 \
|
||||
-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 \
|
||||
-f ./M2-1.hex2 \
|
||||
-o ${out}/bin/M2-Planet
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
{ lib
|
||||
, mkKaemDerivation0
|
||||
, M1
|
||||
, M2
|
||||
, blood-elf-0
|
||||
, hex2
|
||||
, m2libc
|
||||
, m2-mesoplanet-src
|
||||
, m2-planet-src
|
||||
, mescc-tools-src
|
||||
, mescc-tools-extra-src
|
||||
, version
|
||||
}:
|
||||
|
||||
let
|
||||
# We need a few tools from mescc-tools-extra to assemble the output folder
|
||||
buildMesccToolsExtraUtil = name:
|
||||
mkKaemDerivation0 {
|
||||
name = "mescc-tools-extra-${name}-${version}";
|
||||
script = builtins.toFile "build-${name}.kaem" ''
|
||||
''${M2} --architecture ''${ARCH} \
|
||||
-f ''${m2libc}/sys/types.h \
|
||||
-f ''${m2libc}/stddef.h \
|
||||
-f ''${m2libc}/''${ARCH}/linux/fcntl.c \
|
||||
-f ''${m2libc}/fcntl.c \
|
||||
-f ''${m2libc}/''${ARCH}/linux/unistd.c \
|
||||
-f ''${m2libc}/''${ARCH}/linux/sys/stat.c \
|
||||
-f ''${m2libc}/stdlib.c \
|
||||
-f ''${m2libc}/stdio.h \
|
||||
-f ''${m2libc}/stdio.c \
|
||||
-f ''${m2libc}/string.c \
|
||||
-f ''${m2libc}/bootstrappable.c \
|
||||
-f ''${mescc-tools-extra-src}/${name}.c \
|
||||
--debug \
|
||||
-o ${name}.M1
|
||||
|
||||
''${blood-elf-0} ''${ENDIAN_FLAG} -f ${name}.M1 -o ${name}-footer.M1
|
||||
|
||||
''${M1} --architecture ''${ARCH} \
|
||||
''${ENDIAN_FLAG} \
|
||||
-f ''${m2libc}/''${ARCH}/''${ARCH}_defs.M1 \
|
||||
-f ''${m2libc}/''${ARCH}/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 \
|
||||
-f ${name}.hex2 \
|
||||
--base-address ''${BASE_ADDRESS} \
|
||||
-o ''${out}
|
||||
'';
|
||||
inherit M1 M2 blood-elf-0 hex2 m2libc mescc-tools-extra-src;
|
||||
};
|
||||
mkdir = buildMesccToolsExtraUtil "mkdir";
|
||||
cp = buildMesccToolsExtraUtil "cp";
|
||||
chmod = buildMesccToolsExtraUtil "chmod";
|
||||
replace = buildMesccToolsExtraUtil "replace";
|
||||
in
|
||||
mkKaemDerivation0 {
|
||||
name = "mescc-tools-${version}";
|
||||
script = ./build.kaem;
|
||||
|
||||
inherit M1 M2 blood-elf-0 hex2 mkdir cp chmod replace m2libc m2-mesoplanet-src m2-planet-src mescc-tools-src;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
{}:
|
||||
{
|
||||
# Pinned from https://github.com/oriansj/stage0-posix/commit/4ad489ffc261ee036cfd33f20d939d7c5b05844e
|
||||
version = "unstable-2023-04-16";
|
||||
|
||||
bootstrap-seeds-src = builtins.fetchTarball {
|
||||
url = "https://github.com/oriansj/bootstrap-seeds/archive/e4974affa1934274a8b8c29f19c87e758e650f52.tar.gz";
|
||||
sha256 = "0f325x9sixbv35b5s6cjd2qi41n84kmzia11n6w4r6rrldw6wci2";
|
||||
};
|
||||
|
||||
m2-mesoplanet-src = builtins.fetchTarball {
|
||||
url = "https://github.com/oriansj/M2-Mesoplanet/archive/4bf3e2eded821cf9b69fd63a033272197a8703f7.tar.gz";
|
||||
sha256 = "0db13grmxg5hp1jj8vss2ms9c7znk319pkhmnd1ygzg5w8i2v0cj";
|
||||
};
|
||||
|
||||
m2-planet-src = builtins.fetchTarball {
|
||||
url = "https://github.com/oriansj/M2-Planet/archive/f02aaaf67bf004eccd5fd0efb33ced481a0d8346.tar.gz";
|
||||
sha256 = "0bysizqr8nffzzjq6m59gs1m5z2smwfbymijjkxr3l8rxx819vck";
|
||||
};
|
||||
|
||||
m2libc = builtins.fetchTarball {
|
||||
url = "https://github.com/oriansj/M2libc/archive/1139b2bbf5f9c2618e52298917460ec75c345451.tar.gz";
|
||||
sha256 = "113bsmpas8iwflnyjh34ap0p0y23bgdkca9viz9l87kwjbag5y4p";
|
||||
};
|
||||
|
||||
mescc-tools-src = builtins.fetchTarball {
|
||||
url = "https://github.com/oriansj/mescc-tools/archive/3f941824677d74b30d80de08436d63b783adc17f.tar.gz";
|
||||
sha256 = "0cl5934giah2hdzi5q3w3qmkhpm7gx9qjc7nhbwvs3gbmq10nk36";
|
||||
};
|
||||
|
||||
mescc-tools-extra-src = builtins.fetchTarball {
|
||||
url = "https://github.com/oriansj/mescc-tools-extra/archive/ec53af69d6d2119b47b369cd0ec37ac806e7ad60.tar.gz";
|
||||
sha256 = "1kn8mpx104ij9gxifl10dbyalizyn3ifszj5i3msidvr5k7ciay1";
|
||||
};
|
||||
|
||||
stage0-posix-x86-src = builtins.fetchTarball {
|
||||
url = "https://github.com/oriansj/stage0-posix-x86/archive/56e6b8df3e95f4bc04f8b420a4cd8c82c70b9efa.tar.gz";
|
||||
sha256 = "0fih58js6kpflbx9bkl3ikpmbxljlfpg36s78dnaiy6nim36aw7d";
|
||||
};
|
||||
}
|
|
@ -0,0 +1,310 @@
|
|||
# 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
|
||||
|
||||
# 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
|
||||
, hex0
|
||||
, stage0-posix-x86-src
|
||||
, m2libc
|
||||
, m2-planet-src
|
||||
, mescc-tools-src
|
||||
}:
|
||||
rec {
|
||||
out = placeholder "out";
|
||||
|
||||
################################
|
||||
# Phase-1 Build hex1 from hex0 #
|
||||
################################
|
||||
|
||||
hex1 = runBareCommand "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
|
||||
|
||||
################################
|
||||
# Phase-2 Build hex2 from hex1 #
|
||||
################################
|
||||
|
||||
hex2-0 = runBareCommand "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
|
||||
# This is a minimal version which will be used to bootstrap a much more advanced
|
||||
# version in a later stage.
|
||||
|
||||
#################################
|
||||
# Phase-2b Build catm from hex2 #
|
||||
#################################
|
||||
|
||||
catm = runBareCommand "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
|
||||
|
||||
##############################
|
||||
# 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 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 #
|
||||
################################
|
||||
|
||||
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];
|
||||
|
||||
#######################################
|
||||
# Phase-5 Build M2-Planet from cc_x86 #
|
||||
#######################################
|
||||
|
||||
M2-0_c = runBareCommand "M2-0.c" catm [
|
||||
out
|
||||
"${m2libc}/x86/linux/bootstrap.c"
|
||||
"${m2-planet-src}/cc.h"
|
||||
"${m2libc}/bootstrappable.c"
|
||||
"${m2-planet-src}/cc_globals.c"
|
||||
"${m2-planet-src}/cc_reader.c"
|
||||
"${m2-planet-src}/cc_strings.c"
|
||||
"${m2-planet-src}/cc_types.c"
|
||||
"${m2-planet-src}/cc_core.c"
|
||||
"${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];
|
||||
|
||||
############################################
|
||||
# Phase-6 Build blood-elf-0 from C sources #
|
||||
############################################
|
||||
|
||||
blood-elf-0_M1 = runBareCommand "blood-elf-0.M1" M2 [
|
||||
"--architecture" "x86"
|
||||
"-f" "${m2libc}/x86/linux/bootstrap.c"
|
||||
"-f" "${m2libc}/bootstrappable.c"
|
||||
"-f" "${mescc-tools-src}/stringify.c"
|
||||
"-f" "${mescc-tools-src}/blood-elf.c"
|
||||
"--bootstrap-mode"
|
||||
"-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];
|
||||
|
||||
# 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
|
||||
|
||||
#####################################
|
||||
# Phase-7 Build M1-0 from C sources #
|
||||
#####################################
|
||||
|
||||
M1-macro-0_M1 = runBareCommand "M1-macro-0.M1" M2 [
|
||||
"--architecture" "x86"
|
||||
"-f" "${m2libc}/x86/linux/bootstrap.c"
|
||||
"-f" "${m2libc}/bootstrappable.c"
|
||||
"-f" "${mescc-tools-src}/stringify.c"
|
||||
"-f" "${mescc-tools-src}/M1-macro.c"
|
||||
"--bootstrap-mode"
|
||||
"--debug"
|
||||
"-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];
|
||||
|
||||
# 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
|
||||
# version with a bunch of extra goodies.
|
||||
|
||||
#######################################
|
||||
# Phase-8 Build hex2-1 from C sources #
|
||||
#######################################
|
||||
|
||||
hex2_linker-0_M1 = runBareCommand "hex2_linker-0.M1" M2 [
|
||||
"--architecture" "x86"
|
||||
"-f" "${m2libc}/sys/types.h"
|
||||
"-f" "${m2libc}/stddef.h"
|
||||
"-f" "${m2libc}/x86/linux/unistd.c"
|
||||
"-f" "${m2libc}/x86/linux/fcntl.c"
|
||||
"-f" "${m2libc}/fcntl.c"
|
||||
"-f" "${m2libc}/x86/linux/sys/stat.c"
|
||||
"-f" "${m2libc}/stdlib.c"
|
||||
"-f" "${m2libc}/stdio.h"
|
||||
"-f" "${m2libc}/stdio.c"
|
||||
"-f" "${m2libc}/bootstrappable.c"
|
||||
"-f" "${mescc-tools-src}/hex2.h"
|
||||
"-f" "${mescc-tools-src}/hex2_linker.c"
|
||||
"-f" "${mescc-tools-src}/hex2_word.c"
|
||||
"-f" "${mescc-tools-src}/hex2.c"
|
||||
"--debug"
|
||||
"-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_hex2 = runBareCommand "hex2_linker-0.hex2" M1-0 [
|
||||
"--architecture" "x86"
|
||||
"--little-endian"
|
||||
"-f" "${m2libc}/x86/x86_defs.M1"
|
||||
"-f" "${m2libc}/x86/libc-full.M1"
|
||||
"-f" hex2_linker-0_M1
|
||||
"-f" hex2_linker-0-footer_M1
|
||||
"-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-1 = runBareCommand "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
|
||||
|
||||
###################################
|
||||
# Phase-9 Build M1 from C sources #
|
||||
###################################
|
||||
|
||||
M1-macro-1_M1 = runBareCommand "M1-macro-1.M1" M2 [
|
||||
"--architecture" "x86"
|
||||
"-f" "${m2libc}/sys/types.h"
|
||||
"-f" "${m2libc}/stddef.h"
|
||||
"-f" "${m2libc}/x86/linux/fcntl.c"
|
||||
"-f" "${m2libc}/fcntl.c"
|
||||
"-f" "${m2libc}/x86/linux/unistd.c"
|
||||
"-f" "${m2libc}/string.c"
|
||||
"-f" "${m2libc}/stdlib.c"
|
||||
"-f" "${m2libc}/stdio.h"
|
||||
"-f" "${m2libc}/stdio.c"
|
||||
"-f" "${m2libc}/bootstrappable.c"
|
||||
"-f" "${mescc-tools-src}/stringify.c"
|
||||
"-f" "${mescc-tools-src}/M1-macro.c"
|
||||
"--debug"
|
||||
"-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_hex2 = runBareCommand "M1-macro-1.hex2" M1-0 [
|
||||
"--architecture" "x86"
|
||||
"--little-endian"
|
||||
"-f" "${m2libc}/x86/x86_defs.M1"
|
||||
"-f" "${m2libc}/x86/libc-full.M1"
|
||||
"-f" M1-macro-1_M1
|
||||
"-f" M1-macro-1-footer_M1
|
||||
"-o" out
|
||||
];
|
||||
|
||||
M1 = runBareCommand "M1" hex2-1 [
|
||||
"--architecture" "x86"
|
||||
"--little-endian"
|
||||
"--base-address" "0x8048000"
|
||||
"-f" "${m2libc}/x86/ELF-x86-debug.hex2"
|
||||
"-f" M1-macro-1_hex2
|
||||
"-o" out
|
||||
];
|
||||
|
||||
######################################
|
||||
# Phase-10 Build hex2 from C sources #
|
||||
######################################
|
||||
|
||||
hex2_linker-2_M1 = runBareCommand "hex2_linker-2.M1" M2 [
|
||||
"--architecture" "x86"
|
||||
"-f" "${m2libc}/sys/types.h"
|
||||
"-f" "${m2libc}/stddef.h"
|
||||
"-f" "${m2libc}/x86/linux/unistd.c"
|
||||
"-f" "${m2libc}/x86/linux/fcntl.c"
|
||||
"-f" "${m2libc}/fcntl.c"
|
||||
"-f" "${m2libc}/x86/linux/sys/stat.c"
|
||||
"-f" "${m2libc}/stdlib.c"
|
||||
"-f" "${m2libc}/stdio.h"
|
||||
"-f" "${m2libc}/stdio.c"
|
||||
"-f" "${m2libc}/bootstrappable.c"
|
||||
"-f" "${mescc-tools-src}/hex2.h"
|
||||
"-f" "${mescc-tools-src}/hex2_linker.c"
|
||||
"-f" "${mescc-tools-src}/hex2_word.c"
|
||||
"-f" "${mescc-tools-src}/hex2.c"
|
||||
"--debug"
|
||||
"-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_hex2 = runBareCommand "hex2_linker-2.hex2" M1 [
|
||||
"--architecture" "x86"
|
||||
"--little-endian"
|
||||
"-f" "${m2libc}/x86/x86_defs.M1"
|
||||
"-f" "${m2libc}/x86/libc-full.M1"
|
||||
"-f" hex2_linker-2_M1
|
||||
"-f" hex2_linker-2-footer_M1
|
||||
"-o" out
|
||||
];
|
||||
|
||||
hex2 = runBareCommand "hex2" hex2-1 [
|
||||
"--architecture" "x86"
|
||||
"--little-endian"
|
||||
"--base-address" "0x8048000"
|
||||
"-f" "${m2libc}/x86/ELF-x86-debug.hex2"
|
||||
"-f" hex2_linker-2_hex2
|
||||
"-o" out
|
||||
];
|
||||
|
||||
######################################
|
||||
# Phase-11 Build kaem from C sources #
|
||||
######################################
|
||||
|
||||
kaem_M1 = runBareCommand "kaem.M1" M2 [
|
||||
"--architecture" "x86"
|
||||
"-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}/fcntl.c"
|
||||
"-f" "${m2libc}/stdlib.c"
|
||||
"-f" "${m2libc}/stdio.h"
|
||||
"-f" "${m2libc}/stdio.c"
|
||||
"-f" "${m2libc}/bootstrappable.c"
|
||||
"-f" "${mescc-tools-src}/Kaem/kaem.h"
|
||||
"-f" "${mescc-tools-src}/Kaem/variable.c"
|
||||
"-f" "${mescc-tools-src}/Kaem/kaem_globals.c"
|
||||
"-f" "${mescc-tools-src}/Kaem/kaem.c"
|
||||
"--debug"
|
||||
"-o" out
|
||||
];
|
||||
|
||||
kaem-footer_M1 = runBareCommand "kaem-footer.M1" blood-elf-0 ["-f" kaem_M1 "--little-endian" "-o" out];
|
||||
|
||||
kaem_hex2 = runBareCommand "kaem.hex2" M1 [
|
||||
"--architecture" "x86"
|
||||
"--little-endian"
|
||||
"-f" "${m2libc}/x86/x86_defs.M1"
|
||||
"-f" "${m2libc}/x86/libc-full.M1"
|
||||
"-f" kaem_M1
|
||||
"-f" kaem-footer_M1
|
||||
"-o" out
|
||||
];
|
||||
|
||||
kaem-unwrapped = runBareCommand "kaem-unwrapped" hex2 [
|
||||
"--architecture" "x86"
|
||||
"--little-endian"
|
||||
"-f" "${m2libc}/x86/ELF-x86-debug.hex2"
|
||||
"-f" kaem_hex2
|
||||
"--base-address" "0x8048000"
|
||||
"-o" out
|
||||
];
|
||||
}
|
63
pkgs/os-specific/linux/trusting-trust/stage0-posix/utils.nix
Normal file
63
pkgs/os-specific/linux/trusting-trust/stage0-posix/utils.nix
Normal file
|
@ -0,0 +1,63 @@
|
|||
{ lib
|
||||
, system
|
||||
, mkKaemDerivation0
|
||||
, kaem
|
||||
, mescc-tools
|
||||
, mescc-tools-extra
|
||||
}:
|
||||
|
||||
rec {
|
||||
writeTextFile =
|
||||
{ name # the name of the derivation
|
||||
, text
|
||||
, executable ? false # run chmod +x ?
|
||||
, destination ? "" # relative path appended to $out eg "/bin/foo"
|
||||
, allowSubstitutes ? false
|
||||
, preferLocalBuild ? true
|
||||
}:
|
||||
mkKaemDerivation0 {
|
||||
inherit name text executable allowSubstitutes preferLocalBuild;
|
||||
passAsFile = [ "text" ];
|
||||
|
||||
PATH = lib.makeBinPath [ mescc-tools-extra ];
|
||||
script = builtins.toFile "write-text-file.kaem" ''
|
||||
target=''${out}${destination}
|
||||
if match x${if builtins.dirOf destination == "" then "0" else "1"} x1; then
|
||||
mkdir -p ''${out}${builtins.dirOf destination}
|
||||
fi
|
||||
cp ''${textPath} ''${target}
|
||||
if match x''${executable} x1; then
|
||||
chmod 555 ''${target}
|
||||
fi
|
||||
'';
|
||||
};
|
||||
|
||||
writeText = name: text: writeTextFile {inherit name text;};
|
||||
|
||||
mkKaemDerivation = args@{
|
||||
pname ? null,
|
||||
version ? null,
|
||||
name ? null,
|
||||
buildPhase,
|
||||
buildInputs ? [],
|
||||
...
|
||||
}:
|
||||
assert name == null -> pname != null && version != null;
|
||||
let
|
||||
rname = if name != null then name else "${pname}-${version}";
|
||||
in
|
||||
derivation ({
|
||||
inherit system;
|
||||
name = rname;
|
||||
|
||||
builder = "${kaem}/bin/kaem";
|
||||
args = [
|
||||
"--verbose"
|
||||
"--strict"
|
||||
"--file"
|
||||
(writeText "${rname}-builder" buildPhase)
|
||||
];
|
||||
|
||||
PATH = lib.makeBinPath (buildInputs ++ [ kaem mescc-tools mescc-tools-extra ]);
|
||||
} // (builtins.removeAttrs args [ "pname" "version" "name" "buildPhase" "buildInputs" ]));
|
||||
}
|
|
@ -27459,6 +27459,8 @@ with pkgs;
|
|||
|
||||
trust-dns = callPackage ../servers/dns/trust-dns { };
|
||||
|
||||
trusting-trust = recurseIntoAttrs (callPackage ../os-specific/linux/trusting-trust { });
|
||||
|
||||
trustymail = callPackage ../tools/security/trustymail { };
|
||||
|
||||
tunctl = callPackage ../os-specific/linux/tunctl { };
|
||||
|
|
Loading…
Reference in a new issue