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

📄 sdmisc.asm

📁 <BIOS研发技术剖析>书的源代码,包括完整的BIOS汇编语言源程序.
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	page	50,130
	title	SDMISC.ASM
;*****************************************************************;
;*****************************************************************;
;**								**;
;**	(C)Copyright 1985-1999, American Megatrends Inc.	**;
;**								**;
;**			All Rights Reserved.			**;
;**								**;
;**		6145-F, Northbelt Parkway, Norcross,		**;
;**								**;
;**		Georgia - 30071, USA. Phone-(770)-246-8600.	**;
;**								**;
;*****************************************************************;
;*****************************************************************;
;-----------------------------------------------------------------------;
;	MISCELLANEOUS SETUP DATA AND ASSOCIATED ROUTINES		;
;-----------------------------------------------------------------------;
	extrn	str_not_installed:abs
	extrn	str_user:abs
	extrn	str_auto:abs
	extrn	str_cdrom:abs
	extrn	str_floptical:abs
;---------------------------------------;
	extrn	cmos_data_in:near
	extrn	cmos_data_out:near
	extrn	read_cmos_word:near
	extrn	get_setup_$_ptr:near
	extrn	auto_hd_type:near
	extrn	get_pio_mode_value:near
	extrn	check_cmos_8e:near
	extrn	buffer_password_length:near
	extrn	get_bl_al:near

	extrn	ide_prim_base_addr:word
	extrn	ide_sec_base_addr:word
	extrn	setup_data_struc_start:byte
	extrn	hd_tbl_start:byte
	extrn	base_tbl:byte
;---------------------------------------;
_StrSet2	equ	02h		; string set 2
;---------------------------------------;
	include	ramdata.inc
	include	cmos.equ
;---------------------------------------;
setup_data_struc	struc
	cmos_reg	db	(?)	; Cmos register number.
					; if bit-7 = 1 then option is  present
					; else option is absent.
	mask_value	db	(?)	; Mask to be used to acess the value from cmos register.
setup_data_struc	ends
;---------------------------------------;
cgroup	group	_text
_text	segment	word	public	'CODE'
	assume	cs:cgroup, ds:fgroup
.386p
;---------------------------------------;
;	PutCharWord			;
; I/P :	ax	data to store		;
;	es:di	address to store	;
;---------------------------------------;
PutCharWord	proc	near
	mov	cx,10			; divide by 10
	xor	dx,dx
	div	cx
	or	ax,ax			; quotient = 0 ?
	jz	ascii_2			; yes - got a digit
	push	dx			; save remainder
	call	PutCharWord
	pop	dx
ascii_2:
	mov	ax,dx			; get remainder
	or	al,30h			; convert to ascii
	stosb				; and store
	ret
PutCharWord	endp
;---------------------------------------;
;	GET_CMOS_BUFFER_ITEM		;
; puts value in non-consecutive bits in ;
; cmmon cmos buffer byte		;
; input :				;
;	al	structure#		;
; output:				;
;	al	right justified value	;
;	ZR	if value is zero	;
;	NZ	if value is non-zero	;
; Destroys : AX				;
;---------------------------------------;
	public	get_cmos_buffer_item
get_cmos_buffer_item	proc	near
	push	cx
	push	bx
	mov	ch,ah			; save input AH
	movzx	bx,al
	shl	bx,1
	add	bx,offset cgroup:setup_data_struc_start
	mov	ah,cs:(setup_data_struc ptr [bx]).mask_value; AH = mask_value
	mov	bl,cs:(setup_data_struc ptr [bx]).cmos_reg; BL = cmos register
	and	bx,007fh		; BX = cmos reg = offset to cmos buffer
;  AH = mask value..
;  BX = offset to cmos buffer..
	mov	al,_common_cmos_buffer[bx]; AL = value
	mov	bh,ah
;  AL = full register value..BH = mask value for bits..
	mov	cl,08h			; loop count
	mov	ah,0
gcbi_9:
	rol	bh,1			; Check MSB
	jnc	gcbi_10			; No carry = MSB was 0.
	rol	ax,1			; Mov MSB of AL to LSB of Ah.
	jmp	short gcbi_11
gcbi_10:
	rol	al,1			; Ignore MSB.
gcbi_11:
	dec	cl
	jnz	gcbi_9
	mov	al,ah			; Final value.
	mov	ah,ch			; restore original AH
	or	al,al			; Set/Reset Zero flag.
	pop	bx
	pop	cx
	ret				; Go back.
get_cmos_buffer_item	endp
;---------------------------------------;
;	SET_CMOS_BUFFER_ITEM		;
; puts value in non-consecutive bits in ;
; cmmon cmos buffer byte		;
; input :				;
;	al	structure#		;
;	ah	new value of mask	;
; output:				;
;	none				;
; Destroys : none			;
;---------------------------------------;
	public	set_cmos_buffer_item
set_cmos_buffer_item	proc	near
	pusha
	movzx	bx,al
	shl	bx,1
	add	bx,offset cgroup:setup_data_struc_start
	mov	dl,cs:(setup_data_struc ptr [bx]).mask_value; DL = mask_value
	mov	bl,cs:(setup_data_struc ptr [bx]).cmos_reg
	and	bl,7fh
	mov	bh,00h			; BX = cmos register
	mov	al,ah			; AL = new value to put
	call	PutSparseVal
	popa
	ret
set_cmos_buffer_item	endp
;---------------------------------------;
;	PutSparseVal			;
; puts value in non-consecutive bits in ;
; a byte				;
; I/P :	bx	target address		;
;	al	new value to put	;
;	dl	mask value		;
; Returns				;
;	al	new byte value		;
; Destroys	ax,cx,dl		;
;---------------------------------------;
PutSparseVal	proc	near
	mov	ah,al
	mov	al,[bx]
	mov	cx,8
pv1:
	shr	dl,1
	jc	pv0
	ror	al,1
	jmp	short	pv2
pv0:
	shr	ax,1
pv2:
	loop	pv1
	mov	[bx],al
	ret
PutSparseVal	endp
;---------------------------------------;
; 	GetHddType			;
; returns hard disk type		;
; Input :				;
; 	al = 0  harddisk C		;
;	   = 1  harddisk D		;
;	   = 2  harddisk E		;
;	   = 3  harddisk F		;
; Output :				;
;	al = type			;
; Destroys AX,BX			;
;---------------------------------------;
_hddC	equ	0
_hddD	equ	1
_hddE	equ	2
_hddF	equ	3

GetHddType	proc	near
	mov	ah,_cmos[harddisk_cd]	; C/D type
	cmp	al,_hddD
	ja	ght1			; > D, jump
	je	ght2			; = D
	shr	ah,4			; C - get type from upper nibble
ght2:
	and	ah,0fh			; ah = C/D type
	cmp	ah,15			; type 15 ?
	jne	ght3			; no - ok
	mov	bx,extd_hdisk_c		; extd type base = 19h for C/D
	jmp	short	ght4
ght1:					; al = 2/3 -> E/F
	mov	bx,harddisk_e-2		; type base = 29h for E/F
ght4:
	add	bl,al			; C=19/D=1a/E=2b/F=2c
	mov	ah,_cmos[bx]		; get extd type
ght3:
	mov	al,ah
	and	al,3fh			; mask off unwanted bits
	ret
GetHddType	endp
;---------------------------------------;
; 	SetHddType			;
; sets hard disk type in cmos buffer	;
; Input :				;
;	al = type			;
; 	dl = 0  harddisk C		;
;	   = 1  harddisk D		;
;	   = 2  harddisk E		;
;	   = 3  harddisk F		;
; Destroys AX,BX,CX,DX			;
;---------------------------------------;
SetHddType	proc	near
	cmp	dl,_hddD
	ja	sht6			; >D, jump

	mov	ah,0fh			; mask for D
	mov	bx,extd_hdisk_c		; extd type base = 19h for C/D
	je	sht1			; =D, jump
	mov	ah,0f0h			; mask for C
sht1:
	cmp	al,15
	ja	sht2			; > type15, jump
	add	bl,dl			; extd type offset, C=19h/D=1ah
	mov	_cmos[bx],0		; make it 0 for < type 15
	mov	bx,harddisk_cd		; offset for C/D type
	mov	dl,ah			; get mask in dl
	jmp	short	sht3
sht2:					; > type 15
	or	_cmos[harddisk_cd],ah	; put 15 here
	jmp	short	sht7
sht6:
	mov	bx,harddisk_e-2		; type base = 29h for E/F
sht7:
	add	bl,dl			; C=19/D=1a/E=2b/F=2c
	mov	dl,3fh			; mask
sht3:
	lea	bx,_cmos[bx]		; get full address
	call	PutSparseVal		; put new value
	ret
SetHddType	endp
;---------------------------------------;
	public	GetHddTypeC
GetHddTypeC	label	far
	mov	al,0
	jmp	short	hdd_together
;---------------------------------------;
	public	GetHddTypeD
GetHddTypeD	label	far
	mov	al,1
	jmp	short	hdd_together
;---------------------------------------;
	public	GetHddTypeE
