From 776a3710652f78b44718450406d0683974aef72a Mon Sep 17 00:00:00 2001 From: Alejandro Sior Date: Thu, 19 May 2022 08:45:26 +0200 Subject: bios: stub calls interrupt number; simplified bios.ha main interface Instead of having the bios.call stub calling a function, make it directly call an interrupt that is changed dynamically by modifying the code at runtime. Simplify the bios.ha interface and document it. Next up: implementing a high level drive interface for the BIOS using BIOS interrupts --- drive/drive.ha | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 drive/drive.ha (limited to 'drive/drive.ha') diff --git a/drive/drive.ha b/drive/drive.ha new file mode 100644 index 0000000..42cef43 --- /dev/null +++ b/drive/drive.ha @@ -0,0 +1,20 @@ +use bios; +use bios::drive; + +fn lba_to_chs(lba: u16) (u16, u16, u16) = { + let temp = lba / bios::drive::drive_spt; + let sector = (lba % bios::drive::drive_spt) + 1; + let head = temp % bios::drive::drive_heads; + let cylinder = temp / bios::drive::drive_heads; + + return (cylinder, head, sector); +}; + +export fn read(sector: u16, dest: uintptr) void = { + let chs = lba_to_chs(sector); + + bios::regs.eax = 1 | 0x2 << 8; + bios::regs.ebx = ws; + bios::regs.ecx = chs.2 | chs.0 << 8; + bios::regs.edx = bios::drive::drive_no | chs.1 << 8; +}; -- cgit v1.2.3