...

View Full Version : How to build an operating system



digitman
09-08-2008, 01:47 PM
Hi,
I want to build a lightweight operating system that will have these features:

- Storing, editing, and deleting data from hard disk
- Running only one application in the memory.
- Basic input/output features like mouse, keyboard, displaying on the monitor, etc.

What do I need to learn to be able to do this? What programming language is best? etc.

This is a learning project so I'm hoping to get serious answers.

liorean
09-08-2008, 03:21 PM
Some parts of it you need to write in assembly (boot loader at least, unless you just borrow an open source one). Most of the rest you can write in whichever compiled langauge you want to use.

You need to learn about file systems, direct hardware communication, writing rudimentary drivers for your hardware, how OSes deal with hardware and software interupts, and though your single running application doesn't make it strictly necessary you probably should at least think about ways to do memory management and process scheduling.

oracleguy
09-08-2008, 05:04 PM
Instead of writing drivers from scratch for everything which you will need to do, you might want to use an open source kernel as your base and then strip it down. Writing an OS for a system as complex as an x86-based machine (since there is just so much hardware compared to an embedded system) isn't a trivial task.

You'll need assembly and a higher level language, I would recommend C. I wouldn't use C++ for the lower level OS stuff; the reason C is preferable is the closer relation between your code and the generated assembly since you'll probably have to do some debugging at the instruction level.

Then you'll have to write the OS API for user programs. So all that stuff you normally get for free when writing programs, like being able to print to the screen and read from the keyboard will all have to be written.

What is your programming background?

ghell
09-10-2008, 02:59 PM
Your best bet would be to use an existing kernel. The Linux 2.4 kernel is pretty light weight, a lot lighter than 2.6. This would do some of the work for you but you would still need to learn a lot.

If you really wanted to make it from scratch, you could at least do it this way and use what you have learned to do it from scratch later.

TheDevil
04-24-2009, 02:11 AM
I personally want to build a marketable OS. Does anyone have any ideas on how I should do this?

#include

geofftop
05-14-2009, 10:07 AM
Ya your gonna need some assembly and I would use c for exactly the reason the above poster said. It far easier to deduce the machine code for the c code you write. I write compilers for a living so I know. For certain low level tasks c is the way to go. Plus the compilers for it are generally more stable as the language is simpler. Most designers of operating systems and compilers prefer c but c++ if you keep it simple should be fine.

This is not a trivial task. You will have to have a good knowledge of the cpu's your running on, I mean get the reference manuals for intel and amd and understand all the aspects of them. Besides that your going to need knowledge of a low level language. A few years later you may actually make something good. I'm not even thinking about drivers.

Still attempting to write a simple OS will be a rewarding experience and make you a way better coder!

Google "Toy Os" or write your own OS there are tutorials about simple OS basics there some good information there.

Be warned though attempting to develop a serious product is a complex task and if your serious it will probably take years to get a decent product. I'm just being honest tons of people start stuff like this realize what there getting into and give up. Just realize your undertaking a large difficult task before your dive in. And PS you better really really know pointers before you even attempt this

TheDevil
08-27-2009, 01:10 AM
I do understand what I am getting myself into. My purpose is to allow users to fully control all aspects of their computer while still being able to use their favorite programs. I also understand that this project will take a few years to complete. There is also the fact that there are only going to be two poeple (including me) working on this. and we're both beginners. But I do know that if I don't give up, good things will come.

oracleguy
08-27-2009, 01:33 AM
I do understand what I am getting myself into. My purpose is to allow users to fully control all aspects of their computer while still being able to use their favorite programs. I also understand that this project will take a few years to complete. There is also the fact that there are only going to be two poeple (including me) working on this. and we're both beginners. But I do know that if I don't give up, good things will come.

By "favorite programs" do you mean run Windows programs?

You might want to consider building your OS for some much simpler embedded computer system instead of an x86 machine. That way you can focus on learning and not have to deal with extremely complicated hardware.

Though if you are looking to build an OS that can run Windows programs, you should look at ReactOS.

TheDevil
08-29-2009, 12:42 AM
I want it to be able to do more than just run windows programms. I want it to be able to run programms from Mac and UNIX. You probably want to say that I'm a f^#&!=@ lunatic. well, don't. I know that it will be very complex. my estimite for the total LOC(lines of code) is going to be around 120 million. I have accepted it so don't try to put my down.

ghell
08-29-2009, 01:33 AM
Setting aside WINE entirely, didn't they already make that operating system? I think that's how BeOS started or something (a nix OS that could run PE not just ELF)

TheDevil
09-09-2009, 02:51 AM
uh, what?

oracleguy
09-09-2009, 02:59 AM
I want it to be able to do more than just run windows programms. I want it to be able to run programms from Mac and UNIX. You probably want to say that I'm a f^#&!=@ lunatic. well, don't. I know that it will be very complex. my estimite for the total LOC(lines of code) is going to be around 120 million. I have accepted it so don't try to put my down.

No need to be so defensive. Though I do find making an estimate on a project's size using LOC rather unrealistic.

What you are talking about is of course possible but before you even begin to think about user programs, you'll need to be able to have an OS that will initialize the hardware and have at least a console and support for non-volatile storage (like a hard drive). Plus a memory manager, virtual memory support, process and threading support. Once you have those base features in place, you can start to develop the API which will allow those types of programs to run.

TheDevil
09-12-2009, 12:47 AM
That is exactly what I've been thinking about. Good call. I've been working on building the kernel system, but I'm stuck on the directory system. Any ideas?

TheDevil
11-04-2010, 05:03 PM
I have found a kernel to work off of. I am using the Linux 2.6.36 kernel release. Note: You can get this at kernel.org.

CrzySdrs
11-05-2010, 01:59 AM
It's been about a year since you started this thread. How is your project coming along?

TheDevil
11-05-2010, 05:11 PM
Slowly. I now have a base for my OS. I'm using the linux kernel. So my OS is going to be a spin-off of linux. As for what I'm using to build it, Ubuntu Linux of course. Me and my friend are going into design stages today. If anyone has suggestions as for what they would want in an operating system, or any questions, please feel free to email me at firebug98@gmail.com.

bobleny
11-05-2010, 05:40 PM
What I want is basically Gentoo that can play any game built for windows without emulation and without all kinds of configuration issues...

I hate windows. As far as I am concerned the only thing windows does better than most Linux systems is games, and that is really not a plus to windows because it is the game developers that decided to write the games for windows instead of Linux.

The usability, the functionality, the stability, the scalability, the performance, the programs, the user interface, the customization, the eye candy, the "open scourceness," and the list goes on, is what makes systems like Fedora, Ubuntu, Gentoo, etc so popular.

I understand completely how you want to start from scratch, I'm the exact same way, but I can tell you this, those OSs didn't get the way that they are in just a couple of years. I highly recommend modifying an existing OS verses building one from the ground up. However, if you do build one from the ground, I look forward to seeing your accomplishments !

That's my two dollars (inflation), take it or leave it.

TheDevil
11-06-2010, 01:09 AM
Thank you for your support. I will continue to post as more work is done on the OS.

TheDevil
11-06-2010, 04:50 AM
one more update. I set up a SourceForge.net project for this OS. if you would like to contribute, go to http://stormlinux.sourceforge.net/ to post suggestions or to send in possible additions to the project.

TheDevil
11-09-2010, 06:41 PM
Thank you for the book. I managed to get it as a pdf online. It is currently stored on my flash drive. As I said before, if you have requests or suggestions for this operating system, feel free to post or e-mail me at firebug98@gmail.com.

TheDevil
11-11-2010, 05:21 AM
This is an idea I had. One major problem in computers is memory leaks. So I'm thinking of adding in a memory cleanup module into the kernel. What do you think?

bobleny
11-11-2010, 06:35 AM
I think it sounds good, but aren't memory leaks a result of programs that where written badly? How is your module supposed to fix a broken program?
Also, how do you know that particular program just isn't using a lot of memory?

I don't see why the kernel can't shutdown none system critical programs when the memory gets to a certain point, but I'm not sure you need the kernel to do that.

TheDevil
11-11-2010, 06:40 AM
A memory leak occurs when a badly written program exits without freeing the memory it was using. The purpose of this module is the following:

1. scan memory addresses to see if they are being used by the processor.
2.

a. if yes, leave alone.

b. if no, record memory address range.
3. (continuing from 2b.) take memory address range and force free the memory.

That about sums it up. this module pretty much acts as a garbage collector for memory.

bobleny
11-11-2010, 07:02 AM
Oh, I see.

I'm not a system developer, but that seems to me as though that should be a software application and not part of the kernel.

The kernel should stick strictly to the hardware. That is what a kernel is for, right? To deal manage the thousands of different types of hardware so the OS and it's programs don't have to care whether it is a memory chip made by Kingston, or Corsair, right?

I don't know though...

TheDevil
11-11-2010, 07:14 AM
Let me rephrase what I said. The module creates a function API for cleaning up memory. Once the module is loaded, a memory cleanup program uses the exported cleanup functions to free up memory. Am I making any sense whatsoever?

djh101
11-11-2010, 07:32 AM
Wow, a year and a half and you're still going at it. Impressive. And no, it's not making sense. I, personally, know very little outside of post-OS programming. But a year and a half ago, I think I couldn't do anything outside of HTML and basic actionscript [2].

oracleguy
11-11-2010, 07:34 AM
A memory leak occurs when a badly written program exits without freeing the memory it was using. The purpose of this module is the following:

1. scan memory addresses to see if they are being used by the processor.
2.

a. if yes, leave alone.

b. if no, record memory address range.
3. (continuing from 2b.) take memory address range and force free the memory.

That about sums it up. this module pretty much acts as a garbage collector for memory.
That type of memory leak doesn't happen in modern operating systems or more precisely any operating system that uses virtual memory. With virtual memory each process runs in its own memory space so the kernel always knows what memory was being used by the process. So when the process ends the kernel can always reclaim the memory. Since you are using the Linux kernel and it uses virtual memory, the feature you are describing is already there. And don't confuse virtual memory with swap space (also some times called swap file), while you can have swap space with virtual memory, swap space isn't a requirement of virtual memory.

That being said this isn't an excuse to be lazy or bad at freeing your memory when writing software. Memory leaks where the amount of memory the program uses grows without bound can still happen but once it exits (gracefully or not) the memory is reclaimed. And of course you should always try to be efficient in the amount of memory being used.

TheDevil
11-11-2010, 07:46 AM
But the biggest problem with the current linux kernel is, and I looked this up, is that the current version can't really differentiate between a positive or negative memory leak search result. that is what my module does. my module works alongside the OS to find if a specific memory address is associated to a specific program. if not, that memory is freed.

oracleguy
11-11-2010, 07:50 AM
But the biggest problem with the current linux kernel is, and I looked this up, is that the current version can't really differentiate between a positive or negative memory leak search result. that is what my module does. my module works alongside the OS to find if a specific memory address is associated to a specific program. if not, that memory is freed.
You said you looked this up, can you be specific where you learned of this limitation? And why you think that this is true? A URL or even the files(s) in the kernel source?

TheDevil
11-11-2010, 07:59 AM
the file is $(kernelDirectory)/mm/kmemleak.c
where $(kernelDirectory) is the directory that the kernel code is stored at. look in the main summary at the top of the file.
It says that there are false positives, and a general rule to live by(for me) is that where there can be false positives, there can be false negatives.

oracleguy
11-11-2010, 08:20 AM
From $(kernelDirectory)/Documentation/kmemleak.txt: (emphasis mine)


Kmemleak provides a way of detecting possible kernel memory leaks in a
way similar to a tracing garbage collector

That has nothing to do with user mode processes. The kernel most definitely has virtual memory and will always reclaim 100% of the memory used by a process when that process terminates.

That kmemleak.c file is part of the kernel hacking group of config options and would never be normally compiled as it is meant for the kernel developers. However if you are going to be modifying the kernel, it would be useful for you.


Usage
-----

CONFIG_DEBUG_KMEMLEAK in "Kernel hacking" has to be enabled. A kernel
thread scans the memory every 10 minutes (by default) and prints the
number of new unreferenced objects found.

I will say that is a cool feature for kernel developers and must be fairly new since it is not in 2.6.30, it is in 2.6.35 so it must have been added into the kernel tree in the last 10-12 months.

CrzySdrs
11-11-2010, 05:47 PM
OracleGuy is correct that all applications have their memory cleaned up after the application is terminated by the usage of virtual memory. The kernel, obviously lives outside of that and has no garbage collector (kmemleak sounds like a basic garbage collector). So if there is a leak in the kernel, it can be extremely hard to detect and would never be cleaned up barring the use of kmemleak which is only used when debugging.

TheDevil
11-11-2010, 11:45 PM
Okay. I understand the the virtual memory. But like you said, in kernel memory, there is no garbage collector. my new module will act as one.

CrzySdrs
11-11-2010, 11:58 PM
But it sounds like that is more or less a solved problem. Kmemleak is being used to debug and find memory that isn't cleaned up. Thus the programmers would (hopefully) find all their issues before they are place in the actual release kernel. The performance hit of running a garbage collector during normal operation of the kernel would outweigh the benefits (since the leaks should have already been resolved). Kernel development is not taken lightly, I am sure they run many different types of analysis to determine that leaks don't exist before the code is brought into the main codeline.

TheDevil
11-12-2010, 05:22 AM
Then what am I supposed to start with. A support driver for USB 3.0?!?

Tony M
11-18-2010, 03:10 AM
Hi,
What do I need to learn to be able to do this? What programming language is best? etc..

You can read the page at http://www.ehow.com/how_2297259_operating-system.html it had many resources about Your queries and also http://www.microsoft.com/whdc/driver/wdf/kmdf-build.mspx :thumbsup:

TheDevil
11-21-2010, 02:32 AM
I decided to start with working on writing the syscall modules for running windows programs.

TheDevil
11-23-2010, 03:27 AM
BTW, does anyone have any idea how to work with a cross compiler?

prasadjachak
09-06-2011, 03:18 AM
If you are building OS..Why dont u start community like chromium OS? Even i want to build OS. In this thread there are many guys wants to do the same. If you want this to make the setup for this i can do that.tell me at my email address prasadjachak@gmail.com..Let we all work together in this..

OSguru
01-04-2012, 05:55 AM
Any updates on this. To be honest, I registered for this forum just to see the progress on this. Which I am guessing is not anywhere near the 120 million LOC estimated...

Cole001
01-12-2012, 12:13 PM
Hello,

Really? This is a big question to ask. I suggest you learn C until you get pretty advanced at it. Then I recommend you look up Linux From Scratch to give you a good idea of how linux works. Then you can maybe create an OS based on Linux. Also look into the source code of Open Solaris, I don't know if that's based on Linux or not.

Just remember this is going to take a LONG TIME to do. I mean after a few years of learning. And then probably a few more years of coding.
I think you should also learn Assembly.

I hope you will do this one.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum