Skip to content

Latest commit

 

History

History
92 lines (74 loc) · 5.87 KB

File metadata and controls

92 lines (74 loc) · 5.87 KB

Developer notes

  • big fluffy goal: boot and run FreeDOS[1] on a UEFI[2] PC


Relevant standards (and "standards")

  • the hope is that biefircate can implement at least the BIOS interrupts and parts of the BIOS data area described in RBIL[3]

    • intrs. 0x000x1f (incl. 0x080x0f for IRQs 0—7)

    • intrs. 0x700x77 for IRQs 8—15

    • the BIOS data area 0x40:00x50:0

    • maybe also intrs. 0x40 (relocated diskette I/O) and 0x42 (relocated video output services)

    • no need for biefircate to implement MS-DOS intrs. (0x200x33 etc.)

  • biefircate should also properly initialize any option ROMs for PCI devices — PCI firmware spec.[4] says how

  • we assume the PC firmware

    • implements UEFI[2]

    • has some PCI support

    • has a legacy-style PCI option ROM for the VGA device

    • has some ACPI tables[5] which report what features the underlying system has

      • biefircate will likely not support ACPI in its full generality; the spec. is extremely complex

  • some PCs — but not all — allow bootloaders to access the firmware volume protocol;[6] this can be used to discover some option ROMs


Code structure (?)

  • stage 1 is for stuff that happens before exiting UEFI boot services; stage 2 is for stuff after that

    • other than the above, there are (currently) no hard and fast rules for delineating the two

    • stage 1 passes a pointer to a linked list of boot parameters (see bparm.h) to stage 2

  • stage 2

    • currently takes the form of an ELF executable[7]

      • 32-bit, but can access 64-bit addr. space via PAE paging[8]

    • calling convention used is -mregparm=3 -mrtd

      • when calling non-variadic function: first few arguments go in eax, edx, ecx; callee pops any stack arguments

      • callee must preserve ebx (!), esi, edi, ebp


Rough to-do list (?!?) for something approaching a "minimum viable product"

  • ☐ Screen output

    • ☑ via VGA option ROM, if present

    • ☐ via framebuffer from UEFI bootloader[9]

  • ☐ Keyboard input

    • ☑ via PS/2 keyboard — partially working

    • ☑ via USB keyboard emulating legacy PS/2 keyboard using SMI

      • ☑ EHCI — partially working

      • ☑ XHCI — implemented, need testing

    • ☐ via USB keyboard directly

  • ☐ Storage drive I/O

  • ☐ Time-keeping — useful-to-have capability for interacting with other devices e.g. keyboard and storage (!)

    • ☑ via legacy PIT and/or CMOS RTC

    • ☐ via time stamp counter (rdtsc) or APIC timer, on a CPU

    • ☐ via HPET or ACPI timer, outside CPUs


Other notes

  • UEFI stuff

    • note: boot services will be unavailable once bootloader calls BS→ExitBootServices(, )

      • might be possible to implement a BIOS without exiting boot services, but this is non-trivial — UEFI expects to be in control of most system resources, incl. memory, page tables, and IRQs

  • how to correctly interface with PC hardware legacy-style

    • IBM’s published BIOS source code, e.g. PC AT BIOS listings from 1986,[10] might be useful

    • also potentially useful is Eyal Abraham’s new-xt-bios,[11] a rewrite of the BIOS for an (older) PC XT with partially custom hardware (code is under an MIT License)

  • USB stuff — possibly useful are

    • Forever Young Software’s FYSOS code,[12] a companion to their OS design book series, including a book on USB programming[13]

    • the SeaBIOS project[14]

  • Xv6 will panic if it cannot find MP tables per Intel’s (deprecated) MultiProcessor Specification[15]

    • biefircate produces dummy MP tables if XV6_COMPAT is defined

    • other OSes probably do not need MP tables to work


1. https://www.freedos.org/. Retrieved on 15 August 2021.
2. UEFI Forum. Unified Extensible Firmware Interface (UEFI) Specification: Version 2.9. March 2021. https://uefi.org/sites/default/files/resources/UEFI_Spec_2_9_2021_03_18.pdf.
3. Brown, Ralf. The x86 Interrupt List. 16 July 2000. http://www.cs.cmu.edu/~ralf/files.html.
4. PCI-SIG. PCI Firmware Specification: Revision 3.0. June 2005.
5. UEFI Forum. Advanced Configuration and Power Interface (ACPI) Specification: Version 6.4. January 2021. https://uefi.org/sites/default/files/resources/ACPI_Spec_6_4_Jan22.pdf.
6. UEFI Forum. UEFI Platform Initialization (PI) Specification: Version 1.7 Errata A. April 2020. https://uefi.org/sites/default/files/resources/PI_Spec_1_7_A_final_May1.pdf.
7. TIS Committee. Tool Interface Standard (TIS) Executable and Linking Format (ELF) Specification: Version 1.2. May 1995. http://refspecs.linuxbase.org/elf/elf.pdf.
8. Intel Corporation. Intel® 64 and IA-32 Architectures Software Developer’s Manual: Volume 3A, pp. 2-17, 4-14—4-19. June 2021.
9. Bzt et al. GOP. OSDev Wiki, 2020. Retrieved on 22 April 2022.
10. International Business Machines Corporation. IBM: Personal Computer Hardware Reference Library: Technical Reference 6183355, pp. 5-14 et seq. March 1986. https://archive.org/details/bitsavers_ibmpcat618ferenceMar86_25829277/page/n245/mode/2up.
11. https://github.com/eyalabraham/new-xt-bios. Retrieved on 28 August 2021.
12. https://github.com/fysnet/FYSOS. Retrieved on 15 April 2022.
13. B. D. Lunt. USB: The Universal Serial Bus. April 2018.
14. https://www.seabios.org/. Retrieved on 15 April 2022.
15. Intel Corporation. MultiProcessor Specification: Version 1.4. May 1997.