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