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

📄 cstart.asm

📁 一个dos操作系统DRDOS的源码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
	dw	total_length
	dw	static_length
HEADER		ENDS

;	These Segments are forced into the correct order for a CDOS 
;	Resident System Process. First the RSP header which contains
;	the regeneration information required by GENSYS.
;
RSP_SEG	SEGMENT
sysdatseg	dw	0			; system data segment
sdatvar		dw	0047h			; # of system consoles
defconsole	db	0,0			; console # | copy #
		dw	0,0
		dw	RSF_DYNAMIC+RSF_SPECIAL+RSF_ENVIRON
		dw	0
		dw	0

RSP_SEG	ENDS

_DATA		SEGMENT byte public 'DATA'
	extrn	_gp_far_buff:word
_DATA		ENDS

else
R_TEXT	SEGMENT
	assume cs:DGROUP, ds:nothing, es:nothing, ss:nothing

ifdef	WATCOMC
	Public	_small_code_		; Watcom C requires this label to
_small_code_	label	near		; be declared in the start-up module
else
ifdef	MWC
	Public	_mwINIT			; MetaWare requires this label
_mwINIT		label	near		; to be declared in the start-up
					; module
else
    Public  __cstart       
__cstart	label	near		; to be declared in the start-up
					; module
endif
endif

	extrn	_gp_far_buff:word

ifdef	DOSPLUS
	extrn	com_criterr:near
endif


cstart:					; start address of all "C" programs
	call	near ptr getIP		; Push the IP register and Skip the
retIP:					; version control messages.
	dw	0EDCh			; Digital Research Marker
	dw	code_length		; Length of the Code Group
	;dw	static_length		; Length of the Fixed Data Group
ifdef DLS
	dw	total_length
else
	dw	dynamic_length		; length of dynamic data
endif
	dw	total_length		; Minimum Length of the Runtime
					; Data Group

reloc_off	dw 0		; offset of relocated resident code/data 
reloc_seg	dw 0		; segment of relocated resident code/data
reloc_size	dw 0		; size of relocated resident code/data

	public	_batchptr_off
	public	_batchflg_off
	public	_echoflg_off
_batchptr_off	dw 0		; offset of _batch variable
_batchflg_off	dw 0		; offset of _batchflg variable
_echoflg_off	dw 0		; offset of _echoflg variable

; These are the entry points for INT 23 and INT 24. They will have JMPF
; instructions poked into them.
control_break_entry	db 5 dup(90h)
crit_error_entry	db 5 dup(90h)


; The call to MS_X_EXEC must be made from the same segment as the PSP.
; msdos_exec does a far jump to here and then we far jump back.

psp_dofunc4b:
		mov	ax,(MS_X_EXEC*256)
		int	DOS_INT
		jmp  	i22_entry

; Software Carousel Version 5.0 looks for the following three instructions
; and assumes it is an entry point to int 22 code.
		mov	bx,0ffffh
		mov	ah,48h
		int	21h
		clc
i22_entry:		
int22_entry	db	0eah
		dw	dataOFFSET func4b_return
func4b_seg	dw	0

int2E_entry	db	0eah
		dw	dataOFFSET int2E_far_entry
int2E_seg	dw	0


; IMPORTANT - batch_seg_ptr MUST be just before reload_file. - EJH
;
;	***** Do Not change the order of the following variables *****
;

batch_seg_ptr	dw 0ffffh		; file filename. For novell remote
					; boot support.

ifdef DOSPLUS
reload_file	db	'A:\COMMAND.COM',0
else
ifdef NETWARE
reload_file	db	'A:\NETWARE.COM',0
else
reload_file	db	'A:\CDOS.COM',0
endif
endif
		db	(80-15) dup ('n')	; Expanded LoadPath

;cmdline	db	128 dup ('c')	; Local Copy of Initial Command Line

;	dummy pipe filenames for NOVELL

out_pipe 	db	'_:/' , 0 , '_______.___',0
in_pipe		db	'_:/' , 0 , '_______.___',0

;
;	***** Do Not change the order of the preceeding variables *****
;

; This next bit forces hi_seg_start to be on a paragraph boundary 
	org	HISEG_OFF
hi_seg_start	label byte

; Himem Registration chain entry
himem_link_next	dw	0
himem_link_size	dw	0
		db	5

	public	__psp
__psp		dw	0

	Public	_batch_seg_ptr
_batch_seg_ptr	dw	dataOFFSET batch_seg_ptr
		dw	0	; segment will be set to low_seg

	Public	_cbreak_ok

_cbreak_ok	db	0	; set when ctrl-break handler initialised

	; The following causes there to be at least one relocation item
	; in the .exe header so the loader does not think the file is
	; EXEPACKed.
	mov	ax,seg _batch_seg_ptr

R_TEXT	ENDS

endif

_TEXT	SEGMENT
ifdef  CDOSTMP
	assume cs:CGROUP, ds:DGROUP, ss:DGROUP
;
;	This entry point is used when the startup is executed as an
;	RSP. CS is CGROUP and DS is DGROUP. From here on we initialise
;	internal data structures etc. 
;

ifdef	WATCOMC
	Public	_small_code_		; Watcom C requires this label to
_small_code_	label	near		; be declared in the start-up module
else
ifdef	MWC
	Public	_mwINIT			; MetaWare requires this label
_mwINIT		label	near		; to be declared in the start-up
					; module
else
    Public  __cstart       
__cstart	label	near		; to be declared in the start-up
					; module
endif
endif

cstart:
	call	RSP_start		; Push the IP register and Skip the
retIP:					; version control messages.
	dw	0EDCh			; Digital Research Marker
	dw	code_length		; Length of the Code Group
	dw	static_length		; Length of the Fixed Data Group
	dw	total_length		; Minimum Length of the Runtime
					; Data Group
else
 	extrn	_int2e_handler:far
endif
	extrn	__main:far		; C main program


_TEXT	ENDS

_DATA	SEGMENT
;
;	Data held in this segment remains in the resident portion of 
;	the program image is is not overlayed by transient programs
;	loaded by COMMAND.COM. The variables here are private to the
;	startup module.
;
psp_save_area	dw	6 dup (?)

ifndef DOSPLUS
	extrn	_pd:dword		; Concurrent Process Descriptor
	extrn	_sysdat_seg:word	; Concurrent System Data Page
endif

	extrn	_n_option:word
;
;	The following is the offset and segment of the C routine MAIN
;	which is moved up in memory in order to accomodate the
;	Environment variables and Resident Data area.
;
C_code_entry	label	dword
	Public	code_seg,low_seg	
code_off	dw	codeOFFSET __main	; Offset of MAIN
code_seg	dw	?			; Segment of MAIN
data_seg	dw	?			; DGROUP segment
alloc_seg	dw	?			; the start of hi mem allocated
low_seg		dw	?			; segment of low memory stub.

ifdef CDOSTMP	

	Public	__psp
__psp		dw	0

cmd_histbuf	dw	0		; Command Processor History Buffer
prog_histbuf	dw	0		; Program History Buffer

mpb		label	word
mpb_start	dw	?
mpb_min		dw	?
mpb_max		dw	?
mpb_pdadr	dw	?
mpb_flags	dw	?
	
sysdat		dw	?		; Concurrent System Data Page
uda		dw	?		; Concurrent User Data Area
;
;	The following buffer is used by the P_EXEC function. Used
;	by CDOS_EXEC to load DOS and CP/M programs.
;
exec_block	label	byte
exec_pathoff	dw	?		; Offset of ASCIIZ Load file
exec_pathseg	dw	?		; Segment of ASCIIZ Load File
exec_filetype	db	?		; File Type Index
exec_loadtype	db	?		; EXEC or CHAIN to application
exec_clineoff	dw	?		; ASCIIZ Command line Offset
exec_clineseg	dw	?		; ASCIIZ Command Line Segment

exec		label	dword		; FAR pointer to EXEC routine
		dw	dataOFFSET cdos_exec
exec_seg	dw	?

cmdline		db	0		; Blank Command Line

EXEC_CODE	SEGMENT

	Assume	CS:DGROUP, DS:DGROUP, SS:DGROUP

err_tbl		db	0		; 00 Success
		db	-101		; 01 System Call Not Implemented
		db	-102		; 02 Illegal System Call
		db	ED_MEMORY	; 03 Cannot Find Memory
		db	-104		; 04 Illegal Flag Number
		db	-105		; 05 Flag Overrun
		db	-106		; 06 Flag Underrun
		db	-107		; 07 No Unused Queue Descriptors
		db	-108		; 08 No free Queue Buffer
		db	-109		; 09 Cannot find Queue
		db	-110		; 10 Queue in Use
		db	-111		; 11
		db	-112		; 12 No Free Process Descriptors
		db	-113		; 13 No Queue Access
		db	-114		; 14 Empty Queue
		db	-115		; 15 Full Queue
		db	-116		; 16 CLI Queue missing
		db	-117		; 17 No 8087 in system
		db	ED_DMD		; 18 No Unused Memory Descriptors
		db	-119		; 19 Illegal Console Number
		db	-120		; 20 No Process Descriptor Match
		db	-121		; 21 No Console Match
		db	-122		; 22 No CLI Process ??
		db	-123		; 23 Illegal Disk Number
		db	-124		; 24 Illegal FileName
		db	-125		; 25 Illegal FileType 
		db	-126		; 26 Character Not Ready
		db	ED_BLOCK	; 27 Illegal Memory Descriptor
		db	-128		; 28 Bad Return from BDOS load
		db	ED_FAIL		; 29 Bad Return from BDOS read
		db	ED_ACCESS	; 30 Bad Return from BDOS Open
		db	-131		; 31 Null Command
		db	ED_ENVIRON	; 32 Not owner of resource
		db	-133		; 33 No Cseg in Load File
		db	-134		; 34 PD exists on Thread Root
		db	-135		; 35 Could Not Terminate Process
		db	-136		; 36 Cannot ATTACH to Process
		db	-137		; 37 Illegal List Device Number
		db	ED_PASSWORD	; 38 Illegal Password
		db	-139		; 39
		db	-140		; 40 External Termination
		db	-141		; 41 Fixup Error on Load
		db	-142		; 42 Flag Set Ignored
		db	-143		; 43 Illegal Aux Device Number

cdos2dos PROC NEAR
	cmp	ax,0000			; Check for Success
	jz	c2d10			; and skip lookup
	lea	bx,err_tbl		; xlat the error code in AL
	xlat	err_tbl			; into a Negated DOS compatible
	mov	ah,0FFH			; error code
c2d10:
	ret
cdos2dos ENDP

; WORD FAR CDECL cdos_exec(BYTE *path, UWORD type, BYTE *line, BOOLEAN back);
;
; On Entry:
;	back	10[bp]
;	line	08[bp]
;	type	06[bp]
;	path	04[bp]
;
;	ES = SYSDAT
;
; On Exit:
;	AX = exit error code
;
cdos_exec PROC FAR
	lea	si,P_MEM[bx]		; SI -> root of MD's
ce_10:					; find our code segment
	mov	si,es:[si]		; get next memory descriptor
	test	si,si			; end of list?
	 jz	ce_40			; yes, we don't own any separate code
	test	es:word ptr 6[si],MF_CODE
	 jz	ce_10			; loop back if not code segment
	mov	si,es:8[si]		; get MPAD for code segment
	lea	di,P_MPAR[bx]		; get MPAD root
ce_20:
	cmp	si,es:[di]		; is this the predecessor?
	 je	ce_30
	mov	di,es:[di]		; else check next MPAD
	jmp	short ce_20
ce_30:					; SI -> our MPAD, DI -> previous MPAD
	xor	ax,ax
	xchg	ax,es:[si]		; get next MPAD
	mov	es:[di],ax		; unlink our MPAD from list
ce_40:
	push	di
	push	si			; SI = 0 if no separate code alloc

	push	ds
	mov	ds,es:P_PSP[bx]		; point to our PSP
	mov	ds:word ptr [5eh],si	; stash TMP mpad away in here
	pop	ds

	mov	dx,198			; Raise the priority of the TMP
	bdos	P_PRIORITY		; while we wait for the child

	mov	dx,dataOFFSET exec_block
	push	es			; do a P_EXEC but save /restore
	bdos	P_EXEC			; ES around it since DRNET trashes
	pop	es			; it sometimes.

	mov	ax,cx			; Get the Concurrent Error Code
	call	cdos2dos		; and convert to a standard DOS
	push	ax
					; Error Code for COMMAND.RSP
	test	ax,ax			; If any errors occured during the 
	 jnz	ce_60			; exec or the child process is not
	cmp	word ptr 10[bp],0	; inheriting the console the do not
	 jnz	ce_60			; execute a Console Attach function
	bdos	C_ATTACH		; process to terminate
ce_60:	
	mov	dx,200			; Return to the normal priority
	bdos	P_PRIORITY		; now that we have the console back
	pop	ax
	pop	si
	pop	di
	test	si,si			; separate code allocation?
	 jz	ce_50			; no, don't have to un-kludge!
	push	ax
	mov	ax,es:[di]		; get link of previous MPAD
	mov	es:[si],ax		; link it to our MPAD
	mov	es:[di],si		; link our MPAD to previous MPAD
	mov	dx,1			; make sure code gets banked in
	bdos	P_DELAY			; this gets us off/on RLR
	pop	ax
ce_50:
	ret
cdos_exec ENDP	

EXEC_CODE	ENDS

_TEXT	SEGMENT
	assume cs:CGROUP, ds:DGROUP, es:nothing, ss:nothing
	public	_exec			; EXEC routine

;
; WORD CDECL exec(BYTE *path, UWORD type, BYTE *line, BOOLEAN back);
;
; On Entry:
;	back	10[bp]		; This value is ignored for MSDOS_EXEC
;	line	08[bp]
;	type	06[bp]
;	path	04[bp]
;
; On Exit:
;	AX = exit error code
;
_exec:
;-----
	push	bp
	mov	bp,sp
	push	si
	push	di
	mov	ax,04[bp]		; Get the Full Command Name
	mov	exec_pathoff,ax
	mov	exec_pathseg,ds

	mov	ax,08[bp]		; and the Command Line
	mov	exec_clineoff,ax
	mov	exec_clineseg,ds

	mov	ax,06[bp]		; Get the Command Type (.CMD etc)
	mov	exec_filetype,al	; Save the Command type
	mov	exec_loadtype, 0	; The default is to load the command
	cmp	word ptr 10[bp],0	; and for the child to inherit the
	 jz	exec_10			; console
	mov	exec_loadtype,2
exec_10:

	test	al,al			; is command type a CMD
	 jnz	exec20			; no, skip XIOS call
	mov	ax,XIOS_PCKBD		; CMD's expect 24 lines
	mov	cl,40h			; so tell XIOS thats what we must have
	mov	dl,defconsole		; on this console
	call	xios
exec20:

	les	bx,_pd			; Get the process Descriptor Address
	mov	cx,prog_histbuf		; and force the system to use the
	mov	es:P_SB_SEG[bx],cx	; Program Level History Buffer

	call	exec			; do FAR call to cdos_exec

	les	bx,_pd			; Get the process Descriptor Address
	mov	cx,cmd_histbuf		; and force the system to use the
	mov	es:P_SB_SEG[bx],cx	; Command Level History Buffer

⌨️ 快捷键说明

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