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

Last change on this file since 372 was 370, checked in by krille_n_@…, 13 years ago

Changes:

  • Added some missing PIO mode timings to ATA_ID.inc (based on info from http://www.singlix.net/specs/cfspc4_0.pdf)
  • Updated Configuration_FullMode.txt but it may need additional changes as the Tandy info doesn't match the wiki.
  • Optimizations.
  • Excluded some unused code from XTIDECFG.
File size: 11.1 KB
Line 
1; Project name : XTIDE Universal BIOS Configurator v2
2; Description : Functions for flashing the EEPROM.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Flash_EepromWithFlashvarsInDSSI
9; Parameters:
10; DS:SI: Ptr to FLASHVARS
11; Returns:
12; FLASHVARS.flashResult
13; Corrupts registers:
14; All, including segments
15;--------------------------------------------------------------------
16ALIGN JUMP_ALIGN
17Flash_EepromWithFlashvarsInDSSI:
18 mov [si+FLASHVARS.wProgressUpdateParam], bp ; Store handle to progress DIALOG
19 mov bp, si ; Flashvars now in SS:BP
20 mov cx, [bp+FLASHVARS.wPagesToFlash]
21ALIGN JUMP_ALIGN
22.FlashNextPage:
23 call DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP
24 call Flash_SinglePageWithFlashvarsInSSBP
25 jc SHORT .PollingError
26 call AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
27 jne SHORT .DataVerifyError
28
29 mov ax, [bp+FLASHVARS.wEepromPageSize]
30 add [bp+FLASHVARS.fpNextSourcePage], ax
31 add [bp+FLASHVARS.fpNextComparisonPage], ax
32 add [bp+FLASHVARS.fpNextDestinationPage], ax
33
34 loop .FlashNextPage
35%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
36%if FLASH_RESULT.success = 0 ; Just in case this should ever change
37 mov [bp+FLASHVARS.flashResult], cl
38%else
39 mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.success
40%endif
41%endif
42 ret
43
44.PollingError:
45 mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.PollingTimeoutError
46 ret
47.DataVerifyError:
48 mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.DataVerifyError
49 ret
50
51
52;--------------------------------------------------------------------
53; Flash_SinglePageWithFlashvarsInSSBP
54; Parameters:
55; SS:BP: Ptr to FLASHVARS
56; Returns:
57; CF: Set if polling timeout error
58; Cleared if page written successfully
59; Corrupts registers:
60; AX, BX, DX, SI, DI, DS, ES
61;--------------------------------------------------------------------
62ALIGN JUMP_ALIGN
63Flash_SinglePageWithFlashvarsInSSBP:
64 cld
65 call AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
66 je SHORT .NoNeedToFlashThePage ; CF cleared
67
68 push cx
69 call .GetSdpCommandFunctionToDXwithFlashvarsInSSBP
70 mov cx, [bp+FLASHVARS.wEepromPageSize]
71 mov si, [bp+FLASHVARS.fpNextSourcePage]
72 les di, [bp+FLASHVARS.fpNextComparisonPage]
73 mov bx, [bp+FLASHVARS.fpNextDestinationPage]
74 call WriteAllChangedBytesFromPageToEeprom
75 pop cx
76.NoNeedToFlashThePage:
77 ret
78
79;--------------------------------------------------------------------
80; .GetSdpCommandFunctionToDXwithFlashvarsInSSBP
81; Parameters:
82; SS:BP: Ptr to FLASHVARS
83; Returns:
84; DX: Ptr to SDP Command function
85; Corrupts registers:
86; BX, SI
87;--------------------------------------------------------------------
88ALIGN JUMP_ALIGN
89.GetSdpCommandFunctionToDXwithFlashvarsInSSBP:
90 eMOVZX bx, [bp+FLASHVARS.bEepromSdpCommand]
91 mov si, [cs:bx+.rgpSdpCommandToEepromTypeLookupTable]
92 mov bl, [bp+FLASHVARS.bEepromType]
93 mov dx, [cs:bx+si]
94 ret
95
96ALIGN WORD_ALIGN
97.rgpSdpCommandToEepromTypeLookupTable:
98 dw .rgfnFlashWithoutSDP ; SDP_COMMAND.none
99 dw .rgfnEnableSdpAndFlash ; SDP_COMMAND.enable
100 dw .rgfnDisableSdpAndFlash ; SDP_COMMAND.disable
101.rgfnFlashWithoutSDP: ; SDP_COMMAND.none
102 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.2816_2kiB
103 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.2864_8kiB
104 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.2864_8kiB_MOD
105 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.28256_32kiB
106 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.28512_64kiB
107.rgfnEnableSdpAndFlash: ; SDP_COMMAND.enable
108 dw WriteSdpEnableCommandFor2816 ; EEPROM_TYPE.2816_2kiB
109 dw WriteSdpEnableCommandFor2864 ; EEPROM_TYPE.2864_8kiB
110 dw WriteSdpEnableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD
111 dw WriteSdpEnableCommandFor28256or28512 ; EEPROM_TYPE.28256_32kiB
112 dw WriteSdpEnableCommandFor28256or28512 ; EEPROM_TYPE.28512_64kiB
113.rgfnDisableSdpAndFlash: ; SDP_COMMAND.disable
114 dw WriteSdpDisableCommandFor2816 ; EEPROM_TYPE.2816_2kiB
115 dw WriteSdpDisableCommandFor2864 ; EEPROM_TYPE.2864_8kiB
116 dw WriteSdpDisableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD
117 dw WriteSdpDisableCommandFor28256or28512 ; EEPROM_TYPE.28256_32kiB
118 dw WriteSdpDisableCommandFor28256or28512 ; EEPROM_TYPE.28512_64kiB
119
120
121;--------------------------------------------------------------------
122; AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
123; Parameters:
124; SS:BP: Ptr to FLASHVARS
125; Returns:
126; ZF: Set if pages are equal
127; Cleared if pages are not equal
128; Corrupts registers:
129; SI, DI
130;--------------------------------------------------------------------
131ALIGN JUMP_ALIGN
132AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP:
133 push cx
134 mov cx, [bp+FLASHVARS.wEepromPageSize]
135 lds si, [bp+FLASHVARS.fpNextSourcePage]
136 les di, [bp+FLASHVARS.fpNextDestinationPage]
137 repe cmpsb
138 pop cx
139 ret
140
141
142;--------------------------------------------------------------------
143; ENABLE_SDP
144; Parameters:
145; %1: Offset for first command byte
146; %2: Offset for second command byte
147; DS: Segment to beginning of EEPROM
148; Returns:
149; Nothing
150; Corrupts registers:
151; Nothing
152;--------------------------------------------------------------------
153%macro ENABLE_SDP 2
154 mov BYTE [%1], 0AAh
155 mov BYTE [%2], 55h
156 mov BYTE [%1], 0A0h
157%endmacro
158
159;--------------------------------------------------------------------
160; DISABLE_SDP
161; Parameters:
162; %1: Offset for first command byte
163; %2: Offset for second command byte
164; DS: Segment to beginning of EEPROM
165; Returns:
166; Nothing
167; Corrupts registers:
168; Nothing
169;--------------------------------------------------------------------
170%macro DISABLE_SDP 2
171 mov BYTE [%1], 0AAh
172 mov BYTE [%2], 55h
173 mov BYTE [%1], 80h
174 mov BYTE [%1], 0AAh
175 mov BYTE [%2], 55h
176 mov BYTE [%1], 20h
177%endmacro
178
179;--------------------------------------------------------------------
180; SDP Command Functions
181; Parameters:
182; DS: Segment to beginning of EEPROM
183; Returns:
184; Nothing but jumps to WriteActualDataByteAfterSdpCommand
185; Corrupts registers:
186; Nothing
187;--------------------------------------------------------------------
188ALIGN JUMP_ALIGN
189WriteSdpEnableCommandFor2816:
190 ENABLE_SDP 555h, 2AAh
191 jmp ReturnFromSdpCommand
192
193ALIGN JUMP_ALIGN
194WriteSdpEnableCommandFor2864:
195 ENABLE_SDP 1555h, 0AAAh
196 jmp ReturnFromSdpCommand
197
198ALIGN JUMP_ALIGN
199WriteSdpEnableCommandFor2864mod:
200 ENABLE_SDP 155Ch, 0AA3h
201 jmp ReturnFromSdpCommand
202
203ALIGN JUMP_ALIGN
204WriteSdpEnableCommandFor28256or28512:
205 ENABLE_SDP 5555h, 2AAAh
206 jmp ReturnFromSdpCommand
207
208
209ALIGN JUMP_ALIGN
210WriteSdpDisableCommandFor2816:
211 DISABLE_SDP 555h, 2AAh
212 jmp SHORT ReturnFromSdpCommand
213
214ALIGN JUMP_ALIGN
215WriteSdpDisableCommandFor2864:
216 DISABLE_SDP 1555h, 0AAAh
217 jmp SHORT ReturnFromSdpCommand
218
219ALIGN JUMP_ALIGN
220WriteSdpDisableCommandFor2864mod:
221 DISABLE_SDP 155Ch, 0AA3h
222 jmp SHORT ReturnFromSdpCommand
223
224ALIGN JUMP_ALIGN
225WriteSdpDisableCommandFor28256or28512:
226 DISABLE_SDP 5555h, 2AAAh
227DoNotWriteAnySdpCommand:
228 jmp SHORT ReturnFromSdpCommand
229
230
231;--------------------------------------------------------------------
232; WriteNextChangedByteFromPageToEeprom
233; Parameters:
234; CX: Number of bytes left to write
235; DX: Offset to SDP command function
236; BX: Offset to next destination byte
237; SI: Offset to next source byte
238; ES:DI: Ptr to next comparison byte
239; SS:BP: Ptr to FLASHVARS
240; Returns:
241; CF: Set if polling timeout error
242; Cleared if page written successfully
243; Corrupts registers:
244; AX, BX, CX, SI, DI, DS, ES
245;--------------------------------------------------------------------
246ALIGN JUMP_ALIGN
247WriteAllChangedBytesFromPageToEeprom:
248 mov ax, [bp+FLASHVARS.fpNextSourcePage+2] ; AX = Source segment
249 mov ds, [bp+FLASHVARS.fpNextDestinationPage+2] ; DS = EEPROM segment
250 cli ; Disable interrupts
251 jmp dx ; Write SDP command (once to the beginning of page)
252ALIGN JUMP_ALIGN
253ReturnFromSdpCommand:
254 mov ds, ax ; DS:SI now points to source byte
255
256ALIGN JUMP_ALIGN
257.WriteActualDataByteAfterSdpCommand:
258 lodsb ; Load source byte to AL
259 scasb ; Compare source byte to comparison byte
260 je SHORT .NoChangesForThisByte
261
262 mov ds, [bp+FLASHVARS.fpNextDestinationPage+2] ; DS:BX now points to EEPROM
263 mov [bx], al ; Write byte to EEPROM
264 mov ds, [bp+FLASHVARS.fpNextSourcePage+2] ; Restore DS
265 mov [bp+FLASHVARS.wLastOffsetWritten], bx
266 mov [bp+FLASHVARS.bLastByteWritten], al
267
268ALIGN JUMP_ALIGN
269.NoChangesForThisByte:
270 inc bx ; Increment destination offset
271 loop .WriteActualDataByteAfterSdpCommand
272 sti ; Enable interrupts
273 ; Fall to WaitUntilEepromPageWriteHasCompleted
274
275
276;--------------------------------------------------------------------
277; WaitUntilEepromPageWriteHasCompleted
278; Parameters:
279; SS:BP: Ptr to FLASHVARS
280; Returns:
281; CF: Set if polling timeout error
282; Cleared if page written successfully
283; Corrupts registers:
284; AX, BX, DI, DS, ES
285;--------------------------------------------------------------------
286ALIGN JUMP_ALIGN
287WaitUntilEepromPageWriteHasCompleted:
288 call .InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP
289 mov es, [bp+FLASHVARS.fpNextDestinationPage+2]
290 mov di, [bp+FLASHVARS.wLastOffsetWritten]
291ALIGN JUMP_ALIGN
292.PollEeprom:
293 call .HasWriteCycleCompleted
294 je SHORT .PageWriteCompleted ; CF cleared
295 call TimerTicks_GetTimeoutTicksLeftToAXfromDSBX
296 jnc SHORT .PollEeprom
297ALIGN JUMP_ALIGN
298.PageWriteCompleted:
299 ret
300
301;--------------------------------------------------------------------
302; .InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP
303; Parameters:
304; SS:BP: Ptr to FLASHVARS
305; Returns:
306; DS:BX: Ptr to timeout counter variable
307; Corrupts registers:
308; AX
309;--------------------------------------------------------------------
310ALIGN JUMP_ALIGN
311.InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP:
312 push ss
313 pop ds
314 lea bx, [bp+FLASHVARS.wTimeoutCounter]
315 mov ax, EEPROM_POLLING_TIMEOUT_TICKS
316 jmp TimerTicks_InitializeTimeoutFromAX
317
318;--------------------------------------------------------------------
319; .HasWriteCycleCompleted
320; Parameters:
321; ES:DI: Ptr to last written byte in EEPROM
322; SS:BP: Ptr to FLASHVARS
323; Returns:
324; ZF: Set if write cycle has completed
325; Cleared if write cycle in progress
326; Corrupts registers:
327; AX
328;--------------------------------------------------------------------
329ALIGN JUMP_ALIGN
330.HasWriteCycleCompleted:
331 mov ah, [es:di] ; Load byte from EEPROM
332 mov al, [bp+FLASHVARS.bLastByteWritten]
333 and ax, 8080h ; Clear all but bit 7 from both bytes
334 cmp al, ah ; Set ZF if high bits are the same
335 ret
336
337
338;--------------------------------------------------------------------
339; DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP
340; Parameters:
341; CX: Number of pages left to flash
342; SS:BP: Ptr to FLASHVARS
343; Returns:
344; Nothing
345; Corrupts registers:
346; AX, DI
347;--------------------------------------------------------------------
348ALIGN JUMP_ALIGN
349DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP:
350 push bp
351
352 mov ax, [bp+FLASHVARS.wPagesToFlash]
353 sub ax, cx
354 mov bp, [bp+FLASHVARS.wProgressUpdateParam] ; BP now has MENU handle
355 CALL_MENU_LIBRARY SetProgressValueFromAX
356
357 pop bp
358 ret
Note: See TracBrowser for help on using the repository browser.