Hi,
Avarok wrote:Brendan, your link is down again... this time to your whole site. I was so enthusiastic about seeing it too.
My website is mostly offline, and will remain (mostly) offline for a while - I'm redoing my boot code (putting an abstraction layer between the boot code and OS's startup code, so that it can be booted from PC BIOS, LinuxBIOS, EFI, OpenFirmware or directly from ROM without changing any of the OS's startup code). I've also been playing an online game recently, and have been getting more and more annoyed at stupid search engines that ignore my "robots.txt" file and decide to download my entire site (causing huge amounts of lag, usually while I'm trying hard not to get eaten by a dragon or something)...
Avarok wrote:I've almost completely written the code for this myself, but was hoping to see what you had in case I'd buggered anything up. I'd heard somewhere about the work you did to figure this out so I knew it was possible. I currently have a working 32-bit bootloader that I'm branching off of before I start the OS.
Some general notes...
First, the main idea is to prepare everything in advance (while in real mode) then set both PE and PG in CR0 at the same time (after the MSR's, CR3, etc are setup) to go directly from real mode to long mode. By the look of what you've posted (the list of things your bootloader currently does) you already understand this and are doing well.
Secondly, use something like Bochs for debugging. A black screen while the computer resets isn't much fun, while a full interactive debugger that allows you to step through everything an instruction at a time is much much more useful.
Lastly, when I say "prepare everything in advance (while in real mode)" I really do mean *everything*. My old code was stuck ontop of my old boot code, which was around 100 KB of real mode code that loaded a boot image (containing everything the OS needs after switching to long mode or protected mode), did all the memory detection, setup a default video mode, started other CPUs and obtained CPU capabilities/features/bugs, detected NUMA areas, etc. It even had a full physical memory manager so that page tables, etc could be dynamically allocated.
I guess what I'm trying to say is that the BIOS is (mostly) entirely useless once you switch to long mode, so you need to do all of the BIOS related stuff beforehand. The alternative would be to preserve the BIOS"s state (memory areas, PIC settings, etc) and constantly switch between long mode and real mode (without dropping IRQs, etc) until you're ready, which seems much less sensible to me.
Avarok wrote:After that I plan to pack in some vesa hooks to get that out of the bios, and perhaps try to get the real value of highmem somehow. My understanding is that both bios int 0x12 and int 0x15 fail to go over 64MB.
Int 0x12 will only tell you the amount of contiguous RAM below the EBDA - never more than 640 KB. Int 0x15 has several different functions for memory detection (at least 6 different functions that may or may not be supported by the BIOS). The best of them is "int 0x15, eax = 0xE820" which will be present/supported on all computers that support long mode, and does report all areas (not just usable RAM) above and below 4 GB. This makes things easy if your OS is "long mode only".
Cheers,
Brendan