My Haiku RISC-V port progress

NOTE: This post was recovered after broken network and reboot. It was written some time before.

I have progressed to “init modules” stage. It currently crashes with PANIC: remove page 0x000000008183c0a0 from cache 0x0000000081013ee0: page still has mappings!

Kernel stack: 0x80c04000, 0x80c09000
kernel entry at 802d48b0
Kernel entry point
arch_debug_init()
Welcome to kernel debugger output!
Haiku revision: , debug level: 2
INIT: init CPU
INIT: init interrupts
arch_int_init()
MTrap(exception mEcall)
  mstatus: (ie: {s}, pie: {m}, spp: u, mpp: m)
  mepc: <kernel_riscv64> msyscall + 0
  mie: {}
  mip: {mTimer, sExtern, mExtern}
  sip: {}
Stack:
FP: 0x80c08ed0, PC: <kernel_riscv64> MTrap + 331
FP: 0x80c08fd0, PC: <kernel_riscv64> MVec + 81
FP: 0x80c08fe0, PC: <kernel_riscv64> 0x801346cf
FP: 0x80c09000, PC: <kernel_riscv64> _start + 369
FP: 0x80144f10, PC: 0x8000019f
FP: 0x80144f70, PC: 0x800261cb
FP: 0x80145000, PC: 0x800002d3
FP: 0x0, PC: 0x8000000d
testMmodeSyscall(10, -15, 12345678987654321)
testMmodeSyscall: 456
MTrap(exception mEcall)
  mstatus: (ie: {s}, pie: {m}, spp: u, mpp: m)
  mepc: <kernel_riscv64> msyscall + 0
  mie: {}
  mip: {mTimer, sExtern, mExtern}
  sip: {}
Stack:
FP: 0x80c08ed0, PC: <kernel_riscv64> MTrap + 331
FP: 0x80c08fd0, PC: <kernel_riscv64> MVec + 81
FP: 0x80c08fe0, PC: <kernel_riscv64> 0x801346cf
FP: 0x80c09000, PC: <kernel_riscv64> _start + 369
FP: 0x80144f10, PC: 0x8000019f
FP: 0x80144f70, PC: 0x800261cb
FP: 0x80145000, PC: 0x800002d3
FP: 0x0, PC: 0x8000000d
switchToSmodeMmodeSyscall()
  mstatus (2): (ie: {s}, pie: {m}, spp: u, mpp: s)
INIT: init VM
vm_translation_map_init()
paging enabled
PhysMem(0): 0x08145117
PhysMem(4): 0x0810113
PhysMem(8): 0x08ef4401
physical memory ranges:
  80000000 - 88000000
allocated physical ranges:
  80000000 - 80c55000
allocated virtual ranges:
  80000000 - 80c09000
+RISCV64VMPhysicalPageMapper
arch_vm_init()
first phys page = 0x80000, end 0x88000
vm_page_init: entry
vm_init: putting free_page_table @ 0x0000000081800000, # ents 32768 (size 0x280000)
initialized table
mark_page_range_in_use: start 0x0, len 0x80000
mark_page_range_in_use(0x0, 0x80000): start page is before free list
mark_page_range_in_use: start 0x80000, len 0x16db
vm_page_init: exit
arch_vm_translation_map_create_map()
+RISCV64VMTranslationMap(1, 0x80c09000)
_map: 0x000000008100df40
arch_vm_translation_map_init_post_area()
arch_vm_init_post_area()
vm_page_init_post_area()
sPages: 0x0000000081800000
RISCV64VMTranslationMap::Lock()
RISCV64VMTranslationMap::Unlock()
RISCV64VMTranslationMap::Lock()
RISCV64VMTranslationMap::Unlock()
RISCV64VMTranslationMap::Lock()
RISCV64VMTranslationMap::Unmap(0x81000000, 0x81000fff)
RISCV64VMTranslationMap::Unlock()
...
INIT: init modules
user_debug_image_deleted()
RISCV64VMTranslationMap::UnmapPages(0x0x0000000081012000, 0x80c00000, 0x3000, 1)
RISCV64VMTranslationMap::Unmap(0x80c00000, 0x80c03000)
PANIC: remove page 0x000000008183c0a0 from cache 0x0000000081013ee0: page still has mappings!

Welcome to Kernel Debugging Land...
Thread 0 "" running on CPU 0
Stack:
FP: 0x80c08c10, PC: <kernel_riscv64> _ZL20kernel_debugger_loopPKcS0_Pvi + 243
FP: 0x80c08c80, PC: <kernel_riscv64> _ZL24kernel_debugger_internalPKcS0_Pvi + 131
FP: 0x80c08cc0, PC: <kernel_riscv64> panic + 93
FP: 0x80c08d60, PC: <kernel_riscv64> _ZN7VMCache6DeleteEv.localalias.12 + 117
FP: 0x80c08dc0, PC: <kernel_riscv64> _ZL11delete_areaP14VMAddressSpaceP6VMAreab + 409
FP: 0x80c08ee0, PC: <kernel_riscv64> vm_delete_area.localalias.30 + 417
FP: 0x80c08f00, PC: <kernel_riscv64> _ZL16delete_elf_imageP14elf_image_info + 21
FP: 0x80c08f50, PC: <kernel_riscv64> unload_kernel_add_on + 259
FP: 0x80c08fe0, PC: <kernel_riscv64> module_init + 1133
FP: 0x80c09000, PC: <kernel_riscv64> _start + 553
FP: 0x80144f10, PC: 0x8000019f
FP: 0x80144f70, PC: 0x800261cb
FP: 0x80145000, PC: 0x800002d3
FP: 0x0, PC: 0x8000000d
initial commands: page 0x000000008183c0a0; cache 0x0000000081013ee0
, at position: 0, in command line: page 0x000000008183c0a0; cache 0x0000000081013ee0
kdebug> 
3 Likes

I progressed to INIT: init VM semaphores. Now something is attempting to delete kernel address space.

RISCV64VMPhysicalPageMapper::MemsetPhysical(0x8091c000, 0x0, 0x1000)
RISCV64VMTranslationMap::Lock()
RISCV64VMTranslationMap::Map(0x80be0000, 0x8091c000)
RISCV64VMTranslationMap::Unlock()
RISCV64VMPhysicalPageMapper::MemsetPhysical(0x80922000, 0x0, 0x1000)
RISCV64VMTranslationMap::Lock()
RISCV64VMTranslationMap::Map(0x80be1000, 0x80922000)
RISCV64VMTranslationMap::Unlock()
RISCV64VMPhysicalPageMapper::MemsetPhysical(0x8091e000, 0x0, 0x1000)
RISCV64VMTranslationMap::Lock()
RISCV64VMTranslationMap::Map(0x80be2000, 0x8091e000)
RISCV64VMTranslationMap::Unlock()
RISCV64VMPhysicalPageMapper::MemsetPhysical(0x8091f000, 0x0, 0x1000)
RISCV64VMTranslationMap::Lock()
RISCV64VMTranslationMap::Map(0x80be3000, 0x8091f000)
RISCV64VMTranslationMap::Unlock()
INIT: init system info
INIT: init SMP
INIT: init timer
INIT: init real time clock
allocate_commpage_entry(2, 16) -> 0x0000000000000200
INIT: init condition variables
INIT: init VM semaphores
arch_vm_init_end(): 0 virtual ranges to keep:
PANIC: deleting the kernel aspace!

Welcome to Kernel Debugging Land...
Thread 0 "" running on CPU 0
Stack:
FP: 0x80c07de0, PC: <kernel_riscv64> _ZL20kernel_debugger_loopPKcS0_Pvi + 243
FP: 0x80c07e50, PC: <kernel_riscv64> _ZL24kernel_debugger_internalPKcS0_Pvi + 131
FP: 0x80c07e90, PC: <kernel_riscv64> panic + 93
FP: 0x80c07ef0, PC: <kernel_riscv64> _ZN20VMKernelAddressSpaceD2Ev.localalias.5 + 37
FP: 0x80c07f10, PC: <kernel_riscv64> _ZN20VMKernelAddressSpaceD0Ev.localalias.6 + 15
FP: 0x80c07f70, PC: <kernel_riscv64> _ZN20VMKernelAddressSpace21UnreserveAddressRangeEmmj.localalias.19 + 189
FP: 0x80c07fb0, PC: <kernel_riscv64> vm_unreserve_address_range.localalias.37 + 67
FP: 0x80c07fe0, PC: <kernel_riscv64> vm_init_post_sem + 223
FP: 0x80c08000, PC: <kernel_riscv64> _start + 781
FP: 0x80144f10, PC: 0x8000019f
FP: 0x80144f70, PC: 0x800261cb
FP: 0x80145000, PC: 0x800002d3
FP: 0x0, PC: 0x8000000d
kdebug>
3 Likes

Framebuffer KDL is still not working yet, only console. Keyboard input is also not working, it need Virtio keyboard or console driver.

1 Like

Threads are partially working, but something is currently messed up:

INIT: init system info
INIT: init SMP
INIT: init timer
INIT: init real time clock
allocate_commpage_entry(2, 16) -> 0x0000000000000200
INIT: init condition variables
INIT: init VM semaphores
arch_vm_init_end(): 0 virtual ranges to keep:
arch_vm_translation_map_init_post_sem()
INIT: init generic syscall
INIT: init scheduler
scheduler_init: found 1 logical cpu and 0 cache levels
scheduler switches: single core: true, cpu load tracking: false, core load tracking: false
scheduler: switching to low latency mode
INIT: init threads
arch_thread_init_kthread_stack(0x000000008129f700(undertaker), 0x0000000080ae4000, 0x0000000080ae8fe0, 0x00000000802f24de, 0x0000000080ae8fe0)
INIT: init kernel daemons
arch_thread_init_kthread_stack(0x000000008129f240(kernel daemon), 0x0000000080962000, 0x0000000080966fe0, 0x00000000802f24de, 0x0000000080966fe0)
arch_thread_init_kthread_stack(0x000000008129ed80(resource resizer), 0x000000008090b000, 0x000000008090ffe0, 0x00000000802f24de, 0x000000008090ffe0)
INIT: init I/O interrupts
arch_int_init_io()
INIT: init VM threads
arch_thread_init_kthread_stack(0x000000008129e8c0(page scrubber), 0x00000000808e8000, 0x00000000808ecfe0, 0x00000000802f24de, 0x00000000808ecfe0)
arch_thread_init_kthread_stack(0x000000008129e400(page writer), 0x00000000806a7000, 0x00000000806abfe0, 0x00000000802f24de, 0x00000000806abfe0)
arch_thread_init_kthread_stack(0x000000008129df40(page daemon), 0x0000000080691000, 0x0000000080695fe0, 0x00000000802f24de, 0x0000000080695fe0)
arch_thread_init_kthread_stack(0x000000008129da80(object cache resizer), 0x0000000080ae9000, 0x0000000080aedfe0, 0x00000000802f24de, 0x0000000080aedfe0)
arch_thread_init_kthread_stack(0x000000008129d5c0(low resource manager), 0x0000000080967000, 0x000000008096bfe0, 0x00000000802f24de, 0x000000008096bfe0)
INIT: init DPC
arch_thread_init_kthread_stack(0x000000008129d100(dpc: normal priority), 0x0000000080bb1000, 0x0000000080bb5fe0, 0x00000000802f24de, 0x0000000080bb5fe0)
arch_thread_init_kthread_stack(0x000000008129cc40(dpc: high priority), 0x0000000080bb6000, 0x0000000080bbafe0, 0x00000000802f24de, 0x0000000080bbafe0)
arch_thread_init_kthread_stack(0x000000008129c780(dpc: real-time priority), 0x0000000080aab000, 0x0000000080aaffe0, 0x00000000802f24de, 0x0000000080aaffe0)
INIT: init VFS
arch_thread_init_kthread_stack(0x000000008129c2c0(block notifier/writer), 0x00000000809ff000, 0x0000000080a03fe0, 0x00000000802f24de, 0x0000000080a03fe0)
INIT: init swap support
INIT: init POSIX semaphores
INIT: spawning main2 thread
arch_thread_init_kthread_stack(0x000000008129be00(main2), 0x00000000809c8000, 0x00000000809ccfe0, 0x00000000802f24de, 0x00000000809ccfe0)
INIT: waking up AP cpus
INIT: exiting kernel startup
INIT: starting scheduler on cpu 0 and enabling interrupts
arch_thread_context_switch(0x00000000803e8988(idle thread 1), 0x000000008129da80(object cache resizer))
slab memory manager: created area 0x00000000cd001000 (134)
arch_thread_context_switch(0x000000008129da80(object cache resizer), 0x000000008129c780(dpc: real-time priority))
arch_thread_context_switch(0x000000008129c780(dpc: real-time priority), 0x000000008129cc40(dpc: high priority))
arch_thread_context_switch(0x000000008129cc40(dpc: high priority), 0x000000008129f700(undertaker))
arch_thread_context_switch(0x000000008129f700(undertaker), 0x000000008129e400(page writer))
arch_thread_context_switch(0x000000008129e400(page writer), 0x000000008129df40(page daemon))
arch_thread_context_switch(0x000000008129df40(page daemon), 0x000000008129d100(dpc: normal priority))
arch_thread_context_switch(0x000000008129d100(dpc: normal priority), 0x000000008129be00(main2))
INIT: start of main2: initializing devices
INIT: init ports
INIT: init user mutex
INIT: init system notifications
INIT: Init modules
INIT: Init Userland debugging
INIT: Init Messaging Service
INIT: Bootstrap file systems
INIT: Init Device Manager
INIT: Add preloaded old-style drivers
MTrap(exception execPageFault)
  mstatus: (ie: {s}, pie: {m}, spp: u, mpp: s)
  mepc: 0x59a0
  mie: {}
  mip: {mTimer, sExtern, mExtern}
  sip: {}
  mtval: 0x59a0
Stack:
FP: 0x809ccca0, PC: <kernel_riscv64> MTrap + 305
FP: 0x809ccda0, PC: <kernel_riscv64> MVec + 81
FP: 0x809cce10, PC: 0x599f
FP: 0xcccccccccccccccc, PC: 0xcccccccccccccccb
target_read_slow: invalid physical address 0xccccccccccccccc0, PC: 0000000080388a74
target_read_slow: invalid physical address 0xccccccccccccccc8, PC: 0000000080388a74
target_read_slow: invalid physical address 0xccccccccccccccb8, PC: 0000000080388a74
target_read_slow: invalid physical address 0xccccccccccccccc0, PC: 0000000080388a74
FP: 0x40008004198af6c8, PC: 0x40008004198af6c7
target_read_slow: invalid physical address 0x40008004198af6c0, PC: 0000000080388a74
target_read_slow: invalid physical address 0x40008004198af6b8, PC: 0000000080388a74
FP: 0xa, PC: 0x9
target_read_slow: invalid physical address 0xfffffffffffffff8, PC: 0000000080388a74
FP: 0x0, PC: 0xffffffffffffffff
target_read_slow: invalid physical address 0x00000000ccd0c000, PC: 00000000803107a6
target_write_slow: invalid physical address 0x00000000ccd0c000, PC: 00000000803107a6
target_write_slow: invalid physical address 0x00000000ccd0c004, PC: 00000000803107a6
target_read_slow: invalid physical address 0x00000000ccd0c000, PC: 00000000803107a6
target_write_slow: invalid physical address 0x00000000ccd0c008, PC: 0000000080310866
target_write_slow: invalid physical address 0x00000000ccd0c00c, PC: 0000000080310866
target_read_slow: invalid physical address 0x00000000ccd0c000, PC: 0000000080310866
target_write_slow: invalid physical address 0x00000000ccd0c000, PC: 0000000080310866
PANIC: unhandled MTrap
Welcome to Kernel Debugging Land...
Thread 0 "" running on CPU 0
The thread's CPU pointer is 0x0000000000000000, but should be 0x00000000803d7f00.
target_read_slow: invalid physical address 0x00000000ccd0c000, PC: 0000000080310e8e
target_read_slow: invalid physical address 0x00000000ccd0c00c, PC: 0000000080310ee4
Stack:
FP: 0x809ccbb0, PC: <kernel_riscv64> _ZL20kernel_debugger_loopPKcS0_Pvi + 685
FP: 0x809ccc20, PC: <kernel_riscv64> _ZL24kernel_debugger_internalPKcS0_Pvi + 131
FP: 0x809ccc60, PC: <kernel_riscv64> panic + 93
FP: 0x809ccda0, PC: <kernel_riscv64> MVec + 81
FP: 0x809cce10, PC: 0x599f
FP: 0xcccccccccccccccc, PC: 0xcccccccccccccccb
target_read_slow: invalid physical address 0xccccccccccccccc0, PC: 0000000080388a74
target_read_slow: invalid physical address 0xccccccccccccccc8, PC: 0000000080388a74
target_read_slow: invalid physical address 0xccccccccccccccb8, PC: 0000000080388a74
target_read_slow: invalid physical address 0xccccccccccccccc0, PC: 0000000080388a74
FP: 0x4000800400000000, PC: 0x40008003ffffffff
target_read_slow: invalid physical address 0x40008003fffffff8, PC: 0000000080388a74
target_read_slow: invalid physical address 0x40008003fffffff0, PC: 0000000080388a74
FP: 0xa, PC: 0x9
target_read_slow: invalid physical address 0xfffffffffffffff8, PC: 0000000080388a74
FP: 0x0, PC: 0xffffffffffffffff
kdebug> 
15 Likes

