From c242e8c507db0817ba962b38b77fcd84f5832d14 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Fri, 5 Apr 2024 10:23:28 +0800 Subject: [PATCH 1/3] chore: move npc devshell to root directory --- flake.lock | 151 ++++++++++++++++++++++++++++++++++- flake.nix | 67 +++++++++++++++- npc/.envrc | 2 +- npc/flake.lock | 210 ------------------------------------------------- npc/flake.nix | 137 -------------------------------- 5 files changed, 215 insertions(+), 352 deletions(-) delete mode 100644 npc/flake.lock delete mode 100644 npc/flake.nix diff --git a/flake.lock b/flake.lock index 36b9a39..247c2b9 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -18,6 +34,45 @@ "type": "github" } }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1709237383, @@ -34,10 +89,89 @@ "type": "github" } }, + "nixpkgs-circt162": { + "locked": { + "lastModified": 1705645507, + "narHash": "sha256-tX3vipIAmNDBA8WNWG4oY4KyTfnm2YieTHO2BhG8ISA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7995cae3ad60e3d6931283d650d7f43d31aaa5c7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7995cae3ad60e3d6931283d650d7f43d31aaa5c7", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1710695816, + "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "614b4613980a522ba49f0d194531beddbb7220d3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nur-xin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1710242657, + "narHash": "sha256-tgaILHKZH6vC8P8N8NBMNQ/XIpTY72zMojlGLPLPLZk=", + "ref": "refs/heads/master", + "rev": "6a499c8371c6a14d11a8c2fcc9f233e7b8e688a0", + "revCount": 148, + "type": "git", + "url": "https://git.xinyang.life/xin/nur.git" + }, + "original": { + "type": "git", + "url": "https://git.xinyang.life/xin/nur.git" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1712055707, + "narHash": "sha256-4XLvuSIDZJGS17xEwSrNuJLL7UjDYKGJSbK1WWX2AK8=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "e35aed5fda3cc79f88ed7f1795021e559582093a", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "nixpkgs-circt162": "nixpkgs-circt162", + "nur-xin": "nur-xin", + "pre-commit-hooks": "pre-commit-hooks" } }, "systems": { @@ -54,6 +188,21 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 3a07d79..d3a27fc 100644 --- a/flake.nix +++ b/flake.nix @@ -1,13 +1,30 @@ { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + nixpkgs-circt162.url = "github:NixOS/nixpkgs/7995cae3ad60e3d6931283d650d7f43d31aaa5c7"; flake-utils.url = "github:numtide/flake-utils"; + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + nur-xin = { + url = "git+https://git.xinyang.life/xin/nur.git"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = { self, ... }@inputs: with inputs; flake-utils.lib.eachDefaultSystem (system: let - pkgs = nixpkgs.legacyPackages.${system}; + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + overlays = [ + (self: super: { + nvboard = nur-xin.legacyPackages.${system}.nvboard; + }) + ]; + }; crossPkgs = import nixpkgs { localSystem = system; crossSystem = { @@ -20,6 +37,18 @@ }; in { + checks = { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + trim-trailing-whitespace.enable = true; + clang-format = { + enable = true; + types_or = pkgs.lib.mkForce [ "c" "c++" ]; + }; + }; + }; + }; packages.nemu = pkgs.callPackage ./nemu { am-kernels = self.packages.${system}.am-kernels; }; packages.abstract-machine = crossPkgs.callPackage ./abstract-machine { isa = "riscv"; platform = "nemu"; }; @@ -27,7 +56,7 @@ pname = "am-kernels-cmake"; version = "2024.02.18"; - src = ./am-kernels; + src = ./am-kernels; nativeBuildInputs = [ pkgs.cmake @@ -44,7 +73,7 @@ self.packages.${system}.abstract-machine ]; }; - + devShells.nemu = pkgs.mkShell { packages = with pkgs; [ clang-tools @@ -54,6 +83,38 @@ self.packages.${system}.nemu ]; }; + + devShells.npc = with pkgs; mkShell { + inherit (self.checks.${system}.pre-commit-check) shellHook; + CHISEL_FIRTOOL_PATH = "${nixpkgs-circt162.legacyPackages.${system}.circt}/bin"; + packages = [ + clang-tools + cmake + ninja + coursier + espresso + bloop + + gdb + jre + + gtkwave + ]; + + nativeBuildInputs = [ + cmake + sbt + nvboard + nixpkgs-circt162.legacyPackages.${system}.circt + yosys + cli11 + ]; + + buildInputs = [ + verilator + nvboard + ] ++ self.checks.${system}.pre-commit-check.enabledPackages; + }; } ); } diff --git a/npc/.envrc b/npc/.envrc index 3550a30..3f3af37 100644 --- a/npc/.envrc +++ b/npc/.envrc @@ -1 +1 @@ -use flake +use flake ..#npc diff --git a/npc/flake.lock b/npc/flake.lock deleted file mode 100644 index f37f6be..0000000 --- a/npc/flake.lock +++ /dev/null @@ -1,210 +0,0 @@ -{ - "nodes": { - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1696426674, - "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_2": { - "inputs": { - "systems": "systems_2" - }, - "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "gitignore": { - "inputs": { - "nixpkgs": [ - "pre-commit-hooks", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1709087332, - "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "gitignore.nix", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1709961763, - "narHash": "sha256-6H95HGJHhEZtyYA3rIQpvamMKAGoa8Yh2rFV29QnuGw=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "3030f185ba6a4bf4f18b87f345f104e6a6961f34", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-circt162": { - "locked": { - "lastModified": 1705645507, - "narHash": "sha256-tX3vipIAmNDBA8WNWG4oY4KyTfnm2YieTHO2BhG8ISA=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "7995cae3ad60e3d6931283d650d7f43d31aaa5c7", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "7995cae3ad60e3d6931283d650d7f43d31aaa5c7", - "type": "github" - } - }, - "nixpkgs-stable": { - "locked": { - "lastModified": 1710695816, - "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "614b4613980a522ba49f0d194531beddbb7220d3", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-23.11", - "repo": "nixpkgs", - "type": "github" - } - }, - "nur-xin": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1707020873, - "narHash": "sha256-+dNltc7tjgTIyle/I/5siQ5IvPwu+R5Uf6e24CmjLNk=", - "ref": "refs/heads/master", - "rev": "8142717e7154dbaadee0679f0224fe75cebb1735", - "revCount": 147, - "type": "git", - "url": "https://git.xinyang.life/xin/nur.git" - }, - "original": { - "type": "git", - "url": "https://git.xinyang.life/xin/nur.git" - } - }, - "pre-commit-hooks": { - "inputs": { - "flake-compat": "flake-compat", - "flake-utils": "flake-utils_2", - "gitignore": "gitignore", - "nixpkgs": [ - "nixpkgs" - ], - "nixpkgs-stable": "nixpkgs-stable" - }, - "locked": { - "lastModified": 1712055707, - "narHash": "sha256-4XLvuSIDZJGS17xEwSrNuJLL7UjDYKGJSbK1WWX2AK8=", - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "e35aed5fda3cc79f88ed7f1795021e559582093a", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, - "root": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs", - "nixpkgs-circt162": "nixpkgs-circt162", - "nur-xin": "nur-xin", - "pre-commit-hooks": "pre-commit-hooks" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "systems_2": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/npc/flake.nix b/npc/flake.nix deleted file mode 100644 index a0bd61e..0000000 --- a/npc/flake.nix +++ /dev/null @@ -1,137 +0,0 @@ -{ - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - nixpkgs-circt162.url = "github:NixOS/nixpkgs/7995cae3ad60e3d6931283d650d7f43d31aaa5c7"; - flake-utils.url = "github:numtide/flake-utils"; - pre-commit-hooks = { - url = "github:cachix/pre-commit-hooks.nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - nur-xin = { - url = "git+https://git.xinyang.life/xin/nur.git"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; - - outputs = { self, ... }@inputs: with inputs; - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { inherit system; config.allowUnfree = true; }// - { nur.xin = nur-xin.legacyPackages.${system}; }; - in - { - checks = { - pre-commit-check = pre-commit-hooks.lib.${system}.run { - src = ./.; - hooks = { - trim-trailing-whitespace.enable = true; - clang-format = { - enable = true; - types_or = pkgs.lib.mkForce [ "c" "c++" ]; - }; - }; - }; - }; - devShells.default = with pkgs; mkShell { - inherit (self.checks.${system}.pre-commit-check) shellHook; - buildInputs = self.checks.${system}.pre-commit-check.enabledPackages; - CHISEL_FIRTOOL_PATH = "${nixpkgs-circt162.legacyPackages.${system}.circt}/bin"; - packages = [ - clang-tools - cmake - ninja - coursier - espresso - bloop - - gdb - jre - - gtkwave - ]; - - inputsFrom = [ self.packages.${system}.default ]; - }; - packages.default = with pkgs; clangStdenv.mkDerivation { - name = "npc"; - version = "0.0.1"; - src = ./.; - nativeBuildInputs = [ - cmake - sbt - nur.xin.nvboard - nixpkgs-circt162.legacyPackages.${system}.circt - yosys - cli11 - ]; - buildInputs = [ - verilator - nur.xin.nvboard - ]; - - NEMU_HOME="/home/xin/repo/ysyx-workbench/nemu"; - }; - - # This version (1.43.0) of circt does not exist in nixpkgs - # and Chisel 5.1.0 specifically build against it, so here we are. - # Ref: https://github.com/NixOS/nixpkgs/blob/b6465c8/pkgs/development/compilers/circt/default.nix - packages.circt = - with pkgs; - let - pythonEnv = python3.withPackages (ps: [ ps.psutil ]); - in - stdenv.mkDerivation rec { - pname = "circt"; - version = "1.43.0"; - src = fetchFromGitHub { - owner = "llvm"; - repo = "circt"; - rev = "firtool-${version}"; - sha256 = "sha256-RkjigboswLkLgLkgOGahQLIygCkC3Q9rbVw3LqIzREY="; - fetchSubmodules = true; - }; - - requiredSystemFeatures = [ "big-parallel" ]; - - nativeBuildInputs = [ cmake ninja git pythonEnv ]; - - cmakeDir = "../llvm/llvm"; - cmakeFlags = [ - "-DLLVM_ENABLE_BINDINGS=OFF" - "-DLLVM_ENABLE_OCAMLDOC=OFF" - "-DLLVM_BUILD_EXAMPLES=OFF" - "-DLLVM_OPTIMIZED_TABLEGEN=ON" - "-DLLVM_ENABLE_PROJECTS=mlir" - "-DLLVM_EXTERNAL_PROJECTS=circt" - "-DLLVM_EXTERNAL_CIRCT_SOURCE_DIR=.." - "-DCIRCT_LLHD_SIM_ENABLED=OFF" - ]; - - LIT_FILTER_OUT = if stdenv.cc.isClang then "CIRCT :: Target/ExportSystemC/.*\.mlir" else null; - - preConfigure = '' - find ./test -name '*.mlir' -exec sed -i 's|/usr/bin/env|${coreutils}/bin/env|g' {} \; - ''; - - installPhase = '' - runHook preInstall - mkdir -p $out/bin - mv bin/{{fir,hls}tool,circt-{as,dis,lsp-server,opt,reduce,translate}} $out/bin - runHook postInstall - ''; - - doCheck = true; - checkTarget = "check-circt check-circt-integration"; - - meta = { - description = "Circuit IR compilers and tools"; - homepage = "https://circt.org/"; - license = lib.licenses.asl20; - maintainers = with lib.maintainers; [ sharzy ]; - platforms = lib.platforms.all; - }; - }; - } - ); -} - From 6f7d7ba383e6ab494a78456e1f562fed24bbcddb Mon Sep 17 00:00:00 2001 From: xinyangli Date: Fri, 5 Apr 2024 10:40:55 +0800 Subject: [PATCH 2/3] chore: move components to seperate folder --- npc/core/src/main/scala/{ => components}/ALU.scala | 0 npc/core/src/main/scala/{ => components}/Mem.scala | 0 npc/core/src/main/scala/{ => components}/ProgramCounter.scala | 0 npc/core/src/main/scala/{ => components}/RegisterFile.scala | 0 npc/core/src/main/scala/{ => top}/FlowMain.scala | 0 npc/core/src/main/scala/{ => utils}/Keyboard.scala | 0 npc/core/src/main/scala/{ => utils}/SegControllerGenerator.scala | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename npc/core/src/main/scala/{ => components}/ALU.scala (100%) rename npc/core/src/main/scala/{ => components}/Mem.scala (100%) rename npc/core/src/main/scala/{ => components}/ProgramCounter.scala (100%) rename npc/core/src/main/scala/{ => components}/RegisterFile.scala (100%) rename npc/core/src/main/scala/{ => top}/FlowMain.scala (100%) rename npc/core/src/main/scala/{ => utils}/Keyboard.scala (100%) rename npc/core/src/main/scala/{ => utils}/SegControllerGenerator.scala (100%) diff --git a/npc/core/src/main/scala/ALU.scala b/npc/core/src/main/scala/components/ALU.scala similarity index 100% rename from npc/core/src/main/scala/ALU.scala rename to npc/core/src/main/scala/components/ALU.scala diff --git a/npc/core/src/main/scala/Mem.scala b/npc/core/src/main/scala/components/Mem.scala similarity index 100% rename from npc/core/src/main/scala/Mem.scala rename to npc/core/src/main/scala/components/Mem.scala diff --git a/npc/core/src/main/scala/ProgramCounter.scala b/npc/core/src/main/scala/components/ProgramCounter.scala similarity index 100% rename from npc/core/src/main/scala/ProgramCounter.scala rename to npc/core/src/main/scala/components/ProgramCounter.scala diff --git a/npc/core/src/main/scala/RegisterFile.scala b/npc/core/src/main/scala/components/RegisterFile.scala similarity index 100% rename from npc/core/src/main/scala/RegisterFile.scala rename to npc/core/src/main/scala/components/RegisterFile.scala diff --git a/npc/core/src/main/scala/FlowMain.scala b/npc/core/src/main/scala/top/FlowMain.scala similarity index 100% rename from npc/core/src/main/scala/FlowMain.scala rename to npc/core/src/main/scala/top/FlowMain.scala diff --git a/npc/core/src/main/scala/Keyboard.scala b/npc/core/src/main/scala/utils/Keyboard.scala similarity index 100% rename from npc/core/src/main/scala/Keyboard.scala rename to npc/core/src/main/scala/utils/Keyboard.scala diff --git a/npc/core/src/main/scala/SegControllerGenerator.scala b/npc/core/src/main/scala/utils/SegControllerGenerator.scala similarity index 100% rename from npc/core/src/main/scala/SegControllerGenerator.scala rename to npc/core/src/main/scala/utils/SegControllerGenerator.scala From 90be25efc4db901af1d83fdaff25a5d6c56cc09e Mon Sep 17 00:00:00 2001 From: xinyangli Date: Fri, 5 Apr 2024 11:30:52 +0800 Subject: [PATCH 3/3] ci: add npc difftest --- .gitea/workflows/npc-test.yml | 22 +++++++++ flake.nix | 6 +++ nemu/configs/riscv32-lib_defconfig | 72 ++++++++++++++++++++++++++++++ nemu/default.nix | 13 +++--- nemu/scripts/build.mk | 5 +++ npc/CMakeLists.txt | 7 +-- npc/csrc/Flow/CMakeLists.txt | 6 +++ 7 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 .gitea/workflows/npc-test.yml create mode 100644 nemu/configs/riscv32-lib_defconfig diff --git a/.gitea/workflows/npc-test.yml b/.gitea/workflows/npc-test.yml new file mode 100644 index 0000000..ae4232d --- /dev/null +++ b/.gitea/workflows/npc-test.yml @@ -0,0 +1,22 @@ +name: Run CTests within npc +on: [push] + +jobs: + build-abstract-machine: + runs-on: nix + steps: + - uses: https://github.com/cachix/cachix-action@v14 + with: + name: ysyx + authToken: '${{ secrets.CACHIX_SIGNING_KEY }}' + - uses: actions/checkout@v4 + with: + submodules: true + - name: Run tests + run: | + nix develop .#npc + mkdir -p npc/build + cd npc/build + cmake $cmakeFlags ../ + make -j8 + make test diff --git a/flake.nix b/flake.nix index d3a27fc..5ecb49c 100644 --- a/flake.nix +++ b/flake.nix @@ -50,6 +50,7 @@ }; }; packages.nemu = pkgs.callPackage ./nemu { am-kernels = self.packages.${system}.am-kernels; }; + packages.nemu-lib = pkgs.callPackage ./nemu { am-kernels = self.packages.${system}.am-kernels; defconfig = "riscv32-lib_defconfig"; }; packages.abstract-machine = crossPkgs.callPackage ./abstract-machine { isa = "riscv"; platform = "nemu"; }; packages.am-kernels = crossPkgs.stdenv.mkDerivation rec { @@ -82,6 +83,7 @@ inputsFrom = [ self.packages.${system}.nemu ]; + IMAGES_PATH = "${self.packages.${system}.am-kernels}/share/binary"; }; devShells.npc = with pkgs; mkShell { @@ -114,6 +116,10 @@ verilator nvboard ] ++ self.checks.${system}.pre-commit-check.enabledPackages; + + cmakeFlags = [ + "-DDIFFTEST_LIB:string=${self.packages.${system}.nemu-lib}/lib/riscv32-nemu-interpreter-so" + ]; }; } ); diff --git a/nemu/configs/riscv32-lib_defconfig b/nemu/configs/riscv32-lib_defconfig new file mode 100644 index 0000000..15d8758 --- /dev/null +++ b/nemu/configs/riscv32-lib_defconfig @@ -0,0 +1,72 @@ +# +# Automatically generated file; DO NOT EDIT. +# NEMU Configuration Menu +# +# CONFIG_ISA_x86 is not set +# CONFIG_ISA_mips32 is not set +CONFIG_ISA_riscv=y +# CONFIG_ISA_loongarch32r is not set +CONFIG_ISA="riscv32" + +# +# ISA-dependent Options for riscv +# +# CONFIG_RV64 is not set +# CONFIG_RVE is not set +# end of ISA-dependent Options for riscv + +CONFIG_ENGINE_INTERPRETER=y +CONFIG_ENGINE="interpreter" +CONFIG_MODE_SYSTEM=y +# CONFIG_TARGET_NATIVE_ELF is not set +CONFIG_TARGET_SHARE=y +# CONFIG_TARGET_AM is not set + +# +# Build Options +# +CONFIG_CC_GCC=y +# CONFIG_CC_GPP is not set +# CONFIG_CC_CLANG is not set +CONFIG_CC="gcc" +# CONFIG_CC_O0 is not set +# CONFIG_CC_O1 is not set +CONFIG_CC_O2=y +# CONFIG_CC_O3 is not set +CONFIG_CC_OPT="-O2" +CONFIG_CC_LTO=y +CONFIG_CC_DEBUG=y +# CONFIG_CC_ASAN is not set +# end of Build Options + +# +# Testing and Debugging +# +CONFIG_LOG_TRACE=y +# CONFIG_LOG_INFO is not set +# CONFIG_LOG_WARNING is not set +# CONFIG_LOG_ERROR is not set +CONFIG_LOG_LEVEL=4 +# CONFIG_TRACE is not set +CONFIG_DIFFTEST_REF_PATH="none" +CONFIG_DIFFTEST_REF_NAME="none" +# end of Testing and Debugging + +# +# Memory Configuration +# +CONFIG_MBASE=0x80000000 +CONFIG_MSIZE=0x8000000 +CONFIG_PC_RESET_OFFSET=0 +# CONFIG_PMEM_MALLOC is not set +CONFIG_PMEM_GARRAY=y +CONFIG_MEM_RANDOM=y +# end of Memory Configuration + +# +# Miscellaneous +# +CONFIG_TIMER_GETTIMEOFDAY=y +# CONFIG_TIMER_CLOCK_GETTIME is not set +CONFIG_RT_CHECK=y +# end of Miscellaneous diff --git a/nemu/default.nix b/nemu/default.nix index d3d5a70..052b4a7 100644 --- a/nemu/default.nix +++ b/nemu/default.nix @@ -2,7 +2,8 @@ lib, stdenv, am-kernels, - dtc + dtc, + defconfig ? "alldefconfig", }: stdenv.mkDerivation rec { @@ -31,27 +32,27 @@ stdenv.mkDerivation rec { configurePhase = '' export NEMU_HOME=$(pwd) - make alldefconfig + make ${defconfig} ''; buildPhase = '' make ''; - doCheck = true; - checkPhase = '' + doCheck = (defconfig == "alldefconfig"); + checkPhase = if doCheck then '' export IMAGES_PATH=${am-kernels}/share/binary make test - ''; + '' else ""; installPhase = '' mkdir -p $out/bin + mkdir -p $out/lib make PREFIX=$out install ''; shellHook = '' export NEMU_HOME=$(pwd) - export IMAGES_PATH=${am-kernels}/share/binary ''; meta = with lib; { diff --git a/nemu/scripts/build.mk b/nemu/scripts/build.mk index f050197..a3b71d2 100644 --- a/nemu/scripts/build.mk +++ b/nemu/scripts/build.mk @@ -76,8 +76,13 @@ $(BINARY):: $(OBJS) $(ARCHIVES) @$(LD) -o $@ $(OBJS) $(LDFLAGS) $(ARCHIVES) $(LIBS) install: $(BINARY) +ifeq ($(SHARE),1) + @mkdir -p $(PREFIX)/lib + @cp $(BINARY) $(PREFIX)/lib/ +else @mkdir -p $(PREFIX)/bin @cp $(BINARY) $(PREFIX)/bin/ +endif clean: -rm -rf $(BUILD_DIR) diff --git a/npc/CMakeLists.txt b/npc/CMakeLists.txt index 4874780..78dbfe5 100644 --- a/npc/CMakeLists.txt +++ b/npc/CMakeLists.txt @@ -15,6 +15,7 @@ option(BUILD_SIM_TARGET "Whether to build verilator simulation binary" ON) cmake_dependent_option(BUILD_SIM_NVBOARD_TARGET "Whether to build nvboard target" OFF "BUILD_SIM_TARGET" OFF) option(ENABLE_YSYX_GIT_TRACKER "Ysyx tracker support" OFF) set(TOPMODULE "Flow" CACHE STRING "Topmodule name in chisel") +set(DIFFTEST_LIB "" CACHE STRING "Dynamic library file used as difftest reference") # -- Ysyx tracker, configure if(ENABLE_YSYX_GIT_TRACKER) @@ -61,12 +62,6 @@ include_directories(include) add_subdirectory(csrc) -add_test( - NAME V${TOPMODULE} - COMMAND V${TOPMODULE} - --no-bin -m ${PROJECT_SOURCE_DIR}/resource/addi.txt - --diff-lib /home/xin/repo/ysyx-workbench/nemu/build/riscv32-nemu-interpreter-so) - # -- Add build tracking if(ENABLE_YSYX_GIT_TRACKER) add_custom_command( diff --git a/npc/csrc/Flow/CMakeLists.txt b/npc/csrc/Flow/CMakeLists.txt index 0764ea6..606fd73 100644 --- a/npc/csrc/Flow/CMakeLists.txt +++ b/npc/csrc/Flow/CMakeLists.txt @@ -9,3 +9,9 @@ verilate(V${TOPMODULE} TRACE COVERAGE THREADS VERILATOR_ARGS "--vpi" # Enable VPI ) + +add_test( + NAME V${TOPMODULE} + COMMAND V${TOPMODULE} + --no-bin -m ${PROJECT_SOURCE_DIR}/resource/addi.txt + --diff-lib ${DIFFTEST_LIB})