]> wirehaze git hosting - MS-DOS.git/blob - v4.0/src/DEV/XMA2EMS/LIM40B.INC

wirehaze git hosting

MZ is back!
[MS-DOS.git] / v4.0 / src / DEV / XMA2EMS / LIM40B.INC
1
2 page
3 ;=========================================================================
4 ; This module contains all the EQU's, STRUC's, data, and routines necessary
5 ; for LIMDMS.INC.
6 ; This module is to be INCLUDE'd as part of LIMDMS.INC.
7 ;
8 ;=========================================================================
9
10 ;=========================================================================
11 ;========== Begin EQUate Definitions =====================================
12 ;=========================================================================
13
14 AAJ_Option_Max equ 1h ;max option value ;an000; dms;
15 AAJ_Segment equ 1h ;segment request value ;an000; dms;
16 AAJ_No_Pages_To_Map equ 0h ;0 page map request ;an000; dms;
17
18 MAC_Stack_Status_Request equ 02h ;stack size request ;an000; dms;
19
20 ER_Conv_Memory equ 00h ;conv. memory request ;an000; dms;
21 ER_EMS_Memory equ 01h ;EMS memory request ;an000; dms;
22 EMS_Page_Size_In_Bytes equ (16*1024)-1 ;page size in bytes ;an000; dms;
23 ER_Max_Type equ 01h ;max type possible ;an000; dms;
24 ER_Max_Function equ 01h ;max function possible ;an000; dms;
25 ER_Move equ 00h ;move data ;an000; dms;
26 ER_Exchange equ 01h ;exchange data ;an000; dms;
27 ER_EMS_Page_FE equ 0FEh ;phys. page FEh ;an000; dms;
28 ER_EMS_Page_FF equ 0FFh ;phys. page FFh ;an000; dms;
29 ER_Dest_EMS_Memory equ 01h ;bit 0 set ;an000; dms;
30 ER_Source_EMS_Memory equ 02h ;bit 1 set ;an000; dms;
31 ER_Up equ 00h ;signal forward move ;an000; dms;
32 ER_Down equ 0ffh ;signal reverse move
33 ER_10H equ 10h ;equ for 10h ;an000; dms;
34
35 AR_Sub_Max equ 01h ;5ah max. sub functions ;an000; dms;
36
37 ;=========================================================================
38 ;========== End EQUate Definitions =======================================
39 ;=========================================================================
40
41 page
42 ;=========================================================================
43 ;========== Begin STRUC Definitions ======================================
44 ;=========================================================================
45
46 Log_Phys_Map_Struc struc ;page structure ;an000; dms;
47
48 Log_Page_Number dw ? ;logical page number ;an000; dms;
49 Phys_Page_Number_Seg dw ? ;physical page or seg ;an000; dms;
50 ; determined by AL
51 Log_Phys_Map_Struc ends
52
53
54 Map_And_Jump_Struc struc ;carries jump info. ;an000; dms;
55
56 Target_Address dd ? ;jump address ;an000; dms;
57 Log_Phys_Map_Len db ? ;entry count in ;an000; dms;
58 ; Log_Phys_Map_Struct
59 Log_Phys_Map_Ptr dd ? ;Log_Phys_Map_Struct ptr;an000; dms;
60
61 Map_And_Jump_Struc ends ;an000; dms;
62
63
64 Map_And_Call_Struc struc ;carries jump info. ;an000; dms;
65
66 MAC_Target_Address dd ? ;jump address ;an000; dms;
67 MAC_New_Page_Map_Len db ? ;entry count in ;an000; dms;
68 ; Log_Phys_Map_Struct
69 ; for new map scheme
70 MAC_New_Page_Map_Ptr dd ? ;Log_Phys_Map_Struc ptr ;an000; dms;
71 ; for new map scheme
72 MAC_Old_Page_Map_Len db ? ;entry count in ;an000; dms;
73 ; Log_Phys_Map_Struc
74 ; for old map scheme
75 MAC_Old_Page_Map_Ptr dd ? ;Log_Phys_Map_Struc ptr ;an000; dms;
76 ; for old map scheme
77 MAC_Reserved dw 4 DUP (?) ;Used to restore map ;an000; dms;
78 ; context
79
80 Map_And_Call_Struc ends ;an000; dms;
81
82
83 Move_Source_Dest_Struc struc ;structure for move ;an000; dms;
84
85 Region_Length_Low_Word dw ? ;
86 Region_Length_High_Word dw ? ;length of region ;an000; dms;
87
88 Source_Memory_Type db ? ;conv/EMS ;an000; dms;
89 Source_Handle dw ? ;handle if EMS, else 0 ;an000; dms;
90 Source_Initial_Offset dw ? ;offset of source region;an000; dms;
91 Source_Initial_Seg_Page dw ? ;logical page if EMS ;an000; dms;
92 ; seg if conv.
93 Dest_Memory_Type db ? ;conv/EMS ;an000; dms;
94 Dest_Handle dw ? ;handle if EMS, else 0 ;an000; dms;
95 Dest_Initial_Offset dw ? ;offset of source region;an000; dms;
96 Dest_Initial_Seg_Page dw ? ;logical page if EMS ;an000; dms;
97 ; seg if conv.
98 Move_Source_Dest_Struc ends ;end structure ;an000; dms;
99
100 Realloc_Struc Struc ;BP addressible struc ;an000; dms;
101
102 Realloc_Reserved db size Instance_Entry_Struc dup (?) ;an000; dms;
103 Realloc_Alloc_Byte db ? ;reserved ;an000; dms;
104 Realloc_Reg_DI dw ? ;reserved ;an000; dms;
105 Realloc_Handle dw ? ;handle ;an000; dms;
106
107 Realloc_Page_Count dw ? ;new page count ;an000; dms;
108 Realloc_Page_Alloc dw ? ;pages to be allocated ;an000; dms;
109 Realloc_Page_Dealloc dw ? ;pages to be deallocated ;an000; dms;
110
111 Realloc_Handle_Xref_Index dw ? ;index to end of handle table ;an000; dms;
112 Realloc_LookUp_Index dw ? ;index to applicable handle ;an000; dms;
113 Realloc_Mult dw ? ;multiplier ;an000; dms;
114
115 Realloc_Struc Ends ;end structure ;an000; dms;
116
117 AAJ_Struc Struc ;BP addressible struc ;an000; dms;
118
119 AAJ_Reserved db size Instance_Entry_Struc dup (?) ;an000; dms;
120 AAJ_Xref_Pages dw ? ;save logical page count ;an000; dms;
121 AAJ_Handle dw ? ;saved handle ;an000; dms;
122 AAJ_Option db ? ;saved selector state ;an000; dms;
123 AAJ_LookUp_Index dw ? ;save index ;an000; dms;
124 AAJ_Mult dw ? ;multiplier ;an000; dms;
125
126 AAJ_Struc Ends ;end structure ;an000; dms;
127
128 MAC_Struc Struc ;BP addressible struc ;an000; dms;
129
130 MAC_Reserved_Area db size Instance_Entry_Struc dup (?) ;an000; dms;
131 MAC_LookUp_Index dw ? ;save index ;an000; dms;
132 MAC_Xref_Pages dw ? ;save logical page count ;an000; dms;
133 MAC_Option db ? ;saved selector state ;an000; dms;
134
135 EMS_Reg_ES dw ? ;ES reg ;an000; dms;
136 EMS_Reg_DS dw ? ;DS reg ;an000; dms;
137 EMS_Reg_FL dw ? ;FL reg ;an000; dms;
138 EMS_Reg_SI dw ? ;SI reg ;an000; dms;
139 EMS_Reg_DI dw ? ;DI reg ;an000; dms;
140 EMS_Reg_DX dw ? ;DX reg ;an000; dms;
141 EMS_Reg_CX dw ? ;CX reg ;an000; dms;
142 EMS_Reg_BX dw ? ;BX reg ;an000; dms;
143
144 MAC_M_C_Data db size Map_And_Call_Struc dup (?) ;an000; dms;
145 MAC_M_C_Log db size Log_Phys_Map_Struc*Map_Count_Def dup (?) ;an000; dms;
146 MAC_Map_Table db size Mappable_Phys_Page_Struct*Map_Count_Def dup (?) ;an000; dms;
147 MAC_Mult dw ? ;multiplier ;an000; dms;
148
149 MAC_Struc Ends ;end structure ;an000; dms;
150
151
152 ER_Struc Struc ;BP addressible struc ;an000; dms;
153
154 ER_Reserved db size Instance_Entry_Struc dup (?) ;an000; dms;
155 ER_Direction_Flag db ER_Up ;default to forward move;an000; dms;
156
157 ER_Sub_Function db ? ;save subfunction byte ;an000; dms;
158
159 ER_Src_Abs_Beg_Low dw ? ;abs add of src EMS page;an000; dms;
160 ER_Src_Abs_Beg_High dw ? ; beginning of trf area;an000; dms;
161 ER_Src_Abs_End_Low dw ? ;abs add of src EMS page;an000; dms;
162 ER_Src_Abs_End_High dw ? ; end of trf area ;an000; dms;
163
164 ER_Dst_Abs_Beg_Low dw ? ;abs add of src EMS page;an000; dms;
165 ER_Dst_Abs_Beg_High dw ? ; beginning of trf area;an000; dms;
166 ER_Dst_Abs_End_Low dw ? ;abs add of src EMS page;an000; dms;
167 ER_Dst_Abs_End_High dw ? ; end of trf area ;an000; dms;
168
169 ER_Current_Move_Count dw ? ;bytes moved this time ;an000; dms;
170
171 ER_Move_Xchg_Buffer1 db 10h dup (?) ;buffer for move/xchg ;an000; dms;
172 ER_Move_Xchg_Buffer2 db 10h dup (?) ;buffer for move/xchg ;an000; dms;
173
174 ER_Move_Count_Low dw ? ;low word of count ;an000; dms;
175 ER_Move_Count_High dw ? ;high word of count ;an000; dms;
176
177 ER_Source_Phys_Page dw ? ;page number of source ;an000; dms;
178 ER_Dest_Phys_Page dw ? ;page number of dest ;an000; dms;
179
180 ER_Source_Page dw ? ;active source page ;an000; dms;
181 ER_Dest_Page dw ? ;active dest page ;an000; dms;
182
183 ER_Source_Handle dw ? ;active handle ;an000; dms;
184 ER_Dest_Handle dw ? ;active handle ;an000; dms;
185 ; 10h byte moves
186
187 ER_Save_Context_Buffer dw 2*Type Mappable_Phys_Page_Struct dup (0) ;room for 2 pgs;an000; dms;
188
189 ER_Dest_Seg dw ? ;seg value of dest ;an000; dms;
190 ER_Source_Seg dw ? ;seg value of source ;an000; dms;
191
192 ER_Dest_Off dw ? ;off value of dest ;an000; dms;
193 ER_Source_Off dw ? ;off value of source ;an000; dms;
194
195 ER_Mem_Type dw ? ;memory type ;an000; dms;
196
197
198 ER_Struc Ends ;end structure ;an000; dms;
199
200 ;=========================================================================
201 ;========== End STRUC Definitions ========================================
202 ;=========================================================================
203
204 page
205 ;=========================================================================
206 ;========== Begin Macro Definitions ======================================
207 ;=========================================================================
208
209
210 ;=========================================================================
211 ; MAC_Expand_Stack_And_Copy : This routine will place data in the
212 ; instance table by copying the data pointed
213 ; at by ES:DI.
214 ;
215 ; Inputs : AX - Size of stack adjustment
216 ; ES:DI - Pointer to data to be copied to stack
217 ;
218 ; Outputs : BP - data place in instance table
219 ;
220 ;=========================================================================
221
222 MAC_Expand_Stack_And_Copy proc
223
224 mov cx,ax ;get adjustment factor ;an000; dms;
225 shr cx,1 ;convert to word move ;an000; dms;
226 mov ax,es ;get data source seg ;an000; dms;
227 mov ds,ax ;place in ds ;an000; dms;
228 mov si,di ;get data source off ;an000; dms;
229
230 mov ax,cs ;get dest. seg ;an000; dms;
231 mov es,ax ;place in es ;an000; dms;
232 mov di,bx ;get dest. off ;an000; dms;
233
234 cli ;ints off ;an000; dms;
235 rep movsw ;move data to stack ;an000; dms;
236 sti ;ints on ;an000; dms;
237
238 ret ;end routine ;an000; dms;
239
240 MAC_Expand_Stack_And_Copy endp
241
242 page
243 ;=========================================================================
244 ; MAC_Shrink_Stack_And_Copy : This routine move data from the instance
245 ; table and place it at ES:DI.
246 ;
247 ; Inputs : AX - Size of stack adjustment
248 ; ES:DI - Pointer to where data is to be copied
249 ;
250 ; Outputs : BP - data removed from instance table
251 ;
252 ;=========================================================================
253
254 MAC_Shrink_Stack_And_Copy proc
255
256 mov cx,ax ;get adjustment factor ;an000; dms;
257 mov ax,cs ;get data source seg ;an000; dms;
258 mov ds,ax ;place in ds ;an000; dms;
259 mov si,bx ;get data source off ;an000; dms;
260 mov ax,cx ;save count across move ;an000; dms;
261 shr cx,1 ;convert to word move ;an000; dms;
262
263 cli ;ints off ;an000; dms;
264 rep movsw ;move data from stack ;an000; dms;
265 sti ;ints on ;an000; dms;
266
267 ret ;end routine ;an000; dms;
268
269 MAC_Shrink_Stack_And_Copy endp
270
271
272 ;=========================================================================
273 ;========== End Macro Definitions ========================================
274 ;=========================================================================
275
276 page
277 ;=========================================================================
278 ;========== Begin Generic PROC Definitions ===============================
279 ;=========================================================================
280
281 ;=========================================================================
282 ; Map_Pages : This routine will map the pages being
283 ; requested in the struc pointed to by
284 ; DS:SI.
285 ;
286 ; Inputs : ES:DI - Pointer to data in Log_Phys_Map_Struc format
287 ; CX - Count of data iterations in ES:DI
288 ; DX - handle
289 ; BX - page count for handle
290 ; AL - option
291 ;
292 ; Outputs : Revised map
293 ; AH - 0 = no error
294 ; > 0 = error
295 ;=========================================================================
296
297 Map_Pages proc ; ;an000; dms;
298
299 push si ;save reg ;an000; dms;
300
301 mov si,ax ;save option ;an000; dms;
302 cmp cx,AAJ_No_Pages_To_Map ;no pages? ;an000; dms;
303 je Map_Error_Exit ;yes - exit loop ;an000; dms;
304
305 Map_Loop_Continue:
306
307 cmp [di].Log_Page_Number,bx ;logical page out of ;an000; dms;
308 ; range?
309 jbe Map_Get_Segment ;no - in range ;an000; dms;
310 mov ah,EMS_Code8A ;yes - out of range ;an000; dms;
311 jmp Map_Error_Exit ;exit routine ;an000; dms;
312
313 Map_Get_Segment:
314
315 cmp si,AAJ_Segment ;segment request? ;an000; dms;
316 mov ax,[di].Phys_Page_Number_Seg ;get physical page ;an000; dms;
317 jne Map_Page_Request ;no - page request ;an000; dms;
318 push dx ;save handle
319 mov dx,[di].Phys_Page_Number_Seg ;get segment ;an000; dms;
320 call Get_Phys_Seg_Page ;get the associated ;an000; dms;
321 ; page for the segment
322 mov ax,dx ;place page in ax ;an000; dms;
323 pop dx ;restore handle
324 jnc Map_Page_Request ;no error - continue ;an000; dms;
325 mov ah,EMS_Code8B ;phys page not found ;an000; dms;
326 jmp Map_Error_Exit ;exit routine ;an000; dms;
327
328 Map_Page_Request:
329
330 push bx ;save bx across call ;an000; dms;
331 mov bx,[di].Log_Page_Number ;logical page to map ;an000; dms;
332 call Map_L_To_P ;map the page ;an000; dms;
333 pop bx ;restore bx ;an000; dms;
334 or ah,ah ;error? ;an000; dms;
335 jnz Map_Error_Exit ;pass error on & exit ;an000; dms;
336 add di,Type Log_Phys_Map_Struc ;adjust pointer ;an000; dms;
337 loop Map_Loop_Continue ;continue loop ;an000; dms;
338 xor ax,ax ;signal good finish ;an000; dms;
339
340 Map_Error_Exit:
341
342 pop si ;restore reg ;an000; dms;
343
344 ret ;return to caller ;an000; dms;
345
346 Map_Pages endp ;end proc ;an000; dms;
347
348
349 page
350 ;=========================================================================
351 ; Get_Phys_Seg_Page : This routine will obtain the physical page
352 ; number for a given segment.
353 ;
354 ; Inputs : DX - Segment value
355 ; Outputs : DX - Physical page number
356 ; CY - Error
357 ; NC - No error
358 ;=========================================================================
359
360 Get_Phys_Seg_Page proc ;begin routine ;an000; dms;
361
362 push ax ;save regs ;an000; dms;
363 push cx ; ;an000; dms;
364 push di ; ;an000; dms;
365
366 cli ;ints off ;an000; dms;
367 mov di,offset Map_Table ;point to table map ;an000; dms;
368 mov cx,Map_Count ;number of table entries;an000; dms;
369 sti ;ints on ;an000; dms;
370
371 GPSP_Loop:
372
373 cli ;ints off ;an000; dms;
374 cmp dx,cs:[di].Phys_Page_Segment ;segment match? ;an000; dms;
375 je GPSP_Got_Segment ;yes ;an000; dms;
376 add di,Type Mappable_Phys_Page_Struct ;adjust pointer ;an000; dms;
377 loop GPSP_Loop ;continue search ;an000; dms;
378
379 GPSP_Got_Segment:
380
381 sti ;ints on ;an000; dms;
382 cmp cx,0 ;data found? ;an000; dms;
383 je GPSP_Not_Found ;exit with error ;an000; dms;
384 mov dx,cs:[di].Phys_Page_Number ;exit with page number ;an000; dms;
385 clc ;clear cy ;an000; dms;
386 jmp GPSP_Found ;exit ;an000; dms;
387
388 GPSP_Not_Found:
389
390 stc ;signal error ;an000; dms;
391
392 GPSP_Found: ;exit ;an000; dms;
393
394 pop di ;restore regs ;an000; dms;
395 pop cx ; ;an000; dms;
396 pop ax ; ;an000; dms;
397
398 ret ;return to caller ;an000; dms;
399
400 Get_Phys_Seg_Page endp ;end proc ;an000; dms;
401
402
403 ;=========================================================================
404 ;========== End Generic PROC Definitions =================================
405 ;=========================================================================
406
407
408
409 page
410
411 ;-------------------------------------------------------------------
412 ; Reallocate Pages - Function 18
413 ;
414 ; Entry - AX = 51??
415 ; BX = count of new allocation pages
416 ; DX = handle
417 ;
418 ; Exit - AH = status
419 ; BX = new page count
420 ; if error - original page count
421 ;-------------------------------------------------------------------
422 reallocate proc
423
424 push cx ;save affected regs ;an000; dms;
425 push dx ; ;an000; dms;
426 push di ; ;an000; dms;
427 push si ; ;an000; dms;
428
429 push ds ;save segments ;an000; dms;
430 push es ; ;an000; dms;
431
432 mov ax,cs ;get code segment ;an000; dms;
433 mov ds,ax ;put int ds and ;an000; dms;
434 mov es,ax ; es ;an000; dms;
435
436
437 mov cs:[bp].Realloc_Page_Count,bx ;new page count ;an000; dms;
438 mov cs:[bp].Realloc_Handle,dx ;handle ;an000; dms;
439
440
441
442 mov ax,cs:[bp].Realloc_Handle ;get handle for search ;an000; dms;
443 mov cs:[bp].Realloc_Mult,Type H_LookUp_Struc;handle lookup table ;an000; dms;
444 mul cs:[bp].Realloc_Mult ;obtain index position ;an000; dms;
445 mov cs:[bp].Realloc_LookUp_Index,ax ;index to handle ;an000; dms;
446 mov di,ax ;place index in si ;an000; dms;
447 mov dx,cs:[bp].Realloc_Handle ;get handle number ;an000; dms;
448
449
450 cmp dx,Num_Handles-1 ;dx > handle count? ;an000; dms;
451 jbe Realloc_Handle_Search ;handle within range ;an000; dms;
452 mov ah,EMS_Code83 ;EMS handle non-existent;an000; dms;
453 jmp Realloc_Error_Exit ;exit program ;an000; dms;
454
455 Realloc_Handle_Search:
456
457 cmp Handle_LookUp_Table.H_Pages[di],Reusable_Handle ;handle allocated ;an000; dms;
458 jne Realloc_Status_Of_Handle ;handle good ;an000; dms;
459 mov ah,EMS_Code83 ;EMS handle not alloc ;an000; dms;
460 jmp Realloc_Error_Exit ;exit program ;an000; dms;
461
462 Realloc_Status_Of_Handle:
463
464
465 mov ax,Handle_LookUp_Table.H_Pages[di] ;get current page count ;an000; dms;
466 sub ax,cs:[bp].Realloc_Page_Count ;more or less pages? ;an000; dms;
467 jc Realloc_More_Pages ;more pages to alloc ;an000; dms;
468
469 Realloc_Less_Pages:
470
471 mov bx,ax ;pages to deallocate ;an000; dms;
472 mov cs:[bp].Realloc_Page_Dealloc,ax ;save dealloc value ;an000; dms;
473
474 mov si,Handle_LookUp_Table.H_Pal_Ptr[di] ;get start of links ;an000; dms;
475 mov cx,Handle_LookUp_Table.H_Pages[di] ;current pages allocated;an000; dms;
476 sub cx,bx ;pages to remain alloc ;an000; dms;
477
478
479 Realloc_Dealloc_Loop1:
480
481 cmp cx,0 ;pages? ;an000; dms;
482 je Realloc_Dealloc_Loop1_Exit ;no - exit ;an000; dms;
483 shl si,1
484 mov si,Page_Alloc_List[si] ;get next pointer ;an000; dms;
485 dec cx ;dec loop count ;an000; dms;
486 jmp Realloc_Dealloc_Loop1 ;continue ;an000; dms;
487
488 Realloc_Dealloc_Loop1_Exit:
489
490 ;***** Adjust pointers *****
491
492 mov cx,cs:[bp].Realloc_Page_Dealloc ;get dealloc count ;an000; dms;
493 mov ax,cs:PAL_Free_Ptr ;get the free ptr ;an001; dms;
494 cmp cx,0 ;0 pages to dealloc? ;an001; dms;
495 je Realloc_Dealloc_Loop2_Exit1 ;yes - bypass dealloc ;an001; dms;
496 mov cs:PAL_Free_Ptr,si ;no - set new free ptr ;an001; dms;
497 dec cx ;don't loop past last pg;an001; dms;
498
499 Realloc_Dealloc_Loop2:
500
501 cmp cx,0 ;end of deallocate? ;an000; dms;
502 je Realloc_Dealloc_Loop2_Exit ;yes - exit ;an000; dms;
503 shl si,1 ;get index entry ;an001; dms;
504 mov si,Page_Alloc_List[si] ;get next ptr ;an001; dms;
505 dec cx ;decrement counter ;an000; dms;
506 jmp Realloc_Dealloc_Loop2
507
508 Realloc_Dealloc_Loop2_Exit:
509
510 shl si,1 ;get index entry ;an001; dms;
511 mov Page_Alloc_List[si],ax ;pt. last page to orig. ;an001; dms;
512 ; free ptr.
513
514 Realloc_Dealloc_Loop2_Exit1:
515
516 mov ax,cs:[bp].Realloc_Page_Count ;new page count ;an000; dms;
517 mov Handle_LookUp_Table.H_Pages[di],ax ; ;an000; dms;
518
519 mov ax,cs:[bp].Realloc_Page_Dealloc ;adj. value ;an000; dms;
520 add cs:Free_Pages,ax ;free up page ;an000; dms;
521
522 mov bx,cs:[bp].Realloc_Page_Count ;pass back page request ;an000; dms;
523 xor ah,ah ;clear error ;an000; dms;
524 jmp Realloc_Exit ;exit ;an000; dms;
525
526 Realloc_More_Pages:
527
528 mov cx,cs:[bp].Realloc_Page_Count ;get page request count ;an000; dms;
529 mov di,cs:[bp].Realloc_LookUp_Index ;get LookUp Table ptr ;an000; dms;
530 mov ax,Handle_LookUp_Table.H_Pages[di] ;get current page count ;an000; dms;
531 sub cx,ax ;get additional pages ;an000; dms;
532 mov cs:[bp].Realloc_Page_Alloc,cx ;new pages to alloc ;an000; dms;
533 cmp cx,Free_Pages ;> pages remaining? ;an000; dms;
534 jbe Realloc_Pages ;reallocate pages ;an000; dms;
535 mov ah,EMS_Code87 ;Too few pages avail ;an000; dms;
536 jmp Realloc_Error_Exit ;exit prog ;an000; dms;
537
538 Realloc_Pages:
539
540 mov cx,Handle_LookUp_Table.H_Pages[di] ;current pages allocated;an000; dms;
541 cmp cx,0 ;any pages? ;an000; dms;
542 jne Realloc_More_Pages_Cont ;yes ;an000; dms;
543 cmp cs:[bp].Realloc_Page_Alloc,0 ;any pages requested? ;an000; dms;
544 je Realloc_Alloc_Loop1_Exit ;continue ;an000; dms;
545
546 mov cx,cs:[bp].Realloc_Page_Alloc ;get new page count ;an001; dms;
547 cli ;ints off ;an001; dms;
548 call EMS_Page_Contig_Chk ;contig pages avail? ;an001; dms;
549 jnc Realloc_New_Pages
550 mov ah,EMS_Code87 ;Too few pages avail ;an000; dms;
551 sti ;ints on ;an001; dms;
552 jmp Realloc_Error_Exit ;exit prog ;an000; dms;
553
554 Realloc_New_Pages:
555
556 call EMS_Link_Set ;set up page list ;an001; dms;
557
558 mov Handle_LookUp_Table.H_Pal_Ptr[di],si ;set table to pointer ;an000; dms;
559 mov Handle_LookUp_Table.H_Pages[di],cx ;new page count ;an000; dms;
560 mov bx,cs:[bp].Realloc_Page_Count ;return new page count ;an001; dms;
561 sub cs:Free_Pages,bx ;new free count ;an000; dms;
562 sti ;ints on ;an001; dms;
563 xor ax,ax ;clear error flag ;an001; dms;
564
565 jmp Realloc_Exit ;exit routine ;an001; dms;
566
567
568 Realloc_More_Pages_Cont:
569
570 dec cx
571 mov si,Handle_LookUp_Table.H_Pal_Ptr[di] ;get start of links ;an000; dms;
572
573 Realloc_Alloc_Loop1:
574 cmp cx,0 ;at end ;an000; dms;
575 je Realloc_Alloc_Loop1_Exit ;yes ;an000; dms;
576 shl si,1 ;word entry ;an000; dms;
577 mov si,Page_Alloc_List[si] ;get next pointer ;an000; dms;
578 dec cx ;decrement loop count ;an000; dms;
579 jmp Realloc_Alloc_Loop1 ;continue ;an000; dms;
580
581 Realloc_Alloc_Loop1_Exit:
582
583 mov cx,cs:[bp].Realloc_Page_Alloc ;new pages to alloc ;an000; dms;
584 cmp cx,0 ;pages requested? ;an001; dms;
585 je Realloc_Alloc_Exit ;no - exit routine ;an001; dms;
586
587 mov bx,si ;save si ;an001; dms;
588 cli ;ints off ;an001; dms;
589 call EMS_Page_Contig_Chk ;contig pages? ;an001; dms;
590 jnc Realloc_Next_Pages ;yes ;an001; dms;
591 mov ah,EMS_Code87 ;Too few pages avail ;an000; dms;
592 sti ;ints on ;an001; dms;
593 jmp Realloc_Error_Exit ;exit prog ;an000; dms;
594
595 Realloc_Next_Pages:
596
597 ;;;; mov ax,si ;ptr to new list ;an001; dms;
598 ;;;; inc ax ;contig to new links? ;an001; dms;
599 ;;;; cmp ax,bx ; ;an001; dms;
600 ;;;; je Realloc_Next_Pages1 ;yes continue ;an001; dms;
601 ;;;; mov ah,EMS_Code87 ;Too few pages avail ;an000; dms;
602 ;;;; sti ;ints on ;an001; dms;
603 ;;;; jmp Realloc_Error_Exit ;exit prog ;an000; dms;
604
605 Realloc_Next_Pages1:
606
607 call EMS_Link_Set ;set up page list ;an001; dms;
608 mov ax,si ;ptr to new list ;an001; dms;
609 mov si,bx ;end of old list ;an001; dms;
610 shl si,1 ;index entry ;an001; dms;
611 mov Page_Alloc_List[si],ax ;pick up new links ;an001; dms;
612
613 Realloc_Alloc_Exit:
614
615 mov bx,cs:[bp].Realloc_Page_Alloc ;additional pages ;an001; dms;
616 sub cs:Free_Pages,bx ;new free count ;an000; dms;
617 mov bx,cs:[bp].Realloc_Page_Count ;pass back page request ;an000; dms;
618 mov Handle_LookUp_Table.H_Pages[di],bx ;new page count ;an000; dms;
619 sti ;ints on ;an001; dms;
620 xor ah,ah ;clear ah ;an000; dms;
621 jmp Realloc_Exit ;exit ;an000; dms;
622
623
624 Realloc_Error_Exit:
625
626 cli ;ints off ;an000; dms;
627 mov si,cs:[bp].Realloc_LookUp_Index ;get handle index ;an000; dms;
628 mov bx,Handle_LookUp_Table.H_Pages[si] ;get orig. count ;an000; dms;
629 mov Handle_LookUp_Table.H_Pages[si],bx ;new page count ;an000; dms;
630 sti ;ints on ;an000; dms;
631
632 Realloc_Exit:
633
634 pop es ;restore segments ;an000; dms;
635 pop ds ; ;an000; dms;
636
637 pop si ;restore regs ;an000; dms;
638 pop di ; ;an000; dms;
639 pop dx ; ;an000; dms;
640 pop cx ; ;an000; dms;
641
642 ret ;return to caller ;an000; dms;
643
644 reallocate endp
645
646
647
648 page
649 ;=========================================================================
650 ;=============== Function 55h Logic - Alter Page Map & Jump =============
651 ;=========================================================================
652 ;=========================================================================
653 ; Alter_And_Jump - This routine alters the page map and jumps
654 ; to the specified address.
655 ;
656 ; Inputs : AH - 55h (Alter page map & jump)
657 ; AL - Physical page number/segment selector
658 ; 0 = Physical page numbers specified
659 ; 1 = Segment addresses specified in lieu of
660 ; physical page numbers
661 ; DX - handle number
662 ; DS:SI - Pointer to map and jump structure
663 ; (see Map_And_Jump_Struct above)
664 ;
665 ; Outputs : Revised map
666 ; AH - Non-zero if error
667 ;
668 ;=========================================================================
669 Alter_And_Jump proc ;modify map ;an000; dms;
670
671 push bx ;save regs for jump ;an000; dms;
672 push cx ; ;an000; dms;
673 push di ; ;an000; dms;
674 push si ; ;an000; dms;
675
676 pushf ;save flags ;an000; dms;
677 push ds ;save segments ;an000; dms;
678 push es ; ;an000; dms;
679
680 mov bx,cs ;get code segment ;an000; dms;
681 mov es,bx ; es ;an000; dms;
682
683 mov cs:[bp].AAJ_Handle,dx ;save handle ;an000; dms;
684 mov cs:[bp].AAJ_Option,al ;save selector option ;an000; dms;
685
686
687
688 cmp dx,Num_Handles-1 ;dx > handle count ;an000; dms;
689 jbe AAJ_Check_Reusable ;continue test ;an000; dms;
690 mov ah,EMS_Code83 ;EMS handle bad ;an000; dms;
691 jmp AAJ_Error_Exit ;exit routine ;an000; dms;
692
693 AAJ_Check_Reusable:
694
695 mov ax,dx ;get handle ;an000; dms;
696 mov cs:[bp].AAJ_Mult,Type H_LookUp_Struc ;handle lookup table ;an000; dms;
697 mul cs:[bp].AAJ_Mult ;obtain index position ;an000; dms;
698 mov cs:[bp].AAJ_LookUp_Index,ax ;index to handle ;an000; dms;
699 mov di,ax ;place index in di ;an000; dms;
700
701 cli ;ints off ;an000; dms;
702 mov ax,Handle_LookUp_Table.H_Pages[di] ;get logical page count ;an000; dms;
703 mov cs:[bp].AAJ_Xref_Pages,ax ;save logical page count;an000; dms;
704 sti ;ints on ;an000; dms;
705 cmp Handle_LookUp_Table.H_Pages[di],Reusable_Handle ;handle allocated ;an000; dms;
706 jne AAJ_Good_Handle ;handle good ;an000; dms;
707 mov ah,EMS_Code83 ;EMS handle bad ;an000; dms;
708 jmp AAJ_Error_Exit ;exit routine ;an000; dms;
709
710 AAJ_Good_Handle:
711
712 cmp cs:[bp].AAJ_Option,AAJ_Option_Max ;option in range? ;an000; dms;
713 jbe AAJ_Good_Option ;option good ;an000; dms;
714 mov ah,EMS_Code8F ;bad option ;an000; dms;
715 jmp AAJ_Error_Exit ;exit routine ;an000; dms;
716
717 AAJ_Good_Option:
718
719 les di,[si].Log_Phys_Map_Ptr ;point to map data ;an000; dms;
720 xor cx,cx ;clear loop counter ;an000; dms;
721 mov cl,[si].Log_Phys_Map_Len ;get loop count ;an000; dms;
722 mov dx,cs:[bp].AAJ_Handle ;get handle for call ;an000; dms;
723 mov bx,cs:[bp].AAJ_Xref_Pages ;logical page count ;an000; dms;
724 xor ah,ah ;clear high word ;an000; dms;
725 mov al,cs:[bp].AAJ_Option ;option selected ;an000; dms;
726 call Map_Pages ;map the pages requested;an000; dms;
727 or ah,ah ;error? ;an000; dms;
728 jnz AAJ_Error_Exit ;exit with error cond. ;an000; dms;
729
730 AAJ_Loop_Exit:
731
732 pop es ;restore regs ;an000; dms;
733 pop ds ; ;an000; dms;
734 popf ; ;an000; dms;
735 pop si ; ;an000; dms;
736 pop di ; ;an000; dms;
737 pop cx ; ;an000; dms;
738 pop bx ; ;an000; dms;
739
740 mov cs:[bp].IE_Alloc_Byte,Unallocated ;deallocate instance ;an000; dms;
741
742 jmp dword ptr [si].Target_Address ;jump to address & run ;an000; dms;
743
744 AAJ_Error_Exit:
745
746 pop es ;restore regs ;an000; dms;
747 pop ds ; ;an000; dms;
748 popf ; ;an000; dms;
749 pop si ; ;an000; dms;
750 pop di ; ;an000; dms;
751 pop cx ; ;an000; dms;
752 pop bx ; ;an000; dms;
753
754
755 ret ;return to caller ;an000; dms;
756
757 Alter_And_Jump endp ;end proc ;an000; dms;
758
759
760
761 page
762 ;=========================================================================
763 ;=============== Function 56h Logic - Alter Page Map & Call =============
764 ;=========================================================================
765
766
767
768 ;=========================================================================
769 ; Alter_And_Call - This routine alters the page map and calls
770 ; the specified address. The mapping context
771 ; is saved on entry to the routine and restored
772 ; on exit from the routine.
773 ;
774 ; Inputs : AH - 56h (Alter page map & call)
775 ; AL - Physical page number/segment selector
776 ; 0 = Physical page numbers specified
777 ; 1 = Segment addresses specified in lieu of
778 ; physical page numbers
779 ; 2 = Give minimum required stack size
780 ; DX - handle number
781 ; DS:SI - Pointer to map and jump structure
782 ; (see Map_And_Call_Struc above)
783 ;
784 ; Outputs : Revised map
785 ; AH - Non-zero if error
786 ; BX - Function 2 = size in bytes needed for stack
787 ;
788 ;=========================================================================
789
790
791 Alter_And_Call proc ;modify map & call ;an000; dms;
792
793 cmp al,MAC_Stack_Status_Request ;stack report? ;an000; dms;
794 je MAC_Calc_Stack_Status ;yes ;an000; dms;
795 jb MAC_Alter_And_Call ;no - new mapping ;an000; dms;
796 mov ah,EMS_Code8F ;error occurred ;an000; dms;
797 jmp MAC_Stack_Exit ;exit routine ;an000; dms;
798
799 MAC_Calc_Stack_Status:
800
801 mov bx,8h ;room for call address ;an000; dms;
802 ; and return address
803 xor ax,ax ;signal no error ;an000; dms;
804 jmp MAC_Stack_Exit ;exit routine ;an000; dms;
805
806 MAC_Alter_And_Call:
807
808 cli ;ints off ;an000; dms;
809 mov cs:[bp].EMS_Reg_BX,bx ; ;an000; dms;
810 mov bx,ax ;save ax across flags ;an000; dms;
811 lahf ;move flags to ah ;an000; dms;
812 mov cs:[bp].EMS_Reg_FL,ax ;save flags ;an000; dms;
813 mov ax,bx ;restore ax ;an000; dms;
814 mov cs:[bp].EMS_Reg_CX,cx ; ;an000; dms;
815 mov cs:[bp].EMS_Reg_DX,dx ; ;an000; dms;
816 mov cs:[bp].EMS_Reg_DI,di ; ;an000; dms;
817 mov cs:[bp].EMS_Reg_SI,si ; ;an000; dms;
818 mov cs:[bp].EMS_Reg_DS,ds ; ;an000; dms;
819 mov cs:[bp].EMS_Reg_ES,es ; ;an000; dms;
820
821 mov cs:[bp].MAC_Option,al ;save option ;an000; dms;
822 sti ;ints on ;an000; dms;
823 cmp dx,Num_Handles-1 ;dx > handle count ;an000; dms;
824 jbe MAC_Check_Reusable ;continue test ;an000; dms;
825 mov ah,EMS_Code83 ;EMS handle bad ;an000; dms;
826 jmp MAC_Error_Exit ;exit routine ;an000; dms;
827
828 MAC_Check_Reusable:
829
830 mov ax,dx ;get handle ;an000; dms;
831 mov cs:[bp].MAC_Mult,Type H_LookUp_Struc ;handle lookup table ;an000; dms;
832 mul cs:[bp].MAC_Mult ;obtain index position ;an000; dms;
833 mov cs:[bp].MAC_LookUp_Index,ax ;index to handle ;an000; dms;
834 mov di,ax ;place index in di ;an000; dms;
835
836 cli ;ints off ;an000; dms;
837 mov ax,Handle_LookUp_Table.H_Pages[di] ;get logical page count ;an000; dms;
838 mov cs:[bp].MAC_Xref_Pages,ax ;save logical page count;an000; dms;
839 cmp Handle_LookUp_Table.H_Pages[di],Reusable_Handle ;handle allocated ;an000; dms;
840 sti ;ints on ;an000; dms;
841 jne MAC_Verify_New_Count ;handle good ;an000; dms;
842 mov ah,EMS_Code83 ;EMS handle bad ;an000; dms;
843 jmp MAC_Error_Exit ;exit routine ;an000; dms;
844
845 MAC_Verify_New_Count:
846
847 cli ;ints off ;an000; dms;
848 mov ax,Map_Count ;get phys. page count ;an000; dms;
849 sti ;ints on ;an000; dms;
850 cmp [si].MAC_New_Page_Map_Len,al ;> physical pages ;an000; dms;
851 jbe MAC_Verify_Old_Count ;no - continue ;an000; dms;
852 mov ah,EMS_Code8B ;out of range ;an000; dms;
853 jmp MAC_Error_Exit ;exit routine ;an000; dms;
854
855 MAC_Verify_Old_Count:
856
857 cli ;ints off ;an000; dms;
858 mov ax,Map_Count ;get phys. page count ;an000; dms;
859 sti ;ints on ;an000; dms;
860 cmp [si].MAC_Old_Page_Map_Len,al ;> physical pages ;an000; dms;
861 jbe MAC_Do_Alter_and_Call ;no - continue ;an000; dms;
862 mov ah,EMS_Code8B ;yes - error ;an000; dms;
863 jmp MAC_Error_Exit ;exit routine ;an000; dms;
864
865 MAC_Do_Alter_And_Call:
866
867 jmp MAC_Build_Stack_And_Map ;build stack and map ;an000; dms;
868 ; new pages
869 MAC_Return_Routine:
870
871 jmp MAC_Strip_Stack_And_Map ;restore data strucs ;an000; dms;
872 ; and map old pages
873
874 MAC_Exit:
875 MAC_Error_Exit:
876
877 cli ;ints off ;an000; dms;
878 mov bx,ax ;save ax ;an000; dms;
879 mov ax,cs:[bp].EMS_Reg_FL ;obtain entry flag stat ;an000; dms;
880 sahf ;put in flags reg ;an000; dms;
881 mov ax,bx ;restore ax ;an000; dms;
882 mov bx,cs:[bp].EMS_Reg_BX ; ;an000; dms;
883 mov cx,cs:[bp].EMS_Reg_CX ; ;an000; dms;
884 mov dx,cs:[bp].EMS_Reg_DX ; ;an000; dms;
885 mov di,cs:[bp].EMS_Reg_DI ; ;an000; dms;
886 mov si,cs:[bp].EMS_Reg_SI ; ;an000; dms;
887 mov ds,cs:[bp].EMS_Reg_DS ; ;an000; dms;
888 mov es,cs:[bp].EMS_Reg_ES ; ;an000; dms;
889 sti ;ints on ;an000; dms;
890
891 MAC_Stack_Exit:
892
893 ret ;return to caller ;an000; dms;
894
895
896 ;=========================================================================
897 ; MAC_Build_Stack_And_Map : This routine will build the required
898 ; stack structure for a re-entrant
899 ; routine and map the new pages.
900 ;
901 ; Inputs : DS:SI - Pointer to data in Map_And_Call_Struc format
902 ;
903 ; Outputs : BP - Instance table to reflect data copyied to it
904 ; New mapped pages
905 ; AH - 0 = no error
906 ; >0 = error (determined by Map_Pages)
907 ;
908 ; Instance Table carries this data: Old Map Data
909 ; New Map Data
910 ; Map & Call Data
911 ; Context
912 ;=========================================================================
913
914 MAC_Build_Stack_And_Map:
915
916 mov cs:[bp].EMS_Reg_DS,ds ;save DS ;an000; dms;
917 mov cs:[bp].EMS_Reg_SI,si ;save SI ;an000; dms;
918
919 mov ax,word ptr [si].MAC_Old_Page_Map_Ptr[+2];get the segment ;an000; dms;
920 mov es,ax ; of the old map ;an000; dms;
921 mov di,word ptr [si].MAC_Old_Page_Map_Ptr[+0];get its offset ;an000; dms;
922
923 mov al,[si].MAC_Old_Page_Map_Len ;get length of data ;an000; dms;
924 cbw ;convert to word ;an000; dms;
925 xor dx,dx ;clear high word ;an000; dms;
926 mov bx,Type Log_Phys_Map_Struc ;struc size
927 mul bx ;get total byte count ;an000; dms;
928 cli ;ints off ;an000; dms;
929 mov bx,offset MAC_M_C_Log ;offset in struc ;an000; dms;
930 sti ;ints on ;an000; dms;
931 add bx,bp ;actual offset ;an000; dms;
932 call MAC_Expand_Stack_And_Copy ;set up stack for ;an000; dms;
933 ; copy of data and
934 ; copy the data
935 mov ds,cs:[bp].EMS_Reg_DS ;restore ds ;an000; dms;
936 mov si,cs:[bp].EMS_Reg_SI ;restore si ;an000; dms;
937
938 mov ax,word ptr [si].MAC_New_Page_Map_Ptr[+2];get the segment ;an000; dms;
939 mov es,ax ; of the old map ;an000; dms;
940 mov di,word ptr [si].MAC_New_Page_Map_Ptr[+0];get its offset ;an000; dms;
941
942 mov al,[si].MAC_New_Page_Map_Len ;get length of data ;an000; dms;
943 cbw ;conver to word ;an000; dms;
944 xor dx,dx ;clear high word ;an000; dms;
945 mov bx,Type Log_Phys_Map_Struc ;struc size
946 mul bx ;get total byte count ;an000; dms;
947 cli ;ints off ;an000; dms;
948 mov bx,offset MAC_M_C_Log ;Ptr in struc ;an000; dms;
949 add bx,size MAC_M_C_Log/2 ;next entry ;an000; dms;
950 sti ;ints on ;an000; dms;
951 add bx,bp ;offset BP relative ;an000; dms;
952 call MAC_Expand_Stack_And_Copy ;set up stack for ;an000; dms;
953 ; copy of data and
954 ; copy the data
955 mov ds,cs:[bp].EMS_Reg_DS ;restore ds ;an000; dms;
956 mov si,cs:[bp].EMS_Reg_SI ;restore si ;an000; dms;
957
958 mov ax,ds ;move seg of data to ;an000; dms;
959 mov es,ax ; es ;an000; dms;
960 mov di,si ;move off of data ;an000; dms;
961 mov ax,Type Map_And_Call_Struc ;get size of structure ;an000; dms;
962 cli ;ints off ;an000; dms;
963 mov bx,offset MAC_M_C_Data
964 sti ;ints on ;an000; dms;
965 add bx,bp ;offset BP relative ;an000; dms;
966 call MAC_Expand_Stack_And_Copy ;set up stack for ;an000; dms;
967 ; copy of data and
968 ; copy the data
969 mov ds,cs:[bp].EMS_Reg_DS ;restore ds ;an000; dms;
970 mov si,cs:[bp].EMS_Reg_SI ;restore si ;an000; dms;
971
972 mov ax,cs ;get seg of context ;an000; dms;
973 mov es,ax ; in es ;an000; dms;
974 cli ;ints off ;an000; dms;
975 mov di,offset cs:Map_Table ;get offset of context ;an000; dms;
976 mov ax,Map_Count ;get context entry count;an000; dms;
977 sti ;ints on ;an000; dms;
978 xor dx,dx ;clear dx ;an000; dms;
979 mov bx,Type Mappable_Phys_Page_Struct ;get struc size ;an000; dms;
980 mul bx ;get size in bytes ;an000; dms;
981 cli ;ints off ;an000; dms;
982 mov bx,offset cs:MAC_Map_Table
983 sti ;ints on ;an000; dms;
984 add bx,bp ;offset BP relative ;an000; dms;
985 call MAC_Expand_Stack_And_Copy ;set up stack for ;an000; dms;
986 ; copy of data and
987 ; copy the data
988 mov ds,cs:[bp].EMS_Reg_DS ;restore ds ;an000; dms;
989 mov si,cs:[bp].EMS_Reg_SI ;restore si ;an000; dms;
990
991 push cs ;save return segment ;an000; dms;
992 mov ax,offset MAC_Return_Routine ;save return offset ;an000; dms;
993 push ax ; ;an000; dms;
994
995 mov ax,word ptr [si].MAC_Target_Address[+2] ;get seg of call far ;an000; dms;
996 mov bx,word ptr [si].MAC_Target_Address[+0] ;get offset of call far ;an000; dms;
997 push ax ;put on stack ;an000; dms;
998 push bx ; ;an000; dms;
999
1000 les di,[si].MAC_New_Page_Map_Ptr ;set up for call ;an000; dms;
1001 xor cx,cx ;clear cx ;an000; dms;
1002 mov cl,[si].MAC_New_Page_Map_Len ;get array size ;an000; dms;
1003 mov dx,cs:[bp].EMS_Reg_DX ;get handle for call ;an000; dms;
1004 mov bx,cs:[bp].MAC_Xref_Pages ;get handle page count ;an000; dms;
1005 xor ah,ah ;clear high word ;an000; dms;
1006 mov al,cs:[bp].MAC_Option ;get option ;an000; dms;
1007
1008 call Map_Pages ;map the new pages ;an000; dms;
1009 or ah,ah ;error? ;an000; dms;
1010 jnz MAC_Error_Strip_Stack ;take data off stack ;an000; dms;
1011
1012 cli ;ints off ;an000; dms;
1013 mov ax,cs:[bp].EMS_Reg_FL ;obtain entry flag stat ;an000; dms;
1014 sahf ;put in flags reg ;an000; dms;
1015 mov bx,cs:[bp].EMS_Reg_BX ; ;an000; dms;
1016 mov cx,cs:[bp].EMS_Reg_CX ; ;an000; dms;
1017 mov dx,cs:[bp].EMS_Reg_DX ; ;an000; dms;
1018 mov di,cs:[bp].EMS_Reg_DI ; ;an000; dms;
1019 mov si,cs:[bp].EMS_Reg_SI ; ;an000; dms;
1020 mov ds,cs:[bp].EMS_Reg_DS ; ;an000; dms;
1021 mov es,cs:[bp].EMS_Reg_ES ; ;an000; dms;
1022 sti ;ints on ;an000; dms;
1023
1024 Retf_Fake_Out Proc Far ;this proc is to ;an000; dms;
1025 ; simulate a RETF
1026 ; instruction
1027 ret ;performs a far return ;an000; dms;
1028
1029 Retf_Fake_Out Endp ;end of retf fake out ;an000; dms;
1030
1031
1032 MAC_Error_Strip_Stack:
1033
1034 add sp,8h ;adjust for return add. ;an000; dms;
1035 ; and target add. on
1036 ; error
1037 jmp MAC_Error_Exit ;exit routine ;an000; dms;
1038
1039
1040 ;=========================================================================
1041 ; MAC_Strip_Stack_And_Map : This routine will strip the stack of all
1042 ; the data placed on by MAC_Build_Stack_And_Map.
1043 ;
1044 ; Inputs : CS:BP - Pointer to data on the instance table
1045 ;
1046 ; Outputs : All data area restored
1047 ; Pages remapped to original
1048 ; AH - 0 = no error
1049 ; >0 = error (determined by Map_Pages)
1050 ;
1051 ; Instance Table carries this data: Old Map Data
1052 ; New Map Data
1053 ; Map & Call Data
1054 ; Context
1055 ;=========================================================================
1056
1057 MAC_Strip_Stack_And_Map: ;an000; dms;
1058
1059 mov ax,cs ;seg of context ;an000; dms;
1060 mov es,ax ;place in es ;an000; dms;
1061 cli ;ints off ;an000; dms;
1062 mov di,offset cs:Map_Table ;get off of context ;an000; dms;
1063 mov ax,Map_Count ;get entries in context ;an000; dms;
1064 sti ;ints on ;an000; dms;
1065 xor dx,dx ;clear dx ;an000; dms;
1066 mov bx,Type Mappable_Phys_Page_Struct ;struc size ;an000; dms;
1067 mul bx ;get byte count ;an000; dms;
1068 cli ;ints off ;an000; dms;
1069 mov bx,offset MAC_Map_Table
1070 sti ;ints on ;an000; dms;
1071 add bx,bp ;offset BP relative ;an000; dms;
1072 call MAC_Shrink_Stack_And_Copy ;restore context ;an000; dms;
1073
1074 mov si,cs:[bp].EMS_Reg_SI ;restore pointer ;an000; dms;
1075 mov ds,cs:[bp].EMS_Reg_DS ; to data struc ;an000; dms;
1076
1077 mov ax,ds ;transfer seg of struc ;an000; dms;
1078 mov es,ax ; to dest. segment ;an000; dms;
1079 mov di,si ;di=dest. offset ;an000; dms;
1080 mov ax,Type Map_And_Call_Struc ;get size to move ;an000; dms;
1081 cli ;ints off ;an000; dms;
1082 mov bx,offset MAC_M_C_Data
1083 sti ;ints on ;an000; dms;
1084 add bx,bp ;offset BP relative ;an000; dms;
1085 call MAC_Shrink_Stack_And_Copy ;restore Map & Call buf ;an000; dms;
1086
1087 mov ds,cs:[bp].EMS_Reg_DS ;restore ds ;an000; dms;
1088 mov si,cs:[bp].EMS_Reg_SI ;restore si ;an000; dms;
1089
1090 mov ax,word ptr [si].MAC_New_Page_Map_Ptr[+2];get the segment ;an000; dms;
1091 mov es,ax ; of the old map ;an000; dms;
1092 mov di,word ptr [si].MAC_New_Page_Map_Ptr[+0];get its offset ;an000; dms;
1093
1094 mov al,[si].MAC_New_Page_Map_Len ;get length of data ;an000; dms;
1095 cbw ;convert to word ;an000; dms;
1096 xor dx,dx ;clear high word ;an000; dms;
1097 mov bx,Type Log_Phys_Map_Struc ;struc size ;an000; dms;
1098 mul bx ;get total byte count ;an000; dms;
1099 cli ;ints off ;an000; dms;
1100 mov bx,offset MAC_M_C_Log
1101 sti ;ints on ;an000; dms;
1102 add bx,size MAC_M_C_Log/2
1103 add bx,bp ;offset BP relative ;an000; dms;
1104 call MAC_Shrink_Stack_And_Copy ;restore new page data ;an000; dms;
1105
1106 mov ds,cs:[bp].EMS_Reg_DS ;restore ds ;an000; dms;
1107 mov si,cs:[bp].EMS_Reg_SI ;restore si ;an000; dms;
1108
1109 mov ax,word ptr [si].MAC_Old_Page_Map_Ptr[+2];get the segment ;an000; dms;
1110 mov es,ax ; of the old map ;an000; dms;
1111 mov di,word ptr [si].MAC_Old_Page_Map_Ptr[+0];get its offset ;an000; dms;
1112
1113 mov al,[si].MAC_Old_Page_Map_Len ;get length of data ;an000; dms;
1114 cbw ;convert to word ;an000; dms;
1115 xor dx,dx ;clear high word ;an000; dms;
1116 mov bx,Type Log_Phys_Map_Struc ;struc size ;an000; dms;
1117 mul bx ;get total byte count ;an000; dms;
1118 cli ;ints off ;an000; dms;
1119 mov bx,offset MAC_M_C_Log
1120 sti ;ints on ;an000; dms;
1121 add bx,bp ;offset BP relative ;an000; dms;
1122 call MAC_Shrink_Stack_And_Copy ;set up stack for ;an000; dms;
1123
1124 mov ds,cs:[bp].EMS_Reg_DS ;restore ds ;an000; dms;
1125 mov si,cs:[bp].EMS_Reg_SI ;restore si ;an000; dms;
1126
1127 mov dx,cs:[bp].EMS_Reg_DX ;get DX reg
1128
1129 les di,[si].MAC_Old_Page_Map_Ptr ;set up for call ;an000; dms;
1130 xor cx,cx ;clear cx ;an000; dms;
1131 mov cl,[si].MAC_Old_Page_Map_Len ;get array size ;an000; dms;
1132 mov bx,cs:[bp].MAC_Xref_Pages ;get handle page count ;an000; dms;
1133 xor ah,ah ;clear high byte ;an000; dms;
1134 mov al,cs:[bp].MAC_Option ;get option ;an000; dms;
1135
1136 call Map_Pages ;map the new pages ;an000; dms;
1137
1138 jmp MAC_Exit ;exit the program ;an000; dms;
1139
1140
1141 Alter_And_Call endp ;end proc ;an000; dms;
1142
1143
1144 page
1145 ;=========================================================================
1146 ;=============== Function 57h Logic - Move/Exchange Memory Region =======
1147 ;=========================================================================
1148
1149 ;=========================================================================
1150 ; Exchng_Region - This routine moves/exchanges memory regions
1151 ; specified by the user. The following types of
1152 ; moves/exchanges are possible:
1153 ;
1154 ; Source Destination
1155 ; ------------------- ----------------------
1156 ; Conventional Memory Expanded Memory
1157 ; Expanded Memory Conventional Memory
1158 ; Expanded Memory Expanded Memory
1159 ;
1160 ; Inputs : AH - 57h (Move/Exchange Memory Region)
1161 ; AL - Type of transfer
1162 ; 0 = Move memory
1163 ; 1 = Exchange memory
1164 ; DS:SI - Pointer to Move_Source_Dest Structure
1165 ;
1166 ; Outputs : Revised map
1167 ; AH - Non-zero if error
1168 ;=========================================================================
1169
1170
1171 Exchng_Region proc
1172
1173 push bx ;save regs ;an000; dms;
1174 push cx ; ;an000; dms;
1175 push dx ; ;an000; dms;
1176 push di ; ;an000; dms;
1177 push si ; ;an000; dms;
1178 push ds ; ;an000; dms;
1179 push es ; ;an000; dms;
1180
1181 mov cs:[bp].ER_Sub_Function,al ;save subfunction ;an000; dms;
1182 cmp al,ER_Max_Function ;valid function? ;an000; dms;
1183 jbe ER_Valid_Sub_Function ;yes - continue ;an000; dms;
1184 mov ah,EMS_Code8F ;no - error ;an000; dms;
1185 jmp ER_Error_Exit ;exit routine ;an000; dms;
1186
1187 ER_Valid_Sub_Function:
1188
1189 call ER_Type_Check ;Proper types & ;an000; dms;
1190 or ah,ah ; type combinations? ;an000; dms;
1191 jnz ER_Error_Exit ;no - exit routine ;an000; dms;
1192
1193 call ER_Handle_Check ;valid handles? ;an000; dms;
1194 or ah,ah ; ;an000; dms;
1195 jnz ER_Error_Exit ;no - exit routine ;an000; dms;
1196
1197 call ER_Length_Check ;Region fits in page ;an000; dms;
1198 or ah,ah ; and <= 1Mb? ;an000; dms;
1199 jnz ER_Error_Exit ;no - exit routine ;an000; dms;
1200
1201 call ER_Wrap_Check ;> 1Mb wrap on move? ;an000; dms;
1202 or ah,ah ; ;an000; dms;
1203 jnz ER_Error_Exit ;yes - exit routine ;an000; dms;
1204
1205 call ER_Overlap_Check ;conv. memory overlaps ;an000; dms;
1206 or ah,ah ; EMS page frame? ;an000; dms;
1207 jnz ER_Error_Exit ;yes - exit routine ;an000; dms;
1208
1209 call ER_Log_Page_Test ;offset valid for log. ;an000; dms;
1210 or ah,ah ; page? ;an000; dms;
1211 jnz ER_Error_Exit ;no - exit routine ;an000; dms;
1212
1213 cmp cs:[bp].ER_Sub_Function,ER_Move ;move? ;an000; dms;
1214 je ER_Move_Call ;yes - perform move ;an000; dms;
1215 call ER_EMS_Overlap_Check ;EMS pages overlap? ;an000; dms;
1216 or ah,ah ;
1217 jz ER_Exchange_No_Overlap ;no - exit with error ;an000; dms;
1218 mov ah,EMS_Code97 ;signal error ;an000; dms;
1219 jmp ER_Error_Exit ;exit with error code ;an000; dms;
1220
1221 ER_Exchange_No_Overlap:
1222
1223 call ER_Exchange_Data ;no - perform exchange ;an000; dms;
1224 jmp ER_Exit ;exit the routine ;an000; dms;
1225
1226 ER_Move_Call:
1227
1228 call ER_EMS_Overlap_Check ;see if we had a move ;an000; dms;
1229 ; overlap
1230 push ax ;save result across call;an000; dms;
1231 call ER_Move_Data ;perform the move ;an000; dms;
1232 pop ax ;restore result ;an000; dms;
1233
1234 ER_Exit:
1235 ER_Error_Exit:
1236
1237 pop es ;restore regs ;an000; dms;
1238 pop ds ; ;an000; dms;
1239 pop si ; ;an000; dms;
1240 pop di ; ;an000; dms;
1241 pop dx ; ;an000; dms;
1242 pop cx ; ;an000; dms;
1243 pop bx ; ;an000; dms;
1244
1245 ret ;return to caller ;an000; dms;
1246
1247 Exchng_Region endp
1248
1249
1250 ;=========================================================================
1251 ; ER_Handle_Check : This routine checks to see if the EMS handles
1252 ; specified are valid.
1253 ;
1254 ; Inputs : DS:SI - Pointer to Move_Source_Dest_Struc data
1255 ;
1256 ; Outputs : AH - Non-zero on error
1257 ; Possible error codes: 83h
1258 ;=========================================================================
1259
1260 ER_Handle_Check proc ;check requested handles;an000; dms;
1261
1262 push dx ;save regs ;an000; dms;
1263 push di ; ;an000; dms;
1264
1265 cmp [si].Source_Memory_Type,ER_Conv_Memory ;Conv memory for source?;an000; dms;
1266 je ER_Handle_Check_Dest ;yes - ck dest. handle ;an000; dms;
1267
1268 push dx ;save dx ;an000; dms;
1269 xor dx,dx ;clear it ;an000; dms;
1270 mov ax,[si].Source_Handle ;get handle requested ;an000; dms;
1271 mov dx,Type H_LookUp_Struc ;handle lookup table ;an000; dms;
1272 mul dx ;obtain index position ;an000; dms;
1273 mov di,ax ;place index in di ;an000; dms;
1274 pop dx ;restore dx ;an000; dms;
1275
1276 cmp Handle_LookUp_Table.H_Pages[di],Reusable_Handle ;handle allocated ;an000; dms;
1277 je ER_Handle_Check_Error_Exit ;handle not allocated ;an000; dms;
1278
1279 ER_Handle_Check_Dest:
1280
1281 cmp [si].Dest_Memory_Type,ER_Conv_Memory ;Conv memory for dest? ;an000; dms;
1282 je ER_Handle_Check_Good_Exit ;yes - exit routine ;an000; dms;
1283
1284 push dx ;save dx ;an000; dms;
1285 xor dx,dx ;clear it ;an000; dms;
1286 mov ax,[si].Dest_Handle ;get handle requested ;an000; dms;
1287 mov dx,Type H_LookUp_Struc ;handle lookup table ;an000; dms;
1288 mul dx ;obtain index position ;an000; dms;
1289 mov di,ax ;place index in di ;an000; dms;
1290 pop dx ;restore dx ;an000; dms;
1291
1292 cmp Handle_LookUp_Table.H_Pages[di],Reusable_Handle ;handle allocated ;an000; dms;
1293 je ER_Handle_Check_Error_Exit ;handle not allocated ;an000; dms;
1294
1295 ER_Handle_Check_Good_Exit:
1296
1297 xor ah,ah ;signal no error ;an000; dms;
1298 jmp ER_Handle_Check_Exit ;exit program ;an000; dms;
1299
1300 ER_Handle_Check_Error_Exit:
1301
1302 mov ah,EMS_Code83 ;signal error ;an000; dms;
1303
1304 ER_Handle_Check_Exit:
1305
1306 pop di ;restore regs ;an000; dms;
1307 pop dx ; ;an000; dms;
1308
1309 ret ;return to caller ;an000; dms;
1310
1311 ER_Handle_Check endp ;end proc ;an000; dms;
1312
1313
1314
1315 ;=========================================================================
1316 ; ER_Length_Check : This routine checks to see if the region length
1317 ; specified exceeds the page count of either the
1318 ; source or destination EMS handle pages allocated.
1319 ; It also checks to determine if the region length
1320 ; exceeds 1 Mb.
1321 ;
1322 ; Inputs : DS:SI - Pointer to Move_Source_Dest_Struc data
1323 ;
1324 ; Outputs : AH - Non-zero on error
1325 ; Possible error codes: 93h
1326 ; 96h
1327 ; 8Ah
1328 ;=========================================================================
1329
1330 ER_Length_Check proc ;check region length ;an000; dms;
1331
1332 push bx ;save regs ;an000; dms;
1333 push cx ; ;an000; dms;
1334 push dx ; ;an000; dms;
1335 push di ; ;an000; dms;
1336
1337 mov cx,[si].Region_Length_High_Word ;get size of the region ;an000; dms;
1338 mov bx,[si].Region_Length_Low_Word ; in CX:BX ;an000; dms;
1339 cmp cx,ER_10H ;> 1Mb ;an000; dms;
1340 ja ER_Length_Check_Error96 ;exit with error ;an000; dms;
1341 cmp cx,ER_10H ;high word = 10h? ;an000; dms;
1342 jne ER_Length_Check_Cont ;no - continue ;an000; dms;
1343 cmp bx,0 ;low word other than 0? ;an000; dms;
1344 je ER_Length_Check_Cont ;no - good value ;an000; dms;
1345
1346 ER_Length_Check_Error96:
1347
1348 mov ah,EMS_Code96 ;signal error ;an000; dms;
1349 jmp ER_Length_Check_Exit ;exit routine
1350
1351 ER_Length_Check_Cont:
1352
1353 cmp [si].Source_Memory_Type,ER_Conv_Memory ;Conv memory for source?;an000; dms;
1354 je ER_Length_Check_Dest ;yes - ck dest. length ;an000; dms;
1355
1356 push dx ;save dx ;an000; dms;
1357 xor dx,dx ;clear it ;an000; dms;
1358 mov ax,[si].Source_Handle ;get handle requested ;an000; dms;
1359 mov dx,Type H_LookUp_Struc ;handle lookup table ;an000; dms;
1360 mul dx ;obtain index position ;an000; dms;
1361 mov di,ax ;place index in di ;an000; dms;
1362 pop dx ;restore dx ;an000; dms;
1363
1364 mov ax,Handle_LookUp_Table.H_Pages[di] ;get logical page count ;an000; dms;
1365 ; for source handle
1366 sub ax,[si].Source_Initial_Seg_Page ;pages in EMS to fill ;an000; dms;
1367 push ax ;save ax ;an000; dms;
1368 dec ax ;make it 0 based ;an000; dms;
1369 pop ax ;restore ax ;an000; dms;
1370 js ER_Length_Check_Error8A_Exit ;page out of range ;an000; dms;
1371
1372 xor dx,dx ;clear it ;an000; dms;
1373 mov dx,EMS_Page_Size_In_Bytes+1 ;page size in bytes ;an000; dms;
1374 mul dx ;get total bytes to trf ;an000; dms;
1375 sub ax,[si].Source_Initial_Offset ;get byte count in 1st ;an000; dms;
1376 sbb dx,0
1377
1378 mov bx,ax ;prepare for DWORD comp ;an000; dms;
1379 mov ax,dx ; ;an000; dms;
1380
1381 mov cx,[si].Region_Length_High_Word ;get size of the region ;an000; dms;
1382 mov dx,[si].Region_Length_Low_Word ; in CX:BX ;an000; dms;
1383
1384 call ER_Dword_Compare ;region > target? ;an000; dms;
1385 jc ER_Length_Check_Error93_Exit ;CY = region > target ;an000; dms;
1386
1387
1388 ER_Length_Check_Dest:
1389
1390 cmp [si].Dest_Memory_Type,ER_Conv_Memory ;Conv memory for dest? ;an000; dms;
1391 je ER_Length_Check_Good_Exit ;yes - exit routine ;an000; dms;
1392
1393 push dx ;save dx ;an000; dms;
1394 xor dx,dx ;clear it ;an000; dms;
1395 mov ax,[si].Dest_Handle ;get handle requested ;an000; dms;
1396 mov dx,Type H_LookUp_Struc ;handle lookup table ;an000; dms;
1397 mul dx ;obtain index position ;an000; dms;
1398 mov di,ax ;place index in di ;an000; dms;
1399 pop dx ;restore dx ;an000; dms;
1400
1401 mov ax,Handle_LookUp_Table.H_Pages[di] ;get logical page count ;an000; dms;
1402
1403 sub ax,[si].Dest_Initial_Seg_Page ;pages in EMS to fill ;an000; dms;
1404 push ax ;save ax ;an000; dms;
1405 dec ax ;make it 0 based ;an000; dms;
1406 pop ax ;restore ax ;an000; dms;
1407 js ER_Length_Check_Error8A_Exit ;page out of range ;an000; dms;
1408
1409 xor dx,dx ;clear high word ;an000; dms;
1410 mov dx,EMS_Page_Size_In_Bytes+1 ;page size in bytes ;an000; dms;
1411 mul dx ;get total bytes to trf ;an000; dms;
1412 sub ax,[si].Dest_Initial_Offset ;get byte count in 1st ;an000; dms;
1413 sbb dx,0
1414
1415 mov bx,ax ;prepare for DWORD comp ;an000; dms;
1416 mov ax,dx ; ;an000; dms;
1417
1418 mov cx,[si].Region_Length_High_Word ;get size of the region ;an000; dms;
1419 mov dx,[si].Region_Length_Low_Word ; in CX:BX ;an000; dms;
1420
1421 call ER_Dword_Compare ;region > target? ;an000; dms;
1422 jc ER_Length_Check_Error93_Exit ;CY = region > target ;an000; dms;
1423
1424
1425 ER_Length_Check_Good_Exit:
1426
1427 xor ah,ah ;signal no error ;an000; dms;
1428 jmp ER_Length_Check_Exit ;exit routine ;an000; dms;
1429
1430 ER_Length_Check_Error93_Exit:
1431
1432 mov ah,EMS_Code93 ;signal error ;an000; dms;
1433 jmp ER_Length_Check_Exit ;exit routine ;an000; dms;
1434
1435 ER_Length_Check_Error8A_Exit:
1436
1437 mov ah,EMS_Code8A ;signal error ;an000; dms;
1438
1439 ER_Length_Check_Exit: ;main exit ;an000; dms;
1440
1441 pop di ;restore regs ;an000; dms;
1442 pop dx ; ;an000; dms;
1443 pop cx ; ;an000; dms;
1444 pop bx ; ;an000; dms;
1445
1446 ret ;return to caller ;an000; dms;
1447
1448 ER_Length_Check endp ;end proc ;an000; dms;
1449
1450
1451 ;=========================================================================
1452 ; ER_Type_Check : This routine checks the source/destination type
1453 ; specified to determine if they are within the
1454 ; proper range.
1455 ;
1456 ; Inputs : DS:SI - Pointer to Move_Source_Dest_Struc data
1457 ;
1458 ; Outputs : AH - Non-zero on error
1459 ; Possible error codes: 98h
1460 ;=========================================================================
1461
1462 ER_Type_Check proc ;check type ;an000; dms;
1463
1464 cmp [si].Source_Memory_Type,ER_Max_Type ;type within range? ;an000; dms;
1465 ja ER_Type_Check_Error_Exit ;no - error exit ;an000; dms;
1466
1467 cmp [si].Dest_Memory_Type,ER_Max_Type ;type within range? ;an000; dms;
1468 ja ER_Type_Check_Error_Exit ;no - error exit ;an000; dms;
1469
1470
1471 ER_Type_Check_Good_Exit:
1472
1473 xor ah,ah ;signal no error ;an000; dms;
1474 jmp ER_Type_Check_Exit ;exit routine ;an000; dms;
1475
1476 ER_Type_Check_Error_Exit:
1477
1478 mov ah,EMS_Code98 ;signal error ;an000; dms;
1479
1480 ER_Type_Check_Exit:
1481
1482 ret ;return to caller ;an000; dms;
1483
1484 ER_Type_Check endp ;end proc ;an000; dms;
1485
1486
1487 ;=========================================================================
1488 ; ER_Wrap_Check : This routine checks to determine if there will be
1489 ; a wrap of conventional memory beyond 1Mb.
1490 ;
1491 ; Inputs : DS:SI - Pointer to Move_Source_Dest_Struc data
1492 ;
1493 ; Outputs : AH - Non-zero on error
1494 ; Possible error codes: A2h
1495 ;=========================================================================
1496
1497 ER_Wrap_Check proc ;cks. conv. mem. wrap ;an000; dms;
1498
1499 push dx ;save regs ;an000; dms;
1500 push bx ; ;an000; dms;
1501
1502 cmp [si].Source_Memory_Type,ER_Conv_Memory ;conv. memory? ;an000; dms;
1503 jne ER_Wrap_Check_Dest ;no -check dest. ;an000; dms;
1504
1505 mov ax,[si].Source_Initial_Seg_Page ;get segment ;an000; dms;
1506 xor dx,dx ;clear high word ;an000; dms;
1507 mov bx,ER_10H ;adjust segment to ;an000; dms;
1508 ; absolute address
1509 mul bx ; ;an000; dms;
1510 add ax,[si].Source_Initial_Offset ;add in offset ;an000; dms;
1511 adc dx,0 ;pick up carry if any ;an000; dms;
1512
1513 add ax,[si].Region_Length_Low_Word ;add in low word of ;an000; dms;
1514 ; trf size
1515 adc dx,[si].Region_Length_High_Word ;add in high word of ;an000; dms;
1516 ; trf size
1517 cmp dx,ER_10H ;> 1Mb? ;an000; dms;
1518 jae ER_Wrap_Check_Error_Exit ;yes - signal error ;an000; dms;
1519 jmp ER_Wrap_Check_Good_Exit ;no - signal no error ;an000; dms;
1520
1521 ER_Wrap_Check_Dest:
1522
1523 cmp [si].Dest_Memory_Type,ER_Conv_Memory ;conv. memory? ;an000; dms;
1524 jne ER_Wrap_Check_Good_Exit ;no - exit routine ;an000; dms;
1525
1526 mov ax,[si].Dest_Initial_Seg_Page ;get segment ;an000; dms;
1527 xor dx,dx ;clear high word ;an000; dms;
1528 mov bx,ER_10H ;adjust segment to ;an000; dms;
1529 ; absolute address
1530 mul bx ; ;an000; dms;
1531 add ax,[si].Dest_Initial_Offset ;add in offset ;an000; dms;
1532 adc dx,0 ;pick up carry if any ;an000; dms;
1533
1534 add ax,[si].Region_Length_Low_Word ;add in low word of ;an000; dms;
1535 ; trf size
1536 adc dx,[si].Region_Length_High_Word ;add in high word of ;an000; dms;
1537 ; trf size
1538 cmp dx,ER_10H ;> 1Mb? ;an000; dms;
1539 jae ER_Wrap_Check_Error_Exit ;yes - signal error ;an000; dms;
1540
1541 ER_Wrap_Check_Good_Exit:
1542
1543 xor ah,ah ;signal no error ;an000; dms;
1544 jmp ER_Wrap_Check_Exit ;exit routine ;an000; dms;
1545
1546 ER_Wrap_Check_Error_Exit:
1547
1548 mov ah,EMS_CodeA2 ;signal error ;an000; dms;
1549
1550 ER_Wrap_Check_Exit:
1551
1552 pop bx ;restore regs ;an000; dms;
1553 pop dx ; ;an000; dms;
1554
1555 ret ;return to caller ;an000; dms;
1556
1557 ER_Wrap_Check endp ;end proc ;an000; dms;
1558
1559
1560 ;=========================================================================
1561 ; ER_Overlap_Check : This routine checks to determine if the conventional
1562 ; memory region and expanded memory region overlap.
1563 ; Specifically, does the conventional memory region
1564 ; overlap the physical page addresses used for
1565 ; expanded memory?
1566 ;
1567 ; Inputs : DS:SI - Pointer to Move_Source_Dest_Struc data
1568 ;
1569 ; Outputs : AH - Non-zero on error
1570 ; Possible error codes: 94h
1571 ;
1572 ; Algorithm :
1573 ;
1574 ; If Beg.Src.Add. < Beg.Dst.Add
1575 ; If (End.Src.Add - Beg.Dst.Add) > 0
1576 ; signal OVERLAP
1577 ; Else
1578 ; signal NO-OVERLAP
1579 ; EndIf
1580 ; Else
1581 ; If (End.Dst.Add - Beg.Src.Add) > 0
1582 ; signal OVERLAP
1583 ; Else
1584 ; signal NO-OVERLAP
1585 ; EndIf
1586 ; EndIf
1587 ;=========================================================================
1588
1589 ER_Overlap_Check proc ;check for overlap ;an000; dms;
1590
1591 push dx ;save regs ;an000; dms;
1592 call ER_Save_Context ;save context ;an000; dms;
1593
1594 cmp [si].Source_Memory_Type,ER_Conv_Memory ;conventional memory? ;an000; dms;
1595 je ER_Overlap_Check_Source ;yes - check overlap ;an000; dms;
1596 ;no - see if dest is
1597 ; conv. memory
1598
1599 cmp [si].Dest_Memory_Type,ER_Conv_Memory ;conventional memory? ;an000; dms;
1600 jne ER_Overlap_Jump_Good ;no - exit routine ;an000; dms;
1601
1602 ER_Overlap_Check_Dest:
1603
1604 mov di,offset cs:ER_Save_Context_Buffer ;get addressibility to ;an000; dms;
1605 ; the page frame save
1606 ;buffer
1607 add di,bp ;offset BP relative ;an000; dms;
1608 cli ;ints off ;an000; dms;
1609 cmp Map_Count,2 ;>= 2 page frames ;an000; dms;
1610 sti ;ints on ;an000; dms;
1611 jb ER_Overlap_Check_Dest_1_Frame ;no - use 1st. frame ;an000; dms;
1612 add di,Type Mappable_Phys_Page_Struct ;yes - adjust ptr to ;an000; dms;
1613 ; next frame for dest.
1614 ER_Overlap_Check_Dest_1_Frame:
1615
1616 ;**** calc abs address of the bottom of EMS transfer area
1617
1618 mov ax,cs:[di].Phys_Page_Segment ;get seg value ;an000; dms;
1619 xor dx,dx ;clear high word ;an000; dms;
1620 mov bx,ER_10H ;para size ;an000; dms;
1621 mul bx ;make abs address ;an000; dms;
1622 mov cs:[bp].ER_Src_Abs_Beg_Low,ax ;save abs. address of ;an000; dms;
1623 mov cs:[bp].ER_Src_Abs_Beg_High,dx ; phys page beg. ;an000; dms;
1624
1625 ;**** calc abs address of the top of EMS transfer area
1626
1627 add ax,EMS_Page_Size_In_Bytes ;make abs address ;an000; dms;
1628 adc dx,0 ; ;an000; dms;
1629 mov cs:[bp].ER_Src_Abs_End_Low,ax ;save abs. address ;an000; dms;
1630 mov cs:[bp].ER_Src_Abs_End_High,dx ; of phys page end ;an000; dms;
1631
1632 ;**** calc abs address of the bottom of CONV transfer area
1633
1634 mov ax,[si].Dest_Initial_Seg_Page ;get segment ;an000; dms;
1635 xor dx,dx ;clear high word ;an000; dms;
1636 mov bx,ER_10H ;para size ;an000; dms;
1637 mul bx ;make abs address ;an000; dms;
1638 add ax,[si].Dest_Initial_Offset ;get offset ;an000; dms;
1639 adc dx,0 ;pick up carry ;an000; dms;
1640 mov cs:[bp].ER_Dst_Abs_Beg_Low,ax ;save initial seg start ;an000; dms;
1641 mov cs:[bp].ER_Dst_Abs_Beg_High,dx ;save initial off start ;an000; dms;
1642
1643 ;**** calc abs address of the top of CONV transfer area
1644
1645 add ax,[si].Region_Length_Low_Word ;add in low word of ;an000; dms;
1646 ; trf size
1647 adc dx,[si].Region_Length_High_Word ;add in high word of ;an000; dms;
1648 mov cs:[bp].ER_Dst_Abs_End_Low,ax ;save initial seg start ;an000; dms;
1649 mov cs:[bp].ER_Dst_Abs_End_High,dx ;save initial off start ;an000; dms;
1650
1651 call ER_General_Overlap_Test ;test for overlap ;an000; dms;
1652
1653 jc ER_Overlap_Error_Exit ;exit with error ;an000; dms;
1654
1655 ER_Overlap_Jump_Good:
1656
1657 jmp ER_Overlap_Good_Exit ;exit good ;an000; dms;
1658
1659 ER_Overlap_Check_Source:
1660
1661 mov di,offset cs:ER_Save_Context_Buffer ;get addressibility to ;an000; dms;
1662 ; the page frame save
1663 ;buffer
1664 add di,bp ;offset BP relative ;an000; dms;
1665
1666 ;**** calc abs address of the bottom of EMS transfer area
1667
1668 mov ax,cs:[di].Phys_Page_Segment ;get seg value ;an000; dms;
1669 xor dx,dx ;clear high word ;an000; dms;
1670 mov bx,ER_10H ;para size ;an000; dms;
1671 mul bx ;make abs address ;an000; dms;
1672 mov cs:[bp].ER_Src_Abs_Beg_Low,ax ;save abs. address of ;an000; dms;
1673 mov cs:[bp].ER_Src_Abs_Beg_High,dx ; phys page beg. ;an000; dms;
1674
1675 ;**** calc abs address of the top of EMS transfer area
1676
1677 mov ax,cs:[di].Phys_Page_Segment ;get seg value ;an000; dms;
1678 mov dx,EMS_Page_Size_In_Bytes ;get end of phys page ;an000; dms;
1679 mov bx,ER_10H ;para size ;an000; dms;
1680 mul bx ;make abs address ;an000; dms;
1681 mov cs:[bp].ER_Src_Abs_End_Low,ax ;save abs. address ;an000; dms;
1682 mov cs:[bp].ER_Src_Abs_End_High,dx ; of phys page end ;an000; dms;
1683
1684 ;**** calc abs address of the bottom of CONV transfer area
1685
1686 mov ax,[si].Source_Initial_Seg_Page ;get segment ;an000; dms;
1687 xor dx,dx ;clear high word ;an000; dms;
1688 mov bx,ER_10H ;para size ;an000; dms;
1689 mul bx ;make abs address ;an000; dms;
1690 add ax,[si].Source_Initial_Offset ;get offset ;an000; dms;
1691 adc dx,0 ;pick up carry ;an000; dms;
1692 mov cs:[bp].ER_Dst_Abs_Beg_Low,ax ;save initial seg start ;an000; dms;
1693 mov cs:[bp].ER_Dst_Abs_Beg_High,dx ;save initial off start ;an000; dms;
1694
1695 ;**** calc abs address of the top of CONV transfer area
1696
1697 add ax,[si].Region_Length_Low_Word ;add in low word of ;an000; dms;
1698 ; trf size
1699 adc dx,[si].Region_Length_High_Word ;add in high word of ;an000; dms;
1700 mov cs:[bp].ER_Dst_Abs_End_Low,ax ;save initial seg start ;an000; dms;
1701 mov cs:[bp].ER_Dst_Abs_End_High,dx ;save initial off start ;an000; dms;
1702
1703 call ER_General_Overlap_Test ;test for overlap ;an000; dms;
1704
1705 jnc ER_Overlap_Good_Exit ;exit good ;an000; dms;
1706 jmp ER_Overlap_Error_Exit ;exit bad
1707
1708 ER_Overlap_Good_Exit:
1709
1710 xor ah,ah ;signal no error ;an000; dms;
1711 jmp ER_Overlap_Exit ;exit ;an000; dms;
1712
1713 ER_Overlap_Error_Exit:
1714
1715 mov ah,EMS_Code94 ;signal error ;an000; dms;
1716
1717 ER_Overlap_Exit:
1718
1719 call ER_Restore_Context ;restore context ;an000; dms;
1720
1721 pop dx ;restore regs ;an000; dms;
1722
1723 ret ;return to caller ;an000; dms;
1724
1725 ER_Overlap_Check endp ;end proc ;an000; dms;
1726
1727
1728 ;=========================================================================
1729 ; ER_EMS_Overlap_Check : This routine determines if the source and target
1730 ; EMS regions overlap when both the source and target
1731 ; reside in EMS.
1732 ;
1733 ; Inputs : DS:SI - Pointer to Move_Source_Dest_Struc data
1734 ;
1735 ; Outputs : AH - Non-zero on error
1736 ; Possible error codes: 92h
1737 ;
1738 ; Algorithm :
1739 ;
1740 ; If Beg.Src.Add. < Beg.Dst.Add
1741 ; If (End.Src.Add - Beg.Dst.Add) > 0
1742 ; signal OVERLAP
1743 ; Else
1744 ; signal NO-OVERLAP
1745 ; EndIf
1746 ; Else
1747 ; If (End.Dst.Add - Beg.Src.Add) > 0
1748 ; signal OVERLAP
1749 ; Else
1750 ; signal NO-OVERLAP
1751 ; EndIf
1752 ; EndIf
1753 ;=========================================================================
1754
1755 ER_EMS_Overlap_Check proc ;check for overlap ;an000; dms;
1756
1757 push bx ;save regs ;an000; dms;
1758 push dx ; ;an000; dms;
1759
1760 cmp [si].Source_Memory_Type,ER_EMS_Memory ;Source EMS? ;an000; dms;
1761 jne ER_EMS_Overlap_Exit ;no - exit routine ;an000; dms;
1762
1763 cmp [si].Dest_Memory_Type,ER_EMS_Memory ;Dest. EMS? ;an000; dms;
1764 jne ER_EMS_Overlap_Exit ;no - exit routine ;an000; dms;
1765
1766 mov bx,[si].Source_Handle ;get source handle ;an000; dms;
1767 cmp bx,[si].Dest_Handle ;source = dest? ;an000; dms;
1768 jne ER_EMS_Overlap_Good_Exit ;no - exit routine ;an000; dms;
1769
1770 ER_EMS_Overlap_Calc_N_Ck:
1771
1772 ;**** calc absolute beginning address of source page
1773
1774 mov ax,[si].Source_Initial_Seg_Page ;get start page ;an000; dms;
1775 xor dx,dx ;clear high word ;an000; dms;
1776 mov bx,EMS_Page_Size_In_Bytes ;get page size ;an000; dms;
1777 mul bx ;convert page to abs ;an000; dms;
1778 ; address
1779 add ax,[si].Source_Initial_Offset ;add in offset value ;an000; dms;
1780 adc dx,0 ;pick up carry ;an000; dms;
1781
1782 mov cs:[bp].ER_Src_Abs_Beg_Low,ax ;save low word of add
1783 mov cs:[bp].ER_Src_Abs_Beg_High,dx ;save high word of add ;an000; dms;
1784
1785 ;**** calc absolute ending address of source page
1786
1787 add ax,[si].Region_Length_Low_Word ;add in low word of ;an000; dms;
1788 ; length
1789 adc dx,[si].Region_Length_High_Word ;add in high word of ;an000; dms;
1790 ; length
1791 mov cs:[bp].ER_Src_Abs_End_Low,ax ;save low word of end ;an000; dms;
1792 mov cs:[bp].ER_Src_Abs_End_High,dx ;save high word of end ;an000; dms;
1793
1794 ;**** calc absolute beginning address of dest. page
1795
1796 mov ax,[si].Dest_Initial_Seg_Page ;get start page ;an000; dms;
1797 xor dx,dx ;clear high word ;an000; dms;
1798 mov bx,EMS_Page_Size_In_Bytes ;get page size ;an000; dms;
1799 mul bx ;convert page to abs ;an000; dms;
1800 ; address
1801 add ax,[si].Dest_Initial_Offset ;add in offset value ;an000; dms;
1802 adc dx,0 ;pick up carry ;an000; dms;
1803
1804 mov cs:[bp].ER_Dst_Abs_Beg_Low,ax ;save low word of add
1805 mov cs:[bp].ER_Dst_Abs_Beg_High,dx ;save high word of add ;an000; dms;
1806
1807 ;**** calc absolute ending address of dest. page
1808
1809 add ax,[si].Region_Length_Low_Word ;add in low word of ;an000; dms;
1810 ; length
1811 adc dx,[si].Region_Length_High_Word ;add in high word of ;an000; dms;
1812 ; length
1813 mov cs:[bp].ER_Dst_Abs_End_Low,ax ;save low word of end ;an000; dms;
1814 mov cs:[bp].ER_Dst_Abs_End_High,dx ;save high word of end ;an000; dms;
1815
1816 ;**** Actual test for overlap - corresponds to algorithm above
1817
1818 call ER_General_Overlap_Test ;test for overlap ;an000; dms;
1819 jnc ER_EMS_Overlap_Good_Exit ;no error ;an000; dms;
1820
1821 ER_EMS_Overlap_Error_Exit:
1822
1823 mov ah,EMS_Code92 ;signal error ;an000; dms;
1824 jmp ER_EMS_Overlap_Exit ;exit ;an000; dms;
1825
1826 ER_EMS_Overlap_Good_Exit:
1827
1828 xor ah,ah ;no error ;an000; dms;
1829
1830 ER_EMS_Overlap_Exit:
1831
1832 pop dx ;restore regs ;an000; dms;
1833 pop bx ; ;an000; dms;
1834
1835 ret ;return to caller ;an000; dms;
1836
1837 ER_EMS_Overlap_Check endp ;end proc ;an000; dms;
1838
1839
1840 ;=========================================================================
1841 ; ER_General_Overlap_Test:This routine determines if the source and target
1842 ; EMS regions overlap when both the source and target
1843 ; reside in EMS.
1844 ;
1845 ; Inputs : ER_Src_Abs_Beg_Low - Low word of beginning trf area of source
1846 ; ER_Src_Abs_Beg_High - High word of beginning trf area of source
1847 ;
1848 ; ER_Src_Abs_End_Low - Low word of ending trf area of source
1849 ; ER_Src_Abs_End_High - High word of ending trf area of source
1850 ;
1851 ; : ER_Dst_Abs_Beg_Low - Low word of beginning trf area of dest.
1852 ; ER_Dst_Abs_Beg_High - High word of beginning trf area of dest.
1853 ;
1854 ; ER_Dst_Abs_End_Low - Low word of ending trf area of dest.
1855 ; ER_Dst_Abs_End_High - High word of ending trf area of dest.
1856 ;
1857 ; Outputs : NC - no overlap
1858 ; CY - overlap
1859 ;
1860 ; Algorithm :
1861 ;
1862 ; If Beg.Src.Add. < Beg.Dst.Add
1863 ; If (End.Src.Add - Beg.Dst.Add) > 0
1864 ; signal OVERLAP
1865 ; Else
1866 ; signal NO-OVERLAP
1867 ; EndIf
1868 ; Else
1869 ; If (End.Dst.Add - Beg.Src.Add) > 0
1870 ; signal OVERLAP
1871 ; Else
1872 ; signal NO-OVERLAP
1873 ; EndIf
1874 ; EndIf
1875 ;=========================================================================
1876
1877 ER_General_Overlap_Test proc ; ;an000; dms;
1878
1879 push ax ;save regs ;an000; dms;
1880 push bx ; ;an000; dms;
1881 push cx ; ;an000; dms;
1882 push dx ; ;an000; dms;
1883
1884 mov ax,cs:[bp].ER_Src_Abs_Beg_High ;get source beg. add. ;an000; dms;
1885 mov bx,cs:[bp].ER_Src_Abs_Beg_Low ; ;an000; dms;
1886 mov cx,cs:[bp].ER_Dst_Abs_Beg_High ;get dest. beg. add. ;an000; dms;
1887 mov dx,cs:[bp].ER_Dst_Abs_Beg_Low ; ;an000; dms;
1888 call ER_Dword_Compare ;
1889 ; $if c ;< dest. beg. add.? ;an000; dms;
1890 JNC ER_IF1
1891 mov ax,cs:[bp].ER_Src_Abs_End_Low ;get end address ;an000; dms;
1892 mov dx,cs:[bp].ER_Src_Abs_End_High ; ;an000; dms;
1893 sub ax,cs:[bp].ER_Dst_Abs_Beg_Low ;End.Src.Add-Beg.Dst.Add;an000; dms;
1894 sbb dx,cs:[bp].ER_Dst_Abs_Beg_High ; ;an000; dms;
1895 ; $if ns ;yes - overlap ;an000; dms;
1896 JS ER_IF2
1897 stc ;signal error ;an000; dms;
1898 mov cs:[bp].ER_Direction_Flag,ER_Down ;signal reverse move ;an000; dms;
1899 ; $else ;no - not sure yet ;an000; dms;
1900 JMP SHORT ER_EN2
1901 ER_IF2:
1902 clc ;signal no overlap ;an000; dms;
1903 mov cs:[bp].ER_Direction_Flag,ER_Up ;forward move ;an000; dms;
1904 ; $endif ; ;an000; dms;
1905 ER_EN2:
1906 ; $else ;not sure if src < dst ;an000; dms;
1907 JMP SHORT ER_EN1
1908 ER_IF1:
1909 mov ax,cs:[bp].ER_Dst_Abs_End_Low ;get end address ;an000; dms;
1910 mov dx,cs:[bp].ER_Dst_Abs_End_High ; ;an000; dms;
1911 sub ax,cs:[bp].ER_Src_Abs_Beg_Low ;End.Dst.Add-Beg.Src.Add;an000; dms;
1912 sbb dx,cs:[bp].ER_Src_Abs_Beg_High ; ;an000; dms;
1913 ; $if ns ;yes - overlap ;an000; dms;
1914 JS ER_IF6
1915 stc ;signal error ;an000; dms;
1916 mov cs:[bp].ER_Direction_Flag,ER_Up ;forward move ;an000; dms;
1917 ; $else ;no - not sure yet ;an000; dms;
1918 JMP SHORT ER_EN6
1919 ER_IF6:
1920 clc ;signal no overlap ;an000; dms;
1921 mov cs:[bp].ER_Direction_Flag,ER_Up ;forward move ;an000; dms;
1922 ; $endif ; ;an000; dms;
1923 ER_EN6:
1924 ; $endif ; ;an000; dms;
1925 ER_EN1:
1926
1927 pop dx ;restore regs ;an000; dms;
1928 pop cx ; ;an000; dms;
1929 pop bx ; ;an000; dms;
1930 pop ax ; ;an000; dms;
1931
1932 ret ;return to caller ;an000; dms;
1933
1934 ER_General_Overlap_Test endp ;end proc ;an000; dms;
1935
1936
1937 ;=========================================================================
1938 ; ER_Dword_Compare : This routine determines whether or not a dword
1939 ; value is greater than another dword value.
1940 ;
1941 ; Inputs : AX - Source high word
1942 ; BX - Source low word
1943 ; CX - Destination high word
1944 ; DX - Destination low word
1945 ;
1946 ; Outputs : NC - source >= destination
1947 ; CY - source < destination
1948 ;=========================================================================
1949
1950 ER_Dword_Compare proc ; ;an000; dms;
1951
1952 cmp ax,cx ;src high < dest high? ;an000; dms;
1953 ; $if b ;yes ;an000; dms;
1954 JNB ER_IF10
1955 stc ;signal less than ;an000; dms;
1956 ; $else ;no ;an000; dms;
1957 JMP SHORT ER_EN10
1958 ER_IF10:
1959 cmp ax,cx ;src high > dest high? ;an000; dms;
1960 ; $if a ;yes ;an000; dms;
1961 JNA ER_IF12
1962 clc ;signal greater than ;an000; dms;
1963 ; $else ;no ;an000; dms;
1964 JMP SHORT ER_EN12
1965 ER_IF12:
1966 cmp bx,dx ;src low < dest low? ;an000; dms;
1967 ; $if b ;yes ;an000; dms;
1968 JNB ER_IF14
1969 stc ;signal less than ;an000; dms;
1970 ; $else ;no ;an000; dms;
1971 JMP SHORT ER_EN14
1972 ER_IF14:
1973 cmp bx,dx ;src low > dest low? ;an000; dms;
1974 ; $if a ;yes ;an000; dms;
1975 JNA ER_IF16
1976 clc ;signal greater than ;an000; dms;
1977 ; $else ;no ;an000; dms;
1978 JMP SHORT ER_EN16
1979 ER_IF16:
1980 clc ; ;an000; dms;
1981 ; $endif ; ;an000; dms;
1982 ER_EN16:
1983 ; $endif ; ;an000; dms;
1984 ER_EN14:
1985 ; $endif ; ;an000; dms;
1986 ER_EN12:
1987 ; $endif ; ;an000; dms;
1988 ER_EN10:
1989
1990 ret ; ;an000; dms;
1991
1992 ER_Dword_Compare endp ; ;an000; dms;
1993
1994
1995
1996 ;=========================================================================
1997 ; ER_Segment_Adjust : This routine adjusts the segment:offset to a value
1998 ; with an offset less than 16.
1999 ;
2000 ; Inputs : AX:DX - Segment:Offset to be adjusted
2001 ;
2002 ; Outputs : AX:DX - New Segment:Offset value
2003 ;=========================================================================
2004
2005 ER_Segment_Adjust proc ;adjust segment value ;an000; dms;
2006
2007 push bx ;save bx ;an000; dms;
2008 push cx ; ;an000; dms;
2009
2010 mov bx,ax ;save segment value ;an000; dms;
2011 mov ax,dx ;get offset ;an000; dms;
2012 xor dx,dx ;clear high word ;an000; dms;
2013 mov cx,ER_10h ;divide by 10h ;an000; dms;
2014 div cx ;get seg adjustment ;an000; dms;
2015 ; factor
2016 add ax,bx ;adjust segment up ;an000; dms;
2017 ; dx contains new off. ;an000; dms;
2018 pop cx ;restore regs ;an000; dms;
2019 pop bx ;restore bx ;an000; dms;
2020
2021 ret ;return to caller ;an000; dms;
2022
2023 ER_Segment_Adjust endp ;end proc ;an000; dms;
2024
2025
2026 ;=========================================================================
2027 ; ER_Log_Page_Test : This routine checks the offset specified for
2028 ; the logical page to determine if the offset is
2029 ; within the valid ranges for the page size.
2030 ;
2031 ; Inputs : DS:SI - Pointer to Move_Source_Dest_Struc data
2032 ;
2033 ; Outputs : AH - Non-zero on error
2034 ; Possible error codes: 95h
2035 ;=========================================================================
2036
2037 ER_Log_Page_Test proc ; ;an000; dms;
2038
2039 mov ax,EMS_Page_Size_In_Bytes ;get page size ;an000; dms;
2040
2041 cmp [si].Source_Memory_Type,ER_EMS_Memory ;EMS memory specified? ;an000; dms;
2042 jne ER_Log_Dest_Test ;no - check dest. ;an000; dms;
2043
2044 cmp ax,[si].Source_Initial_Offset ;> EMS page size ;an000; dms;
2045 jae ER_Log_Good_Exit ;good exit ;an000; dms;
2046 jmp ER_Log_Error_Exit ;error - bad exit ;an000; dms;
2047
2048 ER_Log_Dest_Test:
2049
2050 cmp [si].Dest_Memory_Type,ER_EMS_Memory ;EMS memory specified? ;an000; dms;
2051 jne ER_Log_Good_Exit ;good exit ;an000; dms;
2052
2053 cmp ax,[si].Dest_Initial_Offset ;> EMS page size ;an000; dms;
2054 jae ER_Log_Good_Exit ;good exit ;an000; dms;
2055
2056 ER_Log_Error_Exit:
2057
2058 mov ah,EMS_Code95 ;signal error ;an000; dms;
2059 jmp ER_Log_Exit ;exit routine ;an000; dms;
2060
2061 ER_Log_Good_Exit:
2062
2063 xor ah,ah ;signal no error ;an000; dms;
2064
2065 ER_Log_Exit:
2066
2067 ret ;return to caller ;an000; dms;
2068
2069 ER_Log_Page_Test endp ;end proc ;an000; dms;
2070
2071 ;=========================================================================
2072 ; ER_Save_Context : This routine saves the context for page frames
2073 ; needed for the move/exchange.
2074 ;
2075 ; Inputs : none
2076 ;
2077 ; Outputs : ER_Save_Context_Buffer - save context for the needed page frames
2078 ;=========================================================================
2079
2080 ER_Save_Context proc ;save contexts ;an000; dms;
2081
2082 push ax ;save regs ;an000; dms;
2083 push cx ; ;an000; dms;
2084 push di ; ;an000; dms;
2085 push si ; ;an000; dms;
2086 push ds ; ;an000; dms;
2087 push es ; ;an000; dms;
2088
2089 mov ax,cs ;make ds/es = cs ;an000; dms;
2090 mov ds,ax ; ;an000; dms;
2091 mov es,ax ; ;an000; dms;
2092
2093 mov si,offset cs:Map_Table ;ptr to page frame table;an000; dms;
2094 mov di,offset cs:ER_Save_Context_Buffer ;get dest. offset
2095 add di,bp ;offset BP relative ;an000; dms;
2096
2097 mov cx,2 ;default frame save ;an000; dms;
2098 cli ;ints off ;an000; dms;
2099 cmp Map_Count,2 ;2 page frames? ;an000; dms;
2100 jae ER_Save_Context_Loop ;< = 2 - continue ;an000; dms;
2101 mov cx,Map_Count ;max frame count to save;an000; dms;
2102
2103 ER_Save_Context_Loop:
2104
2105 sti ;ints on ;an000; dms;
2106 push cx ;save cx ;an000; dms;
2107 mov cx,Type Mappable_Phys_Page_Struct ;get byte count to trf ;an000; dms;
2108 cli ;ints off ;an000; dms;
2109 rep movsb ;perform save ;an000; dms;
2110 sti ;ints on ;an000; dms;
2111 pop cx ;restore cx ;an000; dms;
2112 loop ER_Save_Context_Loop ;continue ;an000; dms;
2113
2114 ER_Save_Exit:
2115
2116 pop es ;restore regs ;an000; dms;
2117 pop ds ; ;an000; dms;
2118 pop si ; ;an000; dms;
2119 pop di ; ;an000; dms;
2120 pop cx ; ;an000; dms;
2121 pop ax ; ;an000; dms;
2122
2123 ret ;return to caller ;an000; dms;
2124
2125 ER_Save_Context endp ;end proc ;an000; dms;
2126
2127
2128 ;=========================================================================
2129 ; ER_Restore_Context : This routine restores the context for page frames
2130 ; saved. These pages were used for the
2131 ; move/exchange requested.
2132 ;
2133 ; Inputs : ER_Save_Context_Buffer - contains saved context
2134 ;
2135 ; Outputs : restored context for the saved page frames
2136 ;=========================================================================
2137
2138 ER_Restore_Context proc ;restore contexts ;an000; dms;
2139
2140 push ax ;save regs ;an000; dms;
2141 push cx ; ;an000; dms;
2142 push di ; ;an000; dms;
2143 push si ; ;an000; dms;
2144 push ds ; ;an000; dms;
2145 push es ; ;an000; dms;
2146
2147 mov ax,cs ;make ds/es = cs ;an000; dms;
2148 mov ds,ax ; ;an000; dms;
2149 mov es,ax ; ;an000; dms;
2150
2151 mov di,offset cs:Map_Table ;ptr to page frame table;an000; dms;
2152 mov si,offset cs:ER_Save_Context_Buffer ;get dest. offset
2153 add si,bp ;offset BP relative ;an000; dms;
2154
2155 mov cx,2 ;default frame restore ;an000; dms;
2156 cli ;ints off ;an000; dms;
2157 cmp Map_Count,2 ;2 page frames? ;an000; dms;
2158 jae ER_Restore_Context_Loop ;< = 2 - continue ;an000; dms;
2159 mov cx,Map_Count ;max frame count to rest;an000; dms;
2160
2161 ER_Restore_Context_Loop:
2162
2163 sti ;ints on ;an000; dms;
2164 mov al,byte ptr ds:[si].Phys_Page_Number ;get physical page num. ;an000; dms;
2165 mov bx,word ptr ds:[si].PPM_Log_Page ;get logical page num. ;an000; dms;
2166 mov dx,word ptr ds:[si].PPM_Handle ;get handle number ;an000; dms;
2167 call Map_L_To_P ;map in orig. page ;an000; dms;
2168
2169 push cx ;save cx ;an000; dms;
2170 mov cx,Type Mappable_Phys_Page_Struct ;get byte count to trf ;an000; dms;
2171 cli ;ints off ;an000; dms;
2172 rep movsb ;perform save ;an000; dms;
2173 sti ;ints on ;an000; dms;
2174 pop cx ;restore cx ;an000; dms;
2175 loop ER_Restore_Context_Loop ;continue ;an000; dms;
2176
2177 ER_Restore_Exit:
2178
2179 pop es ;restore regs ;an000; dms;
2180 pop ds ; ;an000; dms;
2181 pop si ; ;an000; dms;
2182 pop di ; ;an000; dms;
2183 pop cx ; ;an000; dms;
2184 pop ax ; ;an000; dms;
2185
2186 ret ;return to caller ;an000; dms;
2187
2188 ER_Restore_Context endp ;end proc ;an000; dms;
2189
2190
2191
2192 ;=========================================================================
2193 ; ER_Det_Src_Dest_Seg : This routine determines the applicable segment,
2194 ; offset, and page to be used for the move/exchange.
2195 ; This routine sets the pages/addresses to the end
2196 ; of the area to be moved/exchanged, if the move
2197 ; is to be a reverse move. If the move is to be
2198 ; a forward move, the pages/addresses are set to
2199 ; the beginning of the area to be moved/exchanged.
2200 ; In this way an overlapping move can be
2201 ; performed without overlaying data it is to move.
2202 ;
2203 ; Inputs : DS:SI - Pointer to Move_Source_Dest_Struc data
2204 ;
2205 ; Outputs : ER_Source_Seg - Segment value of source
2206 ; ER_Dest_Seg - Segment value of destination
2207 ;
2208 ; ER_Source_Off - Offset value of source
2209 ; ER_Dest_Off - Offset value of destination
2210 ;
2211 ; ER_Source_Page - Source EMS page
2212 ; ER_Dest_Page - Destination EMS page
2213 ;
2214 ; ER_Source_Handle - Source handle
2215 ; ER_Dest_Handle - Destination handle
2216 ;
2217 ; ER_Source_Phys_Page - Physical page number
2218 ; ER_Dest_Phys_Page - Physical page number
2219 ;=========================================================================
2220
2221 ER_Det_Src_Dest_Seg proc ; ;an000; dms;
2222
2223 push ax ;save regs ;an000; dms;
2224 push bx ; ;an000; dms;
2225 push cx ; ;an000; dms;
2226 push dx ; ;an000; dms;
2227 push di ; ;an000; dms;
2228 push ds ; ;an000; dms;
2229 push es ; ;an000; dms;
2230
2231
2232 cmp [si].Source_Memory_Type,ER_EMS_Memory ;EMS? ;an000; dms;
2233 jne ER_Det_Source_Conv ;no - conventional mem. ;an000; dms;
2234
2235 mov di,offset cs:ER_Save_Context_Buffer ;get addressibility to ;an000; dms;
2236 ; the page frame save
2237 ;buffer
2238 add di,bp ;offset BP relative
2239 mov ax,cs:[di].Phys_Page_Segment ;get seg value ;an000; dms;
2240 mov cs:[bp].ER_Source_Seg,ax ;save it in variable ;an000; dms;
2241
2242 mov ax,[si].Source_Handle ;get source handle ;an000; dms;
2243 mov cs:[bp].ER_Source_Handle,ax ;save handle ;an000; dms;
2244
2245 cmp cs:[bp].ER_Direction_Flag,ER_Down ;reverse move? ;an000; dms;
2246 ; $if e ;yes ;an000; dms;
2247 JNE ER_IF22
2248 mov ax,[si].Region_Length_Low_Word ;get low word of move ;an000; dms;
2249 mov dx,[si].Region_Length_High_Word ;get high word ;an000; dms;
2250 add ax,[si].Source_Initial_Offset ;pick up offset value ;an000; dms;
2251 adc dx,0 ;pick up carry ;an000; dms;
2252 mov bx,4000h ;get page size ;an000; dms;
2253 div bx ;get end logical page ;an000; dms;
2254 add ax,[si].Source_Initial_Seg_Page ;adjust it for 1st. ;an000; dms;
2255 mov cs:[bp].ER_Source_Page,ax ;save log. page ;an000; dms;
2256 dec dx ;adjust to end point ;an000; dms;
2257 mov cs:[bp].ER_Source_Off,dx ;save offset in last pg ;an000; dms;
2258
2259 ; $else ;forward move ;an000; dms;
2260 JMP SHORT ER_EN22
2261 ER_IF22:
2262 mov ax,[si].Source_Initial_Seg_Page ;get page ;an000; dms;
2263 mov dx,[si].Source_Initial_Offset ;get offset ;an000; dms;
2264 mov cs:[bp].ER_Source_Page,ax ;save page ;an000; dms;
2265 mov cs:[bp].ER_Source_Off,dx ;save offset ;an000; dms;
2266 ; $endif ; ;an000; dms;
2267 ER_EN22:
2268 mov ax,cs:[di].Phys_Page_Number ;get phys. page ;an000; dms;
2269 mov cs:[bp].ER_Source_Phys_Page,ax ;save it ;an000; dms;
2270 jmp ER_Det_Dest_Check ;jump to dest check ;an000; dms;
2271
2272 ER_Det_Source_Conv:
2273
2274 cmp cs:[bp].ER_Direction_Flag,ER_Down ;reverse move? ;an000; dms;
2275 ; $if e ;yes ;an000; dms;
2276 JNE ER_IF25
2277 mov ax,[si].Region_Length_Low_Word ;get low word of move ;an000; dms;
2278 mov dx,[si].Region_Length_High_Word ;get high word ;an000; dms;
2279 mov bx,ER_10h ;get bytes/para ;an000; dms;
2280 div bx ;get para count ;an000; dms;
2281 ; AX = para's
2282 ; DX = offset
2283 mov bx,ax ;save across adjust call;an000; dms;
2284 mov cx,dx ; ;an000; dms;
2285 mov ax,[si].Source_Initial_Seg_Page ;get seg value ;an000; dms;
2286 mov dx,[si].Source_Initial_Offset ;get off value ;an000; dms;
2287 dec dx ;adjust to end byte
2288 call ER_Segment_Adjust ;adjust it downward ;an000; dms;
2289 add ax,bx ;new segment value ;an000; dms;
2290 add dx,cx ;new offset value ;an000; dms;
2291
2292 mov cs:[bp].ER_Source_Seg,ax ;save it in variable ;an000; dms;
2293 mov cs:[bp].ER_Source_Off,dx ;save offset in var ;an000; dms;
2294 ; $else ;forward move ;an000; dms;
2295 JMP SHORT ER_EN25
2296 ER_IF25:
2297 mov ax,[si].Source_Initial_Seg_Page ;get seg value ;an000; dms;
2298 mov dx,[si].Source_Initial_Offset ;get off value ;an000; dms;
2299 mov cs:[bp].ER_Source_Seg,ax ;save it in variable ;an000; dms;
2300 mov cs:[bp].ER_Source_Off,dx ;save offset in var ;an000; dms;
2301 ; $endif ; ;an000; dms;
2302 ER_EN25:
2303
2304
2305 ER_Det_Dest_Check:
2306
2307 cmp [si].Dest_Memory_Type,ER_EMS_Memory ;Dest. EMS? ;an000; dms;
2308 jne ER_Det_Dest_Conv ;no - conventional mem. ;an000; dms;
2309
2310 mov di,offset cs:ER_Save_Context_Buffer ;save frame buffer ;an000; dms;
2311 add di,bp ;offset BP relative ;an000; dms;
2312 cli ;ints off ;an000; dms;
2313 cmp Map_Count,1 ;> 1 page frame? ;an000; dms;
2314 sti ;ints on ;an000; dms;
2315 jb ER_Det_Dest_Check1 ;don't adjust pointer ;an000; dms;
2316 add di,Type Mappable_Phys_Page_Struct ;next entry in save buf ;an000; dms;
2317
2318 ER_Det_Dest_Check1:
2319
2320 mov ax,cs:[di].Phys_Page_Segment ;get seg value ;an000; dms;
2321 mov cs:[bp].ER_Dest_Seg,ax ;save it in variable ;an000; dms;
2322
2323 mov ax,[si].Dest_Handle ;get dest. handle ;an000; dms;
2324 mov cs:[bp].ER_Dest_Handle,ax ;save handle ;an000; dms;
2325
2326 cmp cs:[bp].ER_Direction_Flag,ER_Down ;reverse move? ;an000; dms;
2327 ; $if e ;yes ;an000; dms;
2328 JNE ER_IF28
2329 mov ax,[si].Region_Length_Low_Word ;get low word of move ;an000; dms;
2330 mov dx,[si].Region_Length_High_Word ;get high word ;an000; dms;
2331 add ax,[si].Dest_Initial_Offset ;pick up offset value ;an000; dms;
2332 adc dx,0 ;pick up carry ;an000; dms;
2333
2334 mov bx,4000h ;get page size ;an000; dms;
2335 div bx ;get end logical page ;an000; dms;
2336 add ax,[si].Dest_Initial_Seg_Page ;adjust it for 1st. ;an000; dms;
2337 mov cs:[bp].ER_Dest_Page,ax ;save log. page ;an000; dms;
2338 dec dx ;adjust to end point ;an000; dms;
2339 mov cs:[bp].ER_Dest_Off,dx ;save off. in last page ;an000; dms;
2340
2341 ; $else ;forward move ;an000; dms;
2342 JMP SHORT ER_EN28
2343 ER_IF28:
2344 mov ax,[si].Dest_Initial_Seg_Page ;get page ;an000; dms;
2345 mov dx,[si].Dest_Initial_Offset ;get offset ;an000; dms;
2346 mov cs:[bp].ER_Dest_Page,ax ;save log. page ;an000; dms;
2347 mov cs:[bp].ER_Dest_Off,dx ;save off. in last page ;an000; dms;
2348 ; $endif ; ;an000; dms;
2349 ER_EN28:
2350 mov ax,cs:[di].Phys_Page_Number ;get phys page number ;an000; dms;
2351 mov cs:[bp].ER_Dest_Phys_Page,ax ;save it ;an000; dms;
2352 jmp ER_Det_Exit ;exit routine ;an000; dms;
2353
2354 ER_Det_Dest_Conv:
2355
2356 cmp cs:[bp].ER_Direction_Flag,ER_Down ;reverse move? ;an000; dms;
2357 ; $if e ;yes ;an000; dms;
2358 JNE ER_IF31
2359 mov ax,[si].Region_Length_Low_Word ;get low word of move ;an000; dms;
2360 mov dx,[si].Region_Length_High_Word ;get high word ;an000; dms;
2361 mov bx,ER_10H ;get bytes/para ;an000; dms;
2362 div bx ;get para count ;an000; dms;
2363 ; AX = para's
2364 ; DX = offset
2365 mov bx,ax ;save across adjust call;an000; dms;
2366 mov cx,dx ; ;an000; dms;
2367 mov ax,[si].Dest_Initial_Seg_Page ;get seg value ;an000; dms;
2368 mov dx,[si].Dest_Initial_Offset ;get off value ;an000; dms;
2369 dec dx ;adjust to end byte ;an000; dms;
2370 call ER_Segment_Adjust ;adjust it downward ;an000; dms;
2371 add ax,bx ;new segment value ;an000; dms;
2372 add dx,cx ;new offset value ;an000; dms;
2373
2374 mov cs:[bp].ER_Dest_Seg,ax ;save it in variable ;an000; dms;
2375 mov cs:[bp].ER_Dest_Off,dx ;save offset in var ;an000; dms;
2376 ; $else ;forward move ;an000; dms;
2377 JMP SHORT ER_EN31
2378 ER_IF31:
2379 mov ax,[si].Dest_Initial_Seg_Page ;get seg value ;an000; dms;
2380 mov dx,[si].Dest_Initial_Offset ;get off value ;an000; dms;
2381 mov cs:[bp].ER_Dest_Seg,ax ;save it in variable ;an000; dms;
2382 mov cs:[bp].ER_Dest_Off,dx ;save offset in var ;an000; dms;
2383 ; $endif ; ;an000; dms;
2384 ER_EN31:
2385
2386
2387 ER_Det_Exit:
2388
2389 pop es ;restore regs ;an000; dms;
2390 pop ds ; ;an000; dms;
2391 pop di ; ;an000; dms;
2392 pop dx ; ;an000; dms;
2393 pop cx ; ;an000; dms;
2394 pop bx ; ;an000; dms;
2395 pop ax ; ;an000; dms;
2396
2397 ret ;return to caller ;an000; dms;
2398
2399 ER_Det_Src_Dest_Seg endp ;end proc ;an000; dms;
2400
2401
2402 ;=========================================================================
2403 ; ER_Det_Move_Count : This initializes the count variables for the
2404 ; loop iteration counter of the move/exchange.
2405 ;
2406 ; Inputs : DS:SI - Pointer to Move_Source_Dest_Struc data
2407 ;
2408 ; Outputs : ER_Move_Count_Low - low word value of move count
2409 ; ER_Move_Count_High - high word value of move count
2410 ;=========================================================================
2411
2412
2413 ER_Det_Move_Count proc ; ;an000; dms;
2414
2415 push ax ;save regs ;an000; dms;
2416 push dx ; ;an000; dms;
2417
2418 mov ax,[si].Region_Length_Low_Word ;get low word count ;an000; dms;
2419 mov dx,[si].Region_Length_High_Word ;get high word count ;an000; dms;
2420 mov cs:[bp].ER_Move_Count_Low,ax ;save low word ;an000; dms;
2421 mov cs:[bp].ER_Move_Count_High,dx ;save high word ;an000; dms;
2422
2423 pop dx ;restore regs ;an000; dms;
2424 pop ax ; ;an000; dms;
2425
2426 ret ;return to caller ;an000; dms;
2427
2428 ER_Det_Move_Count endp ;end proc ;an000; dms;
2429
2430 ;=========================================================================
2431 ; ER_Move_Source_To_Buffer : This routine moves the source data to
2432 ; the buffer before it is transferred to
2433 ; its final destination.
2434 ;
2435 ; Inputs : BP - carries type of memory for source/dest
2436 ; Bit 0 - Destination (EMS if set)
2437 ; Bit 1 - Source (EMS if set)
2438 ;
2439 ; Outputs : ER_Move_Xchg_Buffer1 - Source data
2440 ;=========================================================================
2441
2442 ER_Move_Source_To_Buffer proc ; ;an000; dms;
2443
2444 push ax ;save regs ;an000; dms;
2445 push bx ; ;an000; dms;
2446 push dx ; ;an000; dms;
2447 push di ; ;an000; dms;
2448 push es ; ;an000; dms;
2449
2450 test cs:[bp].ER_Mem_Type,ER_Source_EMS_Memory;Source EMS? ;an000; dms;
2451 jz ER_Move_Source_Conv_Mem ;no - adjust seg:off ;an000; dms;
2452 jmp ER_Move_Source_EMS_Mem ;yes- continue move ;an000; dms;
2453
2454 ER_Move_Source_Conv_Mem:
2455
2456 cmp cs:[bp].ER_Direction_Flag,ER_Down ;reverse move? ;an000; dms;
2457 ; $if e ;yes ;an000; dms;
2458 JNE ER_IF34
2459 mov ax,ds ;adjust segment:off ;an000; dms;
2460 dec ax ;segment - 1 para ;an000; dms;
2461 mov ds,ax ; ;an000; dms;
2462 add si,ER_10H ;adjust offset for 1 ;an000; dms;
2463 ; $else ;forward move ;an000; dms;
2464 JMP SHORT ER_EN34
2465 ER_IF34:
2466 mov ax,ds ;get segment value ;an000; dms;
2467 mov dx,si ;get offset value ;an000; dms;
2468 call ER_Segment_Adjust ;adjust the seg:off ;an000; dms;
2469 mov ds,ax ;restore ds ;an000; dms;
2470 mov si,dx ;restore offset ;an000; dms;
2471 ; $endif ; ;an000; dms;
2472 ER_EN34:
2473 jmp ER_Move_Source_Count ;determine count ;an000; dms;
2474
2475 ER_Move_Source_EMS_Mem:
2476
2477
2478 cmp cs:[bp].ER_Direction_Flag,ER_Down ;reverse move? ;an000; dms;
2479 ; $if e ;yes ;an000; dms;
2480 JNE ER_IF37
2481 cmp si,0ffffh ;beginning of log page ;an000; dms;
2482 ; $if e ;yes ;an000; dms;
2483 JNE ER_IF38
2484 dec cs:[bp].ER_Source_Page ;adjust page ptr ;an000; dms;
2485 mov si,EMS_Page_Size_In_Bytes;get page size ;an000; dms;
2486 ; $endif ; ;an000; dms;
2487 ER_IF38:
2488 ; $else ;forward move ;an000; dms;
2489 JMP SHORT ER_EN37
2490 ER_IF37:
2491 cmp si,4000h ;wrap beyond page ;an000; dms;
2492 ; $if e ;yes ;an000; dms;
2493 JNE ER_IF41
2494 inc cs:[bp].ER_Source_Page ;adjust page ptr ;an000; dms;
2495 xor si,si ;clear si ;an000; dms;
2496 ; $endif ; ;an000; dms;
2497 ER_IF41:
2498 ; $endif ; ;an000; dms;
2499 ER_EN37:
2500 mov bx,cs:[bp].ER_Source_Page ;pass page to map ;an000; dms;
2501 call ER_Map_Next_Src_Page ;no - map in current pg;an000; dms;
2502
2503 ER_Move_Source_Count:
2504
2505 mov cx,ER_10H ;default count ;an000; dms;
2506 cmp cs:[bp].ER_Move_Count_High,0 ;high word set ;an000; dms;
2507 jne ER_Move_Source_High_Set ;yes - use default ;an000; dms;
2508 cmp cs:[bp].ER_Move_Count_Low,cx ;>= 10h bytes ;an000; dms;
2509 jae ER_Move_Source_High_Set ;yes - use default ;an000; dms;
2510 mov cx,cs:[bp].ER_Move_Count_Low ;no - use last few bytes;an000; dms;
2511
2512 ER_Move_Source_High_Set:
2513
2514 cmp cs:[bp].ER_Direction_Flag,ER_Down ;reverse move? ;an000; dms;
2515 ; $if e ;yes ;an000; dms;
2516 JNE ER_IF44
2517 cmp si,di ;source >= dest? ;an000; dms;
2518 ; $if b ;no ;an000; dms;
2519 JNB ER_IF45
2520 cmp si,ER_10H ;source >= 10h? ;an000; dms;
2521 ; $if b ;no ;an000; dms;
2522 JNB ER_IF46
2523 mov cx,si ;get move count ;an000; dms;
2524 inc cx ;always 1 byte off ;an000; dms;
2525 ; $endif ; ;an000; dms;
2526 ER_IF46:
2527 ; $else ;source >= dest ;an000; dms;
2528 JMP SHORT ER_EN45
2529 ER_IF45:
2530 cmp di,ER_10H ;dest >= 10h? ;an000; dms;
2531 ; $if b ;no ;an000; dms;
2532 JNB ER_IF49
2533 mov cx,di ;get move count ;an000; dms;
2534 inc cx ;always 1 byte off ;an000; dms;
2535 ; $endif ; ;an000; dms;
2536 ER_IF49:
2537 ; $endif ; ;an000; dms;
2538 ER_EN45:
2539 ; $else ;forward move ;an000; dms;
2540 JMP SHORT ER_EN44
2541 ER_IF44:
2542 cmp si,di ;source >= dest? ;an000; dms;
2543 ; $if a ;yes ;an000; dms;
2544 JNA ER_IF53
2545 mov ax,4000h ;get end of page ;an000; dms;
2546 sub ax,si ;get bytes remaining ;an000; dms;
2547 cmp ax,ER_10H ;source >= 10h ;an000; dms;
2548 ; $if b ;no ;an000; dms;
2549 JNB ER_IF54
2550 mov cx,ax ;get remaining count ;an000; dms;
2551 ; $endif ; ;an000; dms;
2552 ER_IF54:
2553 ; $else ;source >= dest ;an000; dms;
2554 JMP SHORT ER_EN53
2555 ER_IF53:
2556 mov ax,4000h ;get end of page ;an000; dms;
2557 sub ax,di ;get bytes remaining ;an000; dms;
2558 cmp ax,ER_10H ;dest >= 10h ;an000; dms;
2559 ; $if b ;no ;an000; dms;
2560 JNB ER_IF57
2561 mov cx,ax ;get remaining count ;an000; dms;
2562 ; $endif ; ;an000; dms;
2563 ER_IF57:
2564 ; $endif ; ;an000; dms;
2565 ER_EN53:
2566 ; $endif ; ;an000; dms;
2567 ER_EN44:
2568
2569 jmp ER_Move_Source_Default_Count ;continue routine ;an000; dms;
2570
2571 ER_Move_Source_Default_Count:
2572
2573 mov cs:[bp].ER_Current_Move_Count,cx ;save current move cnt ;an000; dms;
2574
2575 sub cs:[bp].ER_Move_Count_Low,cx ;get new count ;an000; dms;
2576 sbb cs:[bp].ER_Move_Count_High,0 ;pick up borrow ;an000; dms;
2577
2578 mov ax,cs ;get seg for buffer ;an000; dms;
2579 mov es,ax ;put into es ;an000; dms;
2580 mov di,offset cs:ER_Move_Xchg_Buffer1 ;offset of buffer ;an000; dms;
2581 add di,bp ;offset BP relative ;an000; dms;
2582
2583 cmp cs:[bp].ER_Direction_Flag,ER_Down ;reverse move? ;an000; dms;
2584 ; $if e ;yes ;an000; dms;
2585 JNE ER_IF61
2586 add di,ER_10H ;end of buffer + 1 ;an000; dms;
2587 dec di ;end of buffer ;an000; dms;
2588 ; $endif ; ;an000; dms;
2589 ER_IF61:
2590
2591
2592 cmp cs:[bp].ER_Direction_Flag,ER_Down ;reverse move? ;an000; dms;
2593 ; $if e ;yes ;an000; dms;
2594 JNE ER_IF63
2595 std ;reverse move ;an000; dms;
2596 ; $else ;forward move ;an000; dms;
2597 JMP SHORT ER_EN63
2598 ER_IF63:
2599 cld ; ;an000; dms;
2600 ; $endif ; ;an000; dms;
2601 ER_EN63:
2602 cli ;ints off ;an000; dms;
2603 rep movsb ;move the data ;an000; dms;
2604 sti ;ints on ;an000; dms;
2605
2606 ER_Move_Source_Exit:
2607
2608 pop es ;restore regs ;an000; dms;
2609 pop di ; ;an000; dms;
2610 pop dx ; ;an000; dms;
2611 pop bx ; ;an000; dms;
2612 pop ax ; ;an000; dms;
2613
2614 ret ;return to caller ;an000; dms;
2615
2616 ER_Move_Source_To_Buffer endp ;end proc ;an000; dms;
2617
2618
2619 ;=========================================================================
2620 ; ER_Move_Buffer_To_Dest : This routine moves the data in the buffer
2621 ; to the destination specified by the user.
2622 ;
2623 ; Inputs : BP - carries type of memory for source/dest
2624 ; Bit 0 - Destination (EMS if set)
2625 ; Bit 1 - Source (EMS if set)
2626 ; ER_Move_Xchg_Buffer1 - Source data
2627 ;
2628 ; Outputs : Adjusted segment:offset or page/offset
2629 ;=========================================================================
2630
2631 ER_Move_Buffer_To_Dest proc ; ;an000; dms;
2632
2633 push ax ;save regs ;an000; dms;
2634 push bx ; ;an000; dms;
2635 push dx ; ;an000; dms;
2636 push si ; ;an000; dms;
2637 push ds ; ;an000; dms;
2638
2639 test cs:[bp].ER_Mem_Type,ER_Dest_EMS_Memory ;Source EMS? ;an000; dms;
2640 jz ER_Move_Buffer_Conv_Mem ;no - adjust seg:off ;an000; dms;
2641 jmp ER_Move_Buffer_EMS_Mem ;yes- continue move ;an000; dms;
2642
2643 ER_Move_Buffer_Conv_Mem:
2644
2645 cmp cs:[bp].ER_Direction_Flag,ER_Down ;reverse move? ;an000; dms;
2646 ; $if e ;yes ;an000; dms;
2647 JNE ER_IF66
2648 mov ax,es ;adjust segment:off ;an000; dms;
2649 dec ax ;segment - 1 para ;an000; dms;
2650 mov es,ax ; ;an000; dms;
2651 add di,ER_10H ;adjust offset for 1 ;an000; dms;
2652 ; $else ;forward move? ;an000; dms;
2653 JMP SHORT ER_EN66
2654 ER_IF66:
2655 mov ax,es ;adjust seg:off ;an000; dms;
2656 mov dx,di ; ;an000; dms;
2657 call ER_Segment_Adjust ; ;an000; dms;
2658 mov es,ax ;new seg:off ;an000; dms;
2659 mov di,dx ; ;an000; dms;
2660 ; $endif ; ;an000; dms;
2661 ER_EN66:
2662 ; para
2663 jmp ER_Move_Buffer_Count ;determine count ;an000; dms;
2664
2665 ER_Move_Buffer_EMS_Mem:
2666
2667 cmp cs:[bp].ER_Direction_Flag,ER_Down ;reverse move? ;an000; dms;
2668 ; $if e ;yes ;an000; dms;
2669 JNE ER_IF69
2670 cmp di,0ffffh ;beginning of log page ;an000; dms;
2671 ; $if e ;yes ;an000; dms;
2672 JNE ER_IF70
2673 dec cs:[bp].ER_Dest_Page ;next page ;an000; dms;
2674 mov di,EMS_Page_Size_In_Bytes;end of page ;an000; dms;
2675 ; $endif ; ;an000; dms;
2676 ER_IF70:
2677 ; $else ;forward move ;an000; dms;
2678 JMP SHORT ER_EN69
2679 ER_IF69:
2680 cmp di,4000h ;end of page? ;an000; dms;
2681 ; $if e ;yes ;an000; dms;
2682 JNE ER_IF73
2683 inc cs:[bp].ER_Dest_Page ;next page ;an000; dms;
2684 xor di,di ;clear di ;an000; dms;
2685 ; $endif ; ;an000; dms;
2686 ER_IF73:
2687 ; $endif ; ;an000; dms;
2688 ER_EN69:
2689 mov bx,cs:[bp].ER_Dest_Page ;pass page to map ;an000; dms;
2690 call ER_Map_Next_Dest_Page ;map in the page ;an000; dms;
2691
2692 ER_Move_Buffer_Count:
2693
2694 mov cx,cs:[bp].ER_Current_Move_Count ;get move from source ;an000; dms;
2695
2696 mov ax,cs ;get seg for buffer ;an000; dms;
2697 mov ds,ax ;put into es ;an000; dms;
2698 mov si,offset cs:ER_Move_Xchg_Buffer1 ;offset of buffer ;an000; dms;
2699 add si,bp ;offset BP relative ;an000; dms;
2700 cmp cs:[bp].ER_Direction_Flag,ER_Down ;reverse move? ;an000; dms;
2701 ; $if e ;yes ;an000; dms;
2702 JNE ER_IF76
2703 add si,ER_10H ;end of buffer + 1 ;an000; dms;
2704 dec si ;end of buffer ;an000; dms;
2705 ; $endif ; ;an000; dms;
2706 ER_IF76:
2707
2708 cmp cs:[bp].ER_Direction_Flag,ER_Down ;reverse move? ;an000; dms;
2709 ; $if e ;yes ;an000; dms;
2710 JNE ER_IF78
2711 std ;reverse move ;an000; dms;
2712 ; $else ;forward move ;an000; dms;
2713 JMP SHORT ER_EN78
2714 ER_IF78:
2715 cld ; ;an000; dms;
2716 ; $endif ; ;an000; dms;
2717 ER_EN78:
2718 cli ;ints off ;an000; dms;
2719 rep movsb ;move the data ;an000; dms;
2720 sti ;ints on ;an000; dms;
2721
2722 ER_Move_Dest_Exit:
2723
2724 pop ds ;restore regs ;an000; dms;
2725 pop si ; ;an000; dms;
2726 pop dx ; ;an000; dms;
2727 pop bx ; ;an000; dms;
2728 pop ax ; ;an000; dms;
2729
2730 ret ;return to caller ;an000; dms;
2731
2732 ER_Move_Buffer_To_Dest endp ;end proc ;an000; dms;
2733
2734
2735 ;=========================================================================
2736 ; ER_Xchg_Source_To_Buffer : This routine moves the source data to
2737 ; the buffer before it is exchanged with
2738 ; the destination data.
2739 ;
2740 ; Inputs : BP - carries type of memory for source/dest
2741 ; Bit 0 - Destination (EMS if set)
2742 ; Bit 1 - Source (EMS if set)
2743 ;
2744 ; Outputs : ER_Move_Xchg_Buffer1 - Source data
2745 ;=========================================================================
2746
2747 ER_Xchg_Source_To_Buffer proc ; ;an000; dms;
2748
2749 push ax ;save regs ;an000; dms;
2750 push bx ; ;an000; dms;
2751 push dx ; ;an000; dms;
2752 push di ; ;an000; dms;
2753 push si ; ;an000; dms;
2754 push ds ; ;an000; dms;
2755 push es ; ;an000; dms;
2756
2757 test cs:[bp].ER_Mem_Type,ER_Source_EMS_Memory;Source EMS? ;an000; dms;
2758 jz ER_Xchg_Source_Conv_Mem ;no - adjust seg:off ;an000; dms;
2759 jmp ER_Xchg_Source_EMS_Mem ;yes- continue move ;an000; dms;
2760
2761 ER_Xchg_Source_Conv_Mem:
2762
2763 mov ax,ds ;adjust segment:off ;an000; dms;
2764 mov dx,si ; ;an000; dms;
2765 call ER_Segment_Adjust ; ;an000; dms;
2766 mov ds,ax ;new segment:off ;an000; dms;
2767 mov si,dx ; ;an000; dms;
2768 jmp ER_Xchg_Source_Count ;determine count ;an000; dms;
2769
2770 ER_Xchg_Source_EMS_Mem:
2771
2772 cmp si,4000h ;beginning of log page ;an000; dms;
2773 je ER_Xchg_Source_EMS_Next ;yes - get next page ;an000; dms;
2774 mov bx,cs:[bp].ER_Source_Page ;pass log. page to call ;an000; dms;
2775 call ER_Map_Next_Src_Page ;no - map in current pg;an000; dms;
2776 jmp ER_Xchg_Source_Count ;get count for move ;an000; dms;
2777
2778 ER_Xchg_Source_EMS_Next:
2779
2780 mov bx,cs:[bp].ER_Source_Page ;pass log. page to call ;an000; dms;
2781 inc bx ; adjusted upward ;an000; dms;
2782 call ER_Map_Next_Src_Page ;map in the page ;an000; dms;
2783 xor si,si ;reinit pointer ;an000; dms;
2784
2785 ER_Xchg_Source_Count:
2786
2787 mov cx,ER_10H ;default count ;an000; dms;
2788 cmp cs:[bp].ER_Move_Count_High,0 ;high word set ;an000; dms;
2789 jne ER_Xchg_Source_High_Set ;yes - use default ;an000; dms;
2790 cmp cs:[bp].ER_Move_Count_Low,cx ;>= 10h bytes ;an000; dms;
2791 jae ER_Xchg_Source_High_Set ;yes - use default ;an000; dms;
2792 mov cx,cs:[bp].ER_Move_Count_Low ;no - use last few bytes;an000; dms;
2793
2794 ER_Xchg_Source_High_Set:
2795
2796 cmp si,di ;source >= dest? ;an000; dms;
2797 ; $if b ;no ;an000; dms;
2798 JNB ER_IF81
2799 mov ax,4000h ;get end of page ;an000; dms;
2800 sub ax,si ;get bytes remaining ;an000; dms;
2801 cmp ax,ER_10H ;source >= 10h ;an000; dms;
2802 ; $if b ;no ;an000; dms;
2803 JNB ER_IF82
2804 mov cx,ax ;get remaining count ;an000; dms;
2805 ; $endif ; ;an000; dms;
2806 ER_IF82:
2807 ; $else ;source >= dest ;an000; dms;
2808 JMP SHORT ER_EN81
2809 ER_IF81:
2810 mov ax,4000h ;get end of page ;an000; dms;
2811 sub ax,di ;get bytes remaining ;an000; dms;
2812 cmp ax,ER_10H ;dest >= 10h ;an000; dms;
2813 ; $if b ;no ;an000; dms;
2814 JNB ER_IF85
2815 mov cx,ax ;get remaining count ;an000; dms;
2816 ; $endif ; ;an000; dms;
2817 ER_IF85:
2818 ; $endif ; ;an000; dms;
2819 ER_EN81:
2820
2821 ER_Xchg_Source_Default_Count:
2822
2823 mov cs:[bp].ER_Current_Move_Count,cx ;save current move cnt ;an000; dms;
2824
2825 sub cs:[bp].ER_Move_Count_Low,cx ;get new count ;an000; dms;
2826 sbb cs:[bp].ER_Move_Count_High,0 ;pick up borrow ;an000; dms;
2827
2828 mov ax,cs ;get seg for buffer ;an000; dms;
2829 mov es,ax ;put into es ;an000; dms;
2830 mov di,offset cs:ER_Move_Xchg_Buffer1 ;offset of buffer ;an000; dms;
2831 add di,bp ;offset BP relative ;an000; dms;
2832
2833 cld ;forward move ;an000; dms;
2834 cli ;ints off ;an000; dms;
2835 rep movsb ;move the data ;an000; dms;
2836 sti ;ints on ;an000; dms;
2837
2838 ER_Xchg_Source_Exit:
2839
2840 pop es ;restore regs ;an000; dms;
2841 pop ds ; ;an000; dms;
2842 pop si ; ;an000; dms;
2843 pop di ; ;an000; dms;
2844 pop dx ; ;an000; dms;
2845 pop bx ; ;an000; dms;
2846 pop ax ; ;an000; dms;
2847
2848 ret ;return to caller ;an000; dms;
2849
2850 ER_Xchg_Source_To_Buffer endp ;end proc ;an000; dms;
2851
2852
2853 ;=========================================================================
2854 ; ER_Xchg_Dest_To_Buffer : This routine moves the destination data to
2855 ; the buffer before it is exchanged with
2856 ; the source data.
2857 ;
2858 ; Inputs : BP - carries type of memory for source/dest
2859 ; Bit 0 - Destination (EMS if set)
2860 ; Bit 1 - Source (EMS if set)
2861 ;
2862 ; Outputs : ER_Move_Xchg_Buffer2 - Destination data
2863 ;=========================================================================
2864
2865 ER_Xchg_Dest_To_Buffer proc ; ;an000; dms;
2866
2867 push ax ;save regs ;an000; dms;
2868 push bx ; ;an000; dms;
2869 push dx ; ;an000; dms;
2870 push di ; ;an000; dms;
2871 push si ; ;an000; dms;
2872 push ds ; ;an000; dms;
2873 push es ; ;an000; dms;
2874
2875 test cs:[bp].ER_Mem_Type,ER_Dest_EMS_Memory ;Dest EMS? ;an000; dms;
2876 jz ER_Xchg_Dest_Conv_Mem ;no - adjust seg:off ;an000; dms;
2877 jmp ER_Xchg_Dest_EMS_Mem ;yes- continue move ;an000; dms;
2878
2879 ER_Xchg_Dest_Conv_Mem:
2880
2881 mov ax,es ;adjust segment:off ;an000; dms;
2882 mov dx,di ; ;an000; dms;
2883 call ER_Segment_Adjust ; ;an000; dms;
2884 mov es,ax ;new segment:off ;an000; dms;
2885 mov di,dx ; ;an000; dms;
2886 jmp ER_Xchg_Dest_Count ;determine count ;an000; dms;
2887
2888 ER_Xchg_Dest_EMS_Mem:
2889
2890 cmp di,4000h ;beginning of log page ;an000; dms;
2891 je ER_Xchg_Dest_EMS_Next ;yes - get next page ;an000; dms;
2892 mov bx,cs:[bp].ER_Dest_Page ;pass log. page to call ;an000; dms;
2893 call ER_Map_Next_Dest_Page ;no - map in current pg;an000; dms;
2894 jmp ER_Xchg_Dest_Count ;get count for move ;an000; dms;
2895
2896 ER_Xchg_Dest_EMS_Next:
2897
2898 mov bx,cs:[bp].ER_Dest_Page ;pass log. page to call ;an000; dms;
2899 inc bx ; adjusted upward ;an000; dms;
2900 call ER_Map_Next_Dest_Page ;map in the page ;an000; dms;
2901 xor di,di ;reinit pointer ;an000; dms;
2902
2903 ER_Xchg_Dest_Count:
2904
2905 mov cx,cs:[bp].ER_Current_Move_Count ;get move count ;an000; dms;
2906 mov ax,es ;get destination seg ;an000; dms;
2907 mov ds,ax ;put into ds for buffer ;an000; dms;
2908 ; transfer
2909 mov si,di ;get destination off ;an000; dms;
2910 mov ax,cs ;get seg for buffer ;an000; dms;
2911 mov es,ax ;put into es ;an000; dms;
2912 mov di,offset cs:ER_Move_Xchg_Buffer2 ;offset of buffer ;an000; dms;
2913 add di,bp ;offset BP relative ;an000; dms;
2914
2915 cld ;forward move ;an000; dms;
2916 cli ;ints off ;an000; dms;
2917 rep movsb ;move the data ;an000; dms;
2918 sti ;ints on ;an000; dms;
2919
2920 ER_Xchg_Dest_Exit:
2921
2922 pop es ;restore regs ;an000; dms;
2923 pop ds ; ;an000; dms;
2924 pop si ; ;an000; dms;
2925 pop di ; ;an000; dms;
2926 pop dx ; ;an000; dms;
2927 pop bx ; ;an000; dms;
2928 pop ax ; ;an000; dms;
2929
2930 ret ;return to caller ;an000; dms;
2931
2932 ER_Xchg_Dest_To_Buffer endp ;end proc ;an000; dms;
2933
2934
2935
2936
2937 ;=========================================================================
2938 ; ER_Xchg_Buffer_To_Source ; This routine performs the actual exchange
2939 ; from the destination buffer to the source
2940 ; buffer.
2941 ;
2942 ; Inputs : BP - carries type of memory for source/dest
2943 ; Bit 0 - Destination (EMS if set)
2944 ; Bit 1 - Source (EMS if set)
2945 ; ER_Move_Xchg_Buffer2 - Destination data
2946 ;
2947 ; Outputs : Adjusted segment:offset or page/offset
2948 ;=========================================================================
2949
2950 ER_Xchg_Buffer_To_Source proc ; ;an000; dms;
2951
2952 push ax ;save regs ;an000; dms;
2953 push bx ; ;an000; dms;
2954 push dx ; ;an000; dms;
2955 push di ; ;an000; dms;
2956 push es ; ;an000; dms;
2957
2958 test cs:[bp].ER_Mem_Type,ER_Source_EMS_Memory;Source EMS? ;an000; dms;
2959 jz ER_Xchg_Buf2_Conv_Mem ;no - adjust seg:off ;an000; dms;
2960 jmp ER_Xchg_Buf2_EMS_Mem ;yes- continue move ;an000; dms;
2961
2962 ER_Xchg_Buf2_Conv_Mem:
2963
2964 mov ax,ds ;adjust segment:off ;an000; dms;
2965 mov dx,si ; ;an000; dms;
2966 call ER_Segment_Adjust ; ;an000; dms;
2967 mov ds,ax ;new segment:off ;an000; dms;
2968 mov si,dx ; ;an000; dms;
2969 jmp ER_Xchg_Buf2_Count ;determine count ;an000; dms;
2970
2971 ER_Xchg_Buf2_EMS_Mem:
2972
2973 cmp si,4000h ;beginning of log page ;an000; dms;
2974 je ER_Xchg_Buf2_EMS_Next ;yes - get next page ;an000; dms;
2975 mov bx,cs:[bp].ER_Source_Page ;pass log. page to call ;an000; dms;
2976 call ER_Map_Next_Src_Page ;no - map in current pg;an000; dms;
2977 jmp ER_Xchg_Buf2_Count ;get count for move ;an000; dms;
2978
2979 ER_Xchg_Buf2_EMS_Next:
2980
2981 inc cs:[bp].ER_Source_Page ;adjust log page ;an000; dms;
2982 mov bx,cs:[bp].ER_Source_Page ;pass log. page to call ;an000; dms;
2983 call ER_Map_Next_Src_Page ;map in the page ;an000; dms;
2984 xor si,si ;reinit pointer ;an000; dms;
2985
2986 ER_Xchg_Buf2_Count:
2987
2988 mov cx,cs:[bp].ER_Current_Move_Count ;get move count ;an000; dms;
2989
2990 mov ax,ds ;get destination seg ;an000; dms;
2991 mov es,ax ;put into ds for buffer ;an000; dms;
2992 ; transfer
2993 mov di,si ;get destination off ;an000; dms;
2994 add si,cx ;adjust source ptr ;an000; dms;
2995 push si ;save across xchg ;an000; dms;
2996 push ds ; ;an000; dms;
2997
2998 mov ax,cs ;get seg for buffer ;an000; dms;
2999 mov ds,ax ;put into es ;an000; dms;
3000 mov si,offset cs:ER_Move_Xchg_Buffer2 ;offset of buffer ;an000; dms;
3001 add si,bp ;offset BP relative ;an000; dms;
3002
3003 cld ;forward move ;an000; dms;
3004 cli ;ints off ;an000; dms;
3005 rep movsb ;move the data ;an000; dms;
3006 sti ;ints on ;an000; dms;
3007
3008 pop ds ;restore ptr ;an000; dms;
3009 pop si ; ;an000; dms;
3010
3011 ER_Xchg_Buf2_Exit:
3012
3013 pop es ;restore regs ;an000; dms;
3014 pop di ; ;an000; dms;
3015 pop dx ; ;an000; dms;
3016 pop bx ; ;an000; dms;
3017 pop ax ; ;an000; dms;
3018
3019 ret ;return to caller ;an000; dms;
3020
3021 ER_Xchg_Buffer_To_Source endp ;end proc ;an000; dms;
3022
3023
3024
3025 ;=========================================================================
3026 ; ER_Xchg_Buffer_To_Dest ; This routine performs the actual exchange
3027 ; from the source buffer to the destination.
3028 ;
3029 ; Inputs : BP - carries type of memory for source/dest
3030 ; Bit 0 - Destination (EMS if set)
3031 ; Bit 1 - Source (EMS if set)
3032 ; ER_Move_Xchg_Buffer1 - Source data
3033 ;
3034 ; Outputs : Adjusted segment:offset or page/offset
3035 ;=========================================================================
3036
3037 ER_Xchg_Buffer_To_Dest proc ; ;an000; dms;
3038
3039 push ax ;save regs ;an000; dms;
3040 push bx ; ;an000; dms;
3041 push dx ; ;an000; dms;
3042 push si ; ;an000; dms;
3043 push ds ; ;an000; dms;
3044
3045 test cs:[bp].ER_Mem_Type,ER_Dest_EMS_Memory ;Dest EMS? ;an000; dms;
3046 jz ER_Xchg_Buf1_Conv_Mem ;no - adjust seg:off ;an000; dms;
3047 jmp ER_Xchg_Buf1_EMS_Mem ;yes- continue move ;an000; dms;
3048
3049 ER_Xchg_Buf1_Conv_Mem:
3050
3051 mov ax,es ;adjust segment:off ;an000; dms;
3052 mov dx,di ; ;an000; dms;
3053 call ER_Segment_Adjust ; ;an000; dms;
3054 mov es,ax ;new segment:off ;an000; dms;
3055 mov di,dx ; ;an000; dms;
3056 jmp ER_Xchg_Buf1_Count ;determine count ;an000; dms;
3057
3058 ER_Xchg_Buf1_EMS_Mem:
3059
3060 cmp di,4000h ;beginning of log page ;an000; dms;
3061 je ER_Xchg_Buf1_EMS_Next ;yes - get next page ;an000; dms;
3062 mov bx,cs:[bp].ER_Dest_Page ;pass log. page to call ;an000; dms;
3063 call ER_Map_Next_Dest_Page ;no - map in current pg;an000; dms;
3064 jmp ER_Xchg_Buf1_Count ;get count for move ;an000; dms;
3065
3066 ER_Xchg_Buf1_EMS_Next:
3067
3068 inc cs:[bp].ER_Dest_Page ;adjust log page ;an000; dms;
3069 mov bx,cs:[bp].ER_Dest_Page ;pass log. page to call ;an000; dms;
3070 call ER_Map_Next_Dest_Page ;map in the page ;an000; dms;
3071 mov di,EMS_Page_Size_In_Bytes ;reinit pointer ;an000; dms;
3072
3073 ER_Xchg_Buf1_Count:
3074
3075 mov cx,cs:[bp].ER_Current_Move_Count ;get move count ;an000; dms;
3076 mov ax,cs ;get seg for buffer ;an000; dms;
3077 mov ds,ax ;put into es ;an000; dms;
3078 mov si,offset cs:ER_Move_Xchg_Buffer1 ;offset of buffer ;an000; dms;
3079 add si,bp ;offset BP relative ;an000; dms;
3080
3081 cld ;forward move ;an000; dms;
3082 cli ;ints off ;an000; dms;
3083 rep movsb ;move the data ;an000; dms;
3084 sti ;ints on ;an000; dms;
3085
3086 ER_Xchg_Buf1_Exit:
3087
3088 pop ds ;restore regs ;an000; dms;
3089 pop si ; ;an000; dms;
3090 pop dx ; ;an000; dms;
3091 pop bx ; ;an000; dms;
3092 pop ax ; ;an000; dms;
3093
3094 ret ;return to caller ;an000; dms;
3095
3096 ER_Xchg_Buffer_To_Dest endp ;end proc ;an000; dms;
3097
3098
3099
3100 ;=========================================================================
3101 ; ER_Map_Next_Src_Page : This routine maps in the page needed by
3102 ; the source of the move/exchange.
3103 ;
3104 ; Inputs : ER_Source_Phys_Page - Physical page of source
3105 ; ER_Source_Handle - Handle of source
3106 ; BX - logical page
3107 ;
3108 ; Outputs : newly mapped page
3109 ;=========================================================================
3110
3111 ER_Map_Next_Src_Page proc ;map next src. page ;an000; dms;
3112
3113 mov ax,cs:[bp].ER_Source_Phys_Page ;map the source page ;an000; dms;
3114 mov dx,cs:[bp].ER_Source_Handle ;handle to use ;an000; dms;
3115 call Map_L_To_P ;map the page ;an000; dms;
3116
3117 ret ;return to caller ;an000; dms;
3118
3119 ER_Map_Next_Src_Page endp ;end proc ;an000; dms;
3120
3121 ;=========================================================================
3122 ; ER_Map_Next_Dest_Page : This routine maps in the page needed by
3123 ; the destination of the move/exchange.
3124 ;
3125 ; Inputs : ER_Dest_Phys_Page - Physical page of source
3126 ; ER_Dest_Handle - Handle of source
3127 ; BX - logical page to map
3128 ;
3129 ; Outputs : newly mapped page
3130 ;=========================================================================
3131
3132 ER_Map_Next_Dest_Page proc ;map next dest. page ;an000; dms;
3133
3134 mov ax,cs:[bp].ER_Dest_Phys_Page ;map the dest. page ;an000; dms;
3135 mov dx,cs:[bp].ER_Dest_Handle ;handle to use ;an000; dms;
3136 call Map_L_To_P ;map the page ;an000; dms;
3137
3138 ret ;return to caller ;an000; dms;
3139
3140 ER_Map_Next_Dest_Page endp ;end proc ;an000; dms;
3141
3142 ;=========================================================================
3143 ; ER_Move_Data : This routine will perform the actual move of the
3144 ; data for the function 5700h.
3145 ;
3146 ; Inputs : DS:SI - Pointer to Move_Source_Dest_Struc data
3147 ;
3148 ; Outputs : AH - Non-zero on error
3149 ;=========================================================================
3150
3151 ER_Move_Data proc ;move the data ;an000; dms;
3152
3153 push bx ;save regs ;an000; dms;
3154 push cx ; ;an000; dms;
3155 push dx ; ;an000; dms;
3156 push di ; ;an000; dms;
3157 push si ; ;an000; dms;
3158 push ds ; ;an000; dms;
3159 push es ; ;an000; dms;
3160
3161 call ER_Save_Context ;save off max of 2 pages;an000; dms;
3162 call ER_Det_Src_Dest_Seg ;determine segs ;an000; dms;
3163 call ER_Det_Move_Count ;ER_10h_Move_Count = ;an000; dms;
3164 ; # of 10h moves
3165 ;ER_10h_Move_Remainder =
3166 ; # of bytes remaining
3167
3168 ER_Move_Data_Now:
3169
3170 ;set the flags to signal
3171 ;the memory type in use
3172 ;for Source/Destination.
3173
3174 xor al,al ;al signals type of mem ;an000; dms;
3175 or al,[si].Source_Memory_Type ;get source memory type ;an000; dms;
3176 shl al,1 ;put into bit 1 ;an000; dms;
3177 or al,[si].Dest_Memory_Type ;get dest. memory type ;an000; dms;
3178 cbw ;make it a word value ;an000; dms;
3179 mov cs:[bp].ER_Mem_Type,ax ;put flags in var ;an000; dms;
3180 ;bp = bit 0 - dest mem
3181 ; bit 1 - src mem
3182
3183 mov di,cs:[bp].ER_Dest_Off ;get dest. offset ;an000; dms;
3184 mov es,cs:[bp].ER_Dest_Seg ;get dest. seg ;an000; dms;
3185
3186 mov si,cs:[bp].ER_Source_Off ;get src. offset ;an000; dms;
3187 mov ds,cs:[bp].ER_Source_Seg ;get src. seg ;an000; dms;
3188
3189 ER_Move_Data_Loop:
3190
3191 call ER_Move_Source_To_Buffer ;move data to buffer ;an000; dms;
3192 call ER_Move_Buffer_To_Dest ;move buffer to dest. ;an000; dms;
3193
3194 cmp cs:[bp].ER_Move_Count_High,0 ;end of move? ;an000; dms;
3195 jne ER_Move_Data_Loop ;no - continue loop ;an000; dms;
3196 cmp cs:[bp].ER_Move_Count_Low,0 ;end of move? ;an000; dms;
3197 jne ER_Move_Data_Loop ;no - continue loop ;an000; dms;
3198 ;yes - end of loop ;an000; dms;
3199
3200 ER_Move_Data_Error_Exit:
3201
3202 call ER_Restore_Context ;restore the context ;an000; dms;
3203
3204 pop es ;restore regs ;an000; dms;
3205 pop ds ; ;an000; dms;
3206 pop si ; ;an000; dms;
3207 pop di ; ;an000; dms;
3208 pop dx ; ;an000; dms;
3209 pop cx ; ;an000; dms;
3210 pop bx ; ;an000; dms;
3211
3212 ret ;return to caller ;an000; dms;
3213
3214 ER_Move_Data endp ;end proc ;an000; dms;
3215
3216
3217
3218 ;=========================================================================
3219 ; ER_Exchange_Data : This routine will perform the actual exchange of
3220 ; data for the function 5701h.
3221 ;
3222 ; Inputs : DS:SI - Pointer to Move_Source_Dest_Struc data
3223 ;
3224 ; Outputs : AH - Non-zero on error
3225 ;=========================================================================
3226
3227 ER_Exchange_Data proc ;xchg the data ;an000; dms;
3228
3229 push bx ;save regs ;an000; dms;
3230 push cx ; ;an000; dms;
3231 push dx ; ;an000; dms;
3232 push di ; ;an000; dms;
3233 push si ; ;an000; dms;
3234 push ds ; ;an000; dms;
3235 push es ; ;an000; dms;
3236
3237 call ER_Save_Context ;save off max of 2 pages;an000; dms;
3238 call ER_Det_Src_Dest_Seg ;determine segs ;an000; dms;
3239 call ER_Det_Move_Count ;ER_10h_Move_Count = ;an000; dms;
3240 ; # of 10h moves
3241 ;ER_10h_Move_Remainder =
3242 ; # of bytes remaining
3243
3244 ER_Xchg_Data_Now:
3245
3246 ;set the flags to signal
3247 ;the memory type in use
3248 ;for Source/Destination.
3249
3250 xor al,al ;al signals type of mem ;an000; dms;
3251 or al,[si].Source_Memory_Type ;get source memory type ;an000; dms;
3252 shl al,1 ;put into bit 1 ;an000; dms;
3253 or al,[si].Dest_Memory_Type ;get dest. memory type ;an000; dms;
3254 cbw ;make it a word value ;an000; dms;
3255 mov cs:[bp].ER_Mem_Type,ax ;put flags in var ;an000; dms;
3256 ;bp = bit 0 - dest mem
3257 ; bit 1 - src mem
3258
3259 mov di,cs:[bp].ER_Dest_Off ;get dest. offset ;an000; dms;
3260 mov es,cs:[bp].ER_Dest_Seg ;get dest. seg ;an000; dms;
3261
3262 mov si,cs:[bp].ER_Source_Off ;get src. offset ;an000; dms;
3263 mov ds,cs:[bp].ER_Source_Seg ;get src. seg ;an000; dms;
3264
3265 ER_Xchg_Data_Loop:
3266
3267 call ER_Xchg_Source_To_Buffer ;move source to buf 1 ;an000; dms;
3268 call ER_Xchg_Dest_To_Buffer ;move dest. to buf 2 ;an000; dms;
3269 call ER_Xchg_Buffer_To_Source ;move buf2 to source ;an000; dms;
3270 call ER_Xchg_Buffer_To_Dest ;move buf1 to dest. ;an000; dms;
3271
3272 cmp cs:[bp].ER_Move_Count_High,0 ;end of move? ;an000; dms;
3273 jne ER_Xchg_Data_Loop ;no - continue loop ;an000; dms;
3274 cmp cs:[bp].ER_Move_Count_Low,0 ;end of move? ;an000; dms;
3275 jne ER_Xchg_Data_Loop ;no - continue loop ;an000; dms;
3276 ;yes - end of loop ;an000; dms;
3277
3278 ER_Xchg_Data_Error_Exit:
3279
3280 call ER_Restore_Context ;restore the context ;an000; dms;
3281
3282 pop es ;restore regs ;an000; dms;
3283 pop ds ; ;an000; dms;
3284 pop si ; ;an000; dms;
3285 pop di ; ;an000; dms;
3286 pop dx ; ;an000; dms;
3287 pop cx ; ;an000; dms;
3288 pop bx ; ;an000; dms;
3289
3290 ret ;return to caller ;an000; dms;
3291
3292 ER_Exchange_Data endp ;end proc ;an000; dms;
3293
3294
3295
3296 page
3297
3298 ;=========================================================================
3299 ;=============== Function 5Ah Logic - Allocate Raw Pages =============
3300 ;=========================================================================
3301
3302
3303 ;=========================================================================
3304 ; Alloc_Raw - This routine allocates raw EMS pages, pages
3305 ; less than the standard 16k page. These pages
3306 ; are a sub-multiple of 16k. In the IBM version
3307 ; of this implementation the raw page is defined
3308 ; as 16k, thus we do not need to do anything
3309 ; special here. We map this call to the proc
3310 ; GET_HANDLE (function 43h) to allocate a handle.
3311 ;
3312 ; Inputs : AH - 5Ah (Allocate Raw Pages)
3313 ; BX - Number of raw pages to allocate
3314 ;
3315 ; Outputs : AH - Non-zero if error (Determined by Get_Handle proc)
3316 ; DX - Handle if no error
3317 ;=========================================================================
3318
3319 Alloc_Raw proc ;Allocate raw pages ;an000; dms;
3320
3321 PUSH BX
3322 PUSH CX
3323 PUSH DI
3324 PUSH SI
3325 PUSH DS ;save these registers
3326
3327 PUSH CS ;get cs
3328 POP DS ;into ds
3329
3330 ;Remove test for BX = 0. This is @RH4
3331 ; valid under LIM 4.0
3332
3333 cmp al,AR_Sub_Max ;sub function out of range? ;an000; dms;
3334 jna AR_OKSub ;no ;an000; dms;
3335 mov ah,EMS_Code8F ;yes-signal error ;an000; dms;
3336 jmp AR_Exit ;exit routine ;an000; dms;
3337
3338 AR_OKSub:
3339
3340 CMP BX,TOTAL_EMS_PAGES ;Enough total EMS pages?
3341 JNA AR_OKTOTAL
3342 MOV AH,EMS_CODE87
3343 JMP AR_EXIT
3344
3345 AR_OKTOTAL:
3346 cli ;ints off ;an000; dms;
3347 CMP BX,FREE_PAGES ;Enough unallocated pages?
3348 sti ;ints on ;an000; dms;
3349 JNA AR_OKFREE
3350 MOV AH,EMS_CODE88
3351 JMP AR_EXIT
3352 ;-----------------------------------------------------
3353 ; Search for a free handle @RH1 º
3354 ;-----------------------------------------------------
3355 AR_OKFREE:
3356 MOV CX,NUM_HANDLES ;loop counter is #handles
3357 DEC CX ;handle 0 reserved for op. sys. @RH1
3358 MOV DX,1 ;handle assignment set to 1 @RH1
3359 MOV DI,TYPE H_LOOKUP_STRUC ;init table index to 1st entry @RH1
3360 ;--------------------------------
3361 CLI ;interrupts OFF during allocation
3362 ;--------------------------------
3363 AR_FREEHSRCH:
3364 CMP HANDLE_LOOKUP_TABLE.H_PAGES[DI],REUSABLE_HANDLE
3365 ;Is this handle available? @RH1
3366 JE AR_HFREE ;yes end search dx=handle id @RH1
3367 INC DX ;next handle assignment
3368 ADD DI,TYPE H_LOOKUP_STRUC ;next entry in handle lookup @RH1
3369 ;repeat for all table entries
3370 LOOP AR_FREEHSRCH
3371 MOV AH,EMS_CODE85 ;no available handles
3372 JMP AR_EXIT ;go to exit ;GGA
3373
3374 ;-----------------------------------------------------
3375 ; If here then there's enough pages for request. @RH1 º
3376 ; DX = handle #, DI = ptr to hndl lookup entry @RH1 º
3377 AR_HFREE:
3378
3379 MOV CX,NUM_HANDLES ;loop counter
3380 DEC CX ;handle 0 reserved for op. sys. @RH1
3381 ;si = index to hndl lookup tbl @RH1
3382 MOV SI,TYPE H_LOOKUP_STRUC ; for adding pages (skip 0 entry) @RH1
3383 XOR AX,AX ;clear page counter
3384 CLC ;clear carry for addition
3385 AR_PAGESUM:
3386 CMP HANDLE_LOOKUP_TABLE.H_PAGES[SI],REUSABLE_HANDLE
3387 JE AR_PGSUM_BOT ;If handle is free don't add @RH4
3388 ADD AX,HANDLE_LOOKUP_TABLE.H_PAGES[SI]
3389 ;add lengths (pages) of PALs @RH1
3390 ADD SI,TYPE H_LOOKUP_STRUC ; next entry in handle lookup @RH1
3391 AR_PGSUM_BOT:
3392 LOOP AR_PAGESUM
3393 CMP AX,TOTAL_EMS_PAGES ;pages in handle lookup > total? @RH1
3394 JNA AR_CALCHLUP ;no OK @RH1
3395 MOV AH,EMS_CODE80 ;software error..we screwed up @RH1
3396 JMP AR_EXIT ;go to exit @RH1 ;GGA
3397
3398 AR_CALCHLUP: ;calculate entry in hndl lkup tbl @RH1
3399 cmp bx,0 ;page request? ;an000; dms;
3400 jne AR_Alloc_Cont ;yes continue ;an000; dms;
3401 cli ;ints off ;an001; dms;
3402 mov Handle_LookUp_Table.H_Pages[di],bx ;new page count ;an001; dms;
3403 sti ;ints on ;an001; dms;
3404 xor ah,ah ;clear flag ;an000; dms;
3405 jmp AR_Exit ;exit routine ;an000; dms;
3406
3407 AR_Alloc_Cont:
3408
3409 cli ;ints off ;an001; dms;
3410 mov cx,bx ;alloc count ;an000; dms;
3411 call EMS_Page_Contig_Chk ;do we have contig pgs. ;an001; dms;
3412 jnc AR_Alloc ;yes continue process ;an001; dms;
3413 mov ah,EMS_Code88 ;no signal error ;an001; dms;
3414 sti ;ints on ;an001; dms;
3415 jmp AR_Exit ;exit routine ;an001; dms;
3416
3417 AR_Alloc:
3418
3419 call EMS_Link_Set ;set up links ;an001; dms;
3420
3421
3422 sub Free_Pages,bx ;free = free - requested pages
3423 mov Handle_LookUp_Table.H_Pages[di],bx ;page count ;an000; dms;
3424 mov Handle_LookUp_Table.H_Pal_Ptr[di],si ;initialize to ptr for ;ac001; dms;
3425 ; pages
3426 sti ;ints on ;an001; dms;
3427 xor ah,ah ;clear flag ;an000; dms;
3428
3429
3430 AR_EXIT: ;GGA
3431
3432 POP DS
3433 POP SI
3434 POP DI
3435 POP CX
3436 POP BX
3437
3438 ret ;return to caller ;an000; dms;
3439
3440 Alloc_Raw endp ;end proc ;an000; dms;
3441
3442 page
3443 ;=========================================================================
3444 ;=============== Function 5Ch Logic - Prepare for Warm Boot =============
3445 ;=========================================================================
3446
3447
3448 ;=========================================================================
3449 ; Prepare_Boot - This routine prepares the hardware for a
3450 ; warm boot. Since we have no special hardware
3451 ; requirements at this time, this routine sets
3452 ; a good error level and returns to the caller.
3453 ;
3454 ; Inputs : AH - 5Ch (Prepare for Warm Boot)
3455 ;
3456 ; Outputs : AH - Non-zero if error (Determined by Get_Handle proc)
3457 ;=========================================================================
3458
3459 Prepare_Boot proc ;prepare for warm boot ;an000; dms;
3460
3461 xor ah,ah ;signal no error ;an000; dms;
3462
3463 ret ;return to caller ;an000; dms;
3464
3465 Prepare_Boot endp ;end proc ;an000; dms;
3466
3467
3468