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

Last change on this file since 630 was 630, checked in by Krister Nordvall, 8 days ago

Changes:

  • Changed the g_szPCFlashSuccessful string in XTIDECFG to reflect the reality - it turns out ANY key was limited to just ENTER or ESC.
  • Removed the NEC V-specific optimization I added in r602 because NEC's documentation completely fails to mention that the ROL4 instruction also changes the high nibble of AL. Huge thanks to vcfed-member dreNorteR for discovering this and also for suggesting an optimization to the physical address conversion code in IdeTransfer.asm.
  • Made some changes to the OUTPUT_AL_TO_IDE_REGISTER and OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER macros as an optimization. This saves 15+12 bytes in builds without MODULE_8BIT_IDE (e.g. the PS/2 builds).
  • Other minor optimizations and cleanups.
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-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
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 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;--------------------------------------------------------------------
79ALIGN JUMP_ALIGN
80Flash_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;--------------------------------------------------------------------
107ALIGN 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
115ALIGN 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;--------------------------------------------------------------------
153ALIGN JUMP_ALIGN
154AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP:
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;--------------------------------------------------------------------
212ALIGN JUMP_ALIGN
213WriteSdpEnableCommandFor2816:
214 ENABLE_SDP 555h, 2AAh
215 jmp ReturnFromSdpCommand
216
217ALIGN JUMP_ALIGN
218WriteSdpEnableCommandFor2864:
219 ENABLE_SDP 1555h, 0AAAh
220 jmp ReturnFromSdpCommand
221
222ALIGN JUMP_ALIGN
223WriteSdpEnableCommandFor2864mod:
224 ENABLE_SDP 155Ch, 0AA3h
225 jmp SHORT ReturnFromSdpCommand
226
227ALIGN JUMP_ALIGN
228WriteSdpEnableCommandFor28256or28512:
229 ENABLE_SDP 5555h, 2AAAh
230 jmp SHORT ReturnFromSdpCommand
231
232
233ALIGN JUMP_ALIGN
234WriteSdpDisableCommandFor2816:
235 DISABLE_SDP 555h, 2AAh
236 jmp SHORT ReturnFromSdpCommand
237
238ALIGN JUMP_ALIGN
239WriteSdpDisableCommandFor2864:
240 DISABLE_SDP 1555h, 0AAAh
241 jmp SHORT ReturnFromSdpCommand
242
243ALIGN JUMP_ALIGN
244WriteSdpDisableCommandFor2864mod:
245 DISABLE_SDP 155Ch, 0AA3h
246 jmp SHORT ReturnFromSdpCommand
247
248ALIGN JUMP_ALIGN
249WriteSdpDisableCommandFor28256or28512:
250 DISABLE_SDP 5555h, 2AAAh
251 jmp SHORT ReturnFromSdpCommand
252
253DoNotWriteAnySdpCommand 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;--------------------------------------------------------------------
271ALIGN JUMP_ALIGN
272WriteAllChangedBytesFromPageToEeprom:
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)
277ALIGN JUMP_ALIGN
278ReturnFromSdpCommand:
279 mov ds, dx ; DS:SI now points to source byte
280
281ALIGN 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
293ALIGN 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]
319ALIGN 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
326ALIGN 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;--------------------------------------------------------------------
341ALIGN JUMP_ALIGN
342DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP:
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
Note: See TracBrowser for help on using the repository browser.