~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to grub-core/kern/i386/pc/lzma_decode.S

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  GRUB  --  GRand Unified Bootloader
 
3
 *  Copyright (C) 2008  Free Software Foundation, Inc.
 
4
 *
 
5
 *  GRUB is free software: you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation, either version 3 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  GRUB is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#define FIXED_PROPS
 
20
 
 
21
#define LZMA_BASE_SIZE 1846
 
22
#define LZMA_LIT_SIZE 768
 
23
 
 
24
#define LZMA_PROPERTIES_SIZE 5
 
25
 
 
26
#define kNumTopBits 24
 
27
#define kTopValue (1 << kNumTopBits)
 
28
 
 
29
#define kNumBitModelTotalBits 11
 
30
#define kBitModelTotal (1 << kNumBitModelTotalBits)
 
31
#define kNumMoveBits 5
 
32
 
 
33
 
 
34
#define kNumPosBitsMax 4
 
35
#define kNumPosStatesMax (1 << kNumPosBitsMax)
 
36
 
 
37
#define kLenNumLowBits 3
 
38
#define kLenNumLowSymbols (1 << kLenNumLowBits)
 
39
#define kLenNumMidBits 3
 
40
#define kLenNumMidSymbols (1 << kLenNumMidBits)
 
41
#define kLenNumHighBits 8
 
42
#define kLenNumHighSymbols (1 << kLenNumHighBits)
 
43
 
 
44
#define LenChoice 0
 
45
#define LenChoice2 (LenChoice + 1)
 
46
#define LenLow (LenChoice2 + 1)
 
47
#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
 
48
#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
 
49
#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
 
50
 
 
51
 
 
52
#define kNumStates 12
 
53
#define kNumLitStates 7
 
54
 
 
55
#define kStartPosModelIndex 4
 
56
#define kEndPosModelIndex 14
 
57
#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
 
58
 
 
59
#define kNumPosSlotBits 6
 
60
#define kNumLenToPosStates 4
 
61
 
 
62
#define kNumAlignBits 4
 
63
#define kAlignTableSize (1 << kNumAlignBits)
 
64
 
 
65
#define kMatchMinLen 2
 
66
 
 
67
#define IsMatch 0
 
68
#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
 
69
#define IsRepG0 (IsRep + kNumStates)
 
70
#define IsRepG1 (IsRepG0 + kNumStates)
 
71
#define IsRepG2 (IsRepG1 + kNumStates)
 
72
#define IsRep0Long (IsRepG2 + kNumStates)
 
73
#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
 
74
#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
 
75
#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
 
76
#define LenCoder (Align + kAlignTableSize)
 
77
#define RepLenCoder (LenCoder + kNumLenProbs)
 
78
#define Literal (RepLenCoder + kNumLenProbs)
 
79
 
 
80
#define out_size        8(%ebp)
 
81
 
 
82
#define now_pos         -4(%ebp)
 
83
#define prev_byte       -8(%ebp)
 
84
#define range           -12(%ebp)
 
85
#define code            -16(%ebp)
 
86
#define state           -20(%ebp)
 
87
#define rep0            -24(%ebp)
 
88
#define rep1            -28(%ebp)
 
89
#define rep2            -32(%ebp)
 
90
#define rep3            -36(%ebp)
 
91
 
 
92
#ifdef FIXED_PROPS
 
93
 
 
94
#define FIXED_LC        3
 
95
#define FIXED_LP        0
 
96
#define FIXED_PB        2
 
97
 
 
98
#define POS_STATE_MASK  ((1 << (FIXED_PB)) - 1)
 
99
#define LIT_POS_MASK    ((1 << (FIXED_LP)) - 1)
 
100
 
 
101
#define LOCAL_SIZE      36
 
102
 
 
103
#else
 
104
 
 
105
#define lc              (%ebx)
 
106
#define lp              4(%ebx)
 
107
#define pb              8(%ebx)
 
108
#define probs           12(%ebx)
 
109
 
 
110
#define pos_state_mask  -40(%ebp)
 
111
#define lit_pos_mask    -44(%ebp)
 
112
 
 
113
#define LOCAL_SIZE      44
 
114
 
 
115
#endif
 
116
 
 
117
RangeDecoderBitDecode:
 
118
#ifdef FIXED_PROPS
 
119
        leal    (%ebx, %eax, 4), %eax
 
120
#else
 
121
        shll    $2, %eax
 
122
        addl    probs, %eax
 
123
#endif
 
124
 
 
125
        movl    %eax, %ecx
 
126
        movl    (%ecx), %eax
 
127
 
 
128
        movl    range, %edx
 
129
        shrl    $kNumBitModelTotalBits, %edx
 
130
        mull    %edx
 
131
 
 
132
        cmpl    code, %eax
 
133
        jbe     1f
 
134
 
 
135
        movl    %eax, range
 
136
        movl    $kBitModelTotal, %edx
 
137
        subl    (%ecx), %edx
 
138
        shrl    $kNumMoveBits, %edx
 
139
        addl    %edx, (%ecx)
 
140
        clc
 
141
3:
 
142
        pushf
 
143
        cmpl    $kTopValue, range
 
144
        jnc     2f
 
145
        shll    $8, code
 
146
        lodsb
 
147
        movb    %al, code
 
148
        shll    $8, range
 
149
2:
 
150
        popf
 
151
        ret
 
152
1:
 
153
        subl    %eax, range
 
154
        subl    %eax, code
 
155
        movl    (%ecx), %edx
 
156
        shrl    $kNumMoveBits, %edx
 
157
        subl    %edx, (%ecx)
 
158
        stc
 
159
        jmp     3b
 
160
 
 
161
RangeDecoderBitTreeDecode:
 
162
RangeDecoderReverseBitTreeDecode:
 
163
        movzbl  %cl, %ecx
 
164
        xorl    %edx, %edx
 
165
        pushl   %edx
 
166
        incl    %edx
 
167
        pushl   %edx
 
168
 
 
169
1:
 
170
        pushl   %eax
 
171
        pushl   %ecx
 
172
        pushl   %edx
 
173
 
 
174
        addl    %edx, %eax
 
175
        call    RangeDecoderBitDecode
 
176
 
 
177
        popl    %edx
 
178
        popl    %ecx
 
179
 
 
180
        jnc     2f
 
181
        movl    4(%esp), %eax
 
182
        orl     %eax, 8(%esp)
 
183
        stc
 
184
 
 
185
2:
 
186
        adcl    %edx, %edx
 
187
        popl    %eax
 
188
 
 
189
        shll    $1, (%esp)
 
190
        loop    1b
 
191
 
 
192
        popl    %ecx
 
193
        subl    %ecx, %edx              /* RangeDecoderBitTreeDecode */
 
194
        popl    %ecx                    /* RangeDecoderReverseBitTreeDecode */
 
195
        ret
 
196
 
 
197
LzmaLenDecode:
 
198
        pushl   %eax
 
199
        addl    $LenChoice, %eax
 
200
        call    RangeDecoderBitDecode
 
201
        popl    %eax
 
202
        jc      1f
 
203
        pushl   $0
 
204
        movb    $kLenNumLowBits, %cl
 
205
        addl    $LenLow, %eax
 
206
2:
 
207
        movl    12(%esp), %edx
 
208
        shll    %cl, %edx
 
209
        addl    %edx, %eax
 
210
3:
 
211
 
 
212
        call    RangeDecoderBitTreeDecode
 
213
        popl    %eax
 
214
        addl    %eax, %edx
 
215
        ret
 
216
 
 
217
1:
 
218
        pushl   %eax
 
219
        addl    $LenChoice2, %eax
 
220
        call    RangeDecoderBitDecode
 
221
        popl    %eax
 
222
        jc      1f
 
223
        pushl   $kLenNumLowSymbols
 
224
        movb    $kLenNumMidBits, %cl
 
225
        addl    $LenMid, %eax
 
226
        jmp     2b
 
227
 
 
228
1:
 
229
        pushl   $(kLenNumLowSymbols + kLenNumMidSymbols)
 
230
        addl    $LenHigh, %eax
 
231
        movb    $kLenNumHighBits, %cl
 
232
        jmp     3b
 
233
 
 
234
WriteByte:
 
235
        movb    %al, prev_byte
 
236
        stosb
 
237
        incl    now_pos
 
238
        ret
 
239
 
 
240
/*
 
241
 * int LzmaDecode(CLzmaDecoderState *vs,
 
242
 *                const unsigned char *inStream,
 
243
 *                unsigned char *outStream,
 
244
 *                SizeT outSize);
 
245
 */
 
246
 
 
247
_LzmaDecodeA:
 
248
 
 
249
        pushl   %ebp
 
250
        movl    %esp, %ebp
 
251
        subl    $LOCAL_SIZE, %esp
 
252
 
 
253
#ifndef ASM_FILE
 
254
        pushl   %esi
 
255
        pushl   %edi
 
256
        pushl   %ebx
 
257
 
 
258
        movl    %eax, %ebx
 
259
        movl    %edx, %esi
 
260
        pushl   %ecx
 
261
#else
 
262
        pushl   %edi
 
263
#endif
 
264
 
 
265
        cld
 
266
 
 
267
#ifdef FIXED_PROPS
 
268
        movl    %ebx, %edi
 
269
        movl    $(Literal + (LZMA_LIT_SIZE << (FIXED_LC + FIXED_LP))), %ecx
 
270
#else
 
271
        movl    $LZMA_LIT_SIZE, %eax
 
272
        movb    lc, %cl
 
273
        addb    lp, %cl
 
274
        shll    %cl, %eax
 
275
        addl    $Literal, %eax
 
276
        movl    %eax, %ecx
 
277
        movl    probs, %edi
 
278
#endif
 
279
 
 
280
        movl    $(kBitModelTotal >> 1), %eax
 
281
 
 
282
        rep
 
283
        stosl
 
284
 
 
285
        popl    %edi
 
286
 
 
287
        xorl    %eax, %eax
 
288
        movl    %eax, now_pos
 
289
        movl    %eax, prev_byte
 
290
        movl    %eax, state
 
291
 
 
292
        incl    %eax
 
293
        movl    %eax, rep0
 
294
        movl    %eax, rep1
 
295
        movl    %eax, rep2
 
296
        movl    %eax, rep3
 
297
 
 
298
#ifndef FIXED_PROPS
 
299
        movl    %eax, %edx
 
300
        movb    pb, %cl
 
301
        shll    %cl, %edx
 
302
        decl    %edx
 
303
        movl    %edx, pos_state_mask
 
304
 
 
305
        movl    %eax, %edx
 
306
        movb    lp, %cl
 
307
        shll    %cl, %edx
 
308
        decl    %edx
 
309
        movl    %edx, lit_pos_mask;
 
310
#endif
 
311
 
 
312
        /* RangeDecoderInit */
 
313
        negl    %eax
 
314
        movl    %eax, range
 
315
 
 
316
        incl    %eax
 
317
        movb    $5, %cl
 
318
 
 
319
1:
 
320
        shll    $8, %eax
 
321
        lodsb
 
322
        loop    1b
 
323
 
 
324
        movl    %eax, code
 
325
 
 
326
lzma_decode_loop:
 
327
        movl    now_pos, %eax
 
328
        cmpl    out_size, %eax
 
329
 
 
330
        jb      1f
 
331
 
 
332
#ifndef ASM_FILE
 
333
        xorl    %eax, %eax
 
334
 
 
335
        popl    %ebx
 
336
        popl    %edi
 
337
        popl    %esi
 
338
#endif
 
339
 
 
340
        movl    %ebp, %esp
 
341
        popl    %ebp
 
342
        ret
 
343
 
 
344
1:
 
345
#ifdef FIXED_PROPS
 
346
        andl    $POS_STATE_MASK, %eax
 
347
#else
 
348
        andl    pos_state_mask, %eax
 
349
#endif
 
350
        pushl   %eax                            /* posState */
 
351
        movl    state, %edx
 
352
        shll    $kNumPosBitsMax, %edx
 
353
        addl    %edx, %eax
 
354
        pushl   %eax                            /* (state << kNumPosBitsMax) + posState */
 
355
 
 
356
        call    RangeDecoderBitDecode
 
357
        jc      1f
 
358
 
 
359
        movl    now_pos, %eax
 
360
 
 
361
#ifdef FIXED_PROPS
 
362
        andl    $LIT_POS_MASK, %eax
 
363
        shll    $FIXED_LC, %eax
 
364
        movl    prev_byte, %edx
 
365
        shrl    $(8 - FIXED_LC), %edx
 
366
#else
 
367
        andl    lit_pos_mask, %eax
 
368
        movb    lc, %cl
 
369
        shll    %cl, %eax
 
370
        negb    %cl
 
371
        addb    $8, %cl
 
372
        movl    prev_byte, %edx
 
373
        shrl    %cl, %edx
 
374
#endif
 
375
 
 
376
        addl    %edx, %eax
 
377
        movl    $LZMA_LIT_SIZE, %edx
 
378
        mull    %edx
 
379
        addl    $Literal, %eax
 
380
        pushl   %eax
 
381
 
 
382
        incl    %edx                    /* edx = 1 */
 
383
 
 
384
        movl    rep0, %eax
 
385
        negl    %eax
 
386
        pushl   (%edi, %eax)            /* matchByte */
 
387
 
 
388
        cmpb    $kNumLitStates, state
 
389
        jb      5f
 
390
 
 
391
        /* LzmaLiteralDecodeMatch */
 
392
 
 
393
3:
 
394
        cmpl    $0x100, %edx
 
395
        jae     4f
 
396
 
 
397
        xorl    %eax, %eax
 
398
        shlb    $1, (%esp)
 
399
        adcl    %eax, %eax
 
400
 
 
401
        pushl   %eax
 
402
        pushl   %edx
 
403
 
 
404
        shll    $8, %eax
 
405
        leal    0x100(%edx, %eax), %eax
 
406
        addl    12(%esp), %eax
 
407
        call    RangeDecoderBitDecode
 
408
 
 
409
        setc    %al
 
410
        popl    %edx
 
411
        adcl    %edx, %edx
 
412
 
 
413
        popl    %ecx
 
414
        cmpb    %cl, %al
 
415
        jz      3b
 
416
 
 
417
5:
 
418
 
 
419
        /* LzmaLiteralDecode */
 
420
 
 
421
        cmpl    $0x100, %edx
 
422
        jae     4f
 
423
 
 
424
        pushl   %edx
 
425
        movl    %edx, %eax
 
426
        addl    8(%esp), %eax
 
427
        call    RangeDecoderBitDecode
 
428
        popl    %edx
 
429
        adcl    %edx, %edx
 
430
        jmp     5b
 
431
 
 
432
4:
 
433
        addl    $16, %esp
 
434
 
 
435
        movb    %dl, %al
 
436
        call    WriteByte
 
437
 
 
438
        movb    state, %al
 
439
        cmpb    $4, %al
 
440
        jae     2f
 
441
        xorb    %al, %al
 
442
        jmp     3f
 
443
2:
 
444
        subb    $3, %al
 
445
        cmpb    $7, %al
 
446
        jb      3f
 
447
        subb    $3, %al
 
448
3:
 
449
        movb    %al, state
 
450
        jmp     lzma_decode_loop
 
451
 
 
452
1:
 
453
        movl    state, %eax
 
454
        addl    $IsRep, %eax
 
455
        call    RangeDecoderBitDecode
 
456
        jnc     1f
 
457
 
 
458
        movl    state, %eax
 
459
        addl    $IsRepG0, %eax
 
460
        call    RangeDecoderBitDecode
 
461
        jc      10f
 
462
 
 
463
        movl    (%esp), %eax
 
464
        addl    $IsRep0Long, %eax
 
465
        call    RangeDecoderBitDecode
 
466
        jc      20f
 
467
 
 
468
        cmpb    $7, state
 
469
        movb    $9, state
 
470
        jb      100f
 
471
        addb    $2, state
 
472
100:
 
473
 
 
474
        movl    $1, %ecx
 
475
 
 
476
3:
 
477
        movl    rep0, %edx
 
478
        negl    %edx
 
479
 
 
480
4:
 
481
        movb    (%edi, %edx), %al
 
482
        call    WriteByte
 
483
        loop    4b
 
484
 
 
485
        popl    %eax
 
486
        popl    %eax
 
487
        jmp     lzma_decode_loop
 
488
 
 
489
10:
 
490
        movl    state, %eax
 
491
        addl    $IsRepG1, %eax
 
492
        call    RangeDecoderBitDecode
 
493
        movl    rep1, %edx
 
494
        jnc     100f
 
495
 
 
496
        movl    state, %eax
 
497
        addl    $IsRepG2, %eax
 
498
        call    RangeDecoderBitDecode
 
499
        movl    rep2, %edx
 
500
        jnc     1000f
 
501
        movl    rep2, %edx
 
502
        xchgl   rep3, %edx
 
503
1000:
 
504
        pushl   rep1
 
505
        popl    rep2
 
506
100:
 
507
        xchg    rep0, %edx
 
508
        movl    %edx, rep1
 
509
20:
 
510
 
 
511
        movl    $RepLenCoder, %eax
 
512
        call    LzmaLenDecode
 
513
 
 
514
        cmpb    $7, state
 
515
        movb    $8, state
 
516
        jb      100f
 
517
        addb    $3, state
 
518
100:
 
519
        jmp     2f
 
520
 
 
521
1:
 
522
        movl    rep0, %eax
 
523
        xchgl   rep1, %eax
 
524
        xchgl   rep2, %eax
 
525
        movl    %eax, rep3
 
526
 
 
527
        cmpb    $7, state
 
528
        movb    $7, state
 
529
        jb      10f
 
530
        addb    $3, state
 
531
10:
 
532
 
 
533
        movl    $LenCoder, %eax
 
534
        call    LzmaLenDecode
 
535
        pushl   %edx
 
536
 
 
537
        movl    $(kNumLenToPosStates - 1), %eax
 
538
        cmpl    %eax, %edx
 
539
        jbe     100f
 
540
        movl    %eax, %edx
 
541
100:
 
542
        movb    $kNumPosSlotBits, %cl
 
543
        shll    %cl, %edx
 
544
        leal    PosSlot(%edx), %eax
 
545
        call    RangeDecoderBitTreeDecode
 
546
 
 
547
        movl    %edx, rep0
 
548
        cmpl    $kStartPosModelIndex, %edx
 
549
        jb      100f
 
550
 
 
551
        movl    %edx, %ecx
 
552
        shrl    $1, %ecx
 
553
        decl    %ecx
 
554
 
 
555
        movzbl  %dl, %eax
 
556
        andb    $1, %al
 
557
        orb     $2, %al
 
558
        shll    %cl, %eax
 
559
        movl    %eax, rep0
 
560
 
 
561
        cmpl    $kEndPosModelIndex, %edx
 
562
        jae     200f
 
563
        movl    rep0, %eax
 
564
        addl    $(SpecPos - 1), %eax
 
565
        subl    %edx, %eax
 
566
        jmp     300f
 
567
200:
 
568
 
 
569
        subb    $kNumAlignBits, %cl
 
570
 
 
571
        /* RangeDecoderDecodeDirectBits */
 
572
        xorl    %edx, %edx
 
573
 
 
574
1000:
 
575
        shrl    $1, range
 
576
        shll    $1, %edx
 
577
 
 
578
        movl    range, %eax
 
579
        cmpl    %eax, code
 
580
        jb      2000f
 
581
        subl    %eax, code
 
582
        orb     $1, %dl
 
583
2000:
 
584
 
 
585
        cmpl    $kTopValue, %eax
 
586
        jae     3000f
 
587
        shll    $8, range
 
588
        shll    $8, code
 
589
        lodsb
 
590
        movb    %al, code
 
591
 
 
592
3000:
 
593
        loop    1000b
 
594
 
 
595
        movb    $kNumAlignBits, %cl
 
596
        shll    %cl, %edx
 
597
        addl    %edx, rep0
 
598
 
 
599
        movl    $Align, %eax
 
600
 
 
601
300:
 
602
        call    RangeDecoderReverseBitTreeDecode
 
603
        addl    %ecx, rep0
 
604
 
 
605
100:
 
606
        incl    rep0
 
607
        popl    %edx
 
608
 
 
609
2:
 
610
 
 
611
        addl    $kMatchMinLen, %edx
 
612
        movl    %edx, %ecx
 
613
 
 
614
        jmp     3b