1 | ; File name : BootInfo.asm
|
---|
2 | ; Project name : XTIDE Universal BIOS
|
---|
3 | ; Description : Functions for generating and accessing drive
|
---|
4 | ; information to be displayed on boot menu.
|
---|
5 |
|
---|
6 | ; Section containing code
|
---|
7 | SECTION .text
|
---|
8 |
|
---|
9 | ;--------------------------------------------------------------------
|
---|
10 | ; Creates new BOOTNFO struct for detected hard disk.
|
---|
11 | ;
|
---|
12 | ; BootInfo_CreateForHardDisk
|
---|
13 | ; Parameters:
|
---|
14 | ; DL: Drive number
|
---|
15 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
16 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
17 | ; Returns:
|
---|
18 | ; ES:BX: Ptr to BOOTNFO (if successful)
|
---|
19 | ; CF: Cleared if BOOTNFO created succesfully
|
---|
20 | ; Set if any error
|
---|
21 | ; Corrupts registers:
|
---|
22 | ; AX, BX, CX, DX
|
---|
23 | ;--------------------------------------------------------------------
|
---|
24 | ALIGN JUMP_ALIGN
|
---|
25 | BootInfo_CreateForHardDisk:
|
---|
26 | call BootInfo_GetOffsetToBX ; ES:BX now points to new BOOTNFO
|
---|
27 | call BootInfo_StoreSectorCount
|
---|
28 | jmp SHORT BootInfo_StoreDriveName
|
---|
29 |
|
---|
30 |
|
---|
31 | ;--------------------------------------------------------------------
|
---|
32 | ; Returns offset to BOOTNFO for wanted drive.
|
---|
33 | ;
|
---|
34 | ; BootInfo_GetOffsetToBX
|
---|
35 | ; Parameters:
|
---|
36 | ; DL: Drive number
|
---|
37 | ; DS: RAMVARS segment
|
---|
38 | ; Returns:
|
---|
39 | ; BX: Offset to BOOTNFO struct
|
---|
40 | ; Corrupts registers:
|
---|
41 | ; AX
|
---|
42 | ;--------------------------------------------------------------------
|
---|
43 | ALIGN JUMP_ALIGN
|
---|
44 | BootInfo_GetOffsetToBX:
|
---|
45 | mov bl, dl ; Copy drive number to BL
|
---|
46 | mov al, BOOTNFO_size ; Size of struct
|
---|
47 | sub bl, [RAMVARS.bFirstDrv] ; Drive number to index
|
---|
48 | mul bl ; AX = Offset inside BOOTNFO array
|
---|
49 | add ax, BOOTVARS.rgBootNfo ; Add offset to BOOTNFO array
|
---|
50 | xchg bx, ax ; Copy result to BX
|
---|
51 | ret
|
---|
52 |
|
---|
53 |
|
---|
54 | ;--------------------------------------------------------------------
|
---|
55 | ; Stores total sector count to BOOTNFO.
|
---|
56 | ;
|
---|
57 | ; BootInfo_StoreSectorCount
|
---|
58 | ; Parameters:
|
---|
59 | ; ES:BX: Ptr to BOOTNFO
|
---|
60 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
61 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
62 | ; Returns:
|
---|
63 | ; CF: Cleared if variables stored succesfully
|
---|
64 | ; Set if any error
|
---|
65 | ; Corrupts registers:
|
---|
66 | ; AX, CX, DX
|
---|
67 | ;--------------------------------------------------------------------
|
---|
68 | ALIGN JUMP_ALIGN
|
---|
69 | BootInfo_StoreSectorCount:
|
---|
70 | push bx
|
---|
71 | call AtaID_GetTotalSectorCount ; Get to BX:DX:AX
|
---|
72 | mov cx, bx ; Now in CX:DX:AX
|
---|
73 | pop bx
|
---|
74 | mov [es:bx+BOOTNFO.twSectCnt], ax
|
---|
75 | mov [es:bx+BOOTNFO.twSectCnt+2], dx
|
---|
76 | mov [es:bx+BOOTNFO.twSectCnt+4], cx
|
---|
77 | clc
|
---|
78 | ret
|
---|
79 |
|
---|
80 |
|
---|
81 | ;--------------------------------------------------------------------
|
---|
82 | ; Stores drive name to BOOTNFO.
|
---|
83 | ;
|
---|
84 | ; BootInfo_StoreDriveName
|
---|
85 | ; Parameters:
|
---|
86 | ; ES:BX: Ptr to BOOTNFO
|
---|
87 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
88 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
89 | ; Returns:
|
---|
90 | ; CF: Cleared if variables stored succesfully
|
---|
91 | ; Set if any error
|
---|
92 | ; Corrupts registers:
|
---|
93 | ; AX, CX
|
---|
94 | ;--------------------------------------------------------------------
|
---|
95 | ALIGN JUMP_ALIGN
|
---|
96 | BootInfo_StoreDriveName:
|
---|
97 | push ds
|
---|
98 | push si
|
---|
99 | push di
|
---|
100 |
|
---|
101 | ; DS:SI to ATA source string
|
---|
102 | push es
|
---|
103 | pop ds
|
---|
104 | add si, BYTE ATA1.strModel
|
---|
105 |
|
---|
106 | ; ES:DI to BOOTNFO destination string
|
---|
107 | lea di, [bx+BOOTNFO.szDrvName]
|
---|
108 |
|
---|
109 | ; Read string
|
---|
110 | mov cx, LEN_BOOTNFO_DRV>>1
|
---|
111 | call BootInfo_StoreAtaString
|
---|
112 | pop di
|
---|
113 | pop si
|
---|
114 | pop ds
|
---|
115 | clc
|
---|
116 | ret
|
---|
117 |
|
---|
118 | ;--------------------------------------------------------------------
|
---|
119 | ; Stores ATA string.
|
---|
120 | ; Byte ordering will be corrected and string will be STOP terminated.
|
---|
121 | ;
|
---|
122 | ; BootInfo_StoreAtaString
|
---|
123 | ; Parameters:
|
---|
124 | ; CX: Maximum number of WORDs to copy (without STOP)
|
---|
125 | ; DS:SI: Ptr to ATA string
|
---|
126 | ; ES:DI: Ptr to destination string
|
---|
127 | ; Returns:
|
---|
128 | ; Nothing
|
---|
129 | ; Corrupts registers:
|
---|
130 | ; AX, CX, SI, DI
|
---|
131 | ;--------------------------------------------------------------------
|
---|
132 | ALIGN JUMP_ALIGN
|
---|
133 | BootInfo_StoreAtaString:
|
---|
134 | lodsw ; Load WORD from DS:SI to AX
|
---|
135 | xchg al, ah ; Change byte order
|
---|
136 | call BootInfo_StoreAtaChar
|
---|
137 | jc SHORT .Return ; Return if invalid character
|
---|
138 | mov al, ah ; Write next char
|
---|
139 | call BootInfo_StoreAtaChar
|
---|
140 | jc SHORT .Return ; Return if invalid character
|
---|
141 | loop BootInfo_StoreAtaString ; Loop while words left
|
---|
142 | .Return:
|
---|
143 | xor ax, ax ; Terminate string with NULL
|
---|
144 | stosb
|
---|
145 | ret
|
---|
146 |
|
---|
147 | ;--------------------------------------------------------------------
|
---|
148 | ; Stores ATA character.
|
---|
149 | ;
|
---|
150 | ; BootInfo_StoreAtaChar
|
---|
151 | ; Parameters:
|
---|
152 | ; AL: Character to store
|
---|
153 | ; ES:DI: Ptr to destination character
|
---|
154 | ; Returns:
|
---|
155 | ; DI: Incremented to next character
|
---|
156 | ; CF: Set if non writable ASCII character
|
---|
157 | ; Corrupts registers:
|
---|
158 | ; Nothing
|
---|
159 | ;--------------------------------------------------------------------
|
---|
160 | ALIGN JUMP_ALIGN
|
---|
161 | BootInfo_StoreAtaChar:
|
---|
162 | cmp al, 20h ; First allowed ASCII char?
|
---|
163 | jb SHORT .SkipStoring ; If below, end string
|
---|
164 | cmp al, 7Eh ; Last allowed ASCII char?
|
---|
165 | ja SHORT .SkipStoring ; If above, end string
|
---|
166 | stosb ; Store character
|
---|
167 | clc ; Clear CF to continue with next char
|
---|
168 | ret
|
---|
169 | .SkipStoring:
|
---|
170 | stc
|
---|
171 | ret
|
---|
172 |
|
---|
173 |
|
---|
174 | ;--------------------------------------------------------------------
|
---|
175 | ; Finds BOOTNFO for drive and return total sector count.
|
---|
176 | ;
|
---|
177 | ; BootInfo_GetTotalSectorCount
|
---|
178 | ; Parameters:
|
---|
179 | ; DL: Drive number
|
---|
180 | ; DS: RAMVARS segment
|
---|
181 | ; Returns:
|
---|
182 | ; BX:DX:AX: 48-bit sector count
|
---|
183 | ; Corrupts registers:
|
---|
184 | ; Nothing
|
---|
185 | ;--------------------------------------------------------------------
|
---|
186 | ALIGN JUMP_ALIGN
|
---|
187 | BootInfo_GetTotalSectorCount:
|
---|
188 | push ds
|
---|
189 | call BootInfo_GetOffsetToBX
|
---|
190 | LOAD_BDA_SEGMENT_TO ds, ax
|
---|
191 | mov ax, [bx+BOOTNFO.twSectCnt]
|
---|
192 | mov dx, [bx+BOOTNFO.twSectCnt+2]
|
---|
193 | mov bx, [bx+BOOTNFO.twSectCnt+4]
|
---|
194 | pop ds
|
---|
195 | ret
|
---|