From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1MvdpT-0007V1-9Z for mharc-grub-devel@gnu.org; Wed, 07 Oct 2009 17:13:47 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvdpR-0007SD-Lh for grub-devel@gnu.org; Wed, 07 Oct 2009 17:13:45 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvdpM-0007Lc-LZ for grub-devel@gnu.org; Wed, 07 Oct 2009 17:13:45 -0400 Received: from [199.232.76.173] (port=53013 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvdpM-0007L9-9X for grub-devel@gnu.org; Wed, 07 Oct 2009 17:13:40 -0400 Received: from xvm-190-8.ghst.net ([217.70.190.8]:49132 helo=aybabtu.com) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MvdpL-0007JB-Ns for grub-devel@gnu.org; Wed, 07 Oct 2009 17:13:40 -0400 Received: from [192.168.10.10] (helo=thorin) by aybabtu.com with esmtp (Exim 4.69) (envelope-from ) id 1MvdpG-0008N1-Qc for grub-devel@gnu.org; Wed, 07 Oct 2009 23:13:35 +0200 Received: from rmh by thorin with local (Exim 4.69) (envelope-from ) id 1MvdpG-00085Y-3E for grub-devel@gnu.org; Wed, 07 Oct 2009 23:13:34 +0200 Date: Wed, 7 Oct 2009 23:13:34 +0200 From: Robert Millan To: grub-devel@gnu.org Message-ID: <20091007211334.GA31055@thorin> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="GvXjxJ+pjyke8COw" 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.18 (2008-05-17) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [PATCH] Fail gracefuly when attempting to load 64-bit kFreeBSD on IA32 CPU 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, 07 Oct 2009 21:13:46 -0000 --GvXjxJ+pjyke8COw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline -- Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all." --GvXjxJ+pjyke8COw Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="kfreebsd_cpuid.diff" 2009-10-07 Robert Millan Fail gracefuly when attempting to load 64-bit kFreeBSD on IA32 CPU. * include/grub/i386/cpuid.h: New file. * commands/i386/cpuid.c: Include `'. (has_longmode): Rename to ... (grub_cpuid_has_longmode): ... this. Update all users. Remove `unsigned' attribute. * loader/i386/bsd.c: Include `'. (grub_bsd_load_elf): Fail if load of 64-bit kernel was requested on a CPU that doesn't implement AMD64 instruction set. Index: include/grub/i386/cpuid.h =================================================================== --- include/grub/i386/cpuid.h (revision 0) +++ include/grub/i386/cpuid.h (revision 0) @@ -0,0 +1,19 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +extern unsigned char grub_cpuid_has_longmode; Index: commands/i386/cpuid.c =================================================================== --- commands/i386/cpuid.c (revision 2626) +++ commands/i386/cpuid.c (working copy) @@ -1,7 +1,7 @@ /* cpuid.c - test for CPU features */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006, 2007 Free Software Foundation, Inc. + * Copyright (C) 2006, 2007, 2009 Free Software Foundation, Inc. * Based on gcc/gcc/config/i386/driver-i386.c * * GRUB is free software: you can redistribute it and/or modify @@ -24,6 +24,7 @@ #include #include #include +#include #define cpuid(num,a,b,c,d) \ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" \ @@ -38,14 +39,14 @@ static const struct grub_arg_option options[] = #define bit_LM (1 << 29) -static unsigned char has_longmode = 0; +unsigned char grub_cpuid_has_longmode = 0; static grub_err_t grub_cmd_cpuid (grub_extcmd_t cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), char **args __attribute__ ((unused))) { - return has_longmode ? GRUB_ERR_NONE + return grub_cpuid_has_longmode ? GRUB_ERR_NONE : grub_error (GRUB_ERR_TEST_FAILURE, "false"); } @@ -55,7 +56,7 @@ GRUB_MOD_INIT(cpuid) { #ifdef __x86_64__ /* grub-emu */ - has_longmode = 1; + grub_cpuid_has_longmode = 1; #else unsigned int eax, ebx, ecx, edx; unsigned int max_level; @@ -82,7 +83,7 @@ GRUB_MOD_INIT(cpuid) goto done; cpuid (0x80000001, eax, ebx, ecx, edx); - has_longmode = !!(edx & bit_LM); + grub_cpuid_has_longmode = !!(edx & bit_LM); done: #endif Index: loader/i386/bsd.c =================================================================== --- loader/i386/bsd.c (revision 2626) +++ loader/i386/bsd.c (working copy) @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -871,6 +872,9 @@ grub_bsd_load_elf (grub_elf_t elf) { is_64bit = 1; + if (! grub_cpuid_has_longmode) + return grub_error (GRUB_ERR_BAD_OS, "Your CPU does not implement AMD64 architecture."); + /* FreeBSD has 64-bit entry point. */ if (kernel_type == KERNEL_TYPE_FREEBSD) { --GvXjxJ+pjyke8COw--