Search code examples
assemblyx86operating-systemboot

Is a 32-bit bootloader compatible with a 16-bit bootsector?


Is a 32-bit bootloader compatible with a 16-bit bootsector?

I'm running a 32-bit bootloader from a 16-bit bootsector.
I'm building my own OS.

EDIT 1

I'm running a bootsector on a Virtual Machine with an x86_64 CPU on VMWare Workstation 14.
My real CPU is an AMD Vision E2 x64.

EDIT 2

I'm using NASM assembler and C language in my bootloader.


Solution

  • Yes, a 32 bit bootloader can be used from a 16 bit boot sector. The boot sector is always executed as 16 bit code and all modern operating systems are able to boot into protected or long mode from a boot sector, so certainly this is possible.

    The difficult part is that you need to manually enter 32 bit protected mode before you can execute 32 bit code. Typically, this is done either in the boot loader itself or as an intermediate stage that enters protected mode and then proceeds to load your actual boot loader.

    You could also enter protected mode from within your boot sector, but this can be a bit challenging to do within just 512 bytes of code as you need to do more than just that; for example, you might also want to extract memory maps and other useful information from the BIOS or configure a video mode. And of course, you need to load your actual boot loader from the boot sector.