wok diff linld/stuff/src/pipehole.awk @ rev 21791
Fix loram dos boot
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Aug 01 15:16:29 2019 +0200 (2019-08-01) |
parents | 68f9518c4cb0 |
children | 1c40a6bea05c |
line diff
1.1 --- a/linld/stuff/src/pipehole.awk Sun Jul 21 10:32:10 2019 +0200 1.2 +++ b/linld/stuff/src/pipehole.awk Thu Aug 01 15:16:29 2019 +0200 1.3 @@ -1,11 +1,35 @@ 1.4 -BEGIN { hold=0; is386=0; isload=0; isiso=0; istazboot=0; wascall=0; label="none"; xlabel="" } 1.5 +BEGIN { hold=0; is386=0; isload=0; isiso=0; istazboot=0; wascall=0; ishimem=0; label="none"; xlabel=""; file="" } 1.6 function isnum(n) { return match(n,/^[0-9+-]/) } 1.7 { 1.8 sub(/segment word public/,"segment byte public") 1.9 1.10 if (/^@.*:$/ || / endp$/) afterjmp=0 1.11 - if (/dword ptr/) is386=1 1.12 + if (/^ \.386p$/) is386=1 1.13 + if (file == "" && /debug S/) { file=$3; gsub(/\"/,"",file) } 1.14 + if (file == "himem.cpp") { 1.15 + if (/remaining = m-/) ishimem=1 1.16 + if (ishimem == 1 && is386 == 0) { 1.17 + if (/si\+8\]$/ || /si\+4\]$/ || /si\+16\]$/) next 1.18 + if (/si\+6\]$/ || /si\+2\]$/ || /si\+14\]$/) sub(/mov dx,/,"les dx,d") 1.19 + if (/si\+12\],ax/ || /si\+16\],ax/ || /bp-2\],ax/) sub(/,ax/,",es") 1.20 + if (/do \{/) ishimem=0 1.21 + } 1.22 + } # file == "himem.cpp" 1.23 + if (file == "load.cpp") { 1.24 sub(/DGROUP:_imgs\+65534/,"[di-2]") 1.25 + if (/short @1@366$/) isload=10 1.26 + if (isload == 10) { # LOAD.LST 1.27 + if (/^ je /) next 1.28 + if (/ptr @die\$qpxzc/) { 1.29 + $0=" jne @die@" 1.30 + isload=0 1.31 + } 1.32 + } 1.33 + if (/setup_sects == 0/) isload=9 1.34 + if (isload == 9) { # LOAD.LST 1.35 + sub(/,0/,",al") 1.36 + if (/jne/) isload=0 1.37 + } 1.38 if (/fallback\)\[1\] == 0/) isload=8 1.39 if (isload == 8) { # LOAD.LST 1.40 if (/load_image/) isload=0 1.41 @@ -14,10 +38,13 @@ 1.42 if (/cmd_line_ptr =/ && is386 == 0) isload=7 1.43 if (isload == 7) { # LOAD.LST 1.44 if (/add/ || /xor/ || /extrn/ || /N_LXLSH@/ || /cl,4/) next 1.45 - if (/,ax/) { 1.46 - sub(/ax/,"8000h") 1.47 + if (/enable A20 if needed/) { 1.48 + print " mov word ptr [bx+si],8000h" 1.49 isload=0 1.50 } 1.51 + if (/,ax/) $0=" mov bx,55" 1.52 + if (/si-463/) $0=" mov bx,-463" 1.53 + if (/si-465/) $0=" mov word ptr [bx+si-2],-23745" 1.54 if (/,dx/) { 1.55 print " mov cl,12" 1.56 print " shr ax,cl" 1.57 @@ -55,7 +82,6 @@ 1.58 if (isload == 4 && is386 == 0) { # LOAD.LST 1.59 if (/push/ || /pop/) next 1.60 if (/ax,cs/) { 1.61 - print " cwd" 1.62 sub(/ax,cs/,"bx,cs") 1.63 } 1.64 if (/dx,dx/) next 1.65 @@ -68,9 +94,21 @@ 1.66 isload=400 1.67 } 1.68 } 1.69 - if (isload == 400 && /,0/) { 1.70 + if (isload == 400) { 1.71 + if (/call/) { 1.72 + print " extrn N_LXLSH@4:near" 1.73 + sub(/N_LXLSH@/,"N_LXLSH@4") 1.74 + } 1.75 sub(/,0/,",dh") 1.76 - isload=0 1.77 + if (/_base_himem\+2/ || /pop/ || /push/) next 1.78 + if (/_base_himem$/) { 1.79 + sub(/mov dx,/,"les dx,d") 1.80 + isload++ 1.81 + } 1.82 + } 1.83 + if (isload == 401) { 1.84 + sub(/,ax/,",es") 1.85 + if (/load_image/) isload=0 1.86 } 1.87 if (isload == 4 && is386) { # LOAD.LST 1.88 sub(/dx,cs/,"edx,cs") 1.89 @@ -101,15 +139,39 @@ 1.90 sub(/,ax/,",cx") 1.91 if (/version_string/ || /starting linux 1\.3\.73/) isload=0 1.92 } 1.93 - if (/_rm_size=0x200/ || /heap_top = _rm_buf/) isload=1 1.94 + if (/Not a kernel/ || /_rm_size=0x200/ || /heap_top = _rm_buf/) isload=1 1.95 if (isload == 1) { # LOAD.LST 1.96 + if (/ptr .die\$qpxzc/) $0="@die@:\n" $0 1.97 if (/mov al,byte ptr/ && is386) { 1.98 print " movzx eax,byte ptr [si]" 1.99 next 1.100 } 1.101 + if (is386 == 0) { 1.102 + if (/di-5\],ax/) print " cwd" 1.103 + sub(/,0$/,",dx") 1.104 + } 1.105 if (/ax,word ptr/) next 1.106 if (/^ call/) isload=0 1.107 } 1.108 + } # file == "load.cpp" 1.109 + if (file == "iso9660.cpp") { 1.110 + if (/<< SECTORBITS/) isiso=9 1.111 + if (isiso == 9) { # ISO9660.LST 1.112 + if (/dx,/) next 1.113 + sub(/mov ax,/,"les ax,d") 1.114 + if (/^ call/) { 1.115 + print " extrn N_LXLSH@ES:near" 1.116 + sub(/N_LXLSH@/,"N_LXLSH@ES") 1.117 + isiso=0 1.118 + } 1.119 + } 1.120 + if (/filesize =/) isiso=8 1.121 + if (isiso == 8) { # ISO9660.LST 1.122 + if (/ax,/) next 1.123 + sub(/mov dx,/,"les dx,d") 1.124 + sub(/,ax/,",es") 1.125 + if (/filemod/) isiso=0 1.126 + } 1.127 if (/CD001/) isiso=7 1.128 if (isiso == 7) { # ISO9660.LST 1.129 sub(/mov ax,-1/,"dec ax") 1.130 @@ -137,6 +199,8 @@ 1.131 sub(/DGROUP:_isostate\+20/,"[si+20]") 1.132 if (/goto restarted/) isiso=0 1.133 } 1.134 + } # file == "iso9660.cpp" 1.135 + if (file == "iso9660.cpp" || file == "tazboot.cpp") { 1.136 if (/do s\+\+; while/) isiso=3 1.137 if (/for \(p = s; \*s && \*s \!=/) isiso=3 1.138 if (isiso == 3) { # ISO9660.LST, TAZBOOT.LST 1.139 @@ -147,10 +211,15 @@ 1.140 if (/al,0/) print " mov al,[" r "]" 1.141 if (/al,byte ptr/) sub(/mov/,"xchg") 1.142 if (/byte ptr \[.*\],0/) next 1.143 - if (/jmp/) print " mov bx,si" 1.144 + if (/jmp/) { 1.145 + print " mov bx,si" 1.146 + $0=" db 0A8h ; test al,xx instead of " $0 1.147 + } 1.148 if (/word ptr \[bp-4\]/) next 1.149 if (/\) s\+\+;/ || /\],-1/) isiso=0 1.150 } 1.151 + } # file == "iso9660.cpp" || file == "tazboot.cpp" 1.152 + if (file == "iso9660.cpp") { 1.153 if (/endname = NULL/) isiso=2 1.154 if (isiso == 2) { # ISO9660.LST 1.155 if (/mov bx,cx/) next 1.156 @@ -172,10 +241,13 @@ 1.157 if (/jmp @3@58$/) $0=" je @3@58" 1.158 sub(/mov ax,-1/,"dec ax") 1.159 } 1.160 + } # file == "iso9660.cpp" 1.161 if (/endp/) { xlabel = ""; goto2=0 } 1.162 if (/isoopen\(s\+7\)/ && xlabel == "") goto2=1 1.163 if (/_vid_mode,ax/ && xlabel == "") goto2=1 1.164 + if (/_initrd_name,si/ && xlabel == "") goto2=1 1.165 if (/_base_himem\+2,/ && xlabel == "@") goto2=1 1.166 + if (/DGROUP:_skip_alloc/ && xlabel == "@") goto2=1 1.167 if (/puts\(cmdline\)/ && xlabel == "@@") goto2=1 1.168 if (goto2 == 1 && /jmp/) { # TAZBOOT.LST && LINLD.LST 1.169 print $NF xlabel "@:" 1.170 @@ -185,6 +257,30 @@ 1.171 $0=$0 xlabel 1.172 if (goto2++ == 1) xlabel=xlabel "@" 1.173 } 1.174 + if (/if\(\*s>=/) isotazboot=14 1.175 + if (isotazboot == 14) { # LINLD.LST 1.176 + if (/jmp/) { 1.177 + $0=" db 0A9h ; test ax,xxxx instead of " $0 1.178 + isotazboot=0 1.179 + } 1.180 + } 1.181 + if (file == "tazboot.cpp" && /; s \+= 4/) isotazboot=13 1.182 + if (isotazboot == 13) { # TAZBOOT.LST 1.183 + if (/si,4/) $0=" lea bx,[si+4]" 1.184 + if (/bx,si/) next 1.185 + if (/DGROUP:_topmem/ || /set_iso/) isotazboot=0 1.186 + } 1.187 + if (file == "tazboot.cpp" && /case 0x652F:/) isotazboot=12 1.188 + if (isotazboot == 12) { # TAZBOOT.LST 1.189 + sub(/si,word/,"bx,word") 1.190 + if (/short/) isotazboot=0 1.191 + } 1.192 + if (/return load_kernel/) isotazboot=11 1.193 + if (isotazboot == 11) { # TAZBOOT.LST 1.194 + sub(/call/,"jmp") 1.195 + if (/ret/ || /pop/) next 1.196 + if (/endp/) isotazboot=0 1.197 + } 1.198 if (/cmdline=s\+=3/ || /magic \!= 0/ || /&root_dev =/) { isotazboot=10; j="" } 1.199 if (isotazboot == 10) { # TAZBOOT.LST && LINLD.LST 1.200 if (/je/ || /jne/) { j=$1; next } 1.201 @@ -215,9 +311,8 @@ 1.202 } 1.203 if (/\+\+isknoppix/) isotazboot=7 1.204 if (isotazboot == 7) { # TAZBOOT.LST 1.205 - if (/al,byte/) sub (/al,byte ptr DGROUP:/,"bx,offset ") 1.206 - if (/inc/) sub (/al/,"word ptr [bx]") 1.207 - if (/,al/) next 1.208 + if (/inc/ || /,al/) next 1.209 + if (/al,byte/) sub (/mov al,/,"inc ") 1.210 if (/isokernel/) isotazboot=0 1.211 } 1.212 if (/if \(c\) s\+\+;/) isotazboot=6 1.213 @@ -228,6 +323,12 @@ 1.214 } 1.215 } 1.216 if (/static void next_chunk/) isotazboot=5 1.217 + if (isotazboot == 501) { 1.218 + if (/ret/) { 1.219 + print "@1@86:" 1.220 + isotazboot=0 1.221 + } 1.222 + } 1.223 if (isotazboot == 5 || isotazboot == 500) { # TAZBOOT.LST 1.224 if (/cx,ax/) $0=" xchg ax,bx" 1.225 if (/ax,word ptr \[si\+28\]/ && isotazboot == 500) next 1.226 @@ -235,7 +336,19 @@ 1.227 if (/push/ || /pop/ || /bp,sp/ || /si,/) next 1.228 sub(/\[si/,"[di") 1.229 if (/initrd_info/) isotazboot=500 1.230 - if (/endp/) isotazboot=0 1.231 + if (/bx\+6\]/) next 1.232 + if (/bx\+4\]/) sub(/mov dx,/,"les dx,d") 1.233 + sub(/di\+24\],ax/,"di+24],es") 1.234 + sub(/call/,"jmp") 1.235 + if (/ret/ || /pop/ || /^@1@86:/) next 1.236 + if (/_isostate\+14/) next 1.237 + if (/_isostate\+12/) { 1.238 + sub(/mov ax,/,"les ax,d") 1.239 + print 1.240 + print " mov dx,es" 1.241 + next 1.242 + } 1.243 + if (/ax,-4/) isotazboot++ 1.244 } 1.245 if (/0x7FF0/) isotazboot=4 1.246 if (isotazboot == 4) { # TAZBOOT.LST 1.247 @@ -266,6 +379,12 @@ 1.248 } 1.249 if (/\[bp-4\],ax/) sub(/ax/,"bx") 1.250 if (/ax,word ptr \[bx\+2\]/ || /bx,ax/) next 1.251 + if (/_base_himem\+2,dx/) { 1.252 + print " mov bx,offset DGROUP:_base_himem+2" 1.253 + } 1.254 + sub(/DGROUP:_base_himem,/,"[bx-2],") 1.255 + sub(/DGROUP:_base_himem\+2,/,"[bx],") 1.256 + sub(/DGROUP:_base_himem\+3,/,"[bx+1],") 1.257 if (/@strcmp\$qpxzct1/) isotazboot=0 1.258 } 1.259 if (/static void addinitrd/) isotazboot=100