Advertisement
pearmypie

Untitled

Jul 4th, 2025
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | Software | 0 0
  1. #include <sbi/sbi_console.h>
  2.  
  3. void kmain()
  4. {
  5.     sbi_puts("Hello C Kernel!");
  6. }
  7.  
  8. How can I get a program like this to run using `qemu-system-riscv64 -kernel kmain`?
  9. I have libsbi.a and libplatsbi.a in /usr/local/lib64/lp64 and /usr/local/lib64/lp64/opensbi/generic/lib/.
  10. I have all kinds of header files in /usr/local/include/sbi.
  11.  
  12. I am compiling with `riscv64-linux-gnu-gcc -ffreestanding -I/usr/local/include -march=rv64gc -mabi=lp64` and linking with `riscv64-linux-gnu-gcc -ffreestanding -nostdlib -T linker.ld -L/usr/local/lib64/lp64 -march=rv64gc -mabi=lp64`
  13.  
  14. This is my boot.S file:
  15. .section .text.start
  16. .global _start
  17.  
  18. _start:
  19.     # Set up stack pointer
  20.     la sp, stack_top
  21.  
  22.     # Jump to C code
  23.     call kmain
  24.  
  25. .section .bss
  26. .align 4
  27. stack_bottom:
  28.     .space 4096
  29. stack_top:
  30.  
  31. This is my linker script:
  32. OUTPUT_ARCH(riscv)
  33. ENTRY(_start)
  34.  
  35. SECTIONS
  36. {
  37.     . = 0x80200000;
  38.  
  39.     .text : {
  40.         *(.text.start)
  41.         *(.text)
  42.     }
  43.  
  44.     .data : {
  45.         *(.data)
  46.     }
  47.  
  48.     .bss : {
  49.         *(.bss)
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement