minimal-bootstrap.stage0-posix: support x86_64-linux

+231 -174
-8
pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/bootstrap-sources.nix
··· 9 9 outputHashAlgo = "sha256"; 10 10 outputHash = "sha256-FpMp7z+B3cR3LkQ+PooH/b1/NlxH8NHVJNWifaPWt4U="; 11 11 12 - # This 256 byte seed is the only pre-compiled binary in the bootstrap chain. 13 - hex0-seed = import <nix/fetchurl.nix> { 14 - name = "hex0-seed-${version}"; 15 - url = "https://github.com/oriansj/bootstrap-seeds/raw/b1263ff14a17835f4d12539226208c426ced4fba/POSIX/x86/hex0-seed"; 16 - hash = "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8="; 17 - executable = true; 18 - }; 19 - 20 12 /* 21 13 Since `make-minimal-bootstrap-sources` requires nixpkgs and nix it 22 14 will create a circular dependency if it is used in place of the
+6 -4
pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/default.nix
··· 3 3 }: 4 4 5 5 lib.makeScope newScope (self: with self; { 6 - inherit (self.callPackage ./bootstrap-sources.nix {}) 7 - version hex0-seed minimal-bootstrap-sources; 6 + inherit (callPackage ./platforms.nix { }) platforms stage0Arch m2libcArch m2libcOS baseAddress; 7 + 8 + inherit (self.callPackage ./bootstrap-sources.nix {}) version minimal-bootstrap-sources; 8 9 9 10 src = minimal-bootstrap-sources; 10 11 11 12 m2libc = src + "/M2libc"; 12 13 13 14 hex0 = callPackage ./hex0.nix { }; 15 + inherit (self.hex0) hex0-seed; 14 16 15 17 kaem = callPackage ./kaem { }; 16 18 kaem-minimal = callPackage ./kaem/minimal.nix { }; 17 19 18 - stage0-posix-x86 = callPackage ./stage0-posix-x86.nix { }; 20 + mescc-tools-boot = callPackage ./mescc-tools-boot.nix { }; 19 21 20 - inherit (self.stage0-posix-x86) blood-elf-0 hex2 kaem-unwrapped M1 M2; 22 + inherit (self.mescc-tools-boot) blood-elf-0 hex2 kaem-unwrapped M1 M2; 21 23 22 24 mescc-tools = callPackage ./mescc-tools { }; 23 25
+24 -4
pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/hex0.nix
··· 1 1 { lib 2 2 , derivationWithMeta 3 - , hex0-seed 3 + , hostPlatform 4 4 , src 5 5 , version 6 + , platforms 7 + , stage0Arch 6 8 }: 9 + 10 + let 11 + hash = { 12 + "x86" = "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8="; 13 + "AMD64" = "sha256-RCgK9oZRDQUiWLVkcIBSR2HeoB+Bh0czthrpjFEkCaY="; 14 + }.${stage0Arch} or (throw "Unsupported system: ${hostPlatform.system}"); 15 + 16 + # Pinned from https://github.com/oriansj/stage0-posix/commit/3189b5f325b7ef8b88e3edec7c1cde4fce73c76c 17 + # This 256 byte seed is the only pre-compiled binary in the bootstrap chain. 18 + hex0-seed = import <nix/fetchurl.nix> { 19 + name = "hex0-seed"; 20 + url = "https://github.com/oriansj/bootstrap-seeds/raw/b1263ff14a17835f4d12539226208c426ced4fba/POSIX/${stage0Arch}/hex0-seed"; 21 + executable = true; 22 + inherit hash; 23 + }; 24 + in 7 25 derivationWithMeta { 8 26 inherit version; 9 27 pname = "hex0"; 10 28 builder = hex0-seed; 11 29 args = [ 12 - "${src}/x86/hex0_x86.hex0" 30 + "${src}/${stage0Arch}/hex0_${stage0Arch}.hex0" 13 31 (placeholder "out") 14 32 ]; 15 33 ··· 18 36 homepage = "https://github.com/oriansj/stage0-posix"; 19 37 license = licenses.gpl3Plus; 20 38 maintainers = teams.minimal-bootstrap.members; 21 - platforms = [ "i686-linux" ]; 39 + inherit platforms; 22 40 }; 23 41 42 + passthru = { inherit hex0-seed; }; 43 + 24 44 # Ensure the untrusted hex0-seed binary produces a known-good hex0 25 45 outputHashMode = "recursive"; 26 46 outputHashAlgo = "sha256"; 27 - outputHash = "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8="; 47 + outputHash = hash; 28 48 }
+2 -1
pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/kaem/default.nix
··· 6 6 , mescc-tools 7 7 , mescc-tools-extra 8 8 , version 9 + , platforms 9 10 }: 10 11 11 12 # Once mescc-tools-extra is available we can install kaem at /bin/kaem ··· 46 47 homepage = "https://github.com/oriansj/mescc-tools"; 47 48 license = licenses.gpl3Plus; 48 49 maintainers = teams.minimal-bootstrap.members; 49 - platforms = [ "i686-linux" ]; 50 + inherit platforms; 50 51 }; 51 52 }
+4 -2
pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/kaem/minimal.nix
··· 3 3 , src 4 4 , hex0 5 5 , version 6 + , platforms 7 + , stage0Arch 6 8 }: 7 9 derivationWithMeta { 8 10 inherit version; 9 11 pname = "kaem-minimal"; 10 12 builder = hex0; 11 13 args = [ 12 - "${src}/x86/kaem-minimal.hex0" 14 + "${src}/${stage0Arch}/kaem-minimal.hex0" 13 15 (placeholder "out") 14 16 ]; 15 17 ··· 18 20 homepage = "https://github.com/oriansj/stage0-posix"; 19 21 license = licenses.gpl3Plus; 20 22 maintainers = teams.minimal-bootstrap.members; 21 - platforms = [ "i686-linux" ]; 23 + inherit platforms; 22 24 }; 23 25 } 24 26
+1 -1
pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-extra/build.kaem
··· 19 19 ## You should have received a copy of the GNU General Public License 20 20 ## along with mescc-tools. If not, see <http://www.gnu.org/licenses/>. 21 21 22 - alias CC="${mescc-tools}/bin/M2-Mesoplanet --operating-system ${OPERATING_SYSTEM} --architecture ${ARCH} -f" 22 + alias CC="${mescc-tools}/bin/M2-Mesoplanet --operating-system ${m2libcOS} --architecture ${m2libcArch} -f" 23 23 cd ${src}/mescc-tools-extra 24 24 25 25 # Create output folder
+5 -5
pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-extra/default.nix
··· 4 4 , mescc-tools 5 5 , src 6 6 , version 7 + , platforms 8 + , m2libcArch 9 + , m2libcOS 7 10 }: 8 11 derivationWithMeta { 9 - inherit version src mescc-tools; 12 + inherit version src mescc-tools m2libcArch m2libcOS; 10 13 pname = "mescc-tools-extra"; 11 14 builder = kaem-unwrapped; 12 15 args = [ ··· 16 19 ./build.kaem 17 20 ]; 18 21 19 - ARCH = "x86"; 20 - OPERATING_SYSTEM = "linux"; 21 - 22 22 meta = with lib; { 23 23 description = "Collection of tools written for use in bootstrapping"; 24 24 homepage = "https://github.com/oriansj/mescc-tools-extra"; 25 25 license = licenses.gpl3Plus; 26 26 maintainers = teams.minimal-bootstrap.members; 27 - platforms = [ "i686-linux" ]; 27 + inherit platforms; 28 28 }; 29 29 }
+50 -50
pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools/build.kaem
··· 46 46 # Phase-12 Build M2-Mesoplanet from M2-Planet # 47 47 ############################################### 48 48 49 - ${M2} --architecture ${ARCH} \ 49 + ${M2} --architecture ${m2libcArch} \ 50 50 -f ${m2libc}/sys/types.h \ 51 51 -f ${m2libc}/stddef.h \ 52 - -f ${m2libc}/${ARCH}/linux/fcntl.c \ 52 + -f ${m2libc}/${m2libcArch}/linux/fcntl.c \ 53 53 -f ${m2libc}/fcntl.c \ 54 - -f ${m2libc}/${ARCH}/linux/unistd.c \ 55 - -f ${m2libc}/${ARCH}/linux/sys/stat.c \ 54 + -f ${m2libc}/${m2libcArch}/linux/unistd.c \ 55 + -f ${m2libc}/${m2libcArch}/linux/sys/stat.c \ 56 56 -f ${m2libc}/stdlib.c \ 57 57 -f ${m2libc}/stdio.h \ 58 58 -f ${m2libc}/stdio.c \ ··· 69 69 --debug \ 70 70 -o ./M2-Mesoplanet-1.M1 71 71 72 - ${blood-elf-0} ${ENDIAN_FLAG} ${BLOOD_FLAG} -f ./M2-Mesoplanet-1.M1 -o ./M2-Mesoplanet-1-footer.M1 72 + ${blood-elf-0} ${endianFlag} ${bloodFlag} -f ./M2-Mesoplanet-1.M1 -o ./M2-Mesoplanet-1-footer.M1 73 73 74 - ${M1} --architecture ${ARCH} \ 75 - ${ENDIAN_FLAG} \ 76 - -f ${m2libc}/${ARCH}/${ARCH}_defs.M1 \ 77 - -f ${m2libc}/${ARCH}/libc-full.M1 \ 74 + ${M1} --architecture ${m2libcArch} \ 75 + ${endianFlag} \ 76 + -f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \ 77 + -f ${m2libc}/${m2libcArch}/libc-full.M1 \ 78 78 -f ./M2-Mesoplanet-1.M1 \ 79 79 -f ./M2-Mesoplanet-1-footer.M1 \ 80 80 -o ./M2-Mesoplanet-1.hex2 81 81 82 - ${hex2} --architecture ${ARCH} \ 83 - ${ENDIAN_FLAG} \ 84 - --base-address ${BASE_ADDRESS} \ 85 - -f ${m2libc}/${ARCH}/ELF-${ARCH}-debug.hex2 \ 82 + ${hex2} --architecture ${m2libcArch} \ 83 + ${endianFlag} \ 84 + --base-address ${baseAddress} \ 85 + -f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \ 86 86 -f ./M2-Mesoplanet-1.hex2 \ 87 87 -o ${out}/bin/M2-Mesoplanet 88 88 ··· 90 90 # Phase-13 Build final blood-elf from C sources # 91 91 ################################################# 92 92 93 - ${M2} --architecture ${ARCH} \ 93 + ${M2} --architecture ${m2libcArch} \ 94 94 -f ${m2libc}/sys/types.h \ 95 95 -f ${m2libc}/stddef.h \ 96 - -f ${m2libc}/${ARCH}/linux/fcntl.c \ 96 + -f ${m2libc}/${m2libcArch}/linux/fcntl.c \ 97 97 -f ${m2libc}/fcntl.c \ 98 - -f ${m2libc}/${ARCH}/linux/unistd.c \ 98 + -f ${m2libc}/${m2libcArch}/linux/unistd.c \ 99 99 -f ${m2libc}/stdlib.c \ 100 100 -f ${m2libc}/stdio.h \ 101 101 -f ${m2libc}/stdio.c \ ··· 105 105 --debug \ 106 106 -o ./blood-elf-1.M1 107 107 108 - ${blood-elf-0} ${BLOOD_FLAG} ${ENDIAN_FLAG} -f ./blood-elf-1.M1 -o ./blood-elf-1-footer.M1 109 - ${M1} --architecture ${ARCH} \ 110 - ${ENDIAN_FLAG} \ 111 - -f ${m2libc}/${ARCH}/${ARCH}_defs.M1 \ 112 - -f ${m2libc}/${ARCH}/libc-full.M1 \ 108 + ${blood-elf-0} ${endianFlag} ${bloodFlag} -f ./blood-elf-1.M1 -o ./blood-elf-1-footer.M1 109 + 110 + ${M1} --architecture ${m2libcArch} \ 111 + ${endianFlag} \ 112 + -f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \ 113 + -f ${m2libc}/${m2libcArch}/libc-full.M1 \ 113 114 -f ./blood-elf-1.M1 \ 114 115 -f ./blood-elf-1-footer.M1 \ 115 116 -o ./blood-elf-1.hex2 116 117 117 - ${hex2} --architecture ${ARCH} \ 118 - ${ENDIAN_FLAG} \ 119 - --base-address ${BASE_ADDRESS} \ 120 - -f ${m2libc}/${ARCH}/ELF-${ARCH}-debug.hex2 \ 118 + ${hex2} --architecture ${m2libcArch} \ 119 + ${endianFlag} \ 120 + --base-address ${baseAddress} \ 121 + -f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \ 121 122 -f ./blood-elf-1.hex2 \ 122 123 -o ${out}/bin/blood-elf 123 124 ··· 129 130 # Phase-14 Build get_machine from C sources # 130 131 ############################################# 131 132 132 - ${M2} --architecture ${ARCH} \ 133 + ${M2} --architecture ${m2libcArch} \ 133 134 -f ${m2libc}/sys/types.h \ 134 135 -f ${m2libc}/stddef.h \ 135 - -f ${m2libc}/${ARCH}/linux/unistd.c \ 136 - -f ${m2libc}/${ARCH}/linux/fcntl.c \ 136 + -f ${m2libc}/${m2libcArch}/linux/unistd.c \ 137 + -f ${m2libc}/${m2libcArch}/linux/fcntl.c \ 137 138 -f ${m2libc}/fcntl.c \ 138 139 -f ${m2libc}/stdlib.c \ 139 140 -f ${m2libc}/stdio.h \ ··· 143 144 --debug \ 144 145 -o get_machine.M1 145 146 146 - ${out}/bin/blood-elf ${BLOOD_FLAG} ${ENDIAN_FLAG} -f ./get_machine.M1 -o ./get_machine-footer.M1 147 + ${out}/bin/blood-elf ${endianFlag} ${bloodFlag} -f ./get_machine.M1 -o ./get_machine-footer.M1 147 148 148 - ${M1} --architecture ${ARCH} \ 149 - ${ENDIAN_FLAG} \ 150 - -f ${m2libc}/${ARCH}/${ARCH}_defs.M1 \ 151 - -f ${m2libc}/${ARCH}/libc-full.M1 \ 149 + ${M1} --architecture ${m2libcArch} \ 150 + ${endianFlag} \ 151 + -f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \ 152 + -f ${m2libc}/${m2libcArch}/libc-full.M1 \ 152 153 -f ./get_machine.M1 \ 153 154 -f ./get_machine-footer.M1 \ 154 155 -o ./get_machine.hex2 155 156 156 - ${hex2} --architecture ${ARCH} \ 157 - ${ENDIAN_FLAG} \ 158 - --base-address ${BASE_ADDRESS} \ 159 - -f ${m2libc}/${ARCH}/ELF-${ARCH}-debug.hex2 \ 157 + ${hex2} --architecture ${m2libcArch} \ 158 + ${endianFlag} \ 159 + --base-address ${baseAddress} \ 160 + -f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \ 160 161 -f ./get_machine.hex2 \ 161 162 -o ${out}/bin/get_machine 162 163 ··· 164 165 # Phase-15 Build M2-Planet from M2-Planet # 165 166 ############################################ 166 167 167 - ${M2} --architecture ${ARCH} \ 168 + ${M2} --architecture ${m2libcArch} \ 168 169 -f ${m2libc}/sys/types.h \ 169 170 -f ${m2libc}/stddef.h \ 170 - -f ${m2libc}/${ARCH}/linux/unistd.c \ 171 - -f ${m2libc}/${ARCH}/linux/fcntl.c \ 171 + -f ${m2libc}/${m2libcArch}/linux/unistd.c \ 172 + -f ${m2libc}/${m2libcArch}/linux/fcntl.c \ 172 173 -f ${m2libc}/fcntl.c \ 173 174 -f ${m2libc}/stdlib.c \ 174 175 -f ${m2libc}/stdio.h \ ··· 185 186 --debug \ 186 187 -o ./M2-1.M1 187 188 188 - ${out}/bin/blood-elf ${ENDIAN_FLAG} ${BLOOD_FLAG} -f ./M2-1.M1 -o ./M2-1-footer.M1 189 + ${out}/bin/blood-elf ${endianFlag} ${bloodFlag} -f ./M2-1.M1 -o ./M2-1-footer.M1 189 190 190 - ${M1} --architecture ${ARCH} \ 191 - ${ENDIAN_FLAG} \ 192 - -f ${m2libc}/${ARCH}/${ARCH}_defs.M1 \ 193 - -f ${m2libc}/${ARCH}/libc-full.M1 \ 191 + ${M1} --architecture ${m2libcArch} \ 192 + ${endianFlag} \ 193 + -f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \ 194 + -f ${m2libc}/${m2libcArch}/libc-full.M1 \ 194 195 -f ./M2-1.M1 \ 195 196 -f ./M2-1-footer.M1 \ 196 197 -o ./M2-1.hex2 197 198 198 - ${hex2} --architecture ${ARCH} \ 199 - ${ENDIAN_FLAG} \ 200 - --base-address ${BASE_ADDRESS} \ 201 - -f ${m2libc}/${ARCH}/ELF-${ARCH}-debug.hex2 \ 199 + ${hex2} --architecture ${m2libcArch} \ 200 + ${endianFlag} \ 201 + --base-address ${baseAddress} \ 202 + -f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \ 202 203 -f ./M2-1.hex2 \ 203 204 -o ${out}/bin/M2-Planet 204 -
+22 -20
pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools/default.nix
··· 1 1 { lib 2 2 , derivationWithMeta 3 + , hostPlatform 3 4 , kaem-unwrapped 4 5 , M1 5 6 , M2 ··· 8 9 , m2libc 9 10 , src 10 11 , version 12 + , platforms 13 + , m2libcArch 14 + , baseAddress 11 15 }: 12 16 13 17 let 14 - ARCH = "x86"; 15 - BLOOD_FLAG = " "; 16 - BASE_ADDRESS = "0x8048000"; 17 - ENDIAN_FLAG = "--little-endian"; 18 + endianFlag = if hostPlatform.isLittleEndian then "--little-endian" else "--big-endian"; 19 + bloodFlag = if hostPlatform.is64bit then "--64" else " "; 18 20 19 21 # We need a few tools from mescc-tools-extra to assemble the output folder 20 22 buildMesccToolsExtraUtil = name: ··· 26 28 "--strict" 27 29 "--file" 28 30 (builtins.toFile "build-${name}.kaem" '' 29 - ''${M2} --architecture ''${ARCH} \ 31 + ''${M2} --architecture ${m2libcArch} \ 30 32 -f ''${m2libc}/sys/types.h \ 31 33 -f ''${m2libc}/stddef.h \ 32 - -f ''${m2libc}/''${ARCH}/linux/fcntl.c \ 34 + -f ''${m2libc}/${m2libcArch}/linux/fcntl.c \ 33 35 -f ''${m2libc}/fcntl.c \ 34 - -f ''${m2libc}/''${ARCH}/linux/unistd.c \ 35 - -f ''${m2libc}/''${ARCH}/linux/sys/stat.c \ 36 + -f ''${m2libc}/${m2libcArch}/linux/unistd.c \ 37 + -f ''${m2libc}/${m2libcArch}/linux/sys/stat.c \ 36 38 -f ''${m2libc}/stdlib.c \ 37 39 -f ''${m2libc}/stdio.h \ 38 40 -f ''${m2libc}/stdio.c \ ··· 42 44 --debug \ 43 45 -o ${name}.M1 44 46 45 - ''${blood-elf-0} ''${ENDIAN_FLAG} -f ${name}.M1 -o ${name}-footer.M1 47 + ''${blood-elf-0} ${endianFlag} ${bloodFlag} -f ${name}.M1 -o ${name}-footer.M1 46 48 47 - ''${M1} --architecture ''${ARCH} \ 48 - ''${ENDIAN_FLAG} \ 49 - -f ''${m2libc}/''${ARCH}/''${ARCH}_defs.M1 \ 50 - -f ''${m2libc}/''${ARCH}/libc-full.M1 \ 49 + ''${M1} --architecture ${m2libcArch} \ 50 + ${endianFlag} \ 51 + -f ''${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \ 52 + -f ''${m2libc}/${m2libcArch}/libc-full.M1 \ 51 53 -f ${name}.M1 \ 52 54 -f ${name}-footer.M1 \ 53 55 -o ${name}.hex2 54 56 55 - ''${hex2} --architecture ''${ARCH} \ 56 - ''${ENDIAN_FLAG} \ 57 - -f ''${m2libc}/''${ARCH}/ELF-''${ARCH}-debug.hex2 \ 57 + ''${hex2} --architecture ${m2libcArch} \ 58 + ${endianFlag} \ 59 + -f ''${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \ 58 60 -f ${name}.hex2 \ 59 - --base-address ''${BASE_ADDRESS} \ 61 + --base-address ${baseAddress} \ 60 62 -o ''${out} 61 63 '') 62 64 ]; 63 - inherit version M1 M2 blood-elf-0 hex2 m2libc src ARCH BLOOD_FLAG BASE_ADDRESS ENDIAN_FLAG; 65 + inherit version M1 M2 blood-elf-0 hex2 m2libc src; 64 66 }; 65 67 mkdir = buildMesccToolsExtraUtil "mkdir"; 66 68 cp = buildMesccToolsExtraUtil "cp"; ··· 76 78 "--file" 77 79 ./build.kaem 78 80 ]; 79 - inherit version M1 M2 blood-elf-0 hex2 mkdir cp chmod replace m2libc src ARCH BLOOD_FLAG BASE_ADDRESS ENDIAN_FLAG; 81 + inherit version M1 M2 blood-elf-0 hex2 mkdir cp chmod replace m2libc src m2libcArch baseAddress bloodFlag endianFlag; 80 82 81 83 meta = with lib; { 82 84 description = "Collection of tools written for use in bootstrapping"; 83 85 homepage = "https://github.com/oriansj/mescc-tools"; 84 86 license = licenses.gpl3Plus; 85 87 maintainers = teams.minimal-bootstrap.members; 86 - platforms = [ "i686-linux" ]; 88 + inherit platforms; 87 89 }; 88 90 }
+29
pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/platforms.nix
··· 1 + # Platform specific constants 2 + { lib 3 + , hostPlatform 4 + }: 5 + 6 + rec { 7 + # meta.platforms 8 + platforms = [ 9 + "i686-linux" 10 + "x86_64-linux" 11 + ]; 12 + 13 + # system arch as used within the stage0 project 14 + stage0Arch = { 15 + "i686-linux" = "x86"; 16 + "x86_64-linux" = "AMD64"; 17 + }.${hostPlatform.system} or (throw "Unsupported system: ${hostPlatform.system}"); 18 + 19 + # lower-case form is widely used by m2libc 20 + m2libcArch = lib.toLower stage0Arch; 21 + 22 + # Passed to M2-Mesoplanet as --operating-system 23 + m2libcOS = if hostPlatform.isLinux then "linux" else throw "Unsupported system: ${hostPlatform.system}"; 24 + 25 + baseAddress = { 26 + "i686-linux" = "0x08048000"; 27 + "x86_64-linux" = "0x00600000"; 28 + }.${hostPlatform.system} or (throw "Unsupported system: ${hostPlatform.system}"); 29 + }
+88 -79
pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/stage0-posix-x86.nix pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-boot.nix
··· 1 - # This is a translation of stage0-posix/stage0-posix/x86/mescc-tools-mini-kaem.kaem to nix 2 - # https://github.com/oriansj/stage0-posix-x86/blob/56e6b8df3e95f4bc04f8b420a4cd8c82c70b9efa/mescc-tools-mini-kaem.kaem 3 - # 4 - # We have access to mini-kaem at this point but it doesn't support substituting 5 - # environment variables. Without variables there's no way of passing in store inputs, 6 - # or the $out path, other than as command line arguments directly 7 - 8 1 # Mes --- Maxwell Equations of Software 9 2 # Copyright © 2017,2019 Jan Nieuwenhuizen <janneke@gnu.org> 10 3 # Copyright © 2017,2019 Jeremiah Orians ··· 24 17 # You should have received a copy of the GNU General Public License 25 18 # along with Mes. If not, see <http://www.gnu.org/licenses/>. 26 19 20 + # This is a translation of stage0-posix/stage0-posix/x86/mescc-tools-mini-kaem.kaem to nix 21 + # https://github.com/oriansj/stage0-posix-x86/blob/56e6b8df3e95f4bc04f8b420a4cd8c82c70b9efa/mescc-tools-mini-kaem.kaem 22 + # 23 + # We have access to mini-kaem at this point but it doesn't support substituting 24 + # environment variables. Without variables there's no way of passing in store inputs, 25 + # or the $out path, other than as command line arguments directly 26 + 27 27 # Warning all binaries prior to the use of blood-elf will not be readable by 28 28 # Objdump, you may need to use ndism or gdb to view the assembly in the binary. 29 29 30 30 { lib 31 31 , derivationWithMeta 32 + , hostPlatform 32 33 , hex0 33 34 , m2libc 34 35 , src 35 36 , version 37 + , platforms 38 + , stage0Arch 39 + , m2libcArch 40 + , baseAddress 36 41 }: 37 42 rec { 38 43 out = placeholder "out"; 39 44 45 + endianFlag = if hostPlatform.isLittleEndian then "--little-endian" else "--big-endian"; 46 + 47 + bloodFlags = lib.optional hostPlatform.is64bit "--64"; 48 + 40 49 run = pname: builder: args: 41 50 derivationWithMeta { 42 51 inherit pname version builder args; ··· 46 55 homepage = "https://github.com/oriansj/stage0-posix"; 47 56 license = licenses.gpl3Plus; 48 57 maintainers = teams.minimal-bootstrap.members; 49 - platforms = [ "i686-linux" ]; 58 + inherit platforms; 50 59 }; 51 60 }; 52 61 ··· 54 63 # Phase-1 Build hex1 from hex0 # 55 64 ################################ 56 65 57 - hex1 = run "hex1" hex0 ["${src}/x86/hex1_x86.hex0" out]; 66 + hex1 = run "hex1" hex0 ["${src}/${stage0Arch}/hex1_${stage0Arch}.hex0" out]; 58 67 59 68 # hex1 adds support for single character labels and is available in various forms 60 69 # in mescc-tools/x86_bootstrap to allow you various ways to verify correctness ··· 63 72 # Phase-2 Build hex2 from hex1 # 64 73 ################################ 65 74 66 - hex2-0 = run "hex2" hex1 ["${src}/x86/hex2_x86.hex1" out]; 75 + hex2-0 = run "hex2" hex1 ["${src}/${stage0Arch}/hex2_${stage0Arch}.hex1" out]; 67 76 68 77 # hex2 adds support for long labels and absolute addresses thus allowing it 69 78 # to function as an effective linker for later stages of the bootstrap ··· 74 83 # Phase-2b Build catm from hex2 # 75 84 ################################# 76 85 77 - catm = run "catm" hex2-0 ["${src}/x86/catm_x86.hex2" out]; 86 + catm = run "catm" hex2-0 ["${src}/${stage0Arch}/catm_${stage0Arch}.hex2" out]; 78 87 79 88 # catm removes the need for cat or shell support for redirection by providing 80 89 # equivalent functionality via catm output_file input1 input2 ... inputN ··· 83 92 # Phase-3 Build M0 from hex2 # 84 93 ############################## 85 94 86 - M0_hex2 = run "M0.hex2" catm [out "${src}/x86/ELF-i386.hex2" "${src}/x86/M0_x86.hex2"]; 95 + M0_hex2 = run "M0.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}.hex2" "${src}/${stage0Arch}/M0_${stage0Arch}.hex2"]; 87 96 M0 = run "M0" hex2-0 [M0_hex2 out]; 88 97 89 98 # M0 is the architecture specific version of M1 and is by design single 90 99 # architecture only and will be replaced by the C code version of M1 91 100 92 101 ################################ 93 - # Phase-4 Build cc_x86 from M0 # 102 + # Phase-4 Build cc_arch from M0 # 94 103 ################################ 95 104 96 - cc_x86-0_hex2 = run "cc_x86-0.hex2" M0 ["${src}/x86/cc_x86.M1" out]; 97 - cc_x86-1_hex2 = run "cc_x86-1.hex2" catm [out "${src}/x86/ELF-i386.hex2" cc_x86-0_hex2]; 98 - cc_x86 = run "cc_x86" hex2-0 [cc_x86-1_hex2 out]; 105 + cc_arch-0_hex2 = run "cc_arch-0.hex2" M0 ["${src}/${stage0Arch}/cc_${m2libcArch}.M1" out]; 106 + cc_arch-1_hex2 = run "cc_arch-1.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}.hex2" cc_arch-0_hex2]; 107 + cc_arch = run "cc_arch" hex2-0 [cc_arch-1_hex2 out]; 99 108 100 - ####################################### 101 - # Phase-5 Build M2-Planet from cc_x86 # 102 - ####################################### 109 + ######################################## 110 + # Phase-5 Build M2-Planet from cc_arch # 111 + ######################################## 103 112 104 113 M2-0_c = run "M2-0.c" catm [ 105 114 out 106 - "${m2libc}/x86/linux/bootstrap.c" 115 + "${m2libc}/${m2libcArch}/linux/bootstrap.c" 107 116 "${src}/M2-Planet/cc.h" 108 117 "${m2libc}/bootstrappable.c" 109 118 "${src}/M2-Planet/cc_globals.c" ··· 114 123 "${src}/M2-Planet/cc_macro.c" 115 124 "${src}/M2-Planet/cc.c" 116 125 ]; 117 - M2-0_M1 = run "M2-0.M1" cc_x86 [M2-0_c out]; 118 - M2-0-0_M1 = run "M2-0-0.M1" catm [out "${src}/x86/x86_defs.M1" "${src}/x86/libc-core.M1" M2-0_M1]; 126 + M2-0_M1 = run "M2-0.M1" cc_arch [M2-0_c out]; 127 + M2-0-0_M1 = run "M2-0-0.M1" catm [out "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1" "${m2libc}/${m2libcArch}/libc-core.M1" M2-0_M1]; 119 128 M2-0_hex2 = run "M2-0.hex2" M0 [M2-0-0_M1 out]; 120 - M2-0-0_hex2 = run "M2-0-0.hex2" catm [out "${src}/x86/ELF-i386.hex2" M2-0_hex2]; 129 + M2-0-0_hex2 = run "M2-0-0.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}.hex2" M2-0_hex2]; 121 130 M2 = run "M2" hex2-0 [M2-0-0_hex2 out]; 122 131 123 132 ############################################ ··· 125 134 ############################################ 126 135 127 136 blood-elf-0_M1 = run "blood-elf-0.M1" M2 [ 128 - "--architecture" "x86" 129 - "-f" "${m2libc}/x86/linux/bootstrap.c" 137 + "--architecture" m2libcArch 138 + "-f" "${m2libc}/${m2libcArch}/linux/bootstrap.c" 130 139 "-f" "${m2libc}/bootstrappable.c" 131 140 "-f" "${src}/mescc-tools/stringify.c" 132 141 "-f" "${src}/mescc-tools/blood-elf.c" ··· 134 143 "-o" out 135 144 ]; 136 145 137 - 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]; 146 + 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]; 138 147 blood-elf-0_hex2 = run "blood-elf-0.hex2" M0 [blood-elf-0-0_M1 out]; 139 - blood-elf-0-0_hex2 = run "blood-elf-0-0.hex2" catm [out "${m2libc}/x86/ELF-x86.hex2" blood-elf-0_hex2]; 148 + blood-elf-0-0_hex2 = run "blood-elf-0-0.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}.hex2" blood-elf-0_hex2]; 140 149 blood-elf-0 = run "blood-elf-0" hex2-0 [blood-elf-0-0_hex2 out]; 141 150 142 151 # This is the last stage where the binaries will not have debug info ··· 147 156 ##################################### 148 157 149 158 M1-macro-0_M1 = run "M1-macro-0.M1" M2 [ 150 - "--architecture" "x86" 151 - "-f" "${m2libc}/x86/linux/bootstrap.c" 159 + "--architecture" m2libcArch 160 + "-f" "${m2libc}/${m2libcArch}/linux/bootstrap.c" 152 161 "-f" "${m2libc}/bootstrappable.c" 153 162 "-f" "${src}/mescc-tools/stringify.c" 154 163 "-f" "${src}/mescc-tools/M1-macro.c" ··· 157 166 "-o" out 158 167 ]; 159 168 160 - M1-macro-0-footer_M1 = run "M1-macro-0-footer.M1" blood-elf-0 ["-f" M1-macro-0_M1 "--little-endian" "-o" out]; 161 - 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]; 169 + M1-macro-0-footer_M1 = run "M1-macro-0-footer.M1" blood-elf-0 (bloodFlags ++ ["-f" M1-macro-0_M1 endianFlag "-o" out]); 170 + 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]; 162 171 M1-macro-0_hex2 = run "M1-macro-0.hex2" M0 [M1-macro-0-0_M1 out]; 163 - M1-macro-0-0_hex2 = run "M1-macro-0-0.hex2" catm [out "${m2libc}/x86/ELF-x86-debug.hex2" M1-macro-0_hex2]; 172 + M1-macro-0-0_hex2 = run "M1-macro-0-0.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2" M1-macro-0_hex2]; 164 173 M1-0 = run "M1-0" hex2-0 [M1-macro-0-0_hex2 out]; 165 174 166 175 # This is the last stage where catm will need to be used and the last stage where ··· 172 181 ####################################### 173 182 174 183 hex2_linker-0_M1 = run "hex2_linker-0.M1" M2 [ 175 - "--architecture" "x86" 184 + "--architecture" m2libcArch 176 185 "-f" "${m2libc}/sys/types.h" 177 186 "-f" "${m2libc}/stddef.h" 178 - "-f" "${m2libc}/x86/linux/unistd.c" 179 - "-f" "${m2libc}/x86/linux/fcntl.c" 187 + "-f" "${m2libc}/${m2libcArch}/linux/unistd.c" 188 + "-f" "${m2libc}/${m2libcArch}/linux/fcntl.c" 180 189 "-f" "${m2libc}/fcntl.c" 181 - "-f" "${m2libc}/x86/linux/sys/stat.c" 190 + "-f" "${m2libc}/${m2libcArch}/linux/sys/stat.c" 182 191 "-f" "${m2libc}/stdlib.c" 183 192 "-f" "${m2libc}/stdio.h" 184 193 "-f" "${m2libc}/stdio.c" ··· 191 200 "-o" out 192 201 ]; 193 202 194 - hex2_linker-0-footer_M1 = run "hex2_linker-0-footer.M1" blood-elf-0 ["-f" hex2_linker-0_M1 "--little-endian" "-o" out]; 203 + hex2_linker-0-footer_M1 = run "hex2_linker-0-footer.M1" blood-elf-0 (bloodFlags ++ ["-f" hex2_linker-0_M1 endianFlag "-o" out]); 195 204 196 205 hex2_linker-0_hex2 = run "hex2_linker-0.hex2" M1-0 [ 197 - "--architecture" "x86" 198 - "--little-endian" 199 - "-f" "${m2libc}/x86/x86_defs.M1" 200 - "-f" "${m2libc}/x86/libc-full.M1" 206 + "--architecture" m2libcArch 207 + endianFlag 208 + "-f" "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1" 209 + "-f" "${m2libc}/${m2libcArch}/libc-full.M1" 201 210 "-f" hex2_linker-0_M1 202 211 "-f" hex2_linker-0-footer_M1 203 212 "-o" out 204 213 ]; 205 214 206 - hex2_linker-0-0_hex2 = run "hex2_linker-0-0.hex2" catm [out "${m2libc}/x86/ELF-x86-debug.hex2" hex2_linker-0_hex2]; 215 + hex2_linker-0-0_hex2 = run "hex2_linker-0-0.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2" hex2_linker-0_hex2]; 207 216 208 217 hex2-1 = run "hex2-1" hex2-0 [hex2_linker-0-0_hex2 out]; 209 218 ··· 215 224 ################################### 216 225 217 226 M1-macro-1_M1 = run "M1-macro-1.M1" M2 [ 218 - "--architecture" "x86" 227 + "--architecture" m2libcArch 219 228 "-f" "${m2libc}/sys/types.h" 220 229 "-f" "${m2libc}/stddef.h" 221 - "-f" "${m2libc}/x86/linux/fcntl.c" 230 + "-f" "${m2libc}/${m2libcArch}/linux/fcntl.c" 222 231 "-f" "${m2libc}/fcntl.c" 223 - "-f" "${m2libc}/x86/linux/unistd.c" 232 + "-f" "${m2libc}/${m2libcArch}/linux/unistd.c" 224 233 "-f" "${m2libc}/string.c" 225 234 "-f" "${m2libc}/stdlib.c" 226 235 "-f" "${m2libc}/stdio.h" ··· 232 241 "-o" out 233 242 ]; 234 243 235 - M1-macro-1-footer_M1 = run "M1-macro-1-footer.M1" blood-elf-0 ["-f" M1-macro-1_M1 "--little-endian" "-o" out]; 244 + M1-macro-1-footer_M1 = run "M1-macro-1-footer.M1" blood-elf-0 (bloodFlags ++ ["-f" M1-macro-1_M1 endianFlag "-o" out]); 236 245 237 246 M1-macro-1_hex2 = run "M1-macro-1.hex2" M1-0 [ 238 - "--architecture" "x86" 239 - "--little-endian" 240 - "-f" "${m2libc}/x86/x86_defs.M1" 241 - "-f" "${m2libc}/x86/libc-full.M1" 247 + "--architecture" m2libcArch 248 + endianFlag 249 + "-f" "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1" 250 + "-f" "${m2libc}/${m2libcArch}/libc-full.M1" 242 251 "-f" M1-macro-1_M1 243 252 "-f" M1-macro-1-footer_M1 244 253 "-o" out 245 254 ]; 246 255 247 256 M1 = run "M1" hex2-1 [ 248 - "--architecture" "x86" 249 - "--little-endian" 250 - "--base-address" "0x8048000" 251 - "-f" "${m2libc}/x86/ELF-x86-debug.hex2" 257 + "--architecture" m2libcArch 258 + endianFlag 259 + "--base-address" baseAddress 260 + "-f" "${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2" 252 261 "-f" M1-macro-1_hex2 253 262 "-o" out 254 263 ]; ··· 258 267 ###################################### 259 268 260 269 hex2_linker-2_M1 = run "hex2_linker-2.M1" M2 [ 261 - "--architecture" "x86" 270 + "--architecture" m2libcArch 262 271 "-f" "${m2libc}/sys/types.h" 263 272 "-f" "${m2libc}/stddef.h" 264 - "-f" "${m2libc}/x86/linux/unistd.c" 265 - "-f" "${m2libc}/x86/linux/fcntl.c" 273 + "-f" "${m2libc}/${m2libcArch}/linux/unistd.c" 274 + "-f" "${m2libc}/${m2libcArch}/linux/fcntl.c" 266 275 "-f" "${m2libc}/fcntl.c" 267 - "-f" "${m2libc}/x86/linux/sys/stat.c" 276 + "-f" "${m2libc}/${m2libcArch}/linux/sys/stat.c" 268 277 "-f" "${m2libc}/stdlib.c" 269 278 "-f" "${m2libc}/stdio.h" 270 279 "-f" "${m2libc}/stdio.c" ··· 277 286 "-o" out 278 287 ]; 279 288 280 - hex2_linker-2-footer_M1 = run "hex2_linker-2-footer.M1" blood-elf-0 ["-f" hex2_linker-2_M1 "--little-endian" "-o" out]; 289 + hex2_linker-2-footer_M1 = run "hex2_linker-2-footer.M1" blood-elf-0 (bloodFlags ++ ["-f" hex2_linker-2_M1 endianFlag "-o" out]); 281 290 282 291 hex2_linker-2_hex2 = run "hex2_linker-2.hex2" M1 [ 283 - "--architecture" "x86" 284 - "--little-endian" 285 - "-f" "${m2libc}/x86/x86_defs.M1" 286 - "-f" "${m2libc}/x86/libc-full.M1" 292 + "--architecture" m2libcArch 293 + endianFlag 294 + "-f" "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1" 295 + "-f" "${m2libc}/${m2libcArch}/libc-full.M1" 287 296 "-f" hex2_linker-2_M1 288 297 "-f" hex2_linker-2-footer_M1 289 298 "-o" out 290 299 ]; 291 300 292 301 hex2 = run "hex2" hex2-1 [ 293 - "--architecture" "x86" 294 - "--little-endian" 295 - "--base-address" "0x8048000" 296 - "-f" "${m2libc}/x86/ELF-x86-debug.hex2" 302 + "--architecture" m2libcArch 303 + endianFlag 304 + "--base-address" baseAddress 305 + "-f" "${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2" 297 306 "-f" hex2_linker-2_hex2 298 307 "-o" out 299 308 ]; ··· 303 312 ###################################### 304 313 305 314 kaem_M1 = run "kaem.M1" M2 [ 306 - "--architecture" "x86" 315 + "--architecture" m2libcArch 307 316 "-f" "${m2libc}/sys/types.h" 308 317 "-f" "${m2libc}/stddef.h" 309 318 "-f" "${m2libc}/string.c" 310 - "-f" "${m2libc}/x86/linux/unistd.c" 311 - "-f" "${m2libc}/x86/linux/fcntl.c" 319 + "-f" "${m2libc}/${m2libcArch}/linux/unistd.c" 320 + "-f" "${m2libc}/${m2libcArch}/linux/fcntl.c" 312 321 "-f" "${m2libc}/fcntl.c" 313 322 "-f" "${m2libc}/stdlib.c" 314 323 "-f" "${m2libc}/stdio.h" ··· 322 331 "-o" out 323 332 ]; 324 333 325 - kaem-footer_M1 = run "kaem-footer.M1" blood-elf-0 ["-f" kaem_M1 "--little-endian" "-o" out]; 334 + kaem-footer_M1 = run "kaem-footer.M1" blood-elf-0 (bloodFlags ++ ["-f" kaem_M1 endianFlag "-o" out]); 326 335 327 336 kaem_hex2 = run "kaem.hex2" M1 [ 328 - "--architecture" "x86" 329 - "--little-endian" 330 - "-f" "${m2libc}/x86/x86_defs.M1" 331 - "-f" "${m2libc}/x86/libc-full.M1" 337 + "--architecture" m2libcArch 338 + endianFlag 339 + "-f" "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1" 340 + "-f" "${m2libc}/${m2libcArch}/libc-full.M1" 332 341 "-f" kaem_M1 333 342 "-f" kaem-footer_M1 334 343 "-o" out 335 344 ]; 336 345 337 346 kaem-unwrapped = run "kaem-unwrapped" hex2 [ 338 - "--architecture" "x86" 339 - "--little-endian" 340 - "-f" "${m2libc}/x86/ELF-x86-debug.hex2" 347 + "--architecture" m2libcArch 348 + endianFlag 349 + "-f" "${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2" 341 350 "-f" kaem_hex2 342 - "--base-address" "0x8048000" 351 + "--base-address" baseAddress 343 352 "-o" out 344 353 ]; 345 354 }