- tftp_send_optack() was not 64-bit clean (patch from SF bug #1787500)
[bochs-mirror.git] / cpu / descriptor.h
blobd6463299e619d376b1a75373c1eb74afca8abcbf
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: descriptor.h,v 1.17 2006/08/31 18:18:15 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2001 MandrakeSoft S.A.
6 //
7 // MandrakeSoft S.A.
8 // 43, rue d'Aboukir
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 */
33 #if BX_CPU_LEVEL >= 2
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 */
39 #endif
40 } bx_selector_t;
42 #define BX_SELECTOR_RPL(selector) ((selector) & 0x03)
43 #define BX_SELECTOR_RPL_MASK (0xfffc)
45 typedef struct
48 #define SegValidCache (0x1)
49 #define SegAccessROK (0x2)
50 #define SegAccessWOK (0x4)
52 unsigned valid; // Holds above values, Or'd together. Used to
53 // hold only 0 or 1.
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)
61 * 2 = LDT descriptor
62 * 3 = 286 busy Task State Segment (TSS)
63 * 4 = 286 call gate
64 * 5 = task gate
65 * 6 = 286 interrupt gate
66 * 7 = 286 trap gate
67 * 8 = (reserved)
68 * 9 = 386 available TSS
69 * 10 = (reserved)
70 * 11 = 386 busy TSS
71 * 12 = 386 call gate
72 * 13 = (reserved)
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)
86 /* 0x8 reserved */
87 #define BX_SYS_SEGMENT_AVAIL_386_TSS (0x9)
88 /* 0xa reserved */
89 #define BX_SYS_SEGMENT_BUSY_386_TSS (0xb)
90 #define BX_386_CALL_GATE (0xc)
91 /* 0xd reserved */
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)
114 union {
115 struct {
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 */
127 #endif
128 bx_bool avl; /* available for use by system */
129 #endif
130 } segment;
131 struct {
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;
135 Bit16u dest_offset;
136 } gate286;
137 #if BX_CPU_LEVEL >= 3
138 struct {
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;
142 Bit32u dest_offset;
143 } gate386;
144 #endif
145 struct { /* type 5: Task Gate Descriptor */
146 Bit16u tss_selector; /* TSS segment selector */
147 } taskgate;
148 struct {
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 */
155 #endif
156 } system; /* TSS and LDT */
157 } u;
159 } bx_descriptor_t;
161 #define IS_PRESENT(descriptor) (descriptor.p)
163 #if BX_SUPPORT_X86_64
164 #define IS_LONG64_SEGMENT(descriptor) (descriptor.u.segment.l)
165 #else
166 #define IS_LONG64_SEGMENT(descriptor) (0)
167 #endif
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))
187 typedef struct {
188 bx_selector_t selector;
189 bx_descriptor_t cache;
190 } bx_segment_reg_t;
192 #if BX_CPU_LEVEL < 2
193 /* no GDTR or IDTR register in an 8086 */
194 #else
195 typedef struct {
196 bx_address base; /* base address: 24bits=286,32bits=386,64bits=x86-64 */
197 Bit16u limit; /* limit, 16bits */
198 } bx_global_segment_reg_t;
199 #endif
201 #endif