MAke a separate scratch for decompressor

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-09-21 19:39:51 +02:00
parent f8926c32b4
commit e0a8ef26e4
5 changed files with 33 additions and 14 deletions

View File

@ -80,6 +80,27 @@ void *memmove (void *dest, const void *src, grub_size_t n)
void *memcpy (void *dest, const void *src, grub_size_t n)
__attribute__ ((alias ("grub_memmove")));
void *grub_decompressor_scratch;
void
find_scratch (void *src, void *dst, unsigned long srcsize,
unsigned long dstsize)
{
#ifdef _mips
/* Decoding from ROM. */
if (((grub_addr_t) src & 0x10000000))
{
grub_decompressor_scratch = (char *) dst + dstsize;
return;
}
#endif
if ((char *) src + srcsize > (char *) dst + dstsize)
grub_decompressor_scratch = (char *) src + srcsize;
else
grub_decompressor_scratch = (char *) dst + dstsize;
return;
}
void
grub_decompress_core (void *src, void *dst, unsigned long srcsize,
unsigned long dstsize)
@ -87,6 +108,8 @@ grub_decompress_core (void *src, void *dst, unsigned long srcsize,
struct xz_dec *dec;
struct xz_buf buf;
find_scratch (src, dst, srcsize, dstsize);
dec = xz_dec_init (GRUB_DECOMPRESSOR_DICT_SIZE);
buf.in = src;

View File

@ -49,7 +49,7 @@ codestart:
/* Parse arguments. Has to be done before relocation.
So need to do it in asm. */
#if 0 // def GRUB_MACHINE_MIPS_YEELOONG
#ifdef GRUB_MACHINE_MIPS_YEELOONG
move $s2, $zero
move $s3, $zero
move $s4, $zero

View File

@ -109,10 +109,10 @@ bsscont:
bne $t3, $0, bsscont
addiu $t1, $t1, 1
li $sp, GRUB_MACHINE_MEMORY_STACK_HIGH
lui $t1, %hi(grub_main)
addiu $t1, %lo(grub_main)
lui $sp, %hi(GRUB_MACHINE_MEMORY_STACK_HIGH)
jr $t1
nop
addiu $sp, $sp, %lo(GRUB_MACHINE_MEMORY_STACK_HIGH)

View File

@ -1103,7 +1103,6 @@ enum xz_ret xz_dec_lzma2_run(
#ifdef GRUB_EMBED_DECOMPRESSOR
#include <grub/decompressor.h>
static struct xz_dec_lzma2 lzma2;
static char dict[GRUB_DECOMPRESSOR_DICT_SIZE];
#endif
struct xz_dec_lzma2 * xz_dec_lzma2_create(uint32_t dict_max)
@ -1128,14 +1127,8 @@ struct xz_dec_lzma2 * xz_dec_lzma2_create(uint32_t dict_max)
}
#else
if (dict_max > GRUB_DECOMPRESSOR_DICT_SIZE)
return NULL;
s = &lzma2;
if (dict_max > 0) {
s->dict.buf = (void *) &dict;
}
s->dict.buf = grub_decompressor_scratch;
#endif
s->dict.allocated = dict_max;
@ -1165,9 +1158,6 @@ enum xz_ret xz_dec_lzma2_reset(
s->dict.buf = newdict;
s->dict.allocated = s->dict.size;
}
#else
if (s->dict.allocated > 0 && s->dict.allocated < s->dict.size)
return XZ_MEMLIMIT_ERROR;
#endif
s->dict.end = s->dict.size;

View File

@ -23,6 +23,12 @@ void
grub_decompress_core (void *src, void *dst, unsigned long srcsize,
unsigned long dstsize);
void
find_scratch (void *src, void *dst, unsigned long srcsize,
unsigned long dstsize);
#define GRUB_DECOMPRESSOR_DICT_SIZE (1 << 16)
extern void *grub_decompressor_scratch;
#endif