source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Flash.asm@ 629

Last change on this file since 629 was 620, checked in by Krister Nordvall, 3 years ago

Changes:

  • A huge thank you to Jayeson Lee-Steere for adding SST39SF0x0 flash ROM programming support to the configurator (XTIDECFG.COM). This means that there is no longer a need to use a separate program for flashing the Lo-Tech boards and other devices using these flash ROMs.
File size: 11.0 KB
Line 
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-2013 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
21SECTION .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;--------------------------------------------------------------------
32ALIGN JUMP_ALIGN
33Flash_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]
37ALIGN 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;--------------------------------------------------------------------
78ALIGN JUMP_ALIGN
79Flash_SinglePageWithFlashvarsInSSBP:
80%ifdef CLD_NEEDED
81 cld
82%endif
83 call AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
84 je SHORT .NoNeedToFlashThePage ; CF cleared
85
86 push cx
87 call .GetSdpCommandFunctionToAXwithFlashvarsInSSBP
88 mov cx, [bp+FLASHVARS.wEepromPageSize]
89 mov si, [bp+FLASHVARS.fpNextSourcePage]
90 les di, [bp+FLASHVARS.fpNextComparisonPage]
91 mov bx, [bp+FLASHVARS.fpNextDestinationPage]
92 call WriteAllChangedBytesFromPageToEeprom
93 pop cx
94.NoNeedToFlashThePage:
95 ret
96
97;--------------------------------------------------------------------
98; .GetSdpCommandFunctionToAXwithFlashvarsInSSBP
99; Parameters:
100; SS:BP: Ptr to FLASHVARS
101; Returns:
102; AX: Ptr to SDP Command function
103; Corrupts registers:
104; BX, SI
105;--------------------------------------------------------------------
106ALIGN JUMP_ALIGN
107.GetSdpCommandFunctionToAXwithFlashvarsInSSBP:
108 eMOVZX bx, [bp+FLASHVARS.bEepromSdpCommand]
109 mov si, [cs:bx+.rgpSdpCommandToEepromTypeLookupTable]
110 mov bl, [bp+FLASHVARS.bEepromType]
111 mov ax, [cs:bx+si]
112 ret
113
114ALIGN WORD_ALIGN
115.rgpSdpCommandToEepromTypeLookupTable:
116 dw .rgfnFlashWithoutSDP ; SDP_COMMAND.none
117 dw .rgfnEnableSdpAndFlash ; SDP_COMMAND.enable
118 dw .rgfnDisableSdpAndFlash ; SDP_COMMAND.disable
119.rgfnFlashWithoutSDP: ; SDP_COMMAND.none
120 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.2816_2kiB
121 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.2864_8kiB
122 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.2864_8kiB_MOD
123 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.28256_32kiB
124 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.28512_64kiB
125 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.SST_39SF
126.rgfnEnableSdpAndFlash: ; SDP_COMMAND.enable
127 dw WriteSdpEnableCommandFor2816 ; EEPROM_TYPE.2816_2kiB
128 dw WriteSdpEnableCommandFor2864 ; EEPROM_TYPE.2864_8kiB
129 dw WriteSdpEnableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD
130 dw WriteSdpEnableCommandFor28256or28512 ; EEPROM_TYPE.28256_32kiB
131 dw WriteSdpEnableCommandFor28256or28512 ; EEPROM_TYPE.28512_64kiB
132 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.SST_39SF
133.rgfnDisableSdpAndFlash: ; SDP_COMMAND.disable
134 dw WriteSdpDisableCommandFor2816 ; EEPROM_TYPE.2816_2kiB
135 dw WriteSdpDisableCommandFor2864 ; EEPROM_TYPE.2864_8kiB
136 dw WriteSdpDisableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD
137 dw WriteSdpDisableCommandFor28256or28512 ; EEPROM_TYPE.28256_32kiB
138 dw WriteSdpDisableCommandFor28256or28512 ; EEPROM_TYPE.28512_64kiB
139 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.SST_39SF
140
141
142;--------------------------------------------------------------------
143; AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
144; Parameters:
145; SS:BP: Ptr to FLASHVARS
146; Returns:
147; ZF: Set if pages are equal
148; Cleared if pages are not equal
149; Corrupts registers:
150; SI, DI
151;--------------------------------------------------------------------
152ALIGN JUMP_ALIGN
153AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP:
154 push cx
155 mov cx, [bp+FLASHVARS.wEepromPageSize]
156 lds si, [bp+FLASHVARS.fpNextSourcePage]
157 les di, [bp+FLASHVARS.fpNextDestinationPage]
158 repe cmpsb
159 pop cx
160 ret
161
162
163;--------------------------------------------------------------------
164; ENABLE_SDP
165; Parameters:
166; %1: Offset for first command byte
167; %2: Offset for second command byte
168; DS: Segment to beginning of EEPROM
169; Returns:
170; Nothing
171; Corrupts registers:
172; Nothing
173;--------------------------------------------------------------------
174%macro ENABLE_SDP 2
175 mov BYTE [%1], 0AAh
176 mov BYTE [%2], 55h
177 mov BYTE [%1], 0A0h
178%endmacro
179
180;--------------------------------------------------------------------
181; DISABLE_SDP
182; Parameters:
183; %1: Offset for first command byte
184; %2: Offset for second command byte
185; DS: Segment to beginning of EEPROM
186; Returns:
187; Nothing
188; Corrupts registers:
189; AX
190;--------------------------------------------------------------------
191%macro DISABLE_SDP 2
192 mov ax, 80AAh
193%%Again:
194 mov [%1], al ; 0AAh
195 shr al, 1
196 mov [%2], al ; 55h
197 mov [%1], ah ; 80h/20h
198 xor ax, 0A0FFh
199 jns SHORT %%Again
200%endmacro
201
202;--------------------------------------------------------------------
203; SDP Command Functions
204; Parameters:
205; DS: Segment to beginning of EEPROM
206; Returns:
207; Nothing but jumps to WriteActualDataByteAfterSdpCommand
208; Corrupts registers:
209; Nothing
210;--------------------------------------------------------------------
211ALIGN JUMP_ALIGN
212WriteSdpEnableCommandFor2816:
213 ENABLE_SDP 555h, 2AAh
214 jmp ReturnFromSdpCommand
215
216ALIGN JUMP_ALIGN
217WriteSdpEnableCommandFor2864:
218 ENABLE_SDP 1555h, 0AAAh
219 jmp ReturnFromSdpCommand
220
221ALIGN JUMP_ALIGN
222WriteSdpEnableCommandFor2864mod:
223 ENABLE_SDP 155Ch, 0AA3h
224 jmp SHORT ReturnFromSdpCommand
225
226ALIGN JUMP_ALIGN
227WriteSdpEnableCommandFor28256or28512:
228 ENABLE_SDP 5555h, 2AAAh
229 jmp SHORT ReturnFromSdpCommand
230
231
232ALIGN JUMP_ALIGN
233WriteSdpDisableCommandFor2816:
234 DISABLE_SDP 555h, 2AAh
235 jmp SHORT ReturnFromSdpCommand
236
237ALIGN JUMP_ALIGN
238WriteSdpDisableCommandFor2864:
239 DISABLE_SDP 1555h, 0AAAh
240 jmp SHORT ReturnFromSdpCommand
241
242ALIGN JUMP_ALIGN
243WriteSdpDisableCommandFor2864mod:
244 DISABLE_SDP 155Ch, 0AA3h
245 jmp SHORT ReturnFromSdpCommand
246
247ALIGN JUMP_ALIGN
248WriteSdpDisableCommandFor28256or28512:
249 DISABLE_SDP 5555h, 2AAAh
250 jmp SHORT ReturnFromSdpCommand
251
252DoNotWriteAnySdpCommand EQU ReturnFromSdpCommand
253
254
255;--------------------------------------------------------------------
256; WriteAllChangedBytesFromPageToEeprom
257; Parameters:
258; AX: Offset to SDP command function
259; BX: Offset to next destination byte
260; CX: Number of bytes left to write
261; SI: Offset to next source byte
262; ES:DI: Ptr to next comparison byte
263; SS:BP: Ptr to FLASHVARS
264; Returns:
265; CF: Set if polling timeout error
266; Cleared if page written successfully
267; Corrupts registers:
268; AX, BX, CX, DX, SI, DI, DS, ES
269;--------------------------------------------------------------------
270ALIGN JUMP_ALIGN
271WriteAllChangedBytesFromPageToEeprom:
272 mov dx, [bp+FLASHVARS.fpNextSourcePage+2] ; DX = Source segment
273 mov ds, [bp+FLASHVARS.fpNextDestinationPage+2] ; DS = EEPROM segment
274 cli ; Disable interrupts
275 jmp ax ; Write SDP command (once to the beginning of page)
276ALIGN JUMP_ALIGN
277ReturnFromSdpCommand:
278 mov ds, dx ; DS:SI now points to source byte
279
280ALIGN JUMP_ALIGN
281.WriteActualDataByteAfterSdpCommand:
282 lodsb ; Load source byte to AL
283 scasb ; Compare source byte to comparison byte
284 je SHORT .NoChangesForThisByte
285
286 mov ds, [bp+FLASHVARS.fpNextDestinationPage+2] ; DS:BX now points to EEPROM
287 mov [bx], al ; Write byte to EEPROM
288 mov ds, dx ; Restore DS
289 mov [bp+FLASHVARS.wLastOffsetWritten], bx
290 mov [bp+FLASHVARS.bLastByteWritten], al
291
292ALIGN JUMP_ALIGN
293.NoChangesForThisByte:
294 inc bx ; Increment destination offset
295 loop .WriteActualDataByteAfterSdpCommand
296 sti ; Enable interrupts
297 ; Fall to .WaitUntilEepromPageWriteHasCompleted
298
299
300;--------------------------------------------------------------------
301; .WaitUntilEepromPageWriteHasCompleted
302; Parameters:
303; SS:BP: Ptr to FLASHVARS
304; Returns:
305; CF: Set if polling timeout error
306; Cleared if page written successfully
307; Corrupts registers:
308; AX, BX, DI, DS, ES
309;--------------------------------------------------------------------
310.WaitUntilEepromPageWriteHasCompleted:
311 push ss
312 pop ds
313 lea bx, [bp+FLASHVARS.wTimeoutCounter]
314 mov ax, EEPROM_POLLING_TIMEOUT_TICKS
315 call TimerTicks_InitializeTimeoutFromAX
316 mov es, [bp+FLASHVARS.fpNextDestinationPage+2]
317 mov di, [bp+FLASHVARS.wLastOffsetWritten]
318ALIGN JUMP_ALIGN
319.PollEeprom:
320 mov al, [es:di] ; Load byte from EEPROM
321 xor al, [bp+FLASHVARS.bLastByteWritten] ; Clear SF if the most significant bits are the same
322 jns SHORT .PageWriteCompleted ; With CF cleared
323 call TimerTicks_GetTimeoutTicksLeftToAXfromDSBX
324 jnc SHORT .PollEeprom
325ALIGN JUMP_ALIGN, ret
326.PageWriteCompleted:
327 ret
328
329
330;--------------------------------------------------------------------
331; DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP
332; Parameters:
333; CX: Number of pages left to flash
334; SS:BP: Ptr to FLASHVARS
335; Returns:
336; Nothing
337; Corrupts registers:
338; AX, DI
339;--------------------------------------------------------------------
340ALIGN JUMP_ALIGN
341DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP:
342 push bp
343
344 mov ax, [bp+FLASHVARS.wPagesToFlash]
345 sub ax, cx
346 mov bp, [bp+FLASHVARS.wProgressUpdateParam] ; BP now has MENU handle
347 CALL_MENU_LIBRARY SetProgressValueFromAX
348
349 pop bp
350 ret
Note: See TracBrowser for help on using the repository browser.