diff options
author | Nathan Ringo <nathan@remexre.com> | 2024-09-01 21:40:34 -0500 |
---|---|---|
committer | Nathan Ringo <nathan@remexre.com> | 2024-09-01 21:40:34 -0500 |
commit | 158b7123b6a50b2e8d37529e01ccd94c9106c11a (patch) | |
tree | 9af446b259b8ac99524843e215513355668908ef | |
parent | 8cb34498eceef231927c444507b6787128c5f0d8 (diff) |
Fix debuginfo and restore apps.
-rw-r--r-- | boards/configure.py | 10 | ||||
-rw-r--r-- | boards/default.nix | 5 | ||||
-rw-r--r-- | crates/Cargo.toml | 6 | ||||
-rw-r--r-- | flake.nix | 151 |
4 files changed, 90 insertions, 82 deletions
diff --git a/boards/configure.py b/boards/configure.py index 5b01652..cbe255a 100644 --- a/boards/configure.py +++ b/boards/configure.py @@ -25,12 +25,14 @@ def main(): ninja = Ninja(f) # Inherit some environment variables. - for var in ["AS", "ASFLAGS", "LD", "LDFLAGS"]: + for var in ["AS", "ASFLAGS", "LD", "LDFLAGS", "STRIP"]: ninja.variable(var, getenv(var)) # Add rules to assemble and link. ninja.rule("as", "$AS $ASFLAGS -g -o $out $in") ninja.rule("ld", f"$LD $LDFLAGS -T{linker_script} -o $out $in") + ninja.rule("strip", f"$STRIP -o $out $in") + ninja.rule("strip-onlysyms", f"$STRIP --only-keep-debug -o $out $in") for path in srcdir.iterdir(): if path.suffix != ".s": @@ -38,7 +40,11 @@ def main(): obj = str(objdir / f"{path.stem}.o") ninja.build(obj, "as", str(path)) objs.append(obj) - ninja.build("kernel.elf", "ld", objs + [str(libkernel)]) + ninja.build("vernos_kernel_unstripped.elf", "ld", objs + [str(libkernel)]) + ninja.build("vernos_kernel.elf", "strip", "vernos_kernel_unstripped.elf") + ninja.build( + "vernos_kernel.sym", "strip-onlysyms", "vernos_kernel_unstripped.elf" + ) if __name__ == "__main__": diff --git a/boards/default.nix b/boards/default.nix index 6c8c8a9..de0eb34 100644 --- a/boards/default.nix +++ b/boards/default.nix @@ -40,12 +40,15 @@ let ''; installPhase = '' runHook preInstall - install -Dt $out kernel.elf + install -m0755 -Dt $out vernos_kernel.elf + install -m0644 -Dt $out vernos_kernel.sym runHook postInstall ''; + dontFixup = true; AS = "${arch.crossSystem}-as"; LD = "${arch.crossSystem}-ld"; + STRIP = "${arch.crossSystem}-strip"; } // args ); diff --git a/crates/Cargo.toml b/crates/Cargo.toml index 855d815..dd1f42a 100644 --- a/crates/Cargo.toml +++ b/crates/Cargo.toml @@ -1,3 +1,9 @@ [workspace] members = ["alloc_buddy", "alloc_physmem_free_list", "device_tree", "driver_riscv_timer", "kernel", "utils"] resolver = "2" + +[profile.release] +codegen-units = 1 +debug = true +lto = true +overflow-checks = true @@ -57,95 +57,88 @@ ; }; }; - in - /* - pkgsHost = import nixpkgs { - inherit system; - crossSystem.config = "riscv64-unknown-none-elf"; - }; - packages = rec { - boards = import ./boards { - inherit libkernel; - pkgs = pkgsHost; - }; - libkernel = pkgsBuild.callPackage ./kernel { inherit rust; }; - }; - run-vm = pkgsBuild.writeShellApplication { - name = "run-vm"; + run-qemu-virt = pkgs.writeShellApplication { + name = "run-qemu-virt"; - runtimeInputs = [ pkgsBuild.qemu ]; + runtimeInputs = [ pkgs.qemu ]; - text = '' - set -x - qemu-system-riscv64 \ - -machine virt \ - -m 1G \ - -nographic \ - -bios none \ - -kernel ${packages.boards.qemu-virt}/kernel.elf \ - "$@" - ''; - }; - */ + text = '' + set -x + qemu-system-riscv64 \ + -machine virt \ + -m 1G \ + -nographic \ + -bios none \ + -kernel ${packages.kernel.qemu-virt}/vernos_kernel.elf \ + "$@" + ''; + }; + in { - /* - apps = { - default = { - type = "app"; - program = pkgsBuild.lib.getExe run-vm; - }; + apps = { + default = { + type = "app"; + program = pkgs.lib.getExe run-qemu-virt; + }; - run = { - type = "app"; - program = pkgsBuild.lib.getExe run-vm; - }; + run = { + type = "app"; + program = pkgs.lib.getExe run-qemu-virt; + }; - debug = { - type = "app"; - program = pkgsBuild.lib.getExe ( - pkgsBuild.writeShellApplication { - name = "run-vm-debug"; - runtimeInputs = [ run-vm ]; - text = '' - port=$(( 1000 * ("$(id -u)" - 990) )) - run-vm -gdb tcp::$port -S "$@" - ''; - } - ); - }; + debug = { + type = "app"; + program = pkgs.lib.getExe ( + pkgs.writeShellApplication { + name = "run-vm-debug"; + runtimeInputs = [ run-qemu-virt ]; + text = '' + port=$(( 1000 * ("$(id -u)" - 990) )) + run-qemu-virt -gdb tcp::$port -S "$@" + ''; + } + ); + }; - gdb = { - type = "app"; - program = pkgsBuild.lib.getExe ( - pkgsBuild.writeShellApplication { - name = "gdb"; - runtimeInputs = [ toolchain ]; - text = '' - port=$(( 1000 * ("$(id -u)" - 990) )) - rust-gdb ${packages.boards.qemu-virt}/kernel.elf \ - -ex "target remote 127.0.0.1:$port" \ - -ex "set riscv use-compressed-breakpoints yes" \ - -ex "layout asm" \ - -ex "layout regs" \ - -ex "focus cmd" \ - -ex "tbreak hart0_boot" \ - -ex "c" - ''; - } - ); - }; + gdb = { + type = "app"; + program = pkgs.lib.getExe ( + pkgs.writeShellApplication { + name = "gdb"; + text = '' + port=$(( 1000 * ("$(id -u)" - 990) )) + rust-gdb ${packages.kernel.qemu-virt}/vernos_kernel.elf \ + -ex "symbol-file ${packages.kernel.qemu-virt}/vernos_kernel.sym" \ + -ex "target remote 127.0.0.1:$port" \ + -ex "set riscv use-compressed-breakpoints yes" \ + -ex "layout asm" \ + -ex "layout regs" \ + -ex "focus cmd" \ + -ex "tbreak hart0_boot" \ + -ex "c" + ''; + } + ); }; - */ + }; devShells.default = pkgs.mkShell { - nativeBuildInputs = [ - (pkgs.callPackage ./nix/miri.nix { inherit fenix; }) - pkgs.cargo-watch - pkgs.qemu - python - rust-toolchain - ]; + nativeBuildInputs = + [ + (pkgs.callPackage ./nix/miri.nix { inherit fenix; }) + pkgs.cargo-watch + pkgs.qemu + python + rust-toolchain + ] + ++ (builtins.map ( + { crossSystem, ... }: + (import nixpkgs { + inherit system; + crossSystem.config = crossSystem; + }).stdenv.cc.bintools.bintools + ) (builtins.attrValues arches)); }; packages = flake-utils.lib.flattenTree packages; |