I made a helloworld program on RISC-V qemu using the UART using https://popovicu.com/posts/bare-metal-programming-risc-v/ Uros Popovicu’s guide in RISC-V assembly. I was wondering how I could write to the UART using c and RISC-V qemu.
I tried :
#define UART_TX 0x10000000
void _start() {
char *str = "Hello, World!n";
for (int i = 0; str[i] != ''; ++i) {
*(volatile char*)UART_TX = str[i];
}
while (1);
}
I tried compiling the c code :
riscv64-linux-gnu-gcc -S -o hello.s hello.c
riscv64-linux-gnu-as -march=rv64i -mabi=lp64 -o hello.o -c hello.s
to RISC-V and using the same linker file as in popovicu’s example :
riscv64-linux-gnu-ld -T linker.ld --no-dynamic-linker -m elf64lriscv -static -nostdlib -s -o hello hello.o
using the following linker file (with only some slight modifications) :
ENTRY(_start)
MEMORY {
dram_space (rwx) : ORIGIN = 0x80000000, LENGTH = 1024
}
SECTIONS {
.text : {
hello.o(.text.bios)
} > dram_space
}
And running it using :
qemu-system-riscv64 -machine virt -bios hello
This results in nothing being print. Is this the correct way to access the UART or does my error lie elsewhere? Thanks in advance.