UbixOS V2  2.0
gdt.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2002-2018 The UbixOS Project.
3  * All rights reserved.
4  *
5  * This was developed by Christopher W. Olsen for the UbixOS Project.
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted
8  * provided that the following conditions are met:
9  *
10  * 1) Redistributions of source code must retain the above copyright notice, this list of
11  * conditions, the following disclaimer and the list of authors.
12  * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13  * conditions, the following disclaimer and the list of authors in the documentation and/or
14  * other materials provided with the distribution.
15  * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16  * endorse or promote products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef _GDT_H_
30 #define _GDT_H_
31 
32 #define SEL_GET_PL(sel) ((sel)&3) /* Get Priority Level Of Selector */
33 #define SEL_GET_LG(sel) ((sel)&4) /* Return Local/Global Descriptor */
34 #define SEL_GET_IDX(sel) (((sel)>>3) & 0x1FFF) /* Get Selector Index */
35 
36 #define SEL_PL_KERN 0x0
37 #define SEL_PL_USER 0x3
38 
39 /* Descriptor Definitions */
40 #define dCall 0x0C00 /* 386 Call Gate */
41 #define dCode 0x1800 /* Code Segment */
42 #define dData 0x1000 /* Data Segment */
43 #define dInt 0x0E00 /* 386 Interrupt Gate */
44 #define dLdt 0x200 /* Local Descriptor Table (LDT) */
45 #define dTask 0x500 /* Task gate */
46 #define dTrap 0x0F00 /* 386 Trap Gate */
47 #define dTss 0x900 /* Task State Segment (TSS) */
48 
49 /* Descriptor Options */
50 #define dDpl3 0x6000 /* DPL3 or mask for DPL */
51 #define dDpl2 0x4000 /* DPL2 or mask for DPL */
52 #define dDpl1 0x2000 /* DPL1 or mask for DPL */
53 #define dDpl0 0x0000 /* DPL0 or mask for DPL */
54 #define dPresent 0x8000 /* Present */
55 #define dNpresent 0x8000 /* Not Present */
56 #define dAcc 0x100 /* Accessed (Data or Code) */
57 #define dWrite 0x200 /* Writable (Data segments only) */
58 #define dRead 0x200 /* Readable (Code segments only) */
59 #define dBusy 0xB00 /* Busy (TSS only) was 200 */
60 #define dEexdown 0x400 /* Expand down (Data segments only) */
61 #define dConform 0x400 /* Conforming (Code segments only) */
62 #define dBig 0x40 /* Default to 32 bit mode */
63 #define dBiglim 0x80 /* Limit is in 4K units */
64 
65 /* GDT Descriptor */
66 struct gdtDescriptor {
67  unsigned short limitLow; /* Limit 0..15 */
68  unsigned short baseLow; /* Base 0..15 */
69  unsigned char baseMed; /* Base 16..23 */
70  unsigned char access; /* Access Byte */
71  unsigned int limitHigh :4; /* Limit 16..19 */
72  unsigned int granularity :4; /* Granularity */
73  unsigned char baseHigh; /* Base 24..31 */
74 }__attribute__ ((packed));
75 
76 struct gdtGate {
77  unsigned short offsetLow; /* Offset 0..15 */
78  unsigned short selector; /* Selector */
79  unsigned short access; /* Access Flags */
80  unsigned short offsetHigh; /* Offset 16..31 */
81 }__attribute__ ((packed));
82 
84  struct gdtDescriptor descriptor; /* Normal descriptor */
85  struct gdtGate gate; /* Gate descriptor */
86  unsigned long dummy; /* Any other info */
87 };
88 
89 #define ubixDescriptorTable(name, length) union descriptorTableUnion name[length] =
90 #define ubixStandardDescriptor(base, limit, control) {.descriptor = {(limit & 0xffff), (base & 0xffff), ((base >> 16) & 0xff), ((control + dPresent) >> 8), (limit >> 16), ((control & 0xff) >> 4), (base >> 24)}}
91 #define ubixGateDescriptor(offset, selector, control) {.gate = {(offset & 0xffff), selector, (control+dPresent), (offset >> 16) }}
92 
93 extern union descriptorTableUnion ubixGDT[11];
94 
95 #endif
96 
97 /***
98  $Log: gdt.h,v $
99  Revision 1.1.1.1 2006/06/01 12:46:15 reddawg
100  ubix2
101 
102  Revision 1.2 2005/10/12 00:13:37 reddawg
103  Removed
104 
105  Revision 1.1.1.1 2005/09/26 17:23:52 reddawg
106  no message
107 
108  Revision 1.5 2004/08/15 16:47:49 reddawg
109  Fixed
110 
111  Revision 1.4 2004/07/22 20:53:07 reddawg
112  atkbd: fixed problem
113 
114  Revision 1.3 2004/05/21 15:12:17 reddawg
115  Cleaned up
116 
117  END
118  ***/
__attribute__
union descriptorTableUnion __attribute__
descriptorTableUnion::descriptor
struct gdtDescriptor descriptor
Definition: gdt.h:84
ubixGDT
union descriptorTableUnion ubixGDT[11]
gdtGate
Definition: gdt.h:76
descriptorTableUnion::dummy
unsigned long dummy
Definition: gdt.h:86
gdtDescriptor::access
unsigned char access
Definition: gdt.h:70
gdtGate::offsetHigh
unsigned short offsetHigh
Definition: gdt.h:80
gdtDescriptor::granularity
unsigned int granularity
Definition: gdt.h:72
gdtGate::selector
unsigned short selector
Definition: gdt.h:78
gdtDescriptor
Definition: gdt.h:66
descriptorTableUnion
Definition: gdt.h:83
gdtGate::offsetLow
unsigned short offsetLow
Definition: gdt.h:77
gdtGate::access
unsigned short access
Definition: gdt.h:79
gdtDescriptor::baseLow
unsigned short baseLow
Definition: gdt.h:68
gdtDescriptor::baseMed
unsigned char baseMed
Definition: gdt.h:69
gdtDescriptor::baseHigh
unsigned char baseHigh
Definition: gdt.h:73
gdtDescriptor::limitLow
unsigned short limitLow
Definition: gdt.h:67
descriptorTableUnion::gate
struct gdtGate gate
Definition: gdt.h:85
gdtDescriptor::limitHigh
unsigned int limitHigh
Definition: gdt.h:71