Why 0x10?

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
The Legend

Why 0x10?

Post by The Legend »

This codepiece is taken from GazOS:

"lgdtl (loadgdt) \n" /* Load our own GDT */
"movw $0x10,%%ax \n" /* Init data registers with flat_data */
"movw %%ax,%%ds \n"
"movw %%ax,%%es \n"
"movw %%ax,%%fs \n"
"movw %%ax,%%gs \n"
"movw %%ax,%%ss \n" /* ... and the stack, too */

I don't understand what 0x10 means here, the GDT
has only three entries ...

Thanks in advance,
The Legend
Gertfaller

RE:Why 0x10?

Post by Gertfaller »

>On 2002-04-14 07:45:08, The Legend wrote:
>This codepiece is taken from GazOS:
>
>"lgdtl (loadgdt) \n" /* Load our own GDT */
>"movw $0x10,%%ax \n" /* Init data registers with flat_data */
>"movw %%ax,%%ds \n"
>"movw %%ax,%%es \n"
>"movw %%ax,%%fs \n"
>"movw %%ax,%%gs \n"
>"movw %%ax,%%ss \n" /* ... and the stack, too */
>
>I don't understand what 0x10 means here, the GDT
>has only three entries ...
>
>Thanks in advance,
>The Legend

Each entry is 8 bytes long so :
offset 0x00 in GTD : null descriptor
offset 0x08 in GTD : code segment
offset 0x10( = 16 decimal) in GTD : data segment
The Legend

RE:Why 0x10?

Post by The Legend »

>On 2002-04-14 08:04:18, Gertfaller wrote:
>>On 2002-04-14 07:45:08, The Legend wrote:
>>This codepiece is taken from GazOS:
>>
>>"lgdtl (loadgdt) \n" /* Load our own GDT */
>>"movw $0x10,%%ax \n" /* Init data registers with flat_data */
>>"movw %%ax,%%ds \n"
>>"movw %%ax,%%es \n"
>>"movw %%ax,%%fs \n"
>>"movw %%ax,%%gs \n"
>>"movw %%ax,%%ss \n" /* ... and the stack, too */
>>
>>I don't understand what 0x10 means here, the GDT
>>has only three entries ...
>>
>>Thanks in advance,
>>The Legend
>
>Each entry is 8 bytes long so :
>offset 0x00 in GTD : null descriptor
>offset 0x08 in GTD : code segment
>offset 0x10( = 16 decimal) in GTD : data segment

Oh, thanks
The Legend

RE:Why 0x10? (another small question)

Post by The Legend »

>On 2002-04-14 08:04:18, Gertfaller wrote:
>>On 2002-04-14 07:45:08, The Legend wrote:
>>This codepiece is taken from GazOS:
>>
>>"lgdtl (loadgdt) \n" /* Load our own GDT */
>>"movw $0x10,%%ax \n" /* Init data registers with flat_data */
>>"movw %%ax,%%ds \n"
>>"movw %%ax,%%es \n"
>>"movw %%ax,%%fs \n"
>>"movw %%ax,%%gs \n"
>>"movw %%ax,%%ss \n" /* ... and the stack, too */
>>
>>I don't understand what 0x10 means here, the GDT
>>has only three entries ...
>>
>>Thanks in advance,
>>The Legend
>
>Each entry is 8 bytes long so :
>offset 0x00 in GTD : null descriptor
>offset 0x08 in GTD : code segment
>offset 0x10( = 16 decimal) in GTD : data segment
And why doesn't this code piece load a value for cs (0x8 then)?

The Legend
GertFaller

RE:Why 0x10? (another small question)

Post by GertFaller »

>On 2002-04-14 10:41:13, The Legend wrote:
>>On 2002-04-14 08:04:18, Gertfaller wrote:
>>>On 2002-04-14 07:45:08, The Legend wrote:
>>>This codepiece is taken from GazOS:
>>>
>>>"lgdtl (loadgdt) \n" /* Load our own GDT */
>>>"movw $0x10,%%ax \n" /* Init data registers with flat_data */
>>>"movw %%ax,%%ds \n"
>>>"movw %%ax,%%es \n"
>>>"movw %%ax,%%fs \n"
>>>"movw %%ax,%%gs \n"
>>>"movw %%ax,%%ss \n" /* ... and the stack, too */
>>>
>>>I don't understand what 0x10 means here, the GDT
>>>has only three entries ...
>>>
>>>Thanks in advance,
>>>The Legend
>>
>>Each entry is 8 bytes long so :
>>offset 0x00 in GTD : null descriptor
>>offset 0x08 in GTD : code segment
>>offset 0x10( = 16 decimal) in GTD : data segment
>And why doesn't this code piece load a value for cs (0x8 then)?
>
>The Legend
cs can't de loaded directly.
It is loaded when you jump to the code
to be executed.
Here it's with :

"ljmp $0x08,$next\n"
"nop\n"
"nop\n"
"next: \n" /* Continue here

then cs points to the code segment.
The Legend

RE:Why 0x10? (another small question)

Post by The Legend »

>On 2002-04-14 17:33:05, GertFaller wrote:
>>On 2002-04-14 10:41:13, The Legend wrote:
>>>On 2002-04-14 08:04:18, Gertfaller wrote:
>>>>On 2002-04-14 07:45:08, The Legend wrote:
>>>>This codepiece is taken from GazOS:
>>>>
>>>>"lgdtl (loadgdt) \n" /* Load our own GDT */
>>>>"movw $0x10,%%ax \n" /* Init data registers with flat_data */
>>>>"movw %%ax,%%ds \n"
>>>>"movw %%ax,%%es \n"
>>>>"movw %%ax,%%fs \n"
>>>>"movw %%ax,%%gs \n"
>>>>"movw %%ax,%%ss \n" /* ... and the stack, too */
>>>>
>>>>I don't understand what 0x10 means here, the GDT
>>>>has only three entries ...
>>>>
>>>>Thanks in advance,
>>>>The Legend
>>>
>>>Each entry is 8 bytes long so :
>>>offset 0x00 in GTD : null descriptor
>>>offset 0x08 in GTD : code segment
>>>offset 0x10( = 16 decimal) in GTD : data segment
>>And why doesn't this code piece load a value for cs (0x8 then)?
>>
>>The Legend
>cs can't de loaded directly.
>It is loaded when you jump to the code
>to be executed.
>Here it's with :
>
> "ljmp $0x08,$next\n"
> "nop\n"
> "nop\n"
> "next: \n" /* Continue here
>
>then cs points to the code segment.
>
Okay, thank you!

The Legend
Post Reply