• About TC
  • Affiliate Disclaimer
  • Privacy Policy
  • TOS
  • Contact
Saturday, May 17, 2025
Techcratic
Click For A Secret Deal
  • TC
  • AI
    Artificial Intelligence

    Set up a custom plugin on Amazon Q Business and authenticate with Amazon Cognito to interact with backend systems

    Artificial Intelligence

    StreamBridge: Turning Your Offline Video Large Language Model into a Proactive Streaming Assistant

    Artificial Intelligence

    3 Excellent Practical Generative AI Courses

    Artificial Intelligence

    Building End-to-End Data Pipelines with Dask

    Artificial Intelligence

    Automate document translation and standardization with Amazon Bedrock and Amazon Translate

    Artificial Intelligence

    InterVision accelerates AI development using AWS LLM League and Amazon SageMaker AI

    Artificial Intelligence

    FireDucks: An Accelerated Fully Compatible Pandas Library

    Artificial Intelligence

    Breaking Out of Beginner: Python Patterns for Intermediate Data Scientists

    Artificial Intelligence

    Building a Personal Knowledge Management Tool with Reor

  • Crypto
    Bitcoin Mining Stocks Continue Rally as Applied Digital Leads Friday’s Gains

    Bitcoin Mining Stocks Continue Rally as Applied Digital Leads Friday’s Gains

    Bitstamp Gets EU License Under MiCA Crypto Rules

    Bitstamp Gets EU License Under MiCA Crypto Rules

    XRP Price Watch: Bulls Eye $2.60 as Long-Term Trend Holds

    XRP Price Watch: Bulls Eye $2.60 as Long-Term Trend Holds

    France to Boost Security for Crypto Entrepreneurs Amid Kidnappings

    France to Boost Security for Crypto Entrepreneurs Amid Kidnappings

    Everstake to SEC: Non-Custodial Staking Shouldn’t Be Regulated as Securities

    Everstake to SEC: Non-Custodial Staking Shouldn’t Be Regulated as Securities

    SEC Chair Voted Against Suing Elon Musk: Reuters

    Judge Rejects Ripple Deal, Crypto Rules in Flux

    SEC Warns of FOMO, Pushes Long-Term Strategies as Crypto Matures

    SEC Warns of FOMO, Pushes Long-Term Strategies as Crypto Matures

    Hashdex Seeks SEC Approval to Add Litecoin to Crypto Index ETF

    Tinian Debuts First U.S. Public USD Stablecoin on eCash

    From Whiskey to Orthopedic Care: 2 More Companies Race to Hoard Bitcoin

    From Whiskey to Orthopedic Care: 2 More Companies Race to Hoard Bitcoin

  • Cybersecurity
    Cybersecurity

    New HTTPBot Botnet Launches 200+ Precision DDoS Attacks on Gaming and Tech Sectors

    Cybersecurity

    Top 10 Best Practices for Effective Data Protection

    Cybersecurity

    Researchers Expose New Intel CPU Flaws Enabling Memory Leaks and Spectre v2 Attacks

    Cybersecurity

    Learn a Smarter Way to Defend Modern Applications

    Cybersecurity

    Meta to Train AI on E.U. User Data From May 27 Without Consent; Noyb Threatens Lawsuit

    Cybersecurity

    5 BCDR Essentials for Effective Ransomware Defense

    Cybersecurity

    New Chrome Vulnerability Enables Cross-Origin Data Leak via Loader Referrer Policy

    Cybersecurity

    Ivanti Patches EPMM Vulnerabilities Exploited for Remote Code Execution in Limited Attacks

    Cybersecurity

    Fortinet Patches CVE-2025-32756 Zero-Day RCE Flaw Exploited in FortiVoice Systems

  • Deals
    MSI Stealth 16 Studio 16″ WQXGA 240Hz Intel i9-13900H, GeForce RTX 4070 Pro Gaming…

    MSI Stealth 16 Studio 16″ WQXGA 240Hz Intel i9-13900H, GeForce RTX 4070 Pro Gaming…

    128GB USB Flash Drives 1 Pack 128GB Thumb Drives Memory Stick Jump Drive with LED Light…

    128GB USB Flash Drives 1 Pack 128GB Thumb Drives Memory Stick Jump Drive with LED Light…

    CableCreation USB C to DVI Adapter 1080P@60Hz, USB-C to DVI-D Cable Adapter Compatible…

    CableCreation USB C to DVI Adapter 1080P@60Hz, USB-C to DVI-D Cable Adapter Compatible…

    VIVO Steel Wall Mount Bracket Designed for PS5 Gaming Console, Vertical Display for…

    VIVO Steel Wall Mount Bracket Designed for PS5 Gaming Console, Vertical Display for…

    EnHomee 48 Inch L Shaped Desk with Storage Shelves & Side Bag, Gaming Desk with Power…

    EnHomee 48 Inch L Shaped Desk with Storage Shelves & Side Bag, Gaming Desk with Power…

    CHONCHOW Gaming Keyboard and Mouse Led Backlit USB Wired with Light Up 104Key 3600DPI 2…

    CHONCHOW Gaming Keyboard and Mouse Led Backlit USB Wired with Light Up 104Key 3600DPI 2…

    EPOMAKER Luma84 Low Profile Aluminum Mechanical Keyboard, QMK/VIA Programmable, Tri-Mode…

    EPOMAKER Luma84 Low Profile Aluminum Mechanical Keyboard, QMK/VIA Programmable, Tri-Mode…

    Mario Kart 8 – Wii U

    Mario Kart 8 – Wii U

    Gang Beasts – Nintendo Switch

    Gang Beasts – Nintendo Switch

  • Gaming
    House Flipper 2 is having a free weekend, and just got co-op

    House Flipper 2 is having a free weekend, and just got co-op

    why ac shadows is DOOMED

    why ac shadows is DOOMED

    SONY SHOCKS: GAMING WILL NEVER BE THE SAME AGAIN, GTA 6 TRAILER 2, HALO PS5 PRO ENHANCED

    SONY SHOCKS: GAMING WILL NEVER BE THE SAME AGAIN, GTA 6 TRAILER 2, HALO PS5 PRO ENHANCED

    Welp, Fortnite’s iOS version is ‘offline worldwide’ after Apple continues to shuffle its feet around bringing the game back to the US App Store

    Welp, Fortnite’s iOS version is ‘offline worldwide’ after Apple continues to shuffle its feet around bringing the game back to the US App Store

    Drive Mad All Level Gameplay Walkthrough | Fancade Game ( E.PN 4 )

    Drive Mad All Level Gameplay Walkthrough | Fancade Game ( E.PN 4 )

    Tomb Raider Games – Angry Video Game Nerd (AVGN)

    Tomb Raider Games – Angry Video Game Nerd (AVGN)

    Honest Game Trailers | Resident Evil 2 (2019)

    Honest Game Trailers | Resident Evil 2 (2019)

    After Helldivers 2, Arrowhead’s next game will be ‘100% funded by ourselves’, though CEO Shams Jorjani says there’s no hard feelings over Sony’s boneheaded PSN shenanigans

    After Helldivers 2, Arrowhead’s next game will be ‘100% funded by ourselves’, though CEO Shams Jorjani says there’s no hard feelings over Sony’s boneheaded PSN shenanigans

    Kirby and the Forgotten Land – 2 Player Co-Op Walkthrough Part 01 (Wild Mode) [100%] (4K)

    Kirby and the Forgotten Land – 2 Player Co-Op Walkthrough Part 01 (Wild Mode) [100%] (4K)

  • Tesla
    Wireless Charger Mat for Tesla Cybertruck 2023 2024 2025,EleganceX Car Center Console…

    Wireless Charger Mat for Tesla Cybertruck 2023 2024 2025,EleganceX Car Center Console…

    10 PCS Car 3157 12 V 21/5 W Halogen Brake Light Bulb, 0.64″ x 1.62″ Miniature Quartz…

    10 PCS Car 3157 12 V 21/5 W Halogen Brake Light Bulb, 0.64″ x 1.62″ Miniature Quartz…

    B&C Pillar PPF Film for Cybertruck Pillars & Door Buttons Vinyl Wrap Front&Rear Door…

    B&C Pillar PPF Film for Cybertruck Pillars & Door Buttons Vinyl Wrap Front&Rear Door…

    Flying Banner Car Seat Covers Front Seats Rear Bench Polyester car seat Protectors Easy…

    Flying Banner Car Seat Covers Front Seats Rear Bench Polyester car seat Protectors Easy…

    4in1 J1772&CCS to Tesla/Cybertruck (NACS) Adapter, CCS1 Adapter for NACS, Compatible…

    4in1 J1772&CCS to Tesla/Cybertruck (NACS) Adapter, CCS1 Adapter for NACS, Compatible…

    Fanttik Slim V8 Apex Car Vacuum, 4-in-1 Portable Mini Cordless Vacuum with 19000pa…

    Fanttik Slim V8 Apex Car Vacuum, 4-in-1 Portable Mini Cordless Vacuum with 19000pa…

    Tesla’s robotaxi fleet will be powered by ‘plenty of teleoperation’

    Tesla’s robotaxi fleet will be powered by ‘plenty of teleoperation’

    2PCS USB LED Car Interior Atmosphere Lamp, Portable Mini Auto Ambient Lighting Kit,…

    2PCS USB LED Car Interior Atmosphere Lamp, Portable Mini Auto Ambient Lighting Kit,…

    Judge shuts down Tesla’s attempt to reinstate Elon Musk’s giant CEO pay package

    Elon Musk hires another Tesla board member to cash checks and let him destroy the brand

  • UFO
    Som ET – 45 – Moon – Apollo 14 – U.S. Flag on the Moon #Shorts

    Som ET – 45 – Moon – Apollo 14 – U.S. Flag on the Moon #Shorts

    Roswell Delirium

    Roswell Delirium

    ALIENS: The Truth About Roswell

    ALIENS: The Truth About Roswell

    It Was Never Just America | Global UFO Sightings | UFO Documentary

    It Was Never Just America | Global UFO Sightings | UFO Documentary

    Alien Resurrection [Blu-ray]

    Alien Resurrection [Blu-ray]

    Alien Contact: How Would Humanity React? | FULL DOCUMENTARY

    Alien Contact: How Would Humanity React? | FULL DOCUMENTARY

    Ancient Aliens: Ireland's Portals to Different Worlds (Special)

    Ancient Aliens: Ireland's Portals to Different Worlds (Special)

    The Contactee Movement   1950s   Back To The Future Promo1

    The Contactee Movement 1950s Back To The Future Promo1

    Funny Sunnyside Up Egg UFO Abduction Breakfast Bacon Lover T-Shirt

    Funny Sunnyside Up Egg UFO Abduction Breakfast Bacon Lover T-Shirt

