Beyond the Real

“It’s all right letting yourself go as long as you can let yourself back.”

— Mick Jagger

Moving forward

It’s been a mad year and I really haven’t had time for this project. But it’s not like I’m working to a schedule or anything, this is purely an intellectual itch that I’m scratching. So, I’ve shaved the beard, emerged from the cave and am ready to stare into the abyss again.

I’ve cleaned up the editor a bit, which was significantly easier to do with an editor to make the changes. It now scrolls through memory when you hit the margins of the view with your cursor which makes typing in long programs a doddle. Writing the long programs and translating them into hex remains fraught with danger and as frustrating as ever.

We’ve about reached the end of what I want to do in Real Mode, so it’s time to put the processor into Protected Mode where we can get away from the segmented address scheme and use 32-bit instructions/registers.

Oh happy day, but wait, there’s a problem.

The problem

We’re currently relying on BIOS to handle getting keyboard input and disk operations. Replacing the keyboard isn’t a huge undertaking since Qemu is emulating a real, not USB, keyboard for us. The disk is a different matter entirely, and I have little interest in writing a floppy driver at this point in proceedings (or at all if I can help it). That leaves us with figuring out a way to access the BIOS from Protected Mode, and it isn’t straightforward.

The BIOS is 16-bit code, it uses Real Mode interrupts via the IVT table, and it expects Real Mode addressing. We will be operating in Protected Mode where none of these things are available. So how do we get around it? By dwarfing really hard.

The plan

There are a couple of steps we’re going to go through

  • Enable the A20 line
  • Load a Global Descriptor Table
  • Switch from Real Mode to Protected Mode
  • Run our program
  • Switch from Protected Mode to Real Mode
  • Disable the A20 line
  • Return to the Enbugger

Yes, I understand that’s a particularly dwarfish way of running a 32-bit program.

Ultimately what we’re going to do is write wrappers around these BIOS functions such that when they’re called they switch back to real mode, run the interrupt, then return to Protected Mode with the result. It’s a horrible crutch but until there are enough tools to make writing drivers viable it’s going to have to do.

Slow and steady

I’ve decided to put aside two hours a week to work on DwarfOS. The torture that was writing the editor very nearly ended the entire project last year, my desire to pick up where I left off was virtually non-existent. I’m hoping to avoid that kind of burn out by simply going at nice slow pace making incremental steps forwards, or backwards, or sideways, but there will be steps involved.

Back into the byte mines.

—Curufir