wok diff BootProg/stuff/boot32.asm @ rev 25458
Update some web_site
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Sep 27 16:21:52 2022 +0000 (21 months ago) |
parents | ad0bc3efbf37 |
children | 7dd01dedad38 |
line diff
1.1 --- a/BootProg/stuff/boot32.asm Fri Sep 23 08:28:09 2022 +0000 1.2 +++ b/BootProg/stuff/boot32.asm Tue Sep 27 16:21:52 2022 +0000 1.3 @@ -80,11 +80,14 @@ 1.4 %define bx(label) bx+label-boot 1.5 %define si(label) si+label-boot 1.6 ClusterMask equ 1 ; +9 bytes 1.7 -NullEntryCheck equ 1 ; +5 bytes 1.8 +NullEntryCheck equ 0 ; +5 bytes 1.9 ReadRetry equ 1 ; +7 bytes 1.10 -LBA48bits equ 1 ; +13 bytes 1.11 +LBA48bits equ 1 ; +15 bytes 1.12 CHSsupport equ 1 ; +27 bytes 1.13 -CHShardDisk equ 0 ; +11 bytes 1.14 +CHSupTo8GB equ 1 ; +11 bytes 1.15 +CHSupTo32MB equ 1 ; +7 bytes 1.16 +SectorOf512Bytes equ 1 ; -5 bytes 1.17 +Always2FATs equ 0 ; -4 bytes 1.18 1.19 [BITS 16] 1.20 1.21 @@ -99,6 +102,8 @@ 1.22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.23 1.24 boot: 1.25 +DriveNumber equ boot+0 1.26 +HiLBA equ boot+2 1.27 jmp short start ; MS-DOS/Windows checks for this jump 1.28 nop 1.29 bsOemName DB "BootProg" ; 0x03 1.30 @@ -136,17 +141,11 @@ 1.31 bsBackupBootSectorNo DW 0 ; 0x32 1.32 bsreserved times 12 DB 0 ; 0x34 1.33 bsDriveNumber DB 0 ; 0x40 1.34 -%if LBA48bits != 0 1.35 -HiLBA equ boot+0 1.36 -DriveNumber equ bsDriveNumber+0 1.37 -%else 1.38 -DriveNumber equ boot+0 1.39 -%endif 1.40 bsreserved1 DB 0 ; 0x41 1.41 bsExtendedBootSignature DB 0 ; 0x42 1.42 bsVolumeSerialNumber DD 0 ; 0x43 1.43 -bsVolumeLabel DB "NO NAME " ; 0x47 1.44 -bsFileSystemName DB "FAT32 " ; 0x52 1.45 +bsVolumeLabel times 11 DB " " ; 0x47 "NO NAME " 1.46 +bsFileSystemName times 8 DB " " ; 0x52 "FAT32 " 1.47 1.48 ;;;;;;;;;;;;;;;;;;;; 1.49 ;; BPB2 ends here ;; 1.50 @@ -210,8 +209,7 @@ 1.51 pop es 1.52 1.53 RootDirReadContinue: 1.54 - call ReadCluster ; read one cluster of root dir 1.55 - pushf ; save carry="not last cluster" flag 1.56 + call ReadClusterSector ; read one sector of the root dir 1.57 1.58 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.59 ;; Look for the COM/EXE file to load and run ;; 1.60 @@ -243,8 +241,9 @@ 1.61 dec bp 1.62 dec bp 1.63 jnz FindNameCycle ; next root entry 1.64 - popf ; restore carry="not last cluster" flag 1.65 - jc RootDirReadContinue ; continue to the next root dir cluster 1.66 + loop RootDirReadContinue ; next sector in cluster 1.67 + cmp esi, 0FFFFFF6h ; carry=0 if last cluster, and carry=1 otherwise 1.68 + jnc RootDirReadContinue ; continue to the next root dir cluster 1.69 ErrFind: 1.70 call Error ; end of root directory (dir end reached) 1.71 db "File not found." 1.72 @@ -263,7 +262,8 @@ 1.73 push es 1.74 FileReadContinue: 1.75 push di 1.76 - call ReadCluster ; read one cluster of root dir 1.77 + call ReadClusterSector ; read one sector of the boot file 1.78 + dec cx 1.79 mov di, es 1.80 add di, bp 1.81 mov es, di ; es:bx updated 1.82 @@ -350,56 +350,97 @@ 1.83 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.84 retf 1.85 1.86 -ReadCluster: 1.87 +;;;;;;;;;;;;;;;;;;;;;;;;;; 1.88 +;; Error Messaging Code ;; 1.89 +;;;;;;;;;;;;;;;;;;;;;;;;;; 1.90 + 1.91 +Error: 1.92 + pop si 1.93 +puts: 1.94 + mov ah, 0Eh 1.95 + mov bl, 7 1.96 + lodsb 1.97 + int 10h 1.98 + cmp al, '.' 1.99 + jne puts 1.100 + cbw 1.101 + int 16h ; wait for a key... 1.102 + int 19h ; bootstrap 1.103 + 1.104 +Stop: 1.105 + hlt 1.106 + jmp short Stop 1.107 + 1.108 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.109 +;; Reads a FAT32 sector ;; 1.110 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.111 +;; Inout: ES:BX -> buffer ;; 1.112 +;; EAX = prev sector ;; 1.113 +;; CX = rem sectors in cluster ;; 1.114 +;; ESI = next cluster ;; 1.115 +;; Output: EAX = current sector ;; 1.116 +;; CX = rem sectors in cluster ;; 1.117 +;; ESI = next cluster ;; 1.118 +;; BP -> para / sector ;; 1.119 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.120 + 1.121 +ReadClusterSector: 1.122 +%if SectorOf512Bytes != 0 1.123 + mov bp, 32 ; bp = paragraphs per sector 1.124 +%else 1.125 mov bp, [bx(bpbBytesPerSector)] 1.126 shr bp, 4 ; bp = paragraphs per sector 1.127 +%endif 1.128 mov dx, 1 ; adjust LBA for next sector 1.129 inc cx 1.130 loop ReadSectorLBA 1.131 1.132 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.133 -;; Reads a FAT32 cluster ;; 1.134 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.135 -;; Inout: ES:BX -> buffer ;; 1.136 -;; ESI = cluster no ;; 1.137 -;; Output: ESI = next cluster ;; 1.138 -;; BP -> para / sector ;; 1.139 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.140 - 1.141 mul ebx ; edx:eax = 0 1.142 +%if SectorOf512Bytes != 0 1.143 + mov al, 128 ; ax=# of FAT32 entries per sector 1.144 +%else 1.145 imul ax, bp, byte 4 ; ax=# of FAT32 entries per sector 1.146 +%endif 1.147 lea edi, [esi-2] ; esi=cluster # 1.148 xchg eax, esi 1.149 div esi ; eax=FAT sector #, edx=entry # in sector 1.150 1.151 imul si, dx, byte 4 ; si=entry # in sector, clear C 1.152 %if LBA48bits != 0 1.153 - xor dx, dx ; clear C 1.154 + xor dx, dx 1.155 %endif 1.156 - call ReadSectorLBAabsolute ; read 1 FAT32 sector 1.157 + call ReadSectorLBAfromFAT ; read 1 FAT32 sector 1.158 1.159 %if ClusterMask != 0 1.160 and byte [es:si+3], 0Fh ; mask cluster value 1.161 %endif 1.162 mov esi, [es:si] ; esi=next cluster # 1.163 1.164 +%if Always2FATs != 0 1.165 + imul eax, dword [bx(bsSectorsPerFAT32)], 2 1.166 +%else 1.167 movzx eax, byte [bx(bpbNumberOfFATs)] 1.168 mul dword [bx(bsSectorsPerFAT32)] 1.169 +%endif 1.170 1.171 xchg eax, edi 1.172 movzx ecx, byte [bx(bpbSectorsPerCluster)] ; 8..128 1.173 mul ecx ; edx:eax=sector number in data area 1.174 add eax, edi 1.175 +%if LBA48bits != 0 1.176 + adc dx, bx 1.177 +%endif 1.178 1.179 -ReadSectorLBAabsolute: 1.180 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.181 +;; Reads a sector form the start of FAT ;; 1.182 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.183 + 1.184 +ReadSectorLBAfromFAT: 1.185 + add eax, [bx(bpbHiddenSectors)] 1.186 %if LBA48bits != 0 1.187 adc dx, bx 1.188 mov word [bx(HiLBA)], dx 1.189 %endif 1.190 - add eax, [bx(bpbHiddenSectors)] 1.191 -%if LBA48bits != 0 1.192 - adc word [bx(HiLBA)], bx 1.193 -%endif 1.194 mov dx, [bx(bpbReservedSectors)] 1.195 1.196 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.197 @@ -432,7 +473,7 @@ 1.198 push byte 16 ; packet size byte = 16, reserved byte = 0 1.199 1.200 %if CHSsupport != 0 1.201 -%if CHShardDisk != 0 1.202 + %if CHSupTo8GB != 0 1.203 push eax 1.204 pop cx ; save low LBA 1.205 pop ax ; get high LBA 1.206 @@ -440,12 +481,16 @@ 1.207 idiv word [bx(bpbSectorsPerTrack)] ; up to 8GB disks, avoid divide error 1.208 1.209 xchg ax, cx ; restore low LBA, save high LBA / SPT 1.210 -%else 1.211 + %else 1.212 ; Busybox mkdosfs creates fat32 for floppies. 1.213 ; Floppies may support CHS only. 1.214 + %if CHSupTo32MB != 0 1.215 + xor dx, dx ; clear dx (LBA offset <32MB) 1.216 + %else 1.217 cwd ; clear dx (LBA offset <16MB) 1.218 + %endif 1.219 xor cx, cx ; high LBA / SPT = 0 1.220 -%endif 1.221 + %endif 1.222 idiv word [bx(bpbSectorsPerTrack)] 1.223 ; ax = LBA / SPT 1.224 ; dx = LBA % SPT = sector - 1 1.225 @@ -456,13 +501,13 @@ 1.226 ; ax = (LBA / SPT) / HPC = cylinder 1.227 ; dx = (LBA / SPT) % HPC = head 1.228 1.229 - mov ch, al 1.230 + xchg ch, al ; clear al 1.231 ; ch = LSB 0...7 of cylinder no. 1.232 -%if CHShardDisk != 0 1.233 - shl ah, 6 1.234 - or cl, ah 1.235 + %if CHSupTo8GB != 0 || CHSupTo32MB != 0 1.236 + shr ax, 2 1.237 + or cl, al 1.238 ; cl = MSB 8...9 of cylinder no. + sector no. 1.239 -%endif 1.240 + %endif 1.241 mov dh, dl 1.242 ; dh = head no. 1.243 mov dl, [bx(DriveNumber)] ; restore BIOS boot drive number 1.244 @@ -482,11 +527,11 @@ 1.245 jnc ReadSuccess ; CF = 0 if no error 1.246 %endif 1.247 %if ReadRetry != 0 1.248 -%if CHSsupport != 0 1.249 + %if CHSsupport != 0 1.250 cbw ; ah = 0 = reset function 1.251 -%else 1.252 + %else 1.253 xor ax, ax ; ah = 0 = reset function 1.254 -%endif 1.255 + %endif 1.256 int 13h ; reset drive (DL) 1.257 1.258 dec bp ; up to 32 retries 1.259 @@ -499,43 +544,14 @@ 1.260 ReadSuccess: 1.261 1.262 popa ; sp += 16 1.263 - 1.264 popa 1.265 - 1.266 - stc 1.267 - loop ReadSectorNext 1.268 - 1.269 - cmp esi, 0FFFFFF6h ; carry=0 if last cluster, and carry=1 otherwise 1.270 - 1.271 -ReadSectorNext: 1.272 ret 1.273 1.274 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.275 ;; Fill free space with zeroes ;; 1.276 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.277 1.278 - times (512-13-20-($-$$)) db 0 1.279 - 1.280 -;;;;;;;;;;;;;;;;;;;;;;;;;; 1.281 -;; Error Messaging Code ;; 1.282 -;;;;;;;;;;;;;;;;;;;;;;;;;; 1.283 - 1.284 -Error: 1.285 - pop si 1.286 -puts: 1.287 - mov ah, 0Eh 1.288 - mov bl, 7 1.289 - lodsb 1.290 - int 10h 1.291 - cmp al, '.' 1.292 - jne puts 1.293 - cbw 1.294 - int 16h ; wait for a key... 1.295 - int 19h ; bootstrap 1.296 - 1.297 -Stop: 1.298 - hlt 1.299 - jmp short Stop 1.300 + times (512-13-($-$$)) db 0 1.301 1.302 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.303 ;; Name of the file to load and run ;;