No Result
View All Result
  • TC
  • AI
    Artificial Intelligence

    Set up a custom plugin on Amazon Q Business and authenticate with Amazon Cognito to interact with backend systems

    Artificial Intelligence

    StreamBridge: Turning Your Offline Video Large Language Model into a Proactive Streaming Assistant

    Artificial Intelligence

    3 Excellent Practical Generative AI Courses

    Artificial Intelligence

    Building End-to-End Data Pipelines with Dask

    Artificial Intelligence

    Automate document translation and standardization with Amazon Bedrock and Amazon Translate

    Artificial Intelligence

    InterVision accelerates AI development using AWS LLM League and Amazon SageMaker AI

    Artificial Intelligence

    FireDucks: An Accelerated Fully Compatible Pandas Library

    Artificial Intelligence

    Breaking Out of Beginner: Python Patterns for Intermediate Data Scientists

    Artificial Intelligence

    Building a Personal Knowledge Management Tool with Reor

  • Crypto
    Bitcoin Mining Stocks Continue Rally as Applied Digital Leads Friday’s Gains

    Bitcoin Mining Stocks Continue Rally as Applied Digital Leads Friday’s Gains

    Bitstamp Gets EU License Under MiCA Crypto Rules

    Bitstamp Gets EU License Under MiCA Crypto Rules

    XRP Price Watch: Bulls Eye $2.60 as Long-Term Trend Holds

    XRP Price Watch: Bulls Eye $2.60 as Long-Term Trend Holds

    France to Boost Security for Crypto Entrepreneurs Amid Kidnappings

    France to Boost Security for Crypto Entrepreneurs Amid Kidnappings

    Everstake to SEC: Non-Custodial Staking Shouldn’t Be Regulated as Securities

    Everstake to SEC: Non-Custodial Staking Shouldn’t Be Regulated as Securities

    SEC Chair Voted Against Suing Elon Musk: Reuters

    Judge Rejects Ripple Deal, Crypto Rules in Flux

    SEC Warns of FOMO, Pushes Long-Term Strategies as Crypto Matures

    SEC Warns of FOMO, Pushes Long-Term Strategies as Crypto Matures

    Hashdex Seeks SEC Approval to Add Litecoin to Crypto Index ETF

    Tinian Debuts First U.S. Public USD Stablecoin on eCash

    From Whiskey to Orthopedic Care: 2 More Companies Race to Hoard Bitcoin

    From Whiskey to Orthopedic Care: 2 More Companies Race to Hoard Bitcoin

  • Cybersecurity
    Cybersecurity

    New HTTPBot Botnet Launches 200+ Precision DDoS Attacks on Gaming and Tech Sectors

    Cybersecurity

    Top 10 Best Practices for Effective Data Protection

    Cybersecurity

    Researchers Expose New Intel CPU Flaws Enabling Memory Leaks and Spectre v2 Attacks

    Cybersecurity

    Learn a Smarter Way to Defend Modern Applications

    Cybersecurity

    Meta to Train AI on E.U. User Data From May 27 Without Consent; Noyb Threatens Lawsuit

    Cybersecurity

    5 BCDR Essentials for Effective Ransomware Defense

    Cybersecurity

    New Chrome Vulnerability Enables Cross-Origin Data Leak via Loader Referrer Policy

    Cybersecurity

    Ivanti Patches EPMM Vulnerabilities Exploited for Remote Code Execution in Limited Attacks

    Cybersecurity

    Fortinet Patches CVE-2025-32756 Zero-Day RCE Flaw Exploited in FortiVoice Systems

  • Deals
    MSI Stealth 16 Studio 16″ WQXGA 240Hz Intel i9-13900H, GeForce RTX 4070 Pro Gaming…

    MSI Stealth 16 Studio 16″ WQXGA 240Hz Intel i9-13900H, GeForce RTX 4070 Pro Gaming…

    128GB USB Flash Drives 1 Pack 128GB Thumb Drives Memory Stick Jump Drive with LED Light…

    128GB USB Flash Drives 1 Pack 128GB Thumb Drives Memory Stick Jump Drive with LED Light…

    CableCreation USB C to DVI Adapter 1080P@60Hz, USB-C to DVI-D Cable Adapter Compatible…

    CableCreation USB C to DVI Adapter 1080P@60Hz, USB-C to DVI-D Cable Adapter Compatible…

    VIVO Steel Wall Mount Bracket Designed for PS5 Gaming Console, Vertical Display for…

    VIVO Steel Wall Mount Bracket Designed for PS5 Gaming Console, Vertical Display for…

    EnHomee 48 Inch L Shaped Desk with Storage Shelves & Side Bag, Gaming Desk with Power…

    EnHomee 48 Inch L Shaped Desk with Storage Shelves & Side Bag, Gaming Desk with Power…

    CHONCHOW Gaming Keyboard and Mouse Led Backlit USB Wired with Light Up 104Key 3600DPI 2…

    CHONCHOW Gaming Keyboard and Mouse Led Backlit USB Wired with Light Up 104Key 3600DPI 2…

    EPOMAKER Luma84 Low Profile Aluminum Mechanical Keyboard, QMK/VIA Programmable, Tri-Mode…

    EPOMAKER Luma84 Low Profile Aluminum Mechanical Keyboard, QMK/VIA Programmable, Tri-Mode…

    Mario Kart 8 – Wii U

    Mario Kart 8 – Wii U

    Gang Beasts – Nintendo Switch

    Gang Beasts – Nintendo Switch

  • Gaming
    House Flipper 2 is having a free weekend, and just got co-op

    House Flipper 2 is having a free weekend, and just got co-op

    why ac shadows is DOOMED

    why ac shadows is DOOMED

    SONY SHOCKS: GAMING WILL NEVER BE THE SAME AGAIN, GTA 6 TRAILER 2, HALO PS5 PRO ENHANCED

    SONY SHOCKS: GAMING WILL NEVER BE THE SAME AGAIN, GTA 6 TRAILER 2, HALO PS5 PRO ENHANCED

    Welp, Fortnite’s iOS version is ‘offline worldwide’ after Apple continues to shuffle its feet around bringing the game back to the US App Store

    Welp, Fortnite’s iOS version is ‘offline worldwide’ after Apple continues to shuffle its feet around bringing the game back to the US App Store

    Drive Mad All Level Gameplay Walkthrough | Fancade Game ( E.PN 4 )

    Drive Mad All Level Gameplay Walkthrough | Fancade Game ( E.PN 4 )

    Tomb Raider Games – Angry Video Game Nerd (AVGN)

    Tomb Raider Games – Angry Video Game Nerd (AVGN)

    Honest Game Trailers | Resident Evil 2 (2019)

    Honest Game Trailers | Resident Evil 2 (2019)

    After Helldivers 2, Arrowhead’s next game will be ‘100% funded by ourselves’, though CEO Shams Jorjani says there’s no hard feelings over Sony’s boneheaded PSN shenanigans

    After Helldivers 2, Arrowhead’s next game will be ‘100% funded by ourselves’, though CEO Shams Jorjani says there’s no hard feelings over Sony’s boneheaded PSN shenanigans

    Kirby and the Forgotten Land – 2 Player Co-Op Walkthrough Part 01 (Wild Mode) [100%] (4K)

    Kirby and the Forgotten Land – 2 Player Co-Op Walkthrough Part 01 (Wild Mode) [100%] (4K)

  • Tesla
    Wireless Charger Mat for Tesla Cybertruck 2023 2024 2025,EleganceX Car Center Console…

    Wireless Charger Mat for Tesla Cybertruck 2023 2024 2025,EleganceX Car Center Console…

    10 PCS Car 3157 12 V 21/5 W Halogen Brake Light Bulb, 0.64″ x 1.62″ Miniature Quartz…

    10 PCS Car 3157 12 V 21/5 W Halogen Brake Light Bulb, 0.64″ x 1.62″ Miniature Quartz…

    B&C Pillar PPF Film for Cybertruck Pillars & Door Buttons Vinyl Wrap Front&Rear Door…

    B&C Pillar PPF Film for Cybertruck Pillars & Door Buttons Vinyl Wrap Front&Rear Door…

    Flying Banner Car Seat Covers Front Seats Rear Bench Polyester car seat Protectors Easy…

    Flying Banner Car Seat Covers Front Seats Rear Bench Polyester car seat Protectors Easy…

    4in1 J1772&CCS to Tesla/Cybertruck (NACS) Adapter, CCS1 Adapter for NACS, Compatible…

    4in1 J1772&CCS to Tesla/Cybertruck (NACS) Adapter, CCS1 Adapter for NACS, Compatible…

    Fanttik Slim V8 Apex Car Vacuum, 4-in-1 Portable Mini Cordless Vacuum with 19000pa…

    Fanttik Slim V8 Apex Car Vacuum, 4-in-1 Portable Mini Cordless Vacuum with 19000pa…

    Tesla’s robotaxi fleet will be powered by ‘plenty of teleoperation’

    Tesla’s robotaxi fleet will be powered by ‘plenty of teleoperation’

    2PCS USB LED Car Interior Atmosphere Lamp, Portable Mini Auto Ambient Lighting Kit,…

    2PCS USB LED Car Interior Atmosphere Lamp, Portable Mini Auto Ambient Lighting Kit,…

    Judge shuts down Tesla’s attempt to reinstate Elon Musk’s giant CEO pay package

    Elon Musk hires another Tesla board member to cash checks and let him destroy the brand

  • UFO
    Som ET – 45 – Moon – Apollo 14 – U.S. Flag on the Moon #Shorts

    Som ET – 45 – Moon – Apollo 14 – U.S. Flag on the Moon #Shorts

    Roswell Delirium

    Roswell Delirium

    ALIENS: The Truth About Roswell

    ALIENS: The Truth About Roswell

    It Was Never Just America | Global UFO Sightings | UFO Documentary

    It Was Never Just America | Global UFO Sightings | UFO Documentary

    Alien Resurrection [Blu-ray]

    Alien Resurrection [Blu-ray]

    Alien Contact: How Would Humanity React? | FULL DOCUMENTARY

    Alien Contact: How Would Humanity React? | FULL DOCUMENTARY

    Ancient Aliens: Ireland's Portals to Different Worlds (Special)

    Ancient Aliens: Ireland's Portals to Different Worlds (Special)

    The Contactee Movement   1950s   Back To The Future Promo1

    The Contactee Movement 1950s Back To The Future Promo1

    Funny Sunnyside Up Egg UFO Abduction Breakfast Bacon Lover T-Shirt

    Funny Sunnyside Up Egg UFO Abduction Breakfast Bacon Lover T-Shirt

No Result
View All Result
Techcratic
No Result
View All Result

Implementing a RISC-V Hypervisor

Hacker News by Hacker News
May 17, 2025
in Hacker News
Reading Time: 13 mins read
125 5
A A
0
Home Hacker News
Share on FacebookShare on XShare on LinkedIn

2025-05-17 03:46:00
seiya.me

To implement a seamless Linux integration into Starina, I decided to go with a Linux lightweight VM approach similar to WSL2. This means I need to implement a hypervisor that can run Linux.

I had implemented an Intel VT-x based hypervisor before, but this time I wanted to try something different: RISC-V H-extension based hypervisor!

This post is a diary of my journey of writing a RISC-V hypervisor incrementally.

RISC-V H-extension

RISC-V H-extension introduces new CPU modes and some more CSRs (so-called control registers) to implement hardware-assisted virtualization. Its design is similar to Intel VT-x in the sense that both host and guest modes have their own kernel mode and user mode. This design makes it easy to run host OS along with guests, that is, guests behave as normal host processes (e.g. QEMU and Firecracker).

How can I test a hypervisor on macOS?

Unlike Linux KVM-based hypervisors (more specifically, virtual machine monitors), Starina is a new operating system and has been tested on QEMU.

In this case, you typically need to use nested virtualization where the hardware-assisted virtualization is emulated by the host OS. That’s how I did it for Intel VT-x.

Here’s great news: QEMU itself can emulate RISC-V H-extension! You just need to add -cpu rv64,h=true to the QEMU command line. I presume this is thanks to RISC-V’s simplicity and designers’ foresight (and of course QEMU developers’ effort!).

Having a software emulation in QEMU is a key enabler when you’re writing a new operating system from scratch because you can attach GDB to QEMU to debug the OS.

Step 1: Entering the guest

The first thing to do is to enter the guest state. In RISC-V, guest kernel mode is called VS-mode. In RISC-V, you just fill a few CSRs. Specifically, hstatus.SPV should be set to 1 before sret instruction:

first-inst-guest-page-fault

The kernel panicked with an interesting error name: instruction guest-page fault. Yes, CPU has entered the guest mode!

Step 2: First ecall

The next step is to run something in the guest mode. Let’s start with a simple ecall:

const BOOT_CODE: &[u8] = &[
    0x73, 0x00, 0x00, 0x00, // ecall
];

To make it work, we need to prepare the guest’s page table which maps the guest-physical address to the host-physical address so that the CPU can read the instructions in BOOT_CODE.

RISC-V defines another paging modes called Sv39x4/Sv48x4/Sv57x4, and they’re mostly identical to Sv39/Sv48/Sv57. The only caveat is U bit needs to be set to 1 for kernel pages too.

Once hgatp is set, I got another trap reason:

first ecall

Step 3: Hello World from guest!

Now we’re ready to run a Hello World program. I wrote a simple program in assembly:

.section .text
.global _start

_start:
    li a0, 'H'
    li a7, 1
    ecall

    li a0, 'i'
    li a7, 1
    ecall

    li a0, '!'
    li a7, 1
    ecall

    li a0, '\n'
    li a7, 1
    ecall

    unimp

This assumes hypervisor’s ecall handler implements the SBI, a RISC-V’s BIOS interface. This snippet calls so-called putchar API and finally calls an invalid instruction (unimp) to trigger a trap.

Building this tiny guest OS is easy:

$ clang --target=riscv64 -march=rv64g -nostdlib -Wl,-Ttext=0x80200000 guest.S -o guest.elf
$ llvm-objcopy -O binary guest.elf guest.bin

And it works!

minimal hello world

Step 4: Booting Linux

Our minimal guest Hello World worked, so it’s time to try with Linux.

Here are some kernel config options I enabled:

CONFIG_SERIAL_EARLYCON_RISCV_SBI=y
CONFIG_RISCV_SBI_V01=y
CONFIG_HVC_RISCV_SBI=y
CONFIG_RISCV_TIMER=y

Linux kernel for RISC-V can be built with:

make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- Image

The boot image format is documented here, and it’s basically raw binary. Just copy the image file into the guest memory, and jump to the beginning when the CPU enters the guest mode.

Looks like Linux booted, but it crashed with a null dereference:

null dereference in device tree

According to the sepc value, the kernel panicked at __pi_fdt32_ld:

$ gobjdump -d linux/vmlinux | grep -A 5 801cace8 | head
ffffffff801cace8 <__pi_fdt32_ld>:
ffffffff801cace8:	00054783          	lbu	a5,0(a0)  

Step 5: Device Tree

In RISC-V, we need to provide a device tree, a tree data structure defining what devices are available in the computer.

Fortunately, we can use a Rust crate for this: vm-fdt, a device tree builder from RustVMM project (famous for Firecracker). The library supports no_std, so it was super easy to use it in Starina (thank you, thank you RustVMM folks!).

To make Linux work, the device tree should include at least: free memory areas (reg in device_type = memory), and CPUs with RISC-V ISA extensions (riscv,isa-extensions).

Step 6: rdtime support

After adding the device tree, I got another trap. Looks like Linux tried to read rdtime but failed because hcounteren was not set:

hcounteren register is clear, attempts to read the cycle, time, instret, or hpmcounter n register while V=1 will cause a virtual-instruction exception

The fix is to fill hcounteren CSR. Easy peasy.

Step 7: Timer support

While booting, Linux kernel tries to probe the abilities of the CPU and peripherals. That intialization step is mostly done by itself without any help from the hypervisor. However, there’s a bit head-scratching part: the timer speed detection.

In the step, Linux kernel waits for jiffies to progress and it looks as if it’s hanging if the hypervisor doesn’t implement timer.

In RISC-V there are two approaches to implement a timer:

  • sbi_set_timer: Call the hypervisor (SBI) to set the timer.
  • sstc extension: A CPU extension to trigger a timer interrupt without hypervisor’s help.

This step is also the first time I needed to inject interrupts into the guest. While RISC-V spec is clean, but I was totally lost with how to do it. Setting hideleg was what I needed to do, but I was confused by RISC-V Advanced Interrupt Architecture, which extends the RISC-V interrupt handling.

RISC-V extensions are more somtimes look like “patches” to the base spec. RISC-V Unified Database is a great resource to understand how the extensions extend the base spec.

Once I enabled sstc extension and implemented interrupt handling correctly, the kernel booted successfully:

linux-hello-world

Step 8: MMIO support

Linux booted successfully on Starina’s hypervisor. The next step is to provide devices. In RISC-V, as in other architectures, devices are mapped to physical addresses (memory-mapped I/O). Devices need to be emulated are:

  • An interrupt controller. The guest kernel needs it to read pending interrupts, and acknowledge them. PLIC in RISC-V.
  • Disk device: Where the root filesystem is stored. Virtio-blk is a popular choice.
  • Network device: For networking. Virtio-net is the most popular choice.

In hypervisor, MMIO is implemented by not mapping anything at the address range. That is, everytime the guest tries to access the address range:

  1. The CPU tries to read/write a MMIO address, but it’s not mapped. Trigger a guest page fault.
  2. The hypervisor checks if the address range is a MMIO address.
  3. Decode the instruction to determine destination/source registers, and the access width.
  4. Emulate the MMIO operation.
  5. If it’s a read, write the value to the register.
  6. Advance the program counter to the next instruction, and resume the guest.

Doesn’t it sound a bit hacky? In MMIO, hypervisor behaves like a CPU interpreter. Fortunately, RISC-V is very simple and gives us summary of the instruction in htinst CSR. In x86-64, … good luck!

For future RISC-V hypervisor developers, here are few pitfalls I encountered:

  • A guest physical address written to htval is shifted right by 2 bits. You’ll see a weird address if you forget this.
  • htinst could be compressed instruction. This means the instruction width is not always 4 bytes, but sometimes 2 bytes.

Step 9: virtio-fs

This is the last step of this post. While virito-blk is a typical choise to provide the root filesystem, I chose something different: virtio-fs.

Why? Because it allows more seamless integration with Starina. I plan to write another post about the integration, but in short, Starina provides some virtual files to the guest.

Virtio-fs is a virtual filesystem over Virtio. More specifically, it uses FUSE (Filesystem in Userspace) protocol to communicate with the guest kernel.

I have nothing to say about this step because we’ve finished the hypervisor-specific steps already! Design a good virtio library, implement the virtio-fs emulation on top of it, and you’re done:

virtio-fs

Phew, that’s it!

Tip: Debugging both hypervisor/guest worlds

Starina supports Unikernel-like mode, where the microkernel and apps are built into a single ELF executable. This is not only for performance, but also for debugging.

Here’s a gdbinit script which enabled me to watch VMM, hypervisor in Starina kernel, and the Linux kernel in guest:

# Load Starina (hypervisor's) debug info
file build/kernel/debug/kernel

# Load Linux (guest's) debug info
add-symbol-file path/to/vmlinux

And look! You’re seeing the guest’s kernel stack trace!

gdb

This is why I haven’t yet implemented stack traces in Starina: you just need to attach the GDB and type bt.

Source Link


Keep your files stored safely and securely with the SanDisk 2TB Extreme Portable SSD. With over 69,505 ratings and an impressive 4.6 out of 5 stars, this product has been purchased over 8K+ times in the past month. At only $129.99, this Amazon’s Choice product is a must-have for secure file storage.

Help keep private content private with the included password protection featuring 256-bit AES hardware encryption. Order now for just $129.99 on Amazon!


Start your free Amazon Prime trial
today and unlock unlimited streaming and more!

Help Power Techcratic’s Future – Scan To Support

If Techcratic’s content and insights have helped you, consider giving back by supporting the platform with crypto. Every contribution makes a difference, whether it’s for high-quality content, server maintenance, or future updates. Techcratic is constantly evolving, and your support helps drive that progress.

As a solo operator who wears all the hats, creating content, managing the tech, and running the site, your support allows me to stay focused on delivering valuable resources. Your support keeps everything running smoothly and enables me to continue creating the content you love. I’m deeply grateful for your support, it truly means the world to me! Thank you!

BITCOIN

Bitcoin Logo

Bitcoin QR Code

bc1qlszw7elx2qahjwvaryh0tkgg8y68enw30gpvge

Scan the QR code with your crypto wallet app

DOGECOIN

Dogecoin Logo

Dogecoin QR Code

D64GwvvYQxFXYyan3oQCrmWfidf6T3JpBA

Scan the QR code with your crypto wallet app

ETHEREUM

Ethereum Logo

Ethereum QR Code

0xe9BC980DF3d985730dA827996B43E4A62CCBAA7a

Scan the QR code with your crypto wallet app

Please read the Privacy and Security Disclaimer on how Techcratic handles your support.

Disclaimer: As an Amazon Associate, Techcratic may earn from qualifying purchases.

Tags: Hacker News
Share161Tweet101Share28
Previous Post

Why Smog Laws In California Need To Be Changed (According To Jay Leno)

Next Post

Chuchel (Concept Art)

Hacker News

Hacker News

Stay updated with Hacker News, where technology meets entrepreneurial spirit. Get the latest on tech trends, startup news, and discussions from the tech community. Read the latest updates here at Techcratic.

Related Posts

dipampaul17/KVSplit: Run larger LLMs with longer contexts on Apple Silicon by using differentiated precision for KV cache quantization. KVSplit enables 8-bit keys & 4-bit values, reducing memory by 59% with
Hacker News

dipampaul17/KVSplit: Run larger LLMs with longer contexts on Apple Silicon by using differentiated precision for KV cache quantization. KVSplit enables 8-bit keys & 4-bit values, reducing memory by 59% with

May 16, 2025
1.3k
pgjones/sql-tstring: SQL-tString allows for f-string like construction of sql queries
Hacker News

pgjones/sql-tstring: SQL-tString allows for f-string like construction of sql queries

May 16, 2025
1.3k
Cybersecurity
Hacker News

Sednit abuses XSS flaws to hit gov’t entities, defense companies

May 16, 2025
1.3k
How we made billing backendless
Hacker News

How we made billing backendless

May 15, 2025
1.3k
axbycc/LiveSplat: Live Gaussian Splatting for RGBD Camera Streams
Hacker News

axbycc/LiveSplat: Live Gaussian Splatting for RGBD Camera Streams

May 15, 2025
1.3k
git-bug/git-bug: Distributed, offline-first bug tracker embedded in git
Hacker News

git-bug/git-bug: Distributed, offline-first bug tracker embedded in git

May 14, 2025
1.3k
Load More
Next Post
Chuchel (Concept Art)

Chuchel (Concept Art)

MSI Stealth 16 Studio 16″ WQXGA 240Hz Intel i9-13900H, GeForce RTX 4070 Pro Gaming…

MSI Stealth 16 Studio 16" WQXGA 240Hz Intel i9-13900H, GeForce RTX 4070 Pro Gaming...

Kirby and the Forgotten Land – 2 Player Co-Op Walkthrough Part 01 (Wild Mode) [100%] (4K)

Kirby and the Forgotten Land - 2 Player Co-Op Walkthrough Part 01 (Wild Mode) [100%] (4K)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Your Tech Resources

  • 30 Second Tech ™
  • AI
  • App Zone ™
  • Apple
  • Ars Technica
  • CNET
  • ComputerWorld
  • Crypto News
  • Cybersecurity
  • Endgadget
  • Fossbytes
  • Gaming
  • GeekWire
  • Gizmodo
  • Google News
  • Hacker News
  • Harvard Tech
  • I Like Cats ™
  • I Like Dogs ™
  • LifeHacker
  • MacRumors
  • Macworld
  • Mashable
  • Microsoft
  • MIT Tech
  • PC World
  • Photofocus
  • Physics
  • Random Tech
  • Retro Rewind ™
  • Robot Report
  • SiliconANGLE
  • SlashGear
  • Smartphone
  • StackSocial
  • Tech Art
  • Tech Careers
  • Tech Deals
  • Techcratic ™
  • TechCrunch
  • Techdirt
  • TechRepublic
  • Techs Got To Eat ™
  • TechSpot
  • Tesla
  • The Verge
  • TNW
  • Trusted Reviews
  • UFO
  • VentureBeat
  • Visual Capitalist
  • Weird Stuff
  • Wired
  • ZDNet

Tech News

  • 30 Second Tech ™
  • AI
  • AnandTech
  • Apple Insider
  • Ars Technica
  • CNET
  • ComputerWorld
  • Crypto News
  • Cybersecurity
  • Endgadget
  • ExtremeTech
  • Fossbytes
  • Gaming
  • GeekWire
  • Gizmodo

Tech News

  • Harvard Tech
  • MacRumors
  • Macworld
  • Mashable
  • Microsoft
  • MIT Tech
  • Physics
  • PC World
  • Random Tech
  • Retro Rewind ™
  • SiliconANGLE
  • SlashGear
  • Smartphone
  • StackSocial
  • Tech Careers

Tech News​

  • Tech Art
  • TechCrunch
  • Techdirt
  • TechRepublic
  • Techs Got To Eat ™
  • TechSpot
  • Tesla
  • The Verge
  • TNW
  • Trusted Reviews
  • UFO
  • VentureBeat
  • Visual Capitalist
  • Weird Stuff
  • Wired
  • ZDNet

Site Links

  • About Techcratic
  • Affiliate Disclaimer
  • Affiliate Link Policy
  • Contact Techcratic
  • Dealors Discount Store
  • Privacy and Security Disclaimer
  • Privacy Policy
  • RSS Feed
  • Site Map
  • Support Techcratic
  • Techcratic
  • Tech Deals
  • TOS
  • 𝕏
Click For A Secret Deal

Techcratic – Your All In One Tech Hub © 2020 – 2025
All Rights Reserved
∞

No Result
View All Result
  • Home
  • Apple
  • Gaming
  • Microsoft
  • AnandTech