3 ms·
This reminds me of the first lab assignment of my OS class. Ah, here it is (but don't trust this link: the professor takes it down and puts it back up again wit
by philwelch 12y ago
This reminds me of the first lab assignment of my OS class. Ah, here it is (but don't trust this link: the professor takes it down and puts it back up again with slight changes every term): http://eecs.wsu.edu/~cs460/LAB1.html http://eecs.wsu.edu/~cs460/LAB1.html
Interesting notes about this class:
1. This is the second of two one-semester systems programming classes. In the first semester, you learn how to implement ext2. The bootloader assignment is mostly a minimal refresher of the same subject, so you're expected to have remembered from last semester how to traverse the filesystem.
2. You have to write the whole boot loader yourself, aside from some assembly code you've been provided. It runs in 16-bit mode, so you can't use gcc, at least not easily. You use bcc; Bruce's C compiler, which doesn't really read ANSI C.
2a. This actually continues throughout the entire class, during which you will eventually build an entire kernel, in 16 bit x86, using Bruce's C compiler. I don't know who Bruce is, but the professor apparently thought that 32-bit mode did too much of the work for you and wanted us to understand how to do some of the stuff (i.e. switching between kernel and user mode, I think?) ourselves.
2b. Bruce's C compiler lacks a lot of interesting features of more modern C compilers, like function signatures. In Bruce's C compiler, much as in early dialects of C, you can call any function you want and pass whatever arguments you want; the only thing the function does is read it off the stack. Downsides: whatever paltry type safety you get from C is gone; you can pass a long to a function that expects a short and it'll just grab enough bits off the stack to make a short. Upsides: variadic functions, like printf, are marginally simpler to implement; when they released some of the very earliest C/Unix code, I found that my printf had a very close resemblance to the original.
3. You have to fit the whole bootloader in 1 KB, which is not the kind of programming challenge I had yet faced.
4. Since the entire class is taught using ancient technology, there's obviously no emphasis on things like git or API keys. I personally took this class as an opportunity to teach myself git in order to maintain my own sanity.
The professor who teaches these classes is a bit of a legend among CS alumni at my school, partially for these lab assignments and partially for his lectures, which involve extended metaphors, and in which he doesn't erase anything he writes on the whiteboard, instead diagramming or writing over whatever he diagrammed or wrote before.
- userbinator 12y ago3. You have to fit the whole bootloader in 1 KB, which is not the kind of programming challenge I had yet faced. If you were doing it in Asm, 1KB is a lot of code. The regular DOS bootsector is 512 bytes, of which only ~400 are available for actual code. It doesn't take all that much code to read in a few sectors from disk into memory and jump to it, which is all that a bootloader does.