www.pudn.com > hpbios.rar > AM29F400.NVM


;	[]===========================================================[] 
; 
;	NOTICE: THIS PROGRAM BELONGS TO AWARD SOFTWARE INTERNATIONAL(R) 
;	        INC. IT IS CONSIDERED A TRADE SECRET AND IS NOT TO BE 	 
;	        DIVULGED OR USED BY PARTIES WHO HAVE NOT RECEIVED	 
;	        WRITTEN AUTHORIZATION FROM THE OWNER. 
; 
; 	[]===========================================================[] 
; 
 
;---------------------------------------------------------------------------- 
;Rev	Date	 Name	Description 
;---------------------------------------------------------------------------- 
;R02 	02/01/00  BAR	Added define post flash write use XDGROUP 
;R01 	07/20/99 BAR	Support  use SMI update flash ROM . 
;			Move all RXX . 
;R00	11/30/98 BAR	Initial Revision. 
;			Support AMD 29F400BT 4M flash. 
;**************************************************************** 
;*								* 
;*	SUBROUTINES TO SUPPORT AMD 4M TYPE FLASH ROM		* 
;*								* 
;**************************************************************** 
ifndef	Flash_IN_SMBASE		;R06 
;[]========================================================================[] 
; AM29F400BT_Flash_Erase : 
; 
;	Erase AM29F400BT PARAMETER BLOCK (FA000h - FBFFFh) 
; 
;Saves : None 
;Input : None 
; 
;Output: CF = 0 , Successful 
;	 CF = 1 , Error Erase 
; 
;[]========================================================================[] 
AM29F400BT_Flash_Erase	Proc	Near 
 
ifNdef	POST_FLASH_IN_XGROUP		;R02 
		push	di 
 
		mov     di, First_Address 
		mov     al, 0AAh		; 1st byte [0555] = AAh 
		mov	dx,offset Ct_Set_Flash  
		call	dx 
 
		mov     di, Second_Address 
		mov     al, 055h		; 2nd byte [0AAA] = 55h 
		mov	dx,offset Ct_Set_Flash 
		call	dx 
 
		mov     di, First_Address 
		mov     al, 80h			; 3rd byte [0555] = 80h 
		mov	dx,offset Ct_Set_Flash 
		call	dx 
 
		mov     di, First_Address 
		mov     al, 0AAh 		; 4th byte [0555] = AAh 
		mov	dx,offset Ct_Set_Flash 
		call	dx 
 
		mov     di, Second_Address 
		mov     al, 055h		; 5th byte [0AAA] = 55h 
		mov	dx,offset Ct_Set_Flash 
		call	dx 
 
		pop	di 
 
		mov     al, 30h			; 6th byte [0555] = 30h 
		mov	dx,offset Ct_Set_Flash 
		call	dx 
		mov	dx,offset EEPROM_Wait_10ms 
		call	dx 
ifdef	More_Flash_Wait_Time 
		mov	dx,offset EEPROM_Wait_10ms 
		call	dx 
		mov	dx,offset EEPROM_Wait_10ms 
		call	dx 
endif;	More_Flash_Wait_Time 
		pusha 
 
		mov	dx,offset Ct_Get_Flash 
		call	dx 
		mov	bh,al 
;R02 - starts 
else;	POST_FLASH_IN_XGROUP		 
		mov	byte ptr es:[First_Address], 0aah 
		mov	byte ptr es:[Second_Address], 055h 
		mov	byte ptr es:[First_Address], 080h 
		mov	byte ptr es:[First_Address], 0aah 
		mov	byte ptr es:[Second_Address], 055h 
		mov	byte ptr es:[di], 030h		;Erase command 
		push	cx 
ifNdef	More_Flash_Wait_Time 
		mov	cx, 350	 
endif;	More_Flash_Wait_Time 
		mov	cx, 350	*3 
endif;	More_Flash_Wait_Time 
		call	dx 
		pop	cx 
		pusha 
		mov	bh, byte ptr es:[di] 
 
endif;	POST_FLASH_IN_XGROUP		 
;R02 - ends 
 
AM29F400BT_Erase_Verify: 
ifNdef	POST_FLASH_IN_XGROUP		;R02 
		mov	dx,offset Ct_Get_Flash 
		call	dx 
;R02 - starts 
else;	POST_FLASH_IN_XGROUP		 
		mov	al, byte ptr es:[di] 
endif;	POST_FLASH_IN_XGROUP		 
;R02 - ends 
		mov	bl,bh 
		xor	bh,al 
		test	bh,40h 
		mov	bh,al 
		jz	short AM29F400BT_Erase_OK 
 
		test	bl,20h 
		jz	short AM29F400BT_Erase_Verify 
 
ifNdef	POST_FLASH_IN_XGROUP		;R02 
		mov	dx,offset Ct_Get_Flash 
		call	dx 
;R02 - starts 
else;	POST_FLASH_IN_XGROUP		 
		mov	al, byte ptr es:[di] 
endif;	POST_FLASH_IN_XGROUP		 
;R02 - ends 
		xor	bl,al 
		test	bl,40h 
		jz	short AM29F400BT_Erase_OK 
 
AM29F400BT_Erase_Fail: 
		stc 
		popa 
		ret 
 
AM29F400BT_Erase_OK: 
		cmp	al,0ffh 
		jne	short AM29F400BT_Erase_Fail 
		clc 
		popa 
		ret 
AM29F400BT_Flash_Erase	endp 
 
;[]====================================================================[] 
; AM29F400BT_Flash_Write : 
; 
;	Program AM29F400BT PARAMETER BLOCK 
; 
;Saves : 
;Input : Source	= DS : SI 
;	 Target	= ES : DI (Range = FA000h-FBFFFh) 
;	 Length	= CX 
; 
;Output: CF = 0 Successful 
;	 CF = 1	Error Program 
; 
;[]====================================================================[] 
AM29F400BT_Flash_Write	Proc	Near 
 
		pusha 
 
AM29F400BT_Prg_Next_Byte: 
		mov	bx,25				;Program Retry Count 
		mov	al,ds:[si]			;Read Data 
 
AM29F400BT_Verify_Retry: 
		call	AM29F400BT_Prg_Sequence 
ifNdef	POST_FLASH_IN_XGROUP		;R02 
		mov	dx,offset Ct_Set_Flash 
		call	dx 
;R02 - starts 
else;	POST_FLASH_IN_XGROUP		 
		mov	byte ptr es:[di], al 
endif;	POST_FLASH_IN_XGROUP		 
;R02 - ends 
		call	AM29F400BT_Check_Toggle_Ready 
 
		jc	short AM29F002NT_Toggle_error 
 
	;; Make Sure Program Correct 
ifNdef	POST_FLASH_IN_XGROUP		;R02 
		mov	dx,offset Ct_Get_Flash 
		call	dx 
;R02 - starts 
else;	POST_FLASH_IN_XGROUP		 
		mov	al, byte ptr es:[di] 
endif;	POST_FLASH_IN_XGROUP		 
;R02 - ends 
		cmp	al,ds:[si] 
		je	short AM29F400BT_Verify_OK 
AM29F002NT_Toggle_error: 
		dec	bx 
		jnz	short AM29F400BT_Verify_Retry 
 
		stc					;Set Program Fail 
		jmp	short AM29F400BT_Prog_Exit 
 
AM29F400BT_Verify_OK: 
		inc	si 
		inc	di 
		loop	AM29F400BT_Prg_Next_Byte 
		clc 
 
AM29F400BT_Prog_Exit: 
 
		popa 
		ret 
AM29F400BT_Flash_Write	Endp 
 
AM29F400BT_Prg_Sequence	proc	near 
ifNdef	POST_FLASH_IN_XGROUP		;R02 
		push	di 
		push	ax 
 
		mov     di, First_Address 
		mov	al,0aah 
		mov	dx,offset Ct_Set_Flash 
		call	dx 
 
		mov     di, Second_Address 
		mov	al,55h 
		mov	dx,offset Ct_Set_Flash 
		call	dx 
 
		mov     di, First_Address 
		mov	al,0a0h 
		mov	dx,offset Ct_Set_Flash 
		call	dx 
 
		pop	ax 
		pop	di 
;R02 - starts 
else;	POST_FLASH_IN_XGROUP		 
		mov	byte ptr es:[First_Address], 0aah 
		mov	byte ptr es:[Second_Address], 055h 
		mov	byte ptr es:[First_Address], 0a0h 
endif;	POST_FLASH_IN_XGROUP		 
;R02 - ends 
		ret 
AM29F400BT_Prg_Sequence	endp 
 
AM29F400BT_Check_Toggle_Ready	proc	near 
ifNdef	POST_FLASH_IN_XGROUP		;R02 
		clc 
		push	ax 
		push	bx 
AM29F400BT_CTR_TOG1: 
		mov	dx,offset Ct_Get_Flash 
		call	dx 
		mov	ah,ds:[si]			;Read Source Bit once 
		and	ax,8080h 
		cmp	al,ah 
		je	short AM29F400BT_CTR_TOG3 
 
AM29F400BT_CTR_TOG2: 
		mov	bl,ah 
		mov	dx,offset Ct_Get_Flash 
		call	dx 
		and	al,0a0h 
		test	al,20h 
		jz	short AM29F400BT_CTR_TOG1 
		and	al,80h 
		cmp	al,bl 
		je	short AM29F400BT_CTR_TOG3 
		stc 
AM29F400BT_CTR_TOG3: 
		pop	bx 
		pop	ax 
		ret 
;R02 - starts 
else;	POST_FLASH_IN_XGROUP		 
Toggle_Bit	=	01000000b 
		push	cx 
		push	bx 
		mov	ah, byte ptr es:[di] 
		mov	bx,1000 
Ststus_Read_Loop:   
		xor	cx,cx		 
Ststus_Read_Loop_1: 
		mov	al, byte ptr es:[di] 
		xor	ah,al 
		test	ah,Toggle_Bit 
		jz	short Toggle_End 
		mov	ah,al 
		loop	Ststus_Read_Loop_1 
		dec	bx 
		jnz	Ststus_Read_Loop 
		stc				;Time out 
		pop	bx 
		pop	cx 
		ret 
Toggle_End: 
		clc 				;Toggle end 
		pop	bx 
		pop	cx 
		ret 
endif;	POST_FLASH_IN_XGROUP		 
;R02 - ends 
 
AM29F400BT_Check_Toggle_Ready	endp 
else;	Flash_IN_SMBASE 
;[]========================================================================[] 
; AM29F400BT_Flash_Erase : 
; 
;	Erase AM29F400BT PARAMETER BLOCK (FA000h - FBFFFh) 
; 
;Saves : None 
;Input : None 
; 
;Output: CF = 0 , Successful 
;	 CF = 1 , Error Erase 
; 
;[]========================================================================[] 
AM29F400BT_Flash_Erase	Proc	Near 
;R01 - start	 
		push	esi	 
		push	edi 
		mov	esi,0FFFF0000H + First_Address 
		mov	edi,0FFFF0000H + Second_Address 
		mov	byte ptr es:[esi],0AAh 
		mov	byte ptr es:[edi],055h 
		mov	byte ptr es:[esi],080h 
		mov	byte ptr es:[esi],0AAh 
		mov	byte ptr es:[edi],055h 
		pop	edi 
		pop	esi	 
;R01 - end		 
;R01 
;R01		push	edi 
;R01		and	edi,0ffff0000h 
;R01		mov	byte ptr es:[edi + First_Address], 0AAH 
;R01		mov	byte ptr es:[edi + Second_Address], 055H 
;R01		mov	byte ptr es:[edi + First_Address], 080H 
;R01		mov	byte ptr es:[edi + First_Address], 0AAH 
;R01		mov	byte ptr es:[edi + Second_Address], 055H 
;R01		pop	edi 
		mov	byte ptr es:[edi], 030H 
		push	cx 
ifdef	More_Flash_Wait_Time 
		mov	cx,350 * 3		 
else;	More_Flash_Wait_Time 
		mov	cx,350	 
endif;	More_Flash_Wait_Time 
		call	dx		;delay time = (30ns)* cx =10.5ms 
		pop	cx 
 
		pusha 
 		mov	al,byte ptr es:[edi] 
		mov	bh,al 
AM29F400BT_Erase_Verify: 
 		mov	al,byte ptr es:[edi] 
		mov	bl,bh 
		xor	bh,al 
		test	bh,40h 
		mov	bh,al 
		jz	short AM29F400BT_Erase_OK 
 
		test	bl,20h 
		jz	short AM29F400BT_Erase_Verify 
 
 		mov	al,byte ptr es:[edi] 
		xor	bl,al 
		test	bl,40h 
		jz	short AM29F400BT_Erase_OK 
 
AM29F400BT_Erase_Fail: 
		stc 
		popa 
		ret 
 
AM29F400BT_Erase_OK: 
		cmp	al,0ffh 
		jne	short AM29F400BT_Erase_Fail 
		clc 
		popa 
		ret 
AM29F400BT_Flash_Erase	endp 
 
;[]====================================================================[] 
; AM29F400BT_Flash_Write : 
; 
;	Program AM29F400BT PARAMETER BLOCK 
; 
;Saves : 
;Input : Source	= DS : SI 
;	 Target	= ES : DI (Range = FA000h-FBFFFh) 
;	 Length	= CX 
; 
;Output: CF = 0 Successful 
;	 CF = 1	Error Program 
; 
;[]====================================================================[] 
AM29F400BT_Flash_Write	Proc	Near 
 
		pusha 
 
AM29F400BT_Prg_Next_Byte: 
		mov	bx,25				;Program Retry Count 
		mov	al,ds:[esi]			;Read Data 
 
AM29F400BT_Verify_Retry: 
		call	AM29F400BT_Prg_Sequence 
 		mov	byte ptr es:[edi],al 
		call	AM29F400BT_Check_Toggle_Ready 
 
		jc	short AM29F002NT_Toggle_error 
 
	;; Make Sure Program Correct 
 		mov	al,byte ptr es:[edi] 
		cmp	al, ds:[esi] 
		je	short AM29F400BT_Verify_OK 
AM29F002NT_Toggle_error: 
		dec	bx 
		jnz	short AM29F400BT_Verify_Retry 
 
		stc					;Set Program Fail 
		jmp	short AM29F400BT_Prog_Exit 
 
AM29F400BT_Verify_OK: 
		inc	si 
		inc	di 
		loop	AM29F400BT_Prg_Next_Byte 
		clc 
 
AM29F400BT_Prog_Exit: 
 
		popa 
		ret 
AM29F400BT_Flash_Write	Endp 
 
AM29F400BT_Prg_Sequence	proc	near 
;R01 - start	 
		push	esi	 
		push	edi 
		mov	esi,0FFFF0000H + First_Address 
		mov	edi,0FFFF0000H + Second_Address 
		mov	byte ptr es:[esi],0AAh 
		mov	byte ptr es:[edi],055h 
		mov	byte ptr es:[esi],0A0h 
		pop	edi 
		pop	esi	 
;R01 - end		 
;R01		push	edi 
;R01		and	edi,0ffff0000h 
;R01		mov	byte ptr es:[edi + First_Address], 0AAH 
;R01		mov	byte ptr es:[edi + Second_Address], 055H 
;R01		mov	byte ptr es:[edi + First_Address], 0A0H 
;R01		pop	edi 
		ret 
AM29F400BT_Prg_Sequence	endp 
 
AM29F400BT_Check_Toggle_Ready	proc	near 
		clc 
		push	ax 
		push	bx 
AM29F400BT_CTR_TOG1: 
 		mov	al,byte ptr es:[edi] 
		mov	ah,ds:[esi]			;Read Source Bit once 
		and	ax,8080h 
		cmp	al,ah 
		je	short AM29F400BT_CTR_TOG3 
 
AM29F400BT_CTR_TOG2: 
  
		mov	bl,ah 
 		mov	al,byte ptr es:[edi] 
		and	al,0a0h 
		test	al,20h 
		jz	short AM29F400BT_CTR_TOG1 
		and	al,80h 
		cmp	al,bl 
		je	short AM29F400BT_CTR_TOG3 
		stc 
AM29F400BT_CTR_TOG3: 
		pop	bx 
		pop	ax 
		ret 
AM29F400BT_Check_Toggle_Ready	endp 
 
endif;	Flash_IN_SMBASE