d/b bit of GDT entry

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
OSNewbie

d/b bit of GDT entry

Post by OSNewbie »

ok, the d/b bit of a GDT entry controls whether the code segment is a 16 or 32 bit code segment right? well what does the d/b bit do for a read/write data segment? i am setting up a data segment and do not know what to set this bit to.

thanks
Brill

RE:d/b bit of GDT entry

Post by Brill »

I can't tell you want it means for a data descriptor. But i it should be set. :)
Anton

RE:d/b bit of GDT entry

Post by Anton »

The d/b bit does the same thing for the data segment as for code segment:
If you would read who asm is encoded in to bytes, then you will notice that there is such thin as a default arg size, which means if you have a 16-bit data seg, then your default args are ax,bx,... and al,ah,... . To use a eax in 16-bit data code, you would need to put a prefix overide(1 byte). If you are in 32-bit data seg, then the same insruction(in bytes) will mean eax,ebx,... and al,ah,... .
So thats way you need to tell the compiler the data seg you are using.
If you wrote :
mov ax,bx in 16 bit, then running this code on a 32-bit data seg will mean mox eax,ebx and vice-versa.
Anton
OSNewbie

RE:d/b bit of GDT entry

Post by OSNewbie »

OK, can you answer this than? if i set up a gdt entry to a read/write data segment and load the ds with that selector then execute a

mov dword [ds:00], 35
or
mov al, [ds:5] statement, will a different d/b bit setting in the gdt entry affect what happens when statements like this are executed? i am only using that segment for data, not code, so does it affect how i read/write stuff to the segment?

thanks
Chris Giese

RE:d/b bit of GDT entry

Post by Chris Giese »

CS -> descriptor with d/b=1 means USE32/BITS32 code segment
CS -> descriptor with d/b=0 means USE16/BITS16 code segment

SS -> descriptor with d/b=1 means stack is 32 bits wide
SS -> descriptor with d/b=0 means stack is 16 bits wide

I don't think the d/b value matters for the descriptor referenced by DS.

To be on the safe side, just set d/b=1 for all the 32-bit descriptors, if you are making a 32-bit OS.
OSNewbie

RE:d/b bit of GDT entry

Post by OSNewbie »

ok, that makes sense. so when you say the stack is 32 bits wide, what exactly does that mean? can i only push/pop eax, etc... (32 bit values) or can i still push/pop ax, bx... (16 bit values) ??? or does that refer to something besides pushing/popping values?

thanks in advance
Brill

RE:d/b bit of GDT entry

Post by Brill »

you can still push 16bits values yes.
Anton

RE:d/b bit of GDT entry

Post by Anton »

No, it only matters when you use ax or eax not al.
Anton.
Post Reply