wok-current view memtest/stuff/unpack.S @ rev 25504

Update some web_site / wget_url
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Feb 05 09:28:51 2023 +0000 (21 months ago)
parents 2ccf00d9c1cd
children c9972dbaa043
line source
1 #define SYSTEM 0x10000
2 #define SETUP 14
3 #define SYSSIZE 0x1F4
4 #define SETUPSIZE 0x1F1
6 #define KEEP_BOOTSECTOR 0
7 #define LINUX_HEADER 0
8 #define UPDATE_SYSSIZE 1
9 #define FLAT16 1 // lzma case
10 #define FLAT16OUT 0
11 #define COPYTOHIGHMEM 0
12 #define UPDATE_CODE32_START 0
13 #define DOUBLE_PACKED 0
14 #define SAVEREGS 0
15 #define ELKS 0
17 .text
18 .code16
19 .org 0
21 #if KEEP_BOOTSECTOR
22 #undef UPDATE_SYSSIZE
23 #define UPDATE_SYSSIZE 0
24 #endif
25 #if ELKS
26 .arch i8086
27 #define FLAT16 1
28 #define KEEP_BOOTSECTOR 1
29 #define LINUX_HEADER 0
30 #define SAVEREGS 0
31 #define TOPSEG 0x2000
32 #else
33 #define TOPSEG 0x8000
34 #endif
36 .macro pusham
37 #if ELKS
38 pushw %ax
39 // movw %sp, %ax
40 // incw %ax // emulate popa behaviour
41 // incw %ax
42 pushw %cx
43 pushw %dx
44 pushw %bx
45 // pushw %ax // %sp
46 pushw %bp
47 pushw %si
48 pushw %di
49 #else
50 pushaw
51 #endif
52 .endm
54 .macro popam
55 #if ELKS
56 popw %di
57 popw %si
58 popw %bp
59 // popw %ax
60 popw %bx
61 popw %dx
62 popw %cx
63 popw %ax
64 #else
65 popaw
66 #endif
67 .endm
69 .macro pushm val
70 #if ELKS
71 movw \val, %ax
72 pushw %ax
73 #else
74 pushw \val
75 #endif
76 .endm
78 .macro shrwm cnt, reg
79 #if ELKS
80 .rept \cnt
81 shrw $1, \reg
82 .endr
83 #else
84 shrw $\cnt, \reg
85 #endif
86 .endm
88 .globl _start
89 _start:
90 #if LINUX_HEADER
91 jmp start2
92 .ascii "HdrS" // 202 magic
93 .word 0x200 // 206 version 2.00
94 .long 0 // 208 realmode_swtch
95 .word SYSTEM/16 // 20C start_sys_seg
96 .word 0 // 20E kernel_version
97 .byte 0 // 210 type_of_loader
98 .byte 0 // 211 loadflags
99 .word 0 // 212 setup_move_size
100 .long SYSTEM // 214 code32_start
101 .long 0 // 218 ramdisk_image
102 .long 0 // 21C ramdisk_size
103 .long 0 // 220 bootsect_kludge
104 start2:
105 #endif
106 #if SAVEREGS
107 pushfw
108 pushw %cs
109 pushw $0
110 pusham
111 xorw %si, %si
112 pushw %ds
113 pushw %es
114 cld
115 #else
116 pushw %cs // return adress is %cs:0
117 xorw %si, %si
118 pushw %si
119 #endif // SAVEREGS
120 pushw %ds // <A> bootsector+setup segment
121 #if FLAT16
122 # 1- move 9000..9020+stp -> TOPSEG
123 pushm $TOPSEG
124 popw %es
125 # if SAVEREGS
126 setup_word:
127 movw $SETUP*256+256, %cx
128 pushw %cx // <B> bootsector+setup words
129 # endif
130 pushw %es // <C> TOPSEG
131 pushw %es
132 # if SAVEREGS
133 xorw %di, %di // %ds:%si = 9000:0000 %es:%di = TOPSEG:0
134 pushm $0x200+cont
135 rep
136 movsw
137 lret
138 cont:
139 # else
140 movw $-0x200, %di
141 call jumpinto
142 # endif
143 # 2- move 1000..1000+sys -> TOPSEG+stp
144 pushm $0x1000
145 popw %ds
146 xorw %si, %si // %ds:%si = 1000:0
147 subw %di, %cx // %cx = 64K - setupsz
148 rep
149 movsb
150 # 3- unlz(TOPSEG+stp:end, 1000-stp:0)
151 setup_seg:
152 pushm $0x1000-(SETUP*32)-32
153 popw %es
154 #else // FLAT16
155 # 1- move 9020..9020+unpack -> 0700 and jump into
156 movw $0x700, %cx // Up to 3.5KB for unpacker (unlzma is << 1KB)
157 movw %cx, %es // Use 7000 .. 7E00, keep up to 23 elks setup sectors
158 pushw %es
159 xorw %di, %di // %ds:%si = 9000:0000 %es:%di = 0700:0000
160 pushm $0x200+cont
161 # if SAVEREGS
162 rep
163 movsw
164 lret
165 # else
166 jmp jumpinto
167 # endif
168 cont:
169 # 2- move 9020..9020+stp -> 9000-sys-stp
170 movw %ds, %dx
171 setup_byte:
172 movb $SETUP+1, %ch
173 setup_para:
174 subw $SETUP*32+32+0xF000, %dx
175 packed_syssize:
176 movw $0+0x1000, %ax
177 pushw %cx // <B> bootsector+setup words
178 subw %ax, %dx
179 movw %dx, %es
180 pushw %es // <C> 9000-sys-stp
181 xorw %si, %si
182 xorw %di, %di // %ds:%si = 9000:0 %es:%di = 9000-sys-stp:0
183 rep
184 movsw
185 # 3- move 1000..1000+sys -> 9000-sys
186 movw %ds, %dx
187 mvsys:
188 decw %ax
189 decw %dx
190 movw %ax, %ds
191 movw %dx, %es
192 xorw %si, %si
193 xorw %di, %di
194 movw $8, %cx
195 rep
196 movsw
197 cmpw $0x1000, %ax
198 jne mvsys
199 # 4- unlz(9000-sys-stp:end, 1000-stp:0)
200 setup_seg:
201 pushm $0x1000-(SETUP*32)-32
202 popw %es
203 #endif // FLAT16
204 popw %ds // <C>
205 #if FLAT16 && SAVEREGS == 0
206 movw $end-_start, %si // %ds:%si = TOPSSEG:compressed
207 #else
208 movw $0x200+end-_start, %si // %ds:%si = 9000-sys-stp:compressed
209 #endif
210 #if KEEP_BOOTSECTOR
211 setup_keep:
212 xorw %di, %di
213 #else
214 # if UPDATE_SYSSIZE
215 setup_syssize:
216 movw $0x1F4, %di // %es:%di = 1000-setup-bootsector:SYSSIZE
217 # else
218 movw $0x200, %di
219 # endif
220 #endif
221 pushw %di
222 pushw %es
223 #if DOUBLE_PACKED
224 double_packed:
225 pushm $0x4000
226 popw %es
227 pushw %di
228 pushw %es
229 call unpack
230 popw %ds
231 popw %si
232 popw %es
233 popw %di
234 pushw %di
235 pushw %es
236 #endif
237 call unpack
238 #if COPYTOHIGHMEM
239 # if FLAT16OUT
240 movw $0x9310+1, %ax // from 1000:FFFF
241 # else
242 # if 0
243 movw %es, %ax
244 shrw $12, %ax
245 orw $0x9310, %ax
246 # else
247 movw $0x9310+7, %ax // from 7000:FFFF
248 # endif
249 # endif
250 pushw %ss
251 popw %es
252 movw $8, %cx
253 zero1:
254 pushw $0 // 2E..20
255 loop zero1
256 src:
257 pushw %cx // 1E, 16
258 pushw %ax // 1A: dst %ax:%cx, 12: src %ax:%cx
259 pushw %cx
260 pushw $-1 // 18, 10: full 64K segment
261 subb $0x10, %al
262 jnc src
263 movb $8, %cl
264 zero2:
265 pushw $0 // 0E..00
266 loop zero2
267 movw %sp, %si
268 syslp:
269 movb $0x80, %ch
270 movb $0x87, %ah
271 int $0x15
272 # if FLAT16OUT == 0
273 decb %es:0x1C(%si)
274 decb %es:0x14(%si)
275 jne syslp // down to 1000:0000
276 # endif
277 addw $0x30, %sp
278 #endif // COPYTOHIGHMEM
279 popw %ds
280 popw %si // %ds:%si = 1000-setup-bootsector:SYSSIZE / 0
281 #if UPDATE_CODE32_START
282 update_code32_start:
283 // movb $1, 0x216
284 #endif
285 #if FLAT16 == 0 || SAVEREGS
286 popw %cx // <B> bootsector+setup words
287 #endif
288 popw %es // <A> bootsector+setup segment
289 movw %si, %di
290 jumpinto:
291 #if FLAT16 && SAVEREGS == 0
292 setup_word:
293 movw $SETUP*256+256, %cx
294 #endif
295 # 5- move 1000-stp..1000 -> 9000
296 rep
297 movsw
298 #if SAVEREGS
299 popw %es
300 popw %ds
301 popam
302 iret
303 #else
304 lret
305 #endif
307 unpack:
308 #define NO_LZMA_HEADER
309 #define NO_LZSA2_HEADER
310 #define NO_LZSA1_HEADER
311 #define NO_LZ4_HEADER
312 #if ELKS
313 #define ONLY8086 1
314 #endif
315 #if defined(FLAT16OUT) && FLAT16OUT == 0
316 #undef FLAT16OUT
317 #endif
318 #if defined(FLAT16) && FLAT16 == 0
319 #undef FLAT16
320 #endif
321 #include "uncompress.S"
323 end: