From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1JA72u-0005Gi-7J for mharc-grub-devel@gnu.org; Wed, 02 Jan 2008 12:06:24 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JA72s-0005G0-Fg for grub-devel@gnu.org; Wed, 02 Jan 2008 12:06:22 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JA72r-0005FF-No for grub-devel@gnu.org; Wed, 02 Jan 2008 12:06:21 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JA72r-0005F5-J1 for grub-devel@gnu.org; Wed, 02 Jan 2008 12:06:21 -0500 Received: from aybabtu.com ([69.60.117.155]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JA72r-0004M7-29 for grub-devel@gnu.org; Wed, 02 Jan 2008 12:06:21 -0500 Received: from [192.168.10.6] (helo=thorin) by aybabtu.com with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1JA72l-00052g-Kp for grub-devel@gnu.org; Wed, 02 Jan 2008 18:06:19 +0100 Received: from rmh by thorin with local (Exim 4.63) (envelope-from ) id 1JA725-0007ct-SA for grub-devel@gnu.org; Wed, 02 Jan 2008 18:05:33 +0100 Date: Wed, 2 Jan 2008 18:05:33 +0100 From: Robert Millan To: grub-devel@gnu.org Message-ID: <20080102170533.GA29024@thorin> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="uAKRQypu60I7Lcqm" Content-Disposition: inline Organization: free as in freedom X-Message-Flag: Worried about Outlook viruses? Switch to Thunderbird! www.mozilla.com/thunderbird X-Debbugs-No-Ack: true User-Agent: Mutt/1.5.13 (2006-08-11) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [PATCH] memtest86+ fix X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jan 2008 17:06:22 -0000 --uAKRQypu60I7Lcqm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This fixes boot for memtest86+ (and actually, Linux zImages since they were all affected). The problem was that the first code in grub_linux_boot_zimage copied the payload from 0x100000 to 0x10000. Since GRUB starts at 0x8200 and is typicaly more than 8 kiB in size, it'll most likely overwrite part of it. A bit of reestructuring was necessary to allow grub_dl_unload_all() to happen unconditionally as first step, since the information on whether this is a "big linux" was not promptly available. Comments? -- Robert Millan I know my rights; I want my phone call! What use is a phone call, if you are unable to speak? (as seen on /.) --uAKRQypu60I7Lcqm Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="memtest.diff" 2008-01-02 Robert Millan * kern/i386/loader.S (grub_linux_big): New variable. (grub_linux_boot_zimage): Rename to ... (grub_linux_boot): ... this. (grub_linux_boot_bzimage): Merge with `grub_linux_boot_zimage'. (grub_linux_boot_zimage): Conditionalize zImage copy. * include/grub/i386/loader.h (grub_linux_big): Add prototype. (grub_linux_boot_bzimage): Remove prototype. (grub_linux_boot_zimage): Rename to ... (grub_linux_boot): ... this. * loader/i386/pc/linux.c (big_linux): Replace with `grub_linux_big'. (grub_linux_boot): Remove function. diff -urp grub2/include/grub/i386/loader.h grub2.mt/include/grub/i386/loader.h --- grub2/include/grub/i386/loader.h 2007-10-17 11:38:55.000000000 +0200 +++ grub2.mt/include/grub/i386/loader.h 2008-01-02 17:51:45.000000000 +0100 @@ -26,11 +26,11 @@ extern grub_uint32_t EXPORT_VAR(grub_linux_prot_size); extern char *EXPORT_VAR(grub_linux_tmp_addr); extern char *EXPORT_VAR(grub_linux_real_addr); +extern grub_int32_t EXPORT_VAR(grub_linux_big); extern grub_addr_t EXPORT_VAR(grub_os_area_addr); extern grub_size_t EXPORT_VAR(grub_os_area_size); -void EXPORT_FUNC(grub_linux_boot_zimage) (void) __attribute__ ((noreturn)); -void EXPORT_FUNC(grub_linux_boot_bzimage) (void) __attribute__ ((noreturn)); +void EXPORT_FUNC(grub_linux_boot) (void) __attribute__ ((noreturn)); /* The asm part of the multiboot loader. */ void EXPORT_FUNC(grub_multiboot_real_boot) (grub_addr_t entry, diff -urp grub2/kern/i386/loader.S grub2.mt/kern/i386/loader.S --- grub2/kern/i386/loader.S 2007-10-17 22:04:23.000000000 +0200 +++ grub2.mt/kern/i386/loader.S 2008-01-02 17:52:42.000000000 +0100 @@ -56,8 +56,17 @@ VARIABLE(grub_linux_tmp_addr) .long 0 VARIABLE(grub_linux_real_addr) .long 0 +VARIABLE(grub_linux_big) + .long 0 -FUNCTION(grub_linux_boot_zimage) +FUNCTION(grub_linux_boot) + /* Must be done before zImage copy. */ + call EXT_C(grub_dl_unload_all) + + movl EXT_C(grub_linux_big), %ebx + test %ebx, %ebx + jne bzimage + /* copy the kernel */ movl EXT_C(grub_linux_prot_size), %ecx addl $3, %ecx @@ -68,9 +77,7 @@ FUNCTION(grub_linux_boot_zimage) rep movsl -FUNCTION(grub_linux_boot_bzimage) - call EXT_C(grub_dl_unload_all) - +bzimage: movl EXT_C(grub_linux_real_addr), %ebx /* copy the real mode code */ diff -urp grub2/loader/i386/pc/linux.c grub2.mt/loader/i386/pc/linux.c --- grub2/loader/i386/pc/linux.c 2008-01-02 16:28:50.000000000 +0100 +++ grub2.mt/loader/i386/pc/linux.c 2008-01-02 17:51:35.000000000 +0100 @@ -33,23 +33,10 @@ static grub_dl_t my_mod; -static int big_linux; static grub_size_t linux_mem_size; static int loaded; static grub_err_t -grub_linux_boot (void) -{ - if (big_linux) - grub_linux_boot_bzimage (); - else - grub_linux_boot_zimage (); - - /* Never reach here. */ - return GRUB_ERR_NONE; -} - -static grub_err_t grub_linux_unload (void) { grub_dl_unref (my_mod); @@ -106,14 +93,14 @@ grub_rescue_cmd_linux (int argc, char *a goto fail; } - big_linux = 0; + grub_linux_big = 0; setup_sects = lh.setup_sects; linux_mem_size = 0; if (lh.header == grub_cpu_to_le32 (GRUB_LINUX_MAGIC_SIGNATURE) && grub_le_to_cpu16 (lh.version) >= 0x0200) { - big_linux = (lh.loadflags & GRUB_LINUX_FLAG_BIG_KERNEL); + grub_linux_big = (lh.loadflags & GRUB_LINUX_FLAG_BIG_KERNEL); lh.type_of_loader = GRUB_LINUX_BOOT_LOADER_TYPE; /* Put the real mode part at as a high location as possible. */ @@ -158,7 +145,7 @@ grub_rescue_cmd_linux (int argc, char *a grub_linux_tmp_addr = (char *) GRUB_LINUX_BZIMAGE_ADDR + prot_size; - if (! big_linux + if (! grub_linux_big && prot_size > (grub_size_t) (grub_linux_real_addr - (char *) GRUB_LINUX_ZIMAGE_ADDR)) { @@ -177,7 +164,7 @@ grub_rescue_cmd_linux (int argc, char *a } grub_printf (" [Linux-%s, setup=0x%x, size=0x%x]\n", - big_linux ? "bzImage" : "zImage", real_size, prot_size); + grub_linux_big ? "bzImage" : "zImage", real_size, prot_size); for (i = 1; i < argc; i++) if (grub_memcmp (argv[i], "vga=", 4) == 0) --uAKRQypu60I7Lcqm--