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

Last change on this file since 622 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
RevLine 
[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
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
[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;--------------------------------------------------------------------
78ALIGN JUMP_ALIGN
79Flash_SinglePageWithFlashvarsInSSBP:
[592]80%ifdef CLD_NEEDED
[65]81 cld
[592]82%endif
[65]83 call AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
84 je SHORT .NoNeedToFlashThePage ; CF cleared
85
86 push cx
[568]87 call .GetSdpCommandFunctionToAXwithFlashvarsInSSBP
[65]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;--------------------------------------------------------------------
[568]98; .GetSdpCommandFunctionToAXwithFlashvarsInSSBP
[65]99; Parameters:
100; SS:BP: Ptr to FLASHVARS
101; Returns:
[568]102; AX: Ptr to SDP Command function
[65]103; Corrupts registers:
104; BX, SI
105;--------------------------------------------------------------------
106ALIGN JUMP_ALIGN
[568]107.GetSdpCommandFunctionToAXwithFlashvarsInSSBP:
[293]108 eMOVZX bx, [bp+FLASHVARS.bEepromSdpCommand]
[65]109 mov si, [cs:bx+.rgpSdpCommandToEepromTypeLookupTable]
110 mov bl, [bp+FLASHVARS.bEepromType]
[568]111 mov ax, [cs:bx+si]
[65]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
[159]122 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.2864_8kiB_MOD
[65]123 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.28256_32kiB
124 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.28512_64kiB
[620]125 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.SST_39SF
[65]126.rgfnEnableSdpAndFlash: ; SDP_COMMAND.enable
127 dw WriteSdpEnableCommandFor2816 ; EEPROM_TYPE.2816_2kiB
128 dw WriteSdpEnableCommandFor2864 ; EEPROM_TYPE.2864_8kiB
[159]129 dw WriteSdpEnableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD
[65]130 dw WriteSdpEnableCommandFor28256or28512 ; EEPROM_TYPE.28256_32kiB
131 dw WriteSdpEnableCommandFor28256or28512 ; EEPROM_TYPE.28512_64kiB
[620]132 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.SST_39SF
[65]133.rgfnDisableSdpAndFlash: ; SDP_COMMAND.disable
134 dw WriteSdpDisableCommandFor2816 ; EEPROM_TYPE.2816_2kiB
135 dw WriteSdpDisableCommandFor2864 ; EEPROM_TYPE.2864_8kiB
[159]136 dw WriteSdpDisableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD
[65]137 dw WriteSdpDisableCommandFor28256or28512 ; EEPROM_TYPE.28256_32kiB
138 dw WriteSdpDisableCommandFor28256or28512 ; EEPROM_TYPE.28512_64kiB
[620]139 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.SST_39SF
[65]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:
[568]189; AX
[65]190;--------------------------------------------------------------------
191%macro DISABLE_SDP 2
[568]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
[65]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
[159]219 jmp ReturnFromSdpCommand
[65]220
221ALIGN JUMP_ALIGN
[159]222WriteSdpEnableCommandFor2864mod:
223 ENABLE_SDP 155Ch, 0AA3h
[568]224 jmp SHORT ReturnFromSdpCommand
[159]225
226ALIGN JUMP_ALIGN
[65]227WriteSdpEnableCommandFor28256or28512:
228 ENABLE_SDP 5555h, 2AAAh
[568]229 jmp SHORT ReturnFromSdpCommand
[65]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
[159]243WriteSdpDisableCommandFor2864mod:
244 DISABLE_SDP 155Ch, 0AA3h
245 jmp SHORT ReturnFromSdpCommand
246
247ALIGN JUMP_ALIGN
[65]248WriteSdpDisableCommandFor28256or28512:
249 DISABLE_SDP 5555h, 2AAAh
250 jmp SHORT ReturnFromSdpCommand
251
[568]252DoNotWriteAnySdpCommand EQU ReturnFromSdpCommand
[65]253
[568]254
[65]255;--------------------------------------------------------------------
[568]256; WriteAllChangedBytesFromPageToEeprom
[65]257; Parameters:
[568]258; AX: Offset to SDP command function
259; BX: Offset to next destination byte
[65]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:
[568]268; AX, BX, CX, DX, SI, DI, DS, ES
[65]269;--------------------------------------------------------------------
270ALIGN JUMP_ALIGN
271WriteAllChangedBytesFromPageToEeprom:
[568]272 mov dx, [bp+FLASHVARS.fpNextSourcePage+2] ; DX = Source segment
[65]273 mov ds, [bp+FLASHVARS.fpNextDestinationPage+2] ; DS = EEPROM segment
274 cli ; Disable interrupts
[568]275 jmp ax ; Write SDP command (once to the beginning of page)
[65]276ALIGN JUMP_ALIGN
277ReturnFromSdpCommand:
[568]278 mov ds, dx ; DS:SI now points to source byte
[65]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
[568]288 mov ds, dx ; Restore DS
[65]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
[593]297 ; Fall to .WaitUntilEepromPageWriteHasCompleted
[65]298
299
300;--------------------------------------------------------------------
[596]301; .WaitUntilEepromPageWriteHasCompleted
[65]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;--------------------------------------------------------------------
[593]310.WaitUntilEepromPageWriteHasCompleted:
[592]311 push ss
312 pop ds
313 lea bx, [bp+FLASHVARS.wTimeoutCounter]
314 mov ax, EEPROM_POLLING_TIMEOUT_TICKS
315 call TimerTicks_InitializeTimeoutFromAX
[65]316 mov es, [bp+FLASHVARS.fpNextDestinationPage+2]
317 mov di, [bp+FLASHVARS.wLastOffsetWritten]
318ALIGN JUMP_ALIGN
319.PollEeprom:
[592]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
[65]323 call TimerTicks_GetTimeoutTicksLeftToAXfromDSBX
324 jnc SHORT .PollEeprom
[592]325ALIGN JUMP_ALIGN, ret
[65]326.PageWriteCompleted:
327 ret
328
[593]329
[65]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.