-
Notifications
You must be signed in to change notification settings - Fork 1
/
CRITICAL.ASM
118 lines (98 loc) · 3.95 KB
/
CRITICAL.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
;
; Critical.asm - critical error handler.
; Copyright (C) 2000, 2001 Imre Leber
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
; If you have any questions, comments, suggestions, or fixes please
; email me at: [email protected]
;
segment _DATA class=DATA
handler DW 0
segment _TEXT class=CODE
;************************************************************************
;*** call_real_handler ***
;************************************************************************
;*** Private function to encapsulate the critical error handler. ***
;************************************************************************
call_real_handler:
push bx
push cx
push dx
push si ;; Save all registers.
push di
push es
push ss
push ds
sti
mov dx, _DATA ;; Set data segment to _DATA.
mov ds, dx
and di, 0FFh ;; Prepare the parameter to
xor al, al ;; give to the real handler.
add ax, di
push ax ;; Call real handler.
call [handler]
pop dx ;; take parameter from the stack.
pop ds
pop ss
pop es ;; Restore all registers (except AX = retval.).
pop di
pop si
pop dx
pop cx
pop bx
iret
;************************************************************************
;*** SetCriticalHandler ***
;************************************************************************
;*** void SetCriticalHandler(int (*handler)(int status)); ***
;*** ***
;*** Installs the critical error handler and sets the routine to call ***
;*** to handler. ***
;************************************************************************
global _SetCriticalHandler
_SetCriticalHandler:
push bp
mov bp, sp
push es
push ds
mov ax, [bp+04h] ; Get real handler and
mov [handler], ax ; save it.
mov dx, call_real_handler
push cs
pop ds ; Install the new critical handler.
mov ax, 2524h
int 21h
pop ds
pop es
pop bp
ret
%if 0
;**************************************************************************
;*** RenewCriticalHandler ***
;**************************************************************************
;*** void RenewCriticalHandler(int (*handler)(int status)); ***
;*** ***
;*** Sets the routine to call to handler. ***
;**************************************************************************
global _RenewCriticalHandler
_RenewCriticalHandler:
push ds
mov bx, sp
mov ax, [ss:bx+04h] ; Save the newly given handler
mov [handler], ax ; as the handler to call.
pop ds
ret
%endif