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