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

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

Commit 1/2 (Library, Configurators and Serial Server):

  • Changed Emulate.inc so that making 286 and 386 versions now works. Additionally, only one processor type define is needed in the makefile.
  • Minor optimizations.
  • Fixed spelling and did some cleaning.
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%if FLASH_RESULT.success = 0 ; Just in case this should ever change
36 mov [bp+FLASHVARS.flashResult], cl
37%else
38 mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.success
39%endif
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, [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.2864_8kiB_MOD
103 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.28256_32kiB
104 dw DoNotWriteAnySdpCommand ; EEPROM_TYPE.28512_64kiB
105.rgfnEnableSdpAndFlash: ; SDP_COMMAND.enable
106 dw WriteSdpEnableCommandFor2816 ; EEPROM_TYPE.2816_2kiB
107 dw WriteSdpEnableCommandFor2864 ; EEPROM_TYPE.2864_8kiB
108 dw WriteSdpEnableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD
109 dw WriteSdpEnableCommandFor28256or28512 ; EEPROM_TYPE.28256_32kiB
110 dw WriteSdpEnableCommandFor28256or28512 ; EEPROM_TYPE.28512_64kiB
111.rgfnDisableSdpAndFlash: ; SDP_COMMAND.disable
112 dw WriteSdpDisableCommandFor2816 ; EEPROM_TYPE.2816_2kiB
113 dw WriteSdpDisableCommandFor2864 ; EEPROM_TYPE.2864_8kiB
114 dw WriteSdpDisableCommandFor2864mod ; EEPROM_TYPE.2864_8kiB_MOD
115 dw WriteSdpDisableCommandFor28256or28512 ; EEPROM_TYPE.28256_32kiB
116 dw WriteSdpDisableCommandFor28256or28512 ; EEPROM_TYPE.28512_64kiB
117
118
119;--------------------------------------------------------------------
120; AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
121; Parameters:
122; SS:BP: Ptr to FLASHVARS
123; Returns:
124; ZF: Set if pages are equal
125; Cleared if pages are not equal
126; Corrupts registers:
127; SI, DI
128;--------------------------------------------------------------------
129ALIGN JUMP_ALIGN
130AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP:
131 push cx
132 mov cx, [bp+FLASHVARS.wEepromPageSize]
133 lds si, [bp+FLASHVARS.fpNextSourcePage]
134 les di, [bp+FLASHVARS.fpNextDestinationPage]
135 repe cmpsb
136 pop cx
137 ret
138
139
140;--------------------------------------------------------------------
141; ENABLE_SDP
142; Parameters:
143; %1: Offset for first command byte
144; %2: Offset for second command byte
145; DS: Segment to beginning of EEPROM
146; Returns:
147; Nothing
148; Corrupts registers:
149; Nothing
150;--------------------------------------------------------------------
151%macro ENABLE_SDP 2
152 mov BYTE [%1], 0AAh
153 mov BYTE [%2], 55h
154 mov BYTE [%1], 0A0h
155%endmacro
156
157;--------------------------------------------------------------------
158; DISABLE_SDP
159; Parameters:
160; %1: Offset for first command byte
161; %2: Offset for second command byte
162; DS: Segment to beginning of EEPROM
163; Returns:
164; Nothing
165; Corrupts registers:
166; Nothing
167;--------------------------------------------------------------------
168%macro DISABLE_SDP 2
169 mov BYTE [%1], 0AAh
170 mov BYTE [%2], 55h
171 mov BYTE [%1], 80h
172 mov BYTE [%1], 0AAh
173 mov BYTE [%2], 55h
174 mov BYTE [%1], 20h
175%endmacro
176
177;--------------------------------------------------------------------
178; SDP Command Functions
179; Parameters:
180; DS: Segment to beginning of EEPROM
181; Returns:
182; Nothing but jumps to WriteActualDataByteAfterSdpCommand
183; Corrupts registers:
184; Nothing
185;--------------------------------------------------------------------
186ALIGN JUMP_ALIGN
187WriteSdpEnableCommandFor2816:
188 ENABLE_SDP 555h, 2AAh
189 jmp ReturnFromSdpCommand
190
191ALIGN JUMP_ALIGN
192WriteSdpEnableCommandFor2864:
193 ENABLE_SDP 1555h, 0AAAh
194 jmp ReturnFromSdpCommand
195
196ALIGN JUMP_ALIGN
197WriteSdpEnableCommandFor2864mod:
198 ENABLE_SDP 155Ch, 0AA3h
199 jmp ReturnFromSdpCommand
200
201ALIGN JUMP_ALIGN
202WriteSdpEnableCommandFor28256or28512:
203 ENABLE_SDP 5555h, 2AAAh
204 jmp ReturnFromSdpCommand
205
206
207ALIGN JUMP_ALIGN
208WriteSdpDisableCommandFor2816:
209 DISABLE_SDP 555h, 2AAh
210 jmp SHORT ReturnFromSdpCommand
211
212ALIGN JUMP_ALIGN
213WriteSdpDisableCommandFor2864:
214 DISABLE_SDP 1555h, 0AAAh
215 jmp SHORT ReturnFromSdpCommand
216
217ALIGN JUMP_ALIGN
218WriteSdpDisableCommandFor2864mod:
219 DISABLE_SDP 155Ch, 0AA3h
220 jmp SHORT ReturnFromSdpCommand
221
222ALIGN JUMP_ALIGN
223WriteSdpDisableCommandFor28256or28512:
224 DISABLE_SDP 5555h, 2AAAh
225DoNotWriteAnySdpCommand:
226 jmp SHORT ReturnFromSdpCommand
227
228
229;--------------------------------------------------------------------
230; WriteNextChangedByteFromPageToEeprom
231; Parameters:
232; CX: Number of bytes left to write
233; DX: Offset to SDP command function
234; BX: Offset to next destination byte
235; SI: Offset to next source byte
236; ES:DI: Ptr to next comparison byte
237; SS:BP: Ptr to FLASHVARS
238; Returns:
239; CF: Set if polling timeout error
240; Cleared if page written successfully
241; Corrupts registers:
242; AX, BX, CX, SI, DI, DS, ES
243;--------------------------------------------------------------------
244ALIGN JUMP_ALIGN
245WriteAllChangedBytesFromPageToEeprom:
246 mov ax, [bp+FLASHVARS.fpNextSourcePage+2] ; AX = Source segment
247 mov ds, [bp+FLASHVARS.fpNextDestinationPage+2] ; DS = EEPROM segment
248 cli ; Disable interrupts
249 jmp dx ; Write SDP command (once to the beginning of page)
250ALIGN JUMP_ALIGN
251ReturnFromSdpCommand:
252 mov ds, ax ; DS:SI now points to source byte
253
254ALIGN JUMP_ALIGN
255.WriteActualDataByteAfterSdpCommand:
256 lodsb ; Load source byte to AL
257 scasb ; Compare source byte to comparison byte
258 je SHORT .NoChangesForThisByte
259
260 mov ds, [bp+FLASHVARS.fpNextDestinationPage+2] ; DS:BX now points to EEPROM
261 mov [bx], al ; Write byte to EEPROM
262 mov ds, [bp+FLASHVARS.fpNextSourcePage+2] ; Restore DS
263 mov [bp+FLASHVARS.wLastOffsetWritten], bx
264 mov [bp+FLASHVARS.bLastByteWritten], al
265
266ALIGN JUMP_ALIGN
267.NoChangesForThisByte:
268 inc bx ; Increment destination offset
269 loop .WriteActualDataByteAfterSdpCommand
270 sti ; Enable interrupts
271 ; Fall to WaitUntilEepromPageWriteHasCompleted
272
273
274;--------------------------------------------------------------------
275; WaitUntilEepromPageWriteHasCompleted
276; Parameters:
277; SS:BP: Ptr to FLASHVARS
278; Returns:
279; CF: Set if polling timeout error
280; Cleared if page written successfully
281; Corrupts registers:
282; AX, BX, DI, DS, ES
283;--------------------------------------------------------------------
284ALIGN JUMP_ALIGN
285WaitUntilEepromPageWriteHasCompleted:
286 call .InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP
287 mov es, [bp+FLASHVARS.fpNextDestinationPage+2]
288 mov di, [bp+FLASHVARS.wLastOffsetWritten]
289ALIGN JUMP_ALIGN
290.PollEeprom:
291 call .HasWriteCycleCompleted
292 je SHORT .PageWriteCompleted ; CF cleared
293 call TimerTicks_GetTimeoutTicksLeftToAXfromDSBX
294 jnc SHORT .PollEeprom
295ALIGN JUMP_ALIGN
296.PageWriteCompleted:
297 ret
298
299;--------------------------------------------------------------------
300; .InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP
301; Parameters:
302; SS:BP: Ptr to FLASHVARS
303; Returns:
304; DS:BX: Ptr to timeout counter variable
305; Corrupts registers:
306; AX
307;--------------------------------------------------------------------
308ALIGN JUMP_ALIGN
309.InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP:
310 push ss
311 pop ds
312 lea bx, [bp+FLASHVARS.wTimeoutCounter]
313 mov ax, EEPROM_POLLING_TIMEOUT_TICKS
314 jmp TimerTicks_InitializeTimeoutFromAX
315
316;--------------------------------------------------------------------
317; .HasWriteCycleCompleted
318; Parameters:
319; ES:DI: Ptr to last written byte in EEPROM
320; SS:BP: Ptr to FLASHVARS
321; Returns:
322; ZF: Set if write cycle has completed
323; Cleared if write cycle in progress
324; Corrupts registers:
325; AX
326;--------------------------------------------------------------------
327ALIGN JUMP_ALIGN
328.HasWriteCycleCompleted:
329 mov ah, [es:di] ; Load byte from EEPROM
330 mov al, [bp+FLASHVARS.bLastByteWritten]
331 and ax, 8080h ; Clear all but bit 7 from both bytes
332 cmp al, ah ; Set ZF if high bits are the same
333 ret
334
335
336;--------------------------------------------------------------------
337; DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP
338; Parameters:
339; CX: Number of pages left to flash
340; SS:BP: Ptr to FLASHVARS
341; Returns:
342; Nothing
343; Corrupts registers:
344; AX, DI
345;--------------------------------------------------------------------
346ALIGN JUMP_ALIGN
347DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP:
348 push bp
349
350 mov ax, [bp+FLASHVARS.wPagesToFlash]
351 sub ax, cx
352 mov bp, [bp+FLASHVARS.wProgressUpdateParam] ; BP now has MENU handle
353 CALL_MENU_LIBRARY SetProgressValueFromAX
354
355 pop bp
356 ret
Note: See TracBrowser for help on using the repository browser.