]> wirehaze git hosting - MS-DOS.git/blob - v4.0/src/BIOS/STKINIT.INC

wirehaze git hosting

MZ is back!
[MS-DOS.git] / v4.0 / src / BIOS / STKINIT.INC
1 ;
2 ; To follow the standard interrupt sharing scheme, MSSTACK.ASM ;3.30
3 ; has been modified. This initialization routine also has to ;3.30
4 ; be modified because for the interrupt level 7 and 15, FirstFlag ;3.30
5 ; should be set to signal that this interrupt handler is the ;3.30
6 ; first handler hooked to this interrupt vector. ;3.30
7 ; We determine this by looking at the instruction pointed by ;3.30
8 ; this vector. If it is IRET, then this handler should be the ;3.30
9 ; first one. In our case, only the interrupt vector 77h is the ;3.30
10 ; interrupt level 15. (We don't hook interrupt level 7.) ;3.30
11 ; 9/10/1986 ;3.30
12 ; The followings are mainly due to M.R.T; PTM fix of P886 12/3/86;3.30
13 ; Some design changes are needed to the above interrupt sharing ;3.30
14 ; method. The above sharing scheme assumes that 1). Interrupt ;3.30
15 ; sharing is NEVER done on levels that have BIOS support. 2). "Phantom" ;3.30
16 ; interrupts would only be generated on levels 7 and 15. ;3.30
17 ; These assumptions are not true any more. We have to use the FirstFlag ;3.30
18 ; for EVERY level of interrupt. We will set the firstFlag on the following;3.30
19 ; conditions: ;3.30
20 ; a. if the CS portion of the vector is 0000, then "first" ;3.30
21 ; b. else if CS:IP points to valid shared header, then NOT "first" ;3.30
22 ; c. else if CS:IP points to an IRET, then "first" ;3.30
23 ; d. else if CS:IP points to DUMMY, then "first" ;3.30
24 ; where DUMMY is - the CS portion must be F000, and the IP portion must ;3.30
25 ; be equal to the value at F000:FF01. This location is the initial value ;3.30
26 ; from VECTOR_TABLE for interrupt 7, one of the preserved addresses in all;3.30
27 ; the BIOSes for all of the machines. ;3.30
28 ; ;3.30
29 ; System design group requests BIOS to handle the phantom interrupts. ;3.30
30 ; ;3.30
31 ; The "Phantom" interrupt is an illegal interrupt such as an interrupt ;3.30
32 ; produced by the bogus adapter card even without interrupt request is ;3.30
33 ; set. More specifically, 1). The 8259 has a feature when running in ;3.30
34 ; edge triggered mode to latch a pulse and present the interrupt when ;3.30
35 ; the processor indicates interrupt acknowledge (INTA). The interrupt ;3.30
36 ; pulse was exist at the time of INTA to get a "phantom" interrupt. ;3.30
37 ; 2). or, this is caused by adapter cards placing a glitch on the ;3.30
38 ; interrupt line. ;3.30
39 ; ;3.30
40 ; To handle those "phantom" interrupts, the main stack code will check ;3.30
41 ; the own FirstFlag, and if it is not "first" (which means the forward ;3.30
42 ; pointer points to the legal shared interrupt handler), then pass the ;3.30
43 ; control. If it is the first, then the following action should be ;3.30
44 ; taken. We don't have to implement skack logic in this case. ;3.30
45 ; ;3.30
46 ; To implement this logic, we rather choose a simple method. ;3.30
47 ; If ont of the above "FirstFlag" conditions is met, we are not ;3.30
48 ; going to hook this interrupt vector. The reason is if the original ;3.30
49 ; vector points to "IRET" and do nothing, we don't need ;3.30
50 ; to implement the stack logic for it. This will simplify implementation;3.30
51 ; while maintaining compatibility with the old version of DOS. ;3.30
52 ; This implies that in the main stack code, there might be a stack code ;3.30
53 ; that will never be used, a dead code. ;3.30
54 ; ;3.30
55 ; 12/3/86 ;3.30
56 ;3.30
57 ;In - CS, DS -> sysinitseg, ES -> relocated stack code & data. ;3.30
58 ;3.30
59 PAGE ;3.30
60 assume ds:sysinitseg ; sunilp SB340
61 StackInit proc near ;3.30
62 ;3.30
63 PUSH AX ;SAVE ALL ;3.30
64 PUSH DS ;3.30
65 PUSH ES ;3.30
66 PUSH BX ;3.30
67 PUSH CX ;3.30
68 PUSH DX ;3.30
69 PUSH DI ;3.30
70 PUSH SI ;3.30
71 PUSH BP ;3.30
72 ;3.30
73 ;Currently ES -> stack code area ;3.30
74 MOV AX, cs:[STACK_COUNT] ;defined in CS ;3.30
75 MOV es:[STACKCOUNT], AX ;defined in STACK CODE AREA ;3.30
76 MOV AX, [STACK_SIZE] ;in CS ;3.30
77 MOV es:[STACKSIZE], AX ; ;3.30
78 MOV AX, WORD PTR cs:[STACK_ADDR] ; OFFSET ;3.30
79 MOV WORD PTR es:[STACKS], AX ;3.30
80 MOV AX, WORD PTR cs:[STACK_ADDR+WORD] ; SEGMENT ;3.30
81 MOV WORD PTR es:[STACKS+WORD], AX ;3.30
82 ;3.30
83 ; INITIALIZE THE DATA FIELDS WITH THE PARAMETERS ;3.30
84 ;3.30
85 ; "FIRSTENTRY" WILL ALWAYS BE AT STACKS ;3.30
86 ;3.30
87 MOV BP, word ptr es:STACKS ; GET OFFSET OF STACK ;3.30
88 MOV es:FIRSTENTRY,BP ;3.30
89 ;3.30
90 ; THE STACKS WILL ALWAYS IMMEDIATELY FOLLOW THE TABLE ENTRIES ;3.30
91 ;3.30
92 MOV AX,ENTRYSIZE ;3.30
93 MOV CX,es:STACKCOUNT ;3.30
94 MUL CX ;3.30
95 ADD AX,BP ;3.30
96 MOV es:STACKAT,AX ;3.30
97 MOV BX,AX ;3.30
98 SUB BX,2 ;3.30
99 ;3.30
100 ; ZERO THE ENTIRE STACK AREA TO START WITH ;3.30
101 ;3.30
102 MOV DI,es:STACKAT ;3.30
103 MOV AX,es:STACKSIZE ;3.30
104 MUL CX ;3.30
105 MOV CX,AX ;3.30
106 xor ax,ax ;3.30
107 push es ;3.30
108 pop ds ;ds = Relocated stack code seg.;3.30
109 assume ds:nothing ;3.30
110 ;Now, DS -> stack code area ;3.30
111 MOV ES, word ptr ds:[STACKS+2] ; GET SEGMENT OF STACK AREA.;3.30
112 CLD ;3.30
113 REP STOSB ;3.30
114 ;3.30
115 MOV CX, ds:STACKCOUNT ;3.30
116 ;3.30
117 ; LOOP FOR "COUNT" TIMES, BUILDING A TABLE ENTRY ;3.30
118 ; cs = sysinitseg, ds = Relocated stack code seg , es = segment of stack space;3.30
119 ; CX = NUMBER OF ENTRIES ;3.30
120 ; ES:BP => BASE OF STACKS - 2 ;3.30
121 ; ES:BX => FIRST TABLE ENTRY ;3.30
122 ;3.30
123 BUILDLOOP: ;3.30
124 MOV ALLOCBYTE,FREE ;3.30
125 MOV INTLEVEL,AL ;AX = 0 ;3.30
126 MOV SAVEDSP,AX ;3.30
127 MOV SAVEDSS,AX ;3.30
128 ADD BX,ds:STACKSIZE ;3.30
129 MOV NEWSP,BX ;3.30
130 MOV ES:[BX],BP ;3.30
131 ADD BP,ENTRYSIZE ;3.30
132 ;3.30
133 LOOP BUILDLOOP ;3.30
134 ;3.30
135 SUB BP,ENTRYSIZE ;3.30
136 MOV ds:LASTENTRY,BP ;3.30
137 MOV ds:NEXTENTRY,BP ;3.30
138 ;3.30
139 push ds ;3.30
140 mov ax, 0f000h ;loook at the model byte ;3.30
141 mov ds, ax ;3.30
142 cmp ds:byte ptr [0fffeh], mdl_convert ;convertible? ;3.30
143 pop ds ;3.30
144 jne Skip_disableNMIS ;3.30
145 ;3.30
146 MOV AL,07H ; DISABLE Convertible NMIS ;3.30
147 OUT 72H,AL ;3.30
148 ;3.30
149 Skip_disableNMIS: ;3.30
150 XOR AX,AX ;3.30
151 MOV es,AX ;es - SEGID OF VECTOR TABLE AT 0;3.30
152 ASSUME es:NOTHING ;ds - Relocated Stack code segment;3.30
153 ;3.30
154 CLI ;3.30
155 ;3.30
156 IRP AA,<02,08,09,70> ;3.30
157 ;3.30
158 MOV SI,AA&H*4 ;PASS WHERE VECTOR IS TO BE ADJUSTED ;3.30
159 mov di, offset Int19OLD&AA ;we have to set OLD&AA for Int19 handler too.;3.30
160 MOV BX,OFFSET OLD&AA ;PASS WHERE TO SAVE ORIGINAL OWNER POINTER;3.30
161 MOV DX,OFFSET INT&AA ;PASS WHERE NEW HANDLER IS ;3.30
162 CALL NEW_INIT_LOOP ;ADJUST THE VECTOR TO NEW HANDLER, ;3.30
163 ; SAVING POINTER TO ORIGINAL OWNER ;3.30
164 ENDM ;3.30
165 ;3.30
166 IRP AA,<0A,0B,0C,0D,0E,72,73,74,76,77> ;shared interrupts ;3.30
167 ;3.30
168 MOV SI,AA&H*4 ;PASS WHERE VECTOR IS TO BE ADJUSTED ;3.30
169 push ds ;save relocated stack code segment ;3.30
170 lds bx, es:[si] ;ds:bx -> original interrupt handler ;3.30
171 push ds ;3.30
172 pop dx ;dx = segment value ;3.30
173
174 cmp dx,0
175 jz int&AA&_first
176
177 cmp byte ptr ds:[bx],0cfh ;Does vector point to an IRET?
178 jz int&AA&_first
179
180 cmp word ptr ds:[bx.6],424Bh ;Magic offset (see INT&AA, msstack.inc)
181 jz int&AA&_Not_first
182
183 cmp dx,0f000h ;ROM BIOS segment
184 jnz int&AA&_Not_first
185
186 push es
187 push dx
188 mov dx,0f000h
189 mov es,dx
190 cmp bx,word ptr es:0ff01h
191 pop dx
192 pop es
193 jz int&AA&_first
194
195 int&AA&_Not_first: ;Not the first. We are going to hook vector.;3.30
196 pop ds ;3.30
197 mov di, offset Int19OLD&AA ;we have to set OLD&AA for Int19 handler too.;3.30
198 mov BX, OFFSET OLD&AA ;PASS WHERE TO SAVE ORIGINAL OWNER POINTER;3.30
199 MOV DX, OFFSET INT&AA ;PASS WHERE NEW HANDLER IS ;3.30
200 CALL NEW_INIT_LOOP ;ADJUST THE VECTOR TO NEW HANDLER, SAVING;3.30
201 ;POINTER TO ORIGINAL OWNER. ;3.30
202 jmp short int&AA&_end ;3.30
203 int&AA&_first: ;the first. Don't have to hook stack code.;3.30
204 pop ds ;3.30
205 int&AA&_end: ;3.30
206 ;3.30
207 ENDM ;3.30
208 ;3.30
209 push ds ;3.30
210 mov ax, 0f000h ;loook at the model byte ;3.30
211 mov ds, ax ;3.30
212 cmp ds:byte ptr [0fffeh], mdl_convert ;PC convertible? ;3.30
213 pop ds ;3.30
214 jne Skip_EnableNMIS ;3.30
215 ;3.30
216 MOV AL,27H ; ENABLE Convertible NMIS ;3.30
217 OUT 72H,AL ;3.30
218 ;3.30
219 Skip_EnableNMIS: ;3.30
220 STI ;3.30
221 MOV AX,code ;3.30
222 MOV DS,AX ;3.30
223 ASSUME DS:CODE ;3.30
224 ;3.30
225 ; MOV SI,OFFSET STKMSG1 ;3.30
226 ; CALL WRMSG ;3.30
227 ;3.30
228 mov [INT19SEM],1 ; INDICATE THAT INT 19 ;3.30
229 ; INITIALIZATION IS COMPLETE ;3.30
230 ;3.30
231 POP BP ; RESTORE ALL ;3.30
232 POP SI ;3.30
233 POP DI ;3.30
234 POP DX ;3.30
235 POP CX ;3.30
236 POP BX ;3.30
237 ;3.30
238 POP ES ;3.30
239 POP DS ;3.30
240 assume ds:sysinitseg ;3.30
241 POP AX ;3.30
242 RET ;3.30
243 STACKINIT ENDP ;3.30
244 ; ;3.30
245 ;3.30
246 NEW_INIT_LOOP PROC NEAR ;3.30
247 ;INPUT: SI=OFSET INTO VECTOR TABLE OF THE PARTICULAR INT VECTOR BEING ADJUSTED ;3.30
248 ; BX=ds:OFFSET OF OLDxx, WHERE WILL BE SAVED THE POINTER TO ORIGINAL OWNER;3.30
249 ; DX=ds:OFFSET OF INTxx, THE NEW INTERRUPT HANDLER ;3.30
250 ; di=offset value of Int19OLD&AA variable in BIOS. ;3.30
251 ; es=ZERO, SEGID OF VECTOR TABLE ;3.30
252 ; ds=Relocated Stack code segment ;3.30
253 ;3.30
254 MOV AX,es:[SI+0] ;REMEMBER OFFSET IN VECTOR ;3.30
255 MOV WORD PTR ds:[BX],AX ; TO ORIGINAL OWNER in DS ;3.30
256 MOV AX,es:[SI+2] ;REMEMBER SEGID IN VECTOR ;3.30
257 MOV WORD PTR ds:[BX]+2,AX ; TO ORIGINAL OWNER in DS ;3.30
258 push ds ;3.30
259 mov ax, code ;3.30
260 mov ds, ax ;Set Int19OLDxx value in BIOS for ;3.30
261 mov ax,es:[si+0] ;Int 19 handler ;3.30
262 mov word ptr ds:[di],ax ;3.30
263 mov ax,es:[si+2] ;3.30
264 mov word ptr ds:[di]+2,ax ;3.30
265 pop ds ;3.30
266 ;3.30
267 MOV WORD PTR es:[SI+0],DX ;SET VECTOR TO POINT TO NEW INT HANDLER ;3.30
268 MOV es:[SI+2],ds ;3.30
269 RET ;3.30
270 NEW_INIT_LOOP ENDP ;3.30
271 ;3.30