7

What I'm wanting to do is somehow run BIOS-only OSes on computers that do not support BIOS booting or CSM. Does there exist an efi application that I can chainload that can act as some kind of emulator for legacy BIOS?

For my purposes, using a VM defeats the point. I'm looking for as close to bare-metal as possible.

Daffy
  • 269
  • 1
  • 4
  • 12
  • 4
    A company that writes UEFI firmware might be able to write one with a Legacy mode(aka CFM). You might need to fit a chip, this website mentions something about a chip replacement https://biosmaster.co.uk/ – barlop Jun 12 '23 at 04:08
  • @SeñorCMasMas Thank you haha. You have no idea how hard it is to google for this. "BIOS emulator for UEFI" finds everything saying "How do I boot to my BIOS?" "What is a UEFI BIOS" etc etc – Daffy Jun 12 '23 at 04:19
  • 1
    @barlop For my purposes, replacing a chip is out of the question. My question as written is about the general idea of software emulation of BIOS calls that can run on a UEFI-only motherboard. However my specific use case is installing old OSes (like windows xp, dos, windows 3.1, etc) on newer hardware. I didn't include that detail because I feel that would attract "Use DOSBox" and "Use a VM" as answers, which is not in the spirit of what I'm looking for. – Daffy Jun 12 '23 at 04:22
  • @Daffy - You might have to learn to accept, that it will quickly become impossible, to run legacy operating systems that require BIOS instead of UEFI. Intel and AMD are quickly reaching a point of NOT even supporting CSM on newer hardware. I have no idea what "CFM" is supposed to mean, I assume, you actually mean "CSM". – Ramhound Jun 12 '23 at 18:18
  • @Ramhound Yes I meant CSM, edited my question. I struggle with acronyms sometimes – Daffy Jun 13 '23 at 03:57
  • 3
    I think this is a lot more complex than one would assume, looking at https://gitlab.com/tkchia/biefircate/-/blob/main/NOTES.asciidoc here. Found via http://reboot.pro/index.php?showtopic=22488 . There was also BAMBIOS but never heard of it again after initial drop.. – Raf Jun 13 '23 at 13:35
  • 2
    Looks like it exists for Win 7: https://github.com/manatails/uefiseven although the last commit is 2 years old. You could analyze that and see to make it work for other OSes – 1NN Jun 14 '23 at 08:06
  • 1
    And it looks like someone figured it out for Win XP too: https://www.betaarchive.com/forum/viewtopic.php?p=456492&sid=2136f719d63c42b56bae4bb9594f7863#p456492 So the easier approach looks like going OS by OS, rather than to emulate BIOS. It's easier to google, too .. I found this googling for "windows xp on uefi" – 1NN Jun 14 '23 at 08:27
  • 1
    @Ramhound Recently Intel is thinking aloud about [x86-S](https://www.intel.com/content/www/us/en/developer/articles/technical/envisioning-future-simplified-architecture.html). Meaning "Simplified x86" that is dropping 16 bit real mode and 32 bit protected mode support on CPUs. – xenoson Jun 19 '23 at 14:02
  • @xenoson - Yes, I know, why are you telling me that? – Ramhound Jun 19 '23 at 15:00
  • @Ramhound Ok. Dont't worry :) Because of that comment above of Intel and AMD dropping support of CSM. – xenoson Jun 19 '23 at 15:32
  • @xenoson - That is already happening. A 64-bit only x86 architecture might happen; zero products exist from Intel that do not support the necessary modes to support 32-bit operating systems. In other words an architecture like x86-S will be released in the future, as anyone can agree, 32-bit applications are a thing of the past. – Ramhound Jun 19 '23 at 16:11

2 Answers2

12

A "BIOS emulator" would mostly be a full BIOS implementation, minus the motherboard-specific hardware initialization code. The one that's typically used in such situations is SeaBIOS, which is used e.g. on machines that use Coreboot firmware (dual-booting Chromebooks and such) in a very similar way as you're asking for UEFI.

SeaBIOS also seems to be available as an UEFI firmware package (i.e. it can be the CSM embedded in your firmware), though apparently not as a standalone .efi executable.

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • 1
    I think much lesser can be done. I couldn't crack how due to insufficient understanding of UEFI syscalls. You should be able to relocate your emulator above 15MB (memory between 1MB-15MB must be contiguous--but you can use a sparse map above), relocate yourself there, set up a new memory mapping that uses F0000-FFFFF as a 16 bit to 64 bit trampoline and implement bios services in terms of UEFI services. It's open to debate whether or not it's faster to switch between 16 and 64 bit code in the trampoline or just emulate all 16 bit instructions. – Joshua Jun 12 '23 at 18:57
  • This seems like a useful lead, thank you – Daffy Jun 13 '23 at 03:59
  • @Joshua do you think it would be possible to implement all [BIOS interrupt calls](https://en.wikipedia.org/wiki/BIOS_interrupt_call), which is pretty bare metal stuff, in a complete hardware agnostic way using only high level UEFI interfaces? – xenoson Jun 19 '23 at 14:01
  • @xenoson: Assuming no floppy disk device, the only things you would have to implement directly are 14h and 1Ah. 15h function 89h can't be done, but it's so rarely used that it was broken (as in returns to the wrong address) for years before somebody noticed. Note that you can get away with saying "no printer here", "no joystick here", and "no lightpen here". – Joshua Jun 19 '23 at 14:31
  • Correction: "broken for years" -> "broken in dosbox for years" – Joshua Jun 19 '23 at 21:50
  • @Joshua Thanks for your insight. – xenoson Jun 20 '23 at 14:01
2

I am not sure, but I believe GRUB or REFIND (Or it's Mac-compatible fork ReFIT) can boot mbr, but it is really a function of the BIOS to load the legacy MBR/CSM (compatibility support mode). Your best bet is to install these tools and try to see if they will work on your hardware.

Edit: after doing some digging, the answer is likely no: https://www.freebasic.net/forum/viewtopic.php?t=27466 https://mail.coreboot.org/hyperkitty/list/seabios@seabios.org/thread/GNX7DJC7BF6JUSKFZVGSZEWWZG2FUPDR/

Justin Goldberg
  • 592
  • 1
  • 7
  • 15
  • 2
    It does not work because the CSM is needed to implement an archaic API: [real mode software and hardware interrupts](https://en.wikipedia.org/wiki/INT_(x86_instruction)#Real_mode). [SeaBIOS implements 16bit real mode handlers for both hardware interrupts and software request "interrupts".](https://www.seabios.org/Execution_and_code_flow) – xenoson Jun 18 '23 at 13:34