# gdt.h

Go to the documentation of this file.

    00001 /*****************************************************************************************
    00002  Copyright (c) 2002-2004 The UbixOS Project
    00003  All rights reserved.
    00004
    00005  Redistribution and use in source and binary forms, with or without modification, are
    00006  permitted provided that the following conditions are met:
    00007
    00008  Redistributions of source code must retain the above copyright notice, this list of
    00009  conditions, the following disclaimer and the list of authors.  Redistributions in binary
    00010  form must reproduce the above copyright notice, this list of conditions, the following
    00011  disclaimer and the list of authors in the documentation and/or other materials provided
    00012  with the distribution. Neither the name of the UbixOS Project nor the names of its
    00013  contributors may be used to endorse or promote products derived from this software
    00014  without specific prior written permission.
    00015
    00016  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
    00017  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00018  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
    00019  THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00020  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
    00021  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    00022  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
    00023  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00024  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00025
    00026  $Id: gdt_8h-source.html 88 2016-01-12 00:11:29Z reddawg $
    00027
    00028 *****************************************************************************************/
    00029
    00030 #ifndef _GDT_H
    00031 #define _GDT_H
    00032
    00033 /* Descriptor Definitions */
    00034 #define dCall 0x0C00 /* 386 Call Gate                */
    00035 #define dCode 0x1800 /* Code Segment                 */
    00036 #define dData 0x1000 /* Data Segment                 */
    00037 #define dInt  0x0E00 /* 386 Interrupt Gate           */
    00038 #define dLdt  0x200  /* Local Descriptor Table (LDT) */
    00039 #define dTask 0x500  /* Task gate                    */
    00040 #define dTrap 0x0F00 /* 386 Trap Gate                */
    00041 #define dTss  0x900  /* Task State Segment (TSS)     */
    00042
    00043 /* Descriptor Options */
    00044 #define dDpl3     0x6000 /* DPL3 or mask for DPL             */
    00045 #define dDpl2     0x4000 /* DPL2 or mask for DPL             */
    00046 #define dDpl1     0x2000 /* DPL1 or mask for DPL             */
    00047 #define dDpl0     0x0000 /* DPL0 or mask for DPL             */
    00048 #define dPresent  0x8000 /* Present                          */
    00049 #define dNpresent 0x8000 /* Not Present                      */
    00050 #define dAcc      0x100  /* Accessed (Data or Code)          */
    00051 #define dWrite    0x200  /* Writable (Data segments only)    */
    00052 #define dRead     0x200  /* Readable (Code segments only)    */
    00053 #define dBusy     0xB00  /* Busy (TSS only)    was 200       */
    00054 #define dEexdown  0x400  /* Expand down (Data segments only) */
    00055 #define dConform  0x400  /* Conforming (Code segments only)  */
    00056 #define dBig      0x40   /* Default to 32 bit mode           */
    00057 #define dBiglim   0x80   /* Limit is in 4K units             */
    00058
    00059 /* GDT Descriptor */
    00060 struct gdtDescriptor {
    00061   unsigned short limitLow;      /* Limit 0..15    */
    00062   unsigned short baseLow;       /* Base  0..15    */
    00063   unsigned char  baseMed;       /* Base  16..23   */
    00064   unsigned char  access;        /* Access Byte    */
    00065   unsigned int   limitHigh:4;   /* Limit 16..19   */
    00066   unsigned int   granularity:4; /* Granularity    */
    00067   unsigned char  baseHigh;      /* Base 24..31    */
    00068   } __attribute__ ((packed));
    00069
    00070 struct gdtGate {
    00071   unsigned short offsetLow;  /* Offset 0..15  */
    00072   unsigned short selector;   /* Selector      */
    00073   unsigned short access;     /* Access Flags  */
    00074   unsigned short offsetHigh; /* Offset 16..31 */
    00075   } __attribute__ ((packed));
    00076
    00077 union descriptorTableUnion {
    00078   struct gdtDescriptor descriptor; /* Normal descriptor */
    00079   struct gdtGate gate;             /* Gate descriptor   */
    00080   unsigned long dummy;             /* Any other info    */
    00081   };
    00082
    00083
    00084 #define ubixDescriptorTable(name,length) union descriptorTableUnion name[length] =
    00085 #define ubixStandardDescriptor(base, limit, control) {descriptor: \
    00086                                                {(limit & 0xffff), \
    00087                                                (base & 0xffff), \
    00088                                                ((base >> 16) & 0xff), \
    00089                                                ((control+dPresent) >> 8), \
    00090                                                (limit >> 16), \
    00091                                                ((control & 0xff) >> 4), \
    00092                                                (base >> 24)}}
    00093 #define ubixGateDescriptor(offset, selector, control) {gate: {(offset & 0xffff), selector, \
    00094                                                      (control+dPresent), (offset >> 16) }}
    00095
    00096 extern union descriptorTableUnion ubixGDT[9];
    00097
    00098 #endif
    00099
    00100 /***
    00101  $Log: gdt_8h-source.html,v $
    00101  Revision 1.7  2006/12/15 17:47:05  reddawg
    00101  Updates
    00101
    00102  Revision 1.1.1.1  2006/06/01 12:46:15  reddawg
    00103  ubix2
    00104
    00105  Revision 1.2  2005/10/12 00:13:37  reddawg
    00106  Removed
    00107
    00108  Revision 1.1.1.1  2005/09/26 17:23:52  reddawg
    00109  no message
    00110
    00111  Revision 1.5  2004/08/15 16:47:49  reddawg
    00112  Fixed
    00113
    00114  Revision 1.4  2004/07/22 20:53:07  reddawg
    00115  atkbd: fixed problem
    00116
    00117  Revision 1.3  2004/05/21 15:12:17  reddawg
    00118  Cleaned up
    00119
    00120
    00121  END
    00122  ***/