source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/FlashMenu.asm@ 623

Last change on this file since 623 was 621, checked in by Krister Nordvall, 3 years ago

Changes:

  • Fixed three different bugs all causing the boot menu to show drives using IRQs even though the BIOS had been built without MODULE_IRQ.
  • Fixed two bugs in XTIDECFG where loading a BIOS from file and then loading the old settings from EEPROM would
    • overwrite ROMVARS.wFlags in the loaded BIOS file (in RAM). The possibly resulting mismatch of module flags could make it impossible to change settings for modules included in the BIOS or allow changing settings for modules not included in the BIOS.
    • not copy the color theme over to the loaded BIOS.
  • Also fixed two very minor bugs in XTIDECFG in BiosFile_LoadFileFromDSSItoRamBuffer and BiosFile_SaveRamBufferToFileInDSSI where the error handling in these routines would close whatever file handle that happened to match the error code returned by DOS in AX.
  • Made significant changes to the new flash ROM programming routines to reduce the size. Also fixed a minor bug that would cause the second verification to be skipped and return success when programming a 64 KB block of data.
  • Changed the custom BIOS build file names to the 8.3 format.
  • Changed some help strings in XTIDECFG to clarify things.
  • Other minor optimizations and fixes.
File size: 15.7 KB
Line 
1; Project name : XTIDE Universal BIOS Configurator v2
2; Description : "Flash EEPROM" menu structs and functions.
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 initialized data
21SECTION .data
22
23ALIGN WORD_ALIGN
24g_MenupageForFlashMenu:
25istruc MENUPAGE
26 at MENUPAGE.fnEnter, dw FlashMenu_EnterMenuOrModifyItemVisibility
27 at MENUPAGE.fnBack, dw MainMenu_EnterMenuOrModifyItemVisibility
28 at MENUPAGE.wMenuitems, dw 7
29iend
30
31g_MenuitemFlashBackToMainMenu:
32istruc MENUITEM
33 at MENUITEM.fnActivate, dw MainMenu_EnterMenuOrModifyItemVisibility
34 at MENUITEM.szName, dw g_szItemCfgBackToMain
35 at MENUITEM.szQuickInfo, dw g_szItemCfgBackToMain
36 at MENUITEM.szHelp, dw g_szItemCfgBackToMain
37 at MENUITEM.bFlags, db FLG_MENUITEM_VISIBLE
38 at MENUITEM.bType, db TYPE_MENUITEM_PAGEBACK
39iend
40
41g_MenuitemFlashStartFlashing:
42istruc MENUITEM
43 at MENUITEM.fnActivate, dw StartFlashing
44 at MENUITEM.szName, dw g_szItemFlashStart
45 at MENUITEM.szQuickInfo, dw g_szNfoFlashStart
46 at MENUITEM.szHelp, dw g_szNfoFlashStart
47 at MENUITEM.bFlags, db FLG_MENUITEM_VISIBLE
48 at MENUITEM.bType, db TYPE_MENUITEM_ACTION
49iend
50
51g_MenuitemFlashEepromType:
52istruc MENUITEM
53 at MENUITEM.fnActivate, dw Menuitem_ActivateMultichoiceSelectionForMenuitemInDSSI
54 at MENUITEM.fnFormatValue, dw MenuitemPrint_WriteLookupValueStringToBufferInESDIfromShiftedItemInDSSI
55 at MENUITEM.szName, dw g_szItemFlashEepromType
56 at MENUITEM.szQuickInfo, dw g_szNfoFlashEepromType
57 at MENUITEM.szHelp, dw g_szNfoFlashEepromType
58 at MENUITEM.bFlags, db FLG_MENUITEM_MODIFY_MENU | FLG_MENUITEM_PROGRAMVAR | FLG_MENUITEM_BYTEVALUE | FLG_MENUITEM_VISIBLE
59 at MENUITEM.bType, db TYPE_MENUITEM_MULTICHOICE
60 at MENUITEM.itemValue + ITEM_VALUE.wRomvarsValueOffset, dw CFGVARS.bEepromType
61 at MENUITEM.itemValue + ITEM_VALUE.szDialogTitle, dw g_szDlgFlashEepromType
62 at MENUITEM.itemValue + ITEM_VALUE.szMultichoice, dw g_szMultichoiceEepromType
63 at MENUITEM.itemValue + ITEM_VALUE.rgwChoiceToValueLookup, dw g_rgwChoiceToValueLookupForEepromType
64 at MENUITEM.itemValue + ITEM_VALUE.rgszValueToStringLookup, dw g_rgszValueToStringLookupForEepromType
65iend
66
67g_MenuitemFlashSdpCommand:
68istruc MENUITEM
69 at MENUITEM.fnActivate, dw Menuitem_ActivateMultichoiceSelectionForMenuitemInDSSI
70 at MENUITEM.fnFormatValue, dw MenuitemPrint_WriteLookupValueStringToBufferInESDIfromShiftedItemInDSSI
71 at MENUITEM.szName, dw g_szItemFlashSDP
72 at MENUITEM.szQuickInfo, dw g_szNfoFlashSDP
73 at MENUITEM.szHelp, dw g_szHelpFlashSDP
74 at MENUITEM.bFlags, db FLG_MENUITEM_PROGRAMVAR | FLG_MENUITEM_BYTEVALUE
75 at MENUITEM.bType, db TYPE_MENUITEM_MULTICHOICE
76 at MENUITEM.itemValue + ITEM_VALUE.wRomvarsValueOffset, dw CFGVARS.bSdpCommand
77 at MENUITEM.itemValue + ITEM_VALUE.szDialogTitle, dw g_szDlgFlashSDP
78 at MENUITEM.itemValue + ITEM_VALUE.szMultichoice, dw g_szMultichoiceSdpCommand
79 at MENUITEM.itemValue + ITEM_VALUE.rgwChoiceToValueLookup, dw g_rgwChoiceToValueLookupForSdpCommand
80 at MENUITEM.itemValue + ITEM_VALUE.rgszValueToStringLookup, dw g_rgszValueToStringLookupForSdpCommand
81iend
82
83g_MenuitemFlashPageSize:
84istruc MENUITEM
85 at MENUITEM.fnActivate, dw Menuitem_ActivateMultichoiceSelectionForMenuitemInDSSI
86 at MENUITEM.fnFormatValue, dw MenuitemPrint_WriteLookupValueStringToBufferInESDIfromShiftedItemInDSSI
87 at MENUITEM.szName, dw g_szItemFlashPageSize
88 at MENUITEM.szQuickInfo, dw g_szNfoFlashPageSize
89 at MENUITEM.szHelp, dw g_szHelpFlashPageSize
90 at MENUITEM.bFlags, db FLG_MENUITEM_PROGRAMVAR | FLG_MENUITEM_BYTEVALUE
91 at MENUITEM.bType, db TYPE_MENUITEM_MULTICHOICE
92 at MENUITEM.itemValue + ITEM_VALUE.wRomvarsValueOffset, dw CFGVARS.bEepromPage
93 at MENUITEM.itemValue + ITEM_VALUE.szDialogTitle, dw g_szDlgFlashPageSize
94 at MENUITEM.itemValue + ITEM_VALUE.szMultichoice, dw g_szMultichoicePageSize
95 at MENUITEM.itemValue + ITEM_VALUE.rgwChoiceToValueLookup, dw g_rgwChoiceToValueLookupForPageSize
96 at MENUITEM.itemValue + ITEM_VALUE.rgszValueToStringLookup, dw g_rgszValueToStringLookupForPageSize
97iend
98
99g_MenuitemFlashEepromAddress:
100istruc MENUITEM
101 at MENUITEM.fnActivate, dw Menuitem_ActivateHexInputForMenuitemInDSSI
102 at MENUITEM.fnFormatValue, dw MenuitemPrint_WriteHexValueStringToBufferInESDIfromItemInDSSI
103 at MENUITEM.szName, dw g_szItemFlashAddr
104 at MENUITEM.szQuickInfo, dw g_szNfoFlashAddr
105 at MENUITEM.szHelp, dw g_szNfoFlashAddr
106 at MENUITEM.bFlags, db FLG_MENUITEM_PROGRAMVAR | FLG_MENUITEM_VISIBLE
107 at MENUITEM.bType, db TYPE_MENUITEM_HEX
108 at MENUITEM.itemValue + ITEM_VALUE.wRomvarsValueOffset, dw CFGVARS.wEepromSegment
109 at MENUITEM.itemValue + ITEM_VALUE.szDialogTitle, dw g_szDlgFlashAddr
110 at MENUITEM.itemValue + ITEM_VALUE.wMinValue, dw 0C000h
111 at MENUITEM.itemValue + ITEM_VALUE.wMaxValue, dw 0F800h
112iend
113
114g_MenuitemFlashGenerateChecksum:
115istruc MENUITEM
116 at MENUITEM.fnActivate, dw Menuitem_ActivateMultichoiceSelectionForMenuitemInDSSI
117 at MENUITEM.fnFormatValue, dw MenuitemPrint_WriteLookupValueStringToBufferInESDIfromShiftedItemInDSSI
118 at MENUITEM.szName, dw g_szItemFlashChecksum
119 at MENUITEM.szQuickInfo, dw g_szNfoFlashChecksum
120 at MENUITEM.szHelp, dw g_szHelpFlashChecksum
121 at MENUITEM.bFlags, db FLG_MENUITEM_PROGRAMVAR | FLG_MENUITEM_VISIBLE | FLG_MENUITEM_FLAGVALUE
122 at MENUITEM.bType, db TYPE_MENUITEM_MULTICHOICE
123 at MENUITEM.itemValue + ITEM_VALUE.wRomvarsValueOffset, dw CFGVARS.wFlags
124 at MENUITEM.itemValue + ITEM_VALUE.szDialogTitle, dw g_szDlgFlashChecksum
125 at MENUITEM.itemValue + ITEM_VALUE.szMultichoice, dw g_szMultichoiceBooleanFlag
126 at MENUITEM.itemValue + ITEM_VALUE.rgszValueToStringLookup, dw g_rgszValueToStringLookupForFlagBooleans
127 at MENUITEM.itemValue + ITEM_VALUE.wValueBitmask, dw FLG_CFGVARS_CHECKSUM
128iend
129
130g_rgwChoiceToValueLookupForEepromType:
131 dw EEPROM_TYPE.2816_2kiB
132 dw EEPROM_TYPE.2864_8kiB
133 dw EEPROM_TYPE.2864_8kiB_MOD
134 dw EEPROM_TYPE.28256_32kiB
135 dw EEPROM_TYPE.28512_64kiB
136 dw EEPROM_TYPE.SST_39SF
137
138g_rgszValueToStringLookupForEepromType:
139 dw g_szValueFlash2816
140 dw g_szValueFlash2864
141 dw g_szValueFlash2864Mod
142 dw g_szValueFlash28256
143 dw g_szValueFlash28512
144 dw g_szValueFlashSST39SF
145
146g_rgwChoiceToValueLookupForSdpCommand:
147 dw SDP_COMMAND.none
148 dw SDP_COMMAND.enable
149 dw SDP_COMMAND.disable
150g_rgszValueToStringLookupForSdpCommand:
151 dw g_szValueFlashNone
152 dw g_szValueFlashEnable
153 dw g_szValueFlashDisable
154
155g_rgwChoiceToValueLookupForPageSize:
156 dw EEPROM_PAGE.1_byte
157 dw EEPROM_PAGE.2_bytes
158 dw EEPROM_PAGE.4_bytes
159 dw EEPROM_PAGE.8_bytes
160 dw EEPROM_PAGE.16_bytes
161 dw EEPROM_PAGE.32_bytes
162 dw EEPROM_PAGE.64_bytes
163g_rgszValueToStringLookupForPageSize:
164 dw g_szValueFlash1byte
165 dw g_szValueFlash2bytes
166 dw g_szValueFlash4bytes
167 dw g_szValueFlash8bytes
168 dw g_szValueFlash16bytes
169 dw g_szValueFlash32bytes
170 dw g_szValueFlash64bytes
171
172
173; Section containing code
174SECTION .text
175
176;--------------------------------------------------------------------
177; MainMenu_EnterMenuOrModifyItemVisibility
178; Parameters:
179; SS:BP: Menu handle
180; Returns:
181; Nothing
182; Corrupts registers:
183; All, except BP
184;--------------------------------------------------------------------
185ALIGN JUMP_ALIGN
186FlashMenu_EnterMenuOrModifyItemVisibility:
187 push cs
188 pop ds
189
190 cmp WORD [g_cfgVars+CFGVARS.wEepromSegment], 0
191 jne SHORT .AlreadySet
192
193 push es
194 push di
195 call EEPROM_FindXtideUniversalBiosROMtoESDI
196 mov ax, es
197 pop di
198 pop es
199 jnc SHORT .StoreEepromSegment
200 mov ax, DEFAULT_EEPROM_SEGMENT
201.StoreEepromSegment:
202 mov [g_cfgVars+CFGVARS.wEepromSegment], ax
203
204.AlreadySet:
205 mov si, g_MenupageForFlashMenu
206 ePUSH_T bx, Menupage_ChangeToNewMenupageInDSSI
207 cmp BYTE [g_cfgVars+CFGVARS.bEepromType], EEPROM_TYPE.SST_39SF
208 mov ax, DisableMenuitemFromCSBX
209 je SHORT .EnableOrDisableMenuitemsUnusedBySstFlash
210 mov ax, EnableMenuitemFromCSBX
211 ; Fall to .EnableOrDisableMenuitemsUnusedBySstFlash
212
213;--------------------------------------------------------------------
214; .EnableOrDisableMenuitemsUnusedBySstFlash
215; Parameters:
216; AX: Offset to EnableMenuitemFromCSBX / DisableMenuitemFromCSBX
217; SS:BP: Menu handle
218; Returns:
219; Nothing
220; Corrupts registers:
221; BX
222;--------------------------------------------------------------------
223.EnableOrDisableMenuitemsUnusedBySstFlash:
224 mov bx, g_MenuitemFlashSdpCommand
225 call ax
226 mov bx, g_MenuitemFlashPageSize
227 jmp ax
228
229;--------------------------------------------------------------------
230; MENUITEM activation functions (.fnActivate)
231; Parameters:
232; SS:BP: Ptr to MENU
233; Returns:
234; Nothing
235; Corrupts registers:
236; All, except segments
237;--------------------------------------------------------------------
238ALIGN JUMP_ALIGN
239StartFlashing:
240 call .MakeSureThatImageFitsInEeprom
241 jc SHORT .InvalidFlashingParameters
242 cmp BYTE [g_cfgVars+CFGVARS.bEepromType], EEPROM_TYPE.SST_39SF
243 jne SHORT .SkipAlignmentCheck
244 call .MakeSureAddress32KAligned
245 jnz SHORT .InvalidFlashingParameters
246.SkipAlignmentCheck:
247 push es
248 push ds
249
250 call .PrepareBuffersForFlashing
251 mov cl, FLASHVARS_size + PROGRESS_DIALOG_IO_size
252 call Memory_ReserveCLbytesFromStackToDSSI
253 call .InitializeFlashvarsFromDSSI
254 mov bx, si ; DS:BX now points to FLASHVARS
255 cmp BYTE [g_cfgVars+CFGVARS.bEepromType], EEPROM_TYPE.SST_39SF
256 je SHORT .FlashWithoutProgressBar
257 add si, BYTE FLASHVARS_size ; DS:SI now points to PROGRESS_DIALOG_IO
258 call Dialogs_DisplayProgressDialogForFlashingWithDialogIoInDSSIandFlashvarsInDSBX
259.FlashComplete:
260 call .DisplayFlashingResultsFromFlashvarsInDSBX
261
262 add sp, BYTE FLASHVARS_size + PROGRESS_DIALOG_IO_size
263 pop ds
264 pop es
265.InvalidFlashingParameters:
266 ret
267
268.FlashWithoutProgressBar: ; Worst case. SST devices will
269 call FlashSst_WithFlashvarsInDSBX ; either complete flashing
270 jmp SHORT .FlashComplete ; or timeout within 2 seconds.
271
272;--------------------------------------------------------------------
273; .MakeSureThatImageFitsInEeprom
274; Parameters:
275; SS:BP: Ptr to MENU
276; Returns:
277; CF: Set if EEPROM too small
278; Corrupts registers:
279; AX, BX, DX
280;--------------------------------------------------------------------
281ALIGN JUMP_ALIGN
282.MakeSureThatImageFitsInEeprom:
283 call Buffers_GetSelectedEepromSizeInWordsToAX
284 cmp ax, [g_cfgVars+CFGVARS.wImageSizeInWords]
285 jae SHORT .ImageFitsInSelectedEeprom
286 mov dx, g_szErrEepromTooSmall
287 call Dialogs_DisplayErrorFromCSDX
288 stc
289ALIGN JUMP_ALIGN, ret
290.ImageFitsInSelectedEeprom:
291.AlignmentIs32K:
292.DoNotGenerateChecksumByte:
293 ret
294
295;--------------------------------------------------------------------
296; .MakeSureAddress32KAligned
297; Parameters:
298; SS:BP: Ptr to MENU
299; Returns:
300; ZF: Cleared if EEPROM segment is not 32K aligned
301; Corrupts registers:
302; AX, DX
303;--------------------------------------------------------------------
304ALIGN JUMP_ALIGN
305.MakeSureAddress32KAligned:
306 test WORD [g_cfgVars+CFGVARS.wEepromSegment], 07FFh
307 jz SHORT .AlignmentIs32K
308 mov dx, g_szErrAddrNot32KAligned
309 jmp Dialogs_DisplayErrorFromCSDX
310
311;--------------------------------------------------------------------
312; .PrepareBuffersForFlashing
313; Parameters:
314; SS:BP: Ptr to MENU
315; Returns:
316; Nothing
317; Corrupts registers:
318; AX, BX, CX, SI, DI
319;--------------------------------------------------------------------
320ALIGN JUMP_ALIGN
321.PrepareBuffersForFlashing:
322 call EEPROM_LoadFromRomToRamComparisonBuffer
323 call Buffers_AppendZeroesIfNeeded
324 test BYTE [g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_CHECKSUM
325 jz SHORT .DoNotGenerateChecksumByte
326 jmp Buffers_GenerateChecksum
327
328;--------------------------------------------------------------------
329; .InitializeFlashvarsFromDSSI
330; Parameters:
331; DS:SI: Ptr to FLASHVARS to initialize
332; SS:BP: Ptr to MENU
333; Returns:
334; Nothing
335; Corrupts registers:
336; AX, BX, DX, DI, ES
337;--------------------------------------------------------------------
338ALIGN JUMP_ALIGN
339.InitializeFlashvarsFromDSSI:
340 call Buffers_GetFileBufferToESDI
341 mov [si+FLASHVARS.fpNextSourcePage], di
342 mov [si+FLASHVARS.fpNextSourcePage+2], es
343
344 call Buffers_GetFlashComparisonBufferToESDI
345 mov [si+FLASHVARS.fpNextComparisonPage], di
346 mov [si+FLASHVARS.fpNextComparisonPage+2], es
347
348 mov ax, [g_cfgVars+CFGVARS.wEepromSegment]
349 mov WORD [si+FLASHVARS.fpNextDestinationPage], 0
350 mov [si+FLASHVARS.fpNextDestinationPage+2], ax
351
352 mov al, [g_cfgVars+CFGVARS.bEepromType]
353 mov [si+FLASHVARS.bEepromType], al
354
355 mov al, [g_cfgVars+CFGVARS.bSdpCommand]
356 mov [si+FLASHVARS.bEepromSdpCommand], al
357
358 mov ax, SST_PAGE_SIZE
359 cmp BYTE [g_cfgVars+CFGVARS.bEepromType], EEPROM_TYPE.SST_39SF
360 je SHORT .UseSstPageSize
361
362 eMOVZX bx, [g_cfgVars+CFGVARS.bEepromPage]
363 mov ax, [bx+g_rgwEepromPageToSizeInBytes]
364.UseSstPageSize:
365 mov [si+FLASHVARS.wEepromPageSize], ax
366
367 call .GetNumberOfPagesToFlashToAX
368 mov [si+FLASHVARS.wPagesToFlash], ax
369 ret
370
371;--------------------------------------------------------------------
372; .GetNumberOfPagesToFlashToAX
373; Parameters:
374; DS:SI: Ptr to FLASHVARS to initialize
375; Returns:
376; AX: Number of pages to flash (0 = 65536)
377; Corrupts registers:
378; BX, DX
379;--------------------------------------------------------------------
380ALIGN JUMP_ALIGN
381.GetNumberOfPagesToFlashToAX:
382 call Buffers_GetSelectedEepromSizeInWordsToAX
383 xor dx, dx
384 eSHL_IM ax, 1 ; Size in bytes to...
385 eRCL_IM dx, 1 ; ...DX:AX
386
387 cmp WORD [si+FLASHVARS.wEepromPageSize], BYTE 1
388 jbe SHORT .PreventDivideException
389 div WORD [si+FLASHVARS.wEepromPageSize]
390.PreventDivideException:
391 ret
392
393;--------------------------------------------------------------------
394; .DisplayFlashingResultsFromFlashvarsInDSBX
395; Parameters:
396; DS:BX: Ptr to FLASHVARS
397; SS:BP: Ptr to MENU
398; Returns:
399; Nothing
400; Corrupts registers:
401; AX, BX, DX
402;--------------------------------------------------------------------
403ALIGN JUMP_ALIGN
404.DisplayFlashingResultsFromFlashvarsInDSBX:
405 eMOVZX bx, [bx+FLASHVARS.flashResult]
406 jmp [cs:bx+.rgfnFlashResultMessage]
407
408ALIGN WORD_ALIGN
409.rgfnFlashResultMessage:
410 dw .DisplayFlashSuccessful
411 dw .DisplayDeviceDetectionError
412 dw .DisplayPollingError
413 dw .DisplayDataVerifyError
414
415
416;--------------------------------------------------------------------
417; .DisplayDeviceDetectionError
418; .DisplayPollingError
419; .DisplayDataVerifyError
420; .DisplayFlashSuccessful
421; Parameters:
422; SS:BP: Ptr to MENU
423; Returns:
424; Nothing
425; Corrupts registers:
426; AX, DX, DI, ES
427;--------------------------------------------------------------------
428ALIGN JUMP_ALIGN
429.DisplayDeviceDetectionError:
430 mov dx, g_szErrEepromDetection
431 jmp Dialogs_DisplayErrorFromCSDX
432
433ALIGN JUMP_ALIGN
434.DisplayPollingError:
435 mov dx, g_szErrEepromPolling
436 jmp Dialogs_DisplayErrorFromCSDX
437
438ALIGN JUMP_ALIGN
439.DisplayDataVerifyError:
440 mov dx, g_szErrEepromVerify
441 jmp Dialogs_DisplayErrorFromCSDX
442
443ALIGN JUMP_ALIGN
444.DisplayFlashSuccessful:
445 call Buffers_GetFileBufferToESDI
446 cmp WORD [es:di+ROMVARS.wRomSign], 0AA55h ; PC ROM?
447 je SHORT .DisplayRebootMessageAndReboot
448 mov dx, g_szForeignFlash
449 jmp Dialogs_DisplayNotificationFromCSDX
450ALIGN JUMP_ALIGN
451.DisplayRebootMessageAndReboot:
452 mov dx, g_szPCFlashSuccessful
453 call Dialogs_DisplayNotificationFromCSDX
454 xor ax, ax ; Cold boot flag
455 jmp Reboot_ComputerWithBootFlagInAX
Note: See TracBrowser for help on using the repository browser.