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

Up inkscape (0.91) update wget_url
author Yuri Pourre <yuripourre@gmail.com>
date Tue Mar 03 23:37:12 2015 -0300 (2015-03-03)
parents b0e9e83532e2
children 3b334b26197f
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
14 .text
15 .code16
16 .org 0
18 .globl _start
19 _start:
20 #if LINUX_HEADER
21 jmp start2
22 .ascii "HdrS" // 202 magic
23 .word 0x200 // 206 version 2.00
24 .long 0 // 208 realmode_swtch
25 .word SYSTEM/16 // 20C start_sys_seg
26 .word 0 // 20E kernel_version
27 .byte 0 // 210 type_of_loader
28 .byte 0 // 211 loadflags
29 .word 0 // 212 setup_move_size
30 .long SYSTEM // 214 code32_start
31 .long 0 // 218 ramdisk_image
32 .long 0 // 21C ramdisk_size
33 .long 0 // 220 bootsect_kludge
34 start2:
35 #endif
36 pushf
37 pushw %cs
38 #if HARDCODED_IP
39 pushw $0
40 #else
41 call getip
42 getip:
43 #endif
44 pushal
45 #if HARDCODED_SYSSIZE
46 packed_syssize:
47 movw $0, %bx // system size
48 #else
49 movw SYSSIZE, %bx
50 #endif
51 #if HARDCODED_SETUPSIZE == 0
52 xorw %dx, %dx
53 movb SETUPSIZE, %dh
54 #endif
55 #if HARDCODED_IP
56 xorw %si, %si
57 #else
58 movw %sp, %bp
59 #define START_IP 32(%bp)
60 subw $getip-_start, START_IP
61 movw START_IP, %si
62 #endif
63 pushw %ds
64 pushw %es
66 cld
67 #if CHANGE_STACK
68 STKSZ=0x9000-0x0990
69 movw $(TOP-STKSZ)/16, %ax
70 #else
71 movw $TOP/16, %ax
72 #endif
73 movw %ax, %es
74 pushw %es // moved
75 .byte 0x6A, moved-_start // unpack code
76 pushw %cs
77 popw %ds
78 xorw %di, %di
79 movw $end-_start, %cx
80 pushw %si
81 rep
82 movsb // move upack code to $TOP
84 leaw SYSTEM/16(%bx), %bp
85 movlp:
86 decw %bp
87 movw %bp, %ds
88 decw %ax
89 movw %ax, %es
90 xorw %si, %si
91 xorw %di, %di
92 movb $8, %cl
93 rep
94 movsw // move system part
95 decw %bx
96 jnz movlp
98 pushw %cs
99 popw %ds
100 popw %si
101 xorw %di, %di
102 #if HARDCODED_SETUPSIZE
103 movb $SETUP, %ch
104 subw $SETUP*32, %ax
105 #else
106 movb %dh, %ch
107 shrw $3, %dx
108 subw %dx, %ax
109 #endif
110 movw %ax, %es
111 pushw %si
112 rep
113 movsw // move header part
115 pushw %es
116 popw %ds
117 movw $end-_start, %si
118 pushw %cs
119 popw %es // restore setup seg
120 popw %di
121 retf
123 moved:
124 #if CHANGE_STACK
125 movw $STKSZ, %ax // trick: %ss = %sp
126 movw %ss, %bx
127 pushw %ax
128 popw %ss
129 xchgw %ax, %sp
130 pushw %bx // %ss
131 pushw %ax // %sp
132 #endif
133 pushw %bp // SYSTEM/16
134 call unpack // unpack setup
135 popw %es
136 xorw %di,%di
137 call unpack // unpack system
138 #if CHANGE_STACK
139 popw %ax // %sp
140 popw %ss
141 xchgw %ax, %sp
142 #endif
143 #if UPDATE_SYSSIZE
144 # if HARDCODED_SYSSIZE
145 original_syssize:
146 movw $0, %ax
147 # else
148 addw $15, %di
149 shrw $4, %di
150 movw %es, %ax
151 addw %di, %ax
152 subw $SYSTEM/16, %ax
153 # endif
154 #endif
155 popw %es
156 popw %ds
157 #if UPDATE_SYSSIZE
158 movw %ax, SYSSIZE
159 # if HARDCODED_SETUPSIZE
160 original_setupsize:
161 movb $4, SETUPSIZE
162 # endif
163 #endif
164 popal
165 iret
167 unpack:
168 #include "unlzma.S"
170 end: