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

📄 biosinit.a86

📁 Dos7.01的源代码
💻 A86
📖 第 1 页 / 共 4 页
字号:
mark_sm50:
	pop	es
	ret

; Relocate the BIOS code from top of memory
reloc_bios:
	mov	dx,rcode_offset
	mov	cx,rcode_len		; we need to relocate this much
	test	cx,cx			; do we need to move anything ?
	 jnz	reloc_bios10
	ret
reloc_bios10:
	add	cx,15			; round rcode size up to a para
	and	cx,not 15
	mov	ax,bios_target_seg	; where do we go
	test	ax,ax
	 jz	reloc_bios20		; zero - do it ourselves
	inc	ax			; FFFF - unlikely as it's not
	 jz	reloc_bios25		;  currently supported
	dec	ax			; else we've been given a seg
	jmps	reloc_bios40
reloc_bios20:	
	cmp	dos_target_seg,0FFFFh	; if DOS goes up, so does BIOS
	 jne	reloc_bios30
reloc_bios25:
	call	AllocHMA		;  in HIGH memory
	 jnc	reloc_bios50
reloc_bios30:
	mov	ax,cx			; allocate conventionally
	shr ax,1 ! shr ax,1		;  in para's of course
	shr ax,1 ! shr ax,1
	cmp	hidos,0			; do we want to relocate DOS ?
	 je	reloc_bios35		;  no, allocate conventionally
	call	alloc_upper		; try to allocate some upper memory
	 jnc	reloc_bios40		;  can't, so allocate conventional
reloc_bios35:				;  padding out if required
	call	alloc_seg_with_padding
reloc_bios40:
	mov	es,ax
	xor	di,di			; ES:DI -> destination
	shr dx,1 ! shr dx,1		; convert offset to para's
	shr dx,1 ! shr dx,1
	sub	ax,dx			; bias segment appropriately
	xchg	ax,dx			;  and have in DX
reloc_bios50:
	push	es
	push	cx
	push	di

	push	ds
	mov	si,rcode_offset
	mov	ds,rcode_seg
	rep	movsb
	pop	ds
	mov	rcode_seg,dx		; new RCODE location

	call	dd_fixup		; fixup any device drivers

	pop	di
	pop	cx
	pop	es
	ret


;
; The following code performs the fixups necessary for RELOCATABLE executable
; internal device drivers.

dd_fixup:
; On Entry:
;	None
; On Exit:
;	None

	push	es
	mov	di,rcode_seg		; fixup to this segment
	mov	si,rcode_fixups		; get fixup table
	test	si,si			; is there one ?
	 jz	dd_fixup20
	mov	es,bios_seg
dd_fixup10:
	lodsw				; get a fixup offset
	test	ax,ax			; last of the fixups ?
	 jz	dd_fixup20
	xchg	ax,di			; point to the fixup
	stosw				; do the fixup
	xchg	ax,di			; save segment again
	jmps	dd_fixup10
dd_fixup20:
	pop	es
	ret


ReserveOSHMA:
;------------
; reserve space in HMA for OS
; On Entry:
;	None
; On Exit:
;	None
;

ReserveCommandHMA:
;----------------
; reserve space in HMA for COMMAND.COM
; On Entry:
;	None
; On Exit:
;	None
;
	cmp	commandHMA,0		; been here already ??
	 jne	ReserveCommandHMA10
	mov	cx,COMMAND_SIZE
	mov	dx,COMMAND_BASE
	call	ReserveHMA		; reserve the space in HMA
	 jc	ReserveCommandHMA10	;  if we can
	mov	commandHMA,ax		; save for re-use
ReserveCommandHMA10:
	ret

ReserveHMA:
;----------
; reserve some space in the HMA
; On Entry:
;	CX = size require
;	DX = maximum offset acceptable
; On Exit:
;	AX = offset of reserved space
;
	push	es
	call	AllocHMA		; allocate space in HIGH memory
	 jc	ReserveHMA10
	mov	es:word ptr [di],0	; no link, it's this big
	mov	es:word ptr 2[di],cx
	mov	bx,es
	mov	ax,0FFFFh
	sub	ax,bx			; AX = para offset adjustment required
	mov	cl,4
	shl	ax,cl			; convert to byte offset
	add	ax,di			; AX = offset from FFFF:0
ReserveHMA10:
	pop	es
	ret


FreeHMA:
;-------
; Return reserved HMA space to pool
; On Entry:
;	CX = offset of HMA block to relink (0 = noblock)
; On Exit:
;	None
;
	 jcxz	free_himem10		; no block, don't recycle
	push	es
	push	cx			; save offset
	les	bx,cs:drdos_ptr
	pop	ax			; recover offset
	mov	di,ax			; remember offset for later
	xchg	ax,es:DRDOS_HIMEM_ROOT[bx]; become new head of HMA
	mov	bx,0FFFFh
	mov	es,bx			; point ES:DI at our section
	stosw				;  chain on rest of HMA
	pop	es
