1 /* ----------------------------------------------------------------------- *
3 * Copyright 2007-2009 H. Peter Anvin - All Rights Reserved
4 * Copyright 2009 Intel Corporation; author: H. Peter Anvin
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
9 * Boston MA 02110-1301, USA; either version 2 of the License, or
10 * (at your option) any later version; incorporated herein by reference.
12 * ----------------------------------------------------------------------- */
17 * Very simple RLL compressor/decompressor, used to pack binary structures
20 * Format of leading byte
21 * 1-128 = x verbatim bytes follow
22 * 129-223 = (x-126) times subsequent byte
23 * 224-255 = (x-224)*256+(next byte) times the following byte
26 * These structures are stored *in reverse order* in high memory.
27 * High memory pointers point to one byte beyond the end.
34 void rllpack(com32sys_t
* regs
)
36 uint8_t *i
= (uint8_t *) (regs
->esi
.l
);
37 uint8_t *o
= (uint8_t *) (regs
->edi
.l
);
38 size_t cnt
= regs
->ecx
.l
;
39 size_t run
, vrun
, tcnt
;
48 tcnt
= (cnt
> 8191) ? 8191 : cnt
;
49 while (run
< tcnt
&& i
[run
] == c
)
62 if (run
< 224 - 126) {
66 *(uint16_t *) o
= run
+ (224 << 8);
76 regs
->esi
.l
= (size_t)i
;
77 regs
->edi
.l
= (size_t)o
;
80 void rllunpack(com32sys_t
* regs
)
82 uint8_t *i
= (uint8_t *) regs
->esi
.l
;
83 uint8_t *o
= (uint8_t *) regs
->edi
.l
;
95 n
= ((c
- 224) << 8) + *--i
;
102 regs
->esi
.l
= (size_t)i
;
103 regs
->ecx
.l
= (size_t)o
- regs
->edi
.l
;
104 regs
->edi
.l
= (size_t)o
;