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-2012 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 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 |
---|
85 | call .GetSdpCommandFunctionToDXwithFlashvarsInSSBP |
---|
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 | ;-------------------------------------------------------------------- |
---|
96 | ; .GetSdpCommandFunctionToDXwithFlashvarsInSSBP |
---|
97 | ; Parameters: |
---|
98 | ; SS:BP: Ptr to FLASHVARS |
---|
99 | ; Returns: |
---|
100 | ; DX: Ptr to SDP Command function |
---|
101 | ; Corrupts registers: |
---|
102 | ; BX, SI |
---|
103 | ;-------------------------------------------------------------------- |
---|
104 | ALIGN JUMP_ALIGN |
---|
105 | .GetSdpCommandFunctionToDXwithFlashvarsInSSBP: |
---|
106 | eMOVZX bx, [bp+FLASHVARS.bEepromSdpCommand] |
---|
107 | mov si, [cs:bx+.rgpSdpCommandToEepromTypeLookupTable] |
---|
108 | mov bl, [bp+FLASHVARS.bEepromType] |
---|
109 | mov dx, [cs:bx+si] |
---|
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 |
---|
120 | dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.2864_8kiB_MOD |
---|
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 |
---|
126 | dw WriteSdpEnableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD |
---|
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 |
---|
132 | dw WriteSdpDisableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD |
---|
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: |
---|
184 | ; Nothing |
---|
185 | ;-------------------------------------------------------------------- |
---|
186 | %macro DISABLE_SDP 2 |
---|
187 | mov BYTE [%1], 0AAh |
---|
188 | mov BYTE [%2], 55h |
---|
189 | mov BYTE [%1], 80h |
---|
190 | mov BYTE [%1], 0AAh |
---|
191 | mov BYTE [%2], 55h |
---|
192 | mov BYTE [%1], 20h |
---|
193 | %endmacro |
---|
194 | |
---|
195 | ;-------------------------------------------------------------------- |
---|
196 | ; SDP Command Functions |
---|
197 | ; Parameters: |
---|
198 | ; DS: Segment to beginning of EEPROM |
---|
199 | ; Returns: |
---|
200 | ; Nothing but jumps to WriteActualDataByteAfterSdpCommand |
---|
201 | ; Corrupts registers: |
---|
202 | ; Nothing |
---|
203 | ;-------------------------------------------------------------------- |
---|
204 | ALIGN JUMP_ALIGN |
---|
205 | WriteSdpEnableCommandFor2816: |
---|
206 | ENABLE_SDP 555h, 2AAh |
---|
207 | jmp ReturnFromSdpCommand |
---|
208 | |
---|
209 | ALIGN JUMP_ALIGN |
---|
210 | WriteSdpEnableCommandFor2864: |
---|
211 | ENABLE_SDP 1555h, 0AAAh |
---|
212 | jmp ReturnFromSdpCommand |
---|
213 | |
---|
214 | ALIGN JUMP_ALIGN |
---|
215 | WriteSdpEnableCommandFor2864mod: |
---|
216 | ENABLE_SDP 155Ch, 0AA3h |
---|
217 | jmp ReturnFromSdpCommand |
---|
218 | |
---|
219 | ALIGN JUMP_ALIGN |
---|
220 | WriteSdpEnableCommandFor28256or28512: |
---|
221 | ENABLE_SDP 5555h, 2AAAh |
---|
222 | jmp ReturnFromSdpCommand |
---|
223 | |
---|
224 | |
---|
225 | ALIGN JUMP_ALIGN |
---|
226 | WriteSdpDisableCommandFor2816: |
---|
227 | DISABLE_SDP 555h, 2AAh |
---|
228 | jmp SHORT ReturnFromSdpCommand |
---|
229 | |
---|
230 | ALIGN JUMP_ALIGN |
---|
231 | WriteSdpDisableCommandFor2864: |
---|
232 | DISABLE_SDP 1555h, 0AAAh |
---|
233 | jmp SHORT ReturnFromSdpCommand |
---|
234 | |
---|
235 | ALIGN JUMP_ALIGN |
---|
236 | WriteSdpDisableCommandFor2864mod: |
---|
237 | DISABLE_SDP 155Ch, 0AA3h |
---|
238 | jmp SHORT ReturnFromSdpCommand |
---|
239 | |
---|
240 | ALIGN JUMP_ALIGN |
---|
241 | WriteSdpDisableCommandFor28256or28512: |
---|
242 | DISABLE_SDP 5555h, 2AAAh |
---|
243 | DoNotWriteAnySdpCommand: |
---|
244 | jmp SHORT ReturnFromSdpCommand |
---|
245 | |
---|
246 | |
---|
247 | ;-------------------------------------------------------------------- |
---|
248 | ; WriteNextChangedByteFromPageToEeprom |
---|
249 | ; Parameters: |
---|
250 | ; CX: Number of bytes left to write |
---|
251 | ; DX: Offset to SDP command function |
---|
252 | ; BX: Offset to next destination byte |
---|
253 | ; SI: Offset to next source byte |
---|
254 | ; ES:DI: Ptr to next comparison byte |
---|
255 | ; SS:BP: Ptr to FLASHVARS |
---|
256 | ; Returns: |
---|
257 | ; CF: Set if polling timeout error |
---|
258 | ; Cleared if page written successfully |
---|
259 | ; Corrupts registers: |
---|
260 | ; AX, BX, CX, SI, DI, DS, ES |
---|
261 | ;-------------------------------------------------------------------- |
---|
262 | ALIGN JUMP_ALIGN |
---|
263 | WriteAllChangedBytesFromPageToEeprom: |
---|
264 | mov ax, [bp+FLASHVARS.fpNextSourcePage+2] ; AX = Source segment |
---|
265 | mov ds, [bp+FLASHVARS.fpNextDestinationPage+2] ; DS = EEPROM segment |
---|
266 | cli ; Disable interrupts |
---|
267 | jmp dx ; Write SDP command (once to the beginning of page) |
---|
268 | ALIGN JUMP_ALIGN |
---|
269 | ReturnFromSdpCommand: |
---|
270 | mov ds, ax ; DS:SI now points to source byte |
---|
271 | |
---|
272 | ALIGN JUMP_ALIGN |
---|
273 | .WriteActualDataByteAfterSdpCommand: |
---|
274 | lodsb ; Load source byte to AL |
---|
275 | scasb ; Compare source byte to comparison byte |
---|
276 | je SHORT .NoChangesForThisByte |
---|
277 | |
---|
278 | mov ds, [bp+FLASHVARS.fpNextDestinationPage+2] ; DS:BX now points to EEPROM |
---|
279 | mov [bx], al ; Write byte to EEPROM |
---|
280 | mov ds, [bp+FLASHVARS.fpNextSourcePage+2] ; Restore DS |
---|
281 | mov [bp+FLASHVARS.wLastOffsetWritten], bx |
---|
282 | mov [bp+FLASHVARS.bLastByteWritten], al |
---|
283 | |
---|
284 | ALIGN JUMP_ALIGN |
---|
285 | .NoChangesForThisByte: |
---|
286 | inc bx ; Increment destination offset |
---|
287 | loop .WriteActualDataByteAfterSdpCommand |
---|
288 | sti ; Enable interrupts |
---|
289 | ; Fall to WaitUntilEepromPageWriteHasCompleted |
---|
290 | |
---|
291 | |
---|
292 | ;-------------------------------------------------------------------- |
---|
293 | ; WaitUntilEepromPageWriteHasCompleted |
---|
294 | ; Parameters: |
---|
295 | ; SS:BP: Ptr to FLASHVARS |
---|
296 | ; Returns: |
---|
297 | ; CF: Set if polling timeout error |
---|
298 | ; Cleared if page written successfully |
---|
299 | ; Corrupts registers: |
---|
300 | ; AX, BX, DI, DS, ES |
---|
301 | ;-------------------------------------------------------------------- |
---|
302 | ALIGN JUMP_ALIGN |
---|
303 | WaitUntilEepromPageWriteHasCompleted: |
---|
304 | call .InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP |
---|
305 | mov es, [bp+FLASHVARS.fpNextDestinationPage+2] |
---|
306 | mov di, [bp+FLASHVARS.wLastOffsetWritten] |
---|
307 | ALIGN JUMP_ALIGN |
---|
308 | .PollEeprom: |
---|
309 | call .HasWriteCycleCompleted |
---|
310 | je SHORT .PageWriteCompleted ; CF cleared |
---|
311 | call TimerTicks_GetTimeoutTicksLeftToAXfromDSBX |
---|
312 | jnc SHORT .PollEeprom |
---|
313 | ALIGN JUMP_ALIGN |
---|
314 | .PageWriteCompleted: |
---|
315 | ret |
---|
316 | |
---|
317 | ;-------------------------------------------------------------------- |
---|
318 | ; .InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP |
---|
319 | ; Parameters: |
---|
320 | ; SS:BP: Ptr to FLASHVARS |
---|
321 | ; Returns: |
---|
322 | ; DS:BX: Ptr to timeout counter variable |
---|
323 | ; Corrupts registers: |
---|
324 | ; AX |
---|
325 | ;-------------------------------------------------------------------- |
---|
326 | ALIGN JUMP_ALIGN |
---|
327 | .InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP: |
---|
328 | push ss |
---|
329 | pop ds |
---|
330 | lea bx, [bp+FLASHVARS.wTimeoutCounter] |
---|
331 | mov ax, EEPROM_POLLING_TIMEOUT_TICKS |
---|
332 | jmp TimerTicks_InitializeTimeoutFromAX |
---|
333 | |
---|
334 | ;-------------------------------------------------------------------- |
---|
335 | ; .HasWriteCycleCompleted |
---|
336 | ; Parameters: |
---|
337 | ; ES:DI: Ptr to last written byte in EEPROM |
---|
338 | ; SS:BP: Ptr to FLASHVARS |
---|
339 | ; Returns: |
---|
340 | ; ZF: Set if write cycle has completed |
---|
341 | ; Cleared if write cycle in progress |
---|
342 | ; Corrupts registers: |
---|
343 | ; AX |
---|
344 | ;-------------------------------------------------------------------- |
---|
345 | ALIGN JUMP_ALIGN |
---|
346 | .HasWriteCycleCompleted: |
---|
347 | mov ah, [es:di] ; Load byte from EEPROM |
---|
348 | mov al, [bp+FLASHVARS.bLastByteWritten] |
---|
349 | and ax, 8080h ; Clear all but bit 7 from both bytes |
---|
350 | cmp al, ah ; Set ZF if high bits are the same |
---|
351 | ret |
---|
352 | |
---|
353 | |
---|
354 | ;-------------------------------------------------------------------- |
---|
355 | ; DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP |
---|
356 | ; Parameters: |
---|
357 | ; CX: Number of pages left to flash |
---|
358 | ; SS:BP: Ptr to FLASHVARS |
---|
359 | ; Returns: |
---|
360 | ; Nothing |
---|
361 | ; Corrupts registers: |
---|
362 | ; AX, DI |
---|
363 | ;-------------------------------------------------------------------- |
---|
364 | ALIGN JUMP_ALIGN |
---|
365 | DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP: |
---|
366 | push bp |
---|
367 | |
---|
368 | mov ax, [bp+FLASHVARS.wPagesToFlash] |
---|
369 | sub ax, cx |
---|
370 | mov bp, [bp+FLASHVARS.wProgressUpdateParam] ; BP now has MENU handle |
---|
371 | CALL_MENU_LIBRARY SetProgressValueFromAX |
---|
372 | |
---|
373 | pop bp |
---|
374 | ret |
---|