1 ;******************************************************************************
3 ; (C) Copyright MICROSOFT Corp. 1986
5 ; Title: CEMM.EXE - COMPAQ Expanded Memory Manager 386 Driver
6 ; EMMLIB.LIB - Expanded Memory Manager Library
8 ; Module: EMMDEF.INC - defines for EMM code.
14 ;******************************************************************************
18 ; DATE REVISION DESCRIPTION
19 ; -------- -------- -------------------------------------------------------
21 ; 06/25/86 0.02 Changed HANDLE_CNT to 255 to match LIM spec (SBP).
22 ; 06/28/86 0.02 Name change from CEMM386 to CEMM (SBP).
23 ; 07/06/86 0.04 Changed save area struct (SBP).
24 ; 05/25/88 Changed to meet LIM 4.0 Spec (PC)
25 ;******************************************************************************
30 ;******************************************************************************
31 ; G E N E R A L D E F I N E S
32 ;******************************************************************************
33 EMM_PAGE_CNT = 2048 ; maximum of 2048 EMM pages (32MB)
34 HANDLE_CNT = 255 ; maximum of 255 EMM handles
35 FRS_COUNT = 16 ; number of 'Fast Register Sets'
37 EMM32_PHYS_PAGES = 4 ; page frame contains 4 pages
39 ; The 0 to 1M contains 64 physical pages. Of these we are not mapping anything
40 ; between E000 and FFFF, 0000 and 4000. So the Maximum physcial pages we can
41 ; get for mapping is 40.
44 MAX_PHYS_PAGES equ 40 ; Life, the Universe
48 ; Of the above mappable pages the regions C000h to Dfffh have to be searched
49 ; for the mappable pages.
51 ABOVE_CONV_STRT_SEG equ 0C000h
52 ABOVE_CONV_STRT_PG equ ABOVE_CONV_STRT_SEG SHR 10
54 ABOVE_CONV_END_SEG equ 0DC00h
55 ABOVE_CONV_END_PG equ ABOVE_CONV_END_SEG SHR 10
57 MAX_ABOVE_CONV_PAGES EQU 8
59 ; Also the system memory mappable region starts at 4000h
61 CONV_STRT_SEG equ 4000h
62 CONV_STRT_PG equ CONV_STRT_SEG SHR 10
64 NUM_CONV_PGS equ (0A000h -4000h) SHR 10
66 ; During init we keep track of mappable pages with an array of mappable_segs
69 PAGE_MAPPABLE equ 0FFh ;
70 PAGE_NOT_MAPPABLE equ 0h ;
78 ; Flags for memory move/xchg
80 Source_GT_Dest_Flag = 80h ; Source > Destination for copy / xchg
81 Overlap_Flag = 40h ; Copy overlapping memory
82 Backward_Copy_Flag = 20h ; copy is going to be backward
84 ; Flags for PFlag use in Alter Map and Jump
86 PFLAG_VM = 0002h ; VM bit in High word of EFLAG
87 PFLAG_VIRTUAL = 0020h ; wheather it's call from virtual or proected mode
88 PFLAG_PATCH_CS_IP = 0008h ; Tell Protected mode dispatch to
89 ; patch new CS:IP onto it's return address
90 ;******************************************************************************
91 ; S T A T U S D E F I N E S
92 ;******************************************************************************
94 EMM_SW_MALFUNCTION = 80h
95 EMM_HW_MALFUNCTION = 81h
97 INVALID_FUNCTION = 84h
99 SAVED_PAGE_DEALLOC = 86h
100 NOT_ENOUGH_EXT_MEM = 87h
101 NOT_ENOUGH_FREE_MEM = 88h
104 PHYS_PAGE_RANGE = 8Bh
108 INVALID_SUBFUNCTION = 8Fh
113 INSUFFICIENT_EMM_PAGES = 93h
114 CONVENTIONAL_EMM_OVERLAP= 94h
116 INVALID_REGION_LENGTH = 96h
117 OVERLAPPING_EXCHANGE = 97h
118 INVALID_MEMORY_TYPE = 98h
119 FRSETS_UNSUPPORTED = 99h
123 FRSET_UNDEFINED = 9Dh
125 FRSET_INVALID_DMA = 9Fh
126 HANDLE_NAME_NOT_FOUND = 0A0h
127 DUPLICATE_HANDLE_NAME = 0A1h
128 INVALID_WRAPAROUND = 0A2h
129 SOURCE_CORRUPTED = 0A3h
133 ;******************************************************************************
134 ; GET/SET PAGE MAP SUBFUNCTION CODES
135 ;******************************************************************************
148 ;******************************************************************************
149 ; S T R U C T U R E S
150 ;******************************************************************************
153 ; stack frame after pushad on real/virtual mode entry
177 HandleTable_struc struc
178 ht_index dw NULL_PAGE ; index into emm_page for handle's pgs
179 ht_count dw 0 ; number of emm_pages for this handle
180 HandleTable_struc ends
186 s_handle dw NULL_HANDLE ; owning handle
187 s_map dw EMM32_PHYS_PAGES dup (NULL_PAGE) ; EMM page #s
191 ; structure linking segment with physical page number
199 ; Get Partial Page Map
207 ; Structures used as arguments to Map Handle Array function
222 ; Used by Map and Jump and Map and Call -- Identical to mha_array0 and 1
223 log_phys_map_struct struc
225 phys_page_number_seg dw ?
226 log_phys_map_struct ends
228 ; Map and Jump structure
230 maj_target_address dd ?
231 maj_log_phys_map_len db ?
235 ; Map and Call structure
237 mac_target_address dd ?
238 mac_new_page_map_len db ?
239 mac_new_map_address dd ?
240 mac_old_page_map_len db ?
241 mac_old_map_address dd ?
242 mac_reserved dw 4 dup (?)
245 ; Move / Exchange memory structure
246 mem_memory_descriptor_struct struc
249 mem_initial_offset dw ?
250 mem_initial_seg_page dw ?
251 mem_memory_descriptor_struct ends
255 mem_region_length dd ?
256 mem_source db (SIZE mem_memory_descriptor_struct) dup (?)
257 mem_dest db (SIZE mem_memory_descriptor_struct) dup (?)
261 ; Fast Register Set Description
264 FRS_Window dw MAX_PHYS_PAGES dup (NULL_PAGE) ; emm page numbers
265 FRS_alloc dw 0 ; Is this set allocated
269 ;****************************************************************************
271 ; Dword_Align -- Aligns code to dword boundry by inserting nops
273 ;****************************************************************************
275 Dword_Align MACRO Seg_Name
276 IF (($ - OFFSET Seg_Name:0) MOD 4)
277 db 90h ;; Nop in code / else byte of 90h in data
283 ;***********************************************
285 ; Validate_Handle - check the handle in DX
287 ; ENTRY: Handle as per LIM4.0 spec. in DX
289 ; EXIT: If the handle is invalid jump To Death_Label, otherwise,
290 ; EDX points to the _handle_table entry for the handle
294 ;***********************************************
295 Validate_Handle MACRO Death_Label
297 cmp dx, [_handle_table_size] ;Q: handle in range ?
298 jae Death_Label ; N: go to error label
299 shl dx, 2 ; Y: convert handle to
300 add dx, offset _handle_table ; pointer
302 cmp [bx.ht_index], NULL_PAGE ;Q: is this handle active ?
304 je Death_Label ; N: return error
308 ;***********************************************
310 ; Handle2HandlePtr - convert the handle in DX to
311 ; points into handle_table
313 ; ENTRY: Handle as per LIM4.0 spec. in DX
315 ; EXIT: EDX points to the _handle_table entry for the handle
319 ;***********************************************
320 Handle2HandlePtr MACRO
322 shl dx, 2 ; Y: convert handle to
323 add dx, offset _handle_table ; pointer
327 .list ; end of EMMDEF.INC