diff --git a/ChangeLog b/ChangeLog index ded0469a3..d1f01e727 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2011-05-17 Vladimir Serbinenko + + Prevent potential loss of memory map by overwrite on qemu-mips. + + * grub-core/boot/mips/startup_raw.S [GRUB_MACHINE_MIPS_QEMU_MIPS]: + Save ram size in $s4. + * grub-core/kern/mips/qemu_mips/init.c (RAMSIZE): Removed. + All users changed to grub_arch_memsize. + * grub-core/kern/mips/startup.S (grub_arch_machine): Restrict to + Loongson. + [GRUB_MACHINE_MIPS_QEMU_MIPS]: Save grub_arch_memsize. + * grub-core/loader/mips/linux.c (grub_linux_boot): Pass memory size. + * include/grub/mips/qemu_mips/memory.h (grub_arch_memsize): New + external variable. + 2011-05-17 Colin Watson * .bzrignore: Remove grub-dumpbios. diff --git a/grub-core/boot/mips/startup_raw.S b/grub-core/boot/mips/startup_raw.S index e69de26c2..65a2dd59e 100644 --- a/grub-core/boot/mips/startup_raw.S +++ b/grub-core/boot/mips/startup_raw.S @@ -50,6 +50,11 @@ codestart: /* Parse arguments. Has to be done before relocation. So need to do it in asm. */ +#ifdef GRUB_MACHINE_MIPS_QEMU_MIPS + lui $t0, %hi (((16 << 20) - 264) | 0x80000000) + lw $s4, %lo (((16 << 20) - 264) | 0x80000000) ($t0) +#endif + #ifdef GRUB_MACHINE_MIPS_LOONGSON move $s2, $zero move $s3, $zero diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c index b3155eab5..e426b833d 100644 --- a/grub-core/kern/mips/qemu_mips/init.c +++ b/grub-core/kern/mips/qemu_mips/init.c @@ -10,8 +10,6 @@ #include #include -#define RAMSIZE (*(grub_uint32_t *) ((16 << 20) - 264)) - extern void grub_serial_init (void); extern void grub_terminfo_init (void); @@ -24,7 +22,7 @@ grub_machine_init (void) grub_arch_cpuclock = 64000000; modend = grub_modules_get_end (); - grub_mm_init_region ((void *) modend, RAMSIZE + grub_mm_init_region ((void *) modend, grub_arch_memsize - (modend - GRUB_ARCH_LOWMEMVSTART)); grub_install_get_time_ms (grub_rtc_get_time_ms); @@ -59,6 +57,6 @@ grub_reboot (void) grub_err_t grub_machine_mmap_iterate (grub_memory_hook_t hook) { - hook (0, RAMSIZE, GRUB_MEMORY_AVAILABLE); + hook (0, grub_arch_memsize, GRUB_MEMORY_AVAILABLE); return GRUB_ERR_NONE; } diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index 1472aaf8c..2654d744e 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -59,12 +59,20 @@ VARIABLE (grub_arch_memsize) .long 0 VARIABLE (grub_arch_highmemsize) .long 0 +#ifdef GRUB_MACHINE_MIPS_LOONGSON VARIABLE (grub_arch_machine) .long GRUB_ARCH_MACHINE_FULOONG +#endif cont: /* Save our base. */ move $s0, $ra +#ifdef GRUB_MACHINE_MIPS_QEMU_MIPS + lui $t1, %hi(grub_arch_busclock) + addiu $t1, %lo(grub_arch_busclock) + sw $s4, 8($t1) +#endif + #ifdef GRUB_MACHINE_MIPS_LOONGSON lui $t1, %hi(grub_arch_busclock) addiu $t1, %lo(grub_arch_busclock) diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c index 722be36a9..64c4a0531 100644 --- a/grub-core/loader/mips/linux.c +++ b/grub-core/loader/mips/linux.c @@ -80,13 +80,21 @@ grub_linux_boot (void) { grub_err_t err; grub_relocator_chunk_t ch; + grub_uint32_t *memsize; + grub_uint32_t *magic; + char *str; err = grub_relocator_alloc_chunk_addr (relocator, &ch, - ((16 << 20) - 256), - grub_strlen (params) + 1); + ((16 << 20) - 264), + grub_strlen (params) + 1 + 8); if (err) return err; - grub_strcpy (get_virtual_current_address (ch), params); + memsize = get_virtual_current_address (ch); + magic = memsize + 1; + *memsize = grub_mmap_get_lower (); + *magic = 0x12345678; + str = (char *) (magic + 1); + grub_strcpy (str, params); } #endif diff --git a/include/grub/mips/qemu_mips/memory.h b/include/grub/mips/qemu_mips/memory.h index 7a7ff143e..48a9b69f0 100644 --- a/include/grub/mips/qemu_mips/memory.h +++ b/include/grub/mips/qemu_mips/memory.h @@ -29,6 +29,9 @@ #define GRUB_MACHINE_MEMORY_USABLE 0x81000000 #ifndef ASM_FILE + +extern grub_uint32_t grub_arch_memsize; + static inline grub_err_t grub_machine_mmap_register (grub_uint64_t start __attribute__ ((unused)), grub_uint64_t size __attribute__ ((unused)),