📄 nvram.asm
字号:
;**************************************************************************
;*
;* NVRAM.ASM
;*
;* Copyright (c) 1999 National Semiconductor Corporation.
;* All Rights Reserved.
;*
;* Function:
;* nvram definitions
;*
;* $Revision: 2 $
;*
;**************************************************************************
;.MODEL TINY
.486
INCLUDE MACROS.INC
INCLUDE DEF.INC
INCLUDE OPTIONS.INC
INCLUDE BDCFG.INC
INCLUDE NVRAMTOK.INC
_TEXT SEGMENT PUBLIC use16 'CODE'
;*******************
;* Media Structure *
;*******************
NVRAM_MEDIA_STRUCT struct 1
NVRAM_MEDIA db ? ; the media type
NVRAM_CHECK dw ? ; Stackless proc. to check existance of media type
NVRAM_START dw ? ; Value to add to nvram offset to get to the
; beginning location (in BYTES)
NVRAM_MAX_LOC dw ? ; maximum offset in BYTES when added to NVRAM_START
NVRAM_READ dw ? ; Stackless Routine to read from nvram type
NVRAM_WRITE dw ? ; StacklessRoutine to write to nvram type
NVRAM_MEDIA_STRUCT ENDS
;*****************
;* Map Structure *
;*****************
NVRAM_MAP_STRUCT struct 1
NVRAM_T_MEDIA db ? ; media it is in
NVRAM_TOKEN dw ? ; the token
NVRAM_BYTE_ADDR dw ? ; byte containing token
NVRAM_WIDTH db ? ; value of 1-8 - number of bits used by the token
; Bit 4 reserved
; Bit 5 reserved
; Bit 6 reserved
; Bit 7 flag set on if token spans 2 bytes
NVRAM_MASK dw ? ; Mask to AND with memory to isolate token
NVRAM_SHIFT db ? ; Number of bits to shift to normalize
; token value
NVRAM_DEFAULT db ? ; default value if nvram is invalid
NVRAM_MAP_STRUCT ENDS
; checksum token
NVRAM_CHECKSUM = 0ffffh
NVRAM_CHECKSUM_WIDTH = 8
NVRAM_FILL = 0fffeh
IN_MEDIA_CMOS MACRO
CURRENT_MEDIA TEXTEQU <CMOS>
MEDIA_CMOS_USED = 1
ENDM
IN_MEDIA_SEEP MACRO
CURRENT_MEDIA TEXTEQU <SEEP>
MEDIA_SEEP_USED = 1
ENDM
IN_MEDIA_FLASH MACRO
CURRENT_MEDIA TEXTEQU <FLASH>
MEDIA_FLASH_USED = 1
ENDM
IN_MEDIA MACRO media_type
IN_MEDIA_&media_type
MEDIA_&media_type&_USED = 0
ENDM
NVRAM_MAP_INIT MACRO
;**************************************************************
; make pulic the beinning of the table
;**************************************************************
public NVRAM_MAP
NVRAM_MAP LABEL BYTE
;**************************************************************
; init bit address and number of tokens defined
;**************************************************************
; bit address of 1st token for each media
CMOS_TOKEN_ADDRESS = 0
FLASH_TOKEN_ADDRESS = 0
SEEP_TOKEN_ADDRESS = 0
; number of tokes processed
NUMBER_TOKENS = 0
MEDIA_CMOS_USED = 0
MEDIA_FLASH_USED = 0
MEDIA_SEEP_USED = 0
if MEDIA_DEFAULT EQ MEDIA_CMOS
IN_MEDIA CMOS
elseif MEDIA_DEFAULT equ MEDIA_FLASH
IN_MEDIA FLASH
elseif MEDIA_DEFAULT EQ MEDIA_SEEP
IN_MEDIA SEEP
else
.ERR <Invalid Default Media %MEDIA_DEFAULT>
EXITM
ENDIF
ENDM
NVRAM_MAP_END_2 MACRO media
IF (MEDIA_&media&_USED EQ 0)
EXITM
ENDIF
;**************************************************************
; close out token table
; 1st pad out to byte boundary
;**************************************************************
IN_MEDIA_&media&
if ((&media&_TOKEN_ADDRESS mod 8) NE 0)
FILL_LENGTH = 8-(&media&_TOKEN_ADDRESS mod 8)
; need padding
DEFINE_NVRAM_MAP NVRAM_FILL,FILL_LENGTH,0
ENDIF
;**************************************************************
; add checksum entry
;**************************************************************
DEFINE_NVRAM_MAP NVRAM_CHECKSUM,NVRAM_CHECKSUM_WIDTH,0
ENDM
NVRAM_MAP_END MACRO
;**************************************************************
; finish out checksums
;**************************************************************
NVRAM_MAP_END_2 CMOS
NVRAM_MAP_END_2 FLASH
NVRAM_MAP_END_2 SEEP
;**************************************************************
; declare length of token table
;**************************************************************
NVRAM_MAP_LENGTH equ NUMBER_TOKENS
public NVRAM_MAP_LENGTH
ENDM
DEFINE_NVRAM_MAP MACRO token:REQ,tok_size:REQ,def_value:=<0>
DEFINE_NVRAM_MAP_2 token,tok_size,def_value,%CURRENT_MEDIA
ENDM
DEFINE_NVRAM_MAP_2 MACRO token:REQ,tok_size:REQ,def_value,media
;**************************************************************
; Define the token table entry
;**************************************************************
If (((tok_size) EQ 0) or ((tok_size) GT 8))
.ERR <DEFINE_TOKEN: Width must be between 1 and 8 bits>
EXITM
ENDIF
TOKEN_FLAGS = 0
TOKEN_BYTE_ADDR = &media&_TOKEN_ADDRESS / 8
TOKEN_SHIFT = &media&_TOKEN_ADDRESS mod 8
;**************************************************************
; flag if spans two bytes
;**************************************************************
IF ((TOKEN_SHIFT + tok_size) GT 8)
TOKEN_FLAGS = 080h
ENDIF
TOKEN_MASK = ((NOT (0000ffffh SHL (tok_size))) AND 0000ffffh)
TOKEN_MASK = TOKEN_MASK SHL TOKEN_SHIFT
TOK_S = (tok_size or TOKEN_FLAGS)
OFFSET_&token = TOKEN_BYTE_ADDR
PUBLIC OFFSET_&token
MASK_&token = TOKEN_MASK
PUBLIC MASK_&token
SHIFT_&token = TOKEN_SHIFT
public SHIFT_&token
% DEF_MAP_STRUCT &media,token,%TOKEN_BYTE_ADDR,%TOK_S,%TOKEN_MASK,%TOKEN_SHIFT,%def_value
NUMBER_TOKENS = NUMBER_TOKENS + 1
if TOKEN_BYTE_ADDR GT &MEDIA&_size
.ERR <Size of &media exceeded>
EXITM
ENDIF
&media&_TOKEN_ADDRESS = &media&_TOKEN_ADDRESS + tok_size
ENDM
DEF_MAP_STRUCT MACRO media,token,tba,tsize,tmask,tshift,def_value
NVRAM_MAP_STRUCT <MEDIA_&media,token,tba,tsize,tmask,tshift,def_value>
ENDM
NV_MEDIA macro mname:req,mcode:req,mstart:req,mend:req,mcheck:req,mread:req,mwrite:req
NVRAM_MEDIA_STRUCT <mcode, OFFSET mcheck, mstart, mend, OFFSET mread, OFFSET mwrite>
&mname&_size = ((mend-mstart) + 1)
endm
;*******************
;* Media Structure *
;*******************
PUBLIC NVRAM_MEDIA
PUBLIC NVRAM_MEDIA_LENGTH
;********************************************************************
; include the nvram entry definitions
;********************************************************************
include nvram.inc
CheckCmosBX PROC NEAR PUBLIC
CheckCmosBX ENDP
CheckFlashBX PROC NEAR PUBLIC
CheckFlashBX ENDP
CheckSEEPBX PROC NEAR PUBLIC
lahf
or ah, FLAGS_CF ; clear carry flag
and ah, FLAGS_ZF ; set zero flag
sahf
jmp bx
CheckSEEPBX ENDP
StubBX PROC NEAR PUBLIC
StubBX ENDP
ReadCmosBX PROC NEAR PUBLIC
ReadCmosBX ENDP
WriteCmosBX PROC NEAR PUBLIC
WriteCmosBX ENDP
ReadSEEPBX PROC NEAR PUBLIC
ReadSEEPBX ENDP
WriteSEEPBX PROC NEAR PUBLIC
WriteSEEPBX ENDP
ReadFlashBX PROC NEAR PUBLIC
ReadFlashBX ENDP
WriteFlashBX PROC NEAR PUBLIC
jmp bx
WriteFlashBX ENDP
;**************************************************************************
;*
;* NVRAMGetDefault
;*
;* Entry:
;* CX = token
;* DH = media:
;* Exit:
;* DL = value read
;* CF=0 success
;* CF=1 failure
;* Error Codes in DL:
;* 00 = reserved
;* 01 = token not supported
;* 02 = sw support not present
;* 03 = hw support not present
;* 04 = invalid media specified
;* 05 = token not valid in this media
;*
;* Destroys:
;*
;*
;**************************************************************************
NVRAMGetDefault PROC NEAR USES SI
Call GetToken ; Entry: CX = token, dh=media
;Exit: SI pointer to token table entry
; DH updated to correct media
jc NVRAMGetDefaultBad
mov dl,cs:[si].NVRAM_MAP_STRUCT.NVRAM_DEFAULT
GetDefaultDone:
clc
jmp NVRAMGetDefaultDone
NVRAMGetDefaultBad:
stc
NVRAMGetDefaultDone:
ret
NVRAMGetDefault ENDP
;**************************************************************************
;*
;* GetToken
;*
;* Entry:
;* CX = token
;* DH = Media
;* Exit:
;* SI=pointer to NVRAM_MAP entry for token
;* DI=pointer to media table entry
;* DH = Actual Media used
;* CF=0 success
;* CF=1 failure
;* DL = error code if any
;* Destroys:
;*
;**************************************************************************
GetToken proc near uses CX AX
mov ax, cx ;put our token in ax
lea si, cs:NVRAM_MAP
mov cx, NVRAM_MAP_LENGTH
TokenLoop: ; loop looking for our token
cmp ax, WORD PTR cs:(NVRAM_MAP_STRUCT PTR [si]).NVRAM_TOKEN
jne NextToken
je TokenGood ; yes - ok
NextToken:
add si, size NVRAM_MAP_STRUCT ; advance to next token
loop TokenLoop
TokenBad: ; if we didn't find our token in the table, exit
mov dl, 01h ;invalid token not supported
stc
jmp GetTokenDone
TokenGood: ; found our token
;if media_any then need to lookup an check media
mov dh,BYTE PTR cs:[si].NVRAM_MAP_STRUCT.NVRAM_T_MEDIA ; media used
MediaGood:
clc
GetTokenDone:
ret
GetToken endp
ClearFailedBoot proc
ret
ClearFailedBoot endp
;****** All Rights Reserved. ****************************************
;
; Function: GetNVRAMValue
;
; Summary: Gets a value from CMOS, Flash of Seep
; gets the value from whichever one has it
;
; Entry:
; CX - Token to find
;
; Exit:
; CX & DX - preserved
; AL - Value from NVRAM or Default
; CY = 0 ok
; CY = 1 error (ah contains error code)
;
; Destroys:
;
;
; Notes:
;
; Author: Staff Date: 07/21/2000
;
; Revisions:
;
;********************************************************************
GetNVRAMValue PROC NEAR uses dx cx
; bad get get default
call NVRAMGetDefault ; get the default value
jnc value_good ; got good default
value_bad:
mov ah,dl ; set error code
mov al,0 ; return a 0 for value
stc ; set carry for error
jmp short done_value
value_good:
mov ah,0 ; no error
mov al,dl ; get value to al
clc ; no error
done_value:
ret
GetNVRAMValue endp
;****** All Rights Reserved. ****************************************
;
; Function: TranslateNVRAMValue
;
; Summary: take a token and the value from NVRAM
; and translate it to something usable
;
; Entry:
; CX - token
; AL - Value from NVRAM
; SI - Address of translate table
;
; Exit:
; EAX - 32-bit translated value
; CY - 0 - Good
; CY = 1 - Not found - AL not changed
; bits 8-31 of eax are cleared
;
; Destroys:
;
; Notes:
;
; Author: Staff Date: 07/25/2000
;
; Revisions:
;
;********************************************************************
TranslateNVRAMValue PROC near uses cx dx si
; mov si,offset cs:NVRAMTransTable ; point to table
tloop:
cmp cs:[si].NVRAMTransStruct.token,0 ; end of table?
je notfound ; yes - not found
mediaok:
cmp cx,cs:[si].NVRAMTransStruct.token ; same token?
jne next_entry ; not same token
; check if value matches
cmp al,cs:[si].NVRAMTransStruct.NValue ; this value?
jne next_entry ; nope
; found it - return value in eax
mov eax,cs:[si].NVRAMTransStruct.TRvalue
clc ; no error
jmp short transdone ; exit
; point to next entry
next_entry:
add si,size NVRAMTransStruct ; point to next
jmp short tloop ; go check
notfound:
and eax,000000ffh ; preserve al
stc ; error
transdone:
ret
TranslateNVRAMValue endp
;****** All Rights Reserved. ****************************************
;
; Function: GetTransNVRAM
;
; Summary: combines the two above into one call
; gets a value from NVRAM and translates it
;
; Entry:
; CX - token to get
; SI - address of translate table to use
;
; Exit:
; EAX - return value (translated if possible)
; cy - if set error from GetNVRAMValue (AH has error code)
;
; Destroys:
;
; Notes:
;
; Author: Staff Date: 07/25/2000
;
; Revisions:
;
;********************************************************************
GetTransNVRAM proc near uses cx si
call GetNVRAMValue ; get the value
jc gtdone ; exit if error
; got the value - translate if if possible
call TranslateNVRAMValue ; translate
clc ; clear carry - show no error
gtdone:
ret
GetTransNVRAM endp
_TEXT ENDS
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -