Page 1 of 2

How do you really get started with OS development?

Posted: Mon May 31, 2010 3:41 pm
by Developer
Hi,

I've been reading the BrokenThorn Entertainment OS Dev Series,
but still I have different questions.

I know the BASICs for how a OS really WORKS.
However, I do NOT understand all the code implementation, I mean I know
programming that's not the problem but understand the entire code and
knowing really what is does and why the engineer is uing this CPU instruction
or why does he setup a Stack on this line etc.

Can anybody please I would be glad if somebody could explain!!

Thanks!

Re: How do you really get started with OS development?

Posted: Mon May 31, 2010 5:34 pm
by halofreak1990
I guess you want a more in-depth explanation of the functions used?
If so, tell us which function you'd like to know more about, and we'll try to explain it.
However, most functions are self explanatory; their name says it all, in most cases.

Assembly, and the code in the bootloaders is rather complicated.
I only know as much assembly as what's been covered so far in the OSDev series, so I won't be too much of help there.

But, in any case, feel free to ask pretty much anything.

Re: How do you really get started with OS development?

Posted: Thu Jun 03, 2010 4:16 pm
by ehenkes
If you want to start with OSDev you have to learn two things:
1) debugging
2) find and read "specs"

Otherwise you get lost and ask a lot of foolish questions. :mrgreen:

Re: How do you really get started with OS development?

Posted: Fri Jun 04, 2010 9:36 am
by Believer424
You can't learn debugging... Debugging is just a logical ability everyone should have.

"I'm getting a GPF, so let's trace it down and see where it is"

Insert infinite for loops at vital places until you can pin point the exact line of code that's causing the GPF.

Yeah, read the Intel manuals :)

Re: How do you really get started with OS development?

Posted: Fri Jun 04, 2010 8:28 pm
by Andyhhp
Not quite - debugging is not a skill everyone is born with.

On the other hand, after a few examples, anyone should be proficient.

~Andrew

Re: How do you really get started with OS development?

Posted: Sat Jun 05, 2010 6:16 pm
by Developer
halofreak1990 wrote:I guess you want a more in-depth explanation of the functions used?
If so, tell us which function you'd like to know more about, and we'll try to explain it.
However, most functions are self explanatory; their name says it all, in most cases.

Assembly, and the code in the bootloaders is rather complicated.
I only know as much assembly as what's been covered so far in the OSDev series, so I won't be too much of help there.

But, in any case, feel free to ask pretty much anything.
Hi again:
Sorry I left this thread for a while. However, now I am back once again.
Well I know programming and can write code. However, I really would
like to understand the ASM parts, I mean ASM can be pretty hard sometimes,
and sometimes you find Step-by-Step (SBS) tutorials that cover a lot and then
you see a line of code which matches another tutorial, however, in this line the
same code is described different, and therefore I end-up asking.

For instance what does the following code-snippet really do?
============================================================

msg db "Welcome to My Operating System!", 0

;***************************************
; Prints a string
; DS=>SI: 0 terminated string
;***************************************

Print:
lodsb
or al, al ; al=current character
jz PrintDone ; null terminator found
mov ah, 0eh ; get next character
int 10h
jmp Print
PrintDone:
ret

;*************************************************;
; Bootloader Entry Point
;*************************************************;

loader:

; Error Fix 1 ------------------------------------------

xor ax, ax ; Setup segments to insure they are 0. Remember that
mov ds, ax ; we have ORG 0x7c00. This means all addresses are based
mov es, ax ; from 0x7c00:0. Because the data segments are within the same
; code segment, null em.

mov si, msg
call Print

cli ; Clear all Interrupts
hlt ; halt the system

times 510 - ($-$$) db 0 ; We have to be 512 bytes. Clear the rest of the bytes with 0

dw 0xAA55 ; Boot Signiture

Above from: http://www.brokenthorn.com/Resources/OSDev4.html
============================================================

I would like to know more about the "lodsb" instruction the other instructions used here.

Thanks! :)

Re: How do you really get started with OS development?

Posted: Sat Jun 05, 2010 6:49 pm
by Andyhhp
The loadsb stands for Load String Byte.

It loads the byte in memory pointed to by ds:si into al, and increments or decrements si by 1 depending on the state of the direction flag.

As you can see, it does quite a bit. The direction flag is almost always set to forward. The instructions 'std' and 'cld' can be used to set or clear the instruction bit in the flags register.

As for the other instructions:

db means Declare Bytes which stores data at that point in the file. specifically, the data which represents "Welcome..." in binary.

or means the bitwise or of two values. in this case, its oring al with itself (so not changing the value) but setting the zero flag if al was 0 to start with.

jz means "Jump if zero" so in this case, jump to PrintDone if al was 0, or in other words when we hit the zero terminator at the end of the string.

i assume i dont have to explain the mov instruction.

int calls a bios interupt - this one is "print character to screen (int 0x10/0xe)". you just have to learn these numbers or consult Ralf Browns Interrupt List which is easy to find online.

jmp is an unconditional jump. this is what causes the looping round to print the next character.

ret means return and appears at the end of functions.

Other than that, everything else is commented.

does this make sence?

~Andrew

Re: How do you really get started with OS development?

Posted: Sun Jun 06, 2010 9:28 am
by Developer
Thanks Andrew.

That clears things out.
I might have some other questions as well.

I always have a problem to get the ISO to work.
I compile and link the asm file using nasm.exe however,
once I pack it into a *.iso and attach to a virtual machine
it just fails completely, and doesn't want to work. While
the samples for the series works with their own iso image.

How can I fix iso images that work??

Re: How do you really get started with OS development?

Posted: Sun Jun 06, 2010 9:31 am
by Andyhhp
how are you packing it into the iso?

it strictly needs to be the first block in the iso, not just a normal file in it

Re: How do you really get started with OS development?

Posted: Sun Jun 06, 2010 12:21 pm
by Developer
Andyhhp wrote:how are you packing it into the iso?

it strictly needs to be the first block in the iso, not just a normal file in it
I just open the PowerISO program and drag-and-drop the files into it, and then I
save it as ISO.

This maybe is the wrong direction...

Re: How do you really get started with OS development?

Posted: Sun Jun 06, 2010 12:26 pm
by Andyhhp
read http://www.brokenthorn.com/Resources/OSDev3.html

that explains how to do it

Re: How do you really get started with OS development?

Posted: Sun Jun 06, 2010 12:42 pm
by Developer
Andyhhp wrote:read http://www.brokenthorn.com/Resources/OSDev3.html

that explains how to do it
I have read that articles as I said I've been follow this series.

Re: How do you really get started with OS development?

Posted: Sun Jun 06, 2010 12:43 pm
by Developer
I might do something wrong when I perform it.
I am actually doing it under Windows XP since
I first used a Windows 7 machine but it didn't
work well. However, as I said it fails.

Re: How do you really get started with OS development?

Posted: Sun Jun 06, 2010 12:45 pm
by Andyhhp
if you have read that artical then you wont be having these problems. It explains how to use partcopy to set up the image correctly to boot

Re: How do you really get started with OS development?

Posted: Sun Jun 06, 2010 1:24 pm
by Developer
Andyhhp wrote:if you have read that artical then you wont be having these problems. It explains how to use partcopy to set up the image correctly to boot
I have read it. I did as it told to do. It worked fine with the
demos provided here, which I downloaded. However, it
didn't work fine with my boot.bin file.

Using nams like this:

nasm -f bin boot.asm -o boot.bin

I get the *.bin does NOT work perfectly when mount to the VM-floppy.