1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : Functions for generating and accessing drive
|
---|
3 | ; information to be displayed on boot menu.
|
---|
4 |
|
---|
5 | ; Section containing code
|
---|
6 | SECTION .text
|
---|
7 |
|
---|
8 | ;--------------------------------------------------------------------
|
---|
9 | ; Creates new BOOTNFO struct for detected hard disk.
|
---|
10 | ;
|
---|
11 | ; BootInfo_CreateForHardDisk
|
---|
12 | ; Parameters:
|
---|
13 | ; DL: Drive number
|
---|
14 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
15 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
16 | ; Returns:
|
---|
17 | ; ES:BX: Ptr to BOOTNFO (if successful)
|
---|
18 | ; CF: Cleared if BOOTNFO created succesfully
|
---|
19 | ; Set if any error
|
---|
20 | ; Corrupts registers:
|
---|
21 | ; AX, BX, CX, DX
|
---|
22 | ;--------------------------------------------------------------------
|
---|
23 | BootInfo_CreateForHardDisk:
|
---|
24 | call BootInfo_GetOffsetToBX ; ES:BX now points to new BOOTNFO
|
---|
25 | ; Fall to .StoreSectorCount
|
---|
26 |
|
---|
27 | ;--------------------------------------------------------------------
|
---|
28 | ; .StoreSectorCount
|
---|
29 | ; Parameters:
|
---|
30 | ; ES:BX: Ptr to BOOTNFO
|
---|
31 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
32 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
33 | ; Returns:
|
---|
34 | ; Nothing
|
---|
35 | ; Corrupts registers:
|
---|
36 | ; AX, CX, DX
|
---|
37 | ;--------------------------------------------------------------------
|
---|
38 | .StoreSectorCount:
|
---|
39 | push bx
|
---|
40 | call AtaID_GetTotalSectorCount ; Get to BX:DX:AX
|
---|
41 | mov cx, bx ; Now in CX:DX:AX
|
---|
42 | pop bx
|
---|
43 | mov [es:bx+BOOTNFO.twSectCnt], ax
|
---|
44 | mov [es:bx+BOOTNFO.twSectCnt+2], dx
|
---|
45 | mov [es:bx+BOOTNFO.twSectCnt+4], cx
|
---|
46 | ; Fall to .StoreDriveName
|
---|
47 |
|
---|
48 | ;--------------------------------------------------------------------
|
---|
49 | ; .StoreDriveName
|
---|
50 | ; Parameters:
|
---|
51 | ; ES:BX: Ptr to BOOTNFO
|
---|
52 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
53 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
54 | ; Returns:
|
---|
55 | ; CF: Cleared if variables stored succesfully
|
---|
56 | ; Set if any error
|
---|
57 | ; Corrupts registers:
|
---|
58 | ; AX, CX
|
---|
59 | ;--------------------------------------------------------------------
|
---|
60 | .StoreDriveName:
|
---|
61 | push ds
|
---|
62 | push si
|
---|
63 | push di
|
---|
64 |
|
---|
65 | push es
|
---|
66 | pop ds
|
---|
67 | add si, BYTE ATA1.strModel ; DS:SI now points drive name
|
---|
68 | lea di, [bx+BOOTNFO.szDrvName] ; ES:DI now points to name destination
|
---|
69 | mov cx, LEN_BOOTNFO_DRV / 2 ; Max number of WORDs allowed
|
---|
70 | .CopyNextWord:
|
---|
71 | lodsw
|
---|
72 | xchg al, ah ; Change endianness
|
---|
73 | stosw
|
---|
74 | loop .CopyNextWord
|
---|
75 | xor ax, ax
|
---|
76 | stosb ; Terminate with NULL
|
---|
77 |
|
---|
78 | pop di
|
---|
79 | pop si
|
---|
80 | pop ds
|
---|
81 | clc
|
---|
82 | ret
|
---|
83 |
|
---|
84 |
|
---|
85 | ;--------------------------------------------------------------------
|
---|
86 | ; Finds BOOTNFO for drive and returns total sector count.
|
---|
87 | ;
|
---|
88 | ; BootInfo_GetTotalSectorCount
|
---|
89 | ; Parameters:
|
---|
90 | ; DL: Drive number
|
---|
91 | ; DS: RAMVARS segment
|
---|
92 | ; Returns:
|
---|
93 | ; BX:DX:AX: 48-bit sector count
|
---|
94 | ; Corrupts registers:
|
---|
95 | ; Nothing
|
---|
96 | ;--------------------------------------------------------------------
|
---|
97 | ALIGN JUMP_ALIGN
|
---|
98 | BootInfo_GetTotalSectorCount:
|
---|
99 | push ds
|
---|
100 | call BootInfo_GetOffsetToBX
|
---|
101 | LOAD_BDA_SEGMENT_TO ds, ax
|
---|
102 | mov ax, [bx+BOOTNFO.twSectCnt]
|
---|
103 | mov dx, [bx+BOOTNFO.twSectCnt+2]
|
---|
104 | mov bx, [bx+BOOTNFO.twSectCnt+4]
|
---|
105 | pop ds
|
---|
106 | ret
|
---|
107 |
|
---|
108 |
|
---|
109 | ;--------------------------------------------------------------------
|
---|
110 | ; Returns offset to BOOTNFO for wanted drive.
|
---|
111 | ;
|
---|
112 | ; BootInfo_GetOffsetToBX
|
---|
113 | ; Parameters:
|
---|
114 | ; DL: Drive number
|
---|
115 | ; DS: RAMVARS segment
|
---|
116 | ; Returns:
|
---|
117 | ; BX: Offset to BOOTNFO struct
|
---|
118 | ; Corrupts registers:
|
---|
119 | ; AX
|
---|
120 | ;--------------------------------------------------------------------
|
---|
121 | ALIGN JUMP_ALIGN
|
---|
122 | BootInfo_GetOffsetToBX:
|
---|
123 | mov bl, dl ; Copy drive number to BL
|
---|
124 | mov al, BOOTNFO_size ; Size of struct
|
---|
125 | sub bl, [RAMVARS.bFirstDrv] ; Drive number to index
|
---|
126 | mul bl ; AX = Offset inside BOOTNFO array
|
---|
127 | add ax, BOOTVARS.rgBootNfo ; Add offset to BOOTNFO array
|
---|
128 | xchg bx, ax ; Copy result to BX
|
---|
129 | ret
|
---|