diff --git a/grub-core/boot/decompressor.c b/grub-core/boot/decompressor.c index 5c16fb932..604fc754c 100644 --- a/grub-core/boot/decompressor.c +++ b/grub-core/boot/decompressor.c @@ -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; diff --git a/grub-core/boot/mips/startup_raw.S b/grub-core/boot/mips/startup_raw.S index 67dc2ec03..d810f2fb4 100644 --- a/grub-core/boot/mips/startup_raw.S +++ b/grub-core/boot/mips/startup_raw.S @@ -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 diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index 1b27a5b1f..97145b818 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -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) diff --git a/grub-core/lib/xzembed/xz_dec_lzma2.c b/grub-core/lib/xzembed/xz_dec_lzma2.c index c55773ce0..7899e9e87 100644 --- a/grub-core/lib/xzembed/xz_dec_lzma2.c +++ b/grub-core/lib/xzembed/xz_dec_lzma2.c @@ -1103,7 +1103,6 @@ enum xz_ret xz_dec_lzma2_run( #ifdef GRUB_EMBED_DECOMPRESSOR #include 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; diff --git a/include/grub/decompressor.h b/include/grub/decompressor.h index 4d99c41f7..a6eefb01b 100644 --- a/include/grub/decompressor.h +++ b/include/grub/decompressor.h @@ -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