2 * cpu to uname machine name map
4 * Copyright (c) 2009 Loïc Minier
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
23 #include "user-internals.h"
24 //#include "qemu-common.h"
27 /* return highest utsname machine name for emulated instruction set
29 * NB: the default emulated CPU ("any") might not match any existing CPU, e.g.
30 * on ARM it has all features turned on, so there is no perfect arch string to
32 const char *cpu_to_uname_machine(void *cpu_env
)
34 #if defined(TARGET_ARM) && !defined(TARGET_AARCH64)
36 /* utsname machine name on linux arm is CPU arch name + endianness, e.g.
37 * armv7l; to get a list of CPU arch names from the linux source, use:
38 * grep arch_name: -A1 linux/arch/arm/mm/proc-*.S
39 * see arch/arm/kernel/setup.c: setup_processor()
42 /* in theory, endianness is configurable on some ARM CPUs, but this isn't
43 * used in user mode emulation */
44 #ifdef TARGET_WORDS_BIGENDIAN
45 #define utsname_suffix "b"
47 #define utsname_suffix "l"
49 if (arm_feature(cpu_env
, ARM_FEATURE_V7
))
50 return "armv7" utsname_suffix
;
51 if (arm_feature(cpu_env
, ARM_FEATURE_V6
))
52 return "armv6" utsname_suffix
;
53 /* earliest emulated CPU is ARMv5TE; qemu can emulate the 1026, but not its
55 return "armv5te" utsname_suffix
;
56 #elif defined(TARGET_I386) && !defined(TARGET_X86_64)
57 /* see arch/x86/kernel/cpu/bugs.c: check_bugs(), 386, 486, 586, 686 */
58 CPUState
*cpu
= env_cpu((CPUX86State
*)cpu_env
);
59 int family
= object_property_get_int(OBJECT(cpu
), "family", NULL
);
68 /* default is #define-d in each arch/ subdir */
74 #define COPY_UTSNAME_FIELD(dest, src) \
76 memcpy((dest), (src), MIN(sizeof(src), sizeof(dest))); \
77 (dest)[sizeof(dest) - 1] = '\0'; \
80 int sys_uname(struct new_utsname
*buf
)
82 struct utsname uts_buf
;
84 if (uname(&uts_buf
) < 0)
88 * Just in case these have some differences, we
89 * translate utsname to new_utsname (which is the
90 * struct linux kernel uses).
93 memset(buf
, 0, sizeof(*buf
));
94 COPY_UTSNAME_FIELD(buf
->sysname
, uts_buf
.sysname
);
95 COPY_UTSNAME_FIELD(buf
->nodename
, uts_buf
.nodename
);
96 COPY_UTSNAME_FIELD(buf
->release
, uts_buf
.release
);
97 COPY_UTSNAME_FIELD(buf
->version
, uts_buf
.version
);
98 COPY_UTSNAME_FIELD(buf
->machine
, uts_buf
.machine
);
100 COPY_UTSNAME_FIELD(buf
->domainname
, uts_buf
.domainname
);
104 #undef COPY_UTSNAME_FIELD
107 static int relstr_to_int(const char *s
)
109 /* Convert a uname release string like "2.6.18" to an integer
110 * of the form 0x020612. (Beware that 0x020612 is *not* 2.6.12.)
115 for (i
= 0; i
< 3; i
++) {
117 while (*s
>= '0' && *s
<= '9') {
122 tmp
= (tmp
<< 8) + n
;
130 int get_osversion(void)
132 static int osversion
;
133 struct new_utsname buf
;
138 if (qemu_uname_release
&& *qemu_uname_release
) {
139 s
= qemu_uname_release
;
145 osversion
= relstr_to_int(s
);
149 void init_qemu_uname_release(void)
151 /* Initialize qemu_uname_release for later use.
152 * If the host kernel is too old and the user hasn't asked for
153 * a specific fake version number, we might want to fake a minimum
154 * target kernel version.
156 struct new_utsname buf
;
158 if (qemu_uname_release
&& *qemu_uname_release
) {
162 if (sys_uname(&buf
)) {
166 if (relstr_to_int(buf
.release
) < relstr_to_int(UNAME_MINIMUM_RELEASE
)) {
167 qemu_uname_release
= UNAME_MINIMUM_RELEASE
;