First OS attempt, need some advice
Posted: Thu Dec 20, 2007 11:09 pm
Hello everyone.
After lurking here for a while and doing a lot of research on my own, I've finally started off down the road of developing an OS. It's something that I've wanted to do for a few years now, and I think I finally have the work ethic and skills to have a decent shot at getting somewhere with it.
Following some tutorials I've found and using some of my own experience, I've managed to set up the tools and environment necessary to begin, and have gotten a very basic Hello World bootloader done. Now comes that dreaded moment: what next?
I decided immediately that I should plan out my operating system before I got very far at all into it, and so, I figured I'd ask some things here before I got hopelessly lost. I've done a good bit of research on my own, but I still have some questions on basic design that I think I need some advice with.
First and foremost, I suppose I should ask the question of whether or not I'm really ready for this (I've read the wiki article on it, but I'd like some reassurance). I have around 7 years of working with C++, and that's the language I intend to write my kernel in (yes, I understand the implications of writing a basic run time library for it), and I have a pretty good amount of experience with working with moderately complex projects like 3D game programming. But, there are two skills that I'm somewhat concerned about. First, while I do have experience with assembly languages, I've never written an OS hosted application with it (only for 3D games with first generation fragment / vertex programs). Next, I have no experience whatsoever with using multithreading. Since it seems to be a somewhat important part of an operating system / API, I'm worried I won't be able to satisfactorily learn the material while trying to do something as hard as writing an OS. Do you think it's reasonable that I can overcome my inexperience with ASM to learn it while writing those parts of my OS?
Next, I have a few questions on design of the OS itself. I tried to answer these sorts of questions myself, but most are a sort of philosophical take on the problem. First up, I guess I should explain what my goals for the OS are.
I want the OS to have the following features when I consider it "done enough":
Multitasking (what OS can't these days?)
Text only interface (no point getting bogged down with a GUI at this stage)
Very basic video API for applications (possibly text only)
Probably no sound
Support at least a wired ethernet network with TCP/IP
Support for at least one fixed disk filesystem
Single user
Little security
No overconcern for efficiency, just stability
As far as these design goals are, I'd like some input. First up is the question of a sound API. From what I gather, it seems to be possible to get sound on a hobby OS, but there doesn't seem to be any standard way of doing it without drivers (i.e. for video at the very least you can use direct text mode without support drivers). Is it too much of a hassel to expect sound?
One of the biggest reasons I wanted to write this OS was to be able to support a simple web server, and for that I'll need networking and TCP/IP. Obviously this is also possible, but is it completely impractical for my first OS attemp? I know it won't be easy, and to write the drivers I'll probably have to get a specific card with known hardware, but I'm willing to try.
As far as 64/32 bit goes, is there any reason to not go 64-bit? I've seen some things about it not supporting hardware multitasking, but I assume that most modern OSes use software multitasking, correct? Are most of the examples that I've seen for 32-bit OSes going to work in 64-bit? (Barring certain ASM things like address lengths and certain instructions, of course).
Possibly pointless, but I was also wondering a bit about the traditional ring0 - ring3 protection scheme of most OSes. Is there any tangible benefit to, say, make drivers run in ring1? As far as I can tell, it wouldn't be terribly different than running then in ring3 (micro kernel?). Should I just stick to the monolithic ring0 - ring3 convention?
One other big question nagging me is the support for SMP / multithreading. I seriously doubt that I will end up porting any known application or STL to my OS, so I honestly don't know if multithreading will be necessary, since I'll be doing all of the programming and I don't know how anyway. Is this ridiculous? Obviously multiple processes is going to be present, but with only a single thread. As far as SMP goes, I'd love to take advantage of multiple cores or processors, but I haven't found much in the way of examples of using SMP in an OS. I found the manual from Intel, but it's so heavy in hardware design and related stuff that it can't possibly hope to answer the question of whether or not it's reasonable for me to try and implement it.
Also, how practical is it to implement basic USB functionality? I know that some things like this are proprietary (PCI spec is, isn't it?). Basically, the only important things would probably be basic USB support and a standardized driver for Mass Storage Devices. USB keyboards / mice are emulated in the BIOS, right? I forgot to look into this earlier, I'll try to remember to do so later.
Lastly, I wanted to know what's reasonable for implementing file systems. Obviously, FAT12 is going to be very important. But, that's where the obviousness ends. I originally wanted to devise my own file system (that's one of the joys of writing an OS, I'd say), but after some thought I figured that since I'm so used to using Windows that implementing FAT32 and just using Windows to manage my disks between tests and boots might be much more reasonable. Should I go ahead and try and do that instead of wasting time trying to devise my own system and ending up writing utilities that would manage the virtual disk in a file or something?
Thanks for any help you guys can provide, and sorrry for the length of the message. I'm a little long winded sometimes. (Also, I'm sorry if this post really belonged in the OS Design / Theory forum, but my search seemed to favor posts like this in the development forum).
Edit: Added a few more questions to avoid double posting.
After lurking here for a while and doing a lot of research on my own, I've finally started off down the road of developing an OS. It's something that I've wanted to do for a few years now, and I think I finally have the work ethic and skills to have a decent shot at getting somewhere with it.
Following some tutorials I've found and using some of my own experience, I've managed to set up the tools and environment necessary to begin, and have gotten a very basic Hello World bootloader done. Now comes that dreaded moment: what next?
I decided immediately that I should plan out my operating system before I got very far at all into it, and so, I figured I'd ask some things here before I got hopelessly lost. I've done a good bit of research on my own, but I still have some questions on basic design that I think I need some advice with.
First and foremost, I suppose I should ask the question of whether or not I'm really ready for this (I've read the wiki article on it, but I'd like some reassurance). I have around 7 years of working with C++, and that's the language I intend to write my kernel in (yes, I understand the implications of writing a basic run time library for it), and I have a pretty good amount of experience with working with moderately complex projects like 3D game programming. But, there are two skills that I'm somewhat concerned about. First, while I do have experience with assembly languages, I've never written an OS hosted application with it (only for 3D games with first generation fragment / vertex programs). Next, I have no experience whatsoever with using multithreading. Since it seems to be a somewhat important part of an operating system / API, I'm worried I won't be able to satisfactorily learn the material while trying to do something as hard as writing an OS. Do you think it's reasonable that I can overcome my inexperience with ASM to learn it while writing those parts of my OS?
Next, I have a few questions on design of the OS itself. I tried to answer these sorts of questions myself, but most are a sort of philosophical take on the problem. First up, I guess I should explain what my goals for the OS are.
I want the OS to have the following features when I consider it "done enough":
Multitasking (what OS can't these days?)
Text only interface (no point getting bogged down with a GUI at this stage)
Very basic video API for applications (possibly text only)
Probably no sound
Support at least a wired ethernet network with TCP/IP
Support for at least one fixed disk filesystem
Single user
Little security
No overconcern for efficiency, just stability
As far as these design goals are, I'd like some input. First up is the question of a sound API. From what I gather, it seems to be possible to get sound on a hobby OS, but there doesn't seem to be any standard way of doing it without drivers (i.e. for video at the very least you can use direct text mode without support drivers). Is it too much of a hassel to expect sound?
One of the biggest reasons I wanted to write this OS was to be able to support a simple web server, and for that I'll need networking and TCP/IP. Obviously this is also possible, but is it completely impractical for my first OS attemp? I know it won't be easy, and to write the drivers I'll probably have to get a specific card with known hardware, but I'm willing to try.
As far as 64/32 bit goes, is there any reason to not go 64-bit? I've seen some things about it not supporting hardware multitasking, but I assume that most modern OSes use software multitasking, correct? Are most of the examples that I've seen for 32-bit OSes going to work in 64-bit? (Barring certain ASM things like address lengths and certain instructions, of course).
Possibly pointless, but I was also wondering a bit about the traditional ring0 - ring3 protection scheme of most OSes. Is there any tangible benefit to, say, make drivers run in ring1? As far as I can tell, it wouldn't be terribly different than running then in ring3 (micro kernel?). Should I just stick to the monolithic ring0 - ring3 convention?
One other big question nagging me is the support for SMP / multithreading. I seriously doubt that I will end up porting any known application or STL to my OS, so I honestly don't know if multithreading will be necessary, since I'll be doing all of the programming and I don't know how anyway. Is this ridiculous? Obviously multiple processes is going to be present, but with only a single thread. As far as SMP goes, I'd love to take advantage of multiple cores or processors, but I haven't found much in the way of examples of using SMP in an OS. I found the manual from Intel, but it's so heavy in hardware design and related stuff that it can't possibly hope to answer the question of whether or not it's reasonable for me to try and implement it.
Also, how practical is it to implement basic USB functionality? I know that some things like this are proprietary (PCI spec is, isn't it?). Basically, the only important things would probably be basic USB support and a standardized driver for Mass Storage Devices. USB keyboards / mice are emulated in the BIOS, right? I forgot to look into this earlier, I'll try to remember to do so later.
Lastly, I wanted to know what's reasonable for implementing file systems. Obviously, FAT12 is going to be very important. But, that's where the obviousness ends. I originally wanted to devise my own file system (that's one of the joys of writing an OS, I'd say), but after some thought I figured that since I'm so used to using Windows that implementing FAT32 and just using Windows to manage my disks between tests and boots might be much more reasonable. Should I go ahead and try and do that instead of wasting time trying to devise my own system and ending up writing utilities that would manage the virtual disk in a file or something?
Thanks for any help you guys can provide, and sorrry for the length of the message. I'm a little long winded sometimes. (Also, I'm sorry if this post really belonged in the OS Design / Theory forum, but my search seemed to favor posts like this in the development forum).
Edit: Added a few more questions to avoid double posting.