2

I'm writing a bootloader and kernel from scratch and my goal is to create a kernel that can both be loaded by GRUB and my bootloader. The issue isn't with the kernel, though. I don't know how to load the kernel at 0x100000 which is where grub loads the kernel. 0x100000 is not small enough to fit into a 16 bit register and it is too large to reach using segmentation (using address buffer es:bx when reading the disk using BIOS interrupt).

So my question is, how does GRUB load the kernel that far into memory?

Mike
  • 175
  • 1
  • 13
  • I don't know how GRUB does it but you can easily do it in unreal mode – harold Apr 03 '17 at 18:44
  • Wouldn't I be required to write a disk driver though? – Mike Apr 03 '17 at 18:45
  • You can use BIOS interrupts in that mode, so no problems there. It's just real mode with huge segment limits. – harold Apr 03 '17 at 18:48
  • 2
    Harold is correct that you can use [unreal mode](https://en.wikipedia.org/wiki/Unreal_mode) that allows you to potentially address all 4gb of memory without being in protected mode. There is an example of getting into big unreal mode on the [OSDev Wik](http://wiki.osdev.org/Unreal_Mode#Big_Unreal_Mode). You'll be able to use 32-bit registers on memory accesses. The problem is the BIOS disk read routines use Segment:offset so you'd have to load the sectors into the first 1mb and then copy them to 0x100000 and above (using something like instructions `movsb` would work – Michael Petch Apr 03 '17 at 19:14
  • To get unreal mode to work properly to address all 4gb of memory you'll also have to ensure the A20 is enabled http://wiki.osdev.org/A20_Line – Michael Petch Apr 03 '17 at 19:16
  • Yeah I got that far... And then switching from unreal to pm or lm is the same as switching from real? – Mike Apr 03 '17 at 19:17
  • 1
    Yes, being in unreal mode doesn't alter the process of jumping into protected mode or 64-bit long mode – Michael Petch Apr 03 '17 at 19:18
  • Cool. Question answered. Thanks, guys. – Mike Apr 03 '17 at 19:19

1 Answers1

0

I am working on building a kernel through the Little Os Book and as far as I can tell the kernel is loaded at the 1MB address because it is specified in a linker script.

You can check out the book here, read the section Linking The Kernel

Japheth Obala
  • 81
  • 1
  • 3
  • Although this is an answer, it doesn't answer the question the OP asked. The OP is wondering HOW a bootloader (like GRUB) can address memory above 1MiB since real mode is restricted to accessing the first 1MiB+64KiB-16 bytes. – Michael Petch Nov 26 '19 at 14:03