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

Last change on this file since 568 was 568, checked in by krille_n_@…, 9 years ago

Changes:

  • SerDrive: Using named pipe mode (serdrive -p) now works under Windows XP/2000/Server 2003.
  • checksum.pl: Added a compatibility fix for 3Com 3C503 cards.
  • XTIDECFG will now scan every possible segment address to find and load the BIOS and/or its settings from EEPROM. This should simplify things for people using combined option ROMs.
  • Fixed a bug from r521 in BootSector.asm where the BIOS would not display a timeout error if it failed to load the boot sector from harddrive.
  • Fixed a bug from r541 in CompatibleDPT.asm where CompatibleDPT_CreateDeviceParameterTableExtensionToESBXfromDPTinDSSI would generate an invalid checksum in the DPTE.
  • Optimizations and other fixes.
File size: 11.8 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    cld
81    call    AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
82    je      SHORT .NoNeedToFlashThePage ; CF cleared
83
84    push    cx
85    call    .GetSdpCommandFunctionToAXwithFlashvarsInSSBP
86    mov     cx, [bp+FLASHVARS.wEepromPageSize]
87    mov     si, [bp+FLASHVARS.fpNextSourcePage]
88    les     di, [bp+FLASHVARS.fpNextComparisonPage]
89    mov     bx, [bp+FLASHVARS.fpNextDestinationPage]
90    call    WriteAllChangedBytesFromPageToEeprom
91    pop     cx
92.NoNeedToFlashThePage:
93    ret
94
95;--------------------------------------------------------------------
96; .GetSdpCommandFunctionToAXwithFlashvarsInSSBP
97;   Parameters:
98;       SS:BP:  Ptr to FLASHVARS
99;   Returns:
100;       AX:     Ptr to SDP Command function
101;   Corrupts registers:
102;       BX, SI
103;--------------------------------------------------------------------
104ALIGN JUMP_ALIGN
105.GetSdpCommandFunctionToAXwithFlashvarsInSSBP:
106    eMOVZX  bx, [bp+FLASHVARS.bEepromSdpCommand]
107    mov     si, [cs:bx+.rgpSdpCommandToEepromTypeLookupTable]
108    mov     bl, [bp+FLASHVARS.bEepromType]
109    mov     ax, [cs:bx+si]
110    ret
111
112ALIGN WORD_ALIGN
113.rgpSdpCommandToEepromTypeLookupTable:
114    dw      .rgfnFlashWithoutSDP                    ; SDP_COMMAND.none
115    dw      .rgfnEnableSdpAndFlash                  ; SDP_COMMAND.enable
116    dw      .rgfnDisableSdpAndFlash                 ; SDP_COMMAND.disable
117.rgfnFlashWithoutSDP:       ; SDP_COMMAND.none
118    dw      DoNotWriteAnySdpCommand                 ; EEPROM_TYPE.2816_2kiB
119    dw      DoNotWriteAnySdpCommand                 ; EEPROM_TYPE.2864_8kiB
120    dw      DoNotWriteAnySdpCommand                 ; EEPROM_TYPE.2864_8kiB_MOD
121    dw      DoNotWriteAnySdpCommand                 ; EEPROM_TYPE.28256_32kiB
122    dw      DoNotWriteAnySdpCommand                 ; EEPROM_TYPE.28512_64kiB
123.rgfnEnableSdpAndFlash:     ; SDP_COMMAND.enable
124    dw      WriteSdpEnableCommandFor2816            ; EEPROM_TYPE.2816_2kiB
125    dw      WriteSdpEnableCommandFor2864            ; EEPROM_TYPE.2864_8kiB
126    dw      WriteSdpEnableCommandFor2864mod         ; EEPROM_TYPE.2864_8kiB_MOD
127    dw      WriteSdpEnableCommandFor28256or28512    ; EEPROM_TYPE.28256_32kiB
128    dw      WriteSdpEnableCommandFor28256or28512    ; EEPROM_TYPE.28512_64kiB
129.rgfnDisableSdpAndFlash:    ; SDP_COMMAND.disable
130    dw      WriteSdpDisableCommandFor2816           ; EEPROM_TYPE.2816_2kiB
131    dw      WriteSdpDisableCommandFor2864           ; EEPROM_TYPE.2864_8kiB
132    dw      WriteSdpDisableCommandFor2864mod        ; EEPROM_TYPE.2864_8kiB_MOD
133    dw      WriteSdpDisableCommandFor28256or28512   ; EEPROM_TYPE.28256_32kiB
134    dw      WriteSdpDisableCommandFor28256or28512   ; EEPROM_TYPE.28512_64kiB
135
136
137;--------------------------------------------------------------------
138; AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
139;   Parameters:
140;       SS:BP:  Ptr to FLASHVARS
141;   Returns:
142;       ZF:     Set if pages are equal
143;               Cleared if pages are not equal
144;   Corrupts registers:
145;       SI, DI
146;--------------------------------------------------------------------
147ALIGN JUMP_ALIGN
148AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP:
149    push    cx
150    mov     cx, [bp+FLASHVARS.wEepromPageSize]
151    lds     si, [bp+FLASHVARS.fpNextSourcePage]
152    les     di, [bp+FLASHVARS.fpNextDestinationPage]
153    repe cmpsb
154    pop     cx
155    ret
156
157
158;--------------------------------------------------------------------
159; ENABLE_SDP
160;   Parameters:
161;       %1:     Offset for first command byte
162;       %2:     Offset for second command byte
163;       DS:     Segment to beginning of EEPROM
164;   Returns:
165;       Nothing
166;   Corrupts registers:
167;       Nothing
168;--------------------------------------------------------------------
169%macro ENABLE_SDP 2
170    mov     BYTE [%1], 0AAh
171    mov     BYTE [%2], 55h
172    mov     BYTE [%1], 0A0h
173%endmacro
174
175;--------------------------------------------------------------------
176; DISABLE_SDP
177;   Parameters:
178;       %1:     Offset for first command byte
179;       %2:     Offset for second command byte
180;       DS:     Segment to beginning of EEPROM
181;   Returns:
182;       Nothing
183;   Corrupts registers:
184;       AX
185;--------------------------------------------------------------------
186%macro DISABLE_SDP 2
187    mov     ax, 80AAh
188%%Again:
189    mov     [%1], al        ; 0AAh
190    shr     al, 1
191    mov     [%2], al        ; 55h
192    mov     [%1], ah        ; 80h/20h
193    xor     ax, 0A0FFh
194    jns     SHORT %%Again
195%endmacro
196
197;--------------------------------------------------------------------
198; SDP Command Functions
199;   Parameters:
200;       DS:     Segment to beginning of EEPROM
201;   Returns:
202;       Nothing but jumps to WriteActualDataByteAfterSdpCommand
203;   Corrupts registers:
204;       Nothing
205;--------------------------------------------------------------------
206ALIGN JUMP_ALIGN
207WriteSdpEnableCommandFor2816:
208    ENABLE_SDP 555h, 2AAh
209    jmp     ReturnFromSdpCommand
210
211ALIGN JUMP_ALIGN
212WriteSdpEnableCommandFor2864:
213    ENABLE_SDP 1555h, 0AAAh
214    jmp     ReturnFromSdpCommand
215
216ALIGN JUMP_ALIGN
217WriteSdpEnableCommandFor2864mod:
218    ENABLE_SDP 155Ch, 0AA3h
219    jmp     SHORT ReturnFromSdpCommand
220
221ALIGN JUMP_ALIGN
222WriteSdpEnableCommandFor28256or28512:
223    ENABLE_SDP 5555h, 2AAAh
224    jmp     SHORT ReturnFromSdpCommand
225
226
227ALIGN JUMP_ALIGN
228WriteSdpDisableCommandFor2816:
229    DISABLE_SDP 555h, 2AAh
230    jmp     SHORT ReturnFromSdpCommand
231
232ALIGN JUMP_ALIGN
233WriteSdpDisableCommandFor2864:
234    DISABLE_SDP 1555h, 0AAAh
235    jmp     SHORT ReturnFromSdpCommand
236
237ALIGN JUMP_ALIGN
238WriteSdpDisableCommandFor2864mod:
239    DISABLE_SDP 155Ch, 0AA3h
240    jmp     SHORT ReturnFromSdpCommand
241
242ALIGN JUMP_ALIGN
243WriteSdpDisableCommandFor28256or28512:
244    DISABLE_SDP 5555h, 2AAAh
245    jmp     SHORT ReturnFromSdpCommand
246
247DoNotWriteAnySdpCommand EQU ReturnFromSdpCommand
248
249
250;--------------------------------------------------------------------
251; WriteAllChangedBytesFromPageToEeprom
252;   Parameters:
253;       AX:     Offset to SDP command function
254;       BX:     Offset to next destination byte
255;       CX:     Number of bytes left to write
256;       SI:     Offset to next source byte
257;       ES:DI:  Ptr to next comparison byte
258;       SS:BP:  Ptr to FLASHVARS
259;   Returns:
260;       CF:     Set if polling timeout error
261;               Cleared if page written successfully
262;   Corrupts registers:
263;       AX, BX, CX, DX, SI, DI, DS, ES
264;--------------------------------------------------------------------
265ALIGN JUMP_ALIGN
266WriteAllChangedBytesFromPageToEeprom:
267    mov     dx, [bp+FLASHVARS.fpNextSourcePage+2]       ; DX = Source segment
268    mov     ds, [bp+FLASHVARS.fpNextDestinationPage+2]  ; DS = EEPROM segment
269    cli                     ; Disable interrupts
270    jmp     ax              ; Write SDP command (once to the beginning of page)
271ALIGN JUMP_ALIGN
272ReturnFromSdpCommand:
273    mov     ds, dx          ; DS:SI now points to source byte
274
275ALIGN JUMP_ALIGN
276.WriteActualDataByteAfterSdpCommand:
277    lodsb                   ; Load source byte to AL
278    scasb                   ; Compare source byte to comparison byte
279    je      SHORT .NoChangesForThisByte
280
281    mov     ds, [bp+FLASHVARS.fpNextDestinationPage+2]  ; DS:BX now points to EEPROM
282    mov     [bx], al        ; Write byte to EEPROM
283    mov     ds, dx          ; Restore DS
284    mov     [bp+FLASHVARS.wLastOffsetWritten], bx
285    mov     [bp+FLASHVARS.bLastByteWritten], al
286
287ALIGN JUMP_ALIGN
288.NoChangesForThisByte:
289    inc     bx              ; Increment destination offset
290    loop    .WriteActualDataByteAfterSdpCommand
291    sti                     ; Enable interrupts
292    ; Fall to WaitUntilEepromPageWriteHasCompleted
293
294
295;--------------------------------------------------------------------
296; WaitUntilEepromPageWriteHasCompleted
297;   Parameters:
298;       SS:BP:  Ptr to FLASHVARS
299;   Returns:
300;       CF:     Set if polling timeout error
301;               Cleared if page written successfully
302;   Corrupts registers:
303;       AX, BX, DI, DS, ES
304;--------------------------------------------------------------------
305ALIGN JUMP_ALIGN
306WaitUntilEepromPageWriteHasCompleted:
307    call    .InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP
308    mov     es, [bp+FLASHVARS.fpNextDestinationPage+2]
309    mov     di, [bp+FLASHVARS.wLastOffsetWritten]
310ALIGN JUMP_ALIGN
311.PollEeprom:
312    call    .HasWriteCycleCompleted
313    je      SHORT .PageWriteCompleted   ; CF cleared
314    call    TimerTicks_GetTimeoutTicksLeftToAXfromDSBX
315    jnc     SHORT .PollEeprom
316ALIGN JUMP_ALIGN
317.PageWriteCompleted:
318    ret
319
320;--------------------------------------------------------------------
321; .InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP
322;   Parameters:
323;       SS:BP:  Ptr to FLASHVARS
324;   Returns:
325;       DS:BX:  Ptr to timeout counter variable
326;   Corrupts registers:
327;       AX
328;--------------------------------------------------------------------
329ALIGN JUMP_ALIGN
330.InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP:
331    push    ss
332    pop     ds
333    lea     bx, [bp+FLASHVARS.wTimeoutCounter]
334    mov     ax, EEPROM_POLLING_TIMEOUT_TICKS
335    jmp     TimerTicks_InitializeTimeoutFromAX
336
337;--------------------------------------------------------------------
338; .HasWriteCycleCompleted
339;   Parameters:
340;       ES:DI:  Ptr to last written byte in EEPROM
341;       SS:BP:  Ptr to FLASHVARS
342;   Returns:
343;       ZF:     Set if write cycle has completed
344;               Cleared if write cycle in progress
345;   Corrupts registers:
346;       AX
347;--------------------------------------------------------------------
348ALIGN JUMP_ALIGN
349.HasWriteCycleCompleted:
350    mov     ah, [es:di]     ; Load byte from EEPROM
351    mov     al, [bp+FLASHVARS.bLastByteWritten]
352    and     ax, 8080h       ; Clear all but bit 7 from both bytes
353    cmp     al, ah          ; Set ZF if high bits are the same
354    ret
355
356
357;--------------------------------------------------------------------
358; DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP
359;   Parameters:
360;       CX:     Number of pages left to flash
361;       SS:BP:  Ptr to FLASHVARS
362;   Returns:
363;       Nothing
364;   Corrupts registers:
365;       AX, DI
366;--------------------------------------------------------------------
367ALIGN JUMP_ALIGN
368DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP:
369    push    bp
370
371    mov     ax, [bp+FLASHVARS.wPagesToFlash]
372    sub     ax, cx
373    mov     bp, [bp+FLASHVARS.wProgressUpdateParam] ; BP now has MENU handle
374    CALL_MENU_LIBRARY SetProgressValueFromAX
375
376    pop     bp
377    ret
Note: See TracBrowser for help on using the repository browser.