How to write a custom bootloader for mac systems?

六眼飞鱼酱① 提交于 2020-08-06 05:18:58

问题


I wrote a little bootloader in assembly and it uses BIOS interrupts and it works great on my pc. My question is, is there any possibility to make it work on Mac / Apple systems. I know that Apple doesn't use BIOS in that sense and that they are locking lot of things down. However it is possible to use a live ubuntu stick on mac, so might it be possible to run an assembly program from startup on a mac? If yes, do you know any starting points or references of what has been done before?

Thanks a lot!


回答1:


My question is, is there any possibility to make it work on Mac / Apple systems.

There's always a possibility. For example, it's possible that someone might port a system emulator (e.g. Bochs, Qemu) to UEFI (so that it looks like a UEFI application) that's capable of emulating a completely different computer that does have BIOS.

In practice, you'll need to write at a new boot loader for UEFI.

Note that you should also assume that UEFI is the first step in a "legacy baggage removal" scheme (and assume that Intel's "no BIOS after 2020, not even just a compatibility module" statement was made because Intel are planning to rip "legacy baggage" out of chipsets, etc; which would prevent firmware written by other people from continuing to support BIOS). For one simple example (that already exists); Apple machines don't have a PS/2 keyboard controller chip and don't have "legacy PS/2 emulation for USB devices" support, and attempting to access the PS/2 keyboard controller chip can cause the computer to lock up.

Mostly; there are a whole pile of assumptions (e.g. about the memory map, and the existence of things like A20 gate, PIC chips, PIT chip, PS/2 keyboard controller, "BIOS compatible" video card ROM, VGA hardware registers, etc) that are either not true for UEFI or not future-proof for UEFI. For this reason you should also audit the OS that the boot loader boots, to identify and eradicate all of the (potentially false) "legacy assumptions" (otherwise, even if you've got a perfectly good boot loader designed for UEFI, the OS will probably fail soon after boot).




回答2:


Mac firmware doesn't provide a legacy BIOS mode, AFAIK.

You'd have to rewrite your code as a 32 or 64-bit UEFI application, using UEFI "system calls" instead of the int 0x10 and so on BIOS calls. You can of course still write it in assembly, and it will still run natively on the CPU.

Assembly doesn't just mean 16-bit real mode with BIOS calls.

The BIOS int-whatever interfaces are already obsolete on PCs, too, but PC firmware usually has a backwards-compat mode you can enable that switches the CPU back into real mode and provides those software interfaces. (The firmware itself probably switched to 32 or 64-bit mode during bootup before loading your 512-byte bootloader from disk.)

That's what happens when you run legacy BIOS code on your PC.


According to https://www.ubuntu.com/download/desktop, the regular x86-64 Ubuntu bootable disk images work on PC and Mac, presumably both using UEFI.


Or maybe not, according to http://www.rodsbooks.com/ubuntu-efi/ booting Ubuntu on a Mac normally goes through the Mac firmare Compatibility Support Module (CSM) which provides BIOS emulation on a Mac. (Apparently also useful for some ways of booting Windows, which is why it exists in the first place.) That page seems out of date, though; Windows normally boots with UEFI on modern PCs, too.



来源:https://stackoverflow.com/questions/55949186/how-to-write-a-custom-bootloader-for-mac-systems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!