wok-current view memtest/stuff/unpack.S @ rev 19399
memtest: DOS shutdown
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Sep 03 09:48:39 2016 +0200 (2016-09-03) |
parents | 3b334b26197f |
children | fd3dadf90ba9 |
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 FLAT16 1
14 //#define FLAT16OUT 0
16 .text
17 .code16
18 .org 0
20 .globl _start
21 _start:
22 #if LINUX_HEADER
23 jmp start2
24 .ascii "HdrS" // 202 magic
25 .word 0x200 // 206 version 2.00
26 .long 0 // 208 realmode_swtch
27 .word SYSTEM/16 // 20C start_sys_seg
28 .word 0 // 20E kernel_version
29 .byte 0 // 210 type_of_loader
30 .byte 0 // 211 loadflags
31 .word 0 // 212 setup_move_size
32 .long SYSTEM // 214 code32_start
33 .long 0 // 218 ramdisk_image
34 .long 0 // 21C ramdisk_size
35 .long 0 // 220 bootsect_kludge
36 start2:
37 #endif
38 pushf
39 pushw %cs
40 #if HARDCODED_IP
41 pushw $0
42 #else
43 call getip
44 getip:
45 #endif
46 pushal
47 #if !FLAT16
48 #undef FLAT16
49 #if HARDCODED_SYSSIZE
50 packed_syssize:
51 movw $0, %bx // system size
52 #else
53 movw SYSSIZE, %bx
54 #endif
55 #endif
56 #if HARDCODED_SETUPSIZE == 0
57 xorw %dx, %dx
58 movb SETUPSIZE, %dh
59 #endif
60 #if HARDCODED_IP
61 xorw %si, %si
62 #else
63 movw %sp, %bp
64 #define START_IP 32(%bp)
65 subw $getip-_start, START_IP
66 movw START_IP, %si
67 #endif
68 pushw %ds
69 pushw %es
71 cld
73 #if FLAT16
74 flat16mv:
75 #if CHANGE_STACK
76 STKSZ=0x9000-0x0990
77 pushw $(TOP-STKSZ)/16-0x1000
78 #else
79 pushw $TOP/16-0x1000
80 #endif
81 popw %es
82 pushw %es // moved
83 .byte 0x6A, moved-_start // unpack code
84 pushw %cs
85 popw %ds
86 xorw %di, %di
87 #if HARDCODED_SETUPSIZE
88 movw $SETUP*256, %cx
89 #else
90 xorw %cx, %cx
91 movw SETUPSIZE, %ch
92 #endif
93 pushw %si
94 rep
95 movsw // move header part
96 movw $0x1000, %bp
97 movw %bp, %ds
98 xorw %si, %si
99 subw %di, %cx
100 rep
101 movsb // move system part
102 popw %di
103 movw $end-_start, %si
104 #else
105 #if CHANGE_STACK
106 STKSZ=0x9000-0x0990
107 movw $(TOP-STKSZ)/16, %ax
108 #else
109 movw $TOP/16, %ax
110 #endif
111 movw %ax, %es
112 pushw %es // moved
113 .byte 0x6A, moved-_start // unpack code
114 pushw %cs
115 popw %ds
116 xorw %di, %di
117 movw $end-_start, %cx
118 pushw %cx
119 pushw %si
120 rep
121 movsb // move upack code to $TOP
123 leaw SYSTEM/16(%bx), %bp
124 movlp:
125 decw %bp
126 movw %bp, %ds
127 decw %ax
128 movw %ax, %es
129 xorw %si, %si
130 xorw %di, %di
131 movb $8, %cl
132 rep
133 movsw // move system part
134 decw %bx
135 jnz movlp
137 pushw %cs
138 popw %ds
139 popw %si
140 xorw %di, %di
141 #if HARDCODED_SETUPSIZE
142 movb $SETUP, %ch
143 subw $SETUP*32, %ax
144 #else
145 movb %dh, %ch
146 shrw $3, %dx
147 subw %dx, %ax
148 #endif
149 movw %ax, %es
150 pushw %si
151 rep
152 movsw // move header part
153 popw %di
154 popw %si
155 #endif
156 pushw %es
157 popw %ds
158 pushw %cs
159 popw %es // restore setup seg
160 retf
162 moved:
163 #if CHANGE_STACK
164 movw $STKSZ, %ax // trick: %ss = %sp
165 movw %ss, %bx
166 pushw %ax
167 popw %ss
168 xchgw %ax, %sp
169 pushw %bx // %ss
170 pushw %ax // %sp
171 #endif
172 pushw %bp // SYSTEM/16
173 call unpack // unpack setup
174 popw %es
175 xorw %di,%di
176 call unpack // unpack system
177 #if CHANGE_STACK
178 popw %ax // %sp
179 popw %ss
180 xchgw %ax, %sp
181 #endif
182 #if UPDATE_SYSSIZE
183 # if HARDCODED_SYSSIZE
184 original_syssize:
185 movw $0, %ax
186 # else
187 addw $15, %di
188 shrw $4, %di
189 movw %es, %ax
190 addw %di, %ax
191 subw $SYSTEM/16, %ax
192 # endif
193 #endif
194 popw %es
195 popw %ds
196 #if UPDATE_SYSSIZE
197 movw %ax, SYSSIZE
198 # if HARDCODED_SETUPSIZE
199 original_setupsize:
200 movb $4, SETUPSIZE
201 # endif
202 #endif
203 popal
204 iret
206 unpack:
207 #include "unlzma.S"
209 end: