2
0

cpu-target.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Target-specific parts of the CPU object
  3. *
  4. * Copyright (c) 2003 Fabrice Bellard
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library 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 GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "qemu/osdep.h"
  20. #include "qapi/error.h"
  21. #include "qemu/error-report.h"
  22. #include "qemu/qemu-print.h"
  23. #include "system/accel-ops.h"
  24. #include "system/cpus.h"
  25. #include "exec/tswap.h"
  26. #include "exec/replay-core.h"
  27. #include "exec/log.h"
  28. #include "accel/accel-cpu-target.h"
  29. #include "trace/trace-root.h"
  30. char *cpu_model_from_type(const char *typename)
  31. {
  32. const char *suffix = "-" CPU_RESOLVING_TYPE;
  33. if (!object_class_by_name(typename)) {
  34. return NULL;
  35. }
  36. if (g_str_has_suffix(typename, suffix)) {
  37. return g_strndup(typename, strlen(typename) - strlen(suffix));
  38. }
  39. return g_strdup(typename);
  40. }
  41. const char *parse_cpu_option(const char *cpu_option)
  42. {
  43. ObjectClass *oc;
  44. CPUClass *cc;
  45. gchar **model_pieces;
  46. const char *cpu_type;
  47. model_pieces = g_strsplit(cpu_option, ",", 2);
  48. if (!model_pieces[0]) {
  49. error_report("-cpu option cannot be empty");
  50. exit(1);
  51. }
  52. oc = cpu_class_by_name(CPU_RESOLVING_TYPE, model_pieces[0]);
  53. if (oc == NULL) {
  54. error_report("unable to find CPU model '%s'", model_pieces[0]);
  55. g_strfreev(model_pieces);
  56. exit(EXIT_FAILURE);
  57. }
  58. cpu_type = object_class_get_name(oc);
  59. cc = CPU_CLASS(oc);
  60. cc->parse_features(cpu_type, model_pieces[1], &error_fatal);
  61. g_strfreev(model_pieces);
  62. return cpu_type;
  63. }
  64. #ifndef cpu_list
  65. static void cpu_list_entry(gpointer data, gpointer user_data)
  66. {
  67. CPUClass *cc = CPU_CLASS(OBJECT_CLASS(data));
  68. const char *typename = object_class_get_name(OBJECT_CLASS(data));
  69. g_autofree char *model = cpu_model_from_type(typename);
  70. if (cc->deprecation_note) {
  71. qemu_printf(" %s (deprecated)\n", model);
  72. } else {
  73. qemu_printf(" %s\n", model);
  74. }
  75. }
  76. static void cpu_list(void)
  77. {
  78. GSList *list;
  79. list = object_class_get_list_sorted(TYPE_CPU, false);
  80. qemu_printf("Available CPUs:\n");
  81. g_slist_foreach(list, cpu_list_entry, NULL);
  82. g_slist_free(list);
  83. }
  84. #endif
  85. void list_cpus(void)
  86. {
  87. cpu_list();
  88. }
  89. /* enable or disable single step mode. EXCP_DEBUG is returned by the
  90. CPU loop after each instruction */
  91. void cpu_single_step(CPUState *cpu, int enabled)
  92. {
  93. if (cpu->singlestep_enabled != enabled) {
  94. cpu->singlestep_enabled = enabled;
  95. #if !defined(CONFIG_USER_ONLY)
  96. const AccelOpsClass *ops = cpus_get_accel();
  97. if (ops->update_guest_debug) {
  98. ops->update_guest_debug(cpu);
  99. }
  100. #endif
  101. trace_breakpoint_singlestep(cpu->cpu_index, enabled);
  102. }
  103. }
  104. void cpu_abort(CPUState *cpu, const char *fmt, ...)
  105. {
  106. va_list ap;
  107. va_list ap2;
  108. va_start(ap, fmt);
  109. va_copy(ap2, ap);
  110. fprintf(stderr, "qemu: fatal: ");
  111. vfprintf(stderr, fmt, ap);
  112. fprintf(stderr, "\n");
  113. cpu_dump_state(cpu, stderr, CPU_DUMP_FPU | CPU_DUMP_CCOP);
  114. if (qemu_log_separate()) {
  115. FILE *logfile = qemu_log_trylock();
  116. if (logfile) {
  117. fprintf(logfile, "qemu: fatal: ");
  118. vfprintf(logfile, fmt, ap2);
  119. fprintf(logfile, "\n");
  120. cpu_dump_state(cpu, logfile, CPU_DUMP_FPU | CPU_DUMP_CCOP);
  121. qemu_log_unlock(logfile);
  122. }
  123. }
  124. va_end(ap2);
  125. va_end(ap);
  126. replay_finish();
  127. #if defined(CONFIG_USER_ONLY)
  128. {
  129. struct sigaction act;
  130. sigfillset(&act.sa_mask);
  131. act.sa_handler = SIG_DFL;
  132. act.sa_flags = 0;
  133. sigaction(SIGABRT, &act, NULL);
  134. }
  135. #endif
  136. abort();
  137. }
  138. bool target_words_bigendian(void)
  139. {
  140. return TARGET_BIG_ENDIAN;
  141. }
  142. const char *target_name(void)
  143. {
  144. return TARGET_NAME;
  145. }