Random Questions

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
wererabit
Posts:30
Joined:Wed Sep 03, 2008 2:50 am
Random Questions

Post by wererabit » Tue Mar 31, 2009 7:46 am

hi guys,

Can you help me out with this?

Code: Select all

    mov ax, 0x10                            ; set data segments to data selector (0x10)
    mov ds, ax
    mov ss, ax
    mov es, ax
    mov esp, 0x90000 


This is taken from tutorial 11 (Kernel file). I have been using it for a while now and I have taken it for granted. My question is

I understand that we are now in 32 bit protected mode and we need to point the data segment to the data selector which has index of 16 (0x10). But what exactly mov ax, 0x10 means, I mean after this mov ax, 0x10 get executed, everytime we refer to the data segment, what address in the memory we are looking at?

And is there any special reason for setting the stack pointer to 0x90000?

I hope I explain my question alright! Its kind of vague to me though.

Thanks in advance

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: Random Questions

Post by Andyhhp » Tue Mar 31, 2009 11:28 am

This is a bit of code used to switch between Real Mode (16bit) and Protected Mode (32bit)

Prior to this bit of code, you will have set up the GDT with entries describing areas of memory. By default, two descripters are created, one for code and one for data, both spanning the entire 4GB memory range.

In protected mode, the segment registers give an index into the GDT, instead of an absolute memory address.

The purpose of the code you provided is to tell all the segment registers to use the 2nd entry in the GDT - the entry relating to data sections. The reason that 0x10 is the 2nd entry is because the first bits are flags maintained by the CPU. Therefore, the indexs start from the 4th bit, making 0x10 the value of 2 when ignoring the flags.

The reason there is 'mov ax,0x10' is that the segment registers cant be loaded directly from values. 'mov ds,0x10' is invalid and wont work.

There is nothing special about having the stack located at 0x90000 - its just out of the way there.

Hope this helps.

~Andrew
Image

wererabit
Posts:30
Joined:Wed Sep 03, 2008 2:50 am

Re: Random Questions

Post by wererabit » Tue Mar 31, 2009 8:50 pm

I understand otehr things, but this is what I was looking for
In protected mode, the segment registers give an index into the GDT, instead of an absolute memory address.
Thanks for helping out

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: Random Questions

Post by Andyhhp » Tue Mar 31, 2009 8:53 pm

Lol - sorry for excessive information :P
Image

Post Reply