GetHddTypeE	label	far
	mov	al,2
	jmp	short	hdd_together
;---------------------------------------;
	public	GetHddTypeF
GetHddTypeF	label	far
	mov	al,3
;---------------------------------------;
hdd_together:
	call	GetHddType
; now find the string
	mov	bh,str_not_installed
	or	al,al			; if type 0
	jz	ght_2			; say not installed
	cbw				; ah=0
	mov	bh,str_user
	cmp	al,47			; if not between 1..46
	je	ght_2			; 47 = User
	ja	ght_0			; > 47
; here comes types 1..46
	push	ds
	pop	es
	mov	di, offset _temp_buffer	; es:di = buffer
	push	di			; save offset
	call	PutCharWord		; convert to ascii
	sub	al,al
	stosb				; put zero at end
	pop	bx			; get offset in bx
	mov	dx,es			; dx:bx = ptr to string
	retf
ght_0:					; type > 47
	mov	bh,str_auto
	cmp	al,49
	jb	ght_2			; auto
	mov	bh,str_cdrom
	jz	ght_2			; cdrom
	mov	bh,str_floptical	; floptical
ght_2:
	mov	bl,_StrSet2
	call	get_setup_$_ptr		; get string ptr
	mov	bx,ax			; return in dx:bx
	retf
;---------------------------------------;
HdMetrix	STRUC
	_Cyl	dw	?
	_Head	db	?
	_WP	dw	?
	_Sec	db	?
	_Type	dw	?
	_StrSet	db	?
	_StrID	db	?
HdMetrix	ENDS
;---------------------------------------;
_Type47Loc	label	byte		; type 47 area for drives
	db	uc_cylinder		; primary master
	db	ud_cylinder		; primary slave
	db	ue_cylinder		; secondary master
	db	uf_cylinder		; secondary slave
;---------------------------------------;
;	GetHdMetrix			;
; This routine returns drive params	;
; viz. type, cyl, head, sec/trk etc. in	;
; a structure.				;
; Input :				;
;	ax	harddisk type		;
;	bx	ptr to structure buffer	;
;	dx	drive ID		;
; 		0  harddisk C		;
;	   	1  harddisk D		;
;	   	2  harddisk E		;
;	   	3  harddisk F		;
;---------------------------------------;
size_p	equ	6
;---------------------------------------;
	public	GetHdMetrix
GetHdMetrix	proc	near
	pusha
	mov	di,bx
	push	ds
	pop	es

	mov	(HdMetrix ptr [di])._StrSet,_StrSet2
	mov	(HdMetrix ptr [di])._StrID,0
	mov	(HdMetrix ptr [di])._Cyl,0

	mov	bl,str_not_installed
	or	ax,ax
	jz	ghm3			; not installed
	mov	bl,str_auto
	mov	cx,ax			; save type in cx
	sub	ax,47
	ja	ghm0			; Auto/CDROM
	je	ghm1			; type 47

; Type 1..46 ---------------------------;
; calculate offset into parameter table
	mov	ax,cx
	dec	ax
	shl	ax,4			; * 16
	add	ax,offset cgroup:hd_tbl_start	; add with base address
	mov	bx,ax
; retrieve parameters from table
	mov	ax,cs:[bx]		; cylinder
	stosw
	mov	al,cs:[bx+2]		; head
	stosb
	mov	ax,cs:[bx+5]		; write precomp
	stosw
	mov	al,cs:[bx+14]		; sector
	stosb
	jmp	short	ghm2
ghm1:
; Type 47 ------------------------------;
	push	di
	mov	bx,dx			; current hard disk (0..3)
	mov	bl,cs:_Type47Loc[bx]	; type 47 area offset
	lea	si,_cmos[bx]		; si = drive parms
	mov	cx,size_p
	rep	movsb			; copy params
	mov	bl,str_user
	pop	di
	jmp	short	ghm3
ghm0:
	dec	al
	jz	ghm3
	mov	bl,str_cdrom
	dec	al
	jz	ghm3
	mov	bl,str_floptical
ghm3:
	mov	(HdMetrix ptr [di])._StrID,bl
ghm2:
	popa
	ret
GetHdMetrix	endp
;---------------------------------------;
FieldTbl	label	byte
	db	2			; Width of 1st field (Cylinder)
	db	2			; Cylinder
	db	1			; Head
	db	2			; WPcom
	db	1			; Sec
;---------------------------------------;
;	SetUserHdd			;
; Set Type47 Fields.			;
; Input :				;
; 	al	1 - Cyl			;
;		2 - Head		;

⌨️ 快捷键说明

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