Skip to content
jli05Public

About

RISC-V64 version of Operating System in 1000 Lines by Nuta Seiya https://operating-system-in-1000-lines.vercel.app

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

Repository files navigation

Operating System in 1,000 Lines for RISC-V64

This is adaptation of Nuta Seiya's course for RISC-V64

Operating System in 1,000 Lines https://operating-system-in-1000-lines.vercel.app/en/

To make and run

In the shell,

$ make clean
$ make
$ qemu-system-riscv64 -nographic -kernel kernel.elf

Press Ctrl+A then C to switch to the QEMU debug console (QEMU monitor). You can exit QEMU by q command in the monitor.

To debug the kernel

In one shell, start the riscv64 simulator,

$ qemu-system-riscv64 -S -gdb tcp::1234 -nographic -kernel kernel.elf

The -S will pause the execution, the -gdb specifies the port for debugging.

In a separate shell, start lldb,

$ lldb

In the debugging session,

(lldb) file kernel.elf
Current executable set to 'kernel.elf' (riscv64).
(lldb) process connect connect://localhost:1234
Process 1 stopped
* thread #1, stop reason = signal SIGTRAP
    frame #0: 0x0000000000001000
->  0x1000: auipc  t0, 0x0
    0x1004: addi   a2, t0, 0x28
    0x1008: csrr   a0, mhartid
    0x100c: ld     a1, 0x20(t0)
(lldb) di
->  0x1000: auipc  t0, 0x0
    0x1004: addi   a2, t0, 0x28
    0x1008: csrr   a0, mhartid
    0x100c: ld     a1, 0x20(t0)
    0x1010: ld     t0, 0x18(t0)
    0x1014: jr     t0
    0x1018: unimp
(lldb) b kernel.c:16
Breakpoint 1: where = kernel.elf`kernel_entry at kernel.c:16:5, address = 0x0000000080200390
(lldb) c
Process 1 resuming
Process 1 stopped
* thread #1, stop reason = breakpoint 1.1
    frame #0: 0x0000000080200390 kernel.elf`kernel_entry at kernel.c:16:5
   13
   14  	__attribute__((naked))
   15  	void kernel_entry(void) {
-> 16  	    __asm__ __volatile__(
   17  	        "csrw sscratch, sp\n"
   18  	        "addi sp, sp, -8 * 32\n"
   19  	        "sd ra,  8 * 0(sp)\n"
(lldb) di
kernel.elf`kernel_entry:
->  0x80200390 <+0>:   csrw   sscratch, sp
    0x80200394 <+4>:   addi   sp, sp, -0x100
    0x80200396 <+6>:   sd     ra, 0x0(sp)
    0x80200398 <+8>:   sd     gp, 0x8(sp)
    0x8020039a <+10>:  sd     tp, 0x10(sp)
    ......
(lldb) reg read pc ra
      pc = 0x0000000080200390 kernel.elf`kernel_entry at kernel.c:16:5  kernel.elf`kernel_entry at kernel.c:16:5
      ra = 0x000000008000ae9a
(lldb) c
Process 1 resuming
(lldb) q
Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n]

About

RISC-V64 version of Operating System in 1000 Lines by Nuta Seiya https://operating-system-in-1000-lines.vercel.app

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages