What do I need to build an operating system

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.
User avatar
kenneth_phough
Member
Member
Posts: 106
Joined: Sun Sep 18, 2005 11:00 pm
Location: Williamstown, MA; Worcester, MA; Yokohama, Japan
Contact:

What do I need to build an operating system

Post by kenneth_phough »

I've never coded an OS before and OS developement has always been my dream. All I know is that I need a assembler and a linker but I'm not sure what kind and also if that is all I need to build an OS. I bought a book on OS developement but the Author created his own compiler and linker which I can't do. I also bought a book on assembly for beginers and it had a page on how to create a boot sector but it only worked for Bosch and it didn't work when I copied it on to a floppy and booted it. Would it also be possible to code a whole OS (even the boot sector and the kernel) with C++?
P.S. I'm a intermediate programmer (not a professional)
AltCtrlDel
Member
Member
Posts: 25
Joined: Sat Jun 25, 2005 11:00 pm

Re: What do I need to build an operating system

Post by AltCtrlDel »

ok..
first of all you have to understand the architecture, if you are going to work on x86 try the intel documentation
http://www.intel.com/design/pentium4/ma ... ex_new.htm

spend some reasonable time enhancing your skills in assembly .. assembly language concepts are importrant in developing the device drivers and the core kernel functionality
when your OS grows larger you will have to code in C to save time and programming effort; so learn how to mix assembly and C

there are several choices there :
many people use the GCC compiler and the NASM assembler
for me, i used to work with Borland C and TASM32 with TLINK32

read many open source kernels .. they are everywhere on the internet .. always choose the small and simple ones so that it could be easy for you to learn from them

try
http://www.osdever.net/
it is nice for beginners

concerning your problem with boot sectors:
i think that having it working on Bochs means it is correct .. usually your problem is in writing the boot sector onto the floppy .. perhaps you didn't do it the right way

writing every thing in C++ ? i don't know if it is possible or not. but anyway, even if it is possible, i don't think it will be a good idea .. i think some code MUST be written in ASM .. this is a personal opinion that may be right or wrong
User avatar
matthias
Member
Member
Posts: 158
Joined: Fri Oct 22, 2004 11:00 pm
Location: Vlaardingen, Holland
Contact:

Re: What do I need to build an operating system

Post by matthias »

AltCtrlDel wrote: writing every thing in C++ ? i don't know if it is possible or not. but anyway, even if it is possible, i don't think it will be a good idea .. i think some code MUST be written in ASM .. this is a personal opinion that may be right or wrong
Yes it is possible to write you OS entirely in C++... But you'll also need some C and ASM code to support some C++ stuff.. I would recommend C because it's much simpler than C++ and C++ also has a major overhead which you don't want in your OS.. I'm not saying that C++ is a bad thing.. But for osdev it's not ok.. I've built a C++ kernel once.. But my experiences are that writing a kernel in C goes much faster than in C++. Though C++ has some advantages.. But not enough to convince me to use it ;)
The source of my problems is in the source.
User avatar
kenneth_phough
Member
Member
Posts: 106
Joined: Sun Sep 18, 2005 11:00 pm
Location: Williamstown, MA; Worcester, MA; Yokohama, Japan
Contact:

Re: What do I need to build an operating system

Post by kenneth_phough »

Thanks a lot guys.
This is going to help me a lot.
I'm already looking at the intel x86 documentations and studying ASM.

By the way, would is be possible to write a boot sector on to a floppy with MS-DOS on XP?
"Unless mankind redesigns itself by changing our DNA through altering our genetic makeup, computer-generated robots will take over our world" - Stephen Hawking
NatsuOS: 32-bit, multitasking, HFS+ Filesystem
Osbios
Member
Member
Posts: 116
Joined: Fri Jun 10, 2005 11:00 pm

Re: What do I need to build an operating system

Post by Osbios »

kenneth_phough wrote:By the way, would is be possible to write a boot sector on to a floppy with MS-DOS on XP?
No.

Use this: http://uranus.it.swin.edu.au/~jn/linux/rawwrite.htm
dw 0xAA55
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: What do I need to build an operating system

Post by bubach »

Yes.

You can use the command debug in cmd.exe
I think it is:

Code: Select all

A:\>debug bootsect.bin
-w 0 0 0 1
-q
A:\>_

That writes the data found at memory address 0 to disk 0, starting with sector 0 and writing 1 sector.
Be careful, if you type in the wrong things you might overwrite the hdd's bootsector or something.. :P
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
kenneth_phough
Member
Member
Posts: 106
Joined: Sun Sep 18, 2005 11:00 pm
Location: Williamstown, MA; Worcester, MA; Yokohama, Japan
Contact:

Re: What do I need to build an operating system

Post by kenneth_phough »

Thanks!
I'll try both.
"Unless mankind redesigns itself by changing our DNA through altering our genetic makeup, computer-generated robots will take over our world" - Stephen Hawking
NatsuOS: 32-bit, multitasking, HFS+ Filesystem
User avatar
kenneth_phough
Member
Member
Posts: 106
Joined: Sun Sep 18, 2005 11:00 pm
Location: Williamstown, MA; Worcester, MA; Yokohama, Japan
Contact:

Re: What do I need to build an operating system

Post by kenneth_phough »

I was trying to get my boot sector to work again and was reading how to code one. The following is a code that I got from a book which works with Bochs but still doesnt work when I boot it up. The bios says that it is missing something. I'm pretty sure I wrote the sector correctly but I might be wrong.

This is the boot loader:

org 0
section .text

jmp 07C0h:start

print:
lodsb
cmp al, 0
je printend
mov ah, 0Eh
mov bx, 7
int 10h
jmp print
printend:
ret

start:
mov ax, cs
mov ds, ax

mov si, startMsg
call print


fd_reset:
xor ax, ax
xor dx, dx
int 13h
jc fd_reset
mov si, resetMsg
call print

sec_load:
mov ax, 9000h
mov es, ax
mov ax, 0201h
xor bx, bx
mov cx, 0002h
xor dx, dx
int 13h
jc sec_load_err
jmp sec_load_ok

sec_load_err:
mov si, sloadMsgErr
call print
jmp _wait_loop

sec_load_ok:
mov si, sloadMsg
call print

goto_next:
jmp 9000h:0h

_wait_loop:
jmp _wait_loop


section .data
startMsg db 'booting...', 0x0D, 0x0A, 0x00
resetMsg db 'reset complete', 0x0D, 0x0A, 0x00
sloadMsg db 'sector loaded', 0x0D, 0x0A, 0x00
sloadMsgErr db 'sector loading...failed', 0x0D, 0x0A, 0x00
"Unless mankind redesigns itself by changing our DNA through altering our genetic makeup, computer-generated robots will take over our world" - Stephen Hawking
NatsuOS: 32-bit, multitasking, HFS+ Filesystem
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: What do I need to build an operating system

Post by carbonBased »

The last word in a valid bootsector must be 0xAA55. You don't appear to have this coded into your bootsector.

--Jeff
User avatar
kenneth_phough
Member
Member
Posts: 106
Joined: Sun Sep 18, 2005 11:00 pm
Location: Williamstown, MA; Worcester, MA; Yokohama, Japan
Contact:

Re: What do I need to build an operating system

Post by kenneth_phough »

I put the 0xAA55 by using a binary editor which I know is a pain in the neck to do because you can actually write:

times 510-($-$$) db 0
dw 0xAA55

and it will do the same thing and it is easier.

But how do you actually load a kernel (or another file) with a boot sector?

For example if I wanted to use the boot sector to load a file that will print the letter A on to the string instead of putting the code for printing A in the boot sector?

--Kenneth

P.S. I think I need to practice writing the boot sector onto a floppy correctly, but for the time being I'll work with Bosch.
"Unless mankind redesigns itself by changing our DNA through altering our genetic makeup, computer-generated robots will take over our world" - Stephen Hawking
NatsuOS: 32-bit, multitasking, HFS+ Filesystem
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: What do I need to build an operating system

Post by earlz »

its bochs(bosch makes sparkplugs)
a tutorial i would very much reccommend you do is this
http://osdever.net/bkerndev/index.php?the_id=90
[edit]
and make sure to read it slow, be sure you completely understand it
you might need to read it a few times
[/edit]
that is a very good tutorial in my opinion but this was after writing a basic 16 bit os(if you switch to 32 bit you will really miss those interrupts) so i had a fairly good knowledge of things like asembly and some of the more simple c library routines

I would recommend that you start off learning 32 bit stuff(except for bootloader) cause trust me, unlearning those 16 bit practices can be a real headache and can mess up the way you think 32 bit stuff works

another thing
i use nasm and gcc(djgpp) and ld as linker; use to use turboc and tasm but they do not have gpl's and dont even come close(i had to make a lot of work arounds in turboc)
Last edited by earlz on Thu Sep 22, 2005 11:00 pm, edited 1 time in total.
User avatar
kenneth_phough
Member
Member
Posts: 106
Joined: Sun Sep 18, 2005 11:00 pm
Location: Williamstown, MA; Worcester, MA; Yokohama, Japan
Contact:

Re: What do I need to build an operating system

Post by kenneth_phough »

Where can I get gcc for windows and is there a ld for window and if so where can I get that too.

Thanks!
"Unless mankind redesigns itself by changing our DNA through altering our genetic makeup, computer-generated robots will take over our world" - Stephen Hawking
NatsuOS: 32-bit, multitasking, HFS+ Filesystem
User avatar
matthias
Member
Member
Posts: 158
Joined: Fri Oct 22, 2004 11:00 pm
Location: Vlaardingen, Holland
Contact:

Re: What do I need to build an operating system

Post by matthias »

The source of my problems is in the source.
User avatar
kenneth_phough
Member
Member
Posts: 106
Joined: Sun Sep 18, 2005 11:00 pm
Location: Williamstown, MA; Worcester, MA; Yokohama, Japan
Contact:

Re: What do I need to build an operating system

Post by kenneth_phough »

I'm using a Toshiba Dynabook with a Windows XP Home Edition on it.
I installed DJGPP and changed the environment variables on my computer so DJGPP will work but when ever I try to compile a kernel with the attribute "-I./include" it will tell me it can't find the include files which are in a folder called "include" with the kernel souce files. Would anyone know why this is happening? Thanks!

-Kenneth
"Unless mankind redesigns itself by changing our DNA through altering our genetic makeup, computer-generated robots will take over our world" - Stephen Hawking
NatsuOS: 32-bit, multitasking, HFS+ Filesystem
gmoney
Member
Member
Posts: 106
Joined: Mon Jan 03, 2005 12:00 am
Location: Texas, Usa

Re: What do I need to build an operating system

Post by gmoney »

dude get linux, u can compile an os without the hassle that windows put you through, plus linux is FREE
Just because your phone is "smart" doesn't mean the user is... ijs
Post Reply