Hi, ASM fellows!

I'm stuck with a structure that includes a bitfield record. MASM doesn't seem to accept nesting of these. Here's the C structure that I want to translate into ASM:

typedef struct _X86_SELECTOR
  {
  union
    {
    struct
      {
      WORD wValue;      // packed value
      WORD wReserved;
      };
    struct
      {
      unsigned RPL  : 2; // requested privilege level
      unsigned TI    : 1; // table indicator: 0=gdt, 1=ldt
      unsigned Index  : 13; // index into descriptor table
      unsigned Reserved : 16;
      };
    };
  }
  X86_SELECTOR, *PX86_SELECTOR, **PPX86_SELECTOR;

I tried this:

X86_SELECTOR_RECORD RECORD      RPL:2,TI:1,Index:13,Rsrvd:16

X86_SELECTOR UNION
            X86_SELECTOR_RECORD <>
            STRUCT
              wValue WORD ? ;packed value
              wReserved WORD ?
            ENDS
X86_SELECTOR ENDS
PX86_SELECTOR equ X86_SELECTOR PTR
PPX86_SELECTOR equ PX86_SELECTOR PTR

but MASM recognizes only the fields .wValue & .wReserved.
If I tried to put the record's declaration inside the union, I got error messages.

If you encontered this limitation, just tell me. And if you know a workaround that's better!

Thanx in advance!

Lea
Posted on 2006-04-25 09:54:28 by leatherman
X86_SELECTOR_RECORD?  ? RECORD?  ?  ?  Rsrvd:16,Index:13,TI:1,RPL:2

X86_SELECTOR UNION

?  ?  X86_SELECTOR_RECORD <>
?  ? 
?  ?  STRUCT
?  ?  wValue WORD ??  ? ;packed value
?  ?  ?  ?  ?  ?  ?  ?  wReserved WORD ?
?  ?  ENDS
?  ? 
X86_SELECTOR ENDS

For example we have:
.data

xmp X86_SELECTOR <<11111111b,11001b,1,11b>>

This is how to work with xmp as a record:
mov eax,xmp
and eax,mask X86_SELECTOR_RECORD.RPL
Posted on 2006-04-25 15:17:44 by k3Eahn
Thanks, k3Eahn!

I effectively used the mask operand but I hadn't realized a record was just a template for a mask and not a real structure.

By the way,

and eax, mask RPL

works all right too, since records fields must be unique among all symbols (except structures fieldnames).



Posted on 2006-04-26 06:45:01 by leatherman