The SilverOS framebuffer driver provides the foundation for all visual output in the system. At boot, the kernel reads the framebuffer address, dimensions, pitch, and bit depth directly from the Multiboot2Documentation Index
Fetch the complete documentation index at: https://mintlify.com/pastaboy12345/SilverOS/llms.txt
Use this file to discover all available pages before exploring further.
framebuffer tag and stores them in a global framebuffer_t struct. All drawing operations target an in-memory back buffer; a single call to fb_swap_buffers() pushes the finished frame to VRAM, eliminating screen tearing without requiring any hardware acceleration.
Framebuffer structure
Theframebuffer_t struct captures every parameter needed to address and draw into the display. The global fb instance is populated once by fb_init() and remains valid for the lifetime of the kernel.
buffer points directly into VRAM at the physical address provided by the bootloader. back_buffer points to a static array in BSS that all drawing functions write to. pitch may be larger than width * 4 if the display hardware adds padding at the end of each scanline, so fb_swap_buffers() uses pitch rather than width when indexing into buffer.
Color macros
Colors are represented as 32-bituint32_t values in ARGB format (alpha in the most-significant byte). Two construction macros and a set of named constants are provided:
RGB always sets alpha to 0xFF (fully opaque). Use RGBA when you need a custom alpha value to pass to fb_blend().
Drawing API
All functions below write intofb.back_buffer. Call fb_swap_buffers() after compositing the full frame.
| Function | Description |
|---|---|
fb_init | Parses the Multiboot2 framebuffer tag, stores dimensions/pitch/bpp in fb, zeroes the back buffer, and logs the result to serial. |
fb_put_pixel | Writes a single pixel to the back buffer at (x, y). Clips silently if out of bounds. |
fb_get_pixel | Reads the current back-buffer value at (x, y). Returns 0 if out of bounds. |
fb_fill_rect | Fills a solid axis-aligned rectangle. Clips each pixel individually. |
fb_draw_rect | Draws the four edges of a rectangle without filling the interior. |
fb_draw_line | Draws an anti-aliasing-free line between two points using Bresenham’s algorithm. |
fb_fill_screen | Sets every pixel in the back buffer to color in a single loop. |
fb_draw_gradient_v | Fills a rectangle with a top-to-bottom linear interpolation between c1 and c2. |
fb_draw_gradient_h | Fills a rectangle with a left-to-right linear interpolation between c1 and c2. |
fb_swap_buffers | Copies the back buffer to VRAM line-by-line. Must be called once per frame to make drawing visible. |
fb_blit_region | Copies a w×h pixel array from src onto the back buffer at (x, y). Used for image/sprite blitting. |
fb_blend | Alpha-blends foreground color fg over background color bg using an explicit 8-bit alpha (0 = fully transparent, 255 = fully opaque). |
Double buffering
Every drawing function writes exclusively tofb.back_buffer, which is a static uint32_t array allocated in the kernel’s BSS segment. The front buffer (fb.buffer) is the VRAM region mapped directly from the physical address provided by Multiboot2 — writes to it appear on screen immediately.
fb_swap_buffers() bridges the two by copying the back buffer to VRAM one scanline at a time:
memcpy accounts for any scanline padding by indexing the front buffer with pitch_pixels rather than fb.width. The desktop shell calls fb_swap_buffers() exactly once at the end of every frame loop, after all widgets and the cursor have been composed into the back buffer.
The back buffer is a statically allocated array:
static uint32_t back_buf[1920 * 1080] in BSS. This reserves roughly 8 MB of kernel memory at compile time and caps the maximum supported resolution at 1920×1080. Resolutions smaller than 1920×1080 work correctly — the driver uses fb.width and fb.height for all arithmetic; the extra BSS space is simply unused.Font rendering
Text is rendered using an 8×16 pixel bitmap font. Each character glyph is encoded as 16 bytes, one bit per pixel per row, and is drawn directly into the back buffer.| Function | Description |
|---|---|
font_draw_char | Renders a single character glyph at pixel position (x, y) using fb_put_pixel for each set bit. Transparent (zero) bits are not drawn, so the caller must clear the background first if needed. |
font_draw_string | Calls font_draw_char repeatedly, advancing x by FONT_WIDTH for each character. Does not handle newlines. |
font_draw_string_scaled | Like font_draw_string but renders each bit as a scale×scale block, producing larger crisp text without a separate font atlas. |
Console
The text console layer sits on top of the font and framebuffer APIs. It maintains a cursor position in character-grid coordinates and handles common control codes.console_putc interprets four control characters:
\n— moves the cursor to the start of the next row\r— returns the cursor to column 0 without advancing the row\t— advances the cursor to the next 4-column tab stop\b— moves the cursor one column left and erases the character cell with the console background color (RGB(15, 15, 25))
console_scroll() shifts every row of the back buffer up by FONT_HEIGHT pixels using memcpy, clears the bottom row, and decrements cursor_y. This keeps the console scrolling smoothly without allocating a separate character cell array.
kprintf is the primary kernel logging function. It formats a string into a 512-byte stack buffer using vsnprintf, then calls both console_puts (which writes to the back buffer and calls fb_swap_buffers()) and serial_puts, so every message appears simultaneously on screen and on the serial port.
Usage example
fb_swap_buffers() must be called after any sequence of drawing calls that should become visible. Batching all drawing for a frame before swapping avoids partial updates appearing on screen.