Amazing progress and updates. Thank you for the effort!

5 Likes

Kernel framebuffer is working:

screenshot40

19 Likes

I progressed to fourth icon and “PANIC: did not find any boot partitions!” error. Now it is needed to parse FDT and setup Virtio disk driver.

screenshot41

28 Likes

This is simply stellar work.

I implemented publishing FDT nodes in FDT bus manager driver.

Existing VirtIO driver seems to be not useable because it is hardcoded to PCI bus and use different register layout. Also TinyEMU use new VirtIO version 2. But existing VirtIO API and VirtIO block driver may be useable.

PANIC: did not find any boot partitions! 
Welcome to Kernel Debugging Land...
Thread 14 "main2" running on CPU 0
Stack:
FP: 0xcd099a40, PC: <kernel_riscv64> _ZL20kernel_debugger_loopPKcS0_Pvi + 243
FP: 0xcd099ab0, PC: <kernel_riscv64> _ZL24kernel_debugger_internalPKcS0_Pvi + 131
FP: 0xcd099af0, PC: <kernel_riscv64> panic + 93
FP: 0xcd099f70, PC: <kernel_riscv64> vfs_mount_boot_file_system + 821
FP: 0xcd099fc0, PC: <kernel_riscv64> _ZL5main2Pv + 283
FP: 0xcd099fe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
initial commands:  dm_tree
(0) @0x00000000813afe60 "system/devices_root/driver_v1" (ref 26, init 23, module 0x00000000803d3700, data 0x0000000000000000)
      "device/pretty name" : string : "Devices Root"
      "device/bus" : string : "root"
      "device/flags" : uint32 : 6 (0x6)
      "device/driver" : string : "system/devices_root/driver_v1"
   (1) @0x00000000813afdc0 "bus_managers/fdt/root/driver_v1" (ref 21, init 19, module 0x000000008078d878, data 0x00000000813afdc0)
         "device/pretty name" : string : "FDT"
         "device/flags" : uint32 : 4 (0x4)
         "device/driver" : string : "bus_managers/fdt/root/driver_v1"
      (2) @0x00000000813afd20 "bus_managers/fdt/driver_v1" (ref 23, init 17, module 0x000000008078d818, data 0x0000000000000000)
            "device/bus" : string : "fdt"
            "fdt/node" : uint32 : 0 (0x0)
            "fdt/name" : string : ""
            "fdt/compatible" : string : "ucbbar,riscvemu-bar_dev"
            "device/driver" : string : "bus_managers/fdt/driver_v1"
         (3) @0x00000000813af320 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d818, data 0x0000000000000000)
               "device/bus" : string : "fdt"
               "fdt/node" : uint32 : 1664 (0x680)
               "fdt/name" : string : "chosen"
               "device/driver" : string : "bus_managers/fdt/driver_v1"
         (3) @0x00000000813af960 "bus_managers/fdt/driver_v1" (ref 20, init 10, module 0x000000008078d818, data 0x0000000000000000)
               "device/bus" : string : "fdt"
               "fdt/node" : uint32 : 548 (0x224)
               "fdt/name" : string : "soc"
               "fdt/compatible" : string : "ucbbar,riscvemu-bar-soc"
               "device/driver" : string : "bus_managers/fdt/driver_v1"
            (4) @0x00000000813af3c0 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d818, data 0x0000000000000000)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 1496 (0x5d8)
                  "fdt/name" : string : "framebuffer@41000000"
                  "fdt/compatible" : string : "simple-framebuffer"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
            (4) @0x00000000813af460 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d818, data 0x0000000000000000)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 1400 (0x578)
                  "fdt/name" : string : "virtio@40014000"
                  "fdt/compatible" : string : "virtio,mmio"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
            (4) @0x00000000813af500 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d818, data 0x0000000000000000)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 1304 (0x518)
                  "fdt/name" : string : "virtio@40013000"
                  "fdt/compatible" : string : "virtio,mmio"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
            (4) @0x00000000813af5a0 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d818, data 0x0000000000000000)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 1208 (0x4b8)
                  "fdt/name" : string : "virtio@40012000"
                  "fdt/compatible" : string : "virtio,mmio"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
            (4) @0x00000000813af640 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d818, data 0x0000000000000000)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 1112 (0x458)
                  "fdt/name" : string : "virtio@40011000"
                  "fdt/compatible" : string : "virtio,mmio"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
            (4) @0x00000000813af6e0 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d818, data 0x0000000000000000)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 1016 (0x3f8)
                  "fdt/name" : string : "virtio@40010000"
                  "fdt/compatible" : string : "virtio,mmio"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
            (4) @0x00000000813af780 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d818, data 0x0000000000000000)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 920 (0x398)
                  "fdt/name" : string : "serial@10000000"
                  "fdt/compatible" : string : "ns16550a"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
            (4) @0x00000000813af820 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d818, data 0x0000000000000000)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 756 (0x2f4)
                  "fdt/name" : string : "plic@40100000"
                  "fdt/compatible" : string : "riscv,plic0"
                  "fdt/phandle" : uint32 : 2 (0x2)
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
            (4) @0x00000000813af8c0 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d818, data 0x0000000000000000)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 648 (0x288)
                  "fdt/name" : string : "clint@2000000"
                  "fdt/compatible" : string : "riscv,clint0"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
         (3) @0x00000000813afa00 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d818, data 0x0000000000000000)
               "device/bus" : string : "fdt"
               "fdt/node" : uint32 : 508 (0x1fc)
               "fdt/name" : string : "htif"
               "fdt/compatible" : string : "ucb,htif0"
               "device/driver" : string : "bus_managers/fdt/driver_v1"
         (3) @0x00000000813afaa0 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d818, data 0x0000000000000000)
               "device/bus" : string : "fdt"
               "fdt/node" : uint32 : 436 (0x1b4)
               "fdt/name" : string : "memory@80000000"
               "fdt/device_type" : string : "memory"
               "device/driver" : string : "bus_managers/fdt/driver_v1"
         (3) @0x00000000813afc80 "bus_managers/fdt/driver_v1" (ref 5, init 3, module 0x000000008078d818, data 0x0000000000000000)
               "device/bus" : string : "fdt"
               "fdt/node" : uint32 : 112 (0x70)
               "fdt/name" : string : "cpus"
               "device/driver" : string : "bus_managers/fdt/driver_v1"
            (4) @0x00000000813afbe0 "bus_managers/fdt/driver_v1" (ref 4, init 2, module 0x000000008078d818, data 0x0000000000000000)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 172 (0xac)
                  "fdt/name" : string : "cpu@0"
                  "fdt/device_type" : string : "cpu"
                  "fdt/compatible" : string : "riscv"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
               (5) @0x00000000813afb40 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d818, data 0x0000000000000000)
                     "device/bus" : string : "fdt"
                     "fdt/node" : uint32 : 324 (0x144)
                     "fdt/name" : string : "interrupt-controller"
                     "fdt/compatible" : string : "riscv,cpu-intc"
                     "fdt/phandle" : uint32 : 1 (0x1)
                     "device/driver" : string : "bus_managers/fdt/driver_v1"
   (1) @0x00000000813af280 "system/devices_generic/driver_v1" (ref 3, init 2, module 0x00000000803d36a0, data 0x0000000000000000)
         "device/pretty name" : string : "Generic"
         "device/bus" : string : "generic"
         "device/flags" : uint32 : 7 (0x7)
         "device/driver" : string : "system/devices_generic/driver_v1"
kdebug> 
13 Likes

Every day progress amazing! Do not forget to rest!

3 Likes

I think that’s the idea in the virtio stack (and in the “new driver model” in general). The low-level driver is specific to PCI, but then all layers above can be generic and reused easily (hopefully).

1 Like

VirtIO driver registration working:

PANIC: did not find any boot partitions! 
Welcome to Kernel Debugging Land...
Thread 14 "main2" running on CPU 0
Stack:
FP: 0xcd099a40, PC: <kernel_riscv64> _ZL20kernel_debugger_loopPKcS0_Pvi + 243
FP: 0xcd099ab0, PC: <kernel_riscv64> _ZL24kernel_debugger_internalPKcS0_Pvi + 131
FP: 0xcd099af0, PC: <kernel_riscv64> panic + 93
FP: 0xcd099f70, PC: <kernel_riscv64> vfs_mount_boot_file_system + 821
FP: 0xcd099fc0, PC: <kernel_riscv64> _ZL5main2Pv + 283
FP: 0xcd099fe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
initial commands:  dm_tree
(0) @0x00000000813afe60 "system/devices_root/driver_v1" (ref 31, init 28, module 0x00000000803d3730, data 0x0000000000000000)
      "device/pretty name" : string : "Devices Root"
      "device/bus" : string : "root"
      "device/flags" : uint32 : 6 (0x6)
      "device/driver" : string : "system/devices_root/driver_v1"
   (1) @0x00000000813afdc0 "bus_managers/fdt/root/driver_v1" (ref 27, init 24, module 0x000000008078d240, data 0x0000000081262690)
         "device/pretty name" : string : "FDT"
         "device/flags" : uint32 : 4 (0x4)
         "device/driver" : string : "bus_managers/fdt/root/driver_v1"
      (2) @0x00000000813afd20 "bus_managers/fdt/driver_v1" (ref 33, init 22, module 0x000000008078d2a8, data 0x0000000081023630)
            "device/bus" : string : "fdt"
            "fdt/node" : uint32 : 0 (0x0)
            "fdt/name" : string : ""
            "fdt/compatible" : string : "ucbbar,riscvemu-bar_dev"
            "device/driver" : string : "bus_managers/fdt/driver_v1"
         (3) @0x00000000813af000 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d2a8, data 0x00000000813b5b10)
               "device/bus" : string : "fdt"
               "fdt/node" : uint32 : 1664 (0x680)
               "fdt/name" : string : "chosen"
               "device/driver" : string : "bus_managers/fdt/driver_v1"
         (3) @0x00000000813af960 "bus_managers/fdt/driver_v1" (ref 34, init 15, module 0x000000008078d2a8, data 0x0000000081023250)
               "device/bus" : string : "fdt"
               "fdt/node" : uint32 : 548 (0x224)
               "fdt/name" : string : "soc"
               "fdt/compatible" : string : "ucbbar,riscvemu-bar-soc"
               "device/driver" : string : "bus_managers/fdt/driver_v1"
            (4) @0x00000000813af0a0 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d2a8, data 0x00000000813b5b80)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 1496 (0x5d8)
                  "fdt/name" : string : "framebuffer@41000000"
                  "fdt/compatible" : string : "simple-framebuffer"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
            (4) @0x00000000813af1e0 "bus_managers/fdt/driver_v1" (ref 5, init 2, module 0x000000008078d2a8, data 0x00000000813b5c30)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 1400 (0x578)
                  "fdt/name" : string : "virtio@40014000"
                  "fdt/compatible" : string : "virtio,mmio"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
               (5) @0x00000000813af140 "busses/virtio/virtio_mmio/driver_v1" (ref 2, init 1, module 0x00000000809c2db0, data 0x0000000081049440)
                     "device/pretty name" : string : "Virtio MMIO"
                     "virtio/version" : uint32 : 2 (0x2)
                     "virtio/device_id" : uint32 : 18 (0x12)
                     "virtio/vendor_id" : uint32 : 65535 (0xffff)
                     "device/driver" : string : "busses/virtio/virtio_mmio/driver_v1"
            (4) @0x00000000813af320 "bus_managers/fdt/driver_v1" (ref 5, init 2, module 0x000000008078d2a8, data 0x00000000813b5d20)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 1304 (0x518)
                  "fdt/name" : string : "virtio@40013000"
                  "fdt/compatible" : string : "virtio,mmio"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
               (5) @0x00000000813af280 "busses/virtio/virtio_mmio/driver_v1" (ref 2, init 1, module 0x00000000809c2db0, data 0x00000000810494a0)
                     "device/pretty name" : string : "Virtio MMIO"
                     "virtio/version" : uint32 : 2 (0x2)
                     "virtio/device_id" : uint32 : 18 (0x12)
                     "virtio/vendor_id" : uint32 : 65535 (0xffff)
                     "device/driver" : string : "busses/virtio/virtio_mmio/driver_v1"
            (4) @0x00000000813af460 "bus_managers/fdt/driver_v1" (ref 5, init 2, module 0x000000008078d2a8, data 0x00000000813b5df0)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 1208 (0x4b8)
                  "fdt/name" : string : "virtio@40012000"
                  "fdt/compatible" : string : "virtio,mmio"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
               (5) @0x00000000813af3c0 "busses/virtio/virtio_mmio/driver_v1" (ref 2, init 1, module 0x00000000809c2db0, data 0x0000000081049500)
                     "device/pretty name" : string : "Virtio MMIO"
                     "virtio/version" : uint32 : 2 (0x2)
                     "virtio/device_id" : uint32 : 2 (0x2)
                     "virtio/vendor_id" : uint32 : 65535 (0xffff)
                     "device/driver" : string : "busses/virtio/virtio_mmio/driver_v1"
            (4) @0x00000000813af5a0 "bus_managers/fdt/driver_v1" (ref 5, init 2, module 0x000000008078d2a8, data 0x00000000813b5ef0)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 1112 (0x458)
                  "fdt/name" : string : "virtio@40011000"
                  "fdt/compatible" : string : "virtio,mmio"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
               (5) @0x00000000813af500 "busses/virtio/virtio_mmio/driver_v1" (ref 2, init 1, module 0x00000000809c2db0, data 0x0000000081049560)
                     "device/pretty name" : string : "Virtio MMIO"
                     "virtio/version" : uint32 : 2 (0x2)
                     "virtio/device_id" : uint32 : 1 (0x1)
                     "virtio/vendor_id" : uint32 : 65535 (0xffff)
                     "device/driver" : string : "busses/virtio/virtio_mmio/driver_v1"
            (4) @0x00000000813af6e0 "bus_managers/fdt/driver_v1" (ref 5, init 2, module 0x000000008078d2a8, data 0x0000000081023010)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 1016 (0x3f8)
                  "fdt/name" : string : "virtio@40010000"
                  "fdt/compatible" : string : "virtio,mmio"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
               (5) @0x00000000813af640 "busses/virtio/virtio_mmio/driver_v1" (ref 2, init 1, module 0x00000000809c2db0, data 0x00000000810495c0)
                     "device/pretty name" : string : "Virtio MMIO"
                     "virtio/version" : uint32 : 2 (0x2)
                     "virtio/device_id" : uint32 : 3 (0x3)
                     "virtio/vendor_id" : uint32 : 65535 (0xffff)
                     "device/driver" : string : "busses/virtio/virtio_mmio/driver_v1"
            (4) @0x00000000813af780 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d2a8, data 0x0000000081023090)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 920 (0x398)
                  "fdt/name" : string : "serial@10000000"
                  "fdt/compatible" : string : "ns16550a"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
            (4) @0x00000000813af820 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d2a8, data 0x0000000081023130)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 756 (0x2f4)
                  "fdt/name" : string : "plic@40100000"
                  "fdt/compatible" : string : "riscv,plic0"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
            (4) @0x00000000813af8c0 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d2a8, data 0x00000000810231b0)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 648 (0x288)
                  "fdt/name" : string : "clint@2000000"
                  "fdt/compatible" : string : "riscv,clint0"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
         (3) @0x00000000813afa00 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d2a8, data 0x00000000810232d0)
               "device/bus" : string : "fdt"
               "fdt/node" : uint32 : 508 (0x1fc)
               "fdt/name" : string : "htif"
               "fdt/compatible" : string : "ucb,htif0"
               "device/driver" : string : "bus_managers/fdt/driver_v1"
         (3) @0x00000000813afaa0 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d2a8, data 0x0000000081023350)
               "device/bus" : string : "fdt"
               "fdt/node" : uint32 : 436 (0x1b4)
               "fdt/name" : string : "memory@80000000"
               "fdt/device_type" : string : "memory"
               "device/driver" : string : "bus_managers/fdt/driver_v1"
         (3) @0x00000000813afc80 "bus_managers/fdt/driver_v1" (ref 6, init 3, module 0x000000008078d2a8, data 0x0000000081023530)
               "device/bus" : string : "fdt"
               "fdt/node" : uint32 : 112 (0x70)
               "fdt/name" : string : "cpus"
               "device/driver" : string : "bus_managers/fdt/driver_v1"
            (4) @0x00000000813afbe0 "bus_managers/fdt/driver_v1" (ref 5, init 2, module 0x000000008078d2a8, data 0x0000000081023460)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 172 (0xac)
                  "fdt/name" : string : "cpu@0"
                  "fdt/device_type" : string : "cpu"
                  "fdt/compatible" : string : "riscv"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
               (5) @0x00000000813afb40 "bus_managers/fdt/driver_v1" (ref 2, init 1, module 0x000000008078d2a8, data 0x00000000810233f0)
                     "device/bus" : string : "fdt"
                     "fdt/node" : uint32 : 324 (0x144)
                     "fdt/name" : string : "interrupt-controller"
                     "fdt/compatible" : string : "riscv,cpu-intc"
                     "device/driver" : string : "bus_managers/fdt/driver_v1"
   (1) @0x00000000813b9f08 "system/devices_generic/driver_v1" (ref 3, init 2, module 0x00000000803d36d0, data 0x0000000000000000)
         "device/pretty name" : string : "Generic"
         "device/bus" : string : "generic"
         "device/flags" : uint32 : 7 (0x7)
         "device/driver" : string : "system/devices_generic/driver_v1"
