Skip to content

feat: Bochs VBE linear framebuffer support - #2523

Open
GloriousAlpaca wants to merge 6 commits into
hermit-os:mainfrom
GloriousAlpaca:pr-bga-clean
Open

feat: Bochs VBE linear framebuffer support#2523
GloriousAlpaca wants to merge 6 commits into
hermit-os:mainfrom
GloriousAlpaca:pr-bga-clean

Conversation

@GloriousAlpaca

Copy link
Copy Markdown

I'm currently working on porting Doom to Hermit and needed a feature to directly write pixel data into the Bochs Graphics Adaptor as Hermit currently only has support for VGA in textmode.

The feature currently adds standard BGA preparation (Link to OSDev) with a hardcoded resolution (640x400), bpp (32) and a systemcall (sys_get_framebuffer) to receive the address of the framebuffer.
The systemcall falls back to 0 if there was a failure in initializing the framebuffer (e.g. if pci is missing, or the bga feature is not enabled).

I have currently only tested this feature with c programs on a mac using Qemu. The feature is also only available on the x86_64 architecture.

@mkroening mkroening self-assigned this Jul 3, 2026
@mkroening
mkroening self-requested a review July 3, 2026 15:40

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark Results

Details
Benchmark Current: ff8a16b Previous: 2e23902 Performance Ratio
startup_benchmark Build Time 124.40 s 80.34 s 1.55
startup_benchmark File Size 0.77 MB 0.80 MB 0.97
Startup Time - 1 core 0.95 s (±0.04 s) 0.75 s (±0.02 s) 1.27
Startup Time - 2 cores 0.99 s (±0.04 s) 0.74 s (±0.02 s) 1.35
Startup Time - 4 cores 0.98 s (±0.04 s) 0.74 s (±0.02 s) 1.32
multithreaded_benchmark Build Time 130.95 s 82.11 s 1.59
multithreaded_benchmark File Size 0.83 MB 0.86 MB 0.97
Multithreaded Pi Efficiency - 2 Threads 65.26 % (±8.55 %) 85.89 % (±6.61 %) 0.76
Multithreaded Pi Efficiency - 4 Threads 36.50 % (±3.88 %) 43.43 % (±2.56 %) 0.84
Multithreaded Pi Efficiency - 8 Threads 21.60 % (±1.97 %) 25.76 % (±1.53 %) 0.84
micro_benchmarks Build Time 127.17 s 80.40 s 1.58
micro_benchmarks File Size 0.83 MB 0.86 MB 0.97
Scheduling time - 1 thread 76.25 ticks (±2.60 ticks) 62.65 ticks (±4.06 ticks) 1.22
Scheduling time - 2 threads 51.92 ticks (±17.13 ticks) 34.08 ticks (±4.10 ticks) 1.52
Micro - Time for syscall (getpid) 4.25 ticks (±0.30 ticks) 3.45 ticks (±0.58 ticks) 1.23
Memcpy speed - (built_in) block size 4096 56753.93 MByte/s (±39495.32 MByte/s) 82448.38 MByte/s (±56997.13 MByte/s) 0.69
Memcpy speed - (built_in) block size 1048576 29525.56 MByte/s (±24027.90 MByte/s) 30585.98 MByte/s (±24707.84 MByte/s) 0.97
Memcpy speed - (built_in) block size 16777216 27134.26 MByte/s (±22418.82 MByte/s) 26340.06 MByte/s (±21720.96 MByte/s) 1.03
Memset speed - (built_in) block size 4096 57157.63 MByte/s (±39780.19 MByte/s) 82292.76 MByte/s (±56891.50 MByte/s) 0.69
Memset speed - (built_in) block size 1048576 30260.29 MByte/s (±24451.10 MByte/s) 31323.85 MByte/s (±25145.86 MByte/s) 0.97
Memset speed - (built_in) block size 16777216 27892.32 MByte/s (±22875.70 MByte/s) 27104.68 MByte/s (±22209.94 MByte/s) 1.03
Memcpy speed - (rust) block size 4096 51521.06 MByte/s (±36342.87 MByte/s) 74097.96 MByte/s (±51811.44 MByte/s) 0.70
Memcpy speed - (rust) block size 1048576 29443.93 MByte/s (±23985.96 MByte/s) 30361.60 MByte/s (±24602.37 MByte/s) 0.97
Memcpy speed - (rust) block size 16777216 26881.00 MByte/s (±22172.02 MByte/s) 27625.34 MByte/s (±22806.88 MByte/s) 0.97
Memset speed - (rust) block size 4096 52144.26 MByte/s (±36783.49 MByte/s) 74373.47 MByte/s (±51976.48 MByte/s) 0.70
Memset speed - (rust) block size 1048576 30186.75 MByte/s (±24416.22 MByte/s) 31110.89 MByte/s (±25033.24 MByte/s) 0.97
Memset speed - (rust) block size 16777216 27635.24 MByte/s (±22629.49 MByte/s) 28386.93 MByte/s (±23265.03 MByte/s) 0.97
alloc_benchmarks Build Time 122.13 s 74.76 s 1.63
alloc_benchmarks File Size 0.85 MB 0.87 MB 0.97
Allocations - Allocation success 91.35 % 91.31 % 1.00
Allocations - Deallocation success 100.00 % 100.00 % 1
Allocations - Pre-fail Allocations 61.55 % 61.44 % 1.00
Allocations - Average Allocation time 3004.23 Ticks (±1413.56 Ticks) 5860.58 Ticks (±98.43 Ticks) 0.51
Allocations - Average Allocation time (no fail) 4013.56 Ticks (±1190.84 Ticks) 6554.81 Ticks (±92.86 Ticks) 0.61
Allocations - Average Deallocation time 855.34 Ticks (±379.13 Ticks) 1805.01 Ticks (±250.35 Ticks) 0.47
mutex_benchmark Build Time 124.76 s 79.82 s 1.56
mutex_benchmark File Size 0.83 MB 0.86 MB 0.97
Mutex Stress Test Average Time per Iteration - 1 Threads 14.98 ns (±0.62 ns) 12.10 ns (±0.41 ns) 1.24
Mutex Stress Test Average Time per Iteration - 2 Threads 26.24 ns (±9.05 ns) 40.26 ns (±1.68 ns) 0.65

This comment was automatically generated by workflow using github-action-benchmark.

@mkroening mkroening left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! :)

This is great! First I was wondering why we should use BGA instead of UEFI's GOP, which would also work on real machines, but I guess BGA is just easier at the moment. Since it is not that invasive, this is fine with me.

I am a bit confused regarding naming; maybe you could clear that up in a doc comment of the module or even the feature documentation. If I understand correctly, BGA is the Bochs Graphics Adapter, which we talk to via the VESA BIOS Extensions (VBE) API. But instead of talking to the BIOS via interrupts, we can just talk to the VBE API through the special BGA ports, right? In that case, the module names, feature names, and constant names make sense to me now.

Comment thread src/syscalls/system.rs Outdated
Comment thread src/syscalls/system.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs Outdated
Comment thread Cargo.toml
@mkroening

Copy link
Copy Markdown
Member

Ah, please also ensure that your PR does not include merge commits. Please rebase instead.

Comment thread src/arch/x86_64/kernel/bga.rs Outdated
@GloriousAlpaca

Copy link
Copy Markdown
Author

Thanks a lot for the feedback! I have pushed a commit, where I've addressed the feedback you've given. I have actually implemented the systemcall a bit differently than I've written before. Please do have a look if this is a good way to design it. I have also used structs instead of enums to consolidate the constants. Let me know if this is alright with you.

Comment thread src/syscalls/system.rs Outdated

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLM review

The BGA driver implementation has several critical issues that need to be addressed, particularly around unsafe operations, error handling, and potential race conditions.

Comment thread src/arch/x86_64/kernel/bga.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs
Comment thread src/arch/x86_64/kernel/bga.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs
Comment thread src/arch/x86_64/kernel/bga.rs
Comment thread src/syscalls/system.rs
Comment thread src/syscalls/system.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs Outdated
Comment thread src/arch/x86_64/kernel/bga.rs Outdated
@GloriousAlpaca
GloriousAlpaca force-pushed the pr-bga-clean branch 4 times, most recently from 276c635 to 34012fb Compare August 11, 2026 13:50
Comment thread src/syscalls/system.rs
Comment on lines +22 to +27
/// Returns the framebuffer information for the BGA device, if it has been initialized. Returns 0
/// on success, or -1 if the BGA device has not been initialized.
#[cfg(all(target_arch = "x86_64", feature = "bga"))]
#[hermit_macro::system]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn sys_get_bga_info(info: *mut FramebufferInfo) -> c_int {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns the framebuffer information for the BGA device, if it has been initialized. Returns 0
/// on success, or -1 if the BGA device has not been initialized.
#[cfg(all(target_arch = "x86_64", feature = "bga"))]
#[hermit_macro::system]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn sys_get_bga_info(info: *mut FramebufferInfo) -> c_int {
/// Returns the framebuffer information for the video output device.
/// Returns 0 on success, or -1 if the BGA device has not yet been initialized.
#[cfg(all(target_arch = "x86_64", feature = "bga"))]
#[hermit_macro::system]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn sys_get_framebuffer_info(info: *mut FramebufferInfo) -> c_int {

Comment thread src/syscalls/system.rs
#[cfg(all(target_arch = "x86_64", feature = "bga"))]
#[hermit_macro::system]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn sys_set_bga_resolution(width: u16, height: u16, bpp: u16) -> c_int {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub unsafe extern "C" fn sys_set_bga_resolution(width: u16, height: u16, bpp: u16) -> c_int {
pub unsafe extern "C" fn sys_set_resolution(width: u16, height: u16, bpp: u16) -> c_int {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants