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

memtest: tiny shrink
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Aug 27 12:07:37 2016 +0200 (2016-08-27)
parents b6771e9696d7
children ebf8313df61f
line source
1 #define TOP (0x90000+_start-end)
2 #define SYSTEM 0x10000
3 #define SETUP 4
4 #define SYSSIZE 0x1F4
5 #define SETUPSIZE 0x1F1
7 #define CHANGE_STACK 0
8 #define LINUX_HEADER 0
9 #define UPDATE_SYSSIZE 1
10 #define HARDCODED_SYSSIZE 1
11 #define HARDCODED_SETUPSIZE 1
12 #define HARDCODED_IP 1
13 #define SHUTDOWNDOS 0
14 #define FLAT16 1
15 //#define FLAT16OUT 0
17 .text
18 .code16
19 .org 0
21 .globl _start
22 _start:
23 #if LINUX_HEADER
24 jmp start2
25 .ascii "HdrS" // 202 magic
26 .word 0x200 // 206 version 2.00
27 .long 0 // 208 realmode_swtch
28 .word SYSTEM/16 // 20C start_sys_seg
29 .word 0 // 20E kernel_version
30 .byte 0 // 210 type_of_loader
31 .byte 0 // 211 loadflags
32 .word 0 // 212 setup_move_size
33 .long SYSTEM // 214 code32_start
34 .long 0 // 218 ramdisk_image
35 .long 0 // 21C ramdisk_size
36 .long 0 // 220 bootsect_kludge
37 start2:
38 #endif
39 pushf
40 pushw %cs
41 #if HARDCODED_IP
42 pushw $0
43 #else
44 call getip
45 getip:
46 #endif
47 pushal
48 #if SHUTDOWNDOS
49 xorw %si, %si
50 movw %si, %ds # %ds = 0
51 pushl 4(%si)
52 movw %sp, %cs:loadsp19+1(%si)
53 cmpb $0xF0, 7(%si)
54 jnb notdos
55 movw $step19, 4(%si)
56 movw %cs, 6(%si)
57 pushfw
58 popw %ax
59 incb %ah # set TF
60 pushw %ax
61 popfw
62 ljmp *4*0x19(%si)
63 step19:
64 pushw %si
65 pushw %ds
66 movw %sp, %si
67 ldsw %ss:4(%si), %si
68 cmpw $0x19CD, (%si)
69 popw %ds
70 popw %si
71 jne doiret
72 xorw %si, %si
73 mov %si, %ds
74 popl 4*0x19(%si)
75 notdos:
76 loadsp19:
77 movw $0, %sp
78 popl 4(%si)
79 pushw %ss
80 popw %ds
81 #endif
82 #if !FLAT16
83 #undef FLAT16
84 #if HARDCODED_SYSSIZE
85 packed_syssize:
86 movw $0, %bx // system size
87 #else
88 movw SYSSIZE, %bx
89 #endif
90 #endif
91 #if HARDCODED_SETUPSIZE == 0
92 xorw %dx, %dx
93 movb SETUPSIZE, %dh
94 #endif
95 #if HARDCODED_IP
96 xorw %si, %si
97 #else
98 movw %sp, %bp
99 #define START_IP 32(%bp)
100 subw $getip-_start, START_IP
101 movw START_IP, %si
102 #endif
103 pushw %ds
104 pushw %es
106 cld
108 #if FLAT16
109 flat16mv:
110 #if CHANGE_STACK
111 STKSZ=0x9000-0x0990
112 pushw $(TOP-STKSZ)/16-0x1000
113 #else
114 pushw $TOP/16-0x1000
115 #endif
116 popw %es
117 pushw %es // moved
118 .byte 0x6A, moved-_start // unpack code
119 pushw %cs
120 popw %ds
121 xorw %di, %di
122 #if HARDCODED_SETUPSIZE
123 movw $SETUP*256, %cx
124 #else
125 xorw %cx, %cx
126 movw SETUPSIZE, %ch
127 #endif
128 pushw %si
129 rep
130 movsw // move header part
131 movw $0x1000, %bp
132 movw %bp, %ds
133 xorw %si, %si
134 subw %di, %cx
135 rep
136 movsb // move system part
137 popw %di
138 movw $end-_start, %si
139 #else
140 #if CHANGE_STACK
141 STKSZ=0x9000-0x0990
142 movw $(TOP-STKSZ)/16, %ax
143 #else
144 movw $TOP/16, %ax
145 #endif
146 movw %ax, %es
147 pushw %es // moved
148 .byte 0x6A, moved-_start // unpack code
149 pushw %cs
150 popw %ds
151 xorw %di, %di
152 movw $end-_start, %cx
153 pushw %cx
154 pushw %si
155 rep
156 movsb // move upack code to $TOP
158 leaw SYSTEM/16(%bx), %bp
159 movlp:
160 decw %bp
161 movw %bp, %ds
162 decw %ax
163 movw %ax, %es
164 xorw %si, %si
165 xorw %di, %di
166 movb $8, %cl
167 rep
168 movsw // move system part
169 decw %bx
170 jnz movlp
172 pushw %cs
173 popw %ds
174 popw %si
175 xorw %di, %di
176 #if HARDCODED_SETUPSIZE
177 movb $SETUP, %ch
178 subw $SETUP*32, %ax
179 #else
180 movb %dh, %ch
181 shrw $3, %dx
182 subw %dx, %ax
183 #endif
184 movw %ax, %es
185 pushw %si
186 rep
187 movsw // move header part
188 popw %di
189 popw %si
190 #endif
191 pushw %es
192 popw %ds
193 pushw %cs
194 popw %es // restore setup seg
195 retf
197 moved:
198 #if CHANGE_STACK
199 movw $STKSZ, %ax // trick: %ss = %sp
200 movw %ss, %bx
201 pushw %ax
202 popw %ss
203 xchgw %ax, %sp
204 pushw %bx // %ss
205 pushw %ax // %sp
206 #endif
207 pushw %bp // SYSTEM/16
208 call unpack // unpack setup
209 popw %es
210 xorw %di,%di
211 call unpack // unpack system
212 #if CHANGE_STACK
213 popw %ax // %sp
214 popw %ss
215 xchgw %ax, %sp
216 #endif
217 #if UPDATE_SYSSIZE
218 # if HARDCODED_SYSSIZE
219 original_syssize:
220 movw $0, %ax
221 # else
222 addw $15, %di
223 shrw $4, %di
224 movw %es, %ax
225 addw %di, %ax
226 subw $SYSTEM/16, %ax
227 # endif
228 #endif
229 popw %es
230 popw %ds
231 #if UPDATE_SYSSIZE
232 movw %ax, SYSSIZE
233 # if HARDCODED_SETUPSIZE
234 original_setupsize:
235 movb $4, SETUPSIZE
236 # endif
237 #endif
238 popal
239 iret
241 unpack:
242 #include "unlzma.S"
244 end: