Fix segfault with the help of gdb via Nix
This commit is contained in:
parent
2ab32594d3
commit
ff3e779f22
4 changed files with 23 additions and 0 deletions
2
Makefile
2
Makefile
|
@ -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
4
calc.s
|
@ -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
5
cmain.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
extern void regdump(void);
|
||||
|
||||
void cmain(void) {
|
||||
regdump();
|
||||
}
|
12
shell.nix
Normal file
12
shell.nix
Normal 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 ];
|
||||
}) {}
|
Loading…
Reference in a new issue