source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Main.asm @ 621

Last change on this file since 621 was 621, checked in by krille_n_, 2 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.4 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Authors       :   Tomi Tilli
3;               :   aitotat@gmail.com
4;               :
5;               :   Greg Lindhorst
6;               :   gregli@hotmail.com
7;               ;
8;               :   Krister Nordvall
9;               :   krille_n_@hotmail.com
10;               :
11; Description   :   Main file for BIOS. This is the only file that needs
12;                   to be compiled since other files are included to this
13;                   file (so no linker needed, Nasm does it all).
14
15;
16; XTIDE Universal BIOS and Associated Tools
17; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
18;
19; This program is free software; you can redistribute it and/or modify
20; it under the terms of the GNU General Public License as published by
21; the Free Software Foundation; either version 2 of the License, or
22; (at your option) any later version.
23;
24; This program is distributed in the hope that it will be useful,
25; but WITHOUT ANY WARRANTY; without even the implied warranty of
26; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27; GNU General Public License for more details.
28; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
29;
30
31    ORG 0                           ; Code start offset 0000h
32
33    ; We must define included libraries before including "AssemblyLibrary.inc".
34%define EXCLUDE_FROM_XUB                    ; Exclude unused library functions
35%ifdef MODULE_BOOT_MENU
36    %define MENUEVENT_INLINE_OFFSETS        ; Only one menu required, save space and inline offsets
37    %define INCLUDE_MENU_LIBRARY
38    %define MENU_NO_ESC                     ; User cannot 'esc' out of the menu
39%else   ; If no boot menu included
40    %define INCLUDE_DISPLAY_LIBRARY
41    %define INCLUDE_KEYBOARD_LIBRARY
42    %define INCLUDE_TIME_LIBRARY
43%endif
44
45
46    ; Included .inc files
47    %include "AssemblyLibrary.inc"  ; Assembly Library. Must be included first!
48    %include "ModuleDependency.inc" ; Dependency checks for optional modules. Must be included second!
49    %include "Version.inc"
50    %include "ATA_ID.inc"           ; For ATA Drive Information structs
51    %include "IdeRegisters.inc"     ; For ATA Registers, flags and commands
52    %include "Int13h.inc"           ; Equates for INT 13h functions
53    %include "CustomDPT.inc"        ; For Disk Parameter Table
54    %include "RomVars.inc"          ; For ROMVARS and IDEVARS structs
55    %include "RamVars.inc"          ; For RAMVARS struct
56    %include "BootVars.inc"         ; For BOOTVARS struct
57    %include "IdeIO.inc"            ; Macros for IDE port I/O
58    %include "DeviceIDE.inc"        ; For IDE device equates
59
60
61
62; Section containing code
63SECTION .text
64
65; ROM variables (must start at offset 0)
66CNT_ROM_BLOCKS      EQU     BIOS_SIZE / 512     ; number of 512B blocks, 16 = 8kB BIOS
67istruc ROMVARS
68    at  ROMVARS.wRomSign,   dw  0AA55h          ; PC ROM signature
69    at  ROMVARS.bRomSize,   db  CNT_ROM_BLOCKS  ; ROM size in 512B blocks
70    at  ROMVARS.rgbJump,    jmp Initialize_FromMainBiosRomSearch
71    at  ROMVARS.rgbSign,    db  FLASH_SIGNATURE
72    at  ROMVARS.szTitle,    db  TITLE_STRING
73    at  ROMVARS.szVersion,  db  ROM_VERSION_STRING
74
75;---------------------------;
76; AT Build default settings ;
77;---------------------------;
78%ifdef USE_AT
79%ifdef USE_386
80    at  ROMVARS.wFlags,         dw  FLG_ROMVARS_FULLMODE | FLG_ROMVARS_CLEAR_BDA_HD_COUNT | MASK_ROMVARS_INCLUDED_MODULES
81%else
82    at  ROMVARS.wFlags,         dw  FLG_ROMVARS_FULLMODE | MASK_ROMVARS_INCLUDED_MODULES
83%endif
84    at  ROMVARS.wDisplayMode,   dw  DEFAULT_TEXT_MODE
85%ifdef MODULE_BOOT_MENU
86    at  ROMVARS.wBootTimeout,   dw  BOOT_MENU_DEFAULT_TIMEOUT
87    at  ROMVARS.pColorTheme,    dw  ColorTheme              ; Offset to the ATTRIBUTE_CHARS struc that holds the color theme
88%endif
89    at  ROMVARS.bIdeCnt,        db  2                       ; Number of supported controllers
90    at  ROMVARS.bBootDrv,       db  80h                     ; Boot Menu default drive
91    at  ROMVARS.bMinFddCnt,     db  0                       ; Do not force minimum number of floppy drives
92    at  ROMVARS.bStealSize,     db  1                       ; Steal 1kB from base memory
93    at  ROMVARS.bIdleTimeout,   db  0                       ; Standby timer disabled by default
94
95    at  ROMVARS.ideVars0+IDEVARS.wBasePort,         dw  DEVICE_ATA_PRIMARY_PORT         ; Controller Command Block base port
96    at  ROMVARS.ideVars0+IDEVARS.wControlBlockPort, dw  DEVICE_ATA_PRIMARY_PORTCTRL     ; Controller Control Block base port
97    at  ROMVARS.ideVars0+IDEVARS.bDevice,           db  DEVICE_16BIT_ATA
98%ifdef MODULE_IRQ
99    at  ROMVARS.ideVars0+IDEVARS.bIRQ,              db  14
100%endif
101    at  ROMVARS.ideVars0+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  dw  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
102    at  ROMVARS.ideVars0+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   dw  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
103
104    at  ROMVARS.ideVars1+IDEVARS.wBasePort,         dw  DEVICE_ATA_SECONDARY_PORT
105    at  ROMVARS.ideVars1+IDEVARS.wControlBlockPort, dw  DEVICE_ATA_SECONDARY_PORTCTRL
106    at  ROMVARS.ideVars1+IDEVARS.bDevice,           db  DEVICE_16BIT_ATA
107%ifdef MODULE_IRQ
108    at  ROMVARS.ideVars1+IDEVARS.bIRQ,              db  15
109%endif
110    at  ROMVARS.ideVars1+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  dw  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
111    at  ROMVARS.ideVars1+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   dw  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
112
113    at  ROMVARS.ideVars2+IDEVARS.wBasePort,         dw  DEVICE_ATA_TERTIARY_PORT
114    at  ROMVARS.ideVars2+IDEVARS.wControlBlockPort, dw  DEVICE_ATA_TERTIARY_PORTCTRL
115    at  ROMVARS.ideVars2+IDEVARS.bDevice,           db  DEVICE_16BIT_ATA
116%ifdef MODULE_IRQ
117    at  ROMVARS.ideVars2+IDEVARS.bIRQ,              db  0   ; Should be 11 on the GSI Inc. Model 2C
118%endif
119    at  ROMVARS.ideVars2+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  dw  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
120    at  ROMVARS.ideVars2+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   dw  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
121
122    at  ROMVARS.ideVars3+IDEVARS.wBasePort,         dw  DEVICE_ATA_QUATERNARY_PORT
123    at  ROMVARS.ideVars3+IDEVARS.wControlBlockPort, dw  DEVICE_ATA_QUATERNARY_PORTCTRL
124    at  ROMVARS.ideVars3+IDEVARS.bDevice,           db  DEVICE_16BIT_ATA
125%ifdef MODULE_IRQ
126    at  ROMVARS.ideVars3+IDEVARS.bIRQ,              db  0   ; Should be 10 on the GSI Inc. Model 2C
127%endif
128    at  ROMVARS.ideVars3+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  dw  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
129    at  ROMVARS.ideVars3+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   dw  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
130
131%ifdef MODULE_SERIAL
132    at  ROMVARS.ideVarsSerialAuto+IDEVARS.bDevice,  db  DEVICE_SERIAL_PORT
133%endif
134%else
135;-----------------------------------;
136; XT and XT+ Build default settings ;
137;-----------------------------------;
138    at  ROMVARS.wFlags,         dw  MASK_ROMVARS_INCLUDED_MODULES
139    at  ROMVARS.wDisplayMode,   dw  DEFAULT_TEXT_MODE
140%ifdef MODULE_BOOT_MENU
141    at  ROMVARS.wBootTimeout,   dw  BOOT_MENU_DEFAULT_TIMEOUT
142    at  ROMVARS.pColorTheme,    dw  ColorTheme              ; Offset to the ATTRIBUTE_CHARS struc that holds the color theme
143%endif
144    at  ROMVARS.bIdeCnt,        db  1
145    at  ROMVARS.bBootDrv,       db  80h                     ; Boot Menu default drive
146    at  ROMVARS.bMinFddCnt,     db  0                       ; Do not force minimum number of floppy drives
147    at  ROMVARS.bStealSize,     db  1                       ; Steal 1kB from base memory in full mode
148    at  ROMVARS.bIdleTimeout,   db  0                       ; Standby timer disabled by default
149
150%ifndef MODULE_8BIT_IDE
151    at  ROMVARS.ideVars0+IDEVARS.wBasePort,         dw  DEVICE_ATA_PRIMARY_PORT         ; Controller Command Block base port
152    at  ROMVARS.ideVars0+IDEVARS.wControlBlockPort, dw  DEVICE_ATA_PRIMARY_PORTCTRL     ; Controller Control Block base port
153    at  ROMVARS.ideVars0+IDEVARS.bDevice,           db  DEVICE_16BIT_ATA
154%elifdef MODULE_8BIT_IDE_ADVANCED
155    at  ROMVARS.ideVars0+IDEVARS.wBasePort,         dw  DEVICE_XTIDE_DEFAULT_PORT       ; Controller Command Block base port
156    at  ROMVARS.ideVars0+IDEVARS.bDevice,           db  DEVICE_8BIT_XTCF_PIO8
157%else
158    at  ROMVARS.ideVars0+IDEVARS.wBasePort,         dw  DEVICE_XTIDE_DEFAULT_PORT       ; Controller Command Block base port
159    at  ROMVARS.ideVars0+IDEVARS.wControlBlockPort, dw  DEVICE_XTIDE_DEFAULT_PORTCTRL   ; Controller Control Block base port
160    at  ROMVARS.ideVars0+IDEVARS.bDevice,           db  DEVICE_8BIT_XTIDE_REV1
161%endif
162    at  ROMVARS.ideVars0+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
163    at  ROMVARS.ideVars0+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
164
165    at  ROMVARS.ideVars1+IDEVARS.wBasePort,         dw  DEVICE_ATA_SECONDARY_PORT
166    at  ROMVARS.ideVars1+IDEVARS.wControlBlockPort, dw  DEVICE_ATA_SECONDARY_PORTCTRL
167    at  ROMVARS.ideVars1+IDEVARS.bDevice,           db  DEVICE_16BIT_ATA
168    at  ROMVARS.ideVars1+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
169    at  ROMVARS.ideVars1+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
170
171    at  ROMVARS.ideVars2+IDEVARS.wBasePort,         dw  DEVICE_ATA_TERTIARY_PORT
172    at  ROMVARS.ideVars2+IDEVARS.wControlBlockPort, dw  DEVICE_ATA_TERTIARY_PORTCTRL
173    at  ROMVARS.ideVars2+IDEVARS.bDevice,           db  DEVICE_16BIT_ATA
174    at  ROMVARS.ideVars2+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
175    at  ROMVARS.ideVars2+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
176
177    at  ROMVARS.ideVars3+IDEVARS.wBasePort,         dw  DEVICE_ATA_QUATERNARY_PORT
178    at  ROMVARS.ideVars3+IDEVARS.wControlBlockPort, dw  DEVICE_ATA_QUATERNARY_PORTCTRL
179    at  ROMVARS.ideVars3+IDEVARS.bDevice,           db  DEVICE_16BIT_ATA
180    at  ROMVARS.ideVars3+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
181    at  ROMVARS.ideVars3+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
182
183%ifdef MODULE_SERIAL
184    at  ROMVARS.ideVarsSerialAuto+IDEVARS.bDevice,  db  DEVICE_SERIAL_PORT
185%endif
186%endif
187iend
188
189    ; Strings are first to avoid them moving unnecessarily when code is turned on and off with %ifdef's
190    ; since some groups of strings need to be on the same 256-byte page.
191    ;
192%ifdef MODULE_STRINGS_COMPRESSED
193    %define STRINGSCOMPRESSED_STRINGS
194    %include "StringsCompressed.asm"
195%else
196    %include "Strings.asm"          ; For BIOS message strings
197%endif
198
199    ; Libraries, data, Initialization and drive detection
200
201    %include "AssemblyLibrary.asm"
202%ifdef MODULE_WIN9X_CMOS_HACK
203    %include "CMOS.asm"             ; This belongs in the Assembly Library
204%endif
205
206    ; String compression tables need to come after the AssemblyLibrary (since they depend on addresses
207    ; established in the assembly library), and are unnecessary if strings are not compressed.
208    ;
209%ifdef MODULE_STRINGS_COMPRESSED
210    %undef  STRINGSCOMPRESSED_STRINGS
211    %define STRINGSCOMPRESSED_TABLES
212    %include "StringsCompressed.asm"
213%endif
214
215    %include "Initialize.asm"       ; For BIOS initialization
216    %include "Interrupts.asm"       ; For Interrupt initialization
217    %include "RamVars.asm"          ; For RAMVARS initialization and access
218    %include "BootVars.asm"         ; For initializing variables used during init and boot
219    %include "FloppyDrive.asm"      ; Floppy Drive related functions
220    %include "CreateDPT.asm"        ; For creating DPTs
221    %include "FindDPT.asm"          ; For finding DPTs
222    %include "AccessDPT.asm"        ; For accessing DPTs
223    %include "AtaGeometry.asm"      ; For generating L-CHS parameters
224    %include "DrvDetectInfo.asm"    ; For creating DRVDETECTINFO structs
225    %include "AtaID.asm"            ; For ATA Identify Device information
226    %include "DetectDrives.asm"     ; For detecting IDE drives
227    %include "DetectPrint.asm"      ; For printing drive detection strings
228%ifdef MODULE_COMPATIBLE_TABLES
229    %include "CompatibleDPT.asm"
230%endif
231
232    ; Hotkey Bar
233%ifdef MODULE_HOTKEYS
234    %include "HotkeyBar.asm"        ; For hotkeys during drive detection and boot menu
235%endif
236%ifdef MODULE_DRIVEXLATE
237    %include "DriveXlate.asm"       ; For swapping drive numbers, must come immediately after HotkeyBar.asm
238%endif
239
240    ; Boot menu
241%ifdef MODULE_BOOT_MENU
242    %include "BootMenu.asm"         ; For Boot Menu operations
243    %include "BootMenuEvent.asm"    ; For menu library event handling
244                                    ; NOTE: BootMenuPrint needs to come immediately after BootMenuEvent
245                                    ;       so that jump table entries in BootMenuEvent stay within 8-bits
246    %include "BootMenuPrint.asm"    ; For printing Boot Menu strings, also includes "BootMenuPrintCfg.asm"
247%endif
248
249    ; Boot loader
250%ifdef MODULE_VERY_LATE_INIT
251    %include "Int13hBiosInit.asm"
252%endif
253    %include "Int19h.asm"           ; For Int 19h, Boot Loader
254    %include "BootSector.asm"       ; For loading boot sector
255    %include "Int19hReset.asm"      ; INT 19h handler for proper system reset
256
257    ; For all device types
258    %include "Idepack.asm"
259    %include "Device.asm"
260    %include "Timer.asm"            ; For timeout and delay
261
262    ; IDE Device support
263%ifdef MODULE_ADVANCED_ATA
264    %include "AdvAtaInit.asm"       ; For initializing VLB and PCI controllers
265    %include "Vision.asm"           ; QDI Vision QD6500 and QD6580 support
266    %include "PDC20x30.asm"         ; Promise PDC 20230-C and 20630 support
267%endif
268    %include "IdeCommand.asm"
269%ifdef MODULE_8BIT_IDE_ADVANCED
270    %include "JrIdeTransfer.asm"    ; Must be included after IdeCommand.asm
271    %include "IdeDmaBlock.asm"
272%endif
273    %include "IdeTransfer.asm"
274    %include "IdePioBlock.asm"
275    %include "IdeWait.asm"
276    %include "IdeError.asm"         ; Must be included after IdeWait.asm
277    %include "IdeDPT.asm"
278    %include "IdeIO.asm"
279%ifdef MODULE_IRQ
280    %include "IdeIrq.asm"
281%endif
282
283    ; Serial Device support
284%ifdef MODULE_SERIAL                ; Serial Port Device support
285    %include "SerialCommand.asm"
286    %include "SerialDPT.asm"
287%endif
288
289    ; INT 13h Hard Disk BIOS functions
290%ifdef MODULE_MFM_COMPATIBILITY
291    %include "Int13hMFMcompatibility.asm"
292%endif
293    %include "Int13h.asm"           ; For Int 13h, Disk functions
294    %include "AH0h_HReset.asm"
295    %include "AH1h_HStatus.asm"
296    %include "AH2h_HRead.asm"
297    %include "AH3h_HWrite.asm"
298    %include "AH4h_HVerify.asm"
299    %include "AH8h_HParams.asm"
300    %include "AH9h_HInit.asm"
301    %include "AHCh_HSeek.asm"
302    %include "AH10h_HReady.asm"
303    %include "AH11h_HRecal.asm"
304    %include "AH15h_HSize.asm"
305%ifdef MODULE_8BIT_IDE_ADVANCED
306    %include "AH1Eh_XTCF.asm"
307%endif
308    %include "AH23h_HFeatures.asm"
309    %include "AH24h_HSetBlocks.asm"
310    %include "AH25h_HDrvID.asm"
311    %include "Address.asm"          ; For sector address translations
312    %include "Prepare.asm"          ; For buffer pointer normalization
313%ifdef MODULE_EBIOS
314    %include "AH42h_ExtendedReadSectors.asm"
315    %include "AH43h_ExtendedWriteSectors.asm"
316    %include "AH44h_ExtendedVerifySectors.asm"
317    %include "AH47h_ExtendedSeek.asm"
318    %include "AH48h_GetExtendedDriveParameters.asm"
319    %include "AH41h_CheckIfExtensionsPresent.asm"
320%endif
321
322
323%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
324; Although it's very unlikely to happen, we give warnings for builds that cannot be automatically checksummed due to the size being too large.
325; In some cases it's theoretically possible to checksum the build anyway (manually) which is why these are warnings and not errors.
326%if BIOS_SIZE = 8192                ; A small build, possibly a candidate for the ROM socket on a 3Com 3C503 card.
327    %if ($-$$) <= BIOS_SIZE         ; Only give warnings when the problem isn't obvious anyway.
328        %if ($-$$) > BIOS_SIZE - 3
329            %warning "This build is too large to be auto-checksummed!"
330        %endif
331    %endif
332%elif ($-$$) = BIOS_SIZE            ; A large or tiny build.
333    %warning "This build is too large to be auto-checksummed!"
334%endif
335%endif
Note: See TracBrowser for help on using the repository browser.