/* Must set code generation for byte alignment */

/* generic descriptor  - data, code, system, TSS */

typedef struct descriptor {
   unsigned int limit_lo;
   unsigned int base_lo;
   unsigned char base_mid;
   unsigned char type_dpl;
   unsigned char limit_hi;
   unsigned char base_hi; } descriptor;

/* call, task, interrupt, trap gate */

typedef struct gate {
   unsigned int offfset_lo;
   unsigned int selector;
   unsigned char count;
   unsigned chartype_dpl;
   unsigned int offset_hi; } gate;

/* this is layout for task state segment (TSS) */
/* the fill fields of structures are not used by the 80386 */
/* but must be there */

typedef struct tss {
   unsigned int back_link; /* selector for last task */
   unsigned int fill1;
   unsigned long esp0;     /* stack pointer privilege level 0 */
   unsigned long ss0;      /* stack segment privilege level 0 */
   unsigned int fill2;
   unsigned long esp1;     /* stack pointer privilege level 1 */
   unsigned long ss1;      /* stack segment privilege level 1 */
   unsigned int fill3;
   unsigned long esp2;     /* stack pointer privilege level 2 */
   unsigned long ss2;      /* stack segment privilege level 2 */
   unsigned int fill4;
   unsigned long cr3;      /* control register 3, page table  */
   unsigned long eip;      /* instruction pointer             */
   unsigned long eflags;
   unsigned long eax;
   unsigned long ecx;
   unsigned long edx;
   unsigned long ebx;
   unsigned long esp;
   unsigned long ebp;
   unsigned long esi;
   unsigned long edi;
   unsigned int es;
   unsigned int fill5;
   unsigned int cs;
   unsigned int fill6;
   unsigned int ss;
   unsigned int fill7;
   unsigned int ds;
   unsigned int fill8;
   unsigned int fs;
   unsigned int fill9;
   unsigned int gs;
   unsigned int filla;
   unsigned int ldt;
   unsigned int fillb;
   unsigned int tbit;       /* exception on task switch bit */
   unsigned int iomap; } tss;

#define TSS_SIZE             (sizeof(tss))
#define DESCRIPTOR_SIZE      (sizeof(descriptor))
#define GATE_SIZE            (sizeof(gate))
#define DPL(x)               ((x)<<5)
#define TYPE_CODE_DESCR      0x18
#define TYPE_DATA_DESCR      0x10
#define TYPE_TSS_DESCR       0x09
#define TYPE_CALL_GATE       0x0C
#define TYPE_TASK_GATE       0x05
#define TYPE_INTERRUPT_GATE  0x0E
#define TYPE_TRAP_GATE       0x0F
#define SEG_WRITABLE         0x02
#define SEG_READABLE         0x02
#define SEG_EXPAND_DOWN      0x04
#define SEG_CONFORMING       0x04
#define SEG_ACCESSED         0x01
#define SEG_TASK_BUSY_BIT    0x02
#define SEG_PRESENT_BIT      0x80
#define SEG_GRANULARITY_BIT  0x80
#define SEG_DEFAULT_BIT      0x40
#define SELECTOR_MASK        0xFFF8
