> compile NEMU

ysyx_22040000 李心杨
Linux calcite 6.6.18 #1-NixOS SMP PREEMPT_DYNAMIC Fri Feb 23 08:25:28 UTC 2024 x86_64 GNU/Linux
 23:05:05  up   7:22,  2 users,  load average: 0.43, 0.37, 0.33
This commit is contained in:
tracer-ysyx 2024-03-03 23:05:05 +08:00 committed by xinyangli
parent a915be2262
commit 01960837e0
9 changed files with 104 additions and 184 deletions

View file

@ -66,8 +66,8 @@ LINKAGE = $(OBJS) \
## 3. General Compilation Flags ## 3. General Compilation Flags
### (Cross) compilers, e.g., mips-linux-gnu-g++ ### (Cross) compilers, e.g., mips-linux-gnu-g++
AS = $(CROSS_COMPILE)cc AS = $(CROSS_COMPILE)gcc
CC = $(CROSS_COMPILE)cc CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++ CXX = $(CROSS_COMPILE)g++
LD = $(CROSS_COMPILE)ld LD = $(CROSS_COMPILE)ld
AR = $(CROSS_COMPILE)ar AR = $(CROSS_COMPILE)ar

View file

@ -5,11 +5,11 @@
"systems": "systems" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1701680307, "lastModified": 1709126324,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", "narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725", "rev": "d465f4819400de7c8d874d50b982301f28a84605",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -20,11 +20,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1704722960, "lastModified": 1709237383,
"narHash": "sha256-mKGJ3sPsT6//s+Knglai5YflJUF2DGj7Ai6Ynopz0kI=", "narHash": "sha256-cy6ArO4k5qTx+l5o+0mL9f5fa86tYUX3ozE1S+Txlds=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "317484b1ead87b9c1b8ac5261a8d2dd748a0492d", "rev": "1536926ef5621b09bba54035ae2bb6d806d72ac8",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -34,31 +34,10 @@
"type": "github" "type": "github"
} }
}, },
"nur-xin": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1704680562,
"narHash": "sha256-ffec3HL8OgbHB/TvLHILvC3ylou6N+KDtrn4qYVV+U4=",
"ref": "refs/heads/master",
"rev": "8adf33b6fdd113c645d83feda28622a0b1ef9f83",
"revCount": 144,
"type": "git",
"url": "https://git.xinyang.life/xin/nur.git"
},
"original": {
"type": "git",
"url": "https://git.xinyang.life/xin/nur.git"
}
},
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs"
"nur-xin": "nur-xin"
} }
}, },
"systems": { "systems": {

39
flake.nix Normal file
View file

@ -0,0 +1,39 @@
{
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";
abi = "ilp32";
};
};
in
{
packages.nemu = pkgs.callPackage ./nemu {};
devShells.am-kernels = crossPkgs.mkShell {
inputsFrom = [
self.packages.${system}.nemu
];
packages = [
pkgs.stdenv.cc
pkgs.libllvm
];
shellHook = ''
export PROJECT_ROOT=/home/xin/repo/ysyx-workbench
export AM_HOME=$PROJECT_ROOT/abstract-machine;
export NEMU_HOME=$PROJECT_ROOT/nemu;
'';
};
}
);
}

View file

@ -1,74 +0,0 @@
#
# 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=y
# CONFIG_TARGET_SHARE is not set
# 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 is not set
# CONFIG_CC_DEBUG is not set
CONFIG_CC_ASAN=y
# end of Build Options
#
# Testing and Debugging
#
CONFIG_TRACE=y
CONFIG_TRACE_START=0
CONFIG_TRACE_END=10000
CONFIG_ITRACE=y
CONFIG_ITRACE_COND="true"
# CONFIG_DIFFTEST 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
# CONFIG_DEVICE is not set
#
# Miscellaneous
#
CONFIG_TIMER_GETTIMEOFDAY=y
# CONFIG_TIMER_CLOCK_GETTIME is not set
CONFIG_RT_CHECK=y
# end of Miscellaneous

View file

