Skip to content

Commit

Permalink
tinf: Remove legacy stage 3 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsuki committed Mar 1, 2021
1 parent 8c0c36e commit 71d0feb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 30 deletions.
1 change: 0 additions & 1 deletion decompressor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ OBJCOPY = i386-elf-objcopy
CFLAGS = -flto -Os -pipe -Wall -Wextra -Werror

INTERNAL_CFLAGS = \
-DIN_DECOMPRESSOR \
-std=gnu11 \
-ffreestanding \
-fno-stack-protector \
Expand Down
9 changes: 1 addition & 8 deletions tinf/tinfgzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
* distribution.
*/

#ifndef IN_DECOMPRESSOR
# include <lib/blib.h>
#else
# define stage3_text
# define stage3_data
#endif

#include "tinf.h"

typedef enum {
Expand All @@ -40,7 +33,7 @@ typedef enum {
FCOMMENT = 16
} tinf_gzip_flag;

stage3_text int tinf_gzip_uncompress(void *dest,
int tinf_gzip_uncompress(void *dest,
const void *source, unsigned int sourceLen) {
const unsigned char *src = (const unsigned char *) source;
unsigned char *dst = (unsigned char *) dest;
Expand Down
35 changes: 14 additions & 21 deletions tinf/tinflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
* distribution.
*/

#ifndef IN_DECOMPRESSOR
# include <lib/blib.h>
#else
# define stage3_text
# define stage3_data
#endif

#include "tinf.h"

#include <limits.h>
Expand Down Expand Up @@ -62,13 +55,13 @@ struct tinf_data {

/* -- Utility functions -- */

stage3_text static unsigned int read_le16(const unsigned char *p) {
static unsigned int read_le16(const unsigned char *p) {
return ((unsigned int) p[0])
| ((unsigned int) p[1] << 8);
}

/* Build fixed Huffman trees */
stage3_text static void tinf_build_fixed_trees(struct tinf_tree *lt, struct tinf_tree *dt) {
static void tinf_build_fixed_trees(struct tinf_tree *lt, struct tinf_tree *dt) {
int i;

/* Build fixed literal/length tree */
Expand Down Expand Up @@ -110,7 +103,7 @@ stage3_text static void tinf_build_fixed_trees(struct tinf_tree *lt, struct tinf
}

/* Given an array of code lengths, build a tree */
stage3_text static int tinf_build_tree(struct tinf_tree *t, const unsigned char *lengths,
static int tinf_build_tree(struct tinf_tree *t, const unsigned char *lengths,
unsigned int num) {
unsigned short offs[16];
unsigned int i, num_codes, available;
Expand Down Expand Up @@ -174,7 +167,7 @@ stage3_text static int tinf_build_tree(struct tinf_tree *t, const unsigned char

/* -- Decode functions -- */

stage3_text static void tinf_refill(struct tinf_data *d, int num) {
static void tinf_refill(struct tinf_data *d, int num) {

/* Read bytes until at least num bits available */
while (d->bitcount < num) {
Expand All @@ -189,7 +182,7 @@ stage3_text static void tinf_refill(struct tinf_data *d, int num) {

}

stage3_text static unsigned int tinf_getbits_no_refill(struct tinf_data *d, int num) {
static unsigned int tinf_getbits_no_refill(struct tinf_data *d, int num) {
unsigned int bits;


Expand All @@ -204,18 +197,18 @@ stage3_text static unsigned int tinf_getbits_no_refill(struct tinf_data *d, int
}

/* Get num bits from source stream */
stage3_text static unsigned int tinf_getbits(struct tinf_data *d, int num) {
static unsigned int tinf_getbits(struct tinf_data *d, int num) {
tinf_refill(d, num);
return tinf_getbits_no_refill(d, num);
}

/* Read a num bit value from stream and add base */
stage3_text static unsigned int tinf_getbits_base(struct tinf_data *d, int num, int base) {
static unsigned int tinf_getbits_base(struct tinf_data *d, int num, int base) {
return base + (num ? tinf_getbits(d, num) : 0);
}

/* Given a data stream and a tree, decode a symbol */
stage3_text static int tinf_decode_symbol(struct tinf_data *d, const struct tinf_tree *t) {
static int tinf_decode_symbol(struct tinf_data *d, const struct tinf_tree *t) {
int base = 0, offs = 0;
int len;

Expand Down Expand Up @@ -248,7 +241,7 @@ stage3_text static int tinf_decode_symbol(struct tinf_data *d, const struct tinf
}

/* Given a data stream, decode dynamic trees from it */
stage3_text static int tinf_decode_trees(struct tinf_data *d, struct tinf_tree *lt,
static int tinf_decode_trees(struct tinf_data *d, struct tinf_tree *lt,
struct tinf_tree *dt) {
unsigned char lengths[288 + 32];

Expand Down Expand Up @@ -374,7 +367,7 @@ stage3_text static int tinf_decode_trees(struct tinf_data *d, struct tinf_tree *
/* -- Block inflate functions -- */

/* Given a stream and two trees, inflate a block of data */
stage3_text static int tinf_inflate_block_data(struct tinf_data *d, struct tinf_tree *lt,
static int tinf_inflate_block_data(struct tinf_data *d, struct tinf_tree *lt,
struct tinf_tree *dt) {
/* Extra bits and base tables for length codes */
static const unsigned char length_bits[30] = {
Expand Down Expand Up @@ -459,7 +452,7 @@ stage3_text static int tinf_inflate_block_data(struct tinf_data *d, struct tinf_
}

/* Inflate an uncompressed block of data */
stage3_text static int tinf_inflate_uncompressed_block(struct tinf_data *d) {
static int tinf_inflate_uncompressed_block(struct tinf_data *d) {
unsigned int length, invlength;

if (d->source_end - d->source < 4) {
Expand Down Expand Up @@ -492,7 +485,7 @@ stage3_text static int tinf_inflate_uncompressed_block(struct tinf_data *d) {
}

/* Inflate a block of data compressed with fixed Huffman trees */
stage3_text static int tinf_inflate_fixed_block(struct tinf_data *d) {
static int tinf_inflate_fixed_block(struct tinf_data *d) {
/* Build fixed Huffman trees */
tinf_build_fixed_trees(&d->ltree, &d->dtree);

Expand All @@ -501,7 +494,7 @@ stage3_text static int tinf_inflate_fixed_block(struct tinf_data *d) {
}

/* Inflate a block of data compressed with dynamic Huffman trees */
stage3_text static int tinf_inflate_dynamic_block(struct tinf_data *d) {
static int tinf_inflate_dynamic_block(struct tinf_data *d) {
/* Decode trees from stream */
int res = tinf_decode_trees(d, &d->ltree, &d->dtree);

Expand All @@ -516,7 +509,7 @@ stage3_text static int tinf_inflate_dynamic_block(struct tinf_data *d) {
/* -- Public functions -- */

/* Inflate stream from source to dest */
stage3_text int tinf_uncompress(void *dest,
int tinf_uncompress(void *dest,
const void *source, unsigned int sourceLen) {
struct tinf_data d;
int bfinal;
Expand Down

0 comments on commit 71d0feb

Please sign in to comment.