Expand description
s9vm : pure PC BIOS service model for a real-mode DOS-class guest.
This module implements the software half of the classic firmware surface:
it takes the guest register file captured at a BIOS interrupt, performs the
requested service on a guest memory image and a synthetic block device, and
returns the updated register values. It touches no hardware: the kernel
adapter (BiosMemory / BiosDisk) supplies guest memory and disk
sectors, and publishes the resulting CF/ZF through the scratch byte.
§Scratch-byte protocol
The real-mode ROM stubs installed by crate::s9vm::biosrom cannot return
values in registers by themselves: they OUT to a debug port, the host
services the call, and the stub patches the caller’s stacked FLAGS from a
single byte at SCRATCH_GPA. At the end of every call, handled or
not, this model writes that byte:
bit 0 CF value ([`SCRATCH_CF`])
bit 1 ZF value ([`SCRATCH_ZF`])
other zeroBiosOutcome::Unknown writes 0x00 (CF=0, ZF=0) and leaves the BDA
alone: the guest is expected to have installed its own handler for that
vector. On handled calls the two flags are also mirrored into
BiosRegisters::flags, for adapters that derive the scratch byte from the
returned register file; the scratch byte stays authoritative.
§Services
| Vector | Function | Behaviour |
|---|---|---|
05h | print screen | accepted, no-op (CF=0) |
08h, 1Ch | timer / user tick | BiosOutcome::Unknown |
10h | video | mode, cursor, scroll, characters, string |
11h | equipment | AX=0x0021 |
12h | memory size | AX=640 KiB |
13h | disk | reset, status, CHS read, params, type, extensions, DAP read |
15h | system | 88h only; C0h/E8h rejected |
16h | keyboard | polling queue, AH=00/01/02 |
17h | printer | accepted, status 30h |
1Ah | time | tick count and RTC time |
Any other vector is BiosOutcome::Unknown.
§Failure statuses
Every rejected request sets CF=1 and a documented status:
| Constant | Value | Used by |
|---|---|---|
STATUS_INVALID_FUNCTION | 01h | video/system/keyboard/disk subfunction |
DISK_STATUS_WRITE_PROTECTED | 03h | disk write requests (synthetic disk) |
DISK_STATUS_SECTOR_NOT_FOUND | 04h | bad CHS/LBA, backend error, unmapped buffer |
DISK_STATUS_MEDIA_NOT_FOUND | 0Ch | unsupported drive number |
STATUS_NOT_SUPPORTED | 86h | unsupported INT 15h subfunction |
§BIOS data area
initialise_bda fills the fields a DOS boot reads (equipment, memory
size, EBDA segment, keyboard head/tail, tick count, video mode, columns,
cursor, page, CRTC port, rows and character height). After every handled
call BiosState::handle republishes the fields it owns: video mode,
cursor, tick count and keyboard head/tail.
The keyboard buffer is modelled as a compact alloc::collections::VecDeque
rather than a real ring. The BDA therefore publishes a synthetic ring
descriptor: head 0, tail 2 * queued bytes capped at the 32-byte buffer.
This keeps the “head equals tail when empty” invariant without storing ring
indices in the state.
§Disk geometry
FLOPPY_1440 is the canonical 80 x 2 x 18 x 512 geometry (2880 sectors,
1.44 MiB). DiskGeometry::from_sectors returns it for images of at most
2880 sectors and a documented fixed-disk-ish 1024 x 16 x 63 x 512 geometry
above that (1,032,192 sectors, about 504 MiB). The geometry only describes
CHS decoding; the authoritative sector count is
BiosDisk::sectors, and reads past it fail with status 04h.
CHS sectors are one-based, as on the PC. Cylinder bits 9:8 travel in
CL bits 7:6 and are reassembled by the model.
§Documented deviations
INT 10h AH=03returns the cursor shape inCX=0x0607; the prompt also saidCH=0, but the two cannot both hold, and0x0607wins because the shape is the documented return value.CHis0x06(shape start line).INT 11hreturnsAX=0x0021. In that word bit 0 announces the floppy drive and bits 7:6 are00b, not01b: the two fields would make0x0061, so the authoritative literal0x0021is used.INT 13h AH=08returnsDL=2for drive00handDL=3for drive80h. Only those two drive numbers are accepted (a stricter reading of the classic “below0x80means floppy” shorthand); anything else fails with status0Ch.- Text services write the default attribute
07hwhere the caller does not supply one (AH=0Eh, scrolling blank lines useBH). - Guest buffer writes are attempted byte by byte through
BiosMemory. A byte the adapter refuses aborts the call with status04h; bytes already written stay written (the adapter is free to reject a range that crosses the end of mapped memory). INT 17haccepts output but has no parallel port to deliver it to; the bytes are discarded and only the ready status is reported.
Re-exports§
Structs§
- Bios
Registers - Guest register file visible to one BIOS call.
- Bios
State - Architectural state of the BIOS service model.
- Completion 🔒
- Outcome of one service handler: the pair of flags the scratch byte carries.
- Disk
Geometry - CHS geometry used to decode and report disk addresses.
Enums§
- Bios
Outcome - Result of dispatching one interrupt vector.
Constants§
- BDA_
BASE - Base of the BIOS data area.
- BDA_
CHAR_ HEIGHT - BDA field: character height, in scan lines.
- BDA_
COLUMNS - BDA field: number of text columns.
- BDA_
CRTC_ PORT - BDA field: CRTC I/O port base.
- BDA_
CURSOR - BDA field: cursor position of page 0 (
row << 8 | column). - BDA_
EBDA_ SEGMENT - BDA field: extended BIOS data area segment.
- BDA_
EQUIPMENT - BDA field: installed equipment word.
- BDA_
KEYBOARD_ HEAD - BDA field: keyboard buffer head offset.
- BDA_
KEYBOARD_ TAIL - BDA field: keyboard buffer tail offset.
- BDA_
KEY_ BUFFER - Guest-physical base of the BDA keyboard ring entries.
- BDA_
MEMORY_ SIZE - BDA field: conventional memory size, in KiB.
- BDA_
PAGE - BDA field: active display page.
- BDA_
ROWS - BDA field: text rows minus one.
- BDA_
TICK_ COUNT - BDA field: timer tick counter, 32 bits.
- BDA_
VIDEO_ MODE - BDA field: current video mode.
- DAP_
SIZE - Required size of an extended disk address packet.
- DEFAULT_
ATTRIBUTE - Attribute used by text services that do not take one from the caller.
- DEFAULT_
CHAR_ HEIGHT - Character height, in scan lines, installed in the BDA.
- DEFAULT_
COLUMNS - Text columns installed in the BDA.
- DEFAULT_
CRTC_ PORT - CRTC I/O port base installed in the BDA.
- DEFAULT_
PAGE - Active display page installed in the BDA.
- DEFAULT_
ROWS_ MINUS_ ONE - Text rows minus one installed in the BDA.
- DEFAULT_
VIDEO_ MODE - Video mode installed by
initialise_bda(80x25 colour text). - DISK_
STATUS_ INVALID_ FUNCTION - Disk status: invalid function or invalid address packet.
- DISK_
STATUS_ MEDIA_ NOT_ FOUND - Disk status: unsupported drive number.
- DISK_
STATUS_ OK - Disk status: success.
- DISK_
STATUS_ SECTOR_ NOT_ FOUND - Disk status: bad CHS/LBA, backend error, or unmapped guest buffer.
- DISK_
STATUS_ WRITE_ PROTECTED - Disk status: the synthetic disk is read-only.
- EBDA_
SEGMENT - Extended BIOS data area segment written by
initialise_bda. - EQUIPMENT_
WORD - BDA equipment word: one floppy drive, 80x25 colour (bit 0 and bits 5:4).
- EXTENSIONS_
SIGNATURE - Signature returned by the disk extensions presence check.
- FLAG_
CARRY FLAGSbit 0: carry.- FLAG_
ZERO FLAGSbit 6: zero.- FLOPPY_
1440 - Floppy geometry installed by
BiosState::new: 80 x 2 x 18 x 512. - FLOPPY_
DRIVE - Floppy drive number.
- FLOPPY_
TOTAL_ SECTORS - Total number of sectors of a 1.44 MiB floppy.
- HARD_
DISK_ DRIVE - Fixed-disk drive number.
- HARD_
DISK_ GEOMETRY - Fixed-disk-ish geometry for images larger than a floppy: 1024 x 16 x 63 x 512 (about 504 MiB, 1,032,192 sectors).
- KEY_
BUFFER_ BYTES - Size of the BDA-visible keyboard ring, in bytes.
- KEY_
BUFFER_ CAPACITY - Maximum number of keys the model queues.
- KEY_
BUFFER_ FIRST_ OFFSET - First slot offset of the BDA keyboard ring.
- MEMORY_
SIZE_ KIB - Conventional memory size reported by
initialise_bdaandINT 12h. - PRINTER_
STATUS - Status reported by the printer service: selected and ready.
- SCRATCH_
CF - Scratch bit 0: carry flag.
- SCRATCH_
GPA - Guest-physical address of the byte the ROM stubs read back.
- SCRATCH_
ZF - Scratch bit 1: zero flag.
- SECTOR_
SIZE - Size of one disk sector, in bytes.
- SPACE
- Character written to blank cells.
- STATUS_
INVALID_ FUNCTION - Invalid function or invalid parameter status.
- STATUS_
NOT_ SUPPORTED - Unsupported system function status (
INT 15h). - STATUS_
OK - Success status (
CF=0). - TEXT_
COLUMNS - Text columns of the modelled screen.
- TEXT_
ROWS - Text rows of the modelled screen.
- VIDEO_
BASE - Guest-physical base of text-mode video memory.
- VIDEO_
LEN - Size of the video window cleared when a mode is set.
Traits§
- Bios
Disk - Synthetic block-device access used by
INT 13h. - Bios
Memory - Guest memory access used by the service model.
Functions§
- bcd 🔒
- Encodes a binary byte as two packed BCD digits.
- drive_
kind 🔒 - Accepts only the two documented drive numbers.
- fail_ah 🔒
- Writes
statusintoAHand reports a failure. - initialise_
bda - Installs the BIOS data area fields a DOS boot reads.
- linear_
address - Computes a real-mode linear address from a segment and an offset.
- read_
cell 🔒 - Reads one character/attribute cell, falling back to a blank cell.
- read_
sectors 🔒 - Reads one sector after another into a guest buffer.
- read_
text - Renders the 80x25 text screen as trimmed lines.
- read_
u16 🔒 - Reads a little-endian
u16from guest memory. - read_
u64 🔒 - Reads a little-endian
u64from guest memory. - ring_
offset 🔒 - Decodes a BDA keyboard ring offset.
- scroll_
region 🔒 - Scrolls a rectangular text window up or down.
- set_ah 🔒
- Replaces
AHwithout touchingAL. - verify_
sectors 🔒 - Checks that
countsectors starting atlbaexist on the medium. - video_
cell 🔒 - Guest-physical address of one text cell.
- write_
cell 🔒 - Writes one character/attribute cell when it is inside the text screen.
- write_
sectors 🔒 - Writes
countsectors from a guest buffer, one sector at a time. - write_
u16 🔒 - Writes a little-endian
u16to guest memory. - write_
u32 🔒 - Writes a little-endian
u32to guest memory.