Help me how to do one small OS

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
nhon

Help me how to do one small OS

Post by nhon »

I don't know how write Operating system . Who may help me step by step??
Thanks alot
beyondsociety

Re:Help me how to do one small OS

Post by beyondsociety »

What programming language are you going to write it in?

If its C or C++ I can't really help you. If its assembly language then I suggest looking over all the posts on this forum for help.

I would learn the programming language you are using to the extent that you know alot. It will help you with writing your operating system. Get a good book on operating systems design and implementation.

Figure out what features you want to incorporate into your operating system and then go from there.

You could either start with writing a bootsector and then a kernel or you could use a bootloader and just work on the kernel. The choice is up to you.

Hope this helped!
Tim

Re:Help me how to do one small OS

Post by Tim »

Steps for writing an operating system:

1) Find all the information you can
2) Read the information
3) Write some code
4) Give up
5) Start again from scratch
6) Goto (1)
Warmaster199

Re:Help me how to do one small OS

Post by Warmaster199 »

The two MOST valuable site for O.S. developement are:
http://www.nondot.org/sabre/os
http://osdev.neopages.net/

To start building an O.S., you should have at least a semi-intermediate knowledge of Assembler. If you want to make it easier on yourself, a semi-intermediate knowledge of C is recommended.

To start(with ASM and C):
(1) (ASM) Write a bootsector to load your kernel. If you use GCC/LD, then you need this to open PMode as well.
(2) (ASM) Write a start-up stub that will set-up any processor registers, the stack, etc... and then do a "call _main"
(3) (C) Write a function called void main(void). It doesn't have to be int main() because we have nothing to return to :)
(4) (C) Write a putch(uchar c); and an int printf(uchar *, ...); and then in main, write printf("Hello world from SimpleOS!!!");
(5) Build it with GCC, assemble the assembler codes with NASM, and link it all with LD.
(6) Use Partcopy.exe to put the bootcode onto a floppy
ex: partcopy bootcode.bin 0 200 -f0 <enter>
(7) Use partcopy to put your kernel on the floppy drive
ex: partcopy kernel.bin 0 2000 -f0 200 <enter> will put an 8KByte kernel onto the floppy, starting at the second sector, OR you could drag the kernel onto the floppy if your bootcode can read FAT12 and find your kernel. If you do this, you will need an extra file to load PMode for your OS
(8) Put the floppy into your test PC and boot it up!

The 8 step Warmaster199 way of making a simple "Hello, world" Kernel...
Or you could go to http://osdev.neopages.net/ and download their "Hello, world" kernel as an example :)
Tim

Re:Help me how to do one small OS

Post by Tim »

Steps (1) and (2) in the above seem to take the most time for a lot of people, and they tend to never get past step (2). I recommend that you use GRUB instead, which will allow you to concentrate on writing your kernel.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Help me how to do one small OS

Post by Pype.Clicker »

agree with Tim. It extremely complicated to code a bootloader (because of restricted size and difficulty to debug) and even more complicated to code a protected-mode starter because of the high amount of architecture-specific features involved and the speed at which it can reboot your machine...

Better places to start with would be (imho) memory management, kprint, console, etc. code as well as the runtime support you need which can be developed in a unix environment and then cleanly ported to your OS environment (most often even without changing a single line of code).

Remember the loadlin.exe program that allows you to start your 32bit linux from a single DOS session: you can do that too and have in a first time your OS started as a regular DOS program. That's what i did and it surely made me win about 2 monthes of development time. try my Small Operating System if you're not happy with GRUB ;)
Tim

Re:Help me how to do one small OS

Post by Tim »

Not only is writing a boot sector difficult, even if you do learn how, you won't use the skills you've learned anywhere else. Writing a boot sector teaches you how to write bad file system code (because of the size limitation), how to use BIOS interrupt 13h (you'll use direct port I/O in your OS) and things like the A20 gate (which you don't need to touch once you're in protected mode).

I also started with a loader running as a DOS program. If you don't like GRUB, writing a DOS loader saves you a lot of time and effort, since you can use the normal DOS file functions to access your kernel.
Warmaster199

Re:Help me how to do one small OS

Post by Warmaster199 »

A kerenl loader based in DOS? I never heard of that one before... are you sure it won't kill DOS while you're loading the kernel?
- Just a thought
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Help me how to do one small OS

Post by Pype.Clicker »

Warmaster199 wrote: A kerenl loader based in DOS? I never heard of that one before... are you sure it won't kill DOS while you're loading the kernel?
- Just a thought
nope, it wont. i designed it for the sole purpose of speeding up OS development: except in very rare cases, the kernel will not overwrite any DOS regions and will install itself only in memory regions that are declared free by MS-DOS (including XMS memory if available). I've used it during one whole year. Its only real limitation is that your kernel must fit in 640K (for the loading) but once it is called, it can use as much memory as it wants.

All interrupts are also restored and any "severe" crash means a clean return to real mode where you can use all the debugging tools you want to understand what happenned by studying the memory content, etc.
Tim

Re:Help me how to do one small OS

Post by Tim »

When I did mine I didn't keep the aim of being able to return to DOS after loading, so I gave the kernel control of all memory. An interesting bug happens if you load the kernel into the extended memory that SMARTDRV has claimed. :)
Warmaster199

Re:Help me how to do one small OS

Post by Warmaster199 »

Interesting... I forgot the Windoz kernel is loaded from DOS... Maybe that's why it crashes so much compared to the WinNT kernel which is loaded directly and emulates the DOS console(correct??? tell me if wrong). Anyways, Windows is NOT an Operating system. It does not deserve that label(unless you say WinNT/XP). Windows 95/98/3.1 are all just shells that are running on top of DOS... basically a PMode version of MS-DOS 5.0's(or lower) DOSSHELL.EXE.

For a DOS loaded kernel, it could be an OK idea, except for copyright's by the big M$. When DOS 7.0 is loaded into High Memory, it uses only 40KBytes, total. Also, DOS 7.0 loads HIMEM.SYS automatically if it finds it... no need to put it in config.sys. 40KBytes used from the lower MByte, starting at HMA(High Memory Area), not bad, but I think I'll save that for my kernel.

As for the loadlin.exe, It could be a good idea, but then you should kill the DOS in memory and clear interrupts after the load(LINUX init does this) :)
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Help me how to do one small OS

Post by Pype.Clicker »

Warmaster199 wrote: Interesting... I forgot the Windoz kernel is loaded from DOS... Maybe that's why it crashes so much compared to the WinNT kernel which is loaded directly and emulates the DOS console(correct??? tell me if wrong). Anyways, Windows is NOT an Operating system. It does not deserve that label(unless you say WinNT/XP). Windows 95/98/3.1 are all just shells that are running on top of DOS... basically a PMode version of MS-DOS 5.0's(or lower) DOSSHELL.EXE.
The purpose here is for sure not to re-write Win3.11 which was a crap, but rahter to be booted by a development environment where you can return to (MS-DOS or FreeDOS) transparently. Your OS will never know where it was coming from. You just inform it that it can use memory regions [lobase..lotop] and [hibase..hitop] and give it two function pointers exit() and crash(). By doing things this way, you're able to return to realmode for diagnosis/code modifications/compilation/try again rather than being limited to a reboot or a blue screen.

Once my kernel has been mature enough, i only needed 2 weeks to develop a floppy-version of the loader and the kernel runs on both of them without any change... This is possible because absolutely NO dos-service is called within the kernel. Dos is only used to load kernel.bin in memory and to detect the amount of available memory, as well as BIOS is used to read sectors and perform memory detection on a classic bootsector.
Post Reply