@ -40,7 +40,9 @@ SRCS-y += $(shell find -L $(DIRS-y) -name "*.c")
SRCS = $(filter-out $(SRCS-BLACKLIST-y),$(SRCS-y)) SRCS = $(filter-out $(SRCS-BLACKLIST-y),$(SRCS-y))
# Extract compiler and options from menuconfig # Extract compiler and options from menuconfig
ifneq ($(CONFIG_CC),)
CC = $(call remove_quote,$(CONFIG_CC)) CC = $(call remove_quote,$(CONFIG_CC))
endif
CFLAGS_BUILD += $(call remove_quote,$(CONFIG_CC_OPT)) CFLAGS_BUILD += $(call remove_quote,$(CONFIG_CC_OPT))
CFLAGS_BUILD += $(if $(CONFIG_CC_LTO),-flto,) CFLAGS_BUILD += $(if $(CONFIG_CC_LTO),-flto,)
CFLAGS_BUILD += $(if $(CONFIG_CC_DEBUG),-Og -ggdb3,) CFLAGS_BUILD += $(if $(CONFIG_CC_DEBUG),-Og -ggdb3,)

49
nemu/default.nix Normal file
View file

@ -0,0 +1,49 @@
{ pkgs,
lib,
stdenv
}:
stdenv.mkDerivation rec {
pname = "nemu";
version = "2024-03-02";
src = ./.;
NEMU_HOME = "/build/nemu";
nativeBuildInputs = with pkgs; [
gnumake
flex
bison
];
buildInputs = with pkgs; [
check
readline
libllvm
];
configurePhase = ''
echo pwd=$(pwd)
make alldefconfig
'';
buildPhase = ''
make
'';
checkPhase = ''
make test
'';
installPhase = ''
mkdir -p $out/bin
make PREFIX=$out install
'';
meta = with lib; {
description = "NJU EMUlator, a full system x86/mips32/riscv32/riscv64 emulator for teaching";
homepage = "https://github.com/NJU-ProjectN/nemu.git";
license = with licenses; [ ];
maintainers = with maintainers; [ ];
};
}

View file

@ -1,79 +0,0 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
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} //
{ nur.xin = nur-xin.legacyPackages.${system}; };
in
{
devShells.default = with pkgs; mkShell {
packages = [
clang-tools
rnix-lsp
bear
gdb
jre
gtkwave
];
inputsFrom = [ self.packages.${system}.nemu ];
};
packages.nemu = with pkgs; stdenv.mkDerivation rec {
pname = "nemu";
version = "2024-01-02";
src = ./.;
nativeBuildInputs = [
gnumake
flex
bison
pkg-config
python3 # for testing
];
buildInputs = [
check
readline
libllvm
];
configurePhase = ''
echo pwd=$(pwd)
'';
buildPhase = ''
make NEMU_HOME=/build/nemu --trace
'';
installPhase = ''
BUILD_DIR=$out make install
'';
checkPhase = ''
BUILD_DIR=$out make test
'';
meta = with lib; {
description = "NJU EMUlator, a full system x86/mips32/riscv32/riscv64 emulator for teaching";
homepage = "https://github.com/NJU-ProjectN/nemu.git";
license = with licenses; [ ];
maintainers = with maintainers; [ ];
};
};
}
);
}

View file

@ -48,6 +48,9 @@ menuconfig: $(MCONF) $(CONF) $(FIXDEP)
savedefconfig: $(CONF) savedefconfig: $(CONF)
$(Q)$< $(silent) --$@=configs/defconfig $(Kconfig) $(Q)$< $(silent) --$@=configs/defconfig $(Kconfig)
alldefconfig: $(CONF) $(FIXDEP)
$(Q)$(CONF) $(silent) --$@ $(Kconfig)
%defconfig: $(CONF) $(FIXDEP) %defconfig: $(CONF) $(FIXDEP)
$(Q)$< $(silent) --defconfig=configs/$@ $(Kconfig) $(Q)$< $(silent) --defconfig=configs/$@ $(Kconfig)
$(Q)$< $(silent) --syncconfig $(Kconfig) $(Q)$< $(silent) --syncconfig $(Kconfig)
@ -60,7 +63,7 @@ help:
@echo ' savedefconfig - Save current config as configs/defconfig (minimal config)' @echo ' savedefconfig - Save current config as configs/defconfig (minimal config)'
distclean: clean distclean: clean
-@rm -rf $(rm-distclean) -rm -rf $(rm-distclean)
.PHONY: help distclean .PHONY: help distclean

1
result Symbolic link
View file

@ -0,0 +1 @@
/nix/store/3x5nz7zcwq0zhcff1d3l9lpmvmnmx2i5-nemu-2024-03-02