[65] | 1 | ; Project name : XTIDE Universal BIOS Configurator v2
|
---|
| 2 | ; Description : Functions for flashing the EEPROM.
|
---|
| 3 |
|
---|
| 4 | ; Section containing code
|
---|
| 5 | SECTION .text
|
---|
| 6 |
|
---|
| 7 | ;--------------------------------------------------------------------
|
---|
| 8 | ; Flash_EepromWithFlashvarsInDSSI
|
---|
| 9 | ; Parameters:
|
---|
| 10 | ; DS:SI: Ptr to FLASHVARS
|
---|
| 11 | ; Returns:
|
---|
| 12 | ; FLASHVARS.flashResult
|
---|
| 13 | ; Corrupts registers:
|
---|
| 14 | ; All, including segments
|
---|
| 15 | ;--------------------------------------------------------------------
|
---|
| 16 | ALIGN JUMP_ALIGN
|
---|
| 17 | Flash_EepromWithFlashvarsInDSSI:
|
---|
| 18 | mov [si+FLASHVARS.wProgressUpdateParam], bp ; Store handle to progress DIALOG
|
---|
| 19 | mov bp, si ; Flashvars now in SS:BP
|
---|
| 20 | mov cx, [bp+FLASHVARS.wPagesToFlash]
|
---|
| 21 | ALIGN JUMP_ALIGN
|
---|
| 22 | .FlashNextPage:
|
---|
| 23 | call DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP
|
---|
| 24 | call Flash_SinglePageWithFlashvarsInSSBP
|
---|
| 25 | jc SHORT .PollingError
|
---|
| 26 | call AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
|
---|
| 27 | jne SHORT .DataVerifyError
|
---|
| 28 |
|
---|
| 29 | mov ax, [bp+FLASHVARS.wEepromPageSize]
|
---|
| 30 | add [bp+FLASHVARS.fpNextSourcePage], ax
|
---|
| 31 | add [bp+FLASHVARS.fpNextComparisonPage], ax
|
---|
| 32 | add [bp+FLASHVARS.fpNextDestinationPage], ax
|
---|
| 33 |
|
---|
| 34 | loop .FlashNextPage
|
---|
[181] | 35 | %if FLASH_RESULT.success = 0 ; Just in case this should ever change
|
---|
| 36 | mov [bp+FLASHVARS.flashResult], cl
|
---|
| 37 | %else
|
---|
[65] | 38 | mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.success
|
---|
[181] | 39 | %endif
|
---|
[65] | 40 | ret
|
---|
| 41 |
|
---|
| 42 | .PollingError:
|
---|
| 43 | mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.PollingTimeoutError
|
---|
| 44 | ret
|
---|
| 45 | .DataVerifyError:
|
---|
| 46 | mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.DataVerifyError
|
---|
| 47 | ret
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | ;--------------------------------------------------------------------
|
---|
| 51 | ; Flash_SinglePageWithFlashvarsInSSBP
|
---|
| 52 | ; Parameters:
|
---|
| 53 | ; SS:BP: Ptr to FLASHVARS
|
---|
| 54 | ; Returns:
|
---|
| 55 | ; CF: Set if polling timeout error
|
---|
| 56 | ; Cleared if page written successfully
|
---|
| 57 | ; Corrupts registers:
|
---|
| 58 | ; AX, BX, DX, SI, DI, DS, ES
|
---|
| 59 | ;--------------------------------------------------------------------
|
---|
| 60 | ALIGN JUMP_ALIGN
|
---|
| 61 | Flash_SinglePageWithFlashvarsInSSBP:
|
---|
| 62 | cld
|
---|
| 63 | call AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
|
---|
| 64 | je SHORT .NoNeedToFlashThePage ; CF cleared
|
---|
| 65 |
|
---|
| 66 | push cx
|
---|
| 67 | call .GetSdpCommandFunctionToDXwithFlashvarsInSSBP
|
---|
| 68 | mov cx, [bp+FLASHVARS.wEepromPageSize]
|
---|
| 69 | mov si, [bp+FLASHVARS.fpNextSourcePage]
|
---|
| 70 | les di, [bp+FLASHVARS.fpNextComparisonPage]
|
---|
| 71 | mov bx, [bp+FLASHVARS.fpNextDestinationPage]
|
---|
| 72 | call WriteAllChangedBytesFromPageToEeprom
|
---|
| 73 | pop cx
|
---|
| 74 | .NoNeedToFlashThePage:
|
---|
| 75 | ret
|
---|
| 76 |
|
---|
| 77 | ;--------------------------------------------------------------------
|
---|
| 78 | ; .GetSdpCommandFunctionToDXwithFlashvarsInSSBP
|
---|
| 79 | ; Parameters:
|
---|
| 80 | ; SS:BP: Ptr to FLASHVARS
|
---|
| 81 | ; Returns:
|
---|
| 82 | ; DX: Ptr to SDP Command function
|
---|
| 83 | ; Corrupts registers:
|
---|
| 84 | ; BX, SI
|
---|
| 85 | ;--------------------------------------------------------------------
|
---|
| 86 | ALIGN JUMP_ALIGN
|
---|
| 87 | .GetSdpCommandFunctionToDXwithFlashvarsInSSBP:
|
---|
[293] | 88 | eMOVZX bx, [bp+FLASHVARS.bEepromSdpCommand]
|
---|
[65] | 89 | mov si, [cs:bx+.rgpSdpCommandToEepromTypeLookupTable]
|
---|
| 90 | mov bl, [bp+FLASHVARS.bEepromType]
|
---|
| 91 | mov dx, [cs:bx+si]
|
---|
| 92 | ret
|
---|
| 93 |
|
---|
| 94 | ALIGN WORD_ALIGN
|
---|
| 95 | .rgpSdpCommandToEepromTypeLookupTable:
|
---|
| 96 | dw .rgfnFlashWithoutSDP ; SDP_COMMAND.none
|
---|
| 97 | dw .rgfnEnableSdpAndFlash ; SDP_COMMAND.enable
|
---|
| 98 | dw .rgfnDisableSdpAndFlash ; SDP_COMMAND.disable
|
---|
| 99 | .rgfnFlashWithoutSDP: ; SDP_COMMAND.none
|
---|
| 100 | dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.2816_2kiB
|
---|
| 101 | dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.2864_8kiB
|
---|
[159] | 102 | dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.2864_8kiB_MOD
|
---|
[65] | 103 | dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.28256_32kiB
|
---|
| 104 | dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.28512_64kiB
|
---|
| 105 | .rgfnEnableSdpAndFlash: ; SDP_COMMAND.enable
|
---|
| 106 | dw WriteSdpEnableCommandFor2816 ; EEPROM_TYPE.2816_2kiB
|
---|
| 107 | dw WriteSdpEnableCommandFor2864 ; EEPROM_TYPE.2864_8kiB
|
---|
[159] | 108 | dw WriteSdpEnableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD
|
---|
[65] | 109 | dw WriteSdpEnableCommandFor28256or28512 ; EEPROM_TYPE.28256_32kiB
|
---|
| 110 | dw WriteSdpEnableCommandFor28256or28512 ; EEPROM_TYPE.28512_64kiB
|
---|
| 111 | .rgfnDisableSdpAndFlash: ; SDP_COMMAND.disable
|
---|
| 112 | dw WriteSdpDisableCommandFor2816 ; EEPROM_TYPE.2816_2kiB
|
---|
| 113 | dw WriteSdpDisableCommandFor2864 ; EEPROM_TYPE.2864_8kiB
|
---|
[159] | 114 | dw WriteSdpDisableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD
|
---|
[65] | 115 | dw WriteSdpDisableCommandFor28256or28512 ; EEPROM_TYPE.28256_32kiB
|
---|
| 116 | dw WriteSdpDisableCommandFor28256or28512 ; EEPROM_TYPE.28512_64kiB
|
---|
| 117 |
|
---|
| 118 |
|
---|
| 119 | ;--------------------------------------------------------------------
|
---|
| 120 | ; AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
|
---|
| 121 | ; Parameters:
|
---|
| 122 | ; SS:BP: Ptr to FLASHVARS
|
---|
| 123 | ; Returns:
|
---|
| 124 | ; ZF: Set if pages are equal
|
---|
| 125 | ; Cleared if pages are not equal
|
---|
| 126 | ; Corrupts registers:
|
---|
| 127 | ; SI, DI
|
---|
| 128 | ;--------------------------------------------------------------------
|
---|
| 129 | ALIGN JUMP_ALIGN
|
---|
| 130 | AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP:
|
---|
| 131 | push cx
|
---|
| 132 | mov cx, [bp+FLASHVARS.wEepromPageSize]
|
---|
| 133 | lds si, [bp+FLASHVARS.fpNextSourcePage]
|
---|
| 134 | les di, [bp+FLASHVARS.fpNextDestinationPage]
|
---|
| 135 | repe cmpsb
|
---|
| 136 | pop cx
|
---|
| 137 | ret
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 | ;--------------------------------------------------------------------
|
---|
| 141 | ; ENABLE_SDP
|
---|
| 142 | ; Parameters:
|
---|
| 143 | ; %1: Offset for first command byte
|
---|
| 144 | ; %2: Offset for second command byte
|
---|
| 145 | ; DS: Segment to beginning of EEPROM
|
---|
| 146 | ; Returns:
|
---|
| 147 | ; Nothing
|
---|
| 148 | ; Corrupts registers:
|
---|
| 149 | ; Nothing
|
---|
| 150 | ;--------------------------------------------------------------------
|
---|
| 151 | %macro ENABLE_SDP 2
|
---|
| 152 | mov BYTE [%1], 0AAh
|
---|
| 153 | mov BYTE [%2], 55h
|
---|
| 154 | mov BYTE [%1], 0A0h
|
---|
| 155 | %endmacro
|
---|
| 156 |
|
---|
| 157 | ;--------------------------------------------------------------------
|
---|
| 158 | ; DISABLE_SDP
|
---|
| 159 | ; Parameters:
|
---|
| 160 | ; %1: Offset for first command byte
|
---|
| 161 | ; %2: Offset for second command byte
|
---|
| 162 | ; DS: Segment to beginning of EEPROM
|
---|
| 163 | ; Returns:
|
---|
| 164 | ; Nothing
|
---|
| 165 | ; Corrupts registers:
|
---|
| 166 | ; Nothing
|
---|
| 167 | ;--------------------------------------------------------------------
|
---|
| 168 | %macro DISABLE_SDP 2
|
---|
| 169 | mov BYTE [%1], 0AAh
|
---|
| 170 | mov BYTE [%2], 55h
|
---|
| 171 | mov BYTE [%1], 80h
|
---|
| 172 | mov BYTE [%1], 0AAh
|
---|
| 173 | mov BYTE [%2], 55h
|
---|
| 174 | mov BYTE [%1], 20h
|
---|
| 175 | %endmacro
|
---|
| 176 |
|
---|
| 177 | ;--------------------------------------------------------------------
|
---|
| 178 | ; SDP Command Functions
|
---|
| 179 | ; Parameters:
|
---|
| 180 | ; DS: Segment to beginning of EEPROM
|
---|
| 181 | ; Returns:
|
---|
| 182 | ; Nothing but jumps to WriteActualDataByteAfterSdpCommand
|
---|
| 183 | ; Corrupts registers:
|
---|
| 184 | ; Nothing
|
---|
| 185 | ;--------------------------------------------------------------------
|
---|
| 186 | ALIGN JUMP_ALIGN
|
---|
| 187 | WriteSdpEnableCommandFor2816:
|
---|
| 188 | ENABLE_SDP 555h, 2AAh
|
---|
| 189 | jmp ReturnFromSdpCommand
|
---|
| 190 |
|
---|
| 191 | ALIGN JUMP_ALIGN
|
---|
| 192 | WriteSdpEnableCommandFor2864:
|
---|
| 193 | ENABLE_SDP 1555h, 0AAAh
|
---|
[159] | 194 | jmp ReturnFromSdpCommand
|
---|
[65] | 195 |
|
---|
| 196 | ALIGN JUMP_ALIGN
|
---|
[159] | 197 | WriteSdpEnableCommandFor2864mod:
|
---|
| 198 | ENABLE_SDP 155Ch, 0AA3h
|
---|
| 199 | jmp ReturnFromSdpCommand
|
---|
| 200 |
|
---|
| 201 | ALIGN JUMP_ALIGN
|
---|
[65] | 202 | WriteSdpEnableCommandFor28256or28512:
|
---|
| 203 | ENABLE_SDP 5555h, 2AAAh
|
---|
[159] | 204 | jmp ReturnFromSdpCommand
|
---|
[65] | 205 |
|
---|
| 206 |
|
---|
| 207 | ALIGN JUMP_ALIGN
|
---|
| 208 | WriteSdpDisableCommandFor2816:
|
---|
| 209 | DISABLE_SDP 555h, 2AAh
|
---|
| 210 | jmp SHORT ReturnFromSdpCommand
|
---|
| 211 |
|
---|
| 212 | ALIGN JUMP_ALIGN
|
---|
| 213 | WriteSdpDisableCommandFor2864:
|
---|
| 214 | DISABLE_SDP 1555h, 0AAAh
|
---|
| 215 | jmp SHORT ReturnFromSdpCommand
|
---|
| 216 |
|
---|
| 217 | ALIGN JUMP_ALIGN
|
---|
[159] | 218 | WriteSdpDisableCommandFor2864mod:
|
---|
| 219 | DISABLE_SDP 155Ch, 0AA3h
|
---|
| 220 | jmp SHORT ReturnFromSdpCommand
|
---|
| 221 |
|
---|
| 222 | ALIGN JUMP_ALIGN
|
---|
[65] | 223 | WriteSdpDisableCommandFor28256or28512:
|
---|
| 224 | DISABLE_SDP 5555h, 2AAAh
|
---|
| 225 | DoNotWriteAnySdpCommand:
|
---|
| 226 | jmp SHORT ReturnFromSdpCommand
|
---|
| 227 |
|
---|
| 228 |
|
---|
| 229 | ;--------------------------------------------------------------------
|
---|
| 230 | ; WriteNextChangedByteFromPageToEeprom
|
---|
| 231 | ; Parameters:
|
---|
| 232 | ; CX: Number of bytes left to write
|
---|
| 233 | ; DX: Offset to SDP command function
|
---|
| 234 | ; BX: Offset to next destination byte
|
---|
| 235 | ; SI: Offset to next source byte
|
---|
| 236 | ; ES:DI: Ptr to next comparison byte
|
---|
| 237 | ; SS:BP: Ptr to FLASHVARS
|
---|
| 238 | ; Returns:
|
---|
| 239 | ; CF: Set if polling timeout error
|
---|
| 240 | ; Cleared if page written successfully
|
---|
| 241 | ; Corrupts registers:
|
---|
| 242 | ; AX, BX, CX, SI, DI, DS, ES
|
---|
| 243 | ;--------------------------------------------------------------------
|
---|
| 244 | ALIGN JUMP_ALIGN
|
---|
| 245 | WriteAllChangedBytesFromPageToEeprom:
|
---|
| 246 | mov ax, [bp+FLASHVARS.fpNextSourcePage+2] ; AX = Source segment
|
---|
| 247 | mov ds, [bp+FLASHVARS.fpNextDestinationPage+2] ; DS = EEPROM segment
|
---|
| 248 | cli ; Disable interrupts
|
---|
| 249 | jmp dx ; Write SDP command (once to the beginning of page)
|
---|
| 250 | ALIGN JUMP_ALIGN
|
---|
| 251 | ReturnFromSdpCommand:
|
---|
| 252 | mov ds, ax ; DS:SI now points to source byte
|
---|
| 253 |
|
---|
| 254 | ALIGN JUMP_ALIGN
|
---|
| 255 | .WriteActualDataByteAfterSdpCommand:
|
---|
| 256 | lodsb ; Load source byte to AL
|
---|
| 257 | scasb ; Compare source byte to comparison byte
|
---|
| 258 | je SHORT .NoChangesForThisByte
|
---|
| 259 |
|
---|
| 260 | mov ds, [bp+FLASHVARS.fpNextDestinationPage+2] ; DS:BX now points to EEPROM
|
---|
| 261 | mov [bx], al ; Write byte to EEPROM
|
---|
| 262 | mov ds, [bp+FLASHVARS.fpNextSourcePage+2] ; Restore DS
|
---|
| 263 | mov [bp+FLASHVARS.wLastOffsetWritten], bx
|
---|
| 264 | mov [bp+FLASHVARS.bLastByteWritten], al
|
---|
| 265 |
|
---|
| 266 | ALIGN JUMP_ALIGN
|
---|
| 267 | .NoChangesForThisByte:
|
---|
| 268 | inc bx ; Increment destination offset
|
---|
| 269 | loop .WriteActualDataByteAfterSdpCommand
|
---|
| 270 | sti ; Enable interrupts
|
---|
| 271 | ; Fall to WaitUntilEepromPageWriteHasCompleted
|
---|
| 272 |
|
---|
| 273 |
|
---|
| 274 | ;--------------------------------------------------------------------
|
---|
| 275 | ; WaitUntilEepromPageWriteHasCompleted
|
---|
| 276 | ; Parameters:
|
---|
| 277 | ; SS:BP: Ptr to FLASHVARS
|
---|
| 278 | ; Returns:
|
---|
| 279 | ; CF: Set if polling timeout error
|
---|
| 280 | ; Cleared if page written successfully
|
---|
| 281 | ; Corrupts registers:
|
---|
| 282 | ; AX, BX, DI, DS, ES
|
---|
| 283 | ;--------------------------------------------------------------------
|
---|
| 284 | ALIGN JUMP_ALIGN
|
---|
| 285 | WaitUntilEepromPageWriteHasCompleted:
|
---|
| 286 | call .InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP
|
---|
| 287 | mov es, [bp+FLASHVARS.fpNextDestinationPage+2]
|
---|
| 288 | mov di, [bp+FLASHVARS.wLastOffsetWritten]
|
---|
| 289 | ALIGN JUMP_ALIGN
|
---|
| 290 | .PollEeprom:
|
---|
| 291 | call .HasWriteCycleCompleted
|
---|
| 292 | je SHORT .PageWriteCompleted ; CF cleared
|
---|
| 293 | call TimerTicks_GetTimeoutTicksLeftToAXfromDSBX
|
---|
| 294 | jnc SHORT .PollEeprom
|
---|
| 295 | ALIGN JUMP_ALIGN
|
---|
| 296 | .PageWriteCompleted:
|
---|
| 297 | ret
|
---|
| 298 |
|
---|
| 299 | ;--------------------------------------------------------------------
|
---|
| 300 | ; .InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP
|
---|
| 301 | ; Parameters:
|
---|
| 302 | ; SS:BP: Ptr to FLASHVARS
|
---|
| 303 | ; Returns:
|
---|
| 304 | ; DS:BX: Ptr to timeout counter variable
|
---|
| 305 | ; Corrupts registers:
|
---|
| 306 | ; AX
|
---|
| 307 | ;--------------------------------------------------------------------
|
---|
| 308 | ALIGN JUMP_ALIGN
|
---|
| 309 | .InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP:
|
---|
| 310 | push ss
|
---|
| 311 | pop ds
|
---|
| 312 | lea bx, [bp+FLASHVARS.wTimeoutCounter]
|
---|
| 313 | mov ax, EEPROM_POLLING_TIMEOUT_TICKS
|
---|
| 314 | jmp TimerTicks_InitializeTimeoutFromAX
|
---|
| 315 |
|
---|
| 316 | ;--------------------------------------------------------------------
|
---|
| 317 | ; .HasWriteCycleCompleted
|
---|
| 318 | ; Parameters:
|
---|
| 319 | ; ES:DI: Ptr to last written byte in EEPROM
|
---|
| 320 | ; SS:BP: Ptr to FLASHVARS
|
---|
| 321 | ; Returns:
|
---|
| 322 | ; ZF: Set if write cycle has completed
|
---|
| 323 | ; Cleared if write cycle in progress
|
---|
| 324 | ; Corrupts registers:
|
---|
| 325 | ; AX
|
---|
| 326 | ;--------------------------------------------------------------------
|
---|
| 327 | ALIGN JUMP_ALIGN
|
---|
| 328 | .HasWriteCycleCompleted:
|
---|
| 329 | mov ah, [es:di] ; Load byte from EEPROM
|
---|
| 330 | mov al, [bp+FLASHVARS.bLastByteWritten]
|
---|
| 331 | and ax, 8080h ; Clear all but bit 7 from both bytes
|
---|
| 332 | cmp al, ah ; Set ZF if high bits are the same
|
---|
| 333 | ret
|
---|
| 334 |
|
---|
| 335 |
|
---|
| 336 | ;--------------------------------------------------------------------
|
---|
| 337 | ; DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP
|
---|
| 338 | ; Parameters:
|
---|
| 339 | ; CX: Number of pages left to flash
|
---|
| 340 | ; SS:BP: Ptr to FLASHVARS
|
---|
| 341 | ; Returns:
|
---|
| 342 | ; Nothing
|
---|
| 343 | ; Corrupts registers:
|
---|
| 344 | ; AX, DI
|
---|
| 345 | ;--------------------------------------------------------------------
|
---|
| 346 | ALIGN JUMP_ALIGN
|
---|
| 347 | DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP:
|
---|
| 348 | push bp
|
---|
| 349 |
|
---|
| 350 | mov ax, [bp+FLASHVARS.wPagesToFlash]
|
---|
| 351 | sub ax, cx
|
---|
| 352 | mov bp, [bp+FLASHVARS.wProgressUpdateParam] ; BP now has MENU handle
|
---|
| 353 | CALL_MENU_LIBRARY SetProgressValueFromAX
|
---|
| 354 |
|
---|
| 355 | pop bp
|
---|
| 356 | ret
|
---|