wok-6.x view memtest/stuff/unpack.S @ rev 19920

memtest: VCPI support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Apr 19 22:14:58 2017 +0200 (2017-04-19)
parents 4ebd023252ac
children 9e463ebef079
line source
1 #define TOP (0x90000+_start-end)
2 #define SYSTEM 0x10000
3 #define SETUP 14
4 #define SYSSIZE 0x1F4
5 #define SETUPSIZE 0x1F1
7 #define LINUX_HEADER 0
8 #define UPDATE_SYSSIZE 1
9 #define HARDCODED_SYSSIZE 1
10 #define HARDCODED_SETUPSIZE 1
11 #define FLAT16 1
12 //#define FLAT16OUT 0
13 #define SAVEREGS 0
14 #define VM2RM 1
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 #if SAVEREGS
39 pushfw
40 pushw %cs
41 pushw $0
42 pushal
43 pushw %ds
44 #else
45 pushw %cs
46 pushw $0
47 #endif
48 #if UPDATE_SYSSIZE
49 pushw %ds
50 #else
51 pushw %es
52 pushw %cs
53 #endif
54 cld
55 #if FLAT16
56 # 1- move 9020..9020+stp -> 8000
57 # if HARDCODED_SETUPSIZE
58 setup_word:
59 movw $SETUP*256, %cx
60 # else
61 xorw %cx, %cx
62 movb SETUPSIZE, %ch
63 movw %cx, %dx
64 # endif
65 pushw %cx
66 pushw $0x8000
67 popw %es
68 xorw %si, %si
69 xorw %di, %di
70 rep
71 movsw %cs:(%si),%es:(%di)
72 pushw %es
73 // pushw $cont
74 .byte 0x6A, cont
75 lret
76 cont:
77 # 2- move 1000..1000+sys -> 8000+stp
78 pushw $0x1000
79 popw %ds
80 xorw %si, %si
81 subw %di, %cx
82 rep
83 movsb
84 # 3- unlz(8000+stp:end, 1000-stp:0)
85 pushw %es
86 # if HARDCODED_SETUPSIZE
87 setup_seg:
88 # if UPDATE_SYSSIZE
89 pushw $0x1000-(SETUP*32)-32
90 # else
91 pushw $0x1000-(SETUP*32)
92 # endif
93 popw %es
94 # else
95 # if UPDATE_SYSSIZE
96 incb %dh
97 # endif
98 shrw $3, %dx
99 movw %ds, %ax
100 subw %dx, %ax
101 movw %ax, %es
102 # endif
103 #else
104 # 1- move 1000..1000+sys -> 9000-sys
105 # if HARDCODED_SYSSIZE
106 packed_syssize:
107 movw $0x1000+0, %ax
108 # else
109 movw SYSSIZE, %ax
110 addw $0x1000, %ax
111 # endif
112 movw %ds, %dx
113 mvsys:
114 decw %ax
115 decw %dx
116 movw %ax, %ds
117 movw %dx, %es
118 xorw %si, %si
119 xorw %di, %di
120 movw $8, %cx
121 rep
122 movsw
123 cmpw $0x1000, %ax
124 jne mvsys
125 # 2- move 9020..9020+stp -> 9000-sys-stp
127 # if HARDCODED_SETUPSIZE
128 setup_byte:
129 movb $SETUP, %ch
130 setup_para:
131 subw $SETUP*32, %dx
132 # else
133 movb %ss:SETUPSIZE, %ch
134 movw %cx, %ax
135 shrw $3, %ax
136 subw %ax, %dx
137 # endif
138 pushw %cx
139 movw %dx, %es
140 xorw %si, %si
141 xorw %di, %di
142 rep
143 movsw %cs:(%si),%es:(%di)
144 pushw %es
145 # 3- reloc itself in 0x7C00
146 pushw $0x07C0
147 popw %es
148 xorw %si, %si
149 xorw %di, %di
150 movw $end-_start, %cx
151 rep
152 movsb %cs:(%si),%es:(%di)
153 pushw %es
154 // pushw $cont
155 .byte 0x6A, cont
156 lret
157 cont:
158 # 4- unlz(9000-sys-stp:end, 1000-stp:0)
159 # if HARDCODED_SETUPSIZE
160 setup_seg:
161 # if UPDATE_SYSSIZE
162 pushw $0x1000-(SETUP*32)-32
163 # else
164 pushw $0x1000-(SETUP*32)
165 # endif
166 popw %es
167 # else
168 negw %ax
169 # if UPDATE_SYSSIZE
170 addw $0x1000-32, %ax
171 # else
172 addw $0x1000, %ax
173 # endif
174 movw %ax, %es
175 # endif
176 #endif
177 popw %ds
178 movw $end-_start, %si
179 #if UPDATE_SYSSIZE
180 movw $SYSSIZE, %di
181 #else
182 xorw %di, %di
183 #endif
184 pushw %di
185 pushw %es
186 call unpack
187 popw %ds
188 popw %si
189 movw %si, %di
190 popw %cx
191 #if UPDATE_SYSSIZE
192 // not need with memtest movb $(512-SYSSIZE)/2, %cl
193 #endif
194 popw %es
195 # 5- move 1000-stp..1000 -> 9020
196 rep
197 movsw
198 #if UPDATE_SYSSIZE == 0
199 popw %es
200 #endif
201 #if SAVEREGS
202 popw %ds
203 popal
204 iret
205 #else
206 lret
207 #endif
209 #if VM2RM
210 #define EXEADRS(x) (x+0x2E0)
211 #define BOOTEXEADRS(x) (x+0xE0)
212 vm2rm:
213 pagebuf = 0x96000
214 gdt_abs = 0x18e // see bootloader.lst
215 sw2pm_params = gdt_abs+30
216 sw2pm_cr3 = sw2pm_params
217 sw2pm_idtr_ptr = sw2pm_params+8
218 saved_ss_sp = gdt_abs-44
219 saved_sp = gdt_abs-44
220 saved_ss = gdt_abs-42
221 tss = gdt_abs-40
222 gdt = gdt_abs-32
223 gdt_null = gdt_abs-32
224 gdt_vcpi = gdt_abs-24
225 gdt_vcpi2 = gdt_abs-16
226 gdt_vcpi3 = gdt_abs-8
227 gdt_code_base = gdt_abs+10
228 fixuprange = 0x20
229 pushaw
230 pushw %es
231 pushw %ds
232 movl %cs,%edx
233 shll $4,%edx
234 movw $BOOTEXEADRS(gdt_vcpi),%si
235 movw $-fixuprange,%bx
236 addl %edx,sw2pm_idtr_ptr-gdt_vcpi(%si)
237 fixup:
238 addl %edx,fixuprange+gdt_code_base-gdt_vcpi(%bx,%si)
239 addw $8,%bx
240 jne fixup
241 pushw $pagebuf/16
242 popw %es
243 movl $pagebuf+3,%es:0x1000
244 xorw %di,%di
245 movw $0xDE01,%ax // EBX = getiface(DS:SI, ES:DI)
246 int $0x67
247 movw $BOOTEXEADRS(saved_sp),%bx
248 movw %ss,2(%bx)
249 movw %sp,(%bx)
250 leal BOOTEXEADRS(sw2pm_params)(%edx),%esi
251 movw $0xDE0C, %ax // switchpm(ESI)
252 cli
253 int $0x67
254 pm_code:
255 movl %cr0,%eax
256 andl $0x7FFFFFFE,%eax
257 movl %eax,%cr0
258 movl %eax,%cr3
259 lssw %cs:(%bx),%sp
260 popw %ds
261 popw %es
262 popaw
263 retf
264 #endif
266 unpack:
267 #define NO_LZMA_HEADER
268 #include "unlzma.S"
270 end: