Statistics
| Branch: | Revision:

root / linux-user / cpu-uname.c @ a4c075f1

History | View | Annotate | Download (2.5 kB)

1 da79030f Loïc Minier
/*
2 da79030f Loïc Minier
 *  cpu to uname machine name map
3 da79030f Loïc Minier
 *
4 da79030f Loïc Minier
 *  Copyright (c) 2009 Lo?c Minier
5 da79030f Loïc Minier
 *
6 da79030f Loïc Minier
 *  This program is free software; you can redistribute it and/or modify
7 da79030f Loïc Minier
 *  it under the terms of the GNU General Public License as published by
8 da79030f Loïc Minier
 *  the Free Software Foundation; either version 2 of the License, or
9 da79030f Loïc Minier
 *  (at your option) any later version.
10 da79030f Loïc Minier
 *
11 da79030f Loïc Minier
 *  This program is distributed in the hope that it will be useful,
12 da79030f Loïc Minier
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 da79030f Loïc Minier
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 da79030f Loïc Minier
 *  GNU General Public License for more details.
15 da79030f Loïc Minier
 *
16 da79030f Loïc Minier
 *  You should have received a copy of the GNU General Public License
17 da79030f Loïc Minier
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
18 da79030f Loïc Minier
 */
19 da79030f Loïc Minier
20 da79030f Loïc Minier
#include <stdio.h>
21 da79030f Loïc Minier
22 da79030f Loïc Minier
#include "qemu.h"
23 da79030f Loïc Minier
//#include "qemu-common.h"
24 da79030f Loïc Minier
#include "cpu-uname.h"
25 da79030f Loïc Minier
26 da79030f Loïc Minier
/* return highest utsname machine name for emulated instruction set
27 da79030f Loïc Minier
 *
28 da79030f Loïc Minier
 * NB: the default emulated CPU ("any") might not match any existing CPU, e.g.
29 da79030f Loïc Minier
 * on ARM it has all features turned on, so there is no perfect arch string to
30 da79030f Loïc Minier
 * return here */
31 da79030f Loïc Minier
const char *cpu_to_uname_machine(void *cpu_env)
32 da79030f Loïc Minier
{
33 da79030f Loïc Minier
#ifdef TARGET_ARM
34 da79030f Loïc Minier
    /* utsname machine name on linux arm is CPU arch name + endianness, e.g.
35 da79030f Loïc Minier
     * armv7l; to get a list of CPU arch names from the linux source, use:
36 da79030f Loïc Minier
     *     grep arch_name: -A1 linux/arch/arm/mm/proc-*.S
37 da79030f Loïc Minier
     * see arch/arm/kernel/setup.c: setup_processor()
38 da79030f Loïc Minier
     *
39 da79030f Loïc Minier
     * to test by CPU id, compare cpu_env->cp15.c0_cpuid to ARM_CPUID_*
40 da79030f Loïc Minier
     * defines and to test by CPU feature, use arm_feature(cpu_env,
41 da79030f Loïc Minier
     * ARM_FEATURE_*) */
42 da79030f Loïc Minier
43 da79030f Loïc Minier
    /* in theory, endianness is configurable on some ARM CPUs, but this isn't
44 da79030f Loïc Minier
     * used in user mode emulation */
45 da79030f Loïc Minier
#ifdef TARGET_WORDS_BIGENDIAN
46 da79030f Loïc Minier
#define utsname_suffix "b"
47 da79030f Loïc Minier
#else
48 da79030f Loïc Minier
#define utsname_suffix "l"
49 da79030f Loïc Minier
#endif
50 da79030f Loïc Minier
    if (arm_feature(cpu_env, ARM_FEATURE_V7))
51 da79030f Loïc Minier
        return "armv7" utsname_suffix;
52 da79030f Loïc Minier
    if (arm_feature(cpu_env, ARM_FEATURE_V6))
53 da79030f Loïc Minier
        return "armv6" utsname_suffix;
54 da79030f Loïc Minier
    /* earliest emulated CPU is ARMv5TE; qemu can emulate the 1026, but not its
55 da79030f Loïc Minier
     * Jazelle support */
56 da79030f Loïc Minier
    return "armv5te" utsname_suffix;
57 da79030f Loïc Minier
#elif defined(TARGET_X86_64)
58 da79030f Loïc Minier
    return "x86-64";
59 da79030f Loïc Minier
#elif defined(TARGET_I386)
60 da79030f Loïc Minier
    /* see arch/x86/kernel/cpu/bugs.c: check_bugs(), 386, 486, 586, 686 */
61 da79030f Loïc Minier
    uint32_t cpuid_version = ((CPUX86State *)cpu_env)->cpuid_version;
62 da79030f Loïc Minier
    int family = ((cpuid_version >> 8) & 0x0f) + ((cpuid_version >> 20) & 0xff);
63 da79030f Loïc Minier
    if (family == 4)
64 da79030f Loïc Minier
        return "i486";
65 da79030f Loïc Minier
    if (family == 5)
66 da79030f Loïc Minier
        return "i586";
67 da79030f Loïc Minier
    return "i686";
68 da79030f Loïc Minier
#else
69 da79030f Loïc Minier
    /* default is #define-d in each arch/ subdir */
70 da79030f Loïc Minier
    return UNAME_MACHINE;
71 da79030f Loïc Minier
#endif
72 da79030f Loïc Minier
}