]> wirehaze git hosting - MS-DOS.git/blob - v4.0/src/MEMM/MEMM/ROM_SRCH.ASM

wirehaze git hosting

MZ is back!
[MS-DOS.git] / v4.0 / src / MEMM / MEMM / ROM_SRCH.ASM
1
2
3 ;
4 page 58,132
5 ;******************************************************************************
6 title ROM_SRCH - search for option ROMs
7 ;******************************************************************************
8 ;
9 ; (C) Copyright MICROSOFT Corp. 1986
10 ;
11 ; Title: MEMM.EXE - MICROSOFT Expanded Memory Manager 386 Driver
12 ;
13 ; Module: ROM_SRCH - search for option ROMS and RAM
14 ;
15 ; Version: 0.04
16 ;
17 ; Date : June 5,1986
18 ;
19 ; Authors: SP, BT
20 ;
21 ;******************************************************************************
22 ;
23 ; CHANGES:
24 ;
25 ; DATE REVISION DESCRIPTION
26 ; -------- -------- ------------------------------------------------------
27 ; 06/05/86 Original Adapted from ROM code
28 ; 06/25/86 0.02 Fixed upd_map.
29 ; 06/26/86 0.02 Fixed upd_map (again) and ram_srch
30 ; 06/28/86 0.02 Name changed from MEMM386 to MEMM
31 ; 07/06/86 0.04 changed assume to DGROUP
32 ; 08/01/88 Updated to identify mappable segs between C000 and E000
33 ;
34 ;******************************************************************************
35 page
36 ;******************************************************************************
37 ;
38 ; Functional description:
39 ;
40 ; This module contains the code that scans the ROM at the segment
41 ; supplied in register AX looking for ROMs on hardware interface
42 ; boards. The layout of each valid ROM is as follows:
43 ;
44 ; OFFSET +-----------------------+
45 ; 0 | 55h |
46 ; +-----------------------+
47 ; 1 | AAh |
48 ; +-----------------------+
49 ; 2 | ROM size / 512 |
50 ; +-----------------------+
51 ; 3 | Start of init code |
52 ; :
53 ; n-1 | |
54 ; +-----------------------+
55 ; (Sum of all bytes MOD 100h is 00h.)
56 ;
57 ; This module also contains the code to search and vector to VDU
58 ; roms (C000:0 to C000:7800 in 2K increments).
59 ;
60 ;******************************************************************************
61 page
62 .386P
63 ;
64 ;******************************************************************************
65 ; Public Declarations
66 ;******************************************************************************
67 ;
68 public rom_srch ; Search and Vector to option ROMs.
69 ;******************************************************************************
70 ; Externs
71 ;******************************************************************************
72 LAST segment
73 extrn Map_tbl:word
74 extrn max_PF:abs
75 extrn mappable_segs:byte
76 extrn exclude_segments:near
77
78 LAST ends
79 ;
80 ;******************************************************************************
81 ; Equates
82 ;******************************************************************************
83 ;
84 FIRST_ROM = 0C800H ; Segment address of first option ROM.
85 LAST_ROM = 0EF80H ; Segment address of last option ROM.
86 FIRST_VDU_ROM = 0C000H ; Seg address of first VDU option ROM.
87 LAST_VDU_ROM = 0C780H ; Seg address of last VDU option ROM.
88 FIRST_RAM = 0C000H ; Seg address of 1st possible RAM addr
89 LAST_RAM = 0EF80H ; Seg addr of last possible RAM addr
90 NOT_FOUND_INCR = 0800H ; Amount to skip if no ROM found.
91 ;
92 include emmdef.inc
93 include vdmseg.inc
94 include romstruc.equ ; Option ROM structure.
95 PF_LENGTH equ 0400h ; length of a page frame (*16)
96 ;
97 ;******************************************************************************
98 ; S E G M E N T S
99 ;******************************************************************************
100 LAST segment
101 ASSUME CS:LAST, DS:DGROUP
102 ;
103 page
104 ;******************************************************************************
105 ;
106 ; ROM_SRCH - Search for option ROMs.
107 ;
108 ; This section of code searches the auxiliary rom area (from C8000 up
109 ; to E0000) in 2K increments. A ROM checksum is calculated to insure
110 ; that the ROMs are valid. Valid ROMs must have the 1st byte = 55H
111 ; and the next byte = 0AAH. The next byte indicates the size of the
112 ; ROM in 512-byte blocks. The sum of all bytes in the ROM, modulo 256,
113 ; must be zero.
114 ;
115 ; If a ROM is not found at a location, the next location 2K-bytes down
116 ; is examined. However, if it is found, the next location after this
117 ; ROM is tried. The next ROM location is determine according to the
118 ; size of the previous ROM.
119 ;
120 ;
121 ;******************************************************************************
122 rom_srch proc near ; Entry point.
123 push bx
124 ;
125 ; search for option ROMs
126 ;
127 mov ax,FIRST_ROM ; Segment address of first option ROM.
128 cld ; Set direction flag.
129 nxt_opt:
130 call opt_rom ; Look for option ROM.
131 jnc not_fnd1 ; No ROM here
132 call upd_seg
133 not_fnd1:
134 cmp ax,LAST_ROM ;Q: All ROMs looked at ?
135 jbe nxt_opt ; No, keep looking
136 ; Y: check for VDU roms
137 ;
138 ; search for VDM ROMs
139 ;
140 mov ax,FIRST_VDU_ROM ; segment addr for first vdu ROM
141 cld
142 nxt_vdu:
143 call opt_rom ; Q:is it there
144 jnc not_fnd2 ; No ROM here
145 call upd_seg
146 not_fnd2:
147 cmp ax,LAST_VDU_ROM ;Q: last VDU ROM ?
148 jbe nxt_vdu ; N: continue
149 ; Y: check for RAM
150 ;
151 ; search for RAM
152 ;
153 mov ax,FIRST_RAM ; first seg addr for RAM search
154 cld
155 nxt_ram:
156 call ram_srch ;Q: RAM here ?
157 jnc not_fndr ; N: check again ?
158 call upd_seg
159 not_fndr:
160 cmp ax,LAST_RAM ;Q: last RAM location
161 jbe nxt_ram ; N: continue searching
162 ; Y: all done
163 ;
164 pop bx
165 ret
166 rom_srch endp
167 page
168 ;
169 ;******************************************************************************
170 ; OPT_ROM - This routine looks at the ROM located at the segment address
171 ; specified in AX to see if 0TH and 1ST Bytes = 0AA55H.
172 ; If so, it calculates the checksum over the length of
173 ; ROM. If the checksum is valid it updates AX to point
174 ; to the location of the next ROM.
175 ;
176 ; Inputs: AX = Segment address of ROM.
177 ;
178 ; Outputs: CY = Found a VDU ROM at this location.
179 ; NC = Did not find a valid ROM at this location.
180 ; AX = Segment address of next ROM location.
181 ; DX = Length of this ROM
182 ;
183 ;******************************************************************************
184 ;
185 opt_rom proc near
186 push bx
187 push cx
188 push si
189 push ds
190 ;
191 mov ds,ax ; DS=ROM segment address.
192 xor bx,bx ; Index uses less code than absolute.
193 cmp [bx.ROM_RECOGNITION],0AA55H ;Q: Looks like a ROM?
194 jne rs_3 ; No, Skip down
195 ;
196 ; Compute checksum over ROM.
197 ;
198 xor si,si ; DS:SI=ROM Pointer; Start at beg.
199 xor cx,cx ; Prepare to accept byte into word.
200 mov ch,[bx.ROM_LEN] ; CH=byte count/512 (CX=byte count/2)
201 shl cx,1 ; CX=adjusted byte count.
202 mov dx,cx ; Extract size.
203 rs_2:
204 lodsb ; MOV AL,DS:[SI+]; Pickup next byte.
205 add bl,al ; Checksum += byte(SEG:offset)
206 loop rs_2 ; Loop doesn't affect flags.
207 jnz rs_3 ; Jump down if bad checksum.
208 ;
209 mov cl,4 ; Shift of 4...
210 shr dx,cl ; Converts bytes to paragraphs (D.03)
211 mov ax,ds ; Replace segment in AX.
212 add ax,dx ; increment segment by this amount
213 stc ; rom found
214 jmp short rs_exit ; Continue.
215 ;
216 rs_3:
217 mov dx,(NOT_FOUND_INCR shr 4) ; Prepare for next ROM.
218 mov ax,ds ; Replace segment in AX.
219 add ax,dx ; Increment segment.
220 clc ; no rom found
221 ;
222 rs_exit:
223 pop ds
224 pop si
225 pop cx
226 pop bx
227 ret ; *** RETURN ***
228 ;
229 opt_rom endp
230 page
231 ;
232 ;******************************************************************************
233 ; RAM_SRCH - This routine looks at the address range potentially used
234 ; by the Page Frame to determine if any RAM is in the way.
235 ; It updates the map accordingly.
236 ;
237 ; Inputs: AX = Segment address for RAM search.
238 ;
239 ; Outputs: CY = Found RAM at this location.
240 ; NC = Did not find RAM at this location.
241 ; AX = Segment address of next RAM location.
242 ; DX = Length of this RAM
243 ;
244 ;******************************************************************************
245 ;
246 ram_srch proc near
247
248 push bx
249 push ds
250 ;
251 ; search for RAM
252 ;
253 xor dx,dx ; length = 0
254 ram_loop:
255 mov ds,ax
256 add ax,(NOT_FOUND_INCR shr 4); prepare for next chunk
257 mov bx,ds:0 ; get a word
258 xor ds:0,0FFFFh ; flip all bits
259 xor bx,0FFFFh ; BX = "flipped" value
260 cmp bx,ds:0 ;Q: "flipped" value written out ?
261 jne no_more_ram ; N: not RAM - leave
262 xor ds:0,0FFFFh ; Y: is ram, flip bits back
263 add dx,(NOT_FOUND_INCR shr 4); increment length count
264 cmp ax,LAST_RAM ;Q: last RAM location ?
265 jbe ram_loop ; N: continue searching
266 mov ds,ax ; Y: no more searching
267 no_more_ram:
268 ;
269 mov ax,ds ; get current segment
270 or dx,dx ;Q: any RAM found ?
271 jnz ram_found ; Y: set RAM found & chk DS seg again
272 clc ; N: set no RAM
273 add ax,(NOT_FOUND_INCR shr 4) ; AX -> next one to check
274 jmp short ram_exit ; and leave
275 ;
276 ram_found:
277 stc
278 ram_exit:
279 pop ds
280 pop bx
281 ;
282 ret
283 ram_srch endp
284 page
285 ;
286
287 ;******************************************************************************
288 ; UPD_SEG - This routine looks at the address range used by the ROM/RAM
289 ; that was found to determine how many potential physical
290 ; pages are invalidated from being mappable. It updates
291 ; the mappable_segs array appropriately.
292 ;
293 ; Inputs: AX = Segment address of next ROM/RAM position.
294 ; DX = Length of ROM/RAM
295 ;
296 ; Outputs: [mappable_segs] updated.
297 ;
298 ; Written: 8/1/88 ISP
299 ; Modif: 8/25/88 ISP to make use of exclude_segments
300 ;******************************************************************************
301 upd_seg proc near
302 ;
303 push bx
304 push ax
305 ;
306 mov bx,ax
307 sub bx,dx ; bx now has the first segment of the area
308 dec ax ; and ax has the last segment of the area
309 ;
310 call exclude_segments
311 ;
312 pop ax
313 pop bx
314 ret
315 upd_seg endp
316 LAST ENDS
317 END