| 1 |
|
|---|
| 2 | ; Disclaimer:
|
|---|
| 3 | ;=============
|
|---|
| 4 | ; The sourcecode is released via www.netlabs.org CVS *ONLY*.
|
|---|
| 5 | ; You MUST NOT upload it to other servers nor republish it in any way.
|
|---|
| 6 | ; The sourcecode is still COPYRIGHTED and NOT RELEASED UNDER GPL.
|
|---|
| 7 | ; It's (c) Copyright 1998-2003 by Martin Kiewitz.
|
|---|
| 8 | ; You may recompile the source and do *PRIVATE* modifications, but please keep
|
|---|
| 9 | ; in mind that modifying this code needs at least *some* assembly skill. If
|
|---|
| 10 | ; you mess up your system, because you needed to hack your way through, don't
|
|---|
| 11 | ; blame me. Releasing a customized version of AiR-BOOT, selling it in any form
|
|---|
| 12 | ; or reusing parts of this source is *PROHIBITED*. Ask me, if you have some
|
|---|
| 13 | ; idea about new functionality *before* developing the code, otherwise I will
|
|---|
| 14 | ; definitely reject it. Also please accept, that I have some basic design
|
|---|
| 15 | ; rules on AiR-BOOT and I will maintain them at all costs, so this won't get
|
|---|
| 16 | ; another GRUB.
|
|---|
| 17 |
|
|---|
| 18 | ;---------------------------------------------------------------------------
|
|---|
| 19 | ; AiR-BOOT / FAT-16 SUPPORT
|
|---|
| 20 | ;---------------------------------------------------------------------------
|
|---|
| 21 |
|
|---|
| 22 | ; Here is access code for accessing FAT-16 partitions. It's not a complete
|
|---|
| 23 | ; File-API and only for simple readonly-access.
|
|---|
| 24 | ; It's currently only used by SPECIAL\LINUX.ASM for Linux Kernel Loading.
|
|---|
| 25 | ;
|
|---|
| 26 | ; Note: This code will ONLY WORK on computers with INT 13h Extension.
|
|---|
| 27 | ; I did not want to code silly cylinder stuff here. I have also used
|
|---|
| 28 | ; i386 code in here, because Linux requires so as well. Please note that
|
|---|
| 29 | ; I don't use i386 code anywhere (!) else in AiR-BOOT.
|
|---|
| 30 | ;
|
|---|
| 31 | ; Initialize FAT-16 access on specified partition (required for following xs)
|
|---|
| 32 | ; In: DS:SI - IPT-Entry that contains a FAT-16 partition
|
|---|
| 33 | ; Out: None
|
|---|
| 34 | ; Destroyed: None
|
|---|
| 35 | FAT16_InitAccess Proc Near Uses eax bx edx
|
|---|
| 36 | mov al, bptr ds:[si+LocIPT_Drive]
|
|---|
| 37 | mov FAT16_Drive, al
|
|---|
| 38 | mov edx, dptr ds:[si+LocIPT_AbsoluteBegin]
|
|---|
| 39 | mov FAT16_AbsPartitionBegin, edx
|
|---|
| 40 | mov DriveIO_DAP_Absolute, edx ; Read in Boot-Record of partition
|
|---|
| 41 | mov DriveIO_DAP_NumBlocks, 1 ; 1 Sector to load
|
|---|
| 42 | mov FAT16_FATCacheSector, 255 ; Sector 255 - So nothing cached
|
|---|
| 43 | mov ax, ds
|
|---|
| 44 | shl eax, 16
|
|---|
| 45 | mov ax, offset FAT16_FATCache
|
|---|
| 46 | mov DriveIO_DAP_Transfer, eax ; Transfer to FAT-Cache Area
|
|---|
| 47 | call FAT16_LoadSectors
|
|---|
| 48 | mov al, bptr [FAT16_FATCache+13]
|
|---|
| 49 | mov FAT16_SecsPerCluster, al
|
|---|
| 50 | movzx eax, wptr [FAT16_FATCache+14] ; +14 -> ReservedSectors
|
|---|
| 51 | add edx, eax ; EDX = AbsPartitionPos+ReservedSectors
|
|---|
| 52 | mov FAT16_AbsFATBegin, edx ; Is Absolute-FAT-Begin
|
|---|
| 53 | movzx ax, bptr [FAT16_FATCache+16] ; +16 -> FAT-Copies Count
|
|---|
| 54 | mov bx, wptr [FAT16_FATCache+22] ; +22 -> Sectors Per FAT
|
|---|
| 55 | mov FAT16_SecsPerFAT, bx
|
|---|
| 56 | push dx
|
|---|
| 57 | mul bx
|
|---|
| 58 | pop dx
|
|---|
| 59 | movzx eax, ax
|
|---|
| 60 | add edx, eax
|
|---|
| 61 | mov FAT16_AbsRootBegin, edx ; Is Absolute-Root-Begin
|
|---|
| 62 | movzx eax, wptr [FAT16_FATCache+17] ; +17 -> Number of Root Entries
|
|---|
| 63 | mov FAT16_NumOfRootEntries, ax
|
|---|
| 64 | shr eax, 4 ; NumOfRootEntries/16
|
|---|
| 65 | add edx, eax
|
|---|
| 66 | mov FAT16_AbsClusterBegin, edx ; Is Absolute-Cluster-Begin
|
|---|
| 67 | ret
|
|---|
| 68 | FAT16_InitAccess EndP
|
|---|
| 69 |
|
|---|
| 70 | ; Reads Root-Entries to 9000:0 for further processing...
|
|---|
| 71 | ; In: None
|
|---|
| 72 | ; Out: None
|
|---|
| 73 | ; Destroyed: None
|
|---|
| 74 | FAT16_ReadRoot Proc Near Uses eax
|
|---|
| 75 | mov ax, 9000h
|
|---|
| 76 | shl eax, 16 ; 9000:0 -> Space for Root
|
|---|
| 77 | mov DriveIO_DAP_Transfer, eax ; Transfer to that segment
|
|---|
| 78 | mov eax, FAT16_AbsRootBegin
|
|---|
| 79 | mov DriveIO_DAP_Absolute, eax ; Read in Root-Entries...
|
|---|
| 80 | mov ax, FAT16_NumOfRootEntries
|
|---|
| 81 | shr ax, 4 ; NumOfRootEntries/16
|
|---|
| 82 | mov DriveIO_DAP_NumBlocks, ax ; -> Sectors of Root-Entries
|
|---|
| 83 | call FAT16_LoadSectors ; DONE.
|
|---|
| 84 | ret
|
|---|
| 85 | FAT16_ReadRoot EndP
|
|---|
| 86 |
|
|---|
| 87 | ; Searches a FAT16-File-Entry in specified memory block
|
|---|
| 88 | ; In: CX - Total Count of File-Entries to search
|
|---|
| 89 | ; SI - Offset, what to search for Segment CS (11-Byte block)
|
|---|
| 90 | ; Out: DX - Cluster, where the data starts...
|
|---|
| 91 | ; Destroyed: None
|
|---|
| 92 | FAT16_SearchEntry Proc Near Uses ax bx es di
|
|---|
| 93 | xor dx, dx ; No Result as default
|
|---|
| 94 | or cx, cx
|
|---|
| 95 | jz FAT16SE_NoEntries
|
|---|
| 96 | mov bx, cx
|
|---|
| 97 | mov ax, 9000h
|
|---|
| 98 | mov es, ax
|
|---|
| 99 | xor di, di
|
|---|
| 100 | FAT16SE_SearchLoop:
|
|---|
| 101 | push si di
|
|---|
| 102 | mov cx, 11
|
|---|
| 103 | repe cmpsb ; Compare total 11-bytes
|
|---|
| 104 | pop di si
|
|---|
| 105 | je FAT16SE_EntryFound
|
|---|
| 106 | add di, 32 ; Skip 1 FAT16-Entry now :)
|
|---|
| 107 | dec bx
|
|---|
| 108 | jnz FAT16SE_SearchLoop
|
|---|
| 109 | FAT16SE_NoEntries:
|
|---|
| 110 | ret
|
|---|
| 111 |
|
|---|
| 112 | FAT16SE_EntryFound:
|
|---|
| 113 | mov dx, wptr es:[di+26] ; Starting Cluster of Entry
|
|---|
| 114 | ret
|
|---|
| 115 | FAT16_SearchEntry EndP
|
|---|
| 116 |
|
|---|
| 117 | ; Reads a Cluster and gets Next-Cluster as well...
|
|---|
| 118 | ; In: DX - Cluster-Number to load, DAP_Transfer-Offset filled out
|
|---|
| 119 | ; ES - Segment, where to read Cluster to
|
|---|
| 120 | ; DI - Offset, where to read Cluster to
|
|---|
| 121 | ; Out: DX - Cluster that follows this one, [ES:DI] filled out
|
|---|
| 122 | ; DI - Offset, adjusted
|
|---|
| 123 | ; Destroyed: None
|
|---|
| 124 | FAT16_ReadCluster Proc Near Uses eax bx
|
|---|
| 125 | push dx
|
|---|
| 126 | ; First read Cluster into buffer...
|
|---|
| 127 | mov ax, es
|
|---|
| 128 | shl eax, 16
|
|---|
| 129 | mov ax, di
|
|---|
| 130 | mov DriveIO_DAP_Transfer, eax ; Read to 9000:DI
|
|---|
| 131 | mov ax, dx
|
|---|
| 132 | sub ax, 2 ; Everything starts at Cluster 2
|
|---|
| 133 | movzx bx, FAT16_SecsPerCluster
|
|---|
| 134 | mul bx
|
|---|
| 135 | shl edx, 16
|
|---|
| 136 | mov dx, ax ; EDX - Relative to Cluster-Start
|
|---|
| 137 | add edx, FAT16_AbsClusterBegin ; EDX - Absolute Sector Count
|
|---|
| 138 | mov DriveIO_DAP_Absolute, edx
|
|---|
| 139 | mov DriveIO_DAP_NumBlocks, bx ; Get a whole cluster
|
|---|
| 140 | call FAT16_LoadSectors ; DONE.
|
|---|
| 141 | pop dx
|
|---|
| 142 | ; Update DI to next position...
|
|---|
| 143 | mov al, FAT16_SecsPerCluster
|
|---|
| 144 | shl ax, 9
|
|---|
| 145 | add di, ax
|
|---|
| 146 | ; Finally, look for next Cluster following to this one...
|
|---|
| 147 | movzx bx, dl
|
|---|
| 148 | shl bx, 1 ; BX - Offset within FAT-Table
|
|---|
| 149 | shr dx, 8 ; DX - FAT-Sector
|
|---|
| 150 | cmp dl, FAT16_FATCacheSector
|
|---|
| 151 | je FAT16RC_GotFATsectorAlready
|
|---|
| 152 | ; Load FAT-Sector, because the required one is not in Cache
|
|---|
| 153 | mov FAT16_FATCacheSector, dl
|
|---|
| 154 | mov ax, cs
|
|---|
| 155 | shl eax, 16
|
|---|
| 156 | mov ax, offset FAT16_FATCache
|
|---|
| 157 | mov DriveIO_DAP_Transfer, eax ; Transfer to FAT-Cache Area
|
|---|
| 158 | movzx edx, dx
|
|---|
| 159 | mov eax, FAT16_AbsFATBegin
|
|---|
| 160 | add eax, edx
|
|---|
| 161 | mov DriveIO_DAP_Absolute, eax ; Read in Boot-Record of partition
|
|---|
| 162 | mov DriveIO_DAP_NumBlocks, 1 ; 1 Sector to load
|
|---|
| 163 | call FAT16_LoadSectors ; DONE.
|
|---|
| 164 | FAT16RC_GotFATsectorAlready:
|
|---|
| 165 | mov dx, wptr cs:[FAT16_FATCache+bx] ; Get Next-Cluster Pointer
|
|---|
| 166 | ret
|
|---|
| 167 | FAT16_ReadCluster EndP
|
|---|
| 168 |
|
|---|
| 169 | ; Preserves all registers, help routine for LoadKernel
|
|---|
| 170 | ; supports more than 1 sector read (unlike MBR_IO_LoadSector)
|
|---|
| 171 | FAT16_LoadSectors Proc Near Uses eax dx ds si
|
|---|
| 172 | push cs
|
|---|
| 173 | pop ds
|
|---|
| 174 | mov si, offset DriveIO_DAP
|
|---|
| 175 | mov dl, ds:[FAT16_Drive]
|
|---|
| 176 | mov ah, 42h ; Extended Read
|
|---|
| 177 | int 13h
|
|---|
| 178 | jnc FAT16LS_Success
|
|---|
| 179 | call MBR_LoadError
|
|---|
| 180 |
|
|---|
| 181 | FAT16LS_Success:
|
|---|
| 182 | movzx eax, wptr ds:[DriveIO_DAP_NumBlocks]
|
|---|
| 183 | add dptr ds:[DriveIO_DAP_Absolute+0], eax ; Adjust Absolute Offset
|
|---|
| 184 | ret
|
|---|
| 185 | FAT16_LoadSectors EndP
|
|---|
| 186 |
|
|---|
| 187 | ; Will Pre-Process Directory loaded to 9000:0, remove directory and VFAT
|
|---|
| 188 | ; entries for display purpose in window
|
|---|
| 189 | ; In: DI - Ending-Offset of Directory
|
|---|
| 190 | ; ES == CS
|
|---|
| 191 | ; Out: None
|
|---|
| 192 | ; Destroyed: None
|
|---|
| 193 | FAT16_ProcessKrnlDirectory Proc Near Uses ds si es di
|
|---|
| 194 | mov dx, di ; DX - Ending-Offset of Directory
|
|---|
| 195 | mov ax, 9000h
|
|---|
| 196 | mov ds, ax ; DS == 9000h
|
|---|
| 197 | xor si, si ; SI - Current Pos in Directory
|
|---|
| 198 | mov di, offset LINUX_KernelEntries ; DI - Array of Kernel-Entries
|
|---|
| 199 | mov cs:[LINUX_KernelNo], 0
|
|---|
| 200 | FAT16PPD_DirectoryLoop:
|
|---|
| 201 | mov al, ds:[si] ; +0 -> First char of Basename
|
|---|
| 202 | or al, al
|
|---|
| 203 | jz FAT16PPD_IgnoreEntry ; == 0, empty
|
|---|
| 204 | cmp al, 0E5h
|
|---|
| 205 | je FAT16PPD_IgnoreEntry ; == E5, deleted
|
|---|
| 206 | mov al, ds:[si+11] ; +11 -> Flags of Entry
|
|---|
| 207 | cmp al, 0Fh ; 0F as flags -> VFAT Entry
|
|---|
| 208 | je FAT16PPD_IgnoreEntry
|
|---|
| 209 | test al, 18h ; Bit 4 -> Directory
|
|---|
| 210 | jnz FAT16PPD_IgnoreEntry ; Bit 3 -> Volume
|
|---|
| 211 |
|
|---|
| 212 | ; Set Size-Entry in KernelSizeTable
|
|---|
| 213 | push ds si di
|
|---|
| 214 | mov bx, ds:[si+30]
|
|---|
| 215 | mov ax, ds:[si+28] ; BX:AX - Size of file in Bytes
|
|---|
| 216 |
|
|---|
| 217 | mov dx, bx
|
|---|
| 218 | and dx, 511 ; My crazy way of dividing a 32-bit
|
|---|
| 219 | shr ax, 9 ; value through 512 using 16-bit
|
|---|
| 220 | shr bx, 9 ; instructions... :)
|
|---|
| 221 | shl dx, 7 ; (dont ever ever use a DIV)
|
|---|
| 222 | or ax, dx ; BX:AX - Size of file in 512-blocks
|
|---|
| 223 |
|
|---|
| 224 | push cs
|
|---|
| 225 | pop ds ; DS==CS for GetSizeElementPtr
|
|---|
| 226 | push ax
|
|---|
| 227 | mov ax, di
|
|---|
| 228 | call PART_GetSizeElementPointer ; SI - Pointer to Size Element
|
|---|
| 229 | pop ax
|
|---|
| 230 | mov di, si
|
|---|
| 231 | call PART_FillOutSizeElement ; BX:AX -> ES:DI (Size Element)
|
|---|
| 232 | pop di si ds
|
|---|
| 233 |
|
|---|
| 234 | ; Copy entry and make append extension to basename
|
|---|
| 235 | ; "TEST TMP" -> "TESTTMP "
|
|---|
| 236 | mov bx, 7
|
|---|
| 237 | FAT16PPD_GetLenOfBasename:
|
|---|
| 238 | cmp bptr ds:[si+bx], ' '
|
|---|
| 239 | jne FAT16PPD_EndOfBasename
|
|---|
| 240 | dec bx
|
|---|
| 241 | jnz FAT16PPD_GetLenOfBasename
|
|---|
| 242 | FAT16PPD_EndOfBasename:
|
|---|
| 243 | mov ah, bl
|
|---|
| 244 | inc ah ; AH - Count of Basename Chars (max 8)
|
|---|
| 245 | mov bx, 10
|
|---|
| 246 | FAT16PPD_GetLenOfExtension:
|
|---|
| 247 | cmp bptr ds:[si+bx], ' '
|
|---|
| 248 | jne FAT16PPD_EndOfExtension
|
|---|
| 249 | dec bl
|
|---|
| 250 | cmp bl, 7
|
|---|
| 251 | ja FAT16PPD_GetLenOfExtension
|
|---|
| 252 | FAT16PPD_EndOfExtension:
|
|---|
| 253 | sub bl, 7 ; BL - Count of Extension Chars (max 3)
|
|---|
| 254 | ; Now we will copy&fill out 11 characters (Basename&Extension)
|
|---|
| 255 | push dx
|
|---|
| 256 | push ax
|
|---|
| 257 | xor eax, eax
|
|---|
| 258 | stosd ; +0 [DWORD] Empty Serial
|
|---|
| 259 | pop ax
|
|---|
| 260 | mov dx, si
|
|---|
| 261 | movzx cx, ah
|
|---|
| 262 | rep movsb
|
|---|
| 263 | mov si, dx ; Restore SI
|
|---|
| 264 | add si, 8
|
|---|
| 265 | or bl, bl
|
|---|
| 266 | jz FAT16PPD_NoExtensionCopy
|
|---|
| 267 | mov cl, bl
|
|---|
| 268 | rep movsb
|
|---|
| 269 | FAT16PPD_NoExtensionCopy:
|
|---|
| 270 | add ah, bl ; AH - Total Bytes of BaseName
|
|---|
| 271 | mov cl, 11
|
|---|
| 272 | mov al, ' '
|
|---|
| 273 | sub cl, ah
|
|---|
| 274 | jz FAT16PPD_NoFillUpName
|
|---|
| 275 | rep stosb ; +4 [STR*11] Label
|
|---|
| 276 | FAT16PPD_NoFillUpName:
|
|---|
| 277 | mov si, dx ; Restore SI
|
|---|
| 278 |
|
|---|
| 279 | mov al, FAT16_Drive
|
|---|
| 280 | mov ah, 0FDh
|
|---|
| 281 | stosw ; +15 [BYTE/BYTE] Drive, SystemID
|
|---|
| 282 | xor ax, ax
|
|---|
| 283 | stosb ; +17 [BYTE] Flags
|
|---|
| 284 | stosw ; +18 [WORD] CRC
|
|---|
| 285 | mov ax, wptr ds:[si+26] ; Starting Cluster of File
|
|---|
| 286 | stosw
|
|---|
| 287 | xor ax, ax
|
|---|
| 288 | stosb ; +20 [BYTE/BYTE/BYTE] Location Begin
|
|---|
| 289 | stosw
|
|---|
| 290 | stosb ; +23 [BYTE/BYTE/BYTE] Location Part
|
|---|
| 291 | mov cx, 4
|
|---|
| 292 | rep stosw ; +26 [DWORD/DWORD] Abs Locations
|
|---|
| 293 | pop dx
|
|---|
| 294 | inc cs:[LINUX_KernelNo]
|
|---|
| 295 | FAT16PPD_IgnoreEntry:
|
|---|
| 296 | add si, 32
|
|---|
| 297 | cmp si, dx ; We are at Ending-Offset ?
|
|---|
| 298 | jb FAT16PPD_DirectoryLoop
|
|---|
| 299 | ; Done, now we got a maximum of 20 kernels in LINUX_KernelEntries-Array.
|
|---|
| 300 | ret
|
|---|
| 301 | FAT16_ProcessKrnlDirectory EndP
|
|---|