[2] | 1 | ; Project name : XTIDE Univeral BIOS Configurator |
---|
| 2 | ; Description : Function for flashing the EEPROM. |
---|
| 3 | |
---|
| 4 | ; Section containing code |
---|
| 5 | SECTION .text |
---|
| 6 | |
---|
| 7 | ;-------------------------------------------------------------------- |
---|
| 8 | ; Loads old XTIDE Universal BIOS settings from ROM to RAM. |
---|
| 9 | ; |
---|
| 10 | ; EEPROM_LoadSettingsFromRomToRam |
---|
| 11 | ; Parameters: |
---|
| 12 | ; Nothing |
---|
| 13 | ; Returns: |
---|
| 14 | ; Nothing |
---|
| 15 | ; Corrupts registers: |
---|
| 16 | ; BX, CX, ES |
---|
| 17 | ;-------------------------------------------------------------------- |
---|
| 18 | ALIGN JUMP_ALIGN |
---|
| 19 | Flash_CopyCurrentContentsForComparison: |
---|
| 20 | push ds |
---|
| 21 | push di |
---|
| 22 | push si |
---|
| 23 | |
---|
| 24 | call EEPROM_GetComparisonBufferPointerToDSBX |
---|
| 25 | push ds |
---|
| 26 | pop es |
---|
| 27 | mov di, bx ; Comparison buffer now in ES:DI |
---|
| 28 | xor si, si |
---|
| 29 | mov ds, [cs:g_cfgVars+CFGVARS.wEepromSegment] ; EEPROM now in DS:SI |
---|
| 30 | mov cx, [cs:g_cfgVars+CFGVARS.wEepromSize] |
---|
| 31 | shr cx, 1 ; Byte count to word count |
---|
| 32 | cld ; MOVSW to increment DI and SI |
---|
| 33 | rep movsw |
---|
| 34 | |
---|
| 35 | pop si |
---|
| 36 | pop di |
---|
| 37 | pop ds |
---|
| 38 | ret |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | ;-------------------------------------------------------------------- |
---|
| 42 | ; Verifies that all data has been written successfully. |
---|
| 43 | ; |
---|
[293] | 44 | ; Flash_WasDataWriteSuccessful |
---|
[2] | 45 | ; Parameters: |
---|
| 46 | ; Nothing |
---|
| 47 | ; Returns: |
---|
| 48 | ; ZF: Set if data was written successfully |
---|
| 49 | ; Cleared if write failed |
---|
| 50 | ; Corrupts registers: |
---|
| 51 | ; CX, ES |
---|
| 52 | ;-------------------------------------------------------------------- |
---|
| 53 | ALIGN JUMP_ALIGN |
---|
[293] | 54 | Flash_WasDataWriteSuccessful: |
---|
[2] | 55 | push ds |
---|
| 56 | push di |
---|
| 57 | push si |
---|
| 58 | |
---|
| 59 | call EEPROM_GetSourceBufferPointerToDSSI |
---|
| 60 | call EEPROM_GetEepromPointerToESDI |
---|
| 61 | mov cx, [cs:g_cfgVars+CFGVARS.wEepromSize] |
---|
| 62 | shr cx, 1 ; Byte count to word count |
---|
| 63 | cld ; CMPSW to increment SI and DI |
---|
| 64 | repe cmpsw |
---|
| 65 | |
---|
| 66 | pop si |
---|
| 67 | pop di |
---|
| 68 | pop ds |
---|
| 69 | ret |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | ;-------------------------------------------------------------------- |
---|
| 73 | ; Writes page of data to EEPROM. |
---|
| 74 | ; |
---|
| 75 | ; Flash_WritePage |
---|
| 76 | ; Parameters: |
---|
| 77 | ; AX: SDP command |
---|
| 78 | ; CX: Page size (1, 2, 4, 8, 16, 32 or 64 bytes) |
---|
| 79 | ; DS:BX: Ptr to comparison buffer with old EEPROM data |
---|
| 80 | ; DS:SI: Ptr to source data to write |
---|
| 81 | ; ES:DI: Ptr to destination EEPROM |
---|
| 82 | ; Returns: |
---|
| 83 | ; BX, SI, DI: Updated to next page |
---|
| 84 | ; CF: Cleared if page written successfully |
---|
| 85 | ; Set if polling timeout |
---|
| 86 | ; Corrupts registers: |
---|
| 87 | ; Nothing |
---|
| 88 | ;-------------------------------------------------------------------- |
---|
| 89 | ALIGN JUMP_ALIGN |
---|
| 90 | Flash_WritePage: |
---|
| 91 | call Flash_DoesPageNeedToBeWritten |
---|
| 92 | jz SHORT .ReturnWithoutWriting |
---|
| 93 | push bp |
---|
| 94 | push cx |
---|
| 95 | push ax |
---|
| 96 | |
---|
| 97 | mov bp, .LoopWritePageBytes ; Return address from SDP command |
---|
| 98 | cli ; Disable interrupts |
---|
| 99 | jmp SHORT Flash_WriteSdpCommand |
---|
| 100 | |
---|
| 101 | ALIGN JUMP_ALIGN |
---|
| 102 | .LoopWritePageBytes: |
---|
| 103 | lodsb ; Load source byte to AL, increment SI |
---|
| 104 | cmp al, [bx] ; Trying to write existing data? |
---|
| 105 | je SHORT .SkipByte |
---|
| 106 | inc bx ; Increment comparison buffer pointer |
---|
| 107 | mov ah, al ; Last byte written to AH |
---|
| 108 | mov bp, di ; ES:BP points to last byte written |
---|
| 109 | stosb ; Write source byte to EEPROM, increment DI |
---|
| 110 | loop .LoopWritePageBytes |
---|
| 111 | jmp SHORT .PageCompleted |
---|
| 112 | ALIGN JUMP_ALIGN |
---|
| 113 | .SkipByte: |
---|
| 114 | inc bx |
---|
| 115 | inc di |
---|
| 116 | loop .LoopWritePageBytes |
---|
| 117 | |
---|
| 118 | ALIGN JUMP_ALIGN |
---|
| 119 | .PageCompleted: |
---|
| 120 | sti ; Enable interrupts |
---|
| 121 | call Flash_PollEepromUntilWriteCycleHasCompleted |
---|
| 122 | pop ax |
---|
| 123 | pop cx |
---|
| 124 | pop bp |
---|
| 125 | ret |
---|
| 126 | |
---|
| 127 | ALIGN JUMP_ALIGN |
---|
| 128 | .ReturnWithoutWriting: |
---|
| 129 | add bx, cx |
---|
| 130 | add si, cx |
---|
| 131 | add di, cx |
---|
| 132 | clc |
---|
| 133 | ret |
---|
| 134 | |
---|
| 135 | ;-------------------------------------------------------------------- |
---|
| 136 | ; Compares source data and comparison buffer. |
---|
| 137 | ; |
---|
| 138 | ; Flash_DoesPageNeedToBeWritten |
---|
| 139 | ; Parameters: |
---|
| 140 | ; CX: Page size (1, 2, 4, 8, 16, 32 or 64 bytes) |
---|
| 141 | ; DS:BX: Ptr to comparison buffer with old EEPROM data |
---|
| 142 | ; DS:SI: Ptr to source data to write |
---|
| 143 | ; Returns: |
---|
| 144 | ; ZF: Set if no need to write page |
---|
| 145 | ; Cleared if writing is needed |
---|
| 146 | ; Corrupts registers: |
---|
| 147 | ; Nothing |
---|
| 148 | ;-------------------------------------------------------------------- |
---|
| 149 | ALIGN JUMP_ALIGN |
---|
| 150 | Flash_DoesPageNeedToBeWritten: |
---|
| 151 | push es |
---|
| 152 | push di |
---|
| 153 | push si |
---|
| 154 | push cx |
---|
| 155 | |
---|
| 156 | push ds |
---|
| 157 | pop es |
---|
| 158 | mov di, bx ; ES:DI now points to comparison buffer |
---|
| 159 | cld ; CMPSB to increment SI and DI |
---|
| 160 | repe cmpsb |
---|
| 161 | |
---|
| 162 | pop cx |
---|
| 163 | pop si |
---|
| 164 | pop di |
---|
| 165 | pop es |
---|
| 166 | ret |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | ;-------------------------------------------------------------------- |
---|
| 170 | ; Writes Software Data Protection command to EEPROM. |
---|
| 171 | ; |
---|
| 172 | ; Flash_WriteSdpCommand |
---|
| 173 | ; Parameters: |
---|
| 174 | ; AX: SDP command |
---|
| 175 | ; BP: Return address |
---|
| 176 | ; ES: Segment to EEPROM |
---|
| 177 | ; Returns: |
---|
| 178 | ; Nothing |
---|
| 179 | ; Corrupts registers: |
---|
| 180 | ; Nothing |
---|
| 181 | ;-------------------------------------------------------------------- |
---|
| 182 | ALIGN JUMP_ALIGN |
---|
| 183 | Flash_WriteSdpCommand: |
---|
| 184 | cmp ax, CMD_SDP_ENABLE |
---|
| 185 | je SHORT Flash_WriteSdpEnableCommand |
---|
| 186 | cmp ax, CMD_SDP_DISABLE |
---|
| 187 | je SHORT Flash_WriteSdpDisableCommand |
---|
| 188 | jmp bp |
---|
| 189 | |
---|
| 190 | ALIGN JUMP_ALIGN |
---|
| 191 | Flash_WriteSdpEnableCommand: |
---|
| 192 | mov BYTE [es:1555h], 0AAh ; Write AAh to address 1555h |
---|
| 193 | mov BYTE [es:0AAAh], 55h ; Write 55h to address 0AAAh |
---|
| 194 | mov BYTE [es:1555h], 0A0h ; Write A0h to address 1555h |
---|
| 195 | jmp bp |
---|
| 196 | |
---|
| 197 | ALIGN JUMP_ALIGN |
---|
| 198 | Flash_WriteSdpDisableCommand: |
---|
| 199 | mov BYTE [es:1555h], 0AAh ; Write AAh to address 1555h |
---|
| 200 | mov BYTE [es:0AAAh], 55h ; Write 55h to address 0AAAh |
---|
| 201 | mov BYTE [es:1555h], 80h ; Write 80h to address 1555h |
---|
| 202 | mov BYTE [es:1555h], 0AAh ; Write AAh to address 1555h |
---|
| 203 | mov BYTE [es:0AAAh], 55h ; Write 55h to address 0AAAh |
---|
| 204 | mov BYTE [es:1555h], 20h ; Write 20h to address 1555h |
---|
| 205 | jmp bp |
---|
| 206 | |
---|
| 207 | |
---|
| 208 | ;-------------------------------------------------------------------- |
---|
| 209 | ; Polls EEPROM until write cycle ends. |
---|
| 210 | ; |
---|
| 211 | ; Flash_PollEepromUntilWriteCycleHasCompleted |
---|
| 212 | ; Parameters: |
---|
| 213 | ; AH: Last byte written |
---|
| 214 | ; ES:BP: Ptr to EEPROM last write location |
---|
| 215 | ; Returns: |
---|
[293] | 216 | ; CF: Cleared if polling successful |
---|
[2] | 217 | ; Set if polling timeout |
---|
| 218 | ; Corrupts registers: |
---|
| 219 | ; AX, CX |
---|
| 220 | ;-------------------------------------------------------------------- |
---|
| 221 | ALIGN JUMP_ALIGN |
---|
| 222 | Flash_PollEepromUntilWriteCycleHasCompleted: |
---|
| 223 | call Flash_InitializePollingTimeout |
---|
| 224 | ALIGN JUMP_ALIGN |
---|
| 225 | .PollLoop: |
---|
| 226 | mov al, [es:bp] ; Load byte from EEPROM |
---|
| 227 | and ax, 8080h ; Clear all but bit 7 from both bytes |
---|
| 228 | cmp al, ah ; Same bytes? |
---|
| 229 | je SHORT .Return |
---|
| 230 | call Flash_UpdatePollingTimeout |
---|
| 231 | jnc SHORT .PollLoop ; Not timeout |
---|
| 232 | ALIGN JUMP_ALIGN |
---|
| 233 | .Return: |
---|
| 234 | ret |
---|
| 235 | |
---|
| 236 | ;-------------------------------------------------------------------- |
---|
| 237 | ; Initializes timeout counter. Timeouts are implemented using system |
---|
| 238 | ; timer ticks. First tick might take 0...54.9ms and remaining ticks |
---|
| 239 | ; will occur at 54.9ms intervals. Use delay of two (or more) ticks to |
---|
| 240 | ; ensure at least 54.9ms wait. |
---|
| 241 | ; |
---|
| 242 | ; Flash_InitializePollingTimeout |
---|
| 243 | ; Parameters: |
---|
| 244 | ; Nothing |
---|
| 245 | ; Returns: |
---|
| 246 | ; CX: Timeout end time for Flash_UpdatePollingTimeout |
---|
| 247 | ; Corrupts registers: |
---|
| 248 | ; Nothing |
---|
| 249 | ;-------------------------------------------------------------------- |
---|
| 250 | ALIGN JUMP_ALIGN |
---|
| 251 | Flash_InitializePollingTimeout: |
---|
| 252 | push ds |
---|
| 253 | LOAD_BDA_SEGMENT_TO ds, cx |
---|
| 254 | mov cx, CNT_TMEOUT_POLL |
---|
| 255 | add cx, [BDA.dwTimerTicks] ; CX = End time |
---|
| 256 | pop ds |
---|
| 257 | sti ; Enable interrupts |
---|
| 258 | ret |
---|
| 259 | |
---|
| 260 | ;-------------------------------------------------------------------- |
---|
| 261 | ; Updates timeout counter. Timeout counter can be |
---|
| 262 | ; initialized with Flash_InitializePollingTimeout. |
---|
| 263 | ; |
---|
| 264 | ; Flash_UpdatePollingTimeout |
---|
| 265 | ; Parameters: |
---|
| 266 | ; CX: Timeout end time |
---|
| 267 | ; Returns: |
---|
| 268 | ; CF: Set if timeout |
---|
| 269 | ; Cleared if time left |
---|
| 270 | ; Corrupts registers: |
---|
| 271 | ; Nothing |
---|
| 272 | ;-------------------------------------------------------------------- |
---|
| 273 | ALIGN JUMP_ALIGN |
---|
| 274 | Flash_UpdatePollingTimeout: |
---|
| 275 | push ds |
---|
| 276 | push ax |
---|
| 277 | LOAD_BDA_SEGMENT_TO ds, ax |
---|
| 278 | cmp cx, [BDA.dwTimerTicks] ; Timeout? |
---|
| 279 | pop ax |
---|
| 280 | pop ds |
---|
| 281 | je SHORT .ReturnTimeout |
---|
| 282 | clc |
---|
| 283 | ret |
---|
| 284 | .ReturnTimeout: |
---|
| 285 | stc |
---|
| 286 | ret |
---|