summaryrefslogtreecommitdiff
path: root/boards
diff options
context:
space:
mode:
authorNathan Ringo <nathan@remexre.com>2024-09-01 20:49:26 -0500
committerNathan Ringo <nathan@remexre.com>2024-09-01 20:49:26 -0500
commit8cb34498eceef231927c444507b6787128c5f0d8 (patch)
tree0fadd76c82b88d22f993d2333e56a9200f656012 /boards
parent386df39c9866a4d945de46ef0dcab2363c674e0e (diff)
Move everything over to the new organization.
Diffstat (limited to 'boards')
-rw-r--r--boards/configure.py45
-rw-r--r--boards/default.nix72
-rw-r--r--boards/qemu-virt/default.nix11
-rw-r--r--boards/qemu-virt/qemu-virt.s21
4 files changed, 98 insertions, 51 deletions
diff --git a/boards/configure.py b/boards/configure.py
new file mode 100644
index 0000000..5b01652
--- /dev/null
+++ b/boards/configure.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+from argparse import ArgumentParser
+from ninja.ninja_syntax import Writer as Ninja
+from os import getenv
+from pathlib import Path
+
+
+def main():
+ arg_parser = ArgumentParser()
+ arg_parser.add_argument("arch_name")
+ arg_parser.add_argument("board_name")
+ arg_parser.add_argument("libkernel")
+ arg_parser.add_argument("srcdir")
+ args = arg_parser.parse_args()
+
+ libkernel = Path(args.libkernel).resolve() / "lib/libvernos_kernel.a"
+ srcdir = Path(args.srcdir).resolve()
+ objdir = Path("obj")
+ objdir.mkdir()
+
+ linker_script = str(srcdir / f"{args.board_name}.ld")
+
+ objs: list[str] = []
+ with open("build.ninja", "w") as f:
+ ninja = Ninja(f)
+
+ # Inherit some environment variables.
+ for var in ["AS", "ASFLAGS", "LD", "LDFLAGS"]:
+ 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")
+
+ for path in srcdir.iterdir():
+ if path.suffix != ".s":
+ continue
+ obj = str(objdir / f"{path.stem}.o")
+ ninja.build(obj, "as", str(path))
+ objs.append(obj)
+ ninja.build("kernel.elf", "ld", objs + [str(libkernel)])
+
+
+if __name__ == "__main__":
+ main()
diff --git a/boards/default.nix b/boards/default.nix
index dd09255..6c8c8a9 100644
--- a/boards/default.nix
+++ b/boards/default.nix
@@ -1,33 +1,55 @@
-{ libkernel, pkgs }:
+{
+ arches,
+ libkernel,
+ nixpkgs,
+ pkgs,
+ python,
+ system,
+}:
let
- mkKernel = { name, asmFile, linkerScript }:
- pkgs.stdenvNoCC.mkDerivation {
- pname = "${libkernel.pname}-${name}";
- version = libkernel.version;
- inherit asmFile linkerScript;
+ mkKernel =
+ path:
+ let
+ args = import path;
+ arch = arches.${args.vernos-arch};
+ libkernel-arch = libkernel.${args.vernos-arch};
+ pkgs-arch = import nixpkgs {
+ inherit system;
+ crossSystem.config = arch.crossSystem;
+ };
+ in
- nativeBuildInputs = [ pkgs.stdenv.cc.bintools.bintools ];
+ pkgs-arch.stdenvNoCC.mkDerivation (
+ {
+ pname = "vernos-kernel-${args.vernos-board}";
+ version = libkernel-arch.version;
- dontUnpack = true;
- buildPhase = ''
- runHook preBuild
+ nativeBuildInputs = [
+ pkgs.ninja
+ pkgs-arch.stdenv.cc.bintools.bintools
+ python
+ ];
- riscv64-unknown-none-elf-as -g -march=rv64gc -mabi=lp64d -o asm.o \
- $asmFile
+ dontUnpack = true;
+ configurePhase = ''
+ runHook preConfigure
+ python3 ${./configure.py} ${args.vernos-arch} ${args.vernos-board} \
+ ${libkernel-arch} $src
+ runHook postConfigure
+ '';
+ installPhase = ''
+ runHook preInstall
+ install -Dt $out kernel.elf
+ runHook postInstall
+ '';
- riscv64-unknown-none-elf-ld --gc-sections -T$linkerScript -o kernel.elf \
- asm.o ${libkernel}/lib/libkernel.a
+ AS = "${arch.crossSystem}-as";
+ LD = "${arch.crossSystem}-ld";
+ }
+ // args
+ );
- runHook postBuild
- '';
- installPhase = ''
- runHook preInstall
- install -Dt $out kernel.elf
- runHook postInstall
- '';
- };
+in
-in pkgs.lib.recurseIntoAttrs {
- qemu-virt = pkgs.callPackage ./qemu-virt { inherit mkKernel; };
-}
+nixpkgs.lib.recurseIntoAttrs { qemu-virt = mkKernel ./qemu-virt; }
diff --git a/boards/qemu-virt/default.nix b/boards/qemu-virt/default.nix
index e41d924..d80d5d4 100644
--- a/boards/qemu-virt/default.nix
+++ b/boards/qemu-virt/default.nix
@@ -1,7 +1,8 @@
-{ mkKernel }:
+{
+ vernos-arch = "riscv64";
+ vernos-board = "qemu-virt";
+ src = ./.;
-mkKernel {
- name = "qemu-virt";
- asmFile = ./qemu-virt.s;
- linkerScript = ./qemu-virt.ld;
+ ASFLAGS = "-march=rv64gc -mabi=lp64d";
+ LDFLAGS = "--gc-sections";
}
diff --git a/boards/qemu-virt/qemu-virt.s b/boards/qemu-virt/qemu-virt.s
index c7e7642..0d69d4d 100644
--- a/boards/qemu-virt/qemu-virt.s
+++ b/boards/qemu-virt/qemu-virt.s
@@ -11,11 +11,6 @@ _start:
csrr tp, mhartid
bnez tp, wait_for_hart0
- ## Set up console_strict_flush.
- la t0, console_strict_flush
- la t1, CONSOLE_STRICT_FLUSH
- sd t0, (t1)
-
## Set up hart0's stack.
la sp, hart0_initial_stack_top
@@ -89,19 +84,3 @@ wait_for_hart0:
wfi
j wait_for_hart0
.size wait_for_hart0, . - wait_for_hart0
-
-.section .text
-
-.type console_strict_flush, STT_FUNC
-console_strict_flush:
- li t0, 0x10000000
-1:
- c.beqz a1, 2f
- lb t1, (a0)
- sb t1, (t0)
- addi a0, a0, 1
- addi a1, a1, -1
- j 1b
-2:
- ret
-.size console_strict_flush, . - console_strict_flush