diff options
author | Roland McGrath <roland@gnu.org> | 1999-07-11 01:49:09 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 1999-07-11 01:49:09 +0000 |
commit | 19c9a2509802b36e034f7084ce637791eab57683 (patch) | |
tree | ac71ec73eec3e904326c1076028588280d0b45d0 /exec | |
parent | f74ed6f7bb7aa061c75a387763390ab36d83395d (diff) |
1999-07-10 Roland McGrath <roland@baalperazim.frob.com>
* hostarch.c (mach_host_elf_machine): Replaced with ...
(elf_machine_matches_host): New function. Instead of returning
an ELF EM_* code, take one and check if it matches the host;
operate only on mach_host_self(), cache results,
Grok CPU_TYPE_{I486,PENTIUM,PENTIUMPRO} to accept EM_386 or EM_486.
Grok POWERPC, ALPHA, HPPA types.
* exec.c (check_elf): Call elf_machine_matches_host instead of
comparing against elf_machine.
(load_section): #if 0 out no-op code that uses elf_machine.
* priv.h (elf_machine_matches_host): Declare it.
(elf_machine, mach_host_elf_machine): Remove decls.
* main.c (main) [!BFD]: Don't call mach_host_elf_machine.
(elf_machine): Variable removed.
Diffstat (limited to 'exec')
-rw-r--r-- | exec/hostarch.c | 67 |
1 files changed, 41 insertions, 26 deletions
diff --git a/exec/hostarch.c b/exec/hostarch.c index 2bb9d11f..e62e666f 100644 --- a/exec/hostarch.c +++ b/exec/hostarch.c @@ -1,6 +1,6 @@ /* Determine the BFD and ELF architecture and machine flavor from a Mach host port. Used by the exec and core servers. - Copyright (C) 1992, 1993, 1995, 1996 Free Software Foundation, Inc. + Copyright (C) 1992, 1993, 1995, 1996, 1999 Free Software Foundation, Inc. Written by Roland McGrath. This file is part of the GNU Hurd. @@ -10,7 +10,7 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. -The GNU Hurd is distributed in the hope that it will be useful, +The GNU Hurd 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. @@ -26,49 +26,64 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <elf.h> error_t -mach_host_elf_machine (host_t host, - Elf32_Half *e_machine) +elf_machine_matches_host (Elf32_Half e_machine) { - error_t err; + static void *host_type; /* Cached entry into the switch below. */ struct host_basic_info hostinfo; - mach_msg_type_number_t hostinfocnt = HOST_BASIC_INFO_COUNT; - err = host_info (host, HOST_BASIC_INFO, - (natural_t *) &hostinfo, &hostinfocnt); - if (err) - return err; + if (host_type) + goto *host_type; + else + { + error_t err; + mach_msg_type_number_t hostinfocnt = HOST_BASIC_INFO_COUNT; + + err = host_info (mach_host_self (), HOST_BASIC_INFO, + (natural_t *) &hostinfo, &hostinfocnt); + if (err) + return err; + assert (hostinfocnt == HOST_BASIC_INFO_COUNT); + } +#define CACHE(test) ({ __label__ here; host_type = &&here; \ + here: return (test) ? 0 : ENOEXEC; }) switch (hostinfo.cpu_type) { - default: - *e_machine = EM_NONE; - break; - case CPU_TYPE_MC68020: case CPU_TYPE_MC68030: case CPU_TYPE_MC68040: - *e_machine = EM_68K; - break; + CACHE (e_machine == EM_68K); case CPU_TYPE_I860: - *e_machine = EM_860; - break; + CACHE (e_machine == EM_860); case CPU_TYPE_MIPS: - *e_machine = EM_MIPS; - break; + CACHE (e_machine == EM_MIPS); case CPU_TYPE_MC88000: - *e_machine = EM_88K; - break; + CACHE (e_machine == EM_88K); case CPU_TYPE_SPARC: - *e_machine = EM_SPARC; - break; + CACHE (e_machine == EM_SPARC); case CPU_TYPE_I386: - *e_machine = EM_386; - break; + CACHE (e_machine == EM_386); + case CPU_TYPE_I486: + case CPU_TYPE_PENTIUM: + case CPU_TYPE_PENTIUMPRO: + CACHE (e_machine == EM_386 || e_machine == EM_486); + + case CPU_TYPE_POWERPC: + CACHE (e_machine == EM_PPC); + + case CPU_TYPE_ALPHA: + CACHE (e_machine == EM_ALPHA); + + case CPU_TYPE_HPPA: + CACHE (e_machine == EM_PARISC); + + default: + return EGRATUITOUS; /* XXX */ } return 0; |