[3] | 1 | ; Project name : XTIDE Universal BIOS |
---|
[86] | 2 | ; Authors : Tomi Tilli |
---|
| 3 | ; : aitotat@gmail.com |
---|
| 4 | ; : |
---|
[181] | 5 | ; : Greg Lindhorst |
---|
| 6 | ; : gregli@hotmail.com |
---|
| 7 | ; ; |
---|
[86] | 8 | ; : Krister Nordvall |
---|
| 9 | ; : krille_n_@hotmail.com |
---|
| 10 | ; : |
---|
[3] | 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 | |
---|
[376] | 15 | ; |
---|
[380] | 16 | ; XTIDE Universal BIOS and Associated Tools |
---|
[376] | 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. |
---|
[380] | 23 | ; |
---|
[376] | 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 |
---|
[380] | 27 | ; GNU General Public License for more details. |
---|
[376] | 28 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 29 | ; |
---|
| 30 | |
---|
[294] | 31 | ORG 0 ; Code start offset 0000h |
---|
[3] | 32 | |
---|
[379] | 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 |
---|
[392] | 36 | %define MENUEVENT_INLINE_OFFSETS ; Only one menu required, save space and inline offsets |
---|
[379] | 37 | %define INCLUDE_MENU_LIBRARY |
---|
[277] | 38 | |
---|
[379] | 39 | %else ; If no boot menu included |
---|
| 40 | %define INCLUDE_DISPLAY_LIBRARY |
---|
[392] | 41 | %define INCLUDE_KEYBOARD_LIBRARY |
---|
[379] | 42 | %define INCLUDE_TIME_LIBRARY |
---|
| 43 | %endif |
---|
| 44 | |
---|
| 45 | |
---|
[181] | 46 | ; Included .inc files |
---|
| 47 | %include "AssemblyLibrary.inc" ; Assembly Library. Must be included first! |
---|
[398] | 48 | %include "ModuleDependency.inc" ; Dependency checks for optional modules |
---|
[358] | 49 | %include "Version.inc" |
---|
[181] | 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 |
---|
[254] | 56 | %include "BootVars.inc" ; For BOOTVARS struct |
---|
[400] | 57 | %include "IdeIO.inc" ; Macros for IDE port I/O |
---|
[181] | 58 | %include "DeviceIDE.inc" ; For IDE device equates |
---|
[3] | 59 | |
---|
| 60 | |
---|
[397] | 61 | |
---|
[3] | 62 | ; Section containing code |
---|
| 63 | SECTION .text |
---|
| 64 | |
---|
| 65 | ; ROM variables (must start at offset 0) |
---|
[239] | 66 | CNT_ROM_BLOCKS EQU ROMSIZE / 512 ; number of 512B blocks, 16 = 8kB BIOS |
---|
[3] | 67 | istruc ROMVARS |
---|
| 68 | at ROMVARS.wRomSign, dw 0AA55h ; PC ROM signature |
---|
| 69 | at ROMVARS.bRomSize, db CNT_ROM_BLOCKS ; ROM size in 512B blocks |
---|
[181] | 70 | at ROMVARS.rgbJump, jmp Initialize_FromMainBiosRomSearch |
---|
[358] | 71 | at ROMVARS.rgbSign, db FLASH_SIGNATURE |
---|
| 72 | at ROMVARS.szTitle, db TITLE_STRING |
---|
| 73 | at ROMVARS.szVersion, db ROM_VERSION_STRING |
---|
[3] | 74 | |
---|
| 75 | ;---------------------------; |
---|
| 76 | ; AT Build default settings ; |
---|
| 77 | ;---------------------------; |
---|
| 78 | %ifdef USE_AT |
---|
[397] | 79 | at ROMVARS.wFlags, dw FLG_ROMVARS_FULLMODE | MASK_ROMVARS_INCLUDED_MODULES |
---|
[143] | 80 | at ROMVARS.wDisplayMode, dw DEFAULT_TEXT_MODE |
---|
[397] | 81 | %ifdef MODULE_BOOT_MENU |
---|
| 82 | at ROMVARS.wBootTimeout, dw BOOT_MENU_DEFAULT_TIMEOUT |
---|
| 83 | %endif |
---|
[150] | 84 | at ROMVARS.bIdeCnt, db 4 ; Number of supported controllers |
---|
[3] | 85 | at ROMVARS.bBootDrv, db 80h ; Boot Menu default drive |
---|
| 86 | at ROMVARS.bMinFddCnt, db 0 ; Do not force minimum number of floppy drives |
---|
| 87 | at ROMVARS.bStealSize, db 1 ; Steal 1kB from base memory |
---|
[380] | 88 | at ROMVARS.bIdleTimeout, db 0 ; Standby timer disabled by default |
---|
[3] | 89 | |
---|
[398] | 90 | at ROMVARS.ideVars0+IDEVARS.wPort, dw DEVICE_ATA_PRIMARY_PORT ; Controller Command Block base port |
---|
| 91 | at ROMVARS.ideVars0+IDEVARS.wPortCtrl, dw DEVICE_ATA_PRIMARY_PORTCTRL ; Controller Control Block base port |
---|
[150] | 92 | at ROMVARS.ideVars0+IDEVARS.bDevice, db DEVICE_16BIT_ATA |
---|
[160] | 93 | at ROMVARS.ideVars0+IDEVARS.bIRQ, db 0 |
---|
[276] | 94 | at ROMVARS.ideVars0+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
| 95 | at ROMVARS.ideVars0+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
[3] | 96 | |
---|
[398] | 97 | at ROMVARS.ideVars1+IDEVARS.wPort, dw DEVICE_ATA_SECONDARY_PORT |
---|
| 98 | at ROMVARS.ideVars1+IDEVARS.wPortCtrl, dw DEVICE_ATA_SECONDARY_PORTCTRL |
---|
[150] | 99 | at ROMVARS.ideVars1+IDEVARS.bDevice, db DEVICE_16BIT_ATA |
---|
[160] | 100 | at ROMVARS.ideVars1+IDEVARS.bIRQ, db 0 |
---|
[276] | 101 | at ROMVARS.ideVars1+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
| 102 | at ROMVARS.ideVars1+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
[3] | 103 | |
---|
[398] | 104 | at ROMVARS.ideVars2+IDEVARS.wPort, dw DEVICE_ATA_TERTIARY_PORT |
---|
| 105 | at ROMVARS.ideVars2+IDEVARS.wPortCtrl, dw DEVICE_ATA_TERTIARY_PORTCTRL |
---|
[386] | 106 | at ROMVARS.ideVars2+IDEVARS.bDevice, db DEVICE_16BIT_ATA |
---|
[150] | 107 | at ROMVARS.ideVars2+IDEVARS.bIRQ, db 0 |
---|
[276] | 108 | at ROMVARS.ideVars2+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
| 109 | at ROMVARS.ideVars2+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
[143] | 110 | |
---|
[398] | 111 | at ROMVARS.ideVars3+IDEVARS.wPort, dw DEVICE_ATA_QUATERNARY_PORT |
---|
| 112 | at ROMVARS.ideVars3+IDEVARS.wPortCtrl, dw DEVICE_ATA_QUATERNARY_PORTCTRL |
---|
[150] | 113 | at ROMVARS.ideVars3+IDEVARS.bDevice, db DEVICE_16BIT_ATA |
---|
| 114 | at ROMVARS.ideVars3+IDEVARS.bIRQ, db 0 |
---|
[276] | 115 | at ROMVARS.ideVars3+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
| 116 | at ROMVARS.ideVars3+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
[175] | 117 | |
---|
| 118 | %ifdef MODULE_SERIAL |
---|
| 119 | at ROMVARS.ideVarsSerialAuto+IDEVARS.bDevice, db DEVICE_SERIAL_PORT |
---|
[181] | 120 | %endif |
---|
[3] | 121 | %else |
---|
| 122 | ;-----------------------------------; |
---|
| 123 | ; XT and XT+ Build default settings ; |
---|
| 124 | ;-----------------------------------; |
---|
[397] | 125 | at ROMVARS.wFlags, dw MASK_ROMVARS_INCLUDED_MODULES |
---|
[143] | 126 | at ROMVARS.wDisplayMode, dw DEFAULT_TEXT_MODE |
---|
[397] | 127 | %ifdef MODULE_BOOT_MENU |
---|
| 128 | at ROMVARS.wBootTimeout, dw BOOT_MENU_DEFAULT_TIMEOUT |
---|
| 129 | %endif |
---|
[3] | 130 | at ROMVARS.bIdeCnt, db 1 ; Number of supported controllers |
---|
| 131 | at ROMVARS.bBootDrv, db 80h ; Boot Menu default drive |
---|
| 132 | at ROMVARS.bMinFddCnt, db 1 ; Assume at least 1 floppy drive present if autodetect fails |
---|
| 133 | at ROMVARS.bStealSize, db 1 ; Steal 1kB from base memory in full mode |
---|
[380] | 134 | at ROMVARS.bIdleTimeout, db 0 ; Standby timer disabled by default |
---|
[3] | 135 | |
---|
[285] | 136 | at ROMVARS.ideVars0+IDEVARS.wPort, dw DEVICE_XTIDE_DEFAULT_PORT ; Controller Command Block base port |
---|
| 137 | at ROMVARS.ideVars0+IDEVARS.wPortCtrl, dw DEVICE_XTIDE_DEFAULT_PORTCTRL ; Controller Control Block base port |
---|
[400] | 138 | at ROMVARS.ideVars0+IDEVARS.bDevice, db DEVICE_8BIT_XTIDE_REV1 |
---|
[276] | 139 | at ROMVARS.ideVars0+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
| 140 | at ROMVARS.ideVars0+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
[143] | 141 | |
---|
[276] | 142 | at ROMVARS.ideVars1+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
| 143 | at ROMVARS.ideVars1+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
[143] | 144 | |
---|
[276] | 145 | at ROMVARS.ideVars2+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
| 146 | at ROMVARS.ideVars2+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
[143] | 147 | |
---|
[276] | 148 | at ROMVARS.ideVars3+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
| 149 | at ROMVARS.ideVars3+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags, db DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE |
---|
[175] | 150 | |
---|
| 151 | %ifdef MODULE_SERIAL |
---|
| 152 | at ROMVARS.ideVarsSerialAuto+IDEVARS.bDevice, db DEVICE_SERIAL_PORT |
---|
[3] | 153 | %endif |
---|
[181] | 154 | %endif |
---|
[3] | 155 | iend |
---|
| 156 | |
---|
[380] | 157 | ; Strings are first to avoid them moving unnecessarily when code is turned on and off with %ifdef's |
---|
[334] | 158 | ; since some groups of strings need to be on the same 256-byte page. |
---|
| 159 | ; |
---|
| 160 | %ifdef MODULE_STRINGS_COMPRESSED |
---|
| 161 | %define STRINGSCOMPRESSED_STRINGS |
---|
[380] | 162 | %include "StringsCompressed.asm" |
---|
[334] | 163 | %else |
---|
| 164 | %include "Strings.asm" ; For BIOS message strings |
---|
| 165 | %endif |
---|
| 166 | |
---|
[248] | 167 | ; Libraries, data, Initialization and drive detection |
---|
[334] | 168 | |
---|
[181] | 169 | %include "AssemblyLibrary.asm" |
---|
[334] | 170 | |
---|
| 171 | ; String compression tables need to come after the AssemblyLibrary (since they depend on addresses |
---|
[380] | 172 | ; established in the assembly library), and are unnecessary if strings are not compressed. |
---|
[334] | 173 | ; |
---|
| 174 | %ifdef MODULE_STRINGS_COMPRESSED |
---|
[380] | 175 | %undef STRINGSCOMPRESSED_STRINGS |
---|
[334] | 176 | %define STRINGSCOMPRESSED_TABLES |
---|
| 177 | %include "StringsCompressed.asm" |
---|
| 178 | %endif |
---|
[380] | 179 | |
---|
[248] | 180 | %include "Initialize.asm" ; For BIOS initialization |
---|
| 181 | %include "Interrupts.asm" ; For Interrupt initialization |
---|
| 182 | %include "RamVars.asm" ; For RAMVARS initialization and access |
---|
[399] | 183 | %include "BootVars.asm" ; For initializing variables used during init and boot |
---|
[392] | 184 | %include "FloppyDrive.asm" ; Floppy Drive related functions |
---|
[285] | 185 | %include "CreateDPT.asm" ; For creating DPTs |
---|
| 186 | %include "FindDPT.asm" ; For finding DPTs |
---|
[181] | 187 | %include "AccessDPT.asm" ; For accessing DPTs |
---|
[358] | 188 | %include "LbaAssist.asm" ; For generating L-CHS parameters to LBA drives |
---|
[397] | 189 | %include "DrvDetectInfo.asm" ; For creating DRVDETECTINFO structs |
---|
[181] | 190 | %include "AtaID.asm" ; For ATA Identify Device information |
---|
| 191 | %include "DetectDrives.asm" ; For detecting IDE drives |
---|
| 192 | %include "DetectPrint.asm" ; For printing drive detection strings |
---|
[395] | 193 | |
---|
| 194 | ; Hotkey Bar |
---|
| 195 | %ifdef MODULE_HOTKEYS |
---|
[392] | 196 | %include "HotkeyBar.asm" ; For hotkeys during drive detection and boot menu |
---|
[395] | 197 | %include "DriveXlate.asm" ; For swapping drive numbers |
---|
| 198 | %endif |
---|
[248] | 199 | |
---|
[181] | 200 | ; Boot menu |
---|
[379] | 201 | %ifdef MODULE_BOOT_MENU |
---|
[181] | 202 | %include "BootMenu.asm" ; For Boot Menu operations |
---|
| 203 | %include "BootMenuEvent.asm" ; For menu library event handling |
---|
[192] | 204 | ; NOTE: BootMenuPrint needs to come immediately after BootMenuEvent |
---|
[258] | 205 | ; so that jump table entries in BootMenuEvent stay within 8-bits |
---|
| 206 | %include "BootMenuPrint.asm" ; For printing Boot Menu strings, also includes "BootMenuPrintCfg.asm" |
---|
[379] | 207 | %endif |
---|
| 208 | |
---|
| 209 | ; Boot loader |
---|
| 210 | %include "Int19h.asm" ; For Int 19h, Boot Loader |
---|
[392] | 211 | %include "Int19hReset.asm" ; INT 19h handler for proper system reset |
---|
[181] | 212 | %include "BootSector.asm" ; For loading boot sector |
---|
[3] | 213 | |
---|
[181] | 214 | ; For all device types |
---|
[192] | 215 | %include "Idepack.asm" |
---|
[181] | 216 | %include "Device.asm" |
---|
| 217 | %include "Timer.asm" ; For timeout and delay |
---|
[155] | 218 | |
---|
[181] | 219 | ; IDE Device support |
---|
[363] | 220 | %ifdef MODULE_ADVANCED_ATA |
---|
| 221 | %include "AdvAtaInit.asm" ; For initializing VLB and PCI controllers |
---|
| 222 | %include "Vision.asm" ; QDI Vision QD6500 and QD6580 support |
---|
| 223 | %endif |
---|
[181] | 224 | %include "IdeCommand.asm" |
---|
[400] | 225 | %ifdef MODULE_JRIDE |
---|
| 226 | %include "JrIdeTransfer.asm" ; Must be included after IdeCommand.asm |
---|
| 227 | %endif |
---|
| 228 | %include "IdeTransfer.asm" |
---|
[192] | 229 | %include "IdeWait.asm" |
---|
[294] | 230 | %include "IdeError.asm" ; Must be included after IdeWait.asm |
---|
[181] | 231 | %include "IdeDPT.asm" |
---|
| 232 | %include "IdeIO.asm" |
---|
[398] | 233 | %ifdef MODULE_IRQ |
---|
[181] | 234 | %include "IdeIrq.asm" |
---|
[398] | 235 | %endif |
---|
[155] | 236 | |
---|
[400] | 237 | ; Serial Device support |
---|
[181] | 238 | %ifdef MODULE_SERIAL ; Serial Port Device support |
---|
| 239 | %include "SerialCommand.asm" |
---|
| 240 | %include "SerialDPT.asm" |
---|
[175] | 241 | %endif |
---|
[155] | 242 | |
---|
[181] | 243 | ; INT 13h Hard Disk BIOS functions |
---|
| 244 | %include "Int13h.asm" ; For Int 13h, Disk functions |
---|
| 245 | %include "AH0h_HReset.asm" ; Required by Int13h_Jump.asm |
---|
| 246 | %include "AH1h_HStatus.asm" ; Required by Int13h_Jump.asm |
---|
| 247 | %include "AH2h_HRead.asm" ; Required by Int13h_Jump.asm |
---|
| 248 | %include "AH3h_HWrite.asm" ; Required by Int13h_Jump.asm |
---|
| 249 | %include "AH4h_HVerify.asm" ; Required by Int13h_Jump.asm |
---|
| 250 | %include "AH8h_HParams.asm" ; Required by Int13h_Jump.asm |
---|
| 251 | %include "AH9h_HInit.asm" ; Required by Int13h_Jump.asm |
---|
| 252 | %include "AHCh_HSeek.asm" ; Required by Int13h_Jump.asm |
---|
| 253 | %include "AHDh_HReset.asm" ; Required by Int13h_Jump.asm |
---|
| 254 | %include "AH10h_HReady.asm" ; Required by Int13h_Jump.asm |
---|
| 255 | %include "AH11h_HRecal.asm" ; Required by Int13h_Jump.asm |
---|
| 256 | %include "AH15h_HSize.asm" ; Required by Int13h_Jump.asm |
---|
| 257 | %include "AH23h_HFeatures.asm" ; Required by Int13h_Jump.asm |
---|
| 258 | %include "AH24h_HSetBlocks.asm" ; Required by Int13h_Jump.asm |
---|
| 259 | %include "AH25h_HDrvID.asm" ; Required by Int13h_Jump.asm |
---|
[221] | 260 | %include "Address.asm" ; For sector address translations |
---|
| 261 | %include "Prepare.asm" ; For buffer pointer normalization |
---|
[176] | 262 | %ifdef MODULE_EBIOS |
---|
[181] | 263 | %include "AH42h_ExtendedReadSectors.asm" |
---|
| 264 | %include "AH43h_ExtendedWriteSectors.asm" |
---|
| 265 | %include "AH44h_ExtendedVerifySectors.asm" |
---|
| 266 | %include "AH47h_ExtendedSeek.asm" |
---|
| 267 | %include "AH48h_GetExtendedDriveParameters.asm" |
---|
[221] | 268 | %include "AH41h_CheckIfExtensionsPresent.asm" |
---|
[176] | 269 | %endif |
---|