Subversion Repositories Kolibri OS

Rev

Rev 1713 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1713 mario79 1
; do not touch "purge mov"!!!
2
purge mov ; for the correct patch of loader
3
; do not touch "purge mov"!!!
4
;*********************************************************************
5
;die_with_err:
6
;	pop	esi
7
;@@:
8
;	lodsb
9
;	test	al,al
10
;	jz	@f
11
 
12
;	mov	cl,al
13
;	mcall	63,1
14
;	jmp	@b
15
;*********************************************************************
16
;@@:
17
;	mcall	63,,13
18
;	mcall	,,10
19
;	mcall	-1
20
;*********************************************************************
21
kerpack:
22
	call	clear_mess_and_displogo
23
 
9676 leency 24
	mov	ecx,300*1024*3+6A8000h
1713 mario79 25
	mcall	68,12
26
	mov	[infile],eax
27
	mov	[infile3],eax
9676 leency 28
	add	eax,300*1024
1713 mario79 29
	mov	[inbuftmp],eax
9676 leency 30
	add	eax,300*1024
1713 mario79 31
	mov	[outfile],eax
9676 leency 32
	add	eax,300*1024
1713 mario79 33
	mov	[workmem],eax
34
 
35
 
36
	mov	esi,inname
37
	call	get_full_name
38
 
9676 leency 39
	mov	[insize3],300*1024 ; max size of input file
1713 mario79 40
 
41
	mcall	70,fn70_read
42
	cmp	eax,6
43
	jz	read_ok
44
;--------------------------------------
45
read_err:
46
;	call	die_with_err
47
;	db	'KerPack: cannot load kernel.mnt',0
48
	mov	esi,errload_str
49
	push	errload_len
50
	pop	ecx
51
	call	write_string
52
	jmp	read_ok.exit
53
;*********************************************************************
54
read_ok:
55
	mov	[insize3],ebx
56
 
57
	mov	edi,[infile]
58
	add	edi,[insize3]
59
	cmp	dword [edi-8],dword 'KERN'
60
	jnz	.lzma_set_dict_size
61
 
62
	cmp	dword [edi-4],dword 'PACK'
63
	jnz	.lzma_set_dict_size
64
;--------------------------------------
65
	mov	esi,already_str
66
	push	already_len
67
	pop	ecx
68
	call	write_string
69
	jmp	read_ok.exit
70
;*********************************************************************
71
.not_kernel:
72
	mov	esi,notkernel_str
73
	push	notkernel_len
74
	pop	ecx
75
	call	write_string
76
	jmp	read_ok.exit
77
;*********************************************************************
78
.lzma_set_dict_size:
79
	push	18
80
	call	lzma_set_dict_size
81
; find jump to 32-bit code
82
;	mov	edi,infile - 1
83
	mov	edi,[infile]
84
	mov	eax,edi
85
	add	eax,[insize3]
86
	dec	edi
87
;--------------------------------------
88
@@:
89
	cmp	eax,edi
90
	je	.not_kernel
91
 
92
	inc	edi
93
	cmp	dword [edi],0xE88EE08E	 ; mov fs,ax/mov gs,ax
94
	jnz	@b
95
 
96
	cmp	dword [edi+4],0x00BCD08E	; mov ss,ax/mov esp,00xxxxxx
97
	jnz	@b
98
 
99
	add	edi,11
100
	mov	[inptr],edi
101
	sub	edi,[infile]	; infile
102
	mov	[indelta],edi
103
	lea	eax,[ebx+0x10000]
104
	mov	dword [loader_patch3+2],eax
105
	sub	ebx,edi
106
	mov	[insize1],ebx
107
	call	preprocess_calltrick3
108
 
109
	mov	al,[cti]
110
	mov	[loader_patch5-1],al
111
	mov	eax,[ctn]
112
	mov	[loader_patch4+1],eax
113
	mov	eax,[inptr]
114
;	add	eax, outfile - infile + loader_size - 5
115
	add	eax,[outfile]
116
	sub	eax,[infile]
117
	add	eax,loader_size - 5
118
 
119
	push	eax
120
	call	tell_compress_mess
121
	pop	eax
122
 
123
	push	[workmem]	;workmem
124
	push	[insize1]
125
	push	eax
126
	push	[inptr]
127
	call	lzma_compress
128
 
129
	add	eax, loader_size-5
130
	mov	[loader_patch1+6],eax
131
	add	eax,[indelta]
132
	mov	[outsize3],eax
133
	mov	eax,[indelta]
134
;	mov	ecx,dword [eax + outfile + loader_size - 4]
135
	mov	ecx,eax
136
	add	ecx,[outfile]
137
	mov	ecx,[ecx + loader_size - 4]
138
 
139
	bswap	ecx
140
	mov	[loader_patch2+4],ecx
141
	add	eax, 0x10000
142
	mov	[loader_patch1+1],eax
143
	mov	esi,[infile]	;infile
144
	mov	edi,[outfile]	;outfile
145
	mov	ecx,[indelta]
146
	rep	movsb
147
 
148
	mov	esi,loader_start
149
	mov	ecx,loader_size
150
	rep	movsb
151
 
152
	mov	eax,[outfile]
153
	add	eax,[outsize3]
154
	mov	[eax],dword 'KERN'
155
	mov	[eax+4],dword 'PACK'
156
	add	dword [outsize3],8
157
 
158
	mov	eax,[outsize3]
159
	mov	ecx,100
160
	mul	ecx
161
	div	[insize3]
162
	aam
163
	xchg	al,ah
164
	add	ax,'00'
165
	mov	[ratio],ax
166
	mov	esi,done_str
167
	push	done_len
168
	pop	ecx
169
	call	write_string
170
 
171
	mov	eax,[outfile]
172
	mov	[outfile3],eax
173
 
174
	mov	esi,outname
175
	call	get_full_name
176
 
177
	mcall	70,fn70_write
178
	test	eax,eax
179
	jz	.exit	;@f
180
;	call	die_with_err
181
;	db	'KerPack: cannot save kernel.mnt',0
182
 
183
	mov	esi,outfileerr_str
184
	push	outfileerr_len
185
	pop	ecx
186
	call	write_string
187
;*********************************************************************
188
.exit:
189
;	call	die_with_err
190
;	db	'KerPack: all is OK',0
191
	call	return_memory
192
	ret
193
;*********************************************************************
194
preprocess_calltrick3:
195
; input preprocessing
196
	mov	edi,ct1
197
	xor	eax,eax
198
	push	edi
199
	mov	ecx,256/4
200
	rep	stosd
201
 
202
	pop	edi
203
	mov	ecx,ebx
204
	mov	esi,[inptr]
205
	mov	ebx,[inbuftmp]	;inbuftmp
206
	xchg	eax,edx
207
;--------------------------------------
208
input_pre3:
209
	lodsb
210
;--------------------------------------
211
@@:
212
	cmp	al,0Fh
213
	jnz	ip3
214
 
215
	dec	ecx
216
	jz	input_pre_done3
217
 
218
	lodsb
219
	cmp	al,80h
220
	jb	@b
221
 
222
	cmp	al,90h
223
	jb	@f
224
;--------------------------------------
225
ip3:
226
	sub	al,0E8h
227
	cmp	al,1
228
	ja	input_pre_cont3
229
;--------------------------------------
230
@@:
231
	cmp	ecx,5
232
	jb	input_pre_done3
233
 
234
	lodsd
235
	add	eax,esi
236
	sub	eax,[inptr]
237
	cmp	eax,[insize1]
238
	jae	xxx3
239
 
240
	cmp	eax,1000000h
241
	jae	xxx3
242
 
243
	sub	ecx,4
244
	xchg	al,ah
245
	rol	eax,16
246
	xchg	al,ah
247
	mov	[esi-4],eax
248
	inc	edx
249
	mov	[ebx],esi
250
	add	ebx,4
251
	jmp	input_pre_cont3
252
;*********************************************************************
253
xxx3:
254
	sub	esi,4
255
	movzx	eax,byte [esi]
256
	mov	byte [eax+edi],1
257
;--------------------------------------
258
input_pre_cont3:
259
	loop	input_pre3
260
;--------------------------------------
261
input_pre_done3:
262
	mov	[ctn],edx
263
	xor	eax,eax
264
	mov	ecx,256
265
	repnz	scasb
266
	jnz	pack_calltrick_done
267
 
268
	not	cl
269
	mov	[cti],cl
270
;--------------------------------------
271
@@:
272
	cmp	ebx,[inbuftmp]	;inbuftmp
273
	jz	pack_calltrick_done
274
 
275
	sub	ebx,4
276
	mov	eax,[ebx]
277
	mov	[eax-4],cl
278
	jmp	@b
279
;*********************************************************************
280
pack_calltrick_done:
281
	ret
282
;*********************************************************************
283
include 'loader_lzma.inc'
284
;*********************************************************************