source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/AutoConfigure.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: 9.1 KB
Line 
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
7; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
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
22SECTION .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;--------------------------------------------------------------------
35ALIGN JUMP_ALIGN
36AutoConfigure_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
43    call    ChecksumSystemBios
44    call    DetectOlivettiM24
45    call    ResetIdevarsToDefaultValues
46    call    DetectIdePortsAndDevices
47    call    EnableInterruptsForAllStandardControllers
48    call    StoreAndDisplayNumberOfControllers
49
50    pop     ds
51    pop     es
52.Return:
53    ret
54
55
56;--------------------------------------------------------------------
57; ChecksumSystemBios
58;   Parameters:
59;       DS:DI:  Ptr to ROMVARS
60;   Returns:
61;       Nothing
62;   Corrupts registers:
63;       AX, BX, CX, DX, SI
64;--------------------------------------------------------------------
65ALIGN JUMP_ALIGN
66ChecksumSystemBios:
67    push    ds
68    mov     si, 0F000h
69    mov     ds, si
70    mov     si, 0FFFFh
71    ; DS:SI now points to the end of the System BIOS.
72    std
73    mov     cx, 32768   ; The smallest known problematic BIOS so far.
74    mov     dx, si      ; Initialize the checksum
75    call    CalculateCRC_CCITTfromDSSIwithSizeInCX
76    pop     ds
77    mov     bx, .Checksums
78    cld
79.NextChecksum:
80    mov     ax, [cs:bx]
81    test    ax, ax
82    jz      SHORT AutoConfigure_ForThisSystem.Return
83    inc     bx
84    inc     bx
85    cmp     ax, dx
86    jne     SHORT .NextChecksum
87    or      BYTE [di+ROMVARS.wFlags], FLG_ROMVARS_CLEAR_BDA_HD_COUNT
88    mov     dx, g_szDlgBadBiosFound
89    jmp     Dialogs_DisplayNotificationFromCSDX
90
91ALIGN WORD_ALIGN
92.Checksums:
93    dw      0D192h                      ; 32 KB Zenith Z-161 (071784)
94    dw      02F69h                      ; 32 KB Zenith Z-171 (031485)
95    dw      0
96
97
98;--------------------------------------------------------------------
99; CalculateCRC_CCITTfromDSSIwithSizeInCX
100;   Parameters:
101;       DS:SI:  Pointer to string to checksum
102;       CX:     Length of string to checksum
103;       DX:     Checksum (initially 0FFFFh)
104;       DF:     Set/Clear depending on direction wanted
105;   Returns:
106;       DX:     Checksum
107;       DS:SI:  Pointer to byte after the end of checksummed string
108;   Corrupts registers:
109;       AX, BX, CX
110;--------------------------------------------------------------------
111ALIGN JUMP_ALIGN
112CalculateCRC_CCITTfromDSSIwithSizeInCX:
113;   jcxz    .Return
114    xor     bh, bh
115    mov     ah, 0E0h
116.NextByte:
117    lodsb
118    xor     dh, al
119    mov     bl, dh
120%ifdef USE_186
121    rol     bx, 4
122%else
123    rol     bx, 1
124    rol     bx, 1
125    rol     bx, 1
126    rol     bx, 1
127%endif
128    xor     dx, bx
129    rol     bx, 1
130    xchg    dh, dl
131    xor     dx, bx
132%ifdef USE_186
133    ror     bx, 4
134%else
135    ror     bx, 1
136    ror     bx, 1
137    ror     bx, 1
138    ror     bx, 1
139%endif
140    and     bl, ah
141    xor     dx, bx
142    ror     bx, 1
143    xor     dh, bl
144    loop    .NextByte
145;.Return:
146    ret
147
148
149;--------------------------------------------------------------------
150; DetectOlivettiM24
151;   Parameters:
152;       Nothing
153;   Returns:
154;       ZF:     Set if computer is not an Olivetti M24
155;               Clear if computer is an Olivetti M24
156;   Corrupts registers:
157;       AX, BX, CX, DX
158;--------------------------------------------------------------------
159ALIGN JUMP_ALIGN
160DetectOlivettiM24:
161    mov     ah, 0FEh    ; Request the current date and time
162    mov     ch, 0FFh    ; Set the hours to an invalid value
163    int     BIOS_TIME_PCI_PNP_INTERRUPT_1Ah
164    inc     ch          ; Hours changed?
165    jz      SHORT .ThisIsNotAnOlivettiM24
166    mov     BYTE [cs:bIsOlivettiM24], 1
167.ThisIsNotAnOlivettiM24:
168    ret
169
170bIsOlivettiM24:
171    db      0
172
173
174;--------------------------------------------------------------------
175; ResetIdevarsToDefaultValues
176;   Parameters:
177;       DS:DI:  Ptr to ROMVARS
178;       ES:DI:  Ptr to ROMVARS
179;   Returns:
180;       Nothing
181;   Corrupts registers:
182;       AX, CX
183;--------------------------------------------------------------------
184ALIGN JUMP_ALIGN
185ResetIdevarsToDefaultValues:
186    push    di
187    add     di, BYTE ROMVARS.ideVarsBegin
188    mov     cx, ROMVARS.ideVarsEnd - ROMVARS.ideVarsBegin
189    call    Memory_ZeroESDIwithSizeInCX ; Never clears ROMVARS.ideVarsSerialAuto
190    pop     di
191
192    ; Set default values (other than zero)
193    mov     ax, DISABLE_WRITE_CACHE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION) | FLG_DRVPARAMS_BLOCKMODE
194    mov     [di+ROMVARS.ideVars0+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags], ax
195    mov     [di+ROMVARS.ideVars0+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags], ax
196
197    mov     [di+ROMVARS.ideVars1+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags], ax
198    mov     [di+ROMVARS.ideVars1+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags], ax
199
200    mov     [di+ROMVARS.ideVars2+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags], ax
201    mov     [di+ROMVARS.ideVars2+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags], ax
202
203    mov     [di+ROMVARS.ideVars3+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags], ax
204    mov     [di+ROMVARS.ideVars3+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags], ax
205    ret
206
207
208;--------------------------------------------------------------------
209; DetectIdePortsAndDevices
210;   Parameters:
211;       DS:DI:  Ptr to ROMVARS
212;   Returns:
213;       CX:     Number of controllers detected
214;   Corrupts registers:
215;       AX, BX, DX, SI
216;--------------------------------------------------------------------
217ALIGN JUMP_ALIGN
218DetectIdePortsAndDevices:
219    xor     cx, cx                          ; Number of devices found
220    xor     dx, dx                          ; IDE_PORT_TO_START_DETECTION
221    lea     si, [di+ROMVARS.ideVarsBegin]   ; DS:SI points to first IDEVARS
222
223.DetectFromNextPort:
224    call    IdeAutodetect_IncrementDXtoNextIdeBasePort
225    jz      SHORT .AllPortsAlreadyDetected
226    push    si
227    call    IdeAutodetect_DetectIdeDeviceFromPortDXAndReturnControlBlockInSI
228    mov     bx, si
229    pop     si
230    jc      SHORT .DetectFromNextPort
231
232    ; Device found from port DX, Device Type returned in AL
233    inc     cx  ; Increment number of controllers found
234    mov     [si+IDEVARS.wBasePort], dx
235    mov     [si+IDEVARS.wControlBlockPort], bx
236    mov     [si+IDEVARS.bDevice], al
237
238    ; Point to next IDEVARS
239    add     si, IDEVARS_size
240    cmp     si, ROMVARS.ideVars3
241    jbe     SHORT .DetectFromNextPort
242.AllPortsAlreadyDetected:
243    ret
244
245
246;--------------------------------------------------------------------
247; EnableInterruptsForAllStandardControllers
248;   Parameters:
249;       DS:DI:  Ptr to ROMVARS
250;       CX:     Number of controllers detected
251;   Returns:
252;       Nothing
253;   Corrupts registers:
254;       AX
255;--------------------------------------------------------------------
256ALIGN JUMP_ALIGN
257EnableInterruptsForAllStandardControllers:
258    jcxz    .NoControllersDetected
259    test    BYTE [ROMVARS.wFlags+1], FLG_ROMVARS_MODULE_IRQ >> 8
260    jz      SHORT .NoModuleIrq
261    call    Buffers_IsXTbuildLoaded
262    je      SHORT .DoNotEnableIRQforXTbuilds
263    push    di
264    push    cx
265
266    add     di, BYTE ROMVARS.ideVars0   ; DS:DI now points first IDEVARS
267.CheckNextController:
268    mov     al, 14
269    cmp     WORD [di+IDEVARS.wBasePort], DEVICE_ATA_PRIMARY_PORT
270    je      SHORT .EnableIrqAL
271
272    inc     ax  ; 15
273    cmp     WORD [di+IDEVARS.wBasePort], DEVICE_ATA_SECONDARY_PORT
274
275%if 0
276    je      SHORT .EnableIrqAL
277
278    ; Defaults on the GSI Inc. Model 2C EIDE controller
279    mov     al, 11
280    cmp     WORD [di+IDEVARS.wBasePort], DEVICE_ATA_TERTIARY_PORT
281    je      SHORT .EnableIrqAL
282
283    dec     ax  ; 10
284    cmp     WORD [di+IDEVARS.wBasePort], DEVICE_ATA_QUATERNARY_PORT
285%endif
286
287    jne     SHORT .DoNotEnableIRQ
288
289.EnableIrqAL:
290    mov     [di+IDEVARS.bIRQ], al
291.DoNotEnableIRQ:
292    add     di, IDEVARS_size
293    loop    .CheckNextController
294    pop     cx
295    pop     di
296.DoNotEnableIRQforXTbuilds:
297.NoModuleIrq:
298.NoControllersDetected:
299    ret
300
301
302;--------------------------------------------------------------------
303; StoreAndDisplayNumberOfControllers
304;   Parameters:
305;       CX:     Number of controllers detected
306;       DS:DI:  Ptr to ROMVARS
307;       SS:BP:  Ptr to MENU
308;   Returns:
309;       Nothing
310;   Corrupts registers:
311;       AX, BX, DX, DI, SI, DS, ES
312;--------------------------------------------------------------------
313ALIGN JUMP_ALIGN
314StoreAndDisplayNumberOfControllers:
315    xor     ax, ax
316    or      al, cl
317    jnz     SHORT .AtLeastOneController
318    inc     ax                          ; Cannot store zero
319.AtLeastOneController:
320    test    BYTE [di+ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
321    jnz     SHORT .FullModeSoNoNeedToLimit
322    MIN_U   al, MAX_LITE_MODE_CONTROLLERS
323.FullModeSoNoNeedToLimit:
324
325    ; Store number of IDE Controllers. This will also modify
326    ; menu and set unsaved changes flag.
327    push    cs
328    pop     ds
329    mov     si, g_MenuitemConfigurationIdeControllers
330    call    Menuitem_StoreValueFromAXtoMenuitemInDSSI
331
332    ; Display results (should be changed to proper string formatting)
333    add     cl, '0'
334    mov     [cs:g_bControllersDetected], cl
335    mov     dx, g_szDlgAutoConfigure
336    jmp     Dialogs_DisplayNotificationFromCSDX
Note: See TracBrowser for help on using the repository browser.