Newer
Older
ubix / src / sys / include / ubixos / gdt.h
@reddawg reddawg on 4 May 2002 2 KB Woot Woot Libc
/**************************************************************************************
 Copyright (c) 2002
      The UbixOS Project

 $Id$
**************************************************************************************/

#ifndef _GDT_H
#define _GDT_H

/* Descriptor Definitions */
#define dCall 0x0C00 /* 386 Call Gate                */
#define dCode 0x1800 /* Code Segment                 */
#define dData 0x1000 /* Data Segment                 */
#define dInt  0x0E00 /* 386 Interrupt Gate           */
#define dLdt  0x200  /* Local Descriptor Table (LDT) */
#define dTask 0x500  /* Task gate                    */
#define dTrap 0x0F00 /* 386 Trap Gate                */
#define dTss  0x900  /* Task State Segment (TSS)     */

/* Descriptor Options */
#define dDpl3     0x6000 /* DPL3 or mask for DPL             */
#define dDpl2     0x4000 /* DPL2 or mask for DPL             */
#define dDpl1     0x2000 /* DPL1 or mask for DPL             */
#define dPresent  0x8000 /* Present                          */
#define dNpresent 0x8000 /* Not Present                      */
#define dAcc      0x100  /* Accessed (Data or Code)          */
#define dWrite    0x200  /* Writable (Data segments only)    */
#define dRead     0x200  /* Readable (Code segments only)    */
#define dBusy     0xB00  /* Busy (TSS only)    was 200       */
#define dEexdown  0x400  /* Expand down (Data segments only) */
#define dConform  0x400  /* Conforming (Code segments only)  */
#define dBig      0x40   /* Default to 32 bit mode           */
#define dBiglim   0x80   /* Limit is in 4K units             */

/* GDT Descriptor */
struct gdtDescriptor {
  unsigned short limitLow;      /* Limit 0..15    */
  unsigned short baseLow;       /* Base  0..15    */
  unsigned char  baseMed;       /* Base  16..23   */
  unsigned char  access;        /* Access Byte    */
  unsigned int   limitHigh:4;   /* Limit 16..19   */
  unsigned int   granularity:4; /* Granularity    */
  unsigned char  baseHigh;      /* Base 24..31    */
  } __attribute__ ((packed));

struct gdtGate {
  unsigned short offsetLow;  /* Offset 0..15  */
  unsigned short selector;   /* Selector      */
  unsigned short access;     /* Access Flags  */
  unsigned short offsetHigh; /* Offset 16..31 */
  } __attribute__ ((packed));

union descriptorTableunion {
  struct gdtDescriptor descriptor; /* Normal descriptor */
  struct gdtGate gate;             /* Gate descriptor   */
  unsigned long dummy;             /* Any other info    */
  };


#define descriptorTable(name,length) union descriptorTableunion name[length] =
#define standardDescriptor(base, limit, control) {descriptor: {(limit & 0xffff), (base & 0xffff), ((base >> 16) & 0xff), \
                                               ((control+dPresent) >> 8), (limit >> 16), \
                                               ((control & 0xff) >> 4), (base >> 24)}}
#define gateDescriptor(offset, selector, control) {gate: {(offset & 0xffff), selector, \
                                                     (control+dPresent), (offset >> 16) }}

#endif