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