Skip to main content

BiosState

Struct BiosState 

Source
pub struct BiosState {
    pub cursor_row: u8,
    pub cursor_col: u8,
    pub video_mode: u8,
    pub ticks: u32,
    pub keyboard: VecDeque<(u8, u8)>,
    pub disk: DiskGeometry,
    pub rtc_hour: u8,
    pub rtc_minute: u8,
    pub rtc_second: u8,
}
Expand description

Architectural state of the BIOS service model.

The state is deliberately small: cursor, mode, tick counter, keyboard queue, disk geometry and a frozen RTC time. The kernel adapter owns the guest memory image and the backing disk; BiosState::handle only mutates the state and the memory/disk it is given.

Fields§

§cursor_row: u8

Cursor row, 0..=24.

§cursor_col: u8

Cursor column, 0..=79.

§video_mode: u8

Current video mode (3 or 7).

§ticks: u32

Timer tick counter (nominally 18.2 Hz).

§keyboard: VecDeque<(u8, u8)>

Keys waiting for INT 16h, oldest first. Queued (scan code, ASCII) pairs, the layout INT 16h returns.

A printable key carries its ASCII byte with a zero scan code until a guest handler fills the BDA ring; an extended key (arrows, Home/End) carries the scan code with a zero ASCII byte, which is exactly what a PC keyboard buffer holds.

§disk: DiskGeometry

CHS geometry reported to the guest.

§rtc_hour: u8

RTC hour, binary, 0..=23 by convention.

§rtc_minute: u8

RTC minute, binary, 0..=59 by convention.

§rtc_second: u8

RTC second, binary, 0..=59 by convention.

Implementations§

Source§

impl BiosState

Source

pub fn new() -> Self

Creates the reset state: mode 3, cursor at home, floppy geometry, empty keyboard queue and a midnight RTC.

Source

pub fn push_key(&mut self, ascii: u8)

Queues one ASCII key for INT 16h.

The queue is bounded by KEY_BUFFER_CAPACITY; keys arriving when it is full are dropped, like a real keyboard controller overrun.

Source

pub fn push_scan_key(&mut self, scan: u8, ascii: u8)

Queues the (scan code, ASCII) pair INT 16h returns.

A guest INT 9 handler stores this pair in the BDA ring, so the runner feeds extended keys (arrows, Home/End) through the same bounded queue: they carry the scan code and a zero ASCII byte.

Source

pub fn advance_ticks(&mut self, ticks: u32)

Advances the 18.2 Hz tick counter (wrapping).

Source

pub fn handle( &mut self, vector: u8, regs: &mut BiosRegisters, mem: &mut impl BiosMemory, disk: &mut dyn BiosDisk, ) -> BiosOutcome

Services one BIOS interrupt.

vector is the interrupt number, regs the guest register file (read for arguments and updated with results), mem the guest memory image and disk the synthetic block device. The scratch byte is written on every path; the BDA is refreshed on every handled path.

Source

fn sync_bda(&self, mem: &mut impl BiosMemory)

Republishes the BDA fields owned by the model.

Source

fn set_cursor(&mut self, row: u8, col: u8)

Clamps and stores the text cursor.

Source

fn set_video_mode(&mut self, mode: u8, mem: &mut impl BiosMemory)

Sets up one text mode and clears the video window.

Source

fn video_service( &mut self, regs: &mut BiosRegisters, mem: &mut impl BiosMemory, ) -> Completion

INT 10h: video services.

Source

fn write_repeated( &self, ch: u8, count: u16, attr: Option<u8>, mem: &mut impl BiosMemory, )

Writes count copies of ch at the cursor, optionally keeping the existing attribute (attr is None). The cursor does not move; cells are filled across rows up to the end of the screen.

Source

fn teletype(&mut self, ch: u8, mem: &mut impl BiosMemory)

INT 10h AH=0Eh: teletype output.

Source

fn newline(&mut self, mem: &mut impl BiosMemory)

Moves to the next teletype line, scrolling when already on the last one.

Source

fn write_string( &mut self, regs: &mut BiosRegisters, mem: &mut impl BiosMemory, ) -> Completion

INT 10h AH=13h: writes a counted string with optional attribute pairs.

Source

fn disk_service( &mut self, regs: &mut BiosRegisters, mem: &mut impl BiosMemory, disk: &mut dyn BiosDisk, ) -> Completion

INT 13h: disk services.

Source

fn format_track( &self, mem: &mut impl BiosMemory, disk: &mut dyn BiosDisk, count: u64, table: u32, ) -> Result<(), u8>

INT 13h AH=05h: formats a track.

table points at the classic four-byte record per sector (cylinder, head, sector, size code). Every described sector is zero-filled through the block backend, which is the state a freshly formatted FAT volume expects. A read-only backend fails with the write-protected status.

Source

fn system_service(&mut self, regs: &mut BiosRegisters) -> Completion

INT 15h: system services.

Source

fn keyboard_service( &mut self, regs: &mut BiosRegisters, mem: &mut impl BiosMemory, ) -> Completion

INT 16h: keyboard services.

The ring at 0x41E is the interface DOS uses: its own INT 9 handler translates each scancode and stores it there (head/tail at 0x41A/0x41C), and the firmware service is expected to consume it. The model queue is only a fallback for a guest that never installed its own handler (there the firmware is the only producer).

Source

fn take_key( &mut self, mem: &mut impl BiosMemory, consume: bool, ) -> Option<(u8, u8)>

Returns the next key from the guest ring, then from the model queue.

consume advances the ring tail by one entry (two bytes) or pops the model queue; a peek reads without changing either.

Source

fn keyboard_ring(&self, mem: &mut impl BiosMemory) -> Option<(u16, u16)>

Reads the guest keyboard ring head/tail words.

Source

fn printer_service(&mut self, regs: &mut BiosRegisters) -> Completion

INT 17h: printer services (accepted, output discarded).

Source

fn time_service(&mut self, regs: &mut BiosRegisters) -> Completion

INT 1Ah: time services.

Trait Implementations§

Source§

impl Debug for BiosState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BiosState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.