1 ; SCCSID = @(#)msinit.asm 1.2 85/07/23
2 ; TITLE MSINIT.ASM -- MS-DOS INITIALIZATION CODE
3 ; AN000 version 4.0 Jan. 1988
4 ; AN007 PTM 3957 - fake version for IBMCACHE.COM
5 ; AN008 PTM 4070 - fake version for MS WINDOWS
10 I_need DMAAdd
,DWORD ; current dma address
11 I_need DPBHead
,DWORD ; long pointer to DPB chain
12 I_need SFT_Addr
,DWORD ; pointer to open file list
13 I_need NumIO
,BYTE ; number of physical drives
14 I_need BuffHead
,DWORD ; pointer to buffer chain
15 I_need EndMem
,WORD ; first unavailable address in memory
16 I_need CurrentPDB
,WORD ; current process ID
17 I_need CreatePDB
,BYTE ; TRUE => create a new PDB
18 I_need Arena_Head
,WORD ; paragraph address of head of arena
19 I_need sfTabl
,BYTE ; internal file table
20 I_need SysInitVar
,BYTE ; label for internal structures
21 I_need NulDev
,DWORD ; long pointer to device chain
22 I_need BCon
,DWORD ; pointer to console device
23 I_need BClock
,DWORD ; pointer to clock device
24 I_need CallUnit
,BYTE ; unit field in dd packet
25 I_need CallBPB
,DWORD ; returned BPB from DD
31 I_need COUNTRY_CDPG
,BYTE ; country info table, DOS 3.3
32 I_need SysInitTable
,BYTE ; sys init table for SYSINIT
33 I_need FastOpenTable
,BYTE ; table for FASTOPEN
34 I_need FETCHI_TAG
,WORD ; TAG CHECK
35 I_need Special_Entries
,WORD ; address of special entries ;AN007;
36 I_need IFS_DOS_CALL
,DWORD ; IFS IBMDOS CALL entry ;AN000;
37 I_need HASHINITVAR
,WORD ; hash table variables ;AN000;
38 I_need Packet_Temp
,WORD ; used for initial Hash table;AN000;
39 I_need BUF_HASH_PTR
,DWORD ; used for initial Hash table;AN000;
40 I_need SWAP_ALWAYS_AREA
,DWORD ; swap always area addr ;AN000;
41 I_need SWAP_ALWAYS_AREA_LEN
,WORD; swap always area length ;AN000;
42 I_need SWAP_IN_DOS
,DWORD ; swap in dos area ;AN000;
43 I_need SWAP_IN_DOS_LEN
,WORD ; swap in dos area length ;AN000;
44 I_need SWAP_AREA_LEN
,WORD ; swap area length ;AN000;
45 I_need SWAP_START
,BYTE ; swap start addr ;AN000;
46 I_need SWAP_ALWAYS
,BYTE ; swap always addr ;AN000;
47 I_need Hash_Temp
,WORD ; temporary Hash table ;AN000;
49 CODE SEGMENT BYTE PUBLIC 'CODE'
50 Extrn IRETT
:NEAR,INT2F
:NEAR,CALL_ENTRY
:NEAR,QUIT
:NEAR,IFS_DOSCALL
:FAR
51 Extrn COMMAND
:NEAR,ABSDRD
:NEAR,ABSDWRT
:NEAR
54 DATA SEGMENT WORD PUBLIC 'DATA'
55 ORG 0 ; reset to beginning of data segment
57 Public MSINI001S
,MSINI001E
59 INITBLOCK
DB 110H
DUP(0) ; Allow for segment round up
65 ASSUME
CS:DOSGROUP
,SS:NOTHING
68 DOSAssume
CS,<DS,ES>,"MovDPB"
69 ; This section of code is safe from being overwritten by block move
72 REP MOVS BYTE PTR [DI],[SI]
74 MOV WORD PTR ES:[DMAADD
+2],DX
75 MOV SI,WORD PTR [DPBHEAD
] ; Address of first DPB
76 MOV WORD PTR ES:[DPBHEAD
+2],ES
77 MOV WORD PTR ES:[sft_addr
+2],ES
78 MOV CL,[NUMIO
] ; Number of DPBs
81 MOV WORD PTR ES:[SI.dpb_next_dpb
+2],ES
82 MOV ES:[SI.dpb_first_access
],-1 ; Never accessed before
83 ADD SI,DPBSIZ
; Point to next DPB
86 MOV WORD PTR ES:[SI.dpb_next_dpb
+2],-1
89 ;; MOV DI,OFFSET DOSGroup:SYSBUF + 0Fh
100 ; MOV DI,OFFSET DOSGroup:SYSBUF ; Set up one default buffer
101 ; MOV WORD PTR [BUFFHEAD+2],ES
102 ; MOV WORD PTR [BUFFHEAD],DI
103 ;; MOV WORD PTR [Hash_Temp+4],ES ;LB. intitialize one Hash entry ;AN000;
104 ;; MOV WORD PTR [Hash_Temp+2],DI ;LB. ;AN000;
105 ;; MOV WORD PTR [Hash_Temp+6],0 ;LB. dirty count =0 ;AN000;
106 ;; MOV WORD PTR ES:[DI.buf_ID],00FFH
107 ;; MOV WORD PTR ES:[DI.buf_next],DI ;;;1/19/88
108 ;; MOV WORD PTR ES:[DI.buf_prev],DI ;;;1/19/88
111 MOV SI,OFFSET DOSGROUP
:Version_Fake_Table
;MS.;AN007;move special
112 MOV DI,ES:[Special_Entries
] ;MS.;AN007;entries
113 MOV CX,ES:[Temp_Var
] ;MS.;AN007;
114 REP MOVSB ;MS.;AN007;
119 INC DX ; Leave enough room for the ARENA
122 ; MOV BYTE PTR [CreatePDB],0FFh ; create jfns and set CurrentPDB
123 ; invoke $CREATE_PROCESS_DATA_BLOCK ; Set up segment
124 ASSUME
DS:NOTHING
,ES:NOTHING
126 DOSAssume
CS,<ES>,"INIT/CreateProcess"
128 ; set up memory arena
129 ;SPECIAL NOTE FOR HIGHMEM VERSION
130 ; At this point a process header has been built where the start of the CONSTANTS
131 ; segment as refed by CS is. From this point until the return below be careful
132 ; about references off of CS.
135 MOV ES:[CurrentPDB
],AX ; Put it in the REAL location
136 MOV BYTE PTR ES:[CreatePDB
],0h
; reset flag in REAL location
138 MOV ES:[arena_head
],AX
141 MOV DS:[arena_signature
],arena_signature_end
142 MOV DS:[arena_owner
],arena_owner_system
146 MOV DS:[arena_size
],AX
149 MOV DI,OFFSET DOSGROUP
:sftabl
+ SFTable
; Point to sft 0
151 STOSW ; Adjust Refcount
152 MOV DI,OFFSET DOSGROUP
:SySInitTable
158 ; %OUT Random NETWINIT done at install
166 ; the next segment defines a new class that MUST appear last in the link map.
167 ; This defines several important locations for the initialization process that
168 ; must be the first available locations of free memory.
170 LAST
SEGMENT PARA
PUBLIC 'LAST'
175 ASSUME
CS:DOSGROUP
,DS:NOTHING
,ES:NOTHING
,SS:NOTHING
177 INITIRET: ; Temp IRET instruction
189 MOV SP,OFFSET DOSGROUP
:INITSTACK
190 MOV WORD PTR [NULDEV
+2],DS
191 MOV WORD PTR [NULDEV
],SI ; DS:SI Points to CONSOLE Device
193 PUSH DS ; Need Crit vector inited to use DEVIOCALL
196 MOV AX,OFFSET DOSGROUP
:INITIRET
197 MOV DS:[addr_int_IBM
],AX
199 MOV DS:[addr_int_IBM
+2],AX
203 PUSH SI ; Save pointer to header
207 MOV DI,OFFSET DOSGROUP
:sftabl
+ SFTable
; Point to sft 0
211 errnz sf_mode
-(sf_ref_count
+2)
212 STOSW ; Access rd/wr, compatibility
214 errnz sf_attr
-(sf_mode
+2)
216 MOV AL,devid_device_EOF
OR devid_device
OR ISCIN
OR ISCOUT
217 errnz sf_flags
-(sf_attr
+1)
220 errnz sf_devptr
-(sf_flags
+2)
221 STOSW ; Device pointer in devptr
225 errnz sf_firclus
-(sf_devptr
+4)
227 errnz sf_time
-(sf_firclus
+2)
229 errnz sf_date
-(sf_time
+2)
232 errnz sf_size
-(sf_date
+2)
236 errnz sf_position
-(sf_size
+4)
239 ADD DI,sf_name
- sf_cluspos
;Point at name
240 ADD SI,SDEVNAME
; Point to name
245 REP STOSB ; Extension
246 POP SI ; Get back pointer to header
247 OR BYTE PTR [SI.SDEVATT
],ISCIN
OR ISCOUT
248 MOV WORD PTR [BCON
],SI
249 MOV WORD PTR [BCON
+2],DS
251 LDS SI,DWORD PTR [SI] ; AUX device
253 TEST BYTE PTR [SI.SDEVATT
],ISCLOCK
255 MOV WORD PTR [BCLOCK
],SI
256 MOV WORD PTR [BCLOCK
+2],DS
257 MOV BP,OFFSET DOSGROUP
:MEMSTRT
; ES:BP points to DPB
259 LDS SI,DWORD PTR [SI] ; Next device
263 TEST [SI.SDEVATT
],DEVTYP
264 JNZ PERDRV
; Skip any other character devs
267 MOV [SI.SDEVNAME
],CL ; Number of units in name field
275 MOV SI,[BX] ; DS:SI Points to BPB
277 INC BX ; On to next BPB
278 MOV ES:[BP.dpb_drive
],DL
279 MOV ES:[BP.dpb_UNIT
],DH
284 MOV AX,ES:[BP.dpb_sector_size
]
296 MOV WORD PTR ES:[BP.dpb_driver_addr
],SI
297 MOV WORD PTR ES:[BP.dpb_driver_addr
+2],DS
314 ; BP has the current offset to the allocated DPBs. Calculate true address of
315 ; buffers, FATs, free space
317 MOV DI,BP ; First byte after current DPBs
319 ; Compute location of first buffer. If we are to make buffers paragraph
320 ; aligned, change this code to make sure that AX = 0 mod 16 and change the
321 ; setting of the segment address part of BuffHead to make sure that the offset
322 ; is zero. Alternatively, this may be done by making segment LAST paragraph
325 ;;; MOV BP,[MAXSEC] ; get size of buffer
326 MOV AX,OFFSET DOSGROUP
:SYSBUF
328 ; Compute location of DPBs
330 ;;; ADD AX,BP ; One I/O buffer
332 MOV WORD PTR [DPBHEAD
],AX ; True start of DPBs
334 SUB DX,OFFSET DOSGROUP
:SYSBUF
336 ADD BP,DI ; Allocate buffer space
337 SUB BP,ADJFAC
; True address of free memory
339 MOV DI,OFFSET DOSGROUP
:MEMSTRT
; Current start of DPBs
340 ADD DI,dpb_next_dpb
; Point at dpb_next_dpb field
344 ADD AX,DPBSIZ
; Compute address of next DPB
345 STOSW ; Set the link to next DPB
346 ADD DI,DPBSIZ
-2 ; Point at next address
348 SUB DI,DPBSIZ
; Point at last dpb_next_dpb field
352 MOV [Special_Entries
],BP ;MS.;AN007 save starting address of Special entries
353 MOV SI,OFFSET DOSGROUP
:Version_Fake_Table
;MS.;AN007
356 NextEntry: ;MS.;AN007
357 LODSB ;MS.;AN007 get name length
358 OR AL,AL ;MS.;AN007 end of list
359 JZ endlist
;MS.;AN007 yes
360 ADD SI,AX ;MS.;AN007 position to
361 ADD SI,3 ;MS.;AN007 next entry
362 JMP NextEntry
;MS.;AN007
365 MOV [Temp_Var
],SI ;MS.;AN007 si = total table length
369 ADD BP,15 ; True start of free space (round up to segment)
372 SHR BP,CL ; Number of segments for DOS resources
373 ;;;;;; MOV [IBMDOS_SIZE],BP ;MS. save it for information
375 ADD DX,BP ; First free segment
381 MOV BP,CX ; Segment of DOS
382 MOV DX,CS ; Program segment
389 ; BP has segment of DOS (whether to load high or run in place)
390 ; DX has program segment (whether after DOS or overlaying DOS)
391 ; CX has size of memory in paragraphs (reduced by DOS size if HIGHMEM)
399 MOV CX,OFFSET DOSGROUP
:SYSBUF
;# bytes to move
400 SHR CX,1 ;# words to move (carry set if odd)
401 REP MOVSW ; Move DOS to high memory
407 MOV WORD PTR ES:[DSKCHRET
+3],ES
411 ASSUME
DS:NOTHING
,ES:NOTHING
413 MOV AX,BP ; Final DOS segment to AX
416 MOV WORD PTR DS:[0],OFFSET DOSGROUP
:DIVOV
; Set default divide trap address
419 ; Set vectors 20-28 and 2A-3F to point to IRET.
422 REP STOSW ; Set 9 segments
423 ; Sets segs for INTs 20H-28H
424 ADD DI,6 ; Skip INT 29H vector (FAST CON) as it may
427 REP STOSW ; Set 22 segments
428 ; Sets segs for vectors 2AH-3FH
431 MOV AX,OFFSET DOSGROUP
:IRETT
432 MOV CX,9 ; Set 9 offsets (skip 2 between each)
433 ; Sets offsets for INTs 20H-28H
440 ADD DI,4 ; Skip vector 29H
442 MOV CX,22 ; Set 22 offsets (skip 2 between each)
443 ; Sets offsets for INTs 2AH-3FH
450 MOV AX,BP ; Final DOS segment to AX
453 ; the following two are in the Code segment, thus the CS
455 MOV WORD PTR DS:[02FH * 4],OFFSET DOSGROUP
:INT2F
458 ; Set up entry point call at vectors 30-31H
459 MOV BYTE PTR DS:[ENTRYPOINT
],mi_Long_JMP
460 MOV WORD PTR DS:[ENTRYPOINT
+1],OFFSET DOSGROUP
:CALL_ENTRY
461 MOV WORD PTR DS:[ENTRYPOINT
+3],AX
466 REP STOSW ; Set 8 segments (skip 2 between each)
469 MOV WORD PTR DS:[addr_int_abort
],OFFSET DOSGROUP
:QUIT
470 MOV WORD PTR DS:[addr_int_command
],OFFSET DOSGROUP
:COMMAND
471 MOV WORD PTR DS:[addr_int_terminate
],100H
472 MOV WORD PTR DS:[addr_int_terminate
+2],DX
473 MOV WORD PTR DS:[addr_int_disk_read
],OFFSET DOSGROUP
:ABSDRD
; INT 25
474 MOV WORD PTR DS:[addr_int_disk_write
],OFFSET DOSGROUP
:ABSDWRT
; INT 26
475 EXTRN Stay_resident
:NEAR
476 MOV WORD PTR DS:[addr_int_keep_process
],OFFSET DOSGROUP
:Stay_resident
482 ASSUME
DS:DOSGROUP
,ES:DOSGROUP
484 ; Initialize the jump table for the sharer...
486 MOV DI,OFFSET DOSGroup
:JShare
490 ADD DI,2 ; skip offset
491 STOSW ; drop in segment
494 MOV AX,OFFSET DOSGROUP
:INITBLOCK
495 ADD AX,0Fh ; round to a paragraph
503 PUSH DX ; Save COMMAND address
507 invoke SETMEM
; Basic Header
508 ASSUME
DS:NOTHING
,ES:NOTHING
515 STOSB ; 0,1 and 2 are CON device
517 MOV CX,FilPerProc
- 3
518 REP STOSB ; Rest are unused
522 MOV WORD PTR [sft_addr
+2],DS ; Must be set to print messages
524 ; After this points the char device functions for CON will work for
527 IF (NOT IBM
) OR (DEBUG
)
529 MOV SI,OFFSET DOSGROUP
:HEADER
531 LODS CS:BYTE PTR [SI]
537 PUSH CS ; OUT stomps on segments
544 ;F.C Modification start DOS 3.3
545 MOV SI,OFFSET DOSGROUP
:COUNTRY_CDPG
;F.C. for DOS 3.3 country info
547 MOV WORD PTR ES:[SI.ccUcase_ptr
+ 2],ES ; initialize double word
548 MOV WORD PTR ES:[SI.ccFileUcase_ptr
+ 2],ES ; pointers with DOSGROUP
549 MOV WORD PTR ES:[SI.ccFileChar_ptr
+ 2],ES
550 MOV WORD PTR ES:[SI.ccCollate_ptr
+ 2],ES
551 MOV WORD PTR ES:[SI.ccMono_ptr
+ 2],ES
552 MOV WORD PTR ES:[SI.ccDBCS_ptr
+ 2],ES ; 2/16/KK
554 MOV SI,OFFSET DOSGROUP
:SysInitTable
555 MOV WORD PTR ES:[SI.SYSI_Country_Tab
+ 2],ES
556 MOV WORD PTR ES:[SI.SYSI_InitVars
+ 2],ES
558 MOV WORD PTR ES:[BUFFHEAD
+2],ES ;LB. DOS 4.00 buffer head pointer ;AN000;
559 MOV SI,OFFSET DOSGROUP
:HASHINITVAR
;LB. points to Hashinitvar ;AN000;
560 MOV WORD PTR ES:[BUFFHEAD
],SI ;LB. ;AN000;
561 MOV WORD PTR ES:[BUF_HASH_PTR
+2],ES ;LB. ;AN000;
562 MOV SI,OFFSET DOSGROUP
:Hash_Temp
;LB. ;AN000;
563 MOV WORD PTR ES:[BUF_HASH_PTR
],SI ;LB. ;AN000;
565 MOV SI,OFFSET DOSGROUP
:FastOpenTable
566 MOV WORD PTR ES:[SI.FASTOPEN_NAME_CACHING
+ 2],ES
567 MOV ES:[FETCHI_TAG
],22642 ; TAG for IBM,
568 ; Fetchi's serial # = 822642
569 MOV WORD PTR ES:[IFS_DOS_CALL
+2],ES ;IFS. ;AN000;
570 MOV SI,OFFSET DOSGROUP
:IFS_DOSCALL
;IFS. ;AN000;
571 MOV WORD PTR ES:[IFS_DOS_CALL
],SI ;IFS. ;AN000;
573 MOV DI,OFFSET DOSGROUP
:SWAP_START
;IFS. ;AN000;
574 MOV CX,OFFSET DOSGROUP
:SWAP_END
;IFS. ;AN000;
575 MOV DX,OFFSET DOSGroup
:Swap_Always
;IFS. ;AN000;
576 MOV BP,CX ;IFS. ;AN000;
577 SUB BP,DI ;IFS. ;AN000;
578 SHR BP,1 ;IFS. div by 2, remainder in carry ;AN000;
579 ADC BP,0 ;IFS. div by 2 + round up ;AN000;
580 SHL BP,1 ;IFS. round up to 2 boundary. ;AN000;
581 MOV ES:[SWAP_AREA_LEN
],BP ;IFS. ;AN000;
583 SUB CX,DX ;IFS. ;AN000;
584 SUB DX,DI ;IFS. ;AN000;
585 SHR CX,1 ;IFS. div by 2, remainder in carry ;AN000;
586 ADC CX,0 ;IFS. div by 2 + round up ;AN000;
587 SHL CX,1 ;IFS. round up to 2 boundary. ;AN000;
588 MOV ES:[SWAP_IN_DOS_LEN
],CX ;IFS. ;AN000;
589 MOV WORD PTR ES:[SWAP_ALWAYS_AREA
],DI ;IFS. ;AN000;
590 MOV WORD PTR ES:[SWAP_ALWAYS_AREA
+2],ES ;IFS. ;AN000;
591 OR DX,8000H
;IFS. ;AN000;
592 MOV ES:[SWAP_ALWAYS_AREA_LEN
],DX ;IFS. ;AN000;
593 MOV DI,OFFSET DOSGroup
:Swap_Always
;IFS. ;AN000;
594 MOV WORD PTR ES:[SWAP_IN_DOS
],DI ;IFS. ;AN000;
595 MOV WORD PTR ES:[SWAP_IN_DOS
+2],ES ;IFS. ;AN000;
599 ;F.C Modification end DOS 3.3
601 ; Move the FATs into position
602 POP DX ; Restore COMMAND address
604 POP CX ; True address of free memory
605 MOV SI,OFFSET DOSGROUP
:MEMSTRT
; Place to move DPBs from
606 MOV DI,WORD PTR [DPBHEAD
] ; Place to move DPBs to
607 SUB CX,DI ; Total length of DPBs
609 JBE MOVJMP
; Are we moving to higher or lower memory?
610 DEC CX ; Move backwards to higher memory
621 ASSUME
DS:NOTHING
,ES:NOTHING
622 ; DS:SI Points to device header
623 MOV [DEVCALL
.REQLEN
],DINITHL
624 MOV [DEVCALL
.REQUNIT
],0
625 MOV [DEVCALL
.REQFUNC
],DEVINIT
626 MOV [DEVCALL
.REQSTAT
],0
630 MOV BX,OFFSET DOSGROUP
:DEVCALL
639 Public MSINI002S
,MSINI002E
645 DB "ADD SPECIAL ENTRIES",0 ;AN007 tiltle
646 ;The following entries don't expect version 4.0
647 ;The entry format: name_length, name, expected version, fake count
648 ;fake_count: ff means the version will be reset when Abort or Exec is encountered
649 ; n means the version will be reset after n DOS version calls are issued
651 Version_Fake_Table: ;AN007 starting address for special
652 DB 12,"IBMCACHE.COM",3,40,255 ;AN007 ibmcache 1
653 DB 12,"IBMCACHE.SYS",3,40,255 ;AN007 ibmcache 2
654 DB 12,"DXMA0MOD.SYS",3,40,255 ;AN007 lan support 3
655 DB 10,"WIN200.BIN" ,3,40,4 ;AN008 windows 4
656 DB 9,"PSCPG.COM" ,3,40,255 ;AN008 vittoria 5
657 DB 11,"DCJSS02.EXE" ,3,40,255 ;AN008 netview 6
658 DB 8,"ISAM.EXE" ,3,40,255 ;AN008 basic 7
659 DB 9,"ISAM2.EXE" ,3,40,255 ;AN008 basic 8
660 DB 12,"DFIA0MOD.SYS",3,40,255 ;AN008 lan support 9
665 ADJFAC EQU MEMSTRT
-SYSBUF