Fix segfault with the help of gdb via Nix

This commit is contained in:
Wesley Moore 2025-02-09 21:36:54 +10:00
parent 2ab32594d3
commit ff3e779f22
No known key found for this signature in database
4 changed files with 23 additions and 0 deletions

View file

@ -1,5 +1,7 @@
CC=riscv64-unknown-elf-gcc
AS=riscv64-unknown-elf-as
ASFLAGS=-g -mabi=ilp32e -march=rv32ec
CFLAGS=$(ASFLAGS)
LD=riscv64-unknown-elf-ld
all: calc.elf

4
calc.s
View file

@ -108,7 +108,11 @@ regdump_loop:
la a0, buf # load address of buf into a0 as dest
li a2, 2 # copy 2 bytes
addi sp, sp, -4 # allocate stack space
sw ra, 0(sp) # save contents of ra
jal memcpy
lw ra, 0(sp) # save contents of ra
addi sp, sp, 4 # deallocate stack space
# append ': \n'
li t0, ':
sb t0, 0(a0)

5
cmain.c Normal file
View file

@ -0,0 +1,5 @@
extern void regdump(void);
void cmain(void) {
regdump();
}

12
shell.nix Normal file
View file

@ -0,0 +1,12 @@
let
nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/release-24.11";
pkgs = (import nixpkgs {}).pkgsCross.riscv32-embedded;
in
# callPackage is needed due to https://github.com/NixOS/nixpkgs/pull/126844
pkgs.pkgsStatic.callPackage ({ mkShell, zlib, pkg-config, file, gdb }: mkShell {
# these tools run on the build platform, but are configured to target the host platform
nativeBuildInputs = [ pkg-config file gdb ];
# libraries needed for the host platform
buildInputs = [ zlib ];
}) {}