Page 2 of 4

Re:New to OS Dev.

Posted: Thu Sep 08, 2005 5:02 am
by Solar
Pype.Clicker wrote: (If some of you have a good reference - i mean a pocket book covering stuff like "binary arithmetic", "using the stack", "coding a loop in assembly", "how repmovsb works", "BIOS interrupts", etc. , would you mind posting it in the "books" thread ?)
Doing so in a flash once I cross-posted it here:

Art of Assembly (printed)

Art of Assembly (16bit DOS edition, PDF)

Art of Assembly (32bit Linux edition, PDF)

Take your pick. I'm not 100% sure what the printed edition is based upon. But this book starts at the very beginning (how did those cryptic opcodes came to pass?), and does boolean algebra just as well as thoroughly covering adressing modes, explaining the architecture (what's a cache, and why are cache lines important?), interrupts, and structured programming.

Re:New to OS Dev.

Posted: Thu Sep 08, 2005 5:39 am
by Pype.Clicker
tnx Solar, but "Art of Assembly" was just the book i was trying to avoid: >900 pages is a bit hard to digest at once, especially for someone that do not wish to _master_ assembly, only use it to understand the low levels of the computer. I was rather looking for a book that'd be sufficiently small that you can hide it during the english courses ::), sufficiently lightweight so that you can take it in the bus/tram/whatever, and sufficiently cheap so that a teenager can afford it by sparing a few weeks only.

In other words, something you won't hesitate to buy, that you can find in the local bookstore, and that can get read easily enough (thus, if you know something like that _in german_, it's welcome too :).

Re:New to OS Dev.

Posted: Thu Sep 08, 2005 6:03 am
by Solar
Pype.Clicker wrote: tnx Solar, but "Art of Assembly" was just the book i was trying to avoid...
:-*
I was rather looking for a book that'd be sufficiently small that you can hide it during the english courses ::), sufficiently lightweight so that you can take it in the bus/tram/whatever...
That, combined with...
i mean a pocket book covering stuff like "binary arithmetic", "using the stack", "coding a loop in assembly", "how repmovsb works", "BIOS interrupts"...
...leaves a common subset of [tt]zero[/tt] books I know (or could picture in my mind). However...
...that you can find in the local bookstore...
...this alone is a no-go for books on Assembler, sadly. I've only ever seen one book about Assembler in the bookstore, and it was a 1300 page volume by Addison Wesley.

I recommend taking the PDF version of "Art of Assembler", printing it to A5, and taking only one chapter at a time with you at a time.

No kidding, that's how I learned x86 assembler. ;)

Re:New to OS Dev.

Posted: Thu Sep 08, 2005 6:15 am
by Pype.Clicker
Then i guess blegian french speakers are blessed by the mighty god of ASM, which explains why they have access to a small book that covers what i've said, in roughly 300 pages and that i could find in at least 3 bookstores downtown among "visual C++ 6 in your pocket" and other "MS WORD 6" or "Easy Turbo Pascal" :P

Re:New to OS Dev.

Posted: Thu Sep 08, 2005 6:31 am
by Solar
Pype.Clicker wrote: ... and that i could find in at least 3 bookstores downtown among "visual C++ 6 in your pocket" and other "MS WORD 6" or "Easy Turbo Pascal" :P
Not blessed by God Almighty, but looking in corners of bookstores I wouldn't let myself be buried in. :D

Re:New to OS Dev.

Posted: Thu Sep 08, 2005 6:39 am
by distantvoices
beware, not that St. Gnucius the Big gets green of envy. 8)

Nah, Solar, no sorrow here & no need to be buried in olden books (far away from Stora Gamla Torg - hmmm ... jag sluta prata skitsnack now). In Vienna, such small books I have only found for HTML, JAva, C ... but not for assembly. In German thats a series iirc, which is called "Down to the Nitty Gritty" - yeh, funny english name for a book actually written in german lingo. :-)

Re:New to OS Dev.