7 Likes

Existing Haiku virtio_block driver attached. Not working yet because of not implemented VirtIO driver interface.

            (4) @0x00000000813af460 "bus_managers/fdt/driver_v1" (ref 6, init 3, module 0x000000008078d2a8, data 0x00000000813b5d90)
                  "device/bus" : string : "fdt"
                  "fdt/node" : uint32 : 1208 (0x4b8)
                  "fdt/name" : string : "virtio@40012000"
                  "fdt/compatible" : string : "virtio,mmio"
                  "device/driver" : string : "bus_managers/fdt/driver_v1"
               (5) @0x00000000813af3c0 "busses/virtio/virtio_mmio/driver_v1" (ref 4, init 2, module 0x00000000809c2e08, data 0x0000000081049500)
                     "device/pretty name" : string : "Virtio MMIO"
                     "device/bus" : string : "virtio"
                     "virtio/version" : uint32 : 2 (0x2)
                     "virtio/device_id" : uint32 : 2 (0x2)
                     "virtio/type" : uint16 : 2 (0x2)
                     "virtio/vendor_id" : uint32 : 65535 (0xffff)
                     "device/driver" : string : "busses/virtio/virtio_mmio/driver_v1"
                  (6) @0x00000000813af320 "drivers/disk/virtual/virtio_block/driver_v1" (ref 2, init 1, module 0x00000000809bf340, data 0x00000000813b7cb0)
                        "device/driver" : string : "drivers/disk/virtual/virtio_block/driver_v1"
                        "dev/5/path" : string : "disk/virtual/virtio_block/0/raw"
                        "dev/5/driver" : string : "drivers/disk/virtual/virtio_block/device_v1"
                  device: drivers/disk/virtual/virtio_block/device_v1, 0x0000000000000000
9 Likes

So the Haiku software engineering consists in pursuing the goal that will launch the system, and then patching any reported holes (bugs).

VirtIO disk reading is working. Boot volume is mounted.

device 0: /dev/disk/virtual/virtio_block/0/raw
  media status:      No error
  device flags:      2
  offset:            0
  size:              314573312 (300 MB)
  content size:      314572800
  block size:        2048
  child count:       0
  index:             -1
  status:            0
  flags:             3
  volume:            -1
  disk system:       file_systems/bfs/v1
  name:              <NULL>
  content name:      Haiku
  type:              <NULL>
  content type:      Be File System
  params:            <NULL>
  content params:    <NULL>
virtio_block: CALLED status_t virtio_block_read(void*, off_t, void*, size_t*)
virtio_mmio: virtio_device_queue_request_v(0x00000000813b7cb0)
  vector[0]: 0x812ff7b0, 0x10, read
  vector[1]: 0x810598c0, 0x200, write
  vector[2]: 0x812ff7c0, 0x1, write
virtio_mmio: dev->fRegs->queueNotify = 0
TinyEMU: queue_notify(0)
TinyEMU: virtio_block_recv_request
STrap(interrupt sExtern)
  sstatus: (ie: {}, pie: {s}, spp: s)
  sepc: <virtio_block> _ZL5do_ioPvP11IOOperation + 230
  sie: {sExtern}
  sip: {sExtern}
  irq: 3
Stack:
FP: 0xcd11fce0, PC: <kernel_riscv64> STrap + 363
FP: 0xcd11fde0, PC: <kernel_riscv64> SVec + 81
FP: 0xcd11fe60, PC: <virtio_block> _ZL5do_ioPvP11IOOperation + 229
FP: 0xcd11ffc0, PC: <kernel_riscv64> _ZN17IOSchedulerSimple10_SchedulerEv.localalias.2 + 1181
FP: 0xcd11ffe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
virtio_mmio: virtio_interrupt_handler(0x0000000081265600)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_block: CALLED status_t virtio_block_read(void*, off_t, void*, size_t*)
virtio_mmio: virtio_device_queue_request_v(0x00000000813b7cb0)
  vector[0]: 0x812ff7b0, 0x10, read
  vector[1]: 0x810598c0, 0x200, write
  vector[2]: 0x812ff7c0, 0x1, write
virtio_mmio: dev->fRegs->queueNotify = 0
TinyEMU: queue_notify(0)
TinyEMU: virtio_block_recv_request
STrap(interrupt sExtern)
  sstatus: (ie: {}, pie: {s}, spp: s)
  sepc: <virtio_block> _ZL5do_ioPvP11IOOperation + 230
  sie: {sExtern}
  sip: {sExtern}
  irq: 3
Stack:
FP: 0xcd11fce0, PC: <kernel_riscv64> STrap + 363
FP: 0xcd11fde0, PC: <kernel_riscv64> SVec + 81
FP: 0xcd11fe60, PC: <virtio_block> _ZL5do_ioPvP11IOOperation + 229
FP: 0xcd11ffc0, PC: <kernel_riscv64> _ZN17IOSchedulerSimple10_SchedulerEv.localalias.2 + 1181
FP: 0xcd11ffe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
virtio_mmio: virtio_interrupt_handler(0x0000000081265600)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_block: CALLED status_t virtio_block_read(void*, off_t, void*, size_t*)
virtio_mmio: virtio_device_queue_request_v(0x00000000813b7cb0)
  vector[0]: 0x812ff7b0, 0x10, read
  vector[1]: 0x810598c0, 0x200, write
  vector[2]: 0x812ff7c0, 0x1, write
virtio_mmio: dev->fRegs->queueNotify = 0
TinyEMU: queue_notify(0)
TinyEMU: virtio_block_recv_request
STrap(interrupt sExtern)
  sstatus: (ie: {}, pie: {s}, spp: s)
  sepc: <virtio_block> _ZL5do_ioPvP11IOOperation + 230
  sie: {sExtern}
  sip: {sExtern}
  irq: 3
Stack:
FP: 0xcd11fce0, PC: <kernel_riscv64> STrap + 363
FP: 0xcd11fde0, PC: <kernel_riscv64> SVec + 81
FP: 0xcd11fe60, PC: <virtio_block> _ZL5do_ioPvP11IOOperation + 229
FP: 0xcd11ffc0, PC: <kernel_riscv64> _ZN17IOSchedulerSimple10_SchedulerEv.localalias.2 + 1181
FP: 0xcd11ffe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
virtio_mmio: virtio_interrupt_handler(0x0000000081265600)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_block: CALLED status_t virtio_block_read(void*, off_t, void*, size_t*)
virtio_mmio: virtio_device_queue_request_v(0x00000000813b7cb0)
  vector[0]: 0x812ff7b0, 0x10, read
  vector[1]: 0x810598c0, 0x200, write
  vector[2]: 0x812ff7c0, 0x1, write
virtio_mmio: dev->fRegs->queueNotify = 0
TinyEMU: queue_notify(0)
TinyEMU: virtio_block_recv_request
STrap(interrupt sExtern)
  sstatus: (ie: {}, pie: {s}, spp: s)
  sepc: <virtio_block> _ZL5do_ioPvP11IOOperation + 230
  sie: {sExtern}
  sip: {sExtern}
  irq: 3
Stack:
FP: 0xcd11fce0, PC: <kernel_riscv64> STrap + 363
FP: 0xcd11fde0, PC: <kernel_riscv64> SVec + 81
FP: 0xcd11fe60, PC: <virtio_block> _ZL5do_ioPvP11IOOperation + 229
FP: 0xcd11ffc0, PC: <kernel_riscv64> _ZN17IOSchedulerSimple10_SchedulerEv.localalias.2 + 1181
FP: 0xcd11ffe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
virtio_mmio: virtio_interrupt_handler(0x0000000081265600)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_block: CALLED status_t virtio_block_read(void*, off_t, void*, size_t*)
virtio_mmio: virtio_device_queue_request_v(0x00000000813b7cb0)
  vector[0]: 0x812ff7b0, 0x10, read
  vector[1]: 0x810598c0, 0x200, write
  vector[2]: 0x812ff7c0, 0x1, write
virtio_mmio: dev->fRegs->queueNotify = 0
TinyEMU: queue_notify(0)
TinyEMU: virtio_block_recv_request
STrap(interrupt sExtern)
  sstatus: (ie: {}, pie: {s}, spp: s)
  sepc: <virtio_block> _ZL5do_ioPvP11IOOperation + 230
  sie: {sExtern}
  sip: {sExtern}
  irq: 3
Stack:
FP: 0xcd11fce0, PC: <kernel_riscv64> STrap + 363
FP: 0xcd11fde0, PC: <kernel_riscv64> SVec + 81
FP: 0xcd11fe60, PC: <virtio_block> _ZL5do_ioPvP11IOOperation + 229
FP: 0xcd11ffc0, PC: <kernel_riscv64> _ZN17IOSchedulerSimple10_SchedulerEv.localalias.2 + 1181
FP: 0xcd11ffe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
virtio_mmio: virtio_interrupt_handler(0x0000000081265600)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
Identified boot partition by partition offset.
virtio_block: CALLED status_t virtio_block_open(void*, const char*, int, void**)
virtio_block: CALLED status_t virtio_block_ioctl(void*, uint32, void*, size_t)
virtio_block: ioctl(op = 7)
virtio_block: virtio_block: get_geometry(): 512, 614401, 1, 1, 0, 0, 0, 0
virtio_block: CALLED status_t virtio_block_read(void*, off_t, void*, size_t*)
virtio_mmio: virtio_device_queue_request_v(0x00000000813b7cb0)
  vector[0]: 0x812ff7b0, 0x10, read
  vector[1]: 0x81059400, 0x400, write
  vector[2]: 0x812ff7c0, 0x1, write
virtio_mmio: dev->fRegs->queueNotify = 0
TinyEMU: queue_notify(0)
TinyEMU: virtio_block_recv_request
STrap(interrupt sExtern)
  sstatus: (ie: {}, pie: {s}, spp: s)
  sepc: <virtio_block> _ZL5do_ioPvP11IOOperation + 230
  sie: {sExtern}
  sip: {sExtern}
  irq: 3
Stack:
FP: 0xcd11fce0, PC: <kernel_riscv64> STrap + 363
FP: 0xcd11fde0, PC: <kernel_riscv64> SVec + 81
FP: 0xcd11fe60, PC: <virtio_block> _ZL5do_ioPvP11IOOperation + 229
FP: 0xcd11ffc0, PC: <kernel_riscv64> _ZN17IOSchedulerSimple10_SchedulerEv.localalias.2 + 1181
FP: 0xcd11ffe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
virtio_mmio: virtio_interrupt_handler(0x0000000081265600)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_block: CALLED status_t virtio_block_ioctl(void*, uint32, void*, size_t)
virtio_block: ioctl(op = 7)
virtio_block: virtio_block: get_geometry(): 512, 614401, 1, 1, 0, 0, 0, 0
virtio_block: CALLED status_t virtio_block_read(void*, off_t, void*, size_t*)
virtio_mmio: virtio_device_queue_request_v(0x00000000813b7cb0)
  vector[0]: 0x812ff420, 0x10, read
  vector[1]: 0x818e7800, 0x800, write
  vector[2]: 0x812ff430, 0x1, write
virtio_mmio: dev->fRegs->queueNotify = 0
TinyEMU: queue_notify(0)
TinyEMU: virtio_block_recv_request
STrap(interrupt sExtern)
  sstatus: (ie: {}, pie: {s}, spp: s)
  sepc: <virtio_block> _ZL5do_ioPvP11IOOperation + 230
  sie: {sExtern}
  sip: {sExtern}
  irq: 3
Stack:
FP: 0xcd11fce0, PC: <kernel_riscv64> STrap + 363
FP: 0xcd11fde0, PC: <kernel_riscv64> SVec + 81
FP: 0xcd11fe60, PC: <virtio_block> _ZL5do_ioPvP11IOOperation + 229
FP: 0xcd11ffc0, PC: <kernel_riscv64> _ZN17IOSchedulerSimple10_SchedulerEv.localalias.2 + 1181
FP: 0xcd11ffe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
virtio_mmio: virtio_interrupt_handler(0x0000000081265600)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_block: CALLED status_t virtio_block_read(void*, off_t, void*, size_t*)
virtio_mmio: virtio_device_queue_request_v(0x00000000813b7cb0)
  vector[0]: 0x812ff420, 0x10, read
  vector[1]: 0x818e6800, 0x800, write
  vector[2]: 0x812ff430, 0x1, write
virtio_mmio: dev->fRegs->queueNotify = 0
TinyEMU: queue_notify(0)
TinyEMU: virtio_block_recv_request
STrap(interrupt sExtern)
  sstatus: (ie: {}, pie: {s}, spp: s)
  sepc: <virtio_block> _ZL5do_ioPvP11IOOperation + 230
  sie: {sExtern}
  sip: {sExtern}
  irq: 3
