Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions XTIDE_Universal_BIOS_Configurator_v2/Inc/Variables.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
%define VARIABLES_INC

; Equates and defines
BOOT_MENU_DEFAULT_TIMEOUT EQU (TICKS_PER_MINUTE / 2)
MAX_ALLOWED_IDE_CONTROLLERS EQU 4 ; Maximum number of IDE controllers
MAX_LITE_MODE_CONTROLLERS EQU 2
EEPROM_POLLING_TIMEOUT_TICKS EQU 3 ; 1 tick = 54.9 ms
XTIDE_SIGNATURE_LENGTH EQU 6 ; XTIDE Universal BIOS signature string length (must be even)
NUMBER_OF_EEPROM_TYPES EQU 5
MAX_EEPROM_SIZE_IN_BYTES EQU 65536

BOOT_MENU_DEFAULT_TIMEOUT EQU (TICKS_PER_MINUTE / 2)
MAX_ALLOWED_IDE_CONTROLLERS EQU 4 ; Maximum number of IDE controllers
MAX_LITE_MODE_CONTROLLERS EQU 2
EEPROM_POLLING_TIMEOUT_TICKS EQU 3 ; 1 tick = 54.9 ms
XTIDE_SIGNATURE_LENGTH EQU 6 ; XTIDE Universal BIOS signature string length (must be even)
NUMBER_OF_EEPROM_TYPES EQU 5
MAX_EEPROM_SIZE_IN_BYTES EQU 65536
SST_PAGE_SIZE_SHIFT EQU 12 ; Minimum we can erase is a 4K sector.
SST_PAGE_SIZE EQU (1 << SST_PAGE_SIZE_SHIFT)

; Program global variables
struc CFGVARS
Expand Down Expand Up @@ -56,6 +57,7 @@ struc EEPROM_TYPE
.2864_8kiB_MOD resb 2 ; Reversed A0 and A3 address lines
.28256_32kiB resb 2
.28512_64kiB resb 2
.SST_39SF resb 2
endstruc

; Software Data Protection commands
Expand Down Expand Up @@ -95,7 +97,7 @@ struc FLASHVARS
.bEepromType resb 1

.wProgressUpdateParam resb 2
.wTimeoutCounter resb 2
.wTimeoutCounter resb 2 ; On SSI, this is timeout cal
.wLastOffsetWritten resb 2
.bLastByteWritten resb 1
.flashResult resb 1
Expand All @@ -104,6 +106,7 @@ endstruc
; Flashing results
struc FLASH_RESULT
.success resb 2
.DeviceNotDetected resb 2
.PollingTimeoutError resb 2
.DataVerifyError resb 2
endstruc
Expand Down
27 changes: 24 additions & 3 deletions XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ ALIGN JUMP_ALIGN
.NothingToSave:
ret

;--------------------------------------------------------------------
; Buffers_GetSelectedEepromSizeInWordsToAX
; Parameters:
; Nothing
; Returns:
; AX: Selected EEPROM size in WORDs
; Corrupts registers:
; BX
;--------------------------------------------------------------------
ALIGN JUMP_ALIGN
Buffers_GetSelectedEepromSizeInWordsToAX:
eMOVZX bx, [cs:g_cfgVars+CFGVARS.bEepromType]
mov ax, [cs:bx+g_rgwEepromTypeToSizeInWords]

cmp bl, EEPROM_TYPE.SST_39SF
jnz SHORT .HaveEepromSize
cmp ax, [cs:g_cfgVars+CFGVARS.wImageSizeInWords]
jae SHORT .HaveEepromSize
shl ax, 1 ; Auto-double SST size when too small.
.HaveEepromSize:
ret

;--------------------------------------------------------------------
; Buffers_AppendZeroesIfNeeded
Expand All @@ -180,14 +201,14 @@ ALIGN JUMP_ALIGN
; Returns:
; Nothing
; Corrupts registers:
; AX, CX, DI
; AX, BX, CX, DI
;--------------------------------------------------------------------
ALIGN JUMP_ALIGN
Buffers_AppendZeroesIfNeeded:
push es

eMOVZX di, [cs:g_cfgVars+CFGVARS.bEepromType]
mov cx, [cs:di+g_rgwEepromTypeToSizeInWords]
call Buffers_GetSelectedEepromSizeInWordsToAX
mov cx, ax
sub cx, [cs:g_cfgVars+CFGVARS.wImageSizeInWords] ; CX = WORDs to append
jbe SHORT .NoNeedToAppendZeroes

Expand Down
3 changes: 3 additions & 0 deletions XTIDE_Universal_BIOS_Configurator_v2/Src/EEPROM.asm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ g_rgwEepromTypeToSizeInWords:
dw (8<<10) / 2 ; EEPROM_TYPE.2864_8kiB_MOD
dw (32<<10) / 2
dw (64<<10) / 2
dw (32<<10) / 2 ; EEPROM_TYPE.SST_39SF
; Actual size of flash will be larger than 32K,
; however most (all?) XUB devices map a 32K window.

g_rgwEepromPageToSizeInBytes:
dw 1 ; EEPROM_PAGE.1_byte
Expand Down
3 changes: 3 additions & 0 deletions XTIDE_Universal_BIOS_Configurator_v2/Src/Flash.asm
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,21 @@ ALIGN WORD_ALIGN
dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.2864_8kiB_MOD
dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.28256_32kiB
dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.28512_64kiB
dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.SST_39SF
.rgfnEnableSdpAndFlash: ; SDP_COMMAND.enable
dw WriteSdpEnableCommandFor2816 ; EEPROM_TYPE.2816_2kiB
dw WriteSdpEnableCommandFor2864 ; EEPROM_TYPE.2864_8kiB
dw WriteSdpEnableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD
dw WriteSdpEnableCommandFor28256or28512 ; EEPROM_TYPE.28256_32kiB
dw WriteSdpEnableCommandFor28256or28512 ; EEPROM_TYPE.28512_64kiB
dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.SST_39SF
.rgfnDisableSdpAndFlash: ; SDP_COMMAND.disable
dw WriteSdpDisableCommandFor2816 ; EEPROM_TYPE.2816_2kiB
dw WriteSdpDisableCommandFor2864 ; EEPROM_TYPE.2864_8kiB
dw WriteSdpDisableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD
dw WriteSdpDisableCommandFor28256or28512 ; EEPROM_TYPE.28256_32kiB
dw WriteSdpDisableCommandFor28256or28512 ; EEPROM_TYPE.28512_64kiB
dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.SST_39SF


;--------------------------------------------------------------------
Expand Down
268 changes: 268 additions & 0 deletions XTIDE_Universal_BIOS_Configurator_v2/Src/FlashSST.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
; Project name : XTIDE Universal BIOS Configurator v2
; Description : Functions for flashing SST flash devices.

;
; Created by Jayeson Lee-Steere
; Hereby placed into the public domain.
;

; Section containing code
SECTION .text

;--------------------------------------------------------------------
; FlashSst_WithFlashvarsInDSSI
; Parameters:
; DS:BX: Ptr to FLASHVARS
; Returns:
; Updated FLASHVARS in DS:BX
; Corrupts registers:
; AX, DX, DI
;--------------------------------------------------------------------
ALIGN JUMP_ALIGN
FlashSst_WithFlashvarsInDSBX:
push ds
push es
push bx
push cx
push si
push bp
mov bp, bx ; Flashvars now in SS:BP.

mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.DeviceNotDetected
call DetectSstDevice
jc SHORT .ExitOnError

call CalibrateSstTimeout

mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.PollingTimeoutError
mov cx, [bp+FLASHVARS.wPagesToFlash]
lds si, [bp+FLASHVARS.fpNextSourcePage]
les di, [bp+FLASHVARS.fpNextDestinationPage]
%ifdef CLD_NEEDED
cld
%endif

ALIGN JUMP_ALIGN
.NextPage:
; See if this page needs updating.
push si
push di
push cx
mov cx, [bp+FLASHVARS.wEepromPageSize]
mov bx, cx
repe cmpsb
pop cx
pop di
pop si
jnz SHORT .FlashThisPage
add si, bx
add di, bx
jmp SHORT .ContinueLoop

.FlashThisPage:
call EraseSstPage
jc SHORT .ExitOnError
call WriteSstPage
jc SHORT .ExitOnError
.ContinueLoop:
loop .NextPage

; The write process has already confirmed the results one byte at a time.
; Here we do an additional verify check just in case there was some
; kind of oddity with pages / addresses.
mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.DataVerifyError
mov ax, [bp+FLASHVARS.wPagesToFlash]
mov cl, SST_PAGE_SIZE_SHIFT
shl ax, cl
mov cx, ax
lds si, [bp+FLASHVARS.fpNextSourcePage]
les di, [bp+FLASHVARS.fpNextDestinationPage]
repe cmpsb
jnz SHORT .ExitOnError

%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
%if FLASH_RESULT.success = 0 ; Just in case this should ever change
mov [bp+FLASHVARS.flashResult], cl
%else
mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.success
%endif
%endif
ALIGN JUMP_ALIGN
.ExitOnError:
pop bp
pop si
pop cx
pop bx
pop es
pop ds
ret

;--------------------------------------------------------------------
; DetectSstDevice
; Parameters:
; SS:BP: Ptr to FLASHVARS
; Returns:
; CF: Clear if supported SST device found
; Set if supported SST device not found
; Corrupts registers:
; AX, DI, ES
;--------------------------------------------------------------------
ALIGN JUMP_ALIGN
DetectSstDevice:
les di, [bp+FLASHVARS.fpNextDestinationPage]

cli
mov BYTE [es:05555h], 0AAh ; Enter software ID sequence.
mov BYTE [es:02AAAh], 055h
mov BYTE [es:05555h], 090h
mov al, [es:di] ; Extra reads to be sure device
mov al, [es:di] ; has time to respond.
mov al, [es:di]
mov ah, [es:di] ; Vendor ID in AH.
mov al, [es:di + 1] ; Device ID in AL.
mov BYTE [es:05555h], 0F0h ; Exit software ID.
sti

cmp al, 0B4h
jb SHORT .NotValidDevice
cmp al, 0B7h
ja SHORT .NotValidDevice
cmp ah, 0BFh
jne SHORT .NotValidDevice
ret

.NotValidDevice:
stc
ret

;--------------------------------------------------------------------
; CalibrateSstTimeout
; Parameters:
; SS:BP: Ptr to FLASHVARS
; Returns:
; FLASHVARS.wTimeoutCounter
; Corrupts registers:
; AX, BX, CX, SI, DI, DS, ES
;--------------------------------------------------------------------
ALIGN JUMP_ALIGN
CalibrateSstTimeout:
LOAD_BDA_SEGMENT_TO ds, ax
les di, [bp+FLASHVARS.fpNextDestinationPage]
xor cx, cx
mov si, cx
mov di, cx
mov al, [es:di]
not al ; Forces poll to fail.

mov bx, [BDA.dwTimerTicks] ; Read low word only.
inc bx
.WaitForFirstIncrement:
cmp bx, [BDA.dwTimerTicks]
jnz SHORT .WaitForFirstIncrement

inc bx

.WaitForSecondIncrement:
inc ch ; cx now 0x0100
.PollLoop: ; Identical to poll loop used
cmp [es:di], al ; during programming
jz SHORT .PollComplete ; Will never branch in this case
loop .PollLoop
.PollComplete:
add si, 1 ; number of poll loops completed
jc SHORT .countOverflow
cmp bx, [BDA.dwTimerTicks]
jnz SHORT .WaitForSecondIncrement

.CalComplete:
; SI ~= number of polling loops in 215us.
mov [bp+FLASHVARS.wTimeoutCounter], si
ret

.countOverflow:
; Clamp on overflow, although it should not be possible on
; real hardware. In principle SI could overflow on a very
; fast CPU. However the SST device is on a slow bus. Even
; running at the min read cycle time of fastest version of
; the device, SI can not overflow.
dec si
jmp SHORT .CalComplete

;--------------------------------------------------------------------
; EraseSstPage
; Parameters:
; ES:DI: Destination ptr.
; Returns:
; CF: Set on error.
; Corrupts registers:
; AX
;--------------------------------------------------------------------
ALIGN JUMP_ALIGN
EraseSstPage:
push cx

mov BYTE [es:05555h], 0AAh ; Sector erase sequence.
mov BYTE [es:02AAAh], 055h
mov BYTE [es:05555h], 080h
mov BYTE [es:05555h], 0AAh
mov BYTE [es:02AAAh], 055h
mov BYTE [es:di], 030h

mov ax, 1163 ; 1163 x ~215us = 250ms = 10x datasheet max
.TimeoutOuterLoop:
mov cx, [bp+FLASHVARS.wTimeoutCounter]
.TimeoutInnerLoop:
cmp BYTE [es:di], 0FFh ; Will return 0FFh when erase complete.
jz SHORT .Exit
loop .TimeoutInnerLoop
dec ax
jnz SHORT .TimeoutOuterLoop
stc ; Timed out.
.Exit:
pop cx
ret

;--------------------------------------------------------------------
; WriteSstPage
; Parameters:
; DS:SI: Source ptr.
; ES:DI: Destination ptr.
; Returns:
; SI, DI: Each advanced forward 1 page.
; CF: Set on error.
; Corrupts registers:
; AL, BX, DX
;--------------------------------------------------------------------
ALIGN JUMP_ALIGN
WriteSstPage:
push cx

mov bx, [bp+FLASHVARS.wTimeoutCounter]
mov dx, [bp+FLASHVARS.wEepromPageSize]
cli

.NextByte:
lodsb
mov BYTE [es:05555h], 0AAh ; Byte program sequence.
mov BYTE [es:02AAAh], 055h
mov BYTE [es:05555h], 0A0h
mov [es:di], al

mov cx, bx
.WaitLoop:
cmp [es:di], al ; Device won't return actual data until
jz SHORT .ByteFinished ; write complete. Timeout ~215us, or
loop .WaitLoop ; ~10x 20us max program time from datasheet.

stc ; Write timeout.
jmp SHORT .Exit

.ByteFinished:
inc di
dec dx
jnz SHORT .NextByte
clc
.Exit:
sti
pop cx
ret
Loading