Posted: Thu Sep 08, 2005 9:36 am
by 0Scoder
Im not sure, but when should I set SS / DS or whatever?
Also, What role to SS and DS play?
They both reference to an entry in the gdt.
SS Is the stack segment (the segment with your current stack in), and DS is the Data Segment (the segment where program data is)

For an assembly language tutorial I would reccomend this one. Apart from the sometimes strong language, I think it covers most things pretty well:
http://www.groovyweb.uklinux.net/index.php?page_name=assembly%20language%20how%20to

Re:New to OS Dev.

Posted: Fri Sep 09, 2005 1:36 am
by Solar
OScoder wrote:
Im not sure, but when should I set SS / DS or whatever?
Also, What role to SS and DS play?
They both reference to an entry in the gdt.
Only in protected mode. In real mode, they are shifted 4 bits to the left (<< 4) and added to the addressing register.

mov ds, 0x07c0

DS now points to 0x7c00 (beginning of the boot sector). You can now store an offset into e.g. BX...

mov bx, 0x01fe

...and use [ds:bx] to refer to address 0x07c0:0x01fe -> 0x7dfe (location of boot sector signature).

Re:New to OS Dev.

Posted: Sat Sep 10, 2005 1:50 pm
by pradeep
Its good to start with a boot loader instead of using others boot loaders becoz
it gives me a satisfaction that my computer is running out of my own code itself ( Isn't it great )
If you are going to use others loader you might miss something in the learning curve.
If you like to learn something learn it the hard way so that u will never forget it.
It will be tempting to use other's code or getting help from others in writing your code . Try to avoid that temptation

Re:New to OS Dev.

Posted: Sat Sep 10, 2005 2:48 pm
by Solar
We had that particular argument several times already. It depends on what you want to do. If you want to learn how to write a better scheduling algorithm, or want to get into the "real" design work fast, going for GRUB or a similar available bootloader is the way to go recommended by the vets on this board.

If you enjoy doing the nitty-gritty, writing your own bootloader can be interesting and satisfying. But it is by no means a necessary exercise on the road to a real good, very own OS.

Re:New to OS Dev.

Posted: Sat Sep 10, 2005 9:21 pm
by bubach
@ Solar: GRUB may be the best choice for any experienced C programmer, but as most newbies here don't know ANY assembler and hardly even the basics of C, I think writing bootloaders is a better way to learn then writing scheduling algorithms.. :P

You should be able to tell which people that need more practice from those that don't on this board.. ;)

Re:New to OS Dev.

Posted: Sun Sep 11, 2005 2:07 am
by Brendan
Hi,
Solar wrote:If you enjoy doing the nitty-gritty, writing your own bootloader can be interesting and satisfying. But it is by no means a necessary exercise on the road to a real good, very own OS.
For a "real good" OS, deciding on whether or not to use GRUB depends on the OS design, not whether it's easier or if the developer likes doing boot loaders, and writing your own bootloader can be necessary.

A simple example would be allowing the user to select a video mode to use during boot, regardless of which version of VBE the video card supports.

A more complex example would be an OS design that treats all data segment registers as constants, so that DS, ES, FS and GS are never changed and never need to be saved/reloaded during a task switch or when user code enters kernel space (cpl=3 <-> cpl=0 transitions). Reloading a segment register is slow because it involves accessing the GDT (probable cache miss and cache line eviction) and a pile of protection checks, so this can improve performance (and make it easier to port to long mode). However, this does imply that virtual 8086 mode and the special segments needed to use the protected interface for BIOS functions (VBE, plug & play, PCI, APM, etc) aren't desirable because the data segment registers are no longer constants. In this case it can be considered better to use these services during boot in real mode instead.

One (admittedly subjective) problem I have with the "just use GRUB" mentality is that it tends to promote "lack of thought" in inexperienced OS developers. Often "just use GRUB" is followed by "GRUB boots the kernel", which isn't required by GRUB and isn't necessarily a good idea either. Writing your own boot loader forces you to consider things like where the kernel should be loaded, whether or not to have intermediate stages and how the boot should work. An example would be an OS where the boot loader loads a boot image and starts some intermediate code, and the intermediate code detects what hardware is present and automatically selects one of several kernels depending on what was detected. Another example would be an OS that has several different copies of the same kernel in physical memory - one copy for each NUMA domain (so that all CPUs can access the kernel's code from local memory rather than slower remote memory). Of course the same things can still be done if the OS is booted from GRUB - it's just less likely when "GRUB boots the kernel" is assumed without any prior design work.

I also agree with reasons given by others - mostly, that writing your own boot loader can be a good way to gain some experience before jumping into paging and schedulers. I've heard it argued that writing a boot loader teaches nothing that can be applied later, which I refute. It helps gain experience with basic assembly, segementation, protected mode initialization, etc - all things that a very experienced C programmer may never have come across, and all things that are required knowledge, if not strongly recommended, before designing a kernel.

Further, there's one last argument that is often neglected due to it's non-technical nature - "personal pride". To be able to say "I wrote all of the code for this OS" is something that a person can be proud of, much more so than "I wrote the code for this OS, except for X and Y and Z". Personal pride is one of the reasons people want to write thier own OS to start with.

Anyway, my advice is to write your own boot loader and do a whole pile of research (Intel manuals, etc), then start writing a kernel. After you've implemented the memory manager, scheduler and possibly a few device drivers, chuck everything in the bin. After this, write a good OS design on "paper" and decide for yourself, based on everything you've learned, exactly what you do and don't want (including GRUB).


Cheers,

Brendan

Re:New to OS Dev.

Posted: Mon Sep 12, 2005 1:41 am
by Solar
Oh my, here we go again. ::) 8)

bubach says that people who don't have the basic skills for OS development to start with should start with assembly programming under severe size constrictions in a quite confusing and tricky environment which requires all kinds of legacy and fall-back mechanisms to work reliably.

To that, I say those people will fail miserably no matter where they start. And I believe it's much easier to tell incompetence in a couple of lines of C than to do so given 1k or so of spaghetti assembler. In assembler, spaghetti code might actually be a genius at work, and you have to look at the details to tell. In C, it's stupid, period. ;)

Brendan brings up a couple good points. Especially the "GRUB boots the kernel" part.

But you don't have to do that - GRUB can chainload your own boot sector just as well. That still relieves you from implementing a boot mmenu, a file system driver for half a dozen popular FS, a chainloader for dual-booting some OS other than YourOS, and writing your boot sector to some special HD location...

But the point I was trying to make is that it is perfectly OK to use GRUB. pradeep made it sound like "the wimp's way" or something, when it's a perfectly sound design decision. (Just as sound as saying "I want to write my own", if you say so for the right reasons.)

Re:New to OS Dev.

Posted: Mon Sep 12, 2005 4:26 am
by JoeKayzA
Solar wrote: But you don't have to do that - GRUB can chainload your own boot sector just as well.
I think that's not the point, when you use chainload you have to provide your own bootloader anyway. With 'using GRUB to load the kernel' I think of a multiboot or ELF kernel, where GRUB fetches everything from disk and switches to pmode before your code gets running. (I use multiboot too, btw ::), I scheduled my own bootloader to the future, when my own filesystem will be up and running)

If you just want the boot menu, you use GRUB as a 'boot-dispatcher' rather than a boot loader, IMO.

cheers Joe

Re:New to OS Dev.

Posted: Mon Sep 12, 2005 4:57 am
by Solar
Well enough. That still relieves you from having to deal with partition tables, displaying a menu in some meaningful way and accepting keyboard input (which effectively forces you to do a two-stage bootloader).

Last time we discussed this to death (hint, hint... includes links to the last two times this was discussed before that...), I think the consensus was that many things you could learn from writing a bootsector are never done anywhere else but a boot sector, and that a boot sector is the wrong place to learn about assembly programming (just like a kernel is the wrong place to learn C). Rolling your own is OK if you are aiming for specific features that cannot be done with an available bootloader (and very few things cannot be done this way), and that writing your own boot sector is OK as long as you are aware that you are doing it for the geek value.