wok view memtest/stuff/unpack.S @ rev 25492

Up foomatic-db (4.0-20221117)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Nov 18 09:54:27 2022 +0000 (17 months ago)
parents 608a017317a8
children 7f7bd3c9775e
line source
1 #define SYSTEM 0x10000
2 #define SETUP 14
3 #define SYSSIZE 0x1F4
4 #define SETUPSIZE 0x1F1
6 #define LINUX_HEADER 0
7 #define UPDATE_SYSSIZE 1
8 #define HARDCODED_SYSSIZE 1
9 #define HARDCODED_SETUPSIZE 1
10 #define FLAT16 1 // lzma case
11 //#define FLAT16OUT 0
12 #define SAVEREGS 0
13 #define ELKS 0
15 .text
16 .code16
17 .org 0
19 #if ELKS
20 .arch i8086
21 #define FLAT16 1
22 #define LINUX_HEADER 0
23 #define SAVEREGS 0
24 #define TOPSEG 0x2000
25 #else
26 #define TOPSEG 0x8000
27 #endif
29 .globl _start
30 _start:
31 #if LINUX_HEADER
32 jmp start2
33 .ascii "HdrS" // 202 magic
34 .word 0x200 // 206 version 2.00
35 .long 0 // 208 realmode_swtch
36 .word SYSTEM/16 // 20C start_sys_seg
37 .word 0 // 20E kernel_version
38 .byte 0 // 210 type_of_loader
39 .byte 0 // 211 loadflags
40 .word 0 // 212 setup_move_size
41 .long SYSTEM // 214 code32_start
42 .long 0 // 218 ramdisk_image
43 .long 0 // 21C ramdisk_size
44 .long 0 // 220 bootsect_kludge
45 start2:
46 #endif
47 #if SAVEREGS
48 pushfw
49 pushw %cs
50 pushw $0
51 pushal
52 pushw %ds
53 cld
54 #else
55 pushw %cs // return adress is %cs:0
56 # if FLAT16
57 xorw %di, %di
58 pushw %di
59 # else
60 pushw $0
61 # endif
62 #endif
63 #if ELKS
64 movw $0x100, %ax
65 pushw %ax
66 #else
67 # if UPDATE_SYSSIZE
68 pushw %ds // <A>
69 # else
70 pushw %cs // <A>
71 # endif
72 #endif
73 #if FLAT16
74 # 1- move 9020..9020+stp -> TOPSEG
75 # if ELKS
76 movb $TOPSEG/256, %ah
77 movw %ax, %es
78 # else
79 pushw $TOPSEG
80 popw %es // %es:%di = TOPSEG:0
81 # endif
82 movw $0x200, %si // %ds:%si = 9000:0200
83 # if SAVEREGS == 0
84 pushw %es
85 call jumpinto // move setup & jmp %es:cont
86 # else
87 # if HARDCODED_SETUPSIZE
88 setup_word:
89 movw $SETUP*256, %cx
90 # else
91 xorw %cx, %cx
92 movb SETUPSIZE, %ch
93 movw %cx, %dx
94 # endif
95 pushw %cx // <B>
96 pushw %es
97 pushw %di
98 rep
99 movsw
100 lret
101 # endif
102 cont:
103 # 2- move 1000..1000+sys -> TOPSEG+stp
104 # if ELKS
105 movw $0x1000, %ax
106 movw %ax, %ds
107 # else
108 pushw $0x1000
109 popw %ds
110 # endif
111 xorw %si, %si // %ds:%si = 1000:0
112 subw %di, %cx // %cx = 64K - setupsz
113 rep
114 movsb
115 # 3- unlz(TOPSEG+stp:end, 1000-stp:0)
116 pushw %es // <C>
117 # if HARDCODED_SETUPSIZE
118 setup_seg:
119 # if ELKS
120 # if UPDATE_SYSSIZE
121 movw $0x1000-(SETUP*32)-32, %ax
122 # else
123 movw $0x1000-(SETUP*32), %ax
124 # endif
125 movw %ax, %es
126 # else
127 # if UPDATE_SYSSIZE
128 pushw $0x1000-(SETUP*32)-32
129 # else
130 pushw $0x1000-(SETUP*32)
131 # endif
132 popw %es
133 # endif
134 # else
135 # if UPDATE_SYSSIZE
136 incb %dh
137 # endif
138 # if ELKS
139 shrw $1, %dx
140 shrw $1, %dx
141 shrw $1, %dx
142 # else
143 shrw $3, %dx
144 # endif
145 movw %ds, %ax
146 subw %dx, %ax
147 movw %ax, %es
148 # endif
149 # else // FLAT16
150 # 1- move 1000..1000+sys -> 9000-sys
151 # if HARDCODED_SYSSIZE
152 packed_syssize:
153 movw $0x1000+0, %ax
154 # else
155 movw SYSSIZE, %ax
156 addw $0x1000, %ax
157 # endif
158 movw %ds, %dx
159 mvsys:
160 decw %ax
161 decw %dx
162 movw %ax, %ds
163 movw %dx, %es
164 xorw %si, %si
165 xorw %di, %di
166 movw $8, %cx
167 rep
168 movsw
169 cmpw $0x1000, %ax
170 jne mvsys
171 # 2- move 9020..9020+stp -> 9000-sys-stp
173 # if HARDCODED_SETUPSIZE
174 setup_byte:
175 movb $SETUP, %ch
176 setup_para:
177 subw $SETUP*32, %dx
178 # else
179 movb %ss:SETUPSIZE, %ch
180 movw %cx, %ax
181 # if ELKS
182 shrw $1, %ax
183 shrw $1, %ax
184 shrw $1, %ax
185 # else
186 shrw $3, %ax
187 # endif
188 subw %ax, %dx
189 # endif
190 # if SAVEREGS != 0
191 pushw %cx // <B>
192 # endif
193 movw %dx, %es
194 xorw %si, %si // %cs:%si = 9020:0
195 xorw %di, %di // %es:%di = 9000-sys-stp:0
196 rep
197 movsw %cs:(%si),%es:(%di)
198 pushw %es // <C>
199 # 3- reloc itself in 0x7C00
200 pushw $0x07C0
201 popw %es
202 movw $cont, %si // %cs:%si = 9020:cont
203 movw %si, %di // %es:%di = 7C0:cont
204 movw $end-_start, %cx
205 pushw %es
206 pushw %di
207 rep
208 movsb %cs:(%si),%es:(%di)
209 lret
210 cont:
211 # 4- unlz(9000-sys-stp:end, 1000-stp:0)
212 # if HARDCODED_SETUPSIZE
213 setup_seg:
214 # if UPDATE_SYSSIZE
215 pushw $0x1000-(SETUP*32)-32
216 # else
217 pushw $0x1000-(SETUP*32)
218 # endif
219 popw %es
220 # else
221 negw %ax
222 # if UPDATE_SYSSIZE
223 addw $0x1000-32, %ax
224 # else
225 addw $0x1000, %ax
226 # endif
227 movw %ax, %es
228 # endif
229 #endif // FLAT16
230 popw %ds // <C>
231 movw $end-_start, %si // %ds:%si = TOPSSEG:compressed / 9000-sys-stp:compressed
232 #if UPDATE_SYSSIZE
233 movw $SYSSIZE, %di // %es:%di = 1000-setup-bootsector:SYSSIZE
234 #else
235 xorw %di, %di
236 #endif
237 pushw %di
238 pushw %es
239 call unpack
240 popw %ds
241 popw %si // %ds:%si = 1000-setup-bootsector:SYSSIZE
242 movw %si, %di
243 # if SAVEREGS != 0
244 popw %cx // <B>
245 #if UPDATE_SYSSIZE
246 // not need with memtest movb $(512-SYSSIZE)/2, %cl
247 #endif
248 popw %es // <A>
249 # 5- move 1000-stp..1000 -> 9020
250 # else
251 popw %es // <A> %es:%di = 9000:SYSSIZE (the last 12 bytes are missing)
252 jumpinto:
253 # if HARDCODED_SETUPSIZE
254 setup_word:
255 movw $SETUP*256, %cx
256 # else
257 xorw %cx, %cx
258 movb %ss:SETUPSIZE, %ch
259 movw %cx, %dx
260 # endif
261 # endif
262 rep
263 movsw
264 #if SAVEREGS
265 popw %ds
266 popal
267 iret
268 #else
269 lret
270 #endif
272 unpack:
273 #define NO_LZMA_HEADER
274 #define NO_LZSA2_HEADER
275 #define NO_LZSA1_HEADER
276 #define NO_LZ4_HEADER
277 #if ELKS
278 #define ONLY8086 1
279 #endif
280 #include "uncompress.S"
282 end: