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

wirehaze git hosting

MZ is back!
[MS-DOS.git] / v4.0 / src / MEMM / MEMM / ERRHNDLR.ASM
1
2
3 page 58,132
4 ;******************************************************************************
5 TITLE ErrHndlr - Error Handler
6 ;******************************************************************************
7 ; (C) Copyright MICROSOFT Corp. 1986
8 ;
9 ; Title: MEMM.EXE - MICROSOFT Expanded Memory Manager 386 Driver
10 ;
11 ; Module: ErrHndlr - Recover from exception and priveledged operation errors
12 ;
13 ; Version: 0.04
14 ;
15 ; Date: June 6,1986
16 ;
17 ; Authors: Brad Tate
18 ;
19 ;******************************************************************************
20 ;
21 ; CHANGES:
22 ;
23 ; DATE REVISION DESCRIPTION
24 ; -------- -------- ------------------------------------------------------
25 ; 06/06/86 Original
26 ; 06/28/86 0.02 Name changed from MEMM386 to MEMM
27 ; 06/28/86 0.02 Removed STI at end of ErrHndlr
28 ; 06/28/86 0.02 Changed error # display to leading zeroes
29 ; 07/06/86 0.04 Changed assume to DGROUP
30 ;
31 ;******************************************************************************
32 page
33 ;******************************************************************************
34 ;
35 ; Functional description:
36 ;
37 ; This module contains the code that displays an error message and
38 ; asks the user to continue or reboot.
39 ;
40 ;******************************************************************************
41 page
42 .386P
43 ;
44 include vdmseg.inc
45 include vdmsel.inc
46 include vm386.inc
47 include kbd.inc
48 ;******************************************************************************
49 ; Public Declarations
50 ;******************************************************************************
51 ;
52 public ErrHndlr ; Display message and continue or reboot
53 public Error_Flag
54 ;******************************************************************************
55 ; Externs
56 ;******************************************************************************
57 _TEXT segment
58 extrn RetReal:near ; return to real mode
59 extrn egetc:near ; get keyboard character
60 extrn WaitKBD:near ; wait for keyboard ready
61 _TEXT ends
62
63 _DATA segment
64 extrn powr10:word ; power of 10's table
65 extrn POE_Mess:byte ; privileged operation error
66 extrn POE_Num:byte ; where to put error code
67 extrn POE_Len:abs ; length of message
68 extrn EXCPE_Mess:byte ; exception error message
69 extrn EXCPE_Num:byte ; where to put error code
70 extrn EXCPE_CS:byte ; where to put CS
71 extrn EXCPE_EIP:byte ; where to put EIP
72 extrn EXCPE_ERR:byte ; where to put ERR
73 extrn EXCPE_Len:abs ; length of message
74 _DATA ends
75 ;
76 romdata segment use16 at 40h
77 org 71h
78 fBreak db ?
79 fReset dw ?
80 romdata ends
81 ;
82 ;******************************************************************************
83 ; Equates
84 ;******************************************************************************
85 ;
86 MASTER = 0A1H ; Master interrupt i/o port
87 SLAVE = 021H ; Slave interrupt i/o port
88 NMI = 070H ; Non-Maskable interrupt i/o port
89 DIS_MSTSLV = 00H ; Value to write to disable master/slave
90 DIS_NMI = 080H ; Value to write to disable NMI
91 ENA_NMI = 008H ; Value to write to enable NMI
92 B = 48 ; make code for B
93 C = 46 ; make code for C
94 ENTER = 28 ; make code for enter key
95 ATTR = 07 ; attribute for write string
96 WRSTR = 1301h ; write string function code (format 1)
97 CPOSN = 5*256+0 ; cursor position to write
98 ;
99 ;
100 ;******************************************************************************
101 ; LOCAL DATA
102 ;******************************************************************************
103 _DATA segment
104 Error_Flag dw 0 ; flags for Instruction Prefixes
105 masterp db 0 ; save master port value
106 slavep db 0 ; save slave port value
107 mode db 0 ; save mode
108 boot db 0 ; value to reboot
109 continue db 0 ; value to continue
110
111 GPsavERR dw 0 ; GP fault Error Code save
112 GPsavEIP dd 0 ; GP fault EIP save
113 GPsavCS dw 0 ; GP fault CS save
114
115 _DATA ends
116 ;
117 ;******************************************************************************
118 ;
119 ; ErrHndlr - displays the appropriate error message and prompts the
120 ; user for a character to continue or reboot. The screen
121 ; is cleared by this routine. If the user chooses to
122 ; continue, the system is in real mode.
123 ;
124 ; entry: ax = 0 => Privileged operation error
125 ; ax = 1 => Exception error
126 ; bx = error number to display
127 ;
128 ; exit: either reboot, or exit in "real" mode with CLI
129 ;
130 ; used: none
131 ;
132 ; stack:
133 ;
134 ;******************************************************************************
135 _TEXT segment
136 ASSUME CS:_TEXT, DS:DGROUP, ES:DGROUP
137 ErrHndlr proc near
138 ;
139 ; save fault infos
140 ;
141 push eax
142 push ds
143 push VDMD_GSEL
144 pop ds
145 mov eax, dword ptr [bp.VTFO] ; error code
146 mov [GPsavERR], ax
147 mov eax, dword ptr [bp.VTFOE+VMTF_EIP] ; EIP
148 mov [GPsavEIP], eax
149 mov ax, word ptr [bp.VTFOE+VMTF_CS] ; CS
150 mov [GPsavCS], ax
151 pop ds
152 pop eax
153
154 call RetReal ; return to real mode
155 ;
156 push ax
157 push bx
158 push cx
159 push dx
160 push bp
161 push di
162 ;
163 push ax ; save input to this routine
164 in al,MASTER ; get value of master interrupt port
165 mov [masterp],al ; save it
166 in al,SLAVE ; get value of slave interrupt port
167 mov [slavep],al ; save it
168 mov al,DIS_MSTSLV ; value to disable master/slave int
169 out MASTER,al ; disable master
170 out SLAVE,al ; disable slave
171 mov al,DIS_NMI ; value to disable NMI
172 out NMI,al
173 kbdbusy:
174 call egetc ; q: is there stuff in keyboard buffer?
175 jnz kbdbusy ; y: get it and pitch it
176 ; n: continue
177 pop ax ; get entry condition
178 or ax,ax ; q: privileged error?
179 jnz excep ; n: exception error
180 mov bp,offset DGROUP:POE_Mess ; y: privileged error
181 mov cx,POE_Len
182 mov di,offset DGROUP:POE_Num; error number location
183 mov ax,bx ; error number in ax
184 call b2asc10 ; convert to ascii
185 mov [boot],B ; key to boot
186 mov [continue],C ; key to continue
187 jmp skip_exc ; skip exception stuff
188 excep:
189 mov bp,offset DGROUP:EXCPE_Mess ; n: load up exception error
190 mov cx,EXCPE_Len ; length of msg
191 mov di,offset DGROUP:EXCPE_Num ; error number location
192 mov ax,bx ; error number in ax
193 call b2asc10 ; convert to ascii
194 mov di,offset DGROUP:EXCPE_CS
195 mov ax,[GPsavCS]
196 call b2asc16
197 mov di,offset DGROUP:EXCPE_EIP
198 mov eax,[GPsavEIP]
199 ror eax,16
200 call b2asc16
201 ror eax,16
202 call b2asc16
203 mov di,offset DGROUP:EXCPE_ERR
204 mov ax,[GPsavERR]
205 call b2asc16
206 mov [boot],ENTER ; key to reboot
207 mov [continue],0ffh ; can't continue
208 skip_exc:
209 mov ah,0fh ; read video state
210 int 10h
211 mov [mode],al ; save mode
212 ; mov ax,3 ; set to mode 3
213 ; int 10h ; standard 80 x 25 color
214 mov dx,CPOSN ; cursor position
215 mov bl,ATTR ; attribute
216 mov ax,WRSTR ; write string function code
217 int 10h ; do it
218 cli ; make sure int 10 didn't enable
219 key_loop:
220 call egetc ; get a character
221 jz key_loop ; nothing there yet
222 cmp al,[continue] ; q: continue?
223 je err_cont ; y
224 cmp al,[boot] ; q: boot?
225 jne key_loop ; n: try again
226 ;******************************************************************************
227 ;
228 ; Reboot system
229 ;
230 ;******************************************************************************
231 assume ds:romdata
232 mov ax,romdata
233 mov ds,ax ; ds = romdata segment
234 mov [freset],0 ; cold restart
235 mov al,0fh or 80h ; shutdown byte address/disable NMI
236 out 70h,al ; write CMOS address
237 jmp short $+2 ; delay
238 mov al,0h ; shutdown code 0 = processor reset
239 out 71h,al ; write shutdown code to shutdown byte
240 call WaitKBD ; wait for 8042 to accept command
241 mov al,0feh ; feh = pulse output bit 0 (reset)
242 out KbStatus,al ; reset processor
243 hlt
244 assume ds:DGROUP
245 ;
246 err_cont:
247 xor ah,ah ; ah = 0 to set video mode
248 mov al,[mode] ; restore their mode
249 int 10h
250 cli ; turn them off...
251 ;
252 ; restore master, slave, and NMI
253 ;
254 mov al,[masterp] ; get value of master interrupt port
255 out MASTER,al ; restore it
256 mov al,[slavep] ; get value of slave interrupt port
257 out SLAVE,al ; restore it
258 mov al,ENA_NMI ; value to enable NMI
259 out NMI,al
260 ;
261 pop di
262 pop bp
263 pop dx
264 pop cx
265 pop bx
266 pop ax
267 ret
268 ErrHndlr endp
269
270 page
271 ;******************************************************************************
272 ;
273 ; b2asc10 - converts binary to ascii decimal and store at _TEXT:DI
274 ; stores 2 ascii chars (decimal # is right justified and
275 ; filled on left with 0s)
276 ;
277 ; entry: ax = binary number
278 ; ds:DGROUP
279 ; ds:di = place to store ascii chars.
280 ;
281 ; exit: ASCII decimal representation of number stored at _TEXT:DI
282 ;
283 ; used: none
284 ;
285 ; stack:
286 ;
287 ;******************************************************************************
288 ;
289 b2asc10 proc near
290 ;
291 push ax
292 push bx
293 push cx
294 push dx
295 push si
296 push di
297 ;
298 mov si,2 ; pointer to base 10 table
299 mov bl,1 ; leading zeroes on
300 ;
301 ; convert binary number to decimal ascii
302 ;
303 b2_loop:
304 xor dx,dx ; clear word extension
305 mov cx,powr10[si]
306 div cx ; divide by power of 10
307 or bl,bl
308 jnz b2_ascii
309 ;
310 or ax,ax ; q: zero result?
311 jnz b2_ascii ; n: go convert to ascii
312 ;
313 mov al,' ' ; y: go blank fill
314 jmp b2_make_strg ;
315 ;
316 b2_ascii:
317 add al,'0' ; put into ascii format
318 mov bl,1 ; leading zeroes on
319 ;
320 b2_make_strg:
321 mov ds:[di],al ; put ascii number into string
322 xchg ax,dx
323 inc di ; increment buffer string pointer
324 dec si ; decrement power of 10 pointer
325 dec si ;
326 jge b2_loop ; Q: Last digit? N: Jump if not
327 ;
328 pop di
329 pop si
330 pop dx
331 pop cx
332 pop bx
333 pop ax
334 ret ; *** return ***
335 ;
336 b2asc10 endp
337 ;
338 ;******************************************************************************
339 ;
340 ; b2asc16 - converts binary to hexidecimal and store at _TEXT:DI
341 ; stores 4 ascii chars (# is right justified and
342 ; filled on left with 0s)
343 ;
344 ; entry: ax = binary number
345 ; ds:DGROUP
346 ; ds:di = place to store ascii chars.
347 ;
348 ; exit: ASCII hexidecimal representation of number stored at _TEXT:DI
349 ;
350 ; used: none
351 ;
352 ; stack:
353 ;
354 ;******************************************************************************
355 ;
356 b2asc16 proc near
357
358 push ax
359 push bx
360 push cx
361
362 mov cx,4
363 b2asc16_loop:
364 mov bl,ah
365 shr bl,4
366 add bl,'0'
367 cmp bl,'9'
368 jbe b2asc16_skip
369 add bl,'A'-'9'-1
370 b2asc16_skip:
371 mov ds:[di],bl
372 shl ax,4
373 inc di
374 loop b2asc16_loop
375
376 pop cx
377 pop bx
378 pop ax
379 ret
380
381 b2asc16 endp
382
383 _TEXT ENDS
384 END
385 \1a