« machine level instructions are interesting | Main | Simulating the NIOS II w/mmu using Verilator »

pxe booting, huge pages and running raw x86_64 code

Lately, for one of my customers, I've been using "pxeboot".

You know you're in trouble when you order a motherboard with 2 cpu slots and 16 ram slots...

It seems most high end server mother boards support "pxe", which is essentially dhcp + tftp lan booting. Basically booting over the network.

The fun thing is it loads the code 0x7c00, just like the bios loads the boot sector. This means, you can write simple real mode code, just like in a boot sector.

I've been doing this and then jumping to protected mode and then writing C, but naturally the customer wants to use "long mode" since his machine has 320Gb of ram and he wants to use it all. So, I crafted up some code to switch from real mode to long mode. This requires turning on paging so I decided to use 1Gb pages to make the paging table smaller (since I am lazy and writing real mode code is painful).

Anyway, I have pxe loadable code which will flip into "long mode" and run a 64 bit mini-os, all loadable from the network.

Not that hard to do, but. The interesting part is that QEMU was very helpful up through protected mode, but bochs has really shone as a good pc emulator. I modified "bfe" the bochs front end so I could single step through the boot code when loaded but the bios. This is helpful. But I used qemu since it's faster.

But qmeu does not support 1gb pages. I was surprised to find bochs does, if you turn on x86_64 support.

It's a little frightening to build a page table for a 320gb machine, but hey, it only took 320 PDP entries and one PML4 entry.

The point of the story is that "PXE" booting seems like a useful thing for some applications, and being able to write raw code to use a PC and an embedded system in sometimes helpful.