2 TITLE INDEGDT
- 386 XMA Emulator
- Build Global Descriptor Table
5 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
7 * MODULE NAME
: INDEGDT
*
10 * 5669-196 (C
) COPYRIGHT
1988 Microsoft Corp
. *
12 * DESCRIPTIVE NAME
: Build the Global Descriptor Table
(GDT
) *
14 * STATUS
(LEVEL
) : Version
(0) Level
(1.0) *
16 * FUNCTION
: Build the Global Descriptor Table
(GDT
) for the
80386 *
21 * REGISTER USAGE
: 80386 Standard
*
23 * RESTRICTIONS
: None
*
25 * DEPENDENCIES
: None
*
27 * ENTRY POINT
: GDT_BLD
*
29 * LINKAGE
: Called
NEAR from INDEINI
*
31 * INPUT PARMS
: None
*
33 * RETURN PARMS
: None
*
35 * OTHER EFFECTS
: None
*
37 * EXIT NORMAL
: Return to INDEINI
*
44 * SUB-ROUTINES
: SREG_2_24BITS
- Convert the
16 bit value
in AX to a
24 *
45 * bit value
in DH and AX. *
46 * ADDOFF
- Add the
16 bit offset
in AX to the
24 bit value
*
49 * MACROS
: DESCR_DEF
- Declare a descriptor
entry *
50 * DESCR_INIT
- Initialize a descriptor
*
52 * CONTROL BLOCKS
: INDEDAT
- System
data structures
*
56 * $
MOD(INDEGDT
) COMP
(LOAD) PROD
(3270PC
) : *
58 * $D0=D0004700
410 870530 D
: NEW FOR RELEASE
1.1 *
59 * $P1
=P0000293
410 870731 D
: LIMIT LINES TO
80 CHARACTERS
*
60 * $P2
=P0000312
410 870804 D
: CHANGE COMPONENT
FROM MISC TO
LOAD *
61 * $P3
=P0000410
410 870918 D
: RELOCATE
DATA AREAS TO MAKE ROOM FOR BIT MAP
*
63 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
66 .286P
; Enable recognition of 286 privileged instructs.
68 .XLIST
; Turn off the listing
69 INCLUDE INDEDAT
.INC ; Include system data structures
70 INCLUDE INDEACC
.INC ; Include access byte definitions
72 IF1
; Only include macros on the first pass
73 INCLUDE INDEDES
.MAC
; Descriptor macros
75 .LIST
; Turn on the listing
77 PROG
SEGMENT PARA
PUBLIC 'PROG'
91 ; The following data define a pre-initialized GDT. They represent
92 ; all structures which will exist when the emulator comes up.
93 ; THESE MUST BE INITIALIZED IN THE ORDER IN WHICH THEY APPEAR IN THE
94 ; GDT_DEF STRUCTURE DEFINITION AS IT APPEARS IN INDEDAT.INC. This data
95 ; area will be copied from the code segment to the final GDT resting
96 ; place during initialization.
98 GDT_DATA_START
LABEL WORD
100 ; First entry is unusable
102 DESCR_DEF SEG
, 0, 0, 0, 0
104 ; The descriptor for GDT itself
106 DESCR_DEF SEG
, GDT_LEN
, GDT_LOC
, 3, CPL0_DATA_ACCESS
109 ; The system IDT descriptor
111 DESCR_DEF SEG
, SIDT_LEN
, SIDT_LOC
, 3, CPL0_DATA_ACCESS
113 ; The real system data area descriptor (XMA pages)
115 DESCR_DEF SEG
, 0FFFFH, 0000H, 11H
, CPL0_DATA_ACCESS
117 ; The virtual IDT descriptor (not needed so use for all memory)
119 DESCR_DEF SEG
, MAX_SEG_LEN
, NSEG@_LO
, NSEG@_HI
, CPL0_DATA_ACCESS
121 ; The LOADALL descriptor
123 DESCR_DEF SEG
, 0, 0, 0, 0
126 ; Compatible monochrome display
128 DESCR_DEF SEG
, MCRT_SIZE
, MCRT@_LO
, MCRT@_HI
, CPL0_DATA_ACCESS
130 ; Compatible color display
132 DESCR_DEF SEG
, CCRT_SIZE
, CCRT@_LO
, CCRT@_HI
, CPL0_DATA_ACCESS
134 ; Enhanced color display - one entry for each 64K P1C
136 DESCR_DEF SEG
, ECCRT_SIZE
, ECCRT@_LO_LO
, ECCRT@_LO_HI
, CPL0_DATA_ACCESS
138 ; Second part of enhanced display P1C
140 DESCR_DEF SEG
, ECCRT_SIZE
, ECCRT@_HI_LO
, ECCRT@_HI_HI
, CPL0_DATA_ACCESS
143 ; Code segment for ROM code, system IDT
145 DESCR_DEF SEG
, MAX_SEG_LEN
, CSEG@_LO
, CSEG@_HI
, CPL0_CODE_ACCESS
147 ; Data segment for ROM code, system IDT
149 DESCR_DEF SEG
, MAX_SEG_LEN
, CSEG@_LO
, CSEG@_HI
, CPL0_CODE_ACCESS
151 ; Temporarily, the monitor is installed using the patch
152 ; segment descriptors in the GDT
158 ; Code segment for patch code, system IDT
160 DESCR_DEF SEG
, MAX_SEG_LEN
, MSEG@_LO
, MSEG@_HI
, CPL0_CODE_ACCESS
162 ; Data segment for patch code, system IDT
164 DESCR_DEF SEG
, MAX_SEG_LEN
, MSEG@_LO
, MSEG@_HI
, CPL0_DATA_ACCESS
167 ; Code segment for ROM code, virtual IDT
169 DESCR_DEF SEG
, MAX_SEG_LEN
, CSEG@_LO
, CSEG@_HI
, CPL0_CODE_ACCESS
171 ; Data segment for ROM code, virtual IDT
173 DESCR_DEF SEG
, MAX_SEG_LEN
, CSEG@_LO
, CSEG@_HI
, CPL0_CODE_ACCESS
175 ; Code segment for patch code, virtual IDT
177 DESCR_DEF SEG
, NULL_SEG_LEN
, NSEG@_LO
, NSEG@_HI
, NULL_ACCESS
179 ; Data segment for patch code, virtual IDT
181 DESCR_DEF SEG
, NULL_SEG_LEN
, NSEG@_LO
, NSEG@_HI
, NULL_ACCESS
184 ; Temporary descriptors for ES, CS, SS, and DS
186 DESCR_DEF SEG
, MAX_SEG_LEN
, NSEG@_LO
, NSEG@_HI
, CPL0_DATA_ACCESS
188 DESCR_DEF SEG
, MAX_SEG_LEN
, NSEG@_LO
, NSEG@_HI
, CPL0_CODE_ACCESS
190 DESCR_DEF SEG
, MAX_SEG_LEN
, NSEG@_LO
, NSEG@_HI
, CPL0_DATA_ACCESS
192 DESCR_DEF SEG
, MAX_SEG_LEN
, NSEG@_LO
, NSEG@_HI
, CPL0_DATA_ACCESS
195 ; These DQ's pad out the space between the last MultiPC descriptor and the
196 ; PMVM descriptors. They don't need initialization.
198 DQ 9 DUP (0) ; These 9 are for the Monitor descriptors
200 ; This is for the keyboard owner (not used)
204 ; These 16 are for the virtual timer support
208 ; The following 32 descriptors are for exception condition task gates.
214 ; The following 16 pairs are for the hardware interrupt handling tasks.
221 ; The following pair is for the DISPATCH task
223 DESCR_DEF SEG
, TSS_LEN
, DISPATCH_LOC
, 3, <TSS_ACCESS
OR FREE_TSS
>
224 DESCR_DEF SEG
, TSS_LEN
, DISPATCH_LOC
, 3, CPL0_DATA_ACCESS
226 DESCR_DEF SEG
, 0, 0, 0,LDT_DESC
230 DESCR_DEF SEG
, 07FFFH, 06000H, 0FH, CPL0_DATA_ACCESS
234 DESCR_DEF SEG
, 01FFFH, 00000H, 0FH, CPL0_DATA_ACCESS
236 DQ 13 DUP (0) ; Reserved guys
238 ; The following guys are junk ! Used before the first TSS allocated. These
239 ; have to be in the PMVM location in the GDT.
241 DESCR_DEF SEG
, TSS_LEN
, 0C000H, 0, FREE_TSS
; For the TR
243 DESCR_DEF SEG
, TSS_LEN
, 0C000H, 0, CPL0_DATA_ACCESS
; TSS as data
245 DESCR_DEF SEG
, GDT_LEN
, 0D000H, 0, LDT_DESC
; For the LDTR
247 DESCR_DEF SEG
, GDT_LEN
, 0D000H, 0, CPL0_DATA_ACCESS
; LDT as data
249 GDT_DATA_END
LABEL WORD
251 COPY_LEN EQU GDT_DATA_END
-GDT_DATA_START
254 ; End of pre-allocated GDT
261 ; Copy the pre-initialized GDT into its proper location in memory
263 CLI ; All string operations go forward
265 MOV SI,OFFSET GDT_DATA_START
; DS:SI points to the pre-initialized
267 MOV CX,COPY_LEN
/2 ; CX = number of words to copy
268 MOV DI,GDT_LOC
; ES:DI points to the GDT location
269 REP MOVSW ; Copy GDT into its final resting place
271 ; Now let's initialize some of the GDT entries
273 ; Set up the descriptors for our code segment and data segment
275 MOV AX,CS ; Get our CS
276 CALL SREG_2_24BITS
; And convert it to a 24 bit offset
277 MOV BX,AX ; Get the monitor offset
280 DESCR_INIT SEG
, SYS_PATCH_CS
, 07FFFH, BX, DH, CPL0_CODE_ACCESS
281 DESCR_INIT SEG
, SYS_PATCH_DS
, 0FFFFH, BX, DH, CPL0_DATA_ACCESS
283 ; Initialize the descriptor for the GDT
285 MOV AX,ES ; Get the segment of the GDT
286 CALL SREG_2_24BITS
; Convert to a 24 bit offset
287 MOV DL,DH ; Save a copy of the hi byte
288 MOV BX,GDT_LOC
; Add on the offset of the GDT
291 DESCR_INIT SEG
, GDT_PTR
, GDT_LEN
, BX, DH, CPL0_DATA_ACCESS
293 ; Initialize the descriptor for the IDT
295 MOV BX,SIDT_LOC
; DH,AX already contains the segment
296 ; converted to 24 bits so all we
297 CALL ADDOFF
; have to do is add on the offset
299 DESCR_INIT SEG
, MON_IDT_PTR
, SIDT_LEN
, BX, DH, CPL0_DATA_ACCESS
301 ; Initialize the descriptor that accesses all of memory as data
303 DESCR_INIT BSEG
, HUGE_PTR
, 0FFFFH, 0, 0, CPL0_DATA_ACCESS
305 ; Initialize the descriptors for the V86 task's LDT
307 MOV BX,DISPATCH_LOC
; @P3C
310 DESCR_INIT SEG
,SCRUBBER
.VM_LDTR
,00FFFH,BX,DH,LDT_DESC
311 DESCR_INIT SEG
,SCRUBBER
.LDT_PTR
,00FFFH,BX,DH,CPL0_DATA_ACCESS
313 ; Initialize the descriptors for the V86 task's TR
315 MOV BX,DISPATCH_LOC
; @P3C
318 DESCR_INIT SEG
,SCRUBBER
.VM_TR
,TSS_LEN
,BX,DH,FREE_TSS_386
; @P3C
319 DESCR_INIT SEG
,SCRUBBER
.TSS_PTR
,TSS_LEN
,BX,DH,CPL0_DATA_ACCESS
; @P3C
326 ; SREG_2_24BITS converts the segment register 16 bit value in the AX register
327 ; into a 24 bit value in DH and AX
329 ; Input : AX = segment register value
331 ; Output: AX = 24 bit low word
332 ; DH = 24 bit high byte
335 SREG_2_24BITS PROC
NEAR
337 ; Put the high four bits of AH into the low four bits of DH
339 MOV DH,AH ; Get the high byte of the segment value
341 AND DH,0F0H ; Strip off the low nibble
342 SHR DH,4 ; Shift right four bits
344 ; Now shift AX left four bits
346 AND AH,00FH ; Strip high nibble from AH
347 ; This keeps the carry flag from being
348 ; set which could effect later ADDs.
356 ; ADDOFF adds the 16 bit offset in BX to the 24 bit value in DL and AX. The
357 ; result is left in DH and BX.
359 ; Input : DL = 24 bit high byte
360 ; AX = 24 bit low word
361 ; BX = offset to be added
363 ; Output: DH = 24 bit high byte
364 ; BX = 24 bit low word
368 MOV DH,DL ; Restore the high byte that was saved
370 ADD BX,AX ; Add on the offset
371 ADC DH,0 ; Add the carry, if any, to the high