Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

risv-gnu-toolchain spike module "Bad or missing arguments for command str" #1845

Open
cryptolovi opened this issue Oct 27, 2024 · 0 comments

Comments

@cryptolovi
Copy link

I posted this issue on the riscv-gnu-toolchain, but it probably is better to post it here since it resolves around a possible problem in spike issue on riscv-gnu-toolchain

I'm running into problems with Spike reporting "Bad or missing arguments for command str", which I don't know how to resolve or why this is occurring in a simple hello world program.

The riscv-gnu-toolchain is cleanly build. The RISCV and PATH variable is set in the USER environment only (so using sudo -E). The environment variable are set RISCV=/opt/riscv and PATH includes $RISCV/bin. Compiling is done on Ubuntu 24.04.1 LTS
Getting & Building riscv-gnu-toolchain is done by;

git clone https://github.com/riscv/riscv-gnu-toolchain
cd riscv-gnu-toolchain/
./configure --prefix=/opt/riscv --enable-multilib
sudo -E make

Which results in the riscv64-unknown-elf compiiler/tools in /opt/riscv.

I build pk from the riscv-gnu-toolchain directory with;
sudo -E SIM=spike make build-sim

Which results with the spike binaries in /opt/riscv/bin (spike, spike-dasm, spike-log-parser etc.) and pk32, pk64 in /opt/riscv/riscv64-unknown-elf/bin

The sample program;

#include <stdio.h>
int main() {
  printf("Hello World!\n");
}

The compile commando for the example program (with intermediate files enabled);
riscv64-unknown-elf-gcc --save-temps -o example example.c

The generated assembly;

.file	"example.c"
	.option nopic
	.attribute arch, "rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0"
	.attribute unaligned_access, 0
	.attribute stack_align, 16
	.text
	.section	.rodata
	.align	3
.LC0:
	.string	"Hello World!"
	.text
	.align	1
	.globl	main
	.type	main, @function
main:
	addi	sp,sp,-16
	sd	ra,8(sp)
	sd	s0,0(sp)
	addi	s0,sp,16
	lui	a5,%hi(.LC0)
	addi	a0,a5,%lo(.LC0)
	call	puts
	li	a5,0
	mv	a0,a5
	ld	ra,8(sp)
	ld	s0,0(sp)
	addi	sp,sp,16
	jr	ra
	.size	main, .-main
	.ident	"GCC: () 14.2.0"
	.section	.note.GNU-stack,"",@progbits

The disassembly of the executable with riscv64-unknown-elf-objdump --disassemble=main example;

example:     file format elf64-littleriscv


Disassembly of section .text:

00000000000101d4 <main>:
   101d4:	1141                	addi	sp,sp,-16
   101d6:	e406                	sd	ra,8(sp)
   101d8:	e022                	sd	s0,0(sp)
   101da:	0800                	addi	s0,sp,16
   101dc:	67c9                	lui	a5,0x12
   101de:	61878513          	addi	a0,a5,1560 # 12618 <__errno+0x8>
   101e2:	384000ef          	jal	10566 <puts>
   101e6:	4781                	li	a5,0
   101e8:	853e                	mv	a0,a5
   101ea:	60a2                	ld	ra,8(sp)
   101ec:	6402                	ld	s0,0(sp)
   101ee:	0141                	addi	sp,sp,16
   101f0:	8082                	ret

The following command starts the example in spike;
spike -d pk64 example

In spike I run to the address of the jal instruction, display the contents of the a0 register (which should point to the string "hello world" and try to display it. The following is the result;

(spike) until pc 0 101e2
bbl loader
(spike) reg 0 a0
0x0000000000012618
(spike) str 0 12618
Bad or missing arguments for command str

Omitting the core parameter for str commando has the same result. Trying the mem commando to dump the content hexidecimal gives; "0xBad or missing arguments for command mem"

What am I missing/doing wrong or not understanding?

A suggestion was using 0x but that resulted into the same error;

(spike) until pc 0 0x101e2
bbl loader
(spike) reg 0 a0
0x0000000000012618
(spike) str 0 0x12618
Bad or missing arguments for command str
(spike) 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant