wok-tiny view x86test/stuff/unpack.S @ rev 172

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