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