Create an operating system

This is a discussion on Create an operating system within the Tech Board forums, part of the Community Boards category; I know it's an extremely large goal and will probably never happen but I would like to try. I would ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    25

    Create an operating system

    I know it's an extremely large goal and will probably never happen but I would like to try. I would like to create my own operating system. I have already reaserched and planed everything. I just need to write the code, but I don't know where to begin. I have already read all the beggining tutorials and i'm looking for the next step. Any help at all will be much appreciated.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    What tutorials / resources have you read so far?

    Bootstrap and simple console I/O would seem to be a good start.
    Then perhaps a simple task switcher.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    25
    I've read the c++ tutorialls on this site. I have also wrote little practice programs and i believe that I understand the conscepts very well.

    What is Bootstrap?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Jun 2007
    Posts
    25
    I already understand the booting process and I know how I can make my system run as the primary system. The problem arises when I actually attempt to code the system. I don't know how I should begin.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Jun 2007
    Posts
    25
    I'm already examining that site.

  8. #8
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by histevenk View Post
    What is Bootstrap?
    You have a long way to go grasshopper.

    Bootstrap is the term for when the computer boots up its executes a specific piece of code found in sector 0 of the hard disk. This code then loads the rest of the OS using whatever filesystem it uses.

    The term derives from the phrase 'Lifting your self up by your own bootstraps'.

    A simple DOS-like bootloader is fairly easy to implement, just remember you have to wrap everything necessary to load the OS into 512 bytes, probably in assembly. Another good although very old reference is Ralph Brown's Interupts. I have a copy of it in storage, Ill have to post the ISBN sometime. I think you can find an online version of it around in a few places.

    If you arent familiar with assembly, you probably should also check out several books on assembly language programmign fro 16 and 32 bit processors. If you want to write a 32 bit OS then you need to learn how to switch into protected mode from real mode. All Intel compatible computers boot up in real mode. Real mode is probably easier to write your first OS in, protected mode has a lot more complex behavior to take into account, such as paging tables and protection levels.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    One way to avoid some of the tricky stuff with booting the system is to boot DOS on the system, load the OS code with a small DOS program, and then start your OS.

    That way, you don't have to worry about boot-loading.

    Once you have something that can load a binary file, you then have the task of "taking control of the processor".

    In x86, that consists of:
    Code:
    1. Get into 32-bit protected mode, 
       a) set up a GDT (Global Descriptor Table) with one code-segment (CS) and one data-segment (DS). 
       b) set CR0.PE (bit 0) to one. 
       c) jump a far-jump using the index of the CS. 
       d) set DS, ES, SS, FS, GS to the datasegment.
    2. Set up a protected mode vector table (Interrupt Descriptor Table, IDT). 
    3. Set up the interrupt controller (8259 or APIC) to use vectors 0x20 and up [you may choose other vector numbers, but I don't know of a good reason for that]. 
    4. Configure a timer device (e.g. the 8254 or a High Res Timer). Set the corresponding interrupt up and enable interrupts.
    Most of the above CAN be written in C, but you really need to know what you are doing. If not, it's probably easier to do in assembler.

    Now you are ready to actually start writing task-switching code, etc.

    By the way, another way to get the system started without writing your own boot-loader would be to use GRUB and write your code as "grub modules", which isn't very hard if you have access to GNU tools.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    I'd rather hijack grub or lilo as the boot loader.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #11
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    I'd rather hijack another OS

    eg Heavily modify Linux, or Plan9 or something... sure starting from scratch is a good learning experiment, but it's kinda pointless unless there's a reason for it.

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by zacs7 View Post
    I'd rather hijack another OS

    eg Heavily modify Linux, or Plan9 or something... sure starting from scratch is a good learning experiment, but it's kinda pointless unless there's a reason for it.
    That's like learning to design a car by taking a Ferrari apart - it's probably better to start with a VW Beetle [the old model], as it's a much easier design.

    Have you actually looked at the Linux source code enough to understand what it does? It is fairly complex, even for rather simple matters - because it has to be flexible enough to run on 17 different processor architectures, each with several flavours of implementations, etc, etc. So there are 5 different files just to implement some simple mechanism (say timekeeping), which if you have a more dedicated approach can be done in one or two files [not counting header-files].

    If you want to learn how an OS works, then writing a simple OS is a good way to learn.

    Obviously, it gets fairly tricky after some time, for example file-systems can be rather complex [and important to get right], memory management with virtual memory is another "interesting" aspect.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #13
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Sorry matsp, I haven't looked at the entire source - other than a little dadd'ling with the kernel.

    Sorry if I was a fool, but starting fresh seems like a lot of work - surely there is another way?

  14. #14
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Well, you could look at Minix. I heard it's written in a way that is easy to understand.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by zacs7 View Post
    Sorry matsp, I haven't looked at the entire source - other than a little dadd'ling with the kernel.

    Sorry if I was a fool, but starting fresh seems like a lot of work - surely there is another way?
    Not to worry. A lot of people think that the Linux kernel is easy to understand (and modify), when in reality it is very complex. It was a lot easier just a few years back, but even the 2.2 kernel is fairly complex. The 1.0 kernel may be a better choice - but then it's still a BIG kernel even there.

    Minix as CornedBee suggests is one option to start with, because, as stated, it is written to be understandable, rather than the Linux kernel, which is written to support lots of options and being efficient at that.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using an operating system command in c
    By clearrtc in forum C Programming
    Replies: 2
    Last Post: 05-21-2006, 05:26 PM
  2. Floppy Operating System
    By eam in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 10-09-2004, 08:40 AM
  3. Operating system
    By sopranosomega in forum C Programming
    Replies: 6
    Last Post: 10-07-2002, 07:12 AM
  4. idea: operating system
    By roberth9000 in forum Contests Board
    Replies: 6
    Last Post: 09-16-2002, 07:08 AM
  5. What operating system are YOU useing?
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 36
    Last Post: 09-14-2002, 11:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21