Add an example program in C
This commit is contained in:
parent
b8fb51f5e6
commit
c9fc4a420c
7 changed files with 53 additions and 8 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -18,3 +18,4 @@ CTestTestfile.cmake
|
|||
Testing
|
||||
result
|
||||
build
|
||||
example/example
|
2
example/Makefile
Normal file
2
example/Makefile
Normal file
|
@ -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
|
9
example/example.c
Normal file
9
example/example.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
static int mem;
|
||||
|
||||
int main() {
|
||||
int a = 42;
|
||||
int b = 5;
|
||||
mem = a*b + 3;
|
||||
|
||||
return 0;
|
||||
}
|
19
example/linker.ld
Normal file
19
example/linker.ld
Normal file
|
@ -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 */
|
||||
}
|
14
flake.nix
14
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;});
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
12
rve.nix
12
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 = [
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <cstring>
|
||||
|
||||
int main() {
|
||||
const size_t MEMORY_SIZE = 1024;
|
||||
const size_t MEMORY_SIZE = 128*1024;
|
||||
uint8_t memory[MEMORY_SIZE] = {0};
|
||||
|
||||
uint32_t program[] = {
|
||||
|
|
Loading…
Reference in a new issue