Stack:
FP: 0xcd11fce0, PC: <kernel_riscv64> STrap + 363
FP: 0xcd11fde0, PC: <kernel_riscv64> SVec + 81
FP: 0xcd11fe60, PC: <virtio_block> _ZL5do_ioPvP11IOOperation + 229
FP: 0xcd11ffc0, PC: <kernel_riscv64> _ZN17IOSchedulerSimple10_SchedulerEv.localalias.2 + 1181
FP: 0xcd11ffe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
virtio_mmio: virtio_interrupt_handler(0x0000000081265600)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_block: CALLED status_t virtio_block_read(void*, off_t, void*, size_t*)
virtio_mmio: virtio_device_queue_request_v(0x00000000813b7cb0)
  vector[0]: 0x812ff420, 0x10, read
  vector[1]: 0x818e5800, 0x800, write
  vector[2]: 0x812ff430, 0x1, write
virtio_mmio: dev->fRegs->queueNotify = 0
TinyEMU: queue_notify(0)
TinyEMU: virtio_block_recv_request
STrap(interrupt sExtern)
  sstatus: (ie: {}, pie: {s}, spp: s)
  sepc: <virtio_block> _ZL5do_ioPvP11IOOperation + 230
  sie: {sExtern}
  sip: {sExtern}
  irq: 3
Stack:
FP: 0xcd11fce0, PC: <kernel_riscv64> STrap + 363
FP: 0xcd11fde0, PC: <kernel_riscv64> SVec + 81
FP: 0xcd11fe60, PC: <virtio_block> _ZL5do_ioPvP11IOOperation + 229
FP: 0xcd11ffc0, PC: <kernel_riscv64> _ZN17IOSchedulerSimple10_SchedulerEv.localalias.2 + 1181
FP: 0xcd11ffe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
virtio_mmio: virtio_interrupt_handler(0x0000000081265600)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_block: CALLED status_t virtio_block_read(void*, off_t, void*, size_t*)
virtio_block: CALLED status_t virtio_block_read(void*, off_t, void*, size_t*)
virtio_mmio: virtio_device_queue_request_v(0x00000000813b7cb0)
  vector[0]: 0x812ff420, 0x10, read
  vector[1]: 0x818e4800, 0x800, write
  vector[2]: 0x812ff430, 0x1, write
virtio_mmio: dev->fRegs->queueNotify = 0
TinyEMU: queue_notify(0)
TinyEMU: virtio_block_recv_request
STrap(interrupt sExtern)
  sstatus: (ie: {}, pie: {s}, spp: s)
  sepc: <virtio_block> _ZL5do_ioPvP11IOOperation + 230
  sie: {sExtern}
  sip: {sExtern}
  irq: 3
Stack:
FP: 0xcd11fce0, PC: <kernel_riscv64> STrap + 363
FP: 0xcd11fde0, PC: <kernel_riscv64> SVec + 81
FP: 0xcd11fe60, PC: <virtio_block> _ZL5do_ioPvP11IOOperation + 229
FP: 0xcd11ffc0, PC: <kernel_riscv64> _ZN17IOSchedulerSimple10_SchedulerEv.localalias.2 + 1181
FP: 0xcd11ffe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
virtio_mmio: virtio_interrupt_handler(0x0000000081265600)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_mmio: virtio_device_queue_request_v(0x00000000813b7cb0)
  vector[0]: 0x812ff420, 0x10, read
  vector[1]: 0x812b8000, 0x800, write
  vector[2]: 0x812ff430, 0x1, write
virtio_mmio: dev->fRegs->queueNotify = 0
TinyEMU: queue_notify(0)
TinyEMU: virtio_block_recv_request
STrap(interrupt sExtern)
  sstatus: (ie: {}, pie: {s}, spp: s)
  sepc: <virtio_block> _ZL5do_ioPvP11IOOperation + 230
  sie: {sExtern}
  sip: {sExtern}
  irq: 3
Stack:
FP: 0xcd11fce0, PC: <kernel_riscv64> STrap + 363
FP: 0xcd11fde0, PC: <kernel_riscv64> SVec + 81
FP: 0xcd11fe60, PC: <virtio_block> _ZL5do_ioPvP11IOOperation + 229
FP: 0xcd11ffc0, PC: <kernel_riscv64> _ZN17IOSchedulerSimple10_SchedulerEv.localalias.2 + 1181
FP: 0xcd11ffe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
virtio_mmio: virtio_interrupt_handler(0x0000000081265600)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
bfs: mounted "Haiku" (root node at 131072, device = /dev/disk/virtual/virtio_block/0/raw)
Mounted boot partition: /dev/disk/virtual/virtio_block/0/raw

Currently loading stops here. Illegal instruction in strtoull()? What? Lets go disassembling again with my disassembler :slight_smile:

STrap(interrupt sExtern)
  sstatus: (ie: {}, pie: {s}, spp: s)
  sepc: <virtio_block> _ZL5do_ioPvP11IOOperation + 230
  sie: {sExtern}
  sip: {sExtern}
  irq: 3
Stack:
FP: 0xcd11fce0, PC: <kernel_riscv64> STrap + 363
FP: 0xcd11fde0, PC: <kernel_riscv64> SVec + 81
FP: 0xcd11fe60, PC: <virtio_block> _ZL5do_ioPvP11IOOperation + 229
FP: 0xcd11ffc0, PC: <kernel_riscv64> _ZN17IOSchedulerSimple10_SchedulerEv.localalias.2 + 1181
FP: 0xcd11ffe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
virtio_mmio: virtio_interrupt_handler(0x0000000081265600)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
virtio_mmio: virtio_device_queue_dequeue(0x00000000810241e0)
STrap(exception illegalInst)
  sstatus: (ie: {}, pie: {s}, spp: s)
  sepc: <kernel_riscv64> strtoull.localalias.0 + 212
  sie: {sExtern}
  sip: {}
PANIC: unhandled STrap
Welcome to Kernel Debugging Land...
Thread 14 "main2" running on CPU 0
Stack:
FP: 0xcd099090, PC: <kernel_riscv64> _ZL20kernel_debugger_loopPKcS0_Pvi + 243
FP: 0xcd099100, PC: <kernel_riscv64> _ZL24kernel_debugger_internalPKcS0_Pvi + 131
FP: 0xcd099140, PC: <kernel_riscv64> panic + 93
FP: 0xcd099280, PC: <kernel_riscv64> SVec + 81
FP: 0xcd099330, PC: <kernel_riscv64> strtoull.localalias.0 + 211
FP: 0xcd0994a0, PC: <kernel_riscv64> load_driver_settings + 157
FP: 0xcd0994d0, PC: <kernel_riscv64> _ZL10get_optionP11kernel_argsPKcS2_mPcPm.part.2 + 25
FP: 0xcd099510, PC: <kernel_riscv64> _ZL11get_booleanP11kernel_argsPKcb + 33
FP: 0xcd0996c0, PC: <kernel_riscv64> legacy_driver_probe + 1315
FP: 0xcd099720, PC: <kernel_riscv64> _ZL26scan_for_drivers_if_neededPN12_GLOBAL__N_111devfs_vnodeE + 239
FP: 0xcd099760, PC: <kernel_riscv64> _ZL12devfs_lookupP9fs_volumeP8fs_vnodePKcPl + 51
FP: 0xcd0997a0, PC: <kernel_riscv64> _ZL16lookup_dir_entryP5vnodePKcPS0_ + 105
FP: 0xcd099870, PC: <kernel_riscv64> _ZL19vnode_path_to_vnodeP5vnodePcbiP10io_contextPS0_Pl + 475
FP: 0xcd0998a0, PC: <kernel_riscv64> _ZL21common_path_read_statiPcbP4statb + 25
FP: 0xcd099900, PC: <kernel_riscv64> vfs_read_stat.localalias.7 + 73
FP: 0xcd0999b0, PC: <kernel_riscv64> _kern_read_stat + 69
FP: 0xcd0999d0, PC: <kernel_riscv64> _lstat_current.localalias.1 + 25
FP: 0xcd099ac0, PC: <kernel_riscv64> _ZN8BPrivate10DiskDevice18KDiskDeviceManager5_ScanEPKc.localalias.5 + 49
FP: 0xcd099b10, PC: <kernel_riscv64> _ZN8BPrivate10DiskDevice18KDiskDeviceManager17InitialDeviceScanEv.localalias.13 + 161
FP: 0xcd099b30, PC: <kernel_riscv64> _ZN8BPrivate10DiskDevice18KDiskDeviceManager15StartMonitoringEv + 15
FP: 0xcd099f70, PC: <kernel_riscv64> vfs_mount_boot_file_system + 1119
FP: 0xcd099fc0, PC: <kernel_riscv64> _ZL5main2Pv + 283
FP: 0xcd099fe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
kdebug>
5 Likes

Mysterious exception in <kernel_riscv64> strtoull.localalias.0 + 215 continue to occurr in different places.

  strtoull			
8013BFEC	7179 	ADDI SP, SP, -48
8013BFEE	F022 	SD FP, 32(SP)
8013BFF0	E44E 	SD S3, 8(SP)
8013BFF2	E052 	SD S4, 0(SP)
8013BFF4	F406 	SD RA, 40(SP)
8013BFF6	EC26 	SD S1, 24(SP)
8013BFF8	E84A 	SD S2, 16(SP)
8013BFFA	1800 	ADDI FP, SP, 48
8013BFFC	6797 0004 	AUIPC A5, $00046000
8013C000	B783 71C7 	LD A5, __imp___ctype_b
8013C004	89AA 	MV S3, A0
8013C006	86AA 	MV A3, A0
8013C008	8A2E 	MV S4, A1
8013C00A	B803 0007 	LD A6, 0(A5)
8013C00E	6509 	LUI A0, $00002000
8013C010	A011 	J $8013C014
8013C012	86A6 	MV A3, S1
8013C014	8493 0016 	ADDI S1, A3, 1
8013C018	C703 FFF4 	LBU A4, -1(S1)
8013C01C	1793 0017 	SLLI A5, A4, 1
8013C020	97C2 	ADD A5, A6
8013C022	D783 0007 	LHU A5, 0(A5)
8013C026	8FE9 	AND A5, A5, A0
8013C028	F7ED 	BNEZ A5, $8013C012
8013C02A	0793 02D0 	LI A5, 45
8013C02E	0D63 0EF7 	BEQ A4, A5, $8013C128
8013C032	0793 02B0 	LI A5, 43
8013C036	4301 	LI T1, 0
8013C038	0563 0AF7 	BEQ A4, A5, $8013C0E2
8013C03C	E635 	BNEZ A2, $8013C0A8
8013C03E	0793 0300 	LI A5, 48
8013C042	0463 14F7 	BEQ A4, A5, $8013C18A
8013C046	7797 0002 	AUIPC A5, $00027000
8013C04A	8793 3927 	LI A5, $801633D8
8013C04E	638C 	LD A1, 0(A5)
8013C050	4E15 	LI T3, 5
8013C052	48A9 	LI A7, 10
8013C054	4629 	LI A2, 10
8013C056	4681 	LI A3, 0
8013C058	4901 	LI S2, 0
8013C05A	4525 	LI A0, 9
8013C05C	4865 	LI A6, 25
8013C05E	A829 	J $8013C078
8013C060	56FD 	LI A3, -1
8013C062	E863 0125 	BLTU A1, S2, $8013C072
8013C066	0E63 0AB9 	BEQ S2, A1, $8013C122
8013C06A	8933 0328 	MUL S2, A7, S2
8013C06E	4685 	LI A3, 1
8013C070	993E 	ADD S2, A5
8013C072	0485 	ADDI S1, S1, 1
8013C074	C703 FFF4 	LBU A4, -1(S1)
8013C078	079B FD07 	ADDIW A5, A4, -48
8013C07C	F793 0FF7 	ANDI A5, A5, 255
8013C080	7C63 00F5 	BBGEU A0, A5, $8013C098
8013C084	079B FBF7 	ADDIW A5, A4, -65
8013C088	F793 0FF7 	ANDI A5, A5, 255
8013C08C	6163 06F8 	BLTU A6, A5, $8013C0EE
8013C090	079B FC97 	ADDIW A5, A4, -55
8013C094	F793 0FF7 	ANDI A5, A5, 255
8013C098	871B 0007 	ADDIW A4, A5, 0
8013C09C	5763 06C7 	BGE A4, A2, $8013C10A
8013C0A0	D0E3 FC06 	BGE A3, 0, $8013C060
8013C0A4	56FD 	LI A3, -1
8013C0A6	B7F1 	J $8013C072
8013C0A8	47C1 	LI A5, 16
8013C0AA	0F63 08F6 	BEQ A2, A5, $8013C148
8013C0AE	079B FFE6 	ADDIW A5, A2, -2
8013C0B2	0693 0220 	LI A3, 34
8013C0B6	F863 0EF6 	BBGEU A3, A5, $8013C1A6
8013C0BA	80EF 9872 	JAL _errnop
8013C0BE	07B7 8000 	LUI A5, $80000000
8013C0C2	2795 	LI A5, $80000005
8013C0C4	C11C 	SW A5, 0(A0) (* <--- TRAPS HERE *)
8013C0C6	4901 	LI S2, 0
8013C0C8	0463 000A 	BEQ S4, 0, $8013C0D0
8013C0CC	3023 013A 	SD S3, 0(S4)
8013C0D0	70A2 	LD RA, 40(SP)
8013C0D2	7402 	LD FP, 32(SP)
8013C0D4	854A 	MV A0, S2
8013C0D6	64E2 	LD S1, 24(SP)
8013C0D8	6942 	LD S2, 16(SP)
8013C0DA	69A2 	LD S3, 8(SP)
8013C0DC	6A02 	LD S4, 0(SP)
8013C0DE	6145 	ADDI SP, SP, 48
8013C0E0	8082 	RET
3 Likes

What is the value of A0? I don’t know about RISC-V but on other architectures I’ve had “illegal instruction” because of misaligned memory access.

1 Like

One of possible causes may be old kernel module binaries in disk image. Replacing it seems to fix issue, but hit next old module. I try to rebuild whole disk image.

Compiler flags and common headers was changed since last disk image generation.

2 Likes

Problem is still present after recompiling everything:

STrap(exception storePageFault)
  sstatus: (ie: {}, pie: {s}, spp: s)
  sepc: <kernel_riscv64> strtoull.localalias.0 + 216
  sie: {sExtern}
  sip: {}
  stval: 0x2
PANIC: unhandled STrap
Welcome to Kernel Debugging Land...
Thread 14 "main2" running on CPU 0
Stack:
FP: 0xcd0999d0, PC: <kernel_riscv64> _ZL20kernel_debugger_loopPKcS0_Pvi + 243
FP: 0xcd099a40, PC: <kernel_riscv64> _ZL24kernel_debugger_internalPKcS0_Pvi + 131
FP: 0xcd099a80, PC: <kernel_riscv64> panic + 93
FP: 0xcd099bc0, PC: <kernel_riscv64> SVec + 81
FP: 0xcd099ca0, PC: <kernel_riscv64> strtoull.localalias.0 + 215
FP: 0xcd099cb0, PC: <iso9660> 0x1219
FP: 0xcd099de0, PC: <kernel_riscv64> get_module.localalias.1 + 1069
FP: 0xcd099f70, PC: <kernel_riscv64> debug_init_post_modules + 329
FP: 0xcd099fc0, PC: <kernel_riscv64> _ZL5main2Pv + 371
FP: 0xcd099fe0, PC: <kernel_riscv64> _ZL19common_thread_entryPv + 49
FP: 0x0, PC: <kernel_riscv64> arch_thread_entry + 3
kdebug> 

I just disabled dynamic loading of kernel add-ons and loading progressed to rocket icon! Even first userland process “launch_daemon” is visible in KDL. Userland is almost not implemened so it is not expected to run. Currently is infinitely crash without stack trace.

Dynamic loading of kernel add-ons seems not working correctly, probably someting is not implemented (relocations types etc.). Modules preloaded by boot loader are fine.

screenshot42

21 Likes