1 /////////////////////////////////////////////////////////////////////////
2 // $Id: descriptor.h,v 1.17 2006/08/31 18:18:15 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
5 // Copyright (C) 2001 MandrakeSoft S.A.
9 // 75002 Paris - France
10 // http://www.linux-mandrake.com/
11 // http://www.mandrakesoft.com/
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 /////////////////////////////////////////////////////////////////////////
28 #ifndef BX_DESCRIPTOR_H
29 #define BX_DESCRIPTOR_H
31 typedef struct { /* bx_selector_t */
32 Bit16u value
; /* the 16bit value of the selector */
34 /* the following fields are extracted from the value field in protected
35 mode only. They're used for sake of efficiency */
36 Bit16u index
; /* 13bit index extracted from value in protected mode */
37 Bit8u ti
; /* table indicator bit extracted from value */
38 Bit8u rpl
; /* RPL extracted from value */
42 #define BX_SELECTOR_RPL(selector) ((selector) & 0x03)
43 #define BX_SELECTOR_RPL_MASK (0xfffc)
48 #define SegValidCache (0x1)
49 #define SegAccessROK (0x2)
50 #define SegAccessWOK (0x4)
52 unsigned valid
; // Holds above values, Or'd together. Used to
55 bx_bool p
; /* present */
56 Bit8u dpl
; /* descriptor privilege level 0..3 */
57 bx_bool segment
; /* 0 = system/gate, 1 = data/code segment */
58 Bit8u type
; /* For system & gate descriptors:
59 * 0 = invalid descriptor (reserved)
60 * 1 = 286 available Task State Segment (TSS)
62 * 3 = 286 busy Task State Segment (TSS)
65 * 6 = 286 interrupt gate
68 * 9 = 386 available TSS
73 * 14 = 386 interrupt gate
74 * 15 = 386 trap gate */
76 // For system & gate descriptors:
78 #define BX_GATE_TYPE_NONE (0x0)
79 #define BX_SYS_SEGMENT_AVAIL_286_TSS (0x1)
80 #define BX_SYS_SEGMENT_LDT (0x2)
81 #define BX_SYS_SEGMENT_BUSY_286_TSS (0x3)
82 #define BX_286_CALL_GATE (0x4)
83 #define BX_TASK_GATE (0x5)
84 #define BX_286_INTERRUPT_GATE (0x6)
85 #define BX_286_TRAP_GATE (0x7)
87 #define BX_SYS_SEGMENT_AVAIL_386_TSS (0x9)
89 #define BX_SYS_SEGMENT_BUSY_386_TSS (0xb)
90 #define BX_386_CALL_GATE (0xc)
92 #define BX_386_INTERRUPT_GATE (0xe)
93 #define BX_386_TRAP_GATE (0xf)
95 // For data/code descriptors:
97 #define BX_DATA_READ_ONLY (0x0)
98 #define BX_DATA_READ_ONLY_ACCESSED (0x1)
99 #define BX_DATA_READ_WRITE (0x2)
100 #define BX_DATA_READ_WRITE_ACCESSED (0x3)
101 #define BX_DATA_READ_ONLY_EXPAND_DOWN (0x4)
102 #define BX_DATA_READ_ONLY_EXPAND_DOWN_ACCESSED (0x5)
103 #define BX_DATA_READ_WRITE_EXPAND_DOWN (0x6)
104 #define BX_DATA_READ_WRITE_EXPAND_DOWN_ACCESSED (0x7)
105 #define BX_CODE_EXEC_ONLY (0x8)
106 #define BX_CODE_EXEC_ONLY_ACCESSED (0x9)
107 #define BX_CODE_EXEC_READ (0xa)
108 #define BX_CODE_EXEC_READ_ACCESSED (0xb)
109 #define BX_CODE_EXEC_ONLY_CONFORMING (0xc)
110 #define BX_CODE_EXEC_ONLY_CONFORMING_ACCESSED (0xd)
111 #define BX_CODE_EXEC_READ_CONFORMING (0xe)
112 #define BX_CODE_EXEC_READ_CONFORMING_ACCESSED (0xf)
116 bx_address base
; /* base address: 286=24bits, 386=32bits, long=64 */
117 Bit32u limit
; /* limit: 286=16bits, 386=20bits */
118 Bit32u limit_scaled
; /* for efficiency, this contrived field is set to
119 * limit for byte granular, and
120 * (limit << 12) | 0xfff for page granular seg's
122 #if BX_CPU_LEVEL >= 3
123 bx_bool g
; /* granularity: 0=byte, 1=4K (page) */
124 bx_bool d_b
; /* default size: 0=16bit, 1=32bit */
125 #if BX_SUPPORT_X86_64
126 bx_bool l
; /* long mode: 0=compat, 1=64 bit */
128 bx_bool avl
; /* available for use by system */
132 Bit8u word_count
; /* 5bits (0..31) #words to copy from caller's stack
133 * to called procedure's stack. (call gates only)*/
134 Bit16u dest_selector
;
137 #if BX_CPU_LEVEL >= 3
139 Bit8u dword_count
; /* 5bits (0..31) #dwords to copy from caller's stack
140 * to called procedure's stack. (call gates only) */
141 Bit16u dest_selector
;
145 struct { /* type 5: Task Gate Descriptor */
146 Bit16u tss_selector
; /* TSS segment selector */
149 bx_address base
; /* 286=24 386+ = 32/64 bit base */
150 Bit32u limit
; /* 286+ = 16/32 bit limit */
151 #if BX_CPU_LEVEL >= 3
152 Bit32u limit_scaled
; // Same notes as for 'segment' field
153 bx_bool g
; /* granularity: 0=byte, 1=4K (page) */
154 bx_bool avl
; /* available for use by system */
156 } system
; /* TSS and LDT */
161 #define IS_PRESENT(descriptor) (descriptor.p)
163 #if BX_SUPPORT_X86_64
164 #define IS_LONG64_SEGMENT(descriptor) (descriptor.u.segment.l)
166 #define IS_LONG64_SEGMENT(descriptor) (0)
169 #define IS_CODE_SEGMENT(type) (((type) >> 3) & 0x1)
170 #define IS_CODE_SEGMENT_CONFORMING(type) (((type) >> 2) & 0x1)
171 #define IS_DATA_SEGMENT_EXPAND_DOWN(type) (((type) >> 2) & 0x1)
172 #define IS_CODE_SEGMENT_READABLE(type) (((type) >> 1) & 0x1)
173 #define IS_DATA_SEGMENT_WRITEABLE(type) (((type) >> 1) & 0x1)
174 #define IS_SEGMENT_ACCESSED(type) ( (type) & 0x1)
176 #define BX_SEGMENT_CODE (0x8)
177 #define BX_SEGMENT_DATA_EXPAND_DOWN (0x4)
178 #define BX_SEGMENT_CODE_CONFORMING (0x4)
179 #define BX_SEGMENT_DATA_WRITE (0x2)
180 #define BX_SEGMENT_CODE_READ (0x2)
181 #define BX_SEGMENT_ACCESSED (0x1)
183 #define IS_DATA_SEGMENT(type) (! IS_CODE_SEGMENT(type))
184 #define IS_CODE_SEGMENT_NON_CONFORMING(type) \
185 (! IS_CODE_SEGMENT_CONFORMING(type))
188 bx_selector_t selector
;
189 bx_descriptor_t cache
;
193 /* no GDTR or IDTR register in an 8086 */
196 bx_address base
; /* base address: 24bits=286,32bits=386,64bits=x86-64 */
197 Bit16u limit
; /* limit, 16bits */
198 } bx_global_segment_reg_t
;