-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCHKSTK.ASM
executable file
·344 lines (289 loc) · 8.18 KB
/
CHKSTK.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
page ,132
;-----------------------------Module-Header-----------------------------;
; Module Name: CHKSTK.ASM
;
; This file contains the stack checking function used by display drivers.
;
; Created: 16-Jan-1987
; Author: **** ***** [*****]
;
; Copyright (c) 1984-1987 Microsoft Corporation
;
; Exported Functions: none
;
; Public Functions: my_check_stack
;
; Public Data: none
;
; General Description:
;
; A stack probe will be performed to see if the requested amount
; of stack space is available. If not, either a RIP will be
; performed, or an error returned, based on the DEBUG flag.
;
; Restrictions:
;
;-----------------------------------------------------------------------;
.xlist
include cmacros.inc
.list
ifdef DEBUG
externFP FatalExit ;If debugging, error will abort
endif
; Define the stack overflow error code.
stack_overflow equ -1
; The driver cannot link to the library containing the
; definitions for the stack probe locations, so they
; have to be defined here.
public stack_top
public stack_bot
public stack_min
stack_top equ 000Ah ;Topmost location of stack
stack_bot equ 000Eh ;Bottom location of stack
stack_min equ 000Ch ;Smaller top value
sBegin Code
assumes cs,Code
page
;-----------------------------Public-Routine----------------------------;
; my_chkstk
;
; Our own stack probe which will allow us to gracefully abort out
; of the display driver routines if there isn't enough stack space.
; Routines like STRBLT take a lot of space, and should return an
; error if not enough room to perform the operation instead of
; trashing or ripping.
;
; Entry:
; AX = Number of bytes of stack space needed
; Returns:
; SP = new stack top if room
; 'C' clear
; SS:stack_min = new low if achieved
; Error Returns:
; 'C' set if no room
; DX:AX = 8000:0000h
; FatalExit if DEBUG enabled
; Registers Destroyed:
; AX,BX,Flags
; DX if no room
; Registers Preserved:
; CX,SI,DI,BP,DS,ES
; Calls:
; FatalExit if DEBUG enabled
; History:
; Fri 16-Jan-1987 19:59:47 -by- **** ***** [*****]
; Initial version
;-----------------------------------------------------------------------;
;------------------------------Pseudo-Code------------------------------;
; DWORD my_check_stack(size)
; int size;
; {
; if ((SP =< size) || ((SP-size) < stack_top))
; {
; stack_min = stack_top;
; return(0x800000000L);
; }
; if (new_SP < new_minimun)
; stack_min = new_SP;
; SP = new_SP;
; return();
; }
;-----------------------------------------------------------------------;
assumes ds,nothing
assumes es,nothing
cProc my_check_stack,<NEAR,PUBLIC>
cBegin <nogen>
pop bx ;Save return address
sub ax,sp ;See if room
jnc no_room ;No room, return error
neg ax ;Make it positive for other checks
cmp ss:stack_top,ax ;Used up too much stack?
ja no_room ; Yes, return error
cmp ss:stack_min,ax ;Lowest we've received?
jbe not_smaller ; No
mov ss:stack_min,ax ; Yes, set new minimum
not_smaller:
mov sp,ax ;Set new stack
clc ;Clear 'C' to show room
jmp bx ;To caller
no_room:
mov ax,ss:stack_top ;Show user that all of the
mov ss:stack_min,ax ; stack has been used
ifdef DEBUG
mov ax,stack_overflow ;Stack overflow
push bx ;Save return address
cCall FatalExit,<ax>
pop bx
endif ;Returning to caller
xor ax,ax ;Set error code(s)
mov dx,8000h
stc ;Show no room
jmp bx
cEnd <nogen>
sEnd Code
page
createSeg _LINES,LineSeg,word,public,CODE
sBegin LineSeg
assumes cs,LineSeg
;-----------------------------Public-Routine----------------------------;
; LineSeg_check_stack
;
; Our own stack probe which will allow us to gracefully abort out
; of the display driver routines if there isn't enough stack space.
; Routines like STRBLT take a lot of space, and should return an
; error if not enough room to perform the operation instead of
; trashing or ripping.
;
; Entry:
; AX = Number of bytes of stack space needed
; Returns:
; SP = new stack top if room
; 'C' clear
; SS:stack_min = new low if achieved
; Error Returns:
; 'C' set if no room
; DX:AX = 8000:0000h
; FatalExit if DEBUG enabled
; Registers Destroyed:
; AX,BX,Flags
; DX if no room
; Registers Preserved:
; CX,SI,DI,BP,DS,ES
; Calls:
; FatalExit if DEBUG enabled
; History:
; Fri 16-Jan-1987 19:59:47 -by- **** ***** [*****]
; Initial version
;-----------------------------------------------------------------------;
;------------------------------Pseudo-Code------------------------------;
; DWORD my_check_stack_nr(size)
; int size;
; {
; if ((SP =< size) || ((SP-size) < stack_top))
; {
; stack_min = stack_top;
; return(0x800000000L);
; }
; if (new_SP < new_minimun)
; stack_min = new_SP;
; SP = new_SP;
; return();
; }
;-----------------------------------------------------------------------;
assumes ds,nothing
assumes es,nothing
cProc LineSeg_check_stack ,<NEAR,PUBLIC>
cBegin <nogen>
pop bx ;Save return address
sub ax,sp ;See if room
jnc no_room_ls ;No room, return error
neg ax ;Make it positive for other checks
cmp ss:stack_top,ax ;Used up too much stack?
ja no_room_ls ; Yes, return error
cmp ss:stack_min,ax ;Lowest we've received?
jbe not_smaller_ls ; No
mov ss:stack_min,ax ; Yes, set new minimum
not_smaller_ls:
mov sp,ax ;Set new stack
clc ;Clear 'C' to show room
jmp bx ;To caller
no_room_ls:
mov ax,ss:stack_top ;Show user that all of the
mov ss:stack_min,ax ; stack has been used
ifdef DEBUG
mov ax,stack_overflow ;Stack overflow
push bx ;Save return address
cCall FatalExit,<ax>
pop bx
endif ;Returning to caller
xor ax,ax ;Set error code(s)
mov dx,8000h
stc ;Show no room
jmp bx
cEnd <nogen>
sEnd LineSeg
page
createSeg _SCANLINE,ScanlineSeg,word,public,CODE
sBegin ScanlineSeg
assumes cs,ScanlineSeg
;-----------------------------Public-Routine----------------------------;
; ScanlineSeg_check_stack
;
; Our own stack probe which will allow us to gracefully abort out
; of the display driver routines if there isn't enough stack space.
; Routines like STRBLT take a lot of space, and should return an
; error if not enough room to perform the operation instead of
; trashing or ripping.
;
; Entry:
; AX = Number of bytes of stack space needed
; Returns:
; SP = new stack top if room
; 'C' clear
; SS:stack_min = new low if achieved
; Error Returns:
; 'C' set if no room
; DX:AX = 8000:0000h
; FatalExit if DEBUG enabled
; Registers Destroyed:
; AX,BX,Flags
; DX if no room
; Registers Preserved:
; CX,SI,DI,BP,DS,ES
; Calls:
; FatalExit if DEBUG enabled
; History:
; Fri 16-Jan-1987 19:59:47 -by- **** ***** [*****]
; Initial version
;-----------------------------------------------------------------------;
;------------------------------Pseudo-Code------------------------------;
; DWORD my_check_stack_nr(size)
; int size;
; {
; if ((SP =< size) || ((SP-size) < stack_top))
; {
; stack_min = stack_top;
; return(0x800000000L);
; }
; if (new_SP < new_minimun)
; stack_min = new_SP;
; SP = new_SP;
; return();
; }
;-----------------------------------------------------------------------;
assumes ds,nothing
assumes es,nothing
cProc ScanlineSeg_check_stack,<NEAR,PUBLIC>
cBegin <nogen>
pop bx ;Save return address
sub ax,sp ;See if room
jnc no_room_sl ;No room, return error
neg ax ;Make it positive for other checks
cmp ss:stack_top,ax ;Used up too much stack?
ja no_room_sl ; Yes, return error
cmp ss:stack_min,ax ;Lowest we've received?
jbe not_smaller_sl ; No
mov ss:stack_min,ax ; Yes, set new minimum
not_smaller_sl:
mov sp,ax ;Set new stack
clc ;Clear 'C' to show room
jmp bx ;To caller
no_room_sl:
mov ax,ss:stack_top ;Show user that all of the
mov ss:stack_min,ax ; stack has been used
ifdef DEBUG
mov ax,stack_overflow ;Stack overflow
push bx ;Save return address
cCall FatalExit,<ax>
pop bx
endif ;Returning to caller
xor ax,ax ;Set error code(s)
mov dx,8000h
stc ;Show no room
jmp bx
cEnd <nogen>
sEnd ScanlineSeg
ifdef PUBDEFS
include chkstk.pub
endif
end