source: xtideuniversalbios/tags/Configurator_for_v1.1.5/Src/Flash.asm@ 565

Last change on this file since 565 was 65, checked in by Tomi Tilli, 14 years ago

Changes to XTIDE Universal BIOS Configurator v2:

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