⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 init.asm

📁 DOS 源代码 系列之 command 源码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
 	page ,132
	title	COMMAND Initialization
;/*
; *                      Microsoft Confidential
; *                      Copyright (C) Microsoft Corporation 1991
; *                      All Rights Reserved.
; */

;
;	Revision History
;	================
;	M002	SR	07/15/90	Resize right at the start because
;				Carousel depends on it.
;
;	M004	SR	07/17/90	Initialization reworked so that 
;				transient is now moved at EndInit.
;				The old approach assumed that the
;				biggest block is the one currently 
;				loaded in, an assumption not true
;				for UMBs.
;
;	M005	SR	07/20/90	Numerous hacks for Carousel
;				1. Set CurrentPDB to ours at start
;				2. Normalize cs:ip of int 2fh hook
;				so that cs is different.
;
;	M013	SR	08/06/90	Fixed Setup_res_end & Move_res_code
;				to use new GetVersion call that
;				returns info about whether DOS is in
;				HMA or not.
;
;	M015	SR	08/09/90	Increased default environment size to
;				256 bytes from 160 bytes
;
;	M026	SR	9/12/90	Fixed environment trashing on second
;				Command if new comspec is given.
;
;	M030	SR	10/3/90	Before calling int 2fh 4a02h, set di
;				to 0ffffh so that we are ok if no one
;				answers this int 2fh.
;
;	M042	SR	12/13/90	Bug #4660. Changed setup_res_end to
;				take care of the dummy segment that
;				adds a para to the resident size.
;

.xlist
.xcref
	include comsw.asm
	include dossym.inc
	include pdb.inc
	include mult.inc
	include syscall.inc
	include doscntry.inc
	include comseg.asm
	include comequ.asm
	include resmsg.equ

	include envdata.asm
	include xmm.inc
.list
.cref



ENVBIG			equ	32768
ENVSML			equ	256		;Increased to 256 ; M015
KOREA_COUNTRY_CODE	equ	82


CODERES segment public byte

	extrn	ContC		:near
	extrn	DskErr		:near
	extrn	Int_2e		:near
	extrn	LodCom		:near
	extrn	MsgInt2fHandler	:far
	extrn	SetVect	:near
	extrn	ChkSum		:near
	extrn	CrLf		:near
	extrn	LoadCom	:near
	extrn	RPrint		:near

	extrn	EndCode	:byte
	extrn	StartCode	:byte

	ifdef	DBCS
	extrn	ItestKanj	:near
	endif

	extrn	BadMemErr	:near

CODERES ends

DATARES segment public byte

	extrn	Abort_Char	:byte
	extrn	AccDen		:byte
	extrn	Append_State	:word	
	extrn	Batch		:word
	extrn	Com_Fcb1	:dword
	extrn	Com_Fcb2	:dword
	extrn	Com_Ptr		:dword
	extrn	ComDrv		:byte
	extrn	ComSpec		:byte
	extrn	ComSpec_End	:word
	extrn	Crit_Msg_Off	:word	
	extrn	Crit_Msg_Seg	:word	
	extrn	DataResEnd	:byte 	
	extrn	Dbcs_Vector_Addr:word	
	extrn	EchoFlag	:byte
	extrn	EnvirSeg	:word
	extrn	ExtMsgEnd	:byte	
	extrn	fFail		:byte
	extrn	FUCase_addr	:word	
	extrn	InitFlag	:byte
	extrn	Int2fHandler	:dword
	extrn	Io_Save		:word
	extrn	LTpa		:word	
	extrn	MemSiz		:word
	extrn	MySeg		:word	
	extrn	MySeg1		:word
	extrn	MySeg2		:word
	extrn	MySeg3		:word
	extrn	Nest		:word
	extrn	OldTerm	:dword
	extrn	Parent		:word
	extrn	ParseMes_Ptr	:word	
	extrn	ParsMsgPtrs	:word
        extrn   PermCom         :byte
        extrn   SemiPermCom     :word
	extrn	PutBackDrv	:byte
	extrn	PutBackComSpec	:byte
	extrn	RDirChar	:byte
	extrn	Res_Tpa	:word
	extrn	ResMsgEnd	:word	    
	extrn	RSwitChar	:byte
	extrn	SingleCom	:word
	extrn	Sum		:word
	extrn	TrnSeg		:word
	extrn	TrnMvFlg	:byte

	extrn	ResSize	:word
	extrn	RStack		:word

	extrn	ComInHMA	:byte	;flag set if in HMA
	extrn	XMMCallAddr	:dword	;far call address to XMM

;;ifdef	ROMDOS
;;;	If LoadFromROM is in DATARES..
;;	extrn	LoadFromROM_seg	:word
;;endif

;
;All far pointers to resident routines that are to be patched
;
	extrn	Int2f_Entry	:dword
	extrn	Int2e_Entry	:dword
	extrn	Ctrlc_Entry	:dword
	extrn	CritErr_Entry	:dword

	extrn	Int2f_Trap	:near
	extrn	Int2e_Trap	:near
	extrn	Ctrlc_Trap	:near
	extrn	CritErr_Trap	:near
	extrn	LodCom_Trap	:near

	extrn	EndInit	:near

	extrn	Carousel_i2f_Hook	:byte	; M005

ifdef	BETA3WARN
	%out	Take this out before we ship
	extrn	Beta3Warned:byte
endif


DATARES ends


TAIL	segment public para

	extrn	TranStart	:word

TAIL	ends


TRANCODE	segment public byte

	extrn	DatInit	:far

TRANCODE	ends

TRANDATA	segment

	extrn	TranDataEnd	:byte

TRANDATA	ends

TRANSPACE	segment public byte

	extrn	TranSpaceEnd	:byte

TRANSPACE	ends




ifdef ROMDOS

;----------------------------------------------------------------------------
; Image of part of the BIOS data segment, named Bdata.
; Defines the following label:
;
;	BootFlags =	Boot options from CMOS RAM

include	msbdata.inc

; BootFlags bit we're concerned with:

BF_NoConfig	=	00000001b	; No config.sys processing

endif ; ROMDOS




; *******************************************************************
; START OF INIT PORTION
; This code is deallocated after initialization.

INIT	SEGMENT PUBLIC PARA

	extrn	AutoBat	:byte
	extrn	BadComAccMsg	:byte
	extrn	BadComLkMsg	:byte
	extrn	Badcspfl	:byte
	extrn	BadVerMsg	:byte
        extrn   AllocedEnv      :byte
	extrn	Command_?_syn	:byte	
	extrn	Command_c_syn	:byte	
        extrn   Command_k_syn   :byte
	extrn	Command_d_syn	:byte	
	extrn	Command_e_syn	:byte	
	extrn	Command_f_syn	:byte	
	extrn	Command_m_syn	:byte	
	extrn	Command_p_syn	:byte	
	extrn	Comnd1_syn	:word 	
	extrn	Comnd1_addr	:dword	
	extrn	ComSpect	:byte
	extrn	CopyrightMsg	:byte
	extrn	Dswitch	:byte	
	extrn	EnvMax		:word
	extrn	EnvSiz		:word
	extrn	EqualSign	:byte
	extrn	Eswitch	:byte	
	extrn	Ext_msg	:byte	
	extrn	HelpMsgs:word
	extrn	InitAdd	:dword
	extrn	InitEnd	:word
	extrn	Init_Parse	:dword	
	extrn	Internat_Info	:byte	
	extrn	KautoBat	:byte	
	extrn	Lcasea		:byte
	extrn	Lcasez		:byte
	extrn	Num_positionals	:word	
	extrn	OldEnv		:word
	extrn	Old_parse_ptr	:word	
	extrn	OutEnvMsg	:byte
	extrn	Parse_command	:byte	
	extrn	PrdAttm	:byte
	extrn	ResetEnv	:word	
	extrn	Scswitch	:byte
        extrn   Skswitch        :byte
	extrn	Space		:byte
	extrn	Triage_Add	:dword	
	extrn	TrnSize	:word
	extrn	Ucasea		:byte
	extrn	UsedEnv	:word

	extrn	PathString	:byte
        extrn   PathStrLen      :abs
        extrn   DefPathString   :byte
        extrn   DefPathStrLen   :abs
        extrn   DefPath2String  :byte
        extrn   DefPath2StrLen  :abs
        extrn   PrmptString     :byte
        extrn   PrmptStrLen     :abs
        extrn   PrmptStrLen2    :abs
        extrn   ComspOffset     :word
	extrn	ComspString	:byte
        extrn   ComspStrLen     :abs
        extrn   ComspStrLen2    :abs
	extrn	Reloc_Table	:word
	extrn	FirstCom	:byte
	extrn	ResJmpTable	:dword

	extrn	TriageError	:near

	extrn	NUM_RELOC_ENTRIES	:abs

	extrn	DevFlag	:byte
	extrn	PathFlag	:byte

	PUBLIC	ConProc
	PUBLIC	Init_ContC_SpecialCase

	assume	cs:ResGroup,ds:ResGroup,es:ResGroup,ss:ResGroup

	org	0
ZERO	=	$


ConProc:
	mov	sp,offset ResGroup:RStack	; must be first instruction
;
; We need to set the PSP to us right at start because Carousel needs
; to be lied to and it does not set PSP when it transfers control to
; us after loading us as an overlay. By setting PSP, we ensure that
; command.com is also not lied to.
;
        mov     ah,SET_CURRENT_PDB
        mov     bx,es
        int     21h

        mov     ax,GET_VERSION SHL 8
	int	21h
	cmp	ax,EXPECTED_VERSION
	je	OkDos				; DOS version is ok

	mov	dx,offset ResGroup:BadVerMsg	; DX = ptr to msg
	call	RPrint
	mov	ax,es
	cmp	es:PDB_Parent_Pid,ax		; if COMMAND is own parent,
Here:	jz	Here				;  loop forever
	
	int	20h				; otherwise, exit
okdos:

;
;  Calculate and save the end of the INIT segment (which is also
;  the beginning of TRANGROUP).
;

        mov     dx,offset resgroup:TranStart+15 ; get end of init code
        mov     cl,4                            ; change to paragraphs
        shr     dx,cl                           ;
        mov     ax,cs                           ; get current segment
        add     ax,dx                           ; calculate segment of end of init
        mov     InitEnd,ax                      ; save this

;
;  Check for /? on the command line.  If found, display help text
;  and exit.
;
;  NOTE:  this routine may terminate the program, never returning.
;
	call	CheckHelp

;
; We have to patch the segment values for the various interrupt entry points.
; This is because we need to have the default addresses of the handlers in our
; stub before the relocation is done. These values will then be changed once
; the resident is relocated
;
	call	patch_segs

;
;  Turn APPEND off during initialization processing
;
        mov     ax,APPENDINSTALL                ; see if append installed
	int	2fh				;
	cmp	al,0				; append installed?
	je	set_msg_addr			; no - continue
	mov	ax,APPENDDOS			; see if append DOS version right
	int	2fh				;
	cmp	ax,-1				; append version correct?
	jne	set_msg_addr			; no - continue
        mov     ax,APPENDGETSTATE               ; Get the state of Append
	int	2fh				;
        mov     Append_State,bx                 ; save append state
        xor     bx,bx                           ; clear out state
        mov     ax,APPENDSETSTATE               ; Set the state of Append
	int	2fh				; set everything off

set_msg_addr:
	mov	di,offset resgroup:DataresEnd 	; get address of resident end
	mov	ResMsgEnd,di			; save it


        call    get_XMMAddr                     ; get XMM call address
;
; Check if this is the first instance of command.com. If not, we just exit
; this routine without moving any code.
; After the int 2fh, ds:si points at the resident jump table in the previous
; stub. We just have to copy this over
;
	
ifndef ROMDOS
	mov	ax,GET_COMMAND_STATE	
else
	mov	ax,GET_ROMCOMMAND_STATE	
endif ; ROMDOS

	int	2fh
	assume	ds:nothing

	or	ax,ax
	jnz	first_com			;this is the first instance

ifdef	BETA3WARN
	%out	Take this out before we ship
	mov	es:Beta3Warned, 0ffh
endif

	mov	word ptr es:ResJmpTable,si		;save old stub jump table
	mov	word ptr es:ResJmpTable+2,ds
	jmp	short init_cntry

first_com:
	mov	es:FirstCom,1			;indicate first command.com

init_cntry:
	push	es
	pop	ds
	assume	ds:RESGROUP


	mov	ah,GETEXTCNTRY			; get extended country info
	mov	al,4				; get file ucase table
	mov	dx,-1				;
	mov	bx,-1				;
	mov	cx,5				; number of bytes we want
	mov	di,offset resgroup:Fucase_addr	; buffer for address
	int	21h				;

;	Bugbug:	conditionalize dbcs_vector stuff?
	push	ds				;
	mov	ax, (ECS_CALL shl 8) or GETLEADBTBL ;
	int	21h				;
	mov	bx,ds				; get segment to bx
	pop	ds				;
	mov	Dbcs_vector_addr,si			; save address of
	mov	Dbcs_vector_addr+2,bx			; dbcs vector


	mov	ax,word ptr ds:PDB_Parent_Pid 	; Init PARENT so we can exit
	mov	Parent,ax			;  correctly.
	mov	ax,word ptr ds:Pdb_Exit
	mov	word ptr OldTerm,ax
	mov	ax,word ptr ds:Pdb_Exit+2
	mov	word ptr Oldterm+2,ax


	mov	ax,offset ResGroup:EndCode + 15
	mov	cl,4				; ax = size of resident part of
	shr	ax,cl				;  command in paragraphs.  Add
	mov	cx,cs				;  this to CS and you get the
	add	ax,cx				;  segment of the TPA.

	mov	Res_tpa, ax			; Temporarily save the TPA segment
	and	ax, 0f000h
	add	ax, 01000h			; Round up to next 64K boundary
	jnc	TpaSet				; Memory wrap if carry set
	mov	ax, Res_tpa
TpaSet:
	mov	Ltpa,ax			; Good enough for the moment
	mov	ax,word ptr ds:PDB_Block_Len	; ax = # of paras given to command

	mov	Myseg1,ds			; These 3 variables are used as part of
	mov	Myseg2,ds			;  3 long ptrs that the transient will
	mov	Myseg,ds			;  use to call resident routines.
	mov	Myseg3,ds			; segment of msg retriever routine

	mov	Memsiz,ax			; Needed for execing other programs

;
; First reallocate the COMMAND size to its memory image
;
        push    ax                              ;
        mov     bx,offset RESGROUP:TranStart    ;
        add     bx,offset TRANGROUP:TranSpaceEnd;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -