wok-next diff memtest/stuff/unpack.S @ rev 21057
Deal with HOST_ARCH="any"
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Mon Dec 03 14:47:30 2018 +0200 (2018-12-03) |
parents | fd3dadf90ba9 |
children |
line diff
1.1 --- a/memtest/stuff/unpack.S Mon Sep 05 18:15:15 2016 +0200 1.2 +++ b/memtest/stuff/unpack.S Mon Dec 03 14:47:30 2018 +0200 1.3 @@ -1,17 +1,16 @@ 1.4 #define TOP (0x90000+_start-end) 1.5 #define SYSTEM 0x10000 1.6 -#define SETUP 4 1.7 +#define SETUP 14 1.8 #define SYSSIZE 0x1F4 1.9 #define SETUPSIZE 0x1F1 1.10 1.11 -#define CHANGE_STACK 0 1.12 #define LINUX_HEADER 0 1.13 #define UPDATE_SYSSIZE 1 1.14 #define HARDCODED_SYSSIZE 1 1.15 #define HARDCODED_SETUPSIZE 1 1.16 -#define HARDCODED_IP 1 1.17 #define FLAT16 1 1.18 //#define FLAT16OUT 0 1.19 +#define SAVEREGS 0 1.20 1.21 .text 1.22 .code16 1.23 @@ -35,173 +34,176 @@ 1.24 .long 0 // 220 bootsect_kludge 1.25 start2: 1.26 #endif 1.27 - pushf 1.28 +#if SAVEREGS 1.29 + pushfw 1.30 pushw %cs 1.31 -#if HARDCODED_IP 1.32 pushw $0 1.33 + pushal 1.34 + pushw %ds 1.35 #else 1.36 - call getip 1.37 -getip: 1.38 + pushw %cs 1.39 + pushw $0 1.40 #endif 1.41 - pushal 1.42 -#if !FLAT16 1.43 -#undef FLAT16 1.44 -#if HARDCODED_SYSSIZE 1.45 -packed_syssize: 1.46 - movw $0, %bx // system size 1.47 +#if UPDATE_SYSSIZE 1.48 + pushw %ds 1.49 #else 1.50 - movw SYSSIZE, %bx 1.51 + pushw %es 1.52 + pushw %cs 1.53 #endif 1.54 -#endif 1.55 -#if HARDCODED_SETUPSIZE == 0 1.56 - xorw %dx, %dx 1.57 - movb SETUPSIZE, %dh 1.58 -#endif 1.59 -#if HARDCODED_IP 1.60 + cld 1.61 +#if FLAT16 1.62 +# 1- move 9020..9020+stp -> 8000 1.63 +# if HARDCODED_SETUPSIZE 1.64 +setup_word: 1.65 + movw $SETUP*256, %cx 1.66 +# else 1.67 + xorw %cx, %cx 1.68 + movb SETUPSIZE, %ch 1.69 + movw %cx, %dx 1.70 +# endif 1.71 + pushw %cx 1.72 + pushw $0x8000 1.73 + popw %es 1.74 xorw %si, %si 1.75 -#else 1.76 - movw %sp, %bp 1.77 -#define START_IP 32(%bp) 1.78 - subw $getip-_start, START_IP 1.79 - movw START_IP, %si 1.80 -#endif 1.81 - pushw %ds 1.82 + xorw %di, %di 1.83 + rep 1.84 + movsw %cs:(%si),%es:(%di) 1.85 pushw %es 1.86 - 1.87 - cld 1.88 - 1.89 -#if FLAT16 1.90 -flat16mv: 1.91 -#if CHANGE_STACK 1.92 -STKSZ=0x9000-0x0990 1.93 - pushw $(TOP-STKSZ)/16-0x1000 1.94 -#else 1.95 - pushw $TOP/16-0x1000 1.96 -#endif 1.97 - popw %es 1.98 - pushw %es // moved 1.99 - .byte 0x6A, moved-_start // unpack code 1.100 - pushw %cs 1.101 - popw %ds 1.102 - xorw %di, %di 1.103 -#if HARDCODED_SETUPSIZE 1.104 - movw $SETUP*256, %cx 1.105 -#else 1.106 - xorw %cx, %cx 1.107 - movw SETUPSIZE, %ch 1.108 -#endif 1.109 - pushw %si 1.110 - rep 1.111 - movsw // move header part 1.112 - movw $0x1000, %bp 1.113 - movw %bp, %ds 1.114 + // pushw $cont 1.115 + .byte 0x6A, cont 1.116 + lret 1.117 +cont: 1.118 +# 2- move 1000..1000+sys -> 8000+stp 1.119 + pushw $0x1000 1.120 + popw %ds 1.121 xorw %si, %si 1.122 subw %di, %cx 1.123 rep 1.124 - movsb // move system part 1.125 - popw %di 1.126 - movw $end-_start, %si 1.127 -#else 1.128 -#if CHANGE_STACK 1.129 -STKSZ=0x9000-0x0990 1.130 - movw $(TOP-STKSZ)/16, %ax 1.131 + movsb 1.132 +# 3- unlz(8000+stp:end, 1000-stp:0) 1.133 + pushw %es 1.134 +# if HARDCODED_SETUPSIZE 1.135 +setup_seg: 1.136 +# if UPDATE_SYSSIZE 1.137 + pushw $0x1000-(SETUP*32)-32 1.138 +# else 1.139 + pushw $0x1000-(SETUP*32) 1.140 +# endif 1.141 + popw %es 1.142 +# else 1.143 +# if UPDATE_SYSSIZE 1.144 + incb %dh 1.145 +# endif 1.146 + shrw $3, %dx 1.147 + movw %ds, %ax 1.148 + subw %dx, %ax 1.149 + movw %ax, %es 1.150 +# endif 1.151 #else 1.152 - movw $TOP/16, %ax 1.153 -#endif 1.154 - movw %ax, %es 1.155 - pushw %es // moved 1.156 - .byte 0x6A, moved-_start // unpack code 1.157 - pushw %cs 1.158 - popw %ds 1.159 +# 1- move 1000..1000+sys -> 9000-sys 1.160 +# if HARDCODED_SYSSIZE 1.161 +packed_syssize: 1.162 + movw $0x1000+0, %ax 1.163 +# else 1.164 + movw SYSSIZE, %ax 1.165 + addw $0x1000, %ax 1.166 +# endif 1.167 + movw %ds, %dx 1.168 +mvsys: 1.169 + decw %ax 1.170 + decw %dx 1.171 + movw %ax, %ds 1.172 + movw %dx, %es 1.173 + xorw %si, %si 1.174 + xorw %di, %di 1.175 + movw $8, %cx 1.176 + rep 1.177 + movsw 1.178 + cmpw $0x1000, %ax 1.179 + jne mvsys 1.180 +# 2- move 9020..9020+stp -> 9000-sys-stp 1.181 + 1.182 +# if HARDCODED_SETUPSIZE 1.183 +setup_byte: 1.184 + movb $SETUP, %ch 1.185 +setup_para: 1.186 + subw $SETUP*32, %dx 1.187 +# else 1.188 + movb %ss:SETUPSIZE, %ch 1.189 + movw %cx, %ax 1.190 + shrw $3, %ax 1.191 + subw %ax, %dx 1.192 +# endif 1.193 + pushw %cx 1.194 + movw %dx, %es 1.195 + xorw %si, %si 1.196 + xorw %di, %di 1.197 + rep 1.198 + movsw %cs:(%si),%es:(%di) 1.199 + pushw %es 1.200 +# 3- reloc itself in 0x7C00 1.201 + pushw $0x07C0 1.202 + popw %es 1.203 + xorw %si, %si 1.204 xorw %di, %di 1.205 movw $end-_start, %cx 1.206 - pushw %cx 1.207 - pushw %si 1.208 rep 1.209 - movsb // move upack code to $TOP 1.210 - 1.211 - leaw SYSTEM/16(%bx), %bp 1.212 -movlp: 1.213 - decw %bp 1.214 - movw %bp, %ds 1.215 - decw %ax 1.216 + movsb %cs:(%si),%es:(%di) 1.217 + pushw %es 1.218 + // pushw $cont 1.219 + .byte 0x6A, cont 1.220 + lret 1.221 +cont: 1.222 +# 4- unlz(9000-sys-stp:end, 1000-stp:0) 1.223 +# if HARDCODED_SETUPSIZE 1.224 +setup_seg: 1.225 +# if UPDATE_SYSSIZE 1.226 + pushw $0x1000-(SETUP*32)-32 1.227 +# else 1.228 + pushw $0x1000-(SETUP*32) 1.229 +# endif 1.230 + popw %es 1.231 +# else 1.232 + negw %ax 1.233 +# if UPDATE_SYSSIZE 1.234 + addw $0x1000-32, %ax 1.235 +# else 1.236 + addw $0x1000, %ax 1.237 +# endif 1.238 movw %ax, %es 1.239 - xorw %si, %si 1.240 +# endif 1.241 +#endif 1.242 + popw %ds 1.243 + movw $end-_start, %si 1.244 +#if UPDATE_SYSSIZE 1.245 + movw $SYSSIZE, %di 1.246 +#else 1.247 xorw %di, %di 1.248 - movb $8, %cl 1.249 - rep 1.250 - movsw // move system part 1.251 - decw %bx 1.252 - jnz movlp 1.253 - 1.254 - pushw %cs 1.255 +#endif 1.256 + pushw %di 1.257 + pushw %es 1.258 + call unpack 1.259 popw %ds 1.260 popw %si 1.261 - xorw %di, %di 1.262 -#if HARDCODED_SETUPSIZE 1.263 - movb $SETUP, %ch 1.264 - subw $SETUP*32, %ax 1.265 -#else 1.266 - movb %dh, %ch 1.267 - shrw $3, %dx 1.268 - subw %dx, %ax 1.269 -#endif 1.270 - movw %ax, %es 1.271 - pushw %si 1.272 - rep 1.273 - movsw // move header part 1.274 - popw %di 1.275 - popw %si 1.276 -#endif 1.277 - pushw %es 1.278 - popw %ds 1.279 - pushw %cs 1.280 - popw %es // restore setup seg 1.281 - retf 1.282 - 1.283 -moved: 1.284 -#if CHANGE_STACK 1.285 - movw $STKSZ, %ax // trick: %ss = %sp 1.286 - movw %ss, %bx 1.287 - pushw %ax 1.288 - popw %ss 1.289 - xchgw %ax, %sp 1.290 - pushw %bx // %ss 1.291 - pushw %ax // %sp 1.292 -#endif 1.293 - pushw %bp // SYSTEM/16 1.294 - call unpack // unpack setup 1.295 - popw %es 1.296 - xorw %di,%di 1.297 - call unpack // unpack system 1.298 -#if CHANGE_STACK 1.299 - popw %ax // %sp 1.300 - popw %ss 1.301 - xchgw %ax, %sp 1.302 -#endif 1.303 + movw %si, %di 1.304 + popw %cx 1.305 #if UPDATE_SYSSIZE 1.306 -# if HARDCODED_SYSSIZE 1.307 -original_syssize: 1.308 - movw $0, %ax 1.309 -# else 1.310 - addw $15, %di 1.311 - shrw $4, %di 1.312 - movw %es, %ax 1.313 - addw %di, %ax 1.314 - subw $SYSTEM/16, %ax 1.315 -# endif 1.316 +// not need with memtest movb $(512-SYSSIZE)/2, %cl 1.317 #endif 1.318 popw %es 1.319 +# 5- move 1000-stp..1000 -> 9020 1.320 + rep 1.321 + movsw 1.322 +#if UPDATE_SYSSIZE == 0 1.323 + popw %es 1.324 +#endif 1.325 +#if SAVEREGS 1.326 popw %ds 1.327 -#if UPDATE_SYSSIZE 1.328 - movw %ax, SYSSIZE 1.329 -# if HARDCODED_SETUPSIZE 1.330 -original_setupsize: 1.331 - movb $4, SETUPSIZE 1.332 -# endif 1.333 -#endif 1.334 popal 1.335 iret 1.336 +#else 1.337 + lret 1.338 +#endif 1.339 1.340 unpack: 1.341 #define NO_LZMA_HEADER