1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : Functions for detecting drive for the BIOS.
|
---|
3 |
|
---|
4 | ; Section containing code
|
---|
5 | SECTION .text
|
---|
6 |
|
---|
7 | ;--------------------------------------------------------------------
|
---|
8 | ; Detects all IDE hard disks to be controlled by this BIOS.
|
---|
9 | ;
|
---|
10 | ; DetectDrives_FromAllIDEControllers
|
---|
11 | ; Parameters:
|
---|
12 | ; DS: RAMVARS segment
|
---|
13 | ; ES: BDA segment (zero)
|
---|
14 | ; Returns:
|
---|
15 | ; Nothing
|
---|
16 | ; Corrupts registers:
|
---|
17 | ; All (not segments)
|
---|
18 | ;--------------------------------------------------------------------
|
---|
19 | DetectDrives_FromAllIDEControllers:
|
---|
20 | call RamVars_GetIdeControllerCountToCX
|
---|
21 | mov bp, ROMVARS.ideVars0 ; CS:BP now points to first IDEVARS
|
---|
22 | .DriveDetectLoop:
|
---|
23 | call .DetectDrives_WithIDEVARS ; Detect Master and Slave
|
---|
24 | add bp, BYTE IDEVARS_size ; Point to next IDEVARS
|
---|
25 | loop .DriveDetectLoop
|
---|
26 |
|
---|
27 | %ifdef MODULE_SERIAL
|
---|
28 | test BYTE [es:BDA.bKBFlgs1], (1<<2)
|
---|
29 | ;; jz .done
|
---|
30 | mov bp, ROMVARS.ideVarsAutoSerial
|
---|
31 | ;;; fall-through
|
---|
32 | %else
|
---|
33 | ret
|
---|
34 | %endif
|
---|
35 |
|
---|
36 | ;--------------------------------------------------------------------
|
---|
37 | ; Detects IDE hard disks by using information from IDEVARS.
|
---|
38 | ;
|
---|
39 | ; DetectDrives_WithIDEVARS
|
---|
40 | ; Parameters:
|
---|
41 | ; CS:BP: Ptr to IDEVARS
|
---|
42 | ; DS: RAMVARS segment
|
---|
43 | ; ES: Zero (BDA segment)
|
---|
44 | ; Returns:
|
---|
45 | ; Nothing
|
---|
46 | ; Corrupts registers:
|
---|
47 | ; AX, BX, DX, SI, DI
|
---|
48 | ;--------------------------------------------------------------------
|
---|
49 | .DetectDrives_WithIDEVARS:
|
---|
50 | push cx
|
---|
51 | mov ax, g_szMaster
|
---|
52 | mov bh, MASK_DRVNHEAD_SET ; Select Master drive
|
---|
53 | call StartDetectionWithDriveSelectByteInBHandStringInAX ; Detect and create DPT + BOOTNFO
|
---|
54 |
|
---|
55 | mov ax, g_szSlave
|
---|
56 | mov bh, MASK_DRVNHEAD_SET | FLG_DRVNHEAD_DRV
|
---|
57 | call StartDetectionWithDriveSelectByteInBHandStringInAX
|
---|
58 | pop cx
|
---|
59 | .done:
|
---|
60 | ret
|
---|
61 |
|
---|
62 |
|
---|
63 | ;--------------------------------------------------------------------
|
---|
64 | ; StartDetectionWithDriveSelectByteInBHandStringInAX
|
---|
65 | ; Parameters:
|
---|
66 | ; AX: Offset to "Master" or "Slave" string
|
---|
67 | ; BH: Drive Select byte for Drive and Head Register
|
---|
68 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
69 | ; DS: RAMVARS segment
|
---|
70 | ; ES: Zero (BDA segment)
|
---|
71 | ; Returns:
|
---|
72 | ; Nothing
|
---|
73 | ; Corrupts registers:
|
---|
74 | ; AX, BX, CX, DX, SI, DI
|
---|
75 | ;--------------------------------------------------------------------
|
---|
76 | StartDetectionWithDriveSelectByteInBHandStringInAX:
|
---|
77 | call DetectPrint_StartDetectWithMasterOrSlaveStringInAXandIdeVarsInCSBP
|
---|
78 | ; Fall to .ReadAtaInfoFromHardDisk
|
---|
79 |
|
---|
80 | ;--------------------------------------------------------------------
|
---|
81 | ; .ReadAtaInfoFromHardDisk
|
---|
82 | ; Parameters:
|
---|
83 | ; BH: Drive Select byte for Drive and Head Register
|
---|
84 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
85 | ; DS: RAMVARS segment
|
---|
86 | ; ES: Zero (BDA segment)
|
---|
87 | ; Returns:
|
---|
88 | ; CF: Cleared if ATA-information read successfully
|
---|
89 | ; Set if any error
|
---|
90 | ; Corrupts registers:
|
---|
91 | ; AX, BL, CX, DX, SI, DI
|
---|
92 | ;--------------------------------------------------------------------
|
---|
93 | .ReadAtaInfoFromHardDisk:
|
---|
94 | mov si, BOOTVARS.rgbAtaInfo ; ES:SI now points to ATA info location
|
---|
95 | push es
|
---|
96 | push si
|
---|
97 | push bx
|
---|
98 | call Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
|
---|
99 | pop bx
|
---|
100 | pop si
|
---|
101 | pop es
|
---|
102 | jnc SHORT CreateBiosTablesForHardDisk
|
---|
103 | ; Fall to .ReadAtapiInfoFromDrive
|
---|
104 |
|
---|
105 | .ReadAtapiInfoFromDrive: ; Not yet implemented
|
---|
106 | ;call ReadAtapiInfoFromDrive ; Assume CD-ROM
|
---|
107 | ;jnc SHORT _CreateBiosTablesForCDROM
|
---|
108 | jmp DetectPrint_DriveNotFound
|
---|
109 |
|
---|
110 |
|
---|
111 | ;--------------------------------------------------------------------
|
---|
112 | ; CreateBiosTablesForHardDisk
|
---|
113 | ; Parameters:
|
---|
114 | ; BH: Drive Select byte for Drive and Head Register
|
---|
115 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
116 | ; ES:SI Ptr to ATA information for the drive
|
---|
117 | ; DS: RAMVARS segment
|
---|
118 | ; ES: BDA/Bootnfo segment
|
---|
119 | ; Returns:
|
---|
120 | ; Nothing
|
---|
121 | ; Corrupts registers:
|
---|
122 | ; AX, BX, CX, DX, SI, DI
|
---|
123 | ;--------------------------------------------------------------------
|
---|
124 | CreateBiosTablesForHardDisk:
|
---|
125 | call CreateDPT_FromAtaInformation
|
---|
126 | jc SHORT .InvalidAtaInfo
|
---|
127 | call BootInfo_CreateForHardDisk
|
---|
128 | jmp DetectPrint_DriveNameFromBootnfoInESBX
|
---|
129 | .InvalidAtaInfo:
|
---|
130 | jmp DetectPrint_DriveNotFound
|
---|