free_himem10:
	ret


rploader:
;--------
; On Entry:
;	DX = phase code
; On Exit:
;	None, All regs preserved
	push	es
	push	ax
	push	bx
	push	cx
	push	dx
	mov	ax,rpl_off		; do we have an RPL sitting on
	or	ax,rpl_seg		;  Int 13h
	 jz	rploader10
	mov	ax,12ffh		; magic cleanup call to RPL
	mov	bx,5			;  to do any tidy ups it wishes
	xor	cx,cx			;  following resident BIOS
	mov	dx,1			;  initialisation
	pushf
	cli
	callf	rpl_entry		; fake an INT
rploader10:
	pop	dx
	pop	cx
	pop	bx
	pop	ax
	pop	es
	ret

	Public	Verify386

Verify386:
;---------
; On Entry:
;	None
; On Exit:
;	CY clear if 386 or above
;
	push	sp			; really old CPU's inc SP
	pop	ax			;  before pushing
	cmp	ax,sp			; newer ones push original SP
	 jne	Verify386fail
	mov	ax,3000h		; now try to set IOPL = 3
    push    ax
	popf
	pushf
	pop	bx
	and	ax,bx			; any IOPL bits set ?
	 jz	Verify386fail
;	clc				; it's at least a 386
	ret
Verify386fail:
	stc				; it's not a 386
	ret


INITDATA	dseg	'INITDATA'


include	initmsgs.def				; Include TFT Header File


	extrn	history_flg:byte
	extrn	next_drv:byte
	extrn	dev_count:byte

;
;	PUBLIC Variables which are initialised by the BIOS before the
;	BIOSINIT code has been executed. 
;
data_start	rb	0		; used to para-align PSP & ENV

	Public	func52_ptr
func52_ptr	rd	0		; address of internal BDOS variables
func52_off	dw	0		; offset	"	"	"
func52_seg	dw	0		; segment	"	"	"

	Public	drdos_ptr
drdos_ptr	rd	0		; address of internal BDOS variables
drdos_off	dw	0		; offset	"	"	"
drdos_seg	dw	0		; segment	"	"	"


	Public	res_ddsc_ptr
res_ddsc_ptr	rd	0
res_ddsc_off	dw	0
res_ddsc_seg	dw	0

	Public	rcode_offset, rcode_seg, icode_len, rcode_len, rcode_fixups

rcode_offset	dw	0		; current offset of relocated code
rcode_seg	dw	0		; current segment of relocated code
icode_len	dw	0		; initial size of relocated code
rcode_len	dw	0		; final size of relocated code
rcode_fixups	dw	0		; offset of rcode fixup table

	Public	current_dos
current_dos	dw	0		; Current Segment Address of DOS Code

	Public	dos_target_seg, bios_target_seg
dos_target_seg	dw	0		; target address for DOS relocation
bios_target_seg	dw	0		; 0000 - auto-relocate
					; FFFF - high memory (not allocated)
					; xxxx - driver allocated address

dosCodeParaSize	dw	0		; Size of DOS code in para's

systemSize	dw	COMMAND_SIZE	; BIOS+DOS code sizes are added to
					;  give total size to reserve in HMA

systemHMA	dw	0		; offset of area in HMA reserved 
					;  for SYSTEM (BIOS/DOS/COMMAND)
commandHMA	dw	0		; offset of area in HMA reserved 
					;  for COMMAND.COM


	Public	device_root
device_root	rd	1		; Root of Resident Device driver Chain

	Public	mem_size, ext_mem_size, comspec_drv
	Public	init_flags, init_drv

mem_size	dw	0		; Total Memory Size (in Paragraphs)
ext_mem_size	dw	0		; Total Extended Memory Size (in KB.)
init_flags	dw	0		; BIOS INIT Flags
init_drv	db	0		; Boot Drive (A is 0 .....)
comspec_drv	db	0		; Default COMSPEC Drive

	Public	num_stacks, stack_size

num_stacks	dw	DEF_NUM_STACKS
stack_size	dw	DEF_SIZE_STACK

	Public	num_files, num_fcbs, num_fopen
	Public	country_code, code_page
	
num_files	dw	DEF_NUM_FILES	; # of file handles
num_fcbs	dw	DEF_NUM_FCBS	; # of fcb file handles
num_fopen	dw	-1		; "unset" value for fast open
country_code	dw	DEF_COUNTRY	; Country Code 
code_page	dw	DEF_CODEPAGE	; Code Page

	Public	dos_name
IF DRDOS35
dos_name	db	'DRBDOS  SYS',0 
ELSE
dos_name	db	'IBMDOS  COM',0	; default DOS filename
ENDIF

rpl_name	db	'RPLOADER'

rpl_entry	rd	0		; remember RPL entry point for
rpl_off		dw	0		;  startup broadcasts
rpl_seg		dw	0

eject
;
;	Internal variables used by the BIOSINIT code
;
	Public	bios_seg
bios		rd	0		; Far pointer to the BIOS Cleanup
bios_offset	rw	1		; routines.
bios_seg	rw	1

	Public	init_dseg
init_dseg	dw	0		; Init data segment

	Public	dos_dseg
dos_dseg	dw	0		; DOS Data Segment Address

	Public	mem_current_base, mem_current, mem_max
mem_first_base	rw	1		; Base of First Allocated Memory
mem_current_base rw	1		; Base of Current Allocated Memory
mem_current	rw	1		; Next Free Paragraph
mem_max		rw	1		; Last available Paragraph


dos_init	rd	0		; DOS Initialization Code
dos_coff	dw	0		; DOS Init Code Offset
dos_cseg	rw	1		; DOS Init Code Segment

free_seg	rw	1		; First available paragraph.

xms_driver	rd	1		; address of himem driver

	Public	hidos
hidos		db	0		; set true if HIDOS requested
himem_base	dw	0		; base of HIMEM seg allocations
himem_size	dw	0		; length of HIMEM seg allocations

	Public	last_drv

last_drv	db	5		; default is "E:"

console		db	'CON',0		; Default Console Device
printer		db	'PRN',0		; Default Printer Device
auxilary	db	'AUX',0		; Default Auxilary Device

idle_dev	db	'$IDLE$',0	; Idle Device Name
idle_off	rw	1		; Idle Data Area Offset
idle_seg	rw	1		; Idle Data Area Segment

dummy_fcb	db	0,'           '

exec_env	dw	0		; Environment Segment
exec_cloff	dw	shell_cline	; Command Line Offset
exec_clseg	dw	0		; Command Line Segment
		dw	dummy_fcb
exec_fcb1seg	dw	0		; FCB 1 Offset and Segment
		dw	dummy_fcb
exec_fcb2seg	dw	0		; FCB 2 Offset and Segment
		rd	1		; SS:SP
		rd	1		; CS:IP

	Public	shell_cline
shell_cline	db	length shell_drv; Initial Command Line
shell_drv	db	'A: /P'
		db	0Dh
		rb	126 - length shell_drv

dummyVDISK	db	0, 0, 0		; jump instruction
		db	'VDISK3.3'	; OEM name
		dw	128		; bytes per sector
		db	1		; sectors per allocation unit
		dw	1		; number of reserved sectors
		db	1		; number of FATs
		dw	40		; number of root directory entries
		dw	512		; total number of sectors
		db	0FEh		; media descriptor byte
		dw	6		; sectors per FAT
		dw	8		; sectors per track
		dw	1		; number of heads
		dw	0		; number of hidden sectors
		dw	1024+64		; KB of extended memory used

search_state	rb	43		; Search First/Next State

		rw	384		; big stack for ASPI4DOS.SYS driver
stack		rw	0


INITPSP		DSEG	PARA 'INITDATA'
		db	'Z'			; dummy DMD header
		dw	0008h			; owner is system
		dw	0010h			; length of PSP
		rb	3			; pad to 8 bytes
		db	'DOS',0,0,0,0,0		; name field (must be 8 bytes)
psp		rb	16h			; Zero Fill PSP Header
parent_psp	dw	0			; parent, patched to itself
		db	0FFh, 0FFh, 0FFh	; STDIN, STDOUT, STDERR
		db	0FFh, 0FFh		; STDAUX, STDPRN
		db	0FFh, 0FFh, 0FFh	; Remainder CLOSED
		db	0FFh, 0FFh, 0FFh
		db	0FFh, 0FFh, 0FFh
		db	0FFh, 0FFh, 0FFh
		db	0FFh, 0FFh, 0FFh
		dw	0000			  ; PSP Environment Pointer
		dw	0000, 0000		  ; DOS User SS:SP
		dw	20			  ; Maximum of 20 Handles
		dw	offset PSP_XFT		  ; Handle Table Offset
xftbl_seg	dw	0			  ; Handle Table Segment
		rb	offset PSP_VERSION - offset PSP_RES1
	Public	dosVersion
dosVersion	dw	7			  ; DOS version is 7.0
		rb	PSPILEN - offset PSP_VERSION - 2
						  ; PAD to Partial PSP Size

INITENV		DSEG	PARA 'INITDATA'

shell_ask	db	79			; max len
shell_end	db	0			; end of the line
	Public	shell
shell		db	'A:\COMMAND.COM', 0	
		rb	80-length shell

DATAEND	DSEG	PARA 'INITDATA'

	Public	biosinit_end
biosinit_end	rb	0

	end

⌨️ 快捷键说明

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