[497] | 1 | ; Project name : XTIDE Universal BIOS Configurator v2
|
---|
| 2 | ; Description : Functions to automatically configure XTIDE
|
---|
| 3 | ; Universal BIOS for current system.
|
---|
| 4 |
|
---|
| 5 | ;
|
---|
| 6 | ; XTIDE Universal BIOS and Associated Tools
|
---|
[526] | 7 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
[497] | 8 | ;
|
---|
| 9 | ; This program is free software; you can redistribute it and/or modify
|
---|
| 10 | ; it under the terms of the GNU General Public License as published by
|
---|
| 11 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
| 12 | ; (at your option) any later version.
|
---|
| 13 | ;
|
---|
| 14 | ; This program is distributed in the hope that it will be useful,
|
---|
| 15 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | ; GNU General Public License for more details.
|
---|
| 18 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
| 19 | ;
|
---|
| 20 |
|
---|
| 21 | ; Section containing code
|
---|
| 22 | SECTION .text
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 | ;--------------------------------------------------------------------
|
---|
| 26 | ; AutoConfigure_ForThisSystem
|
---|
| 27 | ; MENUITEM activation function (.fnActivate)
|
---|
| 28 | ; Parameters:
|
---|
| 29 | ; SS:BP: Ptr to MENU
|
---|
| 30 | ; Returns:
|
---|
| 31 | ; Nothing
|
---|
| 32 | ; Corrupts registers:
|
---|
| 33 | ; All, except segments
|
---|
| 34 | ;--------------------------------------------------------------------
|
---|
| 35 | ALIGN JUMP_ALIGN
|
---|
| 36 | AutoConfigure_ForThisSystem:
|
---|
| 37 | push es
|
---|
| 38 | push ds
|
---|
| 39 |
|
---|
| 40 | call Buffers_GetFileBufferToESDI ; ROMVARS now in ES:DI
|
---|
| 41 | push es
|
---|
| 42 | pop ds ; ROMVARS now in DS:DI
|
---|
[605] | 43 | call ChecksumSystemBios
|
---|
[497] | 44 | call ResetIdevarsToDefaultValues
|
---|
| 45 | call DetectIdePortsAndDevices
|
---|
[592] | 46 | call EnableInterruptsForAllStandardControllers
|
---|
[497] | 47 | call StoreAndDisplayNumberOfControllers
|
---|
| 48 |
|
---|
| 49 | pop ds
|
---|
| 50 | pop es
|
---|
[605] | 51 | .Return:
|
---|
[497] | 52 | ret
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | ;--------------------------------------------------------------------
|
---|
[605] | 56 | ; ChecksumSystemBios
|
---|
| 57 | ; Parameters:
|
---|
| 58 | ; DS:DI: Ptr to ROMVARS
|
---|
| 59 | ; Returns:
|
---|
| 60 | ; Nothing
|
---|
| 61 | ; Corrupts registers:
|
---|
| 62 | ; AX, BX, CX, DX, SI
|
---|
| 63 | ;--------------------------------------------------------------------
|
---|
| 64 | ALIGN JUMP_ALIGN
|
---|
| 65 | ChecksumSystemBios:
|
---|
| 66 | push ds
|
---|
| 67 | mov si, 0F000h
|
---|
| 68 | mov ds, si
|
---|
| 69 | mov si, 0FFFFh
|
---|
| 70 | ; DS:SI now points to the end of the System BIOS.
|
---|
| 71 | std
|
---|
| 72 | mov cx, 32768 ; The smallest known problematic BIOS so far.
|
---|
| 73 | mov dx, si ; Initialize the checksum
|
---|
| 74 | call CalculateCRC_CCITTfromDSSIwithSizeInCX
|
---|
| 75 | pop ds
|
---|
| 76 | mov bx, .Checksums
|
---|
| 77 | cld
|
---|
| 78 | .NextChecksum:
|
---|
| 79 | mov ax, [cs:bx]
|
---|
| 80 | test ax, ax
|
---|
| 81 | jz SHORT AutoConfigure_ForThisSystem.Return
|
---|
| 82 | inc bx
|
---|
| 83 | inc bx
|
---|
| 84 | cmp ax, dx
|
---|
| 85 | jne SHORT .NextChecksum
|
---|
| 86 | or BYTE [di+ROMVARS.wFlags], FLG_ROMVARS_CLEAR_BDA_HD_COUNT
|
---|
| 87 | mov dx, g_szDlgBadBiosFound
|
---|
| 88 | jmp Dialogs_DisplayNotificationFromCSDX
|
---|
| 89 |
|
---|
| 90 | ALIGN WORD_ALIGN
|
---|
| 91 | .Checksums:
|
---|
| 92 | dw 0D192h ; 32 KB Zenith Z-161 (071784)
|
---|
| 93 | dw 02F69h ; 32 KB Zenith Z-171 (031485)
|
---|
| 94 | dw 0
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | ;--------------------------------------------------------------------
|
---|
| 98 | ; CalculateCRC_CCITTfromDSSIwithSizeInCX
|
---|
| 99 | ; Parameters:
|
---|
| 100 | ; DS:SI: Pointer to string to checksum
|
---|
| 101 | ; CX: Length of string to checksum
|
---|
| 102 | ; DX: Checksum (initially 0FFFFh)
|
---|
| 103 | ; DF: Set/Clear depending on direction wanted
|
---|
| 104 | ; Returns:
|
---|
| 105 | ; DX: Checksum
|
---|
| 106 | ; DS:SI: Pointer to byte after the end of checksummed string
|
---|
| 107 | ; Corrupts registers:
|
---|
| 108 | ; AX, BX, CX
|
---|
| 109 | ;--------------------------------------------------------------------
|
---|
| 110 | ALIGN JUMP_ALIGN
|
---|
| 111 | CalculateCRC_CCITTfromDSSIwithSizeInCX:
|
---|
| 112 | ; jcxz .Return
|
---|
| 113 | xor bh, bh
|
---|
| 114 | mov ah, 0E0h
|
---|
| 115 | .NextByte:
|
---|
| 116 | lodsb
|
---|
| 117 | xor dh, al
|
---|
| 118 | mov bl, dh
|
---|
| 119 | rol bx, 1
|
---|
| 120 | rol bx, 1
|
---|
| 121 | rol bx, 1
|
---|
| 122 | rol bx, 1
|
---|
| 123 | xor dx, bx
|
---|
| 124 | rol bx, 1
|
---|
| 125 | xchg dh, dl
|
---|
| 126 | xor dx, bx
|
---|
| 127 | ror bx, 1
|
---|
| 128 | ror bx, 1
|
---|
| 129 | ror bx, 1
|
---|
| 130 | ror bx, 1
|
---|
| 131 | and bl, ah
|
---|
| 132 | xor dx, bx
|
---|
| 133 | ror bx, 1
|
---|
| 134 | xor dh, bl
|
---|
| 135 | loop .NextByte
|
---|
| 136 | ;.Return:
|
---|
| 137 | ret
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 | ;--------------------------------------------------------------------
|
---|
[497] | 141 | ; ResetIdevarsToDefaultValues
|
---|
| 142 | ; Parameters:
|
---|
| 143 | ; DS:DI: Ptr to ROMVARS
|
---|
[592] | 144 | ; ES:DI: Ptr to ROMVARS
|
---|
[497] | 145 | ; Returns:
|
---|
| 146 | ; Nothing
|
---|
| 147 | ; Corrupts registers:
|
---|
| 148 | ; AX, CX
|
---|
| 149 | ;--------------------------------------------------------------------
|
---|
| 150 | ALIGN JUMP_ALIGN
|
---|
| 151 | ResetIdevarsToDefaultValues:
|
---|
| 152 | push di
|
---|
| 153 | add di, BYTE ROMVARS.ideVarsBegin
|
---|
| 154 | mov cx, ROMVARS.ideVarsEnd - ROMVARS.ideVarsBegin
|
---|
| 155 | call Memory_ZeroESDIwithSizeInCX ; Never clears ROMVARS.ideVarsSerialAuto
|
---|
| 156 | pop di
|
---|
| 157 |
|
---|
| 158 | ; Set default values (other than zero)
|
---|
| 159 | mov ax, DISABLE_WRITE_CACHE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION) | FLG_DRVPARAMS_BLOCKMODE
|
---|
| 160 | mov [di+ROMVARS.ideVars0+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags], ax
|
---|
[502] | 161 | mov [di+ROMVARS.ideVars0+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags], ax
|
---|
| 162 |
|
---|
[497] | 163 | mov [di+ROMVARS.ideVars1+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags], ax
|
---|
[502] | 164 | mov [di+ROMVARS.ideVars1+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags], ax
|
---|
| 165 |
|
---|
[497] | 166 | mov [di+ROMVARS.ideVars2+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags], ax
|
---|
[502] | 167 | mov [di+ROMVARS.ideVars2+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags], ax
|
---|
| 168 |
|
---|
[497] | 169 | mov [di+ROMVARS.ideVars3+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags], ax
|
---|
[502] | 170 | mov [di+ROMVARS.ideVars3+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags], ax
|
---|
[497] | 171 | ret
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 | ;--------------------------------------------------------------------
|
---|
| 175 | ; DetectIdePortsAndDevices
|
---|
| 176 | ; Parameters:
|
---|
| 177 | ; DS:DI: Ptr to ROMVARS
|
---|
| 178 | ; Returns:
|
---|
| 179 | ; CX: Number of controllers detected
|
---|
| 180 | ; Corrupts registers:
|
---|
| 181 | ; AX, BX, DX, SI
|
---|
| 182 | ;--------------------------------------------------------------------
|
---|
| 183 | ALIGN JUMP_ALIGN
|
---|
| 184 | DetectIdePortsAndDevices:
|
---|
| 185 | xor cx, cx ; Number of devices found
|
---|
| 186 | xor dx, dx ; IDE_PORT_TO_START_DETECTION
|
---|
| 187 | lea si, [di+ROMVARS.ideVarsBegin] ; DS:SI points to first IDEVARS
|
---|
| 188 |
|
---|
| 189 | .DetectFromNextPort:
|
---|
| 190 | call IdeAutodetect_IncrementDXtoNextIdeBasePort
|
---|
| 191 | jz SHORT .AllPortsAlreadyDetected
|
---|
[504] | 192 | push si
|
---|
| 193 | call IdeAutodetect_DetectIdeDeviceFromPortDXAndReturnControlBlockInSI
|
---|
| 194 | mov bx, si
|
---|
| 195 | pop si
|
---|
[497] | 196 | jc SHORT .DetectFromNextPort
|
---|
| 197 |
|
---|
| 198 | ; Device found from port DX, Device Type returned in AL
|
---|
| 199 | inc cx ; Increment number of controllers found
|
---|
| 200 | mov [si+IDEVARS.wBasePort], dx
|
---|
| 201 | mov [si+IDEVARS.wControlBlockPort], bx
|
---|
| 202 | mov [si+IDEVARS.bDevice], al
|
---|
| 203 |
|
---|
| 204 | ; Point to next IDEVARS
|
---|
[505] | 205 | add si, IDEVARS_size
|
---|
[497] | 206 | cmp si, ROMVARS.ideVars3
|
---|
[505] | 207 | jbe SHORT .DetectFromNextPort
|
---|
[497] | 208 | .AllPortsAlreadyDetected:
|
---|
| 209 | ret
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 | ;--------------------------------------------------------------------
|
---|
[592] | 213 | ; EnableInterruptsForAllStandardControllers
|
---|
[523] | 214 | ; Parameters:
|
---|
| 215 | ; DS:DI: Ptr to ROMVARS
|
---|
| 216 | ; CX: Number of controllers detected
|
---|
| 217 | ; Returns:
|
---|
| 218 | ; Nothing
|
---|
| 219 | ; Corrupts registers:
|
---|
[592] | 220 | ; AX
|
---|
[523] | 221 | ;--------------------------------------------------------------------
|
---|
| 222 | ALIGN JUMP_ALIGN
|
---|
[592] | 223 | EnableInterruptsForAllStandardControllers:
|
---|
[523] | 224 | jcxz .NoControllersDetected
|
---|
| 225 | call Buffers_IsXTbuildLoaded
|
---|
| 226 | je SHORT .DoNotEnableIRQforXTbuilds
|
---|
| 227 | push di
|
---|
| 228 | push cx
|
---|
| 229 |
|
---|
| 230 | add di, BYTE ROMVARS.ideVars0 ; DS:DI now points first IDEVARS
|
---|
| 231 | .CheckNextController:
|
---|
| 232 | mov al, 14
|
---|
| 233 | cmp WORD [di+IDEVARS.wBasePort], DEVICE_ATA_PRIMARY_PORT
|
---|
| 234 | je SHORT .EnableIrqAL
|
---|
| 235 |
|
---|
| 236 | inc ax ; 15
|
---|
| 237 | cmp WORD [di+IDEVARS.wBasePort], DEVICE_ATA_SECONDARY_PORT
|
---|
[592] | 238 |
|
---|
| 239 | %if 0
|
---|
| 240 | je SHORT .EnableIrqAL
|
---|
| 241 |
|
---|
| 242 | ; Defaults on the GSI Inc. Model 2C EIDE controller
|
---|
| 243 | mov al, 11
|
---|
| 244 | cmp WORD [di+IDEVARS.wBasePort], DEVICE_ATA_TERTIARY_PORT
|
---|
| 245 | je SHORT .EnableIrqAL
|
---|
| 246 |
|
---|
| 247 | dec ax ; 10
|
---|
| 248 | cmp WORD [di+IDEVARS.wBasePort], DEVICE_ATA_QUATERNARY_PORT
|
---|
| 249 | %endif
|
---|
| 250 |
|
---|
[523] | 251 | jne SHORT .DoNotEnableIRQ
|
---|
| 252 |
|
---|
| 253 | .EnableIrqAL:
|
---|
| 254 | mov [di+IDEVARS.bIRQ], al
|
---|
| 255 | .DoNotEnableIRQ:
|
---|
[592] | 256 | add di, IDEVARS_size
|
---|
[523] | 257 | loop .CheckNextController
|
---|
| 258 | pop cx
|
---|
| 259 | pop di
|
---|
| 260 | .DoNotEnableIRQforXTbuilds:
|
---|
| 261 | .NoControllersDetected:
|
---|
| 262 | ret
|
---|
| 263 |
|
---|
| 264 |
|
---|
| 265 | ;--------------------------------------------------------------------
|
---|
[497] | 266 | ; StoreAndDisplayNumberOfControllers
|
---|
| 267 | ; Parameters:
|
---|
| 268 | ; CX: Number of controllers detected
|
---|
| 269 | ; DS:DI: Ptr to ROMVARS
|
---|
| 270 | ; SS:BP: Ptr to MENU
|
---|
| 271 | ; Returns:
|
---|
| 272 | ; Nothing
|
---|
| 273 | ; Corrupts registers:
|
---|
| 274 | ; AX, BX, DX, DI, SI, DS, ES
|
---|
| 275 | ;--------------------------------------------------------------------
|
---|
| 276 | ALIGN JUMP_ALIGN
|
---|
| 277 | StoreAndDisplayNumberOfControllers:
|
---|
[525] | 278 | xor ax, ax
|
---|
| 279 | or al, cl
|
---|
| 280 | jnz SHORT .AtLeastOneController
|
---|
| 281 | inc ax ; Cannot store zero
|
---|
| 282 | .AtLeastOneController:
|
---|
[497] | 283 | test BYTE [di+ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
|
---|
| 284 | jnz SHORT .FullModeSoNoNeedToLimit
|
---|
| 285 | MIN_U al, MAX_LITE_MODE_CONTROLLERS
|
---|
| 286 | .FullModeSoNoNeedToLimit:
|
---|
| 287 |
|
---|
| 288 | ; Store number of IDE Controllers. This will also modify
|
---|
| 289 | ; menu and set unsaved changes flag.
|
---|
| 290 | push cs
|
---|
| 291 | pop ds
|
---|
| 292 | mov si, g_MenuitemConfigurationIdeControllers
|
---|
| 293 | call Menuitem_StoreValueFromAXtoMenuitemInDSSI
|
---|
| 294 |
|
---|
| 295 | ; Display results (should be changed to proper string formatting)
|
---|
| 296 | add cl, '0'
|
---|
| 297 | mov [cs:g_bControllersDetected], cl
|
---|
| 298 | mov dx, g_szDlgAutoConfigure
|
---|
| 299 | jmp Dialogs_DisplayNotificationFromCSDX
|
---|