from Hacker News

Writing a BIOS bootloader for 64-bit mode from scratch

by D4ckard on 7/14/24, 8:46 AM with 80 comments

  • by 5- on 7/14/24, 10:40 AM

    note that you can switch to long mode directly, without going into protected mode first, with way less code:

    https://wiki.osdev.org/Entering_Long_Mode_Directly

    i've had a bootloader for a small 64-bit kernel based on this that fit comfortably into the bootsector, including loading the kernel from disk and setting up vesa modes, no stage2 required.

  • by hyperman1 on 7/14/24, 12:55 PM

    The 80286 has the Machine Status Word (MSW), a 16 bit register. The 80386 expands this to CR0, a 32 bits register. Then 64 bit long mode adds the EFER MSR and expands CR0 to 64 bits. But even today only 11 bits of CR0 are in use and EFER has 8 active bits. I wonder why intel/AMD did not simply use the free bits of the existing register, and made that decision twice?

    https://wiki.osdev.org/CPU_Registers_x86-64#CR0.

  • by rep_lodsb on 7/14/24, 3:09 PM

    The most unnecessarily complicated thing in this article to me is the Makefile and linker script. NASM supports generating flat binary output, but apparently using it would be too "hacky"?
  • by ForOldHack on 7/16/24, 1:55 PM

    This seems both cool, and a good exercise, but is it useful? Does it have a UX like a fisher/price toy that you can verify/change your settings on the fly?

    Booting is the process of going from mini-me mode/single user/recovery mode to flying.

    I have been running Unix along side a Microsoft product since Xenix/dos. ( Looks like 40 years...) How much have we advanced?

    I also have been using Linux since the swedish version came out ( first release ) and GNU 0.1.

    My apologies about calling Xenix, Unix, It is a has-been wanna-be me-too square-excrament from shortly after release until it's languishing demise.

    Microsoft does not release products, they empty their cat boxes onto customers. ( The most recent example is both co-pilot And 22H2. )

    If you look at how F1 cars have evolved, and pencils as well as pocket calculators - how close are we to the usable ideal?

    Why isn't the bootloader a static kernel mode? It used to be. Someone recently suggested it should be, and I agreed.

  • by blankx32 on 7/14/24, 11:12 AM

  • by ThinkBeat on 7/14/24, 12:40 PM

    All to me entirely unnecessary steps required to get the CPU into the correct mode is astounding.

    They all seem to be steps needed for backwards compatibility.

    Could Intel just provide a flag, command, to start in the right mode from the beginning.

    Or just remove all the backwards compatibility.

    I think I remember doing some research and ARM64 has some of the same issues.

    Are there any CPUs that are designed from scratch as 64 bit it will not have any need for backwards compatibility and would enter the required state by default?

    I guess sthat was the goal / design of Itanium?

    are made to start in the desired 64 bit state from th

  • by cf100clunk on 7/14/24, 3:22 PM

    A laudable project. UEFI proponents here wondering why the person bothered to create a new bootloader approach might be missing the point of why people undertake such tasks as this. As the writer ends:

    > Cool if you actually came along this far.

    Cool indeed.

  • by AstralStorm on 7/14/24, 10:22 AM

    How old is UEFI now? Pity nobody deprecated BIOS alongside long mode.
  • by ruslan on 7/14/24, 12:14 PM

    Does this boot procedure work with EFI/UEFI ? If so, does UEFI supervisor emulate swithing real/protected/long modes or does it go in real hardware ?
  • by amelius on 7/14/24, 12:21 PM

    Is this any simpler on ARM?