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

Last change on this file since 610 was 596, checked in by Krister Nordvall, 6 years ago

Changes:

  • Made changes to HotkeyBar.asm to give the Boot Menu and Hotkey Bar a more consistent look. It will probably seem a bit strange at first to people used to the classic theme.
  • Added the missing parts of USE_NEC_V that should have been committed with the rest in r593.
  • Removed DEFINES_ALL_FEATURES from the BIOS makefile. It didn't work anymore and never really made sense anyway. Added all the official builds to 'make unused' instead which actually uncovered some unused code in the Tiny build.
  • XTIDECFG will no longer load color themes from unrecognized versions of the BIOS.
  • Other fixes in comments and some minor optimizations.
File size: 10.9 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.rgfnEnableSdpAndFlash: ; SDP_COMMAND.enable
126 dw WriteSdpEnableCommandFor2816 ; EEPROM_TYPE.2816_2kiB
127 dw WriteSdpEnableCommandFor2864 ; EEPROM_TYPE.2864_8kiB
128 dw WriteSdpEnableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD
129 dw WriteSdpEnableCommandFor28256or28512 ; EEPROM_TYPE.28256_32kiB
130 dw WriteSdpEnableCommandFor28256or28512 ; EEPROM_TYPE.28512_64kiB
131.rgfnDisableSdpAndFlash: ; SDP_COMMAND.disable
132 dw WriteSdpDisableCommandFor2816 ; EEPROM_TYPE.2816_2kiB
133 dw WriteSdpDisableCommandFor2864 ; EEPROM_TYPE.2864_8kiB
134 dw WriteSdpDisableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD
135 dw WriteSdpDisableCommandFor28256or28512 ; EEPROM_TYPE.28256_32kiB
136 dw WriteSdpDisableCommandFor28256or28512 ; EEPROM_TYPE.28512_64kiB
137
138
139;--------------------------------------------------------------------
140; AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
141; Parameters:
142; SS:BP: Ptr to FLASHVARS
143; Returns:
144; ZF: Set if pages are equal
145; Cleared if pages are not equal
146; Corrupts registers:
147; SI, DI
148;--------------------------------------------------------------------
149ALIGN JUMP_ALIGN
150AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP:
151 push cx
152 mov cx, [bp+FLASHVARS.wEepromPageSize]
153 lds si, [bp+FLASHVARS.fpNextSourcePage]
154 les di, [bp+FLASHVARS.fpNextDestinationPage]
155 repe cmpsb
156 pop cx
157 ret
158
159
160;--------------------------------------------------------------------
161; ENABLE_SDP
162; Parameters:
163; %1: Offset for first command byte
164; %2: Offset for second command byte
165; DS: Segment to beginning of EEPROM
166; Returns:
167; Nothing
168; Corrupts registers:
169; Nothing
170;--------------------------------------------------------------------
171%macro ENABLE_SDP 2
172 mov BYTE [%1], 0AAh
173 mov BYTE [%2], 55h
174 mov BYTE [%1], 0A0h
175%endmacro
176
177;--------------------------------------------------------------------
178; DISABLE_SDP
179; Parameters:
180; %1: Offset for first command byte
181; %2: Offset for second command byte
182; DS: Segment to beginning of EEPROM
183; Returns:
184; Nothing
185; Corrupts registers:
186; AX
187;--------------------------------------------------------------------
188%macro DISABLE_SDP 2
189 mov ax, 80AAh
190%%Again:
191 mov [%1], al ; 0AAh
192 shr al, 1
193 mov [%2], al ; 55h
194 mov [%1], ah ; 80h/20h
195 xor ax, 0A0FFh
196 jns SHORT %%Again
197%endmacro
198
199;--------------------------------------------------------------------
200; SDP Command Functions
201; Parameters:
202; DS: Segment to beginning of EEPROM
203; Returns:
204; Nothing but jumps to WriteActualDataByteAfterSdpCommand
205; Corrupts registers:
206; Nothing
207;--------------------------------------------------------------------
208ALIGN JUMP_ALIGN
209WriteSdpEnableCommandFor2816:
210 ENABLE_SDP 555h, 2AAh
211 jmp ReturnFromSdpCommand
212
213ALIGN JUMP_ALIGN
214WriteSdpEnableCommandFor2864:
215 ENABLE_SDP 1555h, 0AAAh
216 jmp ReturnFromSdpCommand
217
218ALIGN JUMP_ALIGN
219WriteSdpEnableCommandFor2864mod:
220 ENABLE_SDP 155Ch, 0AA3h
221 jmp SHORT ReturnFromSdpCommand
222
223ALIGN JUMP_ALIGN
224WriteSdpEnableCommandFor28256or28512:
225 ENABLE_SDP 5555h, 2AAAh
226 jmp SHORT ReturnFromSdpCommand
227
228
229ALIGN JUMP_ALIGN
230WriteSdpDisableCommandFor2816:
231 DISABLE_SDP 555h, 2AAh
232 jmp SHORT ReturnFromSdpCommand
233
234ALIGN JUMP_ALIGN
235WriteSdpDisableCommandFor2864:
236 DISABLE_SDP 1555h, 0AAAh
237 jmp SHORT ReturnFromSdpCommand
238
239ALIGN JUMP_ALIGN
240WriteSdpDisableCommandFor2864mod:
241 DISABLE_SDP 155Ch, 0AA3h
242 jmp SHORT ReturnFromSdpCommand
243
244ALIGN JUMP_ALIGN
245WriteSdpDisableCommandFor28256or28512:
246 DISABLE_SDP 5555h, 2AAAh
247 jmp SHORT ReturnFromSdpCommand
248
249DoNotWriteAnySdpCommand EQU ReturnFromSdpCommand
250
251
252;--------------------------------------------------------------------
253; WriteAllChangedBytesFromPageToEeprom
254; Parameters:
255; AX: Offset to SDP command function
256; BX: Offset to next destination byte
257; CX: Number of bytes left to write
258; SI: Offset to next source byte
259; ES:DI: Ptr to next comparison byte
260; SS:BP: Ptr to FLASHVARS
261; Returns:
262; CF: Set if polling timeout error
263; Cleared if page written successfully
264; Corrupts registers:
265; AX, BX, CX, DX, SI, DI, DS, ES
266;--------------------------------------------------------------------
267ALIGN JUMP_ALIGN
268WriteAllChangedBytesFromPageToEeprom:
269 mov dx, [bp+FLASHVARS.fpNextSourcePage+2] ; DX = Source segment
270 mov ds, [bp+FLASHVARS.fpNextDestinationPage+2] ; DS = EEPROM segment
271 cli ; Disable interrupts
272 jmp ax ; Write SDP command (once to the beginning of page)
273ALIGN JUMP_ALIGN
274ReturnFromSdpCommand:
275 mov ds, dx ; DS:SI now points to source byte
276
277ALIGN JUMP_ALIGN
278.WriteActualDataByteAfterSdpCommand:
279 lodsb ; Load source byte to AL
280 scasb ; Compare source byte to comparison byte
281 je SHORT .NoChangesForThisByte
282
283 mov ds, [bp+FLASHVARS.fpNextDestinationPage+2] ; DS:BX now points to EEPROM
284 mov [bx], al ; Write byte to EEPROM
285 mov ds, dx ; Restore DS
286 mov [bp+FLASHVARS.wLastOffsetWritten], bx
287 mov [bp+FLASHVARS.bLastByteWritten], al
288
289ALIGN JUMP_ALIGN
290.NoChangesForThisByte:
291 inc bx ; Increment destination offset
292 loop .WriteActualDataByteAfterSdpCommand
293 sti ; Enable interrupts
294 ; Fall to .WaitUntilEepromPageWriteHasCompleted
295
296
297;--------------------------------------------------------------------
298; .WaitUntilEepromPageWriteHasCompleted
299; Parameters:
300; SS:BP: Ptr to FLASHVARS
301; Returns:
302; CF: Set if polling timeout error
303; Cleared if page written successfully
304; Corrupts registers:
305; AX, BX, DI, DS, ES
306;--------------------------------------------------------------------
307.WaitUntilEepromPageWriteHasCompleted:
308 push ss
309 pop ds
310 lea bx, [bp+FLASHVARS.wTimeoutCounter]
311 mov ax, EEPROM_POLLING_TIMEOUT_TICKS
312 call TimerTicks_InitializeTimeoutFromAX
313 mov es, [bp+FLASHVARS.fpNextDestinationPage+2]
314 mov di, [bp+FLASHVARS.wLastOffsetWritten]
315ALIGN JUMP_ALIGN
316.PollEeprom:
317 mov al, [es:di] ; Load byte from EEPROM
318 xor al, [bp+FLASHVARS.bLastByteWritten] ; Clear SF if the most significant bits are the same
319 jns SHORT .PageWriteCompleted ; With CF cleared
320 call TimerTicks_GetTimeoutTicksLeftToAXfromDSBX
321 jnc SHORT .PollEeprom
322ALIGN JUMP_ALIGN, ret
323.PageWriteCompleted:
324 ret
325
326
327;--------------------------------------------------------------------
328; DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP
329; Parameters:
330; CX: Number of pages left to flash
331; SS:BP: Ptr to FLASHVARS
332; Returns:
333; Nothing
334; Corrupts registers:
335; AX, DI
336;--------------------------------------------------------------------
337ALIGN JUMP_ALIGN
338DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP:
339 push bp
340
341 mov ax, [bp+FLASHVARS.wPagesToFlash]
342 sub ax, cx
343 mov bp, [bp+FLASHVARS.wProgressUpdateParam] ; BP now has MENU handle
344 CALL_MENU_LIBRARY SetProgressValueFromAX
345
346 pop bp
347 ret
Note: See TracBrowser for help on using the repository browser.