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

Last change on this file since 379 was 379, checked in by aitotat@…, 12 years ago

Changes to XTIDE Universal BIOS:

  • Preparing to make boot menu an optional module.
File size: 13.1 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-2012 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_XTIDE_UNIVERSAL_BIOS   ; 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
39%else   ; If no boot menu included
40    %define INCLUDE_DISPLAY_LIBRARY
41    %define INCLUDE_TIME_LIBRARY
42%endif
43
44
45    ; Included .inc files
46    %include "AssemblyLibrary.inc"  ; Assembly Library. Must be included first!
47    %include "Version.inc"
48    %include "IntController.inc"    ; For Interrupt Controller equates
49    %include "ATA_ID.inc"           ; For ATA Drive Information structs
50    %include "IdeRegisters.inc"     ; For ATA Registers, flags and commands
51    %include "Int13h.inc"           ; Equates for INT 13h functions
52%ifdef MODULE_EBIOS
53    %include "EBIOS.inc"            ; Equates for EBIOS functions
54%endif
55    %include "CustomDPT.inc"        ; For Disk Parameter Table
56    %include "RomVars.inc"          ; For ROMVARS and IDEVARS structs
57    %include "RamVars.inc"          ; For RAMVARS struct
58    %include "BootVars.inc"         ; For BOOTVARS struct
59    %include "BootMenu.inc"         ; For Boot Menu
60    %include "IDE_8bit.inc"         ; For IDE 8-bit data port macros
61    %include "DeviceIDE.inc"        ; For IDE device equates
62    %include "Vision.inc"           ; For QDI Vision QD65xx VLB IDE Controllers
63
64
65; Section containing code
66SECTION .text
67
68; ROM variables (must start at offset 0)
69CNT_ROM_BLOCKS      EQU     ROMSIZE / 512       ; number of 512B blocks, 16 = 8kB BIOS
70istruc ROMVARS
71    at  ROMVARS.wRomSign,   dw  0AA55h          ; PC ROM signature
72    at  ROMVARS.bRomSize,   db  CNT_ROM_BLOCKS  ; ROM size in 512B blocks
73    at  ROMVARS.rgbJump,    jmp Initialize_FromMainBiosRomSearch
74    at  ROMVARS.rgbSign,    db  FLASH_SIGNATURE
75    at  ROMVARS.szTitle,    db  TITLE_STRING
76    at  ROMVARS.szVersion,  db  ROM_VERSION_STRING
77
78;;; For OR'ing into wFlags below
79;;;
80%ifdef MODULE_SERIAL
81    MAIN_FLG_MODULE_SERIAL  equ FLG_ROMVARS_MODULE_SERIAL
82%else
83    MAIN_FLG_MODULE_SERIAL  equ 0
84%endif
85
86%ifdef MODULE_EBIOS
87    MAIN_FLG_MODULE_EBIOS   equ FLG_ROMVARS_MODULE_EBIOS
88%else
89    MAIN_FLG_MODULE_EBIOS   equ 0
90%endif
91
92%ifdef MODULE_JRIDE
93    MAIN_FLG_MODULE_JRIDE   equ FLG_ROMVARS_MODULE_JRIDE
94%else
95    MAIN_FLG_MODULE_JRIDE   equ 0
96%endif
97
98%ifdef MODULE_ADVANCED_ATA
99    MAIN_FLG_MODULE_ADVATA  equ FLG_ROMVARS_MODULE_ADVATA
100%else
101    MAIN_FLG_MODULE_ADVATA  equ 0
102%endif
103
104
105;---------------------------;
106; AT Build default settings ;
107;---------------------------;
108%ifdef USE_AT
109    at  ROMVARS.wFlags,         dw  FLG_ROMVARS_FULLMODE | FLG_ROMVARS_DRVXLAT | MAIN_FLG_MODULE_SERIAL | MAIN_FLG_MODULE_EBIOS | MAIN_FLG_MODULE_JRIDE | MAIN_FLG_MODULE_ADVATA
110    at  ROMVARS.wDisplayMode,   dw  DEFAULT_TEXT_MODE
111    at  ROMVARS.wBootTimeout,   dw  BOOT_MENU_DEFAULT_TIMEOUT
112    at  ROMVARS.bIdeCnt,        db  4                       ; Number of supported controllers
113    at  ROMVARS.bBootDrv,       db  80h                     ; Boot Menu default drive
114    at  ROMVARS.bMinFddCnt,     db  0                       ; Do not force minimum number of floppy drives
115    at  ROMVARS.bStealSize,     db  1                       ; Steal 1kB from base memory
116
117    at  ROMVARS.ideVars0+IDEVARS.wPort,         dw  DEVICE_ATA_DEFAULT_PORT         ; Controller Command Block base port
118    at  ROMVARS.ideVars0+IDEVARS.wPortCtrl,     dw  DEVICE_ATA_DEFAULT_PORTCTRL     ; Controller Control Block base port
119    at  ROMVARS.ideVars0+IDEVARS.bDevice,       db  DEVICE_16BIT_ATA
120    at  ROMVARS.ideVars0+IDEVARS.bIRQ,          db  0
121    at  ROMVARS.ideVars0+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
122    at  ROMVARS.ideVars0+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
123
124    at  ROMVARS.ideVars1+IDEVARS.wPort,         dw  DEVICE_ATA_DEFAULT_SECONDARY_PORT
125    at  ROMVARS.ideVars1+IDEVARS.wPortCtrl,     dw  DEVICE_ATA_DEFAULT_SECONDARY_PORTCTRL
126    at  ROMVARS.ideVars1+IDEVARS.bDevice,       db  DEVICE_16BIT_ATA
127    at  ROMVARS.ideVars1+IDEVARS.bIRQ,          db  0
128    at  ROMVARS.ideVars1+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
129    at  ROMVARS.ideVars1+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
130
131    at  ROMVARS.ideVars2+IDEVARS.wPort,         dw  DEVICE_XTIDE_DEFAULT_PORT           ; Controller Command Block base port
132    at  ROMVARS.ideVars2+IDEVARS.wPortCtrl,     dw  DEVICE_XTIDE_DEFAULT_PORTCTRL       ; Controller Control Block base port
133    at  ROMVARS.ideVars2+IDEVARS.bDevice,       db  DEVICE_XTIDE_REV1
134    at  ROMVARS.ideVars2+IDEVARS.bIRQ,          db  0
135    at  ROMVARS.ideVars2+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
136    at  ROMVARS.ideVars2+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
137
138    at  ROMVARS.ideVars3+IDEVARS.wPort,         dw  168h            ; Controller Command Block base port
139    at  ROMVARS.ideVars3+IDEVARS.wPortCtrl,     dw  368h            ; Controller Control Block base port
140    at  ROMVARS.ideVars3+IDEVARS.bDevice,       db  DEVICE_16BIT_ATA
141    at  ROMVARS.ideVars3+IDEVARS.bIRQ,          db  0
142    at  ROMVARS.ideVars3+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
143    at  ROMVARS.ideVars3+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
144
145%ifdef MODULE_SERIAL
146    at  ROMVARS.ideVarsSerialAuto+IDEVARS.bDevice,      db  DEVICE_SERIAL_PORT
147%endif
148%else
149;-----------------------------------;
150; XT and XT+ Build default settings ;
151;-----------------------------------;
152    at  ROMVARS.wFlags,         dw  FLG_ROMVARS_DRVXLAT | MAIN_FLG_MODULE_SERIAL | MAIN_FLG_MODULE_EBIOS | MAIN_FLG_MODULE_JRIDE | MAIN_FLG_MODULE_ADVATA
153    at  ROMVARS.wDisplayMode,   dw  DEFAULT_TEXT_MODE
154    at  ROMVARS.wBootTimeout,   dw  BOOT_MENU_DEFAULT_TIMEOUT
155    at  ROMVARS.bIdeCnt,        db  1                       ; Number of supported controllers
156    at  ROMVARS.bBootDrv,       db  80h                     ; Boot Menu default drive
157    at  ROMVARS.bMinFddCnt,     db  1                       ; Assume at least 1 floppy drive present if autodetect fails
158    at  ROMVARS.bStealSize,     db  1                       ; Steal 1kB from base memory in full mode
159
160    at  ROMVARS.ideVars0+IDEVARS.wPort,         dw  DEVICE_XTIDE_DEFAULT_PORT           ; Controller Command Block base port
161    at  ROMVARS.ideVars0+IDEVARS.wPortCtrl,     dw  DEVICE_XTIDE_DEFAULT_PORTCTRL       ; Controller Control Block base port
162%ifdef MODULE_JRIDE
163    at  ROMVARS.ideVars0+IDEVARS.bDevice,       db  DEVICE_JRIDE_ISA
164%else
165    at  ROMVARS.ideVars0+IDEVARS.bDevice,       db  DEVICE_XTIDE_REV1
166%endif
167    at  ROMVARS.ideVars0+IDEVARS.bIRQ,          db  0               ; IRQ
168    at  ROMVARS.ideVars0+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
169    at  ROMVARS.ideVars0+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
170
171    at  ROMVARS.ideVars1+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
172    at  ROMVARS.ideVars1+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
173
174    at  ROMVARS.ideVars2+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
175    at  ROMVARS.ideVars2+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
176
177    at  ROMVARS.ideVars3+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,  db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
178    at  ROMVARS.ideVars3+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,   db  DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE
179
180%ifdef MODULE_SERIAL
181    at  ROMVARS.ideVarsSerialAuto+IDEVARS.bDevice,      db  DEVICE_SERIAL_PORT
182%endif
183%endif
184iend
185
186    ; Strings are first to avoid them moving unnessarily when code is turned on and off with %ifdef's
187    ; since some groups of strings need to be on the same 256-byte page.
188    ;
189%ifdef MODULE_STRINGS_COMPRESSED
190    %define STRINGSCOMPRESSED_STRINGS
191    %include "StringsCompressed.asm" 
192%else
193    %include "Strings.asm"          ; For BIOS message strings
194%endif
195
196    ; Libraries, data, Initialization and drive detection
197
198    %include "AssemblyLibrary.asm"
199
200    ; String compression tables need to come after the AssemblyLibrary (since they depend on addresses
201    ; established in the assembly library), and are unncessary if strings are not compressed.
202    ;
203%ifdef MODULE_STRINGS_COMPRESSED
204    %undef  STRINGSCOMPRESSED_STRINGS       
205    %define STRINGSCOMPRESSED_TABLES
206    %include "StringsCompressed.asm"
207%endif
208       
209    %include "Initialize.asm"       ; For BIOS initialization
210    %include "Interrupts.asm"       ; For Interrupt initialization
211    %include "RamVars.asm"          ; For RAMVARS initialization and access
212    %include "CreateDPT.asm"        ; For creating DPTs
213    %include "FindDPT.asm"          ; For finding DPTs
214    %include "AccessDPT.asm"        ; For accessing DPTs
215    %include "LbaAssist.asm"        ; For generating L-CHS parameters to LBA drives
216    %include "BootMenuInfo.asm"     ; For creating BOOTMENUINFO structs
217    %include "AtaID.asm"            ; For ATA Identify Device information
218    %include "DetectDrives.asm"     ; For detecting IDE drives
219    %include "DetectPrint.asm"      ; For printing drive detection strings
220
221    ; Boot menu
222%ifdef MODULE_BOOT_MENU
223    %include "BootMenu.asm"         ; For Boot Menu operations
224    %include "BootMenuEvent.asm"    ; For menu library event handling
225                                    ; NOTE: BootMenuPrint needs to come immediately after BootMenuEvent
226                                    ;       so that jump table entries in BootMenuEvent stay within 8-bits
227    %include "BootMenuPrint.asm"    ; For printing Boot Menu strings, also includes "BootMenuPrintCfg.asm"
228%endif
229
230    ; Boot loader
231    %include "BootPrint.asm"        ; For printing boot information
232    %include "Int19h.asm"           ; For Int 19h, Boot Loader
233    %include "FloppyDrive.asm"      ; Floppy Drive related functions
234    %include "BootSector.asm"       ; For loading boot sector
235
236    ; For all device types
237    %include "Idepack.asm"
238    %include "Device.asm"
239    %include "Timer.asm"            ; For timeout and delay
240
241    ; IDE Device support
242%ifdef MODULE_ADVANCED_ATA
243    %include "AdvAtaInit.asm"       ; For initializing VLB and PCI controllers
244    %include "Vision.asm"           ; QDI Vision QD6500 and QD6580 support
245%endif
246%define IDEDEVICE Ide
247%define ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS
248    %include "IOMappedIDE.inc"      ; Assembly IDE support for normal I/O mapped controllers
249    %include "IdeCommand.asm"
250    %include "IdeTransfer.asm"      ; Must be included after IdeCommand.asm
251    %include "IdeWait.asm"
252    %include "IdeError.asm"         ; Must be included after IdeWait.asm
253    %include "IdeDPT.asm"
254    %include "IdeIO.asm"
255    %include "IdeIrq.asm"
256%undef IDEDEVICE
257%undef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS
258
259    ; JR-IDE support
260%ifdef MODULE_JRIDE
261%define IDEDEVICE MemIde
262    %include "MemMappedIDE.inc"     ; Assembly IDE support for memory mapped controllers
263    %include "IdeCommand.asm"
264    %include "MemIdeTransfer.asm"   ; Must be included after IdeCommand.asm
265    %include "IdeWait.asm"
266    %include "IdeError.asm"         ; Must be included after IdeWait.asm
267%undef IDEDEVICE
268%endif
269
270
271%ifdef MODULE_SERIAL                ; Serial Port Device support
272    %include "SerialCommand.asm"
273    %include "SerialDPT.asm"
274%endif
275
276    ; INT 13h Hard Disk BIOS functions
277    %include "Int13h.asm"           ; For Int 13h, Disk functions
278    %include "AH0h_HReset.asm"      ; Required by Int13h_Jump.asm
279    %include "AH1h_HStatus.asm"     ; Required by Int13h_Jump.asm
280    %include "AH2h_HRead.asm"       ; Required by Int13h_Jump.asm
281    %include "AH3h_HWrite.asm"      ; Required by Int13h_Jump.asm
282    %include "AH4h_HVerify.asm"     ; Required by Int13h_Jump.asm
283    %include "AH8h_HParams.asm"     ; Required by Int13h_Jump.asm
284    %include "AH9h_HInit.asm"       ; Required by Int13h_Jump.asm
285    %include "AHCh_HSeek.asm"       ; Required by Int13h_Jump.asm
286    %include "AHDh_HReset.asm"      ; Required by Int13h_Jump.asm
287    %include "AH10h_HReady.asm"     ; Required by Int13h_Jump.asm
288    %include "AH11h_HRecal.asm"     ; Required by Int13h_Jump.asm
289    %include "AH15h_HSize.asm"      ; Required by Int13h_Jump.asm
290    %include "AH23h_HFeatures.asm"  ; Required by Int13h_Jump.asm
291    %include "AH24h_HSetBlocks.asm" ; Required by Int13h_Jump.asm
292    %include "AH25h_HDrvID.asm"     ; Required by Int13h_Jump.asm
293    %include "DriveXlate.asm"       ; For swapping drive numbers
294    %include "Address.asm"          ; For sector address translations
295    %include "Prepare.asm"          ; For buffer pointer normalization
296%ifdef MODULE_EBIOS
297    %include "AH42h_ExtendedReadSectors.asm"
298    %include "AH43h_ExtendedWriteSectors.asm"
299    %include "AH44h_ExtendedVerifySectors.asm"
300    %include "AH47h_ExtendedSeek.asm"
301    %include "AH48h_GetExtendedDriveParameters.asm"
302    %include "AH41h_CheckIfExtensionsPresent.asm"
303%endif
Note: See TracBrowser for help on using the repository browser.