Rewrite in Progress
It’s been over a year since I posted here last, mostly because it had been a year since I’d done any work on Zebu. I’m writing now because I’ve spent the last few days making some progress on something.
I decided to re-write Zebu entirely from scratch. There are a number of reasons for this. First of all, I wanted the kernel to be entirely (or as much as possible) in C++ rather than C. Secondly, as I progressed before, I realized that I should have done a number of things slightly (or significantly) differently. I wanted to make it easier for me to maintain Zebu, by making the code easier to read and doing things in ways that make more sense (now that I have more of a full understanding of what writing an OS involves).
So, my current progress on this rewrite (which I started on Friday) is this:
I’ve written a bootloader that works on a hard drive (master boot record). It’s nothing special — it does no more than, say, the old DOS MBR. It looks for the active partition on the drive and executes the first sector of that partition.
I wrote a bootloader that resides in that first sector of a hard drive partition. Eventually this will become the first sector or two of a filesystem, but right now it’s just code. The code here loads the kernel (from a fixed position on the partition) into memory. It loads it to the 1 MB mark in memory, which is where main memory begins. (My previous implementation kept the kernel below the 640K mark, which was somewhat restrictive.) It switches directly from 16-bit real mode into 64-bit long mode, and then executes the kernel.
The kernel itself is, as I mentioned, almost entirely written in C++. It’s compiled entirely as 64-bit code (AMD64, EM64T, or whatever you want to call it). It’s highly object-oriented (that’s why I wanted it in C++), which I’ve found to be increase my development speed greatly. It currently has a physical memory manager, it can handle some interrupts, and it can create page tables. There’s still a lot of work to do to catch up to what I had before, but it doesn’t seem like it’ll take long to get there.
I discovered a very useful tool which has helped me quite a bit: I compiled Bochs (an emulator) with its graphical debugger enabled. This is proven to be extremely useful in debugging problems along the way. I wish I had done this the last time around.
I’ll continue to post updates here as I make more progress with it.