diff --git a/.gitignore b/.gitignore index 2b050c3..6b7083d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ CMakeCache.txt CTestTestfile.cmake Testing result -build \ No newline at end of file +build +example/example \ No newline at end of file diff --git a/example/Makefile b/example/Makefile new file mode 100644 index 0000000..57666ed --- /dev/null +++ b/example/Makefile @@ -0,0 +1,2 @@ +example: example.c + riscv32-none-elf-gcc -fno-builtin -fvisibility=hidden -nostdlib -nostartfiles -march=rv32im -mabi=ilp32 -o example example.c -T linker.ld diff --git a/example/example.c b/example/example.c new file mode 100644 index 0000000..460520c --- /dev/null +++ b/example/example.c @@ -0,0 +1,9 @@ +static int mem; + +int main() { + int a = 42; + int b = 5; + mem = a*b + 3; + + return 0; +} diff --git a/example/linker.ld b/example/linker.ld new file mode 100644 index 0000000..a5ea337 --- /dev/null +++ b/example/linker.ld @@ -0,0 +1,19 @@ +ENTRY(_start) + +SECTIONS { + . = 0x1000; /* Start address of the program */ + + .text : { + *(.text) /* Place all .text sections (code) here */ + } + + .data : { + *(.data) /* Place all .data sections (initialized data) here */ + } + + .bss : { + *(.bss) /* Place all .bss sections (uninitialized data) here */ + } + + /DISCARD/ : { *(.note.GNU-stack) } /* Discard stack section */ +} diff --git a/flake.nix b/flake.nix index 9e06636..6e2312b 100644 --- a/flake.nix +++ b/flake.nix @@ -21,16 +21,22 @@ forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f { pkgs = import nixpkgs { inherit system; }; }); + riscv-pkgs = import nixpkgs { + localSystem = "x86_64-linux"; + crossSystem = { + config = "riscv32-unknown-linux-gnu"; + }; + }; in { - packages = forAllSystems( {pkgs }: + packages = forAllSystems( {pkgs}: { - lisp = (pkgs.callPackage ./rve.nix {}); - default = (pkgs.callPackage ./rve.nix {}); + lisp = (pkgs.callPackage ./rve.nix {riscv-pkgs=riscv-pkgs;}); + default = (pkgs.callPackage ./rve.nix {riscv-pkgs=riscv-pkgs;}); } ); overlays.default = final: prev: { - lisp = (prev.callPackage ./rve.nix {}); + lisp = (prev.callPackage ./rve.nix {riscv-pkgs=riscv-pkgs;}); }; }; } diff --git a/rve.nix b/rve.nix index 0608629..6be2130 100644 --- a/rve.nix +++ b/rve.nix @@ -1,4 +1,4 @@ -{ pkgs, stdenv }: +{ pkgs, stdenv, riscv-pkgs }: pkgs.gcc13Stdenv.mkDerivation rec { pname = "rve"; version = "0.1.0"; @@ -13,7 +13,15 @@ pkgs.gcc13Stdenv.mkDerivation rec { nativeBuildInputs = with pkgs; [ pkg-config cmake ninja ]; - buildInputs = with pkgs; [ gdb linuxPackages.perf jq lcov ]; + buildInputs = with pkgs; [ + gdb + linuxPackages.perf + jq + lcov + #riscv-pkgs.buildPackages.gcc + pkgsCross.riscv32-embedded.buildPackages.gcc + pkgsCross.riscv32-embedded.buildPackages.binutils + ]; hardeningDisable = [ "all" ]; cmakeFlags = [ diff --git a/src/rve.cpp b/src/rve.cpp index 92be719..d179de5 100644 --- a/src/rve.cpp +++ b/src/rve.cpp @@ -5,7 +5,7 @@ #include int main() { - const size_t MEMORY_SIZE = 1024; + const size_t MEMORY_SIZE = 128*1024; uint8_t memory[MEMORY_SIZE] = {0}; uint32_t program[] = {