Note that this is not the MBR, but what is known as the "volume boot record" (VBR) which is located at the start of each partition. And to be honest, I don't think this code is significantly more readable than the Asm version... or maybe it's the lack of comments. It'd also be interesting to compare the compiled version's code with the handwritten Asm one.
This is probably one of the few times assembly is more readable and easy to understand than C. Many years ago I used to teach OS classes at a local university, we would build a simple bootstrap using NASM. The source code includes 32bits (a20 etc) and GDT iirc:
Going into protmode in the boot sector is extremely early. Most OSs I've seen will stay in realmode (or "unreal" mode) for a little bit longer, so they can use the BIOS to setup some more stuff before making that leap.
Also noticed a minor optimisation:
mov AL, [SI] ; pega um byte da string e carrega em al
inc SI
Could've been replaced with a 'lodsb', saving 2 bytes. Ditto for MOV BH/MOV BL with MOV BX. :-)
Actually, I really prefer writing that in C rather than asm: You can use bitfields to define the GDT, IDT, Page Directories and so on. Doing everything is ASM is a PITA, for debugging and for readability.
(I am a teaching assistant at one of these courses and hate when students do everything in asm.. but they are allowed to do as they want, as long as it works as specified).
I'm actually pretty surprised and impressed at how short and legible this turned out. Out of curiosity I've written code to do I/O through the BIOS and parse files out of FAT, it didn't turn out this short.
I think it's pretty cool.. I know that it's a bit of an odd thing to notice, but thought it was almost odd that it is on Google Code, and not github. Not that there's anything wrong with that, it just feels like when I see something new that isn't on github that's open source related it surprises me a little.
But it looks like this was actually started over 4 years ago, I didn't notice the date of the article. Was curious if anyone else noticed it like I did.
GitHub is easier to browse (both over the site and through individual repos). Also, GitHub has better integration between issues, commits, and pull requests.
Which layout? The x86 boot process is pretty well documented and not something that needs a source at this point. Either way he says he learned this all by studying MSDOS.
Here is the annotated disassembly of the DOS 6.2 VBR: http://www.tburke.net/info/ntldr/bootsect.txt