2024-03-03 15:05:05 +00:00
|
|
|
{
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
};
|
|
|
|
|
|
|
|
outputs = { self, ... }@inputs: with inputs;
|
|
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
|
|
let
|
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
crossPkgs = import nixpkgs {
|
|
|
|
localSystem = system;
|
|
|
|
crossSystem = {
|
|
|
|
config = "riscv32-none-elf";
|
2024-03-24 08:07:06 +00:00
|
|
|
gcc = {
|
|
|
|
abi = "ilp32";
|
|
|
|
arch = "rv32if";
|
|
|
|
};
|
2024-03-03 15:05:05 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
2024-03-24 08:26:21 +00:00
|
|
|
packages.nemu = pkgs.callPackage ./nemu { am-kernels = self.packages.${system}.am-kernels-cmake; };
|
2024-03-05 10:21:57 +00:00
|
|
|
|
2024-03-24 02:10:28 +00:00
|
|
|
packages.abstract-machine = crossPkgs.stdenv.mkDerivation rec {
|
|
|
|
pname = "abstract-machine";
|
|
|
|
version = "2024.02.18";
|
|
|
|
|
|
|
|
src = ./abstract-machine;
|
|
|
|
|
2024-03-24 08:26:21 +00:00
|
|
|
cmakeFlags = [
|
|
|
|
(pkgs.lib.cmakeFeature "ISA" "riscv")
|
|
|
|
(pkgs.lib.cmakeBool "__PLATFORM_NEMU__" true)
|
|
|
|
];
|
|
|
|
|
2024-03-24 02:10:28 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
pkgs.cmake
|
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
# SDL2
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
packages.am-kernels-cmake = crossPkgs.stdenv.mkDerivation rec {
|
|
|
|
pname = "am-kernels-cmake";
|
2024-03-24 08:26:21 +00:00
|
|
|
version = "2024.02.18";
|
2024-03-24 02:10:28 +00:00
|
|
|
|
2024-03-24 08:07:06 +00:00
|
|
|
src = ./am-kernels;
|
2024-03-24 02:10:28 +00:00
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
pkgs.cmake
|
|
|
|
];
|
|
|
|
|
2024-03-24 08:07:06 +00:00
|
|
|
cmakeFlags = [
|
|
|
|
(pkgs.lib.cmakeFeature "ISA" "riscv")
|
|
|
|
(pkgs.lib.cmakeFeature "PLATFORM" "nemu")
|
|
|
|
(pkgs.lib.cmakeFeature "CMAKE_INSTALL_DATADIR" "share")
|
|
|
|
];
|
|
|
|
|
2024-03-24 02:10:28 +00:00
|
|
|
buildInputs = [
|
|
|
|
# SDL2
|
|
|
|
self.packages.${system}.abstract-machine
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2024-03-20 12:24:59 +00:00
|
|
|
packages.am-kernels = pkgs.stdenv.mkDerivation rec {
|
2024-03-05 10:21:57 +00:00
|
|
|
pname = "am-kernels";
|
|
|
|
version = "2024.02.18";
|
|
|
|
|
2024-03-24 02:10:28 +00:00
|
|
|
buildInputs = with pkgs; [
|
|
|
|
SDL2
|
2024-03-20 12:24:59 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
src = pkgs.fetchFromGitHub {
|
|
|
|
owner = "NJU-ProjectN";
|
|
|
|
repo = "am-kernels";
|
|
|
|
rev = "bb725d6f8223dd7de831c3b692e8c4531e9d01af";
|
|
|
|
hash = "sha256-ZHdrw28TN8cMvhhzM469OV7cp0Yp+8yao855HP4+P4A=";
|
|
|
|
};
|
|
|
|
|
|
|
|
AM_HOME = pkgs.fetchFromGitHub {
|
|
|
|
owner = "xinyangli";
|
|
|
|
repo = "abstract-machine";
|
|
|
|
rev = "788595aac61c6b2f3b78ca8aa7d08dc33911bca4";
|
|
|
|
hash = "sha256-YvWHIBP9tz3HL2TyibftvvQrpkWUDPnviCF4oyLmdjg=";
|
|
|
|
};
|
|
|
|
|
|
|
|
ARCH = "native";
|
|
|
|
|
|
|
|
patchPhase = ''
|
|
|
|
sed -i 's/\/bin\/echo/echo/' tests/cpu-tests/Makefile
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
AS=$CC make -C tests/cpu-tests BUILD_DIR=$(pwd)/build ARCH=$ARCH
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
2024-03-20 12:28:19 +00:00
|
|
|
mkdir -p $out/bin
|
2024-03-24 02:10:28 +00:00
|
|
|
rm -r build/native/src build/native/tests
|
|
|
|
cp -r build/native/* $out/bin/
|
2024-03-20 12:24:59 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
packages.am-kernels-rv32 = crossPkgs.stdenv.mkDerivation rec {
|
|
|
|
pname = "am-kernels-rv32";
|
|
|
|
version = "2024.02.18";
|
|
|
|
|
2024-03-05 10:21:57 +00:00
|
|
|
src = pkgs.fetchFromGitHub {
|
|
|
|
owner = "NJU-ProjectN";
|
|
|
|
repo = "am-kernels";
|
|
|
|
rev = "bb725d6f8223dd7de831c3b692e8c4531e9d01af";
|
|
|
|
hash = "sha256-ZHdrw28TN8cMvhhzM469OV7cp0Yp+8yao855HP4+P4A=";
|
|
|
|
};
|
|
|
|
|
|
|
|
AM_HOME = pkgs.fetchFromGitHub {
|
|
|
|
owner = "xinyangli";
|
|
|
|
repo = "abstract-machine";
|
|
|
|
rev = "788595aac61c6b2f3b78ca8aa7d08dc33911bca4";
|
|
|
|
hash = "sha256-YvWHIBP9tz3HL2TyibftvvQrpkWUDPnviCF4oyLmdjg=";
|
|
|
|
};
|
|
|
|
|
|
|
|
ARCH = "riscv32-nemu";
|
|
|
|
|
|
|
|
patchPhase = ''
|
|
|
|
sed -i 's/\/bin\/echo/echo/' tests/cpu-tests/Makefile
|
2024-03-03 15:05:05 +00:00
|
|
|
'';
|
2024-03-05 10:21:57 +00:00
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
AS=$CC make -C tests/cpu-tests BUILD_DIR=$(pwd)/build ARCH=$ARCH
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/share/images $out/share/dump
|
2024-03-24 02:10:28 +00:00
|
|
|
mkdir -p $out/bin
|
2024-03-05 10:21:57 +00:00
|
|
|
cp build/riscv32-nemu/*.bin $out/share/images
|
|
|
|
cp build/riscv32-nemu/*.txt $out/share/dump
|
2024-03-24 02:10:28 +00:00
|
|
|
cp build/riscv32-nemu/*.elf $out/bin
|
2024-03-05 10:21:57 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
dontFixup = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
devShells.default = pkgs.mkShell {
|
|
|
|
packages = with pkgs; [
|
|
|
|
gdb
|
|
|
|
] ++ builtins.attrValues self.packages.${system};
|
2024-03-03 15:05:05 +00:00
|
|
|
};
|
2024-03-05 10:37:12 +00:00
|
|
|
|
|
|
|
devShells.nemu = pkgs.mkShell {
|
|
|
|
packages = with pkgs; [
|
|
|
|
clang-tools
|
2024-03-13 07:42:07 +00:00
|
|
|
gdb
|
2024-03-05 10:37:12 +00:00
|
|
|
];
|
|
|
|
inputsFrom = [
|
|
|
|
self.packages.${system}.nemu
|
|
|
|
];
|
|
|
|
};
|
2024-03-24 02:10:28 +00:00
|
|
|
|
|
|
|
devShells.abstract-machine-shell = pkgs.mkShell {
|
|
|
|
packages = with pkgs; [
|
|
|
|
clang-tools
|
|
|
|
cmake
|
|
|
|
check
|
|
|
|
pkg-config
|
|
|
|
SDL2
|
|
|
|
];
|
|
|
|
};
|
2024-03-03 15:05:05 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|