cpu-uname.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * cpu to uname machine name map
  3. *
  4. * Copyright (c) 2009 Loïc Minier
  5. *
  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.
  10. *
  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.
  15. *
  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/>.
  18. */
  19. #include <stdio.h>
  20. #include "qemu.h"
  21. //#include "qemu-common.h"
  22. #include "cpu-uname.h"
  23. /* return highest utsname machine name for emulated instruction set
  24. *
  25. * NB: the default emulated CPU ("any") might not match any existing CPU, e.g.
  26. * on ARM it has all features turned on, so there is no perfect arch string to
  27. * return here */
  28. const char *cpu_to_uname_machine(void *cpu_env)
  29. {
  30. #ifdef TARGET_ARM
  31. /* utsname machine name on linux arm is CPU arch name + endianness, e.g.
  32. * armv7l; to get a list of CPU arch names from the linux source, use:
  33. * grep arch_name: -A1 linux/arch/arm/mm/proc-*.S
  34. * see arch/arm/kernel/setup.c: setup_processor()
  35. *
  36. * to test by CPU id, compare cpu_env->cp15.c0_cpuid to ARM_CPUID_*
  37. * defines and to test by CPU feature, use arm_feature(cpu_env,
  38. * ARM_FEATURE_*) */
  39. /* in theory, endianness is configurable on some ARM CPUs, but this isn't
  40. * used in user mode emulation */
  41. #ifdef TARGET_WORDS_BIGENDIAN
  42. #define utsname_suffix "b"
  43. #else
  44. #define utsname_suffix "l"
  45. #endif
  46. if (arm_feature(cpu_env, ARM_FEATURE_V7))
  47. return "armv7" utsname_suffix;
  48. if (arm_feature(cpu_env, ARM_FEATURE_V6))
  49. return "armv6" utsname_suffix;
  50. /* earliest emulated CPU is ARMv5TE; qemu can emulate the 1026, but not its
  51. * Jazelle support */
  52. return "armv5te" utsname_suffix;
  53. #elif defined(TARGET_X86_64)
  54. return "x86-64";
  55. #elif defined(TARGET_I386)
  56. /* see arch/x86/kernel/cpu/bugs.c: check_bugs(), 386, 486, 586, 686 */
  57. uint32_t cpuid_version = ((CPUX86State *)cpu_env)->cpuid_version;
  58. int family = ((cpuid_version >> 8) & 0x0f) + ((cpuid_version >> 20) & 0xff);
  59. if (family == 4)
  60. return "i486";
  61. if (family == 5)
  62. return "i586";
  63. return "i686";
  64. #else
  65. /* default is #define-d in each arch/ subdir */
  66. return UNAME_MACHINE;
  67. #endif
  68. }