summaryrefslogtreecommitdiff
path: root/v2.0/source/MSINIT.ASM
diff options
context:
space:
mode:
Diffstat (limited to 'v2.0/source/MSINIT.ASM')
-rw-r--r--v2.0/source/MSINIT.ASM408
1 files changed, 408 insertions, 0 deletions
diff --git a/v2.0/source/MSINIT.ASM b/v2.0/source/MSINIT.ASM
new file mode 100644
index 0000000..36edf9f
--- /dev/null
+++ b/v2.0/source/MSINIT.ASM
@@ -0,0 +1,408 @@
1; TITLE MSINIT.ASM -- MS-DOS INITIALIZATION CODE
2
3 ORG 0 ; reset to beginning of data segment
4; Init code below overlaps with data area
5
6INITBLOCK DB 110H DUP(0) ; Allow for segment round up
7
8INITSP DW ?
9INITSS DW ?
10BUFFSTRT DW ?
11
12ASSUME CS:DOSGROUP,DS:DOSGROUP,ES:DOSGROUP,SS:NOTHING
13
14 EXTRN QUIT:NEAR,IRET:NEAR,ABSDRD:FAR,ABSDWRT:FAR
15 EXTRN COMMAND:NEAR,CALL_ENTRY:NEAR
16 IF NOT IBM
17 EXTRN HEADER:BYTE
18 ENDIF
19
20MOVDPB:
21; This section of code is safe from being overwritten by block move
22 MOV SP,CS:[INITSP]
23 MOV SS,CS:[INITSS]
24 REP MOVS BYTE PTR [DI],[SI]
25 CLD
26 MOV WORD PTR ES:[DMAADD+2],DX
27 MOV SI,WORD PTR [DPBHEAD] ; Address of first DPB
28 MOV WORD PTR ES:[DPBHEAD+2],ES
29 MOV WORD PTR ES:[sft_addr+2],ES
30 MOV CL,[NUMIO] ; Number of DPBs
31 XOR CH,CH
32SETFINDPB:
33 MOV WORD PTR ES:[SI.dpb_next_dpb+2],ES
34 MOV ES:[SI.dpb_first_access],-1 ; Never accessed before
35 ADD SI,DPBSIZ ; Point to next DPB
36 LOOP SETFINDPB
37 SUB SI,DPBSIZ
38 MOV WORD PTR ES:[SI.dpb_next_dpb+2],-1
39 MOV DI,[BUFFSTRT] ; Set up one default buffer
40 MOV WORD PTR ES:[BUFFHEAD+2],ES
41 MOV WORD PTR ES:[BUFFHEAD],DI
42 MOV WORD PTR ES:[DI.BUFDRV],00FFH
43 MOV ES:[DI.BUFPRI],FREEPRI
44 MOV WORD PTR ES:[DI.NEXTBUF],-1
45 MOV WORD PTR ES:[DI.NEXTBUF+2],-1
46 PUSH ES
47 INC DX ; Leave enough room for the ARENA
48 MOV BYTE PTR [CreatePDB],0FFh ; create jfns and set CurrentPDB
49 invoke $CREATE_PROCESS_DATA_BLOCK ; Set up segment
50ASSUME DS:NOTHING,ES:NOTHING
51 POP ES
52ASSUME ES:DOSGROUP
53
54;
55; set up memory arena
56;SPECIAL NOTE FOR HIGHMEM VERSION
57; At this point a process header has been built where the start of the
58; CONSTANTS segment as refed by CS is. From this point until the return
59; below be careful about references off of CS.
60;
61 PUSH AX
62 MOV AX,[CurrentPDB]
63 MOV ES:[CurrentPDB],AX ; Put it in the REAL location
64 MOV BYTE PTR ES:[CreatePDB],0h ; reset flag in REAL location
65 DEC AX
66 MOV ES:[arena_head],AX
67 PUSH DS
68 MOV DS,AX
69 MOV DS:[arena_signature],arena_signature_end
70 MOV DS:[arena_owner],arena_owner_system
71 SUB AX,ES:[ENDMEM]
72 NEG AX
73 DEC AX
74 MOV DS:[arena_size],AX
75 POP DS
76 POP AX
77
78 MOV DI,OFFSET DOSGROUP:sftabl + sft_table ; Point to sft 0
79 MOV AL,3
80 STOSB ; Adjust Refcount
81 MOV DI,OFFSET DOSGROUP:SYSINITVAR
82
83XXX PROC FAR
84 RET
85XXX ENDP
86DATA ENDS
87
88; the next segment defines a new class that MUST appear last in the link map.
89; This defines several important locations for the initialization process that
90; must be the first available locations of free memory.
91
92LAST SEGMENT BYTE PUBLIC 'LAST'
93 PUBLIC SYSBUF
94 PUBLIC MEMSTRT
95
96SYSBUF LABEL WORD
97ASSUME CS:DOSGROUP,DS:NOTHING,ES:NOTHING,SS:NOTHING
98
99DOSINIT:
100 CLI
101 CLD
102 MOV [ENDMEM],DX
103 MOV [INITSP],SP
104 MOV [INITSS],SS
105 MOV SP,OFFSET DOSGROUP:INITSTACK
106 MOV AX,CS
107 MOV SS,AX
108ASSUME SS:DOSGROUP
109 MOV WORD PTR [DEVHEAD+2],DS
110 MOV WORD PTR [DEVHEAD],SI ; DS:SI Points to CONSOLE Device
111 CALL CHARINIT
112 PUSH SI
113 ADD SI,SDEVNAME ; Point to name
114 PUSH CS
115 POP ES
116ASSUME ES:DOSGROUP
117 MOV DI,OFFSET DOSGROUP:sftabl + sft_table ; Point to sft 0
118 MOV AL,3
119 STOSB ; Refcount
120 DEC AL
121 STOSB ; Access rd/wr
122 XOR AL,AL
123 STOSB ; Drive byte
124 STOSB ; attribute
125 MOV CX,4
126 REP MOVSW ; Name
127 MOV CL,3
128 MOV AL," "
129 REP STOSB ; Extension
130 ADD DI,12 ; Skip
131 MOV AL,0C0H OR ISCIN OR ISCOUT
132 STOSB
133 POP SI
134 MOV AX,SI
135 STOSW ; Device pointer in FIRCLUS
136 MOV AX,DS
137 STOSW
138 OR BYTE PTR [SI.SDEVATT],ISCIN OR ISCOUT
139 MOV WORD PTR [BCON],SI
140 MOV WORD PTR [BCON+2],DS
141CHAR_INIT_LOOP:
142 LDS SI,DWORD PTR [SI] ; AUX device
143 CALL CHARINIT
144 TEST BYTE PTR [SI.SDEVATT],ISCLOCK
145 JZ CHAR_INIT_LOOP
146 MOV WORD PTR [BCLOCK],SI
147 MOV WORD PTR [BCLOCK+2],DS
148 MOV BP,OFFSET DOSGROUP:MEMSTRT ; ES:BP points to DPB
149PERDRV:
150 LDS SI,DWORD PTR [SI] ; Next device
151 CMP SI,-1
152 JZ CONTINIT
153 CALL CHARINIT
154 TEST [SI.SDEVATT],DEVTYP
155 JNZ PERDRV ; Skip any other character devs
156 MOV CL,[CALLUNIT]
157 XOR CH,CH
158 MOV [SI.SDEVNAME],CL ; Number of units in name field
159 MOV DL,[NUMIO]
160 XOR DH,DH
161 ADD [NUMIO],CL
162 PUSH DS
163 PUSH SI
164 LDS BX,[CALLBPB]
165PERUNIT:
166 MOV SI,[BX] ; DS:SI Points to BPB
167 INC BX
168 INC BX ; On to next BPB
169 MOV ES:[BP.dpb_drive],DL
170 MOV ES:[BP.dpb_UNIT],DH
171 PUSH BX
172 PUSH CX
173 PUSH DX
174 invoke $SETDPB
175 MOV AX,ES:[BP.dpb_sector_size]
176 CMP AX,[MAXSEC]
177 JBE NOTMAX
178 MOV [MAXSEC],AX
179NOTMAX:
180 POP DX
181 POP CX
182 POP BX
183 MOV AX,DS ; Save DS
184 POP SI
185 POP DS
186 MOV WORD PTR ES:[BP.dpb_driver_addr],SI
187 MOV WORD PTR ES:[BP.dpb_driver_addr+2],DS
188 PUSH DS
189 PUSH SI
190 INC DH
191 INC DL
192 MOV DS,AX
193 ADD BP,DPBSIZ
194 LOOP PERUNIT
195 POP SI
196 POP DS
197 JMP PERDRV
198
199CONTINIT:
200 PUSH CS
201 POP DS
202ASSUME DS:DOSGROUP
203; Calculate true address of buffers, FATs, free space
204 MOV DI,BP ; First byte after current DPBs
205 MOV BP,[MAXSEC]
206 MOV AX,OFFSET DOSGROUP:SYSBUF
207 MOV [BUFFSTRT],AX
208 ADD AX,BP ; One I/O buffer
209 ADD AX,BUFINSIZ
210 MOV WORD PTR [DPBHEAD],AX ; True start of DPBs
211 MOV DX,AX
212 SUB DX,OFFSET DOSGROUP:SYSBUF
213 MOV BP,DX
214 ADD BP,DI ; Allocate buffer space
215 SUB BP,ADJFAC ; True address of free memory
216 PUSH BP
217 MOV DI,OFFSET DOSGROUP:MEMSTRT ; Current start of DPBs
218 ADD DI,dpb_next_dpb ; Point at dpb_next_dpb field
219 MOV CL,[NUMIO]
220 XOR CH,CH
221TRUEDPBAD:
222 ADD AX,DPBSIZ ; Compute address of next DPB
223 STOSW ; Set the link to next DPB
224 ADD DI,DPBSIZ-2 ; Point at next address
225 LOOP TRUEDPBAD
226 SUB DI,DPBSIZ ; Point at last dpb_next_dpb field
227 MOV AX,-1
228 STOSW ; End of list
229 ADD BP,15 ;True start of free space (round up to segment)
230 MOV CL,4
231 SHR BP,CL ; Number of segments for DOS resources
232 MOV DX,CS
233 ADD DX,BP ; First free segment
234 MOV BX,0FH
235 MOV CX,[ENDMEM]
236
237 IF HIGHMEM
238 SUB CX,BP
239 MOV BP,CX ; Segment of DOS
240 MOV DX,CS ; Program segment
241 ENDIF
242
243 IF NOT HIGHMEM
244 MOV BP,CS
245 ENDIF
246
247; BP has segment of DOS (whether to load high or run in place)
248; DX has program segment (whether after DOS or overlaying DOS)
249; CX has size of memory in paragraphs (reduced by DOS size if HIGHMEM)
250 MOV [ENDMEM],CX
251 MOV ES,BP
252ASSUME ES:DOSGROUP
253
254 IF HIGHMEM
255 XOR SI,SI
256 MOV DI,SI
257 MOV CX,OFFSET DOSGROUP:SYSBUF ;# bytes to move
258 SHR CX,1 ;# words to move (carry set if odd)
259 REP MOVSW ; Move DOS to high memory
260 JNC NOTODD
261 MOVSB
262NOTODD:
263 ENDIF
264
265 MOV WORD PTR ES:[DSKCHRET+3],ES
266 XOR AX,AX
267 MOV DS,AX
268 MOV ES,AX
269ASSUME DS:NOTHING,ES:NOTHING
270 MOV DI,INTBASE+2
271 MOV AX,BP
272 MOV BYTE PTR DS:[ENTRYPOINT],mi_Long_JMP
273 MOV WORD PTR DS:[ENTRYPOINT+1],OFFSET DOSGROUP:CALL_ENTRY
274 MOV WORD PTR DS:[ENTRYPOINT+3],AX
275 EXTRN DIVOV:near
276 MOV WORD PTR DS:[0],OFFSET DOSGROUP:DIVOV ; Set default divide
277 ; trap address
278 MOV DS:[2],AX
279 MOV CX,17
280 REP STOSW ; Set 9 segments (skip 2 between each)
281
282 IF ALTVECT
283 MOV DI,ALTBASE+2
284 MOV CX,15
285 REP STOSW ; Set 8 segments (skip 2 between each)
286 ENDIF
287
288 MOV WORD PTR DS:[addr_int_abort],OFFSET DOSGROUP:QUIT
289 MOV WORD PTR DS:[addr_int_command],OFFSET DOSGROUP:COMMAND
290 MOV WORD PTR DS:[addr_int_terminate],100H
291 MOV WORD PTR DS:[addr_int_terminate+2],DX
292 MOV WORD PTR DS:[addr_int_ctrl_c],OFFSET DOSGROUP:IRET
293 ; Ctrl-C exit
294 MOV WORD PTR DS:[addr_int_fatal_abort],OFFSET DOSGROUP:IRET
295 ; Fatal error exit
296 MOV WORD PTR DS:[addr_int_disk_read],OFFSET DOSGROUP:ABSDRD
297 ; INT 25
298 MOV WORD PTR DS:[addr_int_disk_write],OFFSET DOSGROUP:ABSDWRT
299 ; INT 26
300 EXTRN Stay_resident:NEAR
301 MOV WORD PTR DS:[addr_int_keep_process],OFFSET DOSGROUP:Stay_resident
302 MOV WORD PTR DS:[addr_int_spooler],OFFSET DOSGROUP:IRET ; Spooler
303
304 IF NOT ALTVECT
305 MOV CX,12
306 XOR AX,AX
307 MOV DI,2AH*4
308 REP STOSW ;Zero interrupt locs for ints 2AH-2FH
309 ENDIF
310
311 PUSH CS
312 POP DS
313 PUSH CS
314 POP ES
315ASSUME DS:DOSGROUP,ES:DOSGROUP
316 MOV AX,OFFSET DOSGROUP:INITBLOCK
317 ADD AX,0Fh ; round to a paragraph
318 MOV CL,4
319 SHR AX,CL
320 MOV DI,DS
321 ADD DI,AX
322 INC DI
323 MOV [CurrentPDB],DI
324 PUSH BP
325 PUSH DX ; Save COMMAND address
326 MOV AX,[ENDMEM]
327 MOV DX,DI
328
329 invoke SETMEM ; Basic Header
330ASSUME DS:NOTHING,ES:NOTHING
331 PUSH CS
332 POP DS
333ASSUME DS:DOSGROUP
334 MOV DI,PDB_JFN_Table
335 XOR AX,AX
336 STOSW
337 STOSB ; 0,1 and 2 are CON device
338 MOV AL,0FFH
339 MOV CX,FilPerProc - 3
340 REP STOSB ; Rest are unused
341 PUSH CS
342 POP ES
343ASSUME ES:DOSGROUP
344 MOV WORD PTR [sft_addr+2],DS ; Must be set to print messages
345
346; After this points the char device functions for CON will work for
347; printing messages
348
349 IF NOT IBM
350 IF NOT ALTVECT
351 MOV SI,OFFSET DOSGROUP:HEADER
352 invoke OUTMES
353 PUSH CS ; Outmes stomps on segments
354 POP DS
355 PUSH CS
356 POP ES
357 ENDIF
358 ENDIF
359
360; Move the FATs into position
361 POP DX ; Restore COMMAND address
362 POP BP
363 POP CX ; True address of free memory
364 MOV SI,OFFSET DOSGROUP:MEMSTRT ; Place to move DPBs from
365 MOV DI,WORD PTR [DPBHEAD] ; Place to move DPBs to
366 SUB CX,DI ; Total length of DPBs
367 CMP DI,SI
368 JBE MOVJMP ; Are we moving to higher or
369 ; lower memory?
370 DEC CX ; Move backwards to higher memory
371 ADD DI,CX
372 ADD SI,CX
373 INC CX
374 STD
375MOVJMP:
376 MOV ES,BP
377ASSUME ES:DOSGROUP
378 JMP MOVDPB
379
380CHARINIT:
381ASSUME DS:NOTHING,ES:NOTHING
382; DS:SI Points to device header
383 MOV [DEVCALL.REQLEN],DINITHL
384 MOV [DEVCALL.REQUNIT],0
385 MOV [DEVCALL.REQFUNC],DEVINIT
386 MOV [DEVCALL.REQSTAT],0
387 PUSH ES
388 PUSH BX
389 PUSH AX
390 MOV BX,OFFSET DOSGROUP:DEVCALL
391 PUSH CS
392 POP ES
393 invoke DEVIOCALL2
394 POP AX
395 POP BX
396 POP ES
397 RET
398
399 DB 80H DUP(?)
400INITSTACK LABEL BYTE
401 DW ?
402
403MEMSTRT LABEL WORD
404ADJFAC EQU MEMSTRT-SYSBUF
405
406 do_ext
407LAST ENDS
408 \ No newline at end of file