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: u8Cursor row, 0..=24.
cursor_col: u8Cursor column, 0..=79.
video_mode: u8Current video mode (3 or 7).
ticks: u32Timer 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: DiskGeometryCHS geometry reported to the guest.
rtc_hour: u8RTC hour, binary, 0..=23 by convention.
rtc_minute: u8RTC minute, binary, 0..=59 by convention.
rtc_second: u8RTC second, binary, 0..=59 by convention.
Implementations§
Source§impl BiosState
impl BiosState
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates the reset state: mode 3, cursor at home, floppy geometry, empty keyboard queue and a midnight RTC.
Sourcepub fn push_key(&mut self, ascii: u8)
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.
Sourcepub fn push_scan_key(&mut self, scan: u8, ascii: u8)
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.
Sourcepub fn advance_ticks(&mut self, ticks: u32)
pub fn advance_ticks(&mut self, ticks: u32)
Advances the 18.2 Hz tick counter (wrapping).
Sourcepub fn handle(
&mut self,
vector: u8,
regs: &mut BiosRegisters,
mem: &mut impl BiosMemory,
disk: &mut dyn BiosDisk,
) -> BiosOutcome
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.
Sourcefn sync_bda(&self, mem: &mut impl BiosMemory)
fn sync_bda(&self, mem: &mut impl BiosMemory)
Republishes the BDA fields owned by the model.
Sourcefn set_cursor(&mut self, row: u8, col: u8)
fn set_cursor(&mut self, row: u8, col: u8)
Clamps and stores the text cursor.
Sourcefn set_video_mode(&mut self, mode: u8, mem: &mut impl BiosMemory)
fn set_video_mode(&mut self, mode: u8, mem: &mut impl BiosMemory)
Sets up one text mode and clears the video window.
Sourcefn video_service(
&mut self,
regs: &mut BiosRegisters,
mem: &mut impl BiosMemory,
) -> Completion
fn video_service( &mut self, regs: &mut BiosRegisters, mem: &mut impl BiosMemory, ) -> Completion
INT 10h: video services.
Sourcefn write_repeated(
&self,
ch: u8,
count: u16,
attr: Option<u8>,
mem: &mut impl BiosMemory,
)
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.
Sourcefn teletype(&mut self, ch: u8, mem: &mut impl BiosMemory)
fn teletype(&mut self, ch: u8, mem: &mut impl BiosMemory)
INT 10h AH=0Eh: teletype output.
Sourcefn newline(&mut self, mem: &mut impl BiosMemory)
fn newline(&mut self, mem: &mut impl BiosMemory)
Moves to the next teletype line, scrolling when already on the last one.
Sourcefn write_string(
&mut self,
regs: &mut BiosRegisters,
mem: &mut impl BiosMemory,
) -> Completion
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.
Sourcefn disk_service(
&mut self,
regs: &mut BiosRegisters,
mem: &mut impl BiosMemory,
disk: &mut dyn BiosDisk,
) -> Completion
fn disk_service( &mut self, regs: &mut BiosRegisters, mem: &mut impl BiosMemory, disk: &mut dyn BiosDisk, ) -> Completion
INT 13h: disk services.
Sourcefn format_track(
&self,
mem: &mut impl BiosMemory,
disk: &mut dyn BiosDisk,
count: u64,
table: u32,
) -> Result<(), u8>
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.
Sourcefn system_service(&mut self, regs: &mut BiosRegisters) -> Completion
fn system_service(&mut self, regs: &mut BiosRegisters) -> Completion
INT 15h: system services.
Sourcefn keyboard_service(
&mut self,
regs: &mut BiosRegisters,
mem: &mut impl BiosMemory,
) -> Completion
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).
Sourcefn take_key(
&mut self,
mem: &mut impl BiosMemory,
consume: bool,
) -> Option<(u8, u8)>
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.
Sourcefn keyboard_ring(&self, mem: &mut impl BiosMemory) -> Option<(u16, u16)>
fn keyboard_ring(&self, mem: &mut impl BiosMemory) -> Option<(u16, u16)>
Reads the guest keyboard ring head/tail words.
Sourcefn printer_service(&mut self, regs: &mut BiosRegisters) -> Completion
fn printer_service(&mut self, regs: &mut BiosRegisters) -> Completion
INT 17h: printer services (accepted, output discarded).
Sourcefn time_service(&mut self, regs: &mut BiosRegisters) -> Completion
fn time_service(&mut self, regs: &mut BiosRegisters) -> Completion
INT 1Ah: time services.
Trait Implementations§
Auto Trait Implementations§
impl Forget for BiosState
impl Freeze for BiosState
impl Move for BiosState
impl RefUnwindSafe for BiosState
impl Send for BiosState
impl Sync for BiosState
impl Unpin for BiosState
impl UnsafeUnpin for BiosState
impl UnwindSafe for BiosState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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