00001 00002 00003 00004 /************************************************************************************** 00005 Copyright (c) 2002 The UbixOS Project 00006 All rights reserved. 00007 00008 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 00009 00010 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. 00011 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors 00012 in the documentation and/or other materials provided 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 without specific prior written permission. 00014 00015 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 00016 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00017 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00018 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00019 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00020 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00021 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00022 00023 $Id$ 00024 00025 **************************************************************************************/ 00026 00027 #ifndef _GDT_H 00028 #define _GDT_H 00029 00030 /* Descriptor Definitions */ 00031 #define dCall 0x0C00 /* 386 Call Gate */ 00032 #define dCode 0x1800 /* Code Segment */ 00033 #define dData 0x1000 /* Data Segment */ 00034 #define dInt 0x0E00 /* 386 Interrupt Gate */ 00035 #define dLdt 0x200 /* Local Descriptor Table (LDT) */ 00036 #define dTask 0x500 /* Task gate */ 00037 #define dTrap 0x0F00 /* 386 Trap Gate */ 00038 #define dTss 0x900 /* Task State Segment (TSS) */ 00039 00040 /* Descriptor Options */ 00041 #define dDpl3 0x6000 /* DPL3 or mask for DPL */ 00042 #define dDpl2 0x4000 /* DPL2 or mask for DPL */ 00043 #define dDpl1 0x2000 /* DPL1 or mask for DPL */ 00044 #define dPresent 0x8000 /* Present */ 00045 #define dNpresent 0x8000 /* Not Present */ 00046 #define dAcc 0x100 /* Accessed (Data or Code) */ 00047 #define dWrite 0x200 /* Writable (Data segments only) */ 00048 #define dRead 0x200 /* Readable (Code segments only) */ 00049 #define dBusy 0xB00 /* Busy (TSS only) was 200 */ 00050 #define dEexdown 0x400 /* Expand down (Data segments only) */ 00051 #define dConform 0x400 /* Conforming (Code segments only) */ 00052 #define dBig 0x40 /* Default to 32 bit mode */ 00053 #define dBiglim 0x80 /* Limit is in 4K units */ 00054 00055 /* GDT Descriptor */ 00056 struct gdtDescriptor { 00057 unsigned short limitLow; /* Limit 0..15 */ 00058 unsigned short baseLow; /* Base 0..15 */ 00059 unsigned char baseMed; /* Base 16..23 */ 00060 unsigned char access; /* Access Byte */ 00061 unsigned int limitHigh:4; /* Limit 16..19 */ 00062 unsigned int granularity:4; /* Granularity */ 00063 unsigned char baseHigh; /* Base 24..31 */ 00064 } __attribute__ ((packed)); 00065 00066 struct gdtGate { 00067 unsigned short offsetLow; /* Offset 0..15 */ 00068 unsigned short selector; /* Selector */ 00069 unsigned short access; /* Access Flags */ 00070 unsigned short offsetHigh; /* Offset 16..31 */ 00071 } __attribute__ ((packed)); 00072 00073 union descriptorTableunion { 00074 struct gdtDescriptor descriptor; /* Normal descriptor */ 00075 struct gdtGate gate; /* Gate descriptor */ 00076 unsigned long dummy; /* Any other info */ 00077 }; 00078 00079 00080 #define descriptorTable(name,length) union descriptorTableunion name[length] = 00081 #define standardDescriptor(base, limit, control) {descriptor: {(limit & 0xffff), (base & 0xffff), ((base >> 16) & 0xff), \ 00082 ((control+dPresent) >> 8), (limit >> 16), \ 00083 ((control & 0xff) >> 4), (base >> 24)}} 00084 #define gateDescriptor(offset, selector, control) {gate: {(offset & 0xffff), selector, \ 00085 (control+dPresent), (offset >> 16) }} 00086 00087 #endif 00088