tinf: Do not share decompressor and stage2/3 decompression code

This commit is contained in:
mintsuki 2021-02-21 05:01:18 +01:00
parent 960549377b
commit 6739ff84ff
14 changed files with 37 additions and 35 deletions

View File

@ -26,7 +26,7 @@ install: all
install -d $(DESTDIR)$(PREFIX)/bin
install -s limine-install $(DESTDIR)$(PREFIX)/bin/
bootloader: stage2 decompressor
bootloader: | decompressor decompressor-clean stage2
gzip -n -9 < stage2/stage2.bin > stage2/stage2.bin.gz
cd bootsect && nasm bootsect.asm -fbin -o ../limine.bin
cd pxeboot && nasm bootsect.asm -fbin -o ../limine-pxe.bin

View File

@ -5,6 +5,7 @@ OBJCOPY = i386-elf-objcopy
CFLAGS = -flto -Os -pipe -Wall -Wextra -Werror
INTERNAL_CFLAGS = \
-DIN_DECOMPRESSOR \
-std=gnu11 \
-ffreestanding \
-fno-stack-protector \

View File

@ -23,6 +23,13 @@
* distribution.
*/
#ifndef IN_DECOMPRESSOR
# include <lib/blib.h>
#else
# define stage3_text
# define stage3_data
#endif
#include "tinf.h"
typedef enum {
@ -33,7 +40,7 @@ typedef enum {
FCOMMENT = 16
} tinf_gzip_flag;
int tinf_gzip_uncompress(void *dest,
stage3_text 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;

View File

@ -23,6 +23,13 @@
* distribution.
*/
#ifndef IN_DECOMPRESSOR
# include <lib/blib.h>
#else
# define stage3_text
# define stage3_data
#endif
#include "tinf.h"
#include <limits.h>
@ -55,13 +62,13 @@ struct tinf_data {
/* -- Utility functions -- */
static unsigned int read_le16(const unsigned char *p) {
stage3_text static unsigned int read_le16(const unsigned char *p) {
return ((unsigned int) p[0])
| ((unsigned int) p[1] << 8);
}
/* Build fixed Huffman trees */
static void tinf_build_fixed_trees(struct tinf_tree *lt, struct tinf_tree *dt) {
stage3_text static void tinf_build_fixed_trees(struct tinf_tree *lt, struct tinf_tree *dt) {
int i;
/* Build fixed literal/length tree */
@ -103,7 +110,7 @@ static void tinf_build_fixed_trees(struct tinf_tree *lt, struct tinf_tree *dt) {
}
/* Given an array of code lengths, build a tree */
static int tinf_build_tree(struct tinf_tree *t, const unsigned char *lengths,
stage3_text 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;
@ -167,7 +174,7 @@ static int tinf_build_tree(struct tinf_tree *t, const unsigned char *lengths,
/* -- Decode functions -- */
static void tinf_refill(struct tinf_data *d, int num) {
stage3_text static void tinf_refill(struct tinf_data *d, int num) {
/* Read bytes until at least num bits available */
while (d->bitcount < num) {
@ -182,7 +189,7 @@ static void tinf_refill(struct tinf_data *d, int num) {
}
static unsigned int tinf_getbits_no_refill(struct tinf_data *d, int num) {
stage3_text static unsigned int tinf_getbits_no_refill(struct tinf_data *d, int num) {
unsigned int bits;
@ -197,18 +204,18 @@ static unsigned int tinf_getbits_no_refill(struct tinf_data *d, int num) {
}
/* Get num bits from source stream */
static unsigned int tinf_getbits(struct tinf_data *d, int num) {
stage3_text 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 */
static unsigned int tinf_getbits_base(struct tinf_data *d, int num, int base) {
stage3_text 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 */
static int tinf_decode_symbol(struct tinf_data *d, const struct tinf_tree *t) {
stage3_text static int tinf_decode_symbol(struct tinf_data *d, const struct tinf_tree *t) {
int base = 0, offs = 0;
int len;
@ -241,7 +248,7 @@ static int tinf_decode_symbol(struct tinf_data *d, const struct tinf_tree *t) {
}
/* Given a data stream, decode dynamic trees from it */
static int tinf_decode_trees(struct tinf_data *d, struct tinf_tree *lt,
stage3_text static int tinf_decode_trees(struct tinf_data *d, struct tinf_tree *lt,
struct tinf_tree *dt) {
unsigned char lengths[288 + 32];
@ -367,7 +374,7 @@ static int tinf_decode_trees(struct tinf_data *d, struct tinf_tree *lt,
/* -- Block inflate functions -- */
/* Given a stream and two trees, inflate a block of data */
static int tinf_inflate_block_data(struct tinf_data *d, struct tinf_tree *lt,
stage3_text 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] = {
@ -452,7 +459,7 @@ static int tinf_inflate_block_data(struct tinf_data *d, struct tinf_tree *lt,
}
/* Inflate an uncompressed block of data */
static int tinf_inflate_uncompressed_block(struct tinf_data *d) {
stage3_text static int tinf_inflate_uncompressed_block(struct tinf_data *d) {
unsigned int length, invlength;
if (d->source_end - d->source < 4) {
@ -485,7 +492,7 @@ static int tinf_inflate_uncompressed_block(struct tinf_data *d) {
}
/* Inflate a block of data compressed with fixed Huffman trees */
static int tinf_inflate_fixed_block(struct tinf_data *d) {
stage3_text static int tinf_inflate_fixed_block(struct tinf_data *d) {
/* Build fixed Huffman trees */
tinf_build_fixed_trees(&d->ltree, &d->dtree);
@ -494,7 +501,7 @@ static int tinf_inflate_fixed_block(struct tinf_data *d) {
}
/* Inflate a block of data compressed with dynamic Huffman trees */
static int tinf_inflate_dynamic_block(struct tinf_data *d) {
stage3_text static int tinf_inflate_dynamic_block(struct tinf_data *d) {
/* Decode trees from stream */
int res = tinf_decode_trees(d, &d->ltree, &d->dtree);
@ -509,7 +516,7 @@ static int tinf_inflate_dynamic_block(struct tinf_data *d) {
/* -- Public functions -- */
/* Inflate stream from source to dest */
int tinf_uncompress(void *dest,
stage3_text int tinf_uncompress(void *dest,
const void *source, unsigned int sourceLen) {
struct tinf_data d;
int bfinal;

View File

@ -12,13 +12,12 @@ void entry(uint8_t *compressed_stage2, size_t stage2_size, uint8_t boot_drive, i
asm volatile (
"mov esp, 0x7c00\n\t"
"xor ebp, ebp\n\t"
"push %2\n\t"
"push %1\n\t"
"push %0\n\t"
"push 0\n\t"
"jmp 0x8000\n\t"
:
: "r" ((uint32_t)boot_drive), "r" (pxe), "r" (tinf_gzip_uncompress)
: "r" ((uint32_t)boot_drive), "r" (pxe)
: "memory"
);

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -40,8 +40,8 @@ INTERNAL_LDFLAGS = \
.PHONY: all clean
C_FILES := $(shell find ./ -type f -name '*.c' | sort)
ASM_FILES := $(shell find ./ -type f -name '*.asm' | sort)
C_FILES := $(shell find -L ./ -type f -name '*.c' | sort)
ASM_FILES := $(shell find -L ./ -type f -name '*.asm' | sort)
OBJ := $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o)
HEADER_DEPS := $(C_FILES:.c=.d)

View File

@ -1,4 +0,0 @@
#include <lib/tinf.h>
int (*tinf_gzip_uncompress)(void *dest,
const void *source, unsigned int sourceLen);

View File

@ -1,7 +0,0 @@
#ifndef __LIB__TINF_H__
#define __LIB__TINF_H__
extern int (*tinf_gzip_uncompress)(void *dest,
const void *source, unsigned int sourceLen);
#endif

View File

@ -8,7 +8,7 @@
#include <mm/pmm.h>
#include <lib/print.h>
#include <pxe/tftp.h>
#include <lib/tinf.h>
#include <tinf/tinf.h>
// A URI takes the form of: resource://root/path
// The following function splits up a URI into its componenets

View File

@ -19,11 +19,9 @@
#include <menu.h>
#include <pxe/pxe.h>
#include <pxe/tftp.h>
#include <lib/tinf.h>
void entry(uint8_t _boot_drive, int pxe_boot, void *_tinf_gzip_uncompress) {
void entry(uint8_t _boot_drive, int pxe_boot) {
boot_drive = _boot_drive;
tinf_gzip_uncompress = _tinf_gzip_uncompress;
booted_from_pxe = pxe_boot;

1
stage2/tinf Symbolic link
View File

@ -0,0 +1 @@
../decompressor/gzip/