Page 1 of 1

Segment descriptor and endianness

Posted: Fri Oct 03, 2014 9:51 pm
by HyperAssembler
Hi guys!
I'm trying to write functions that set up gdt in c.
My definition of segment descriptor is:

Code: Select all

typedef struct
{
    uint16 limit_low;
    uint16 base_low;
    uint8 base_middle;
    uint8 access;
    uint8 limit_mid_flag;
    uint8 base_high;
} gdt_descriptor;
My problem is about the first uint16 field.
I know 80386 is little-endian. So when writing a 16-bit value to mem(let's say 0x1234), the actual data in ram would be

Code: Select all

Addr Data
0x0 0x34
0x1 0x12
Suppose I have a limit of 0x123456, I assign 0x1234 to limit_low and if you look at the binary of bits 0-15 of segment descriptor, it should be

Code: Select all

Bit   Data
0-7   0x34 
8-15  0x12.
But intel seems to expect this:

Code: Select all

Bit   Data
0-7   0x12 
8-15  0x34.
I've seen fair amount of tutorials. Some of them do 0x12 0x34 and the others do 0x34 0x12.
So I'm confused here:
Should it be 0x12 0x34 or 0x34 0x12(little-endian form)?
Thanks!

Re: Segment descriptor and endianness

Posted: Fri Oct 03, 2014 10:10 pm
by Brendan
Hi,
HyperAssembler wrote:Should it be 0x12 0x34 or 0x34 0x12(little-endian form)?
Um, what?

The lowest 16-bits of 0x123456 would be 0x3456 (not 0x1234); which would be stored in little-endian as the bytes 0x56, 0x34.


Cheers,

Brendan