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

📄 flsnvrid.asm

📁 <BIOS研发技术剖析>书的源代码,包括完整的BIOS汇编语言源程序.
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;---------------------------------------;--------------------------------------;
; This function writes one byte to NVRam.  This function should only be        ;
; supported if NVRam may be written one byte at a time.  If Flash is being     ;
; used for NVRam, then this function should just return with CF set.           ;
;                                                                              ;
; Input:  AL = Byte to write to NVRam                                          ;
;         DI = Offset into NVRam where byte should be written                  ;
;         ES = Segment/Selector needed to access NVRam                         ;
;                                                                              ;
; Output: CF = Set if error, cleared otherwise                                 ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
rthnvr_write_nvr_byte	proc	near
;	mov	byte ptr es:[di], al
;	clc
	stc
	ret
rthnvr_write_nvr_byte	endp


;---------------------------------------;
; rthnvr_write_nvr_word                 ;
;---------------------------------------;--------------------------------------;
; This function writes one word to NVRam.  This function should only be        ;
; supported if NVRam may be written one word at a time.  If Flash is being     ;
; used for NVRam, then this function should just return with CF set.           ;
;                                                                              ;
; Input:  AX = Word to write to NVRam                                          ;
;         DI = Offset into NVRam where word should be written                  ;
;         ES = Segment/Selector needed to access NVRam                         ;
;                                                                              ;
; Output: CF = Set if error, cleared otherwise                                 ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
rthnvr_write_nvr_word	proc	near
;	mov	word ptr es:[di], ax
;	clc
	stc
	ret
rthnvr_write_nvr_word	endp


;---------------------------------------;
; rthnvr_write                          ;
;---------------------------------------;--------------------------------------;
; This function writes the entire contents of NVRam from a buffer supplied by  ;
; the caller.                                                                  ;
;                                                                              ;
; Input: DS:(E)SI = Buffer of data to write to NVRam                           ;
;        ES:(E)DI = Seg/Offset of NVRam (caller passes in whatever is returned ;
;                   by the rtnvr_get_escd_size function)                       ;
;                                                                              ;
; Output: CF  = Set if error, cleared otherwise                                ;
;         AX = Non zero return code if CF set (see RT.EQU)                     ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
rthnvr_write	proc	near

;;stc				;These two lines may be added during 
;;ret				;development, so that it is possible to
				;boot the system without NVRam code.

	push	ecx
	push	esi
	push	edi

	mov	cx, cs:rth_nvram_size	;Get size defined in RTH.ASM
	mov	ax, RT_ESCD_INVALID	;Error code for no ESCD
	stc				;Set CF in case following jcxz jumps
	jcxz	write_nvram_done	;Br if no NVRam on this system

	push	bx
	push	cx
	push	si
	pushf
	xor	bl, bl			;BL will accumulate checksum
	mov	(nvr_header ptr [si]).nvrhd_nvram_checksum, bl
	cld
write_nvram_cksum:
	lodsb				;AL = next byte from caller's buffer
	add	bl, al
	loop	write_nvram_cksum
	popf
	pop	si
	pop	cx			;Update NVRam cksum in caller's buffer
	neg	bl
	mov	(nvr_header ptr [si]).nvrhd_nvram_checksum, bl
	pop	bx

	call	flash_write
	mov	ax, 0			;AX = Code for no error
	jnc	write_nvram_done	;Br if Flash written OK
	mov	ax, RT_ESCD_READ_ERROR

write_nvram_done:
	pop	edi
	pop	esi
	pop	ecx
	ret

rthnvr_write	endp


;---------------------------------------;
; flash_write                           ;
;---------------------------------------;--------------------------------------;
; This function erases and writes the NVRam contents in Flash from a buffer    ;
; supplied by the caller.                                                      ;
;                                                                              ;
; Input: DS:SI = Buffer of data to write to NVRam                              ;
;        ES:DI = Seg/Offset of NVRam (caller passes in whatever is returned    ;
;                by the rtnvr_get_escd_size function)                          ;
;           CX = Size of Flash block to write                                  ;
;                                                                              ;
; Output: CF  = Set if error, cleared otherwise                                ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
flash_write	proc	near
	pushad
	pushf				;Save state of IF
	cli
	pusha
	call	flash_write_enable	; enable write to flash
	popa
	push	es
	push	ds
	push	es
	push	ds
	pop	es			; ES:SI = source buffer
	pop	ds			; DS:DI = NVRAM storage
	call	check_flash_presence	; flash part found ?
	jc	flash_skip_write	; no flash part found
;  AX = start offset of NVRAM..
	add	di,ax			; DS:DI = ptr to byte in NVRAM

;---------------------------------------; 01/06/96
;  DS = ESCD Segment/Selector
;  input in (GS) to this routine contains the BIOS Segment/Selector.
;
;  Since this routine does not access NVRAM area below 4GB address,
;  use GS to access NVRAM area BECAUSE some test softwares (e.g. NVRAM.EXE,
;  NSP BIOSTEST.EXE, etc.) do not pass ESCD Segment/Selector (which should
;  be used to access NVRAM area) properly
	mov	ax,gs
	mov	ds,ax
	mov	ax,cs
	cmp	ax,0f000h
	jnz	x2			; protected mode
	mov	ax,0f000h
	mov	ds,ax
x2:
;---------------------------------------; 01/06/96

	mov	bx,cgroup:word ptr flash_found_table
	call	cs:word ptr [bx+2]	; erase
	jc	flash_skip_write	;Br if error erasing
	call	cs:word ptr [bx+4]	; program
flash_skip_write:
	pushf				;Save status of programming flash
	pusha
	call	flash_write_disable	; disable write to flash
	popa
	popf
	pop	ds
	pop	es
	jc	flash_write_error
	popf				;Restore state of IF
	clc				;Indicate success
flash_write_done:
	popad
	ret
flash_write_error:
	popf				;Restore state of IF
	stc				;Indicate failure
	jmp	short flash_write_done

flash_write	endp

;---------------------------------------;
;	CHECK_FLASH_PRESENCE		;
;  input :				;
;	none				;
;  output:				;
;	nc	flash present		;
;		ax  start offset of NVRAM
;	cy	flash not found		;
;  register destroyed : AX		;
;---------------------------------------;
check_flash_presence	proc	near
	mov	ax,cgroup:word ptr flash_found_table+2; start offset of NVRAM
	cmp	cgroup:word ptr flash_found_table,0ffffh
	cmc
	ret
check_flash_presence	endp
;---------------------------------------;
;*****************************************************************;
;*****************************************************************;
;**                                                             **;
;**      (C)Copyright 1985-1996, American Megatrends, Inc.      **;
;**                                                             **;
;**                     All Rights Reserved.                    **;
;**                                                             **;
;**           6145-F Northbelt Pkwy, Norcross, GA 30071         **;
;**                                                             **;
;**                     Phone (770)-246-8600                    **;
;**                                                             **;
;*****************************************************************;
;*****************************************************************;
_text	ends
end

⌨️ 快捷键说明

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