wok diff BootProg/stuff/boot16.asm @ rev 24942
BootProg: clear cmdline
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Apr 20 15:10:50 2022 +0000 (2022-04-20) |
parents | d8c511e24c20 |
children | 584e67527789 |
line diff
1.1 --- a/BootProg/stuff/boot16.asm Fri Feb 18 22:59:06 2022 +0000 1.2 +++ b/BootProg/stuff/boot16.asm Wed Apr 20 15:10:50 2022 +0000 1.3 @@ -213,14 +213,14 @@ 1.4 mul bx ; dx:ax = 0 = LBA (LBA are relative to FAT) 1.5 mov cx, word [bx(bpbSectorsPerFAT)] 1.6 1.7 - call ReadCXSectors ; read fat and clear cx 1.8 + call ReadCXSectors ; read fat and clear ax & cx 1.9 1.10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.11 ;; load the root directory in ;; 1.12 ;; its entirety (16KB max) ;; 1.13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.14 1.15 - mov ax, 32 1.16 + mov al, 32 1.17 1.18 mul word [bx(bpbRootEntries)] 1.19 div word [bx(bpbBytesPerSector)] 1.20 @@ -230,7 +230,7 @@ 1.21 mul bp ; [bx(bpbSectorsPerFAT)], set by ReadCXSectors 1.22 1.23 push es 1.24 - call ReadCXSectors ; read root directory, clear cx and di 1.25 + call ReadCXSectors ; read root directory; clear ax, cx and di 1.26 pop es 1.27 1.28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.29 @@ -248,15 +248,15 @@ 1.30 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.31 1.32 FindNameCycle: 1.33 - cmp byte [es:di], ch 1.34 - je FindNameFailed ; end of root directory (NULL entry found) 1.35 push di 1.36 mov cl, 11 1.37 mov si, ProgramName ; ds:si -> program name 1.38 repe cmpsb 1.39 pop di 1.40 je FindNameFound 1.41 - add di, byte 32 1.42 + scasb 1.43 + je FindNameFailed ; end of root directory (NULL entry found) 1.44 + add di, byte 31 1.45 dec word [bx(bpbRootEntries)] 1.46 jnz FindNameCycle ; next root entry 1.47 1.48 @@ -298,28 +298,26 @@ 1.49 jnc First64 1.50 mov ah, (1000h+ImageLoadSeg)>>8 ; adjust segment for 2nd part of FAT16 1.51 First64: 1.52 + mov dx, 0FFF8h 1.53 + 1.54 cmp [bx(bpbSectorsPerFAT)], cx ; 1..12 = FAT12, 16..256 = FAT16 1.55 mov ds, ax 1.56 - jbe ReadClusterFat12 1.57 + ja ReadClusterFat16 1.58 1.59 - lodsw ; ax = next cluster 1.60 - cmp ax, 0FFF8h 1.61 - jmp short ReadClusterDone 1.62 - 1.63 -ReadClusterFat12: 1.64 + mov dh, 0Fh 1.65 add si, [cs:di] 1.66 shr si, 1 ; si = cluster * 3 / 2 1.67 1.68 +ReadClusterFat16: 1.69 lodsw ; ax = next cluster 1.70 jnc ReadClusterEven 1.71 1.72 rol ax, cl 1.73 1.74 ReadClusterEven: 1.75 - and ax, 0FFFh ; mask cluster value 1.76 - cmp ax, 0FF8h 1.77 + and ah, dh ; mask cluster value 1.78 + cmp ax, dx 1.79 1.80 -ReadClusterDone: 1.81 push cs 1.82 pop ds 1.83 inc di 1.84 @@ -352,7 +350,7 @@ 1.85 add ax, bp ; LBA for cluster data 1.86 adc dx, bx ; dx:ax = LBA 1.87 1.88 - call ReadSector ; clear cx 1.89 + call ReadSector ; clear ax & cx, restore dx 1.90 1.91 jne ReadClusters 1.92 1.93 @@ -365,7 +363,6 @@ 1.94 mov ds, bp ; bp=ds=seg the file is loaded to 1.95 1.96 add bp, [bx+08h] ; bp = image base 1.97 - mov ax, [bx+06h] ; ax = reloc items 1.98 mov di, [bx+18h] ; di = reloc table pointer 1.99 1.100 cmp word [bx], 5A4Dh ; "MZ" signature? 1.101 @@ -374,19 +371,22 @@ 1.102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.103 ;; Setup and run a .COM program ;; 1.104 ;; Set CS=DS=ES=SS SP=0 IP=100h ;; 1.105 +;; AX=0ffffh BX=0 CX=0 DX=drive ;; 1.106 +;; and cmdline=void ;; 1.107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.108 1.109 + mov di, 100h ; ip 1.110 mov bp, ImageLoadSeg-10h ; "org 100h" stuff :) 1.111 mov ss, bp 1.112 xor sp, sp 1.113 push bp ; cs, ds and es 1.114 - mov bh, 1 ; ip 1.115 jmp short Run 1.116 1.117 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.118 ;; Relocate, setup and run a .EXE program ;; 1.119 ;; Set CS:IP, SS:SP, DS, ES and AX according ;; 1.120 ;; to wiki.osdev.org/MZ#Initial_Program_State ;; 1.121 +;; AX=0ffffh BX=0 CX=0 DX=drive cmdline=void ;; 1.122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.123 1.124 ReloCycle: 1.125 @@ -397,8 +397,8 @@ 1.126 scasw ; point to next entry 1.127 1.128 RelocateEXE: 1.129 - dec ax ; 32768 max (128KB table) 1.130 - jns ReloCycle ; leave with ax=0ffffh: both FCB in the 1.131 + dec word [bx+06h] ; reloc items, 32768 max (128KB table) 1.132 + jns ReloCycle 1.133 ; PSP don't have a valid drive identifier 1.134 les si, [bx+0Eh] 1.135 add si, bp 1.136 @@ -409,13 +409,15 @@ 1.137 push si ; containing the PSP structure 1.138 1.139 add bp, [bx+16h] ; cs for EXE 1.140 - mov bx, [bx+14h] ; ip for EXE 1.141 + mov di, [bx+14h] ; ip for EXE 1.142 Run: 1.143 pop ds 1.144 push bp 1.145 - push bx 1.146 + push di 1.147 push ds 1.148 pop es 1.149 + mov [80h], ax ; clear cmdline 1.150 + dec ax ; both FCB in the PSP don't have a valid drive identifier 1.151 1.152 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.153 ;; Set the magic numbers so the program knows that it ;; 1.154 @@ -539,10 +541,17 @@ 1.155 dec di ; keep C 1.156 loopne ReadSectorNext ; until cluster sector count or file sector count is reached 1.157 pop si 1.158 + mov ax, bx ; clear ax 1.159 mov dx, [bx] ; pass the BIOS boot drive to Run or Error 1.160 1.161 ret 1.162 1.163 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.164 +;; Fill free space with zeroes ;; 1.165 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.166 + 1.167 + times (512-13-20-($-$$)) db 0 1.168 + 1.169 ;;;;;;;;;;;;;;;;;;;;;;;;;; 1.170 ;; Error Messaging Code ;; 1.171 ;;;;;;;;;;;;;;;;;;;;;;;;;; 1.172 @@ -566,12 +575,6 @@ 1.173 hlt 1.174 jmp short Stop 1.175 1.176 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.177 -;; Fill free space with zeroes ;; 1.178 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.179 - 1.180 - times (512-13-($-$$)) db 0 1.181 - 1.182 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.183 ;; Name of the file to load and run ;; 1.184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;