source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Boot/BootInfo.asm @ 3

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