35

I love to code, but I am currently only doing web development. I'd like to do something that will be unique and fun and very different from web programming.

Yeah, this might be a dumb question, but I think it would be really cool to build a really simple Operating System. So please do not say anything rude. I just want to know the following things:

*Where to start? *Resources *What language would I use?

I was thinking something simple like a cmd based

Kevin
  • 379
  • 1
  • 3
  • 4
  • 7
    You will write a LOT of code before you even begin to approach the point where you will be writing the actual console/"cmd" software. – Joe Dec 21 '10 at 18:18
  • 7
    thanks for down voting thats real helpful – Kevin Dec 21 '10 at 18:37
  • 12
    @Joe Oh but Joe, remember, programmers always think they are more capable then they are. the fun times are when, as a hobby project where you don't cause problems for your company, you discover that you can't actually do that, and understand just how much it actually takes to program something. I love those moments. When I step back and applaud the work of programers who came before me and have done better than I ever could. – Narcolapser Apr 25 '11 at 23:55
  • 5
    This is a very constructive question. – jyoungdev Jan 04 '13 at 17:09
  • This looks like enough to get you started on the implementation side: http://www.codeproject.com/Articles/15843/Building-your-own-operating-system. I think you (we) will want to understand more theory to start designing and implementing the rest. – jyoungdev Jan 04 '13 at 17:17
  • For some hello worlds: https://stackoverflow.com/questions/22054578/how-to-run-a-program-without-an-operating-system – Ciro Santilli OurBigBook.com Jun 21 '20 at 08:07

7 Answers7

21

The absolute "bible" on operating system design is and was Andrew Tanenbaum's Operating Systems Design and Implementation - the "Dragon" book :-)

alt text

There are plenty of other references, too, e.g. Developing Your Own 32-Bit Operating System.

Microsoft Research also has/had a project on creating an operating system in managed code (C#) called Singularity - that might provide some insights/papers etc.

Writing a complete OS is neither a trivial nor a quick task, though.....

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 3
    thank you for including a picture – Kevin Dec 21 '10 at 19:07
  • 3
    Good book recommendation. The Dragon book is "Compilers: Principles, Techniques, and Tools", by the way. I must be missing a joke... I guess the book is a monster of a read. – Jacob Dec 12 '11 at 02:50
9

Switching from webdev to backend will be quite frustrating.

First, choose a board/hardware/architecture - maybe even go with an OS simulator which you can run on your machine. Learn C and some assembly (intel, MIPS, ARM, coldfire/motorolla 68k) depending on which CPU architecture you are building your OS for.

I've have seen C++ packages which will allow you to make an OS in C++, then convert it automatically for you to assembly, but it is such a headache to get them to convert properly. I would not recommend them.

Before you start writing code, you should design your OS. Maybe even put your design decisions in a 50 page paper with some diagrams as well.

Some things to think about:

  • memory map (where exactly in memory do you load parts of your OS; where will it reside)
  • how your scheduler would work (process and/or thread aware, priorities). Perhaps a diagram with queues for different priorities; also a diagram for process states in different queues (Ready, blocked, waiting for msg, running, executing, interrupted, etc)
  • how to do interprocess communication (mailboxes, mutexes, atomicity, synchronous vs asynchronous communication, format of message envelopes {sender process id, receiver process id, message type, message})
  • how to handle kernel vs user modes
  • memory allocation algorithms - you will write your own malloc/free operator (how do you keep track when user allocates memory dynamically? will you use a buddy tree algo? linked list? stack? etc)
  • how to handle interrupts (also context switch goes in here - how will you save all registers and restore them: you have one stack you need to keep track of where you are on it)
  • standard processes: keyboard process, monitor output, timing,
  • how to add timing services
  • how to load user processes and run them
  • to add preemption or not
  • add hotkeys (useful to debug your OS esp. in case it freezes, you can add hot keys to inspect memory)
  • testing your OS

EDIT - URL update Developing Your Own 32-Bit Operating System is out of print but is available online: http://www.ipdatacorp.com/mmurtl/mmurtlv1.pdf

Adrian
  • 5,603
  • 8
  • 53
  • 85
5

Here are some links to get you started:

http://www.brokenthorn.com/Resources

http://wiki.osdev.org/Main_Page/

Your gonna need GCC and NASM. I think you can also use GASM.

Learn BIOS interrupts.

Also before you even start grab a bunch of standards such as: APIC A20 Gate PCI & PCIEx - Good luck trying to obtain one of those. Cost some change. Intel & AMD - Look at these, gives you a lot of information. VGA ATA & SATA etc... There are a lot.

Also grab emulators like: bochs and qemu

Understand how the computer works, that is, how it boots up.

There is a lot of information out there you just gotta do your research.

Good luck.

Matthew Beck
  • 339
  • 3
  • 10
4

Start by reading some operating system books - like Tanenbaums' Modern operating systems.

This should give you an understanding of what problems you need to solve in order to write an operating system.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Oded
  • 489,969
  • 99
  • 883
  • 1,009
2

I guess you better start exploring Andrew S. Tanenbaum's work.

Pradeep
  • 3,258
  • 1
  • 23
  • 36
2

There are quite some resources when you google for them, but I would encourage you not to take this step yet!

For writing an OS, even a simple one, you will need a good understanding of how your computer works at a low level, and you'll need at least C or C++ and preferably Assembly as well. Without these skills it will be a tedious and frustrating project. It is hard and challenging even for skilled C programmers.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
2

Writing an OS is hard. I recommend becoming a developer before becoming an OS developer. You will need to know C/C++ and assembly to make a basic operating system. you will need to think about how to make your OS, i.e. type of kernel, real mode or protected mode, memory maps, and many other things.

PersonMan
  • 21
  • 1