SchOS/include/gfx/fb.h
Nexoniarz b1323e193a input, fb, vt, sysfs: the kernel calls Xorg makes
Xorg on a framebuffer -- the fbdev video driver, the evdev input driver,
libpciaccess -- asks the kernel a fixed set of questions before it draws
anything, and gives up on the first wrong answer. These are those
answers.

evdev: EVIOCGVERSION, GID, GNAME, GPHYS, GUNIQ, GPROP, GBIT, GKEY, GABS,
GREP and the accepted setters. Xorg and libinput decide what a device
*is* from the capability bitmaps; /dev/input/eventN answered only
EVIOCGRAB, which reads as no device at all. Each device's bitmaps are
its defaults plus whatever it has reported, so a USB tablet makes the
pointer absolute.

fbdev: FBIOPUT_VSCREENINFO succeeds for the mode already set, as on
Linux -- the fbdev driver sets it every time it starts -- and still
refuses any other. FBIOPAN_DISPLAY to the origin; FBIOBLANK.

The console: KDSETMODE(KD_GRAPHICS) stops it drawing on a terminal,
KDSKBMODE(K_OFF) stops keys reaching its tty, and VT_PROCESS now does
the switch handshake: leaving the terminal sends relsig and waits for
VT_RELDISP, arriving sends acqsig. A terminal whose owner has died goes
back to the kernel whole, so a crashed X cannot leave the console dead.

/sys: boot_vga, a writable enable, and graphics/fb0 under the display
device, which is how the fbdev driver pairs a card with /dev/fb0.

ports/linux-headers: <linux/*.h> into musl's prefix, from sabotage-
linux's kernel-headers 4.19.88-2. Its checksum is recorded from the
first download; upstream publishes none.

cmd/xready makes each call and checks the answer, including the switch
handshake on tty2 and an owner that dies holding it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4
2026-10-24 12:06:04 +02:00

96 lines
3.7 KiB
C

#pragma once
// Framebuffer device ABI -- /dev/fb0.
//
// These are Linux's fbdev request numbers and structure layouts, not ours.
// SchOS invented this device, so nothing forced the choice; matching Linux
// was still the right one. A framebuffer is the first thing a graphics
// program looks for, and every such program already knows how to ask
// FBIOGET_VSCREENINFO. Inventing a private struct would have meant patching
// each one we ever port, and -- worse -- a Linux-ABI binary calling
// FBIOGET_VSCREENINFO would have gotten a *differently shaped* answer to a
// request it thought it understood, which is the failure mode that made
// `>>` truncate back when include/uapi/fcntl.h held xv6's open flags instead of
// Linux's. Same lesson, applied before it bites rather than after.
//
// Plain C types throughout (no types.h) so userspace can include this
// directly. Both sides are LP64.
#define FBIOGET_VSCREENINFO 0x4600
#define FBIOPUT_VSCREENINFO 0x4601
#define FBIOGET_FSCREENINFO 0x4602
#define FBIOBLANK 0x4611
#define FBIOPAN_DISPLAY 0x4606
// fb_fix_screeninfo.type
#define FB_TYPE_PACKED_PIXELS 0
// fb_fix_screeninfo.visual
#define FB_VISUAL_TRUECOLOR 2
// fb_var_screeninfo.activate
#define FB_ACTIVATE_NOW 0
// One colour channel's position within a pixel. `offset` is the bit position
// of the channel's least significant bit; `length` is how many bits it gets.
// A length of 0 means the channel does not exist -- which is how an opaque
// framebuffer reports `transp`.
struct fb_bitfield {
unsigned int offset;
unsigned int length;
unsigned int msb_right; // != 0 means bit 0 is the MSB; never here
};
struct fb_var_screeninfo {
unsigned int xres; // visible resolution
unsigned int yres;
unsigned int xres_virtual; // virtual resolution; == visible, no panning
unsigned int yres_virtual;
unsigned int xoffset; // offset of visible area within virtual
unsigned int yoffset;
unsigned int bits_per_pixel;
unsigned int grayscale; // 0 == colour
struct fb_bitfield red;
struct fb_bitfield green;
struct fb_bitfield blue;
struct fb_bitfield transp;
unsigned int nonstd; // 0 == standard pixel format
unsigned int activate;
unsigned int height; // physical size in mm; 0 == unknown, and
unsigned int width; // VBE does not tell us, so it stays 0
unsigned int accel_flags;
// Timings. The mode is whatever the bootloader's VBE call established and
// we cannot change it, so these are all reported as zero rather than
// invented.
unsigned int pixclock;
unsigned int left_margin;
unsigned int right_margin;
unsigned int upper_margin;
unsigned int lower_margin;
unsigned int hsync_len;
unsigned int vsync_len;
unsigned int sync;
unsigned int vmode;
unsigned int rotate;
unsigned int colorspace;
unsigned int reserved[4];
};
struct fb_fix_screeninfo {
char id[16]; // "schosfb"
unsigned long smem_start; // physical address of the framebuffer
unsigned int smem_len; // its length in bytes
unsigned int type;
unsigned int type_aux;
unsigned int visual;
unsigned short xpanstep; // 0 == panning unsupported
unsigned short ypanstep;
unsigned short ywrapstep;
unsigned int line_length; // bytes per scanline (the VBE stride, which
// is NOT always xres * bytes_per_pixel)
unsigned long mmio_start; // no separate register aperture
unsigned int mmio_len;
unsigned int accel; // no acceleration
unsigned short capabilities;
unsigned short reserved[2];
};