| 1 | ;
|
|---|
| 2 | ; XMS.ASM -- Manage extended memory
|
|---|
| 3 | ;
|
|---|
| 4 | ; Copyright (c) 1991-1995 by Eberhard Mattes
|
|---|
| 5 | ;
|
|---|
| 6 | ; This file is part of emx.
|
|---|
| 7 | ;
|
|---|
| 8 | ; emx is free software; you can redistribute it and/or modify it
|
|---|
| 9 | ; under the terms of the GNU General Public License as published by
|
|---|
| 10 | ; the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 11 | ; any later version.
|
|---|
| 12 | ;
|
|---|
| 13 | ; emx is distributed in the hope that it will be useful,
|
|---|
| 14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 16 | ; GNU General Public License for more details.
|
|---|
| 17 | ;
|
|---|
| 18 | ; You should have received a copy of the GNU General Public License
|
|---|
| 19 | ; along with emx; see the file COPYING. If not, write to
|
|---|
| 20 | ; the Free Software Foundation, 59 Temple Place - Suite 330,
|
|---|
| 21 | ; Boston, MA 02111-1307, USA.
|
|---|
| 22 | ;
|
|---|
| 23 | ; See emx.asm for a special exception.
|
|---|
| 24 | ;
|
|---|
| 25 |
|
|---|
| 26 | INCLUDE EMX.INC
|
|---|
| 27 | INCLUDE MEMORY.INC
|
|---|
| 28 | INCLUDE RPRINT.INC
|
|---|
| 29 | INCLUDE OPTIONS.INC
|
|---|
| 30 | INCLUDE VCPI.INC
|
|---|
| 31 |
|
|---|
| 32 | PUBLIC XMS_FLAG, DISABLE_XMS_MEM
|
|---|
| 33 | PUBLIC CHECK_XMS, INIT_XMS, CLEANUP_XMS
|
|---|
| 34 | PUBLIC XMS_A20_ON, XMS_A20_OFF
|
|---|
| 35 |
|
|---|
| 36 | XMS_NULL_HANDLE = 0
|
|---|
| 37 |
|
|---|
| 38 | SV_DATA SEGMENT
|
|---|
| 39 |
|
|---|
| 40 | XMS_ENTRY LABEL DWORD
|
|---|
| 41 | XMS_OFF DW ?
|
|---|
| 42 | XMS_SEG DW ?
|
|---|
| 43 |
|
|---|
| 44 | XMS_FLAG DB FALSE
|
|---|
| 45 | DISABLE_XMS_MEM DB FALSE
|
|---|
| 46 |
|
|---|
| 47 | $XMS_A20_ON DB "Cannot enable A20 via XMS", CR, LF, 0
|
|---|
| 48 | $XMS_VER DB "Unsupported XMS version", CR, LF, 0
|
|---|
| 49 |
|
|---|
| 50 | SV_DATA ENDS
|
|---|
| 51 |
|
|---|
| 52 | INIT_CODE SEGMENT
|
|---|
| 53 |
|
|---|
| 54 | ASSUME CS:INIT_CODE, DS:NOTHING
|
|---|
| 55 |
|
|---|
| 56 | ;
|
|---|
| 57 | ; Check presence of XMS driver
|
|---|
| 58 | ;
|
|---|
| 59 | ASSUME DS:SV_DATA
|
|---|
| 60 | CHECK_XMS PROC NEAR
|
|---|
| 61 | CMP DISABLE_EXT_MEM, FALSE ; Extended memory disabled?
|
|---|
| 62 | JNE SHORT CX_RET ; Yes -> don't use XMS
|
|---|
| 63 | MOV AX, 4300H ; XMS installation check
|
|---|
| 64 | INT 2FH
|
|---|
| 65 | CMP AL, 80H ; XMS available?
|
|---|
| 66 | JNE SHORT CX_RET ; No -> skip
|
|---|
| 67 | MOV AX, 4310H ; Get entry point
|
|---|
| 68 | INT 2FH
|
|---|
| 69 | MOV XMS_OFF, BX ; Store entry point
|
|---|
| 70 | MOV XMS_SEG, ES
|
|---|
| 71 | MOV AH, 00H ; Get version
|
|---|
| 72 | CALL XMS_ENTRY
|
|---|
| 73 | CMP OVERRIDE_FLAG, FALSE ; Override version check?
|
|---|
| 74 | JNE SHORT CX_OK ; Yes -> skip (danger!)
|
|---|
| 75 | CMP AX, 0200H ; Specification 2.0 or later?
|
|---|
| 76 | JB SHORT XMS_VER ; No -> abort
|
|---|
| 77 | CMP BX, 0206H ; Driver revision >= 2.06?
|
|---|
| 78 | JB SHORT XMS_VER ; No -> abort (buggy driver!)
|
|---|
| 79 | CX_OK: MOV XMS_FLAG, NOT FALSE
|
|---|
| 80 | CX_RET: RET
|
|---|
| 81 |
|
|---|
| 82 | XMS_VER: LEA DX, $XMS_VER ; Unsupported XMS version
|
|---|
| 83 | CALL RTEXT ; Display message
|
|---|
| 84 | MOV AX, 4CFFH ; Abort
|
|---|
| 85 | INT 21H
|
|---|
| 86 |
|
|---|
| 87 | CHECK_XMS ENDP
|
|---|
| 88 |
|
|---|
| 89 | ;
|
|---|
| 90 | ; Initialize high memory (XMS)
|
|---|
| 91 | ;
|
|---|
| 92 | ASSUME DS:SV_DATA
|
|---|
| 93 | INIT_XMS PROC NEAR
|
|---|
| 94 | CMP DISABLE_XMS_MEM, FALSE ; Usage of XMS memory disabled?
|
|---|
| 95 | JNE IX9 ; Yes -> skip
|
|---|
| 96 | LEA SI, HIMEM_TAB[0]
|
|---|
| 97 | ASSUME SI:PTR HIMEM_ENTRY
|
|---|
| 98 | IX1: CMP HIMEM_COUNT, HIMEM_MAX ; Table full?
|
|---|
| 99 | JAE SHORT IX9 ; Yes -> done
|
|---|
| 100 | MOV AH, 08H ; Query free extended memory
|
|---|
| 101 | CALL XMS_ENTRY
|
|---|
| 102 | CMP AX, 7 ; Don't use less than 7KB
|
|---|
| 103 | JB SHORT IX9
|
|---|
| 104 | MOV DX, AX
|
|---|
| 105 | MOVZX EAX, AX
|
|---|
| 106 | SHL EAX, 10 ; Multiply by 1K
|
|---|
| 107 | MOV [SI].HM_SIZE, EAX
|
|---|
| 108 | MOV AH, 09H ; Allocate extended memory blk
|
|---|
| 109 | CALL XMS_ENTRY
|
|---|
| 110 | OR AX, AX ; Ok?
|
|---|
| 111 | JZ SHORT IX9 ; No -> quit loop
|
|---|
| 112 | MOV [SI].HM_HANDLE, DX ; Save handle
|
|---|
| 113 | MOV AH, 0CH ; Lock extended memory block
|
|---|
| 114 | CALL XMS_ENTRY
|
|---|
| 115 | OR AX, AX ; Ok?
|
|---|
| 116 | JZ SHORT IX9 ; No -> quit loop
|
|---|
| 117 | MOV WORD PTR [SI].HM_ADDR[0], BX
|
|---|
| 118 | MOV WORD PTR [SI].HM_ADDR[2], DX
|
|---|
| 119 | ADD SI, SIZE HIMEM_ENTRY
|
|---|
| 120 | INC HIMEM_COUNT
|
|---|
| 121 | JMP SHORT IX1
|
|---|
| 122 | ASSUME SI:NOTHING
|
|---|
| 123 | IX9: RET
|
|---|
| 124 | INIT_XMS ENDP
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 | ASSUME DS:SV_DATA
|
|---|
| 128 | CLEANUP_XMS PROC NEAR
|
|---|
| 129 | CMP XMS_FLAG, FALSE
|
|---|
| 130 | JE SHORT CUX_RET
|
|---|
| 131 | LEA SI, HIMEM_TAB
|
|---|
| 132 | ASSUME SI:PTR HIMEM_ENTRY
|
|---|
| 133 | MOV CX, HIMEM_COUNT
|
|---|
| 134 | JCXZ CUX_RET
|
|---|
| 135 | ;
|
|---|
| 136 | ; Note: If XMS_FLAG is non-zero, we have only extended memory blocks
|
|---|
| 137 | ; allocated via XMS! There won't be a memory block allocated
|
|---|
| 138 | ; by hooking INT 15H.
|
|---|
| 139 | ;
|
|---|
| 140 | CUX_1: MOV DX, [SI].HM_HANDLE
|
|---|
| 141 | MOV AH, 0DH ; Unlock extended memory block
|
|---|
| 142 | CALL XMS_ENTRY
|
|---|
| 143 | MOV AH, 0AH ; Free extended memory block
|
|---|
| 144 | CALL XMS_ENTRY
|
|---|
| 145 | ADD SI, SIZE HIMEM_ENTRY
|
|---|
| 146 | LOOP CUX_1
|
|---|
| 147 | ASSUME SI:NOTHING
|
|---|
| 148 | CUX_RET: RET
|
|---|
| 149 | CLEANUP_XMS ENDP
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 | ;
|
|---|
| 153 | ; Enable A20
|
|---|
| 154 | ;
|
|---|
| 155 | ASSUME DS:SV_DATA
|
|---|
| 156 | XMS_A20_ON PROC NEAR
|
|---|
| 157 | MOV AH, 05H
|
|---|
| 158 | CALL XMS_ENTRY
|
|---|
| 159 | OR AX, AX
|
|---|
| 160 | JNZ SHORT XMS_A20_ON_RET
|
|---|
| 161 | LEA DX, $XMS_A20_ON
|
|---|
| 162 | CALL RTEXT
|
|---|
| 163 | MOV AX, 4CFFH
|
|---|
| 164 | INT 21H
|
|---|
| 165 | XMS_A20_ON_RET: CLI
|
|---|
| 166 | RET
|
|---|
| 167 | XMS_A20_ON ENDP
|
|---|
| 168 |
|
|---|
| 169 | ;
|
|---|
| 170 | ; Disable A20
|
|---|
| 171 | ;
|
|---|
| 172 | ASSUME DS:SV_DATA
|
|---|
| 173 | XMS_A20_OFF PROC NEAR
|
|---|
| 174 | MOV AH, 06H
|
|---|
| 175 | CALL XMS_ENTRY
|
|---|
| 176 | CLI
|
|---|
| 177 | RET
|
|---|
| 178 | XMS_A20_OFF ENDP
|
|---|
| 179 |
|
|---|
| 180 | INIT_CODE ENDS
|
|---|
| 181 |
|
|---|
| 182 | END
|
|---|