sim-if.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* Main simulator entry points specific to the IQ2000.
  2. Copyright (C) 2000-2015 Free Software Foundation, Inc.
  3. Contributed by Cygnus Solutions.
  4. This file is part of the GNU simulators.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #include "sim-main.h"
  16. #ifdef HAVE_STDLIB_H
  17. #include <stdlib.h>
  18. #endif
  19. #include "sim-options.h"
  20. #include "libiberty.h"
  21. #include "bfd.h"
  22. static void free_state (SIM_DESC);
  23. /* Records simulator descriptor so utilities like iq2000_dump_regs can be
  24. called from gdb. */
  25. SIM_DESC current_state;
  26. /* Cover function for sim_cgen_disassemble_insn. */
  27. void
  28. iq2000bf_disassemble_insn (SIM_CPU *cpu, const CGEN_INSN *insn,
  29. const ARGBUF *abuf, IADDR pc, char *buf)
  30. {
  31. sim_cgen_disassemble_insn(cpu, insn, abuf, pc, buf);
  32. }
  33. /* Cover function of sim_state_free to free the cpu buffers as well. */
  34. static void
  35. free_state (SIM_DESC sd)
  36. {
  37. if (STATE_MODULES (sd) != NULL)
  38. sim_module_uninstall (sd);
  39. sim_cpu_free_all (sd);
  40. sim_state_free (sd);
  41. }
  42. /* Create an instance of the simulator. */
  43. SIM_DESC
  44. sim_open (kind, callback, abfd, argv)
  45. SIM_OPEN_KIND kind;
  46. host_callback *callback;
  47. struct bfd *abfd;
  48. char **argv;
  49. {
  50. char c;
  51. int i;
  52. SIM_DESC sd = sim_state_alloc (kind, callback);
  53. /* The cpu data is kept in a separately allocated chunk of memory. */
  54. if (sim_cpu_alloc_all (sd, 1, cgen_cpu_max_extra_bytes ()) != SIM_RC_OK)
  55. {
  56. free_state (sd);
  57. return 0;
  58. }
  59. #if 0 /* FIXME: pc is in mach-specific struct */
  60. /* FIXME: watchpoints code shouldn't need this */
  61. {
  62. SIM_CPU *current_cpu = STATE_CPU (sd, 0);
  63. STATE_WATCHPOINTS (sd)->pc = &(PC);
  64. STATE_WATCHPOINTS (sd)->sizeof_pc = sizeof (PC);
  65. }
  66. #endif
  67. if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
  68. {
  69. free_state (sd);
  70. return 0;
  71. }
  72. #if 0 /* FIXME: 'twould be nice if we could do this */
  73. /* These options override any module options.
  74. Obviously ambiguity should be avoided, however the caller may wish to
  75. augment the meaning of an option. */
  76. if (extra_options != NULL)
  77. sim_add_option_table (sd, extra_options);
  78. #endif
  79. /* getopt will print the error message so we just have to exit if this fails.
  80. FIXME: Hmmm... in the case of gdb we need getopt to call
  81. print_filtered. */
  82. if (sim_parse_args (sd, argv) != SIM_RC_OK)
  83. {
  84. free_state (sd);
  85. return 0;
  86. }
  87. /* Allocate core managed memory. */
  88. sim_do_commandf (sd, "memory region 0x%lx,0x%lx", IQ2000_INSN_VALUE, IQ2000_INSN_MEM_SIZE);
  89. sim_do_commandf (sd, "memory region 0x%lx,0x%lx", IQ2000_DATA_VALUE, IQ2000_DATA_MEM_SIZE);
  90. /* check for/establish the reference program image */
  91. if (sim_analyze_program (sd,
  92. (STATE_PROG_ARGV (sd) != NULL
  93. ? *STATE_PROG_ARGV (sd)
  94. : NULL),
  95. abfd) != SIM_RC_OK)
  96. {
  97. free_state (sd);
  98. return 0;
  99. }
  100. /* Establish any remaining configuration options. */
  101. if (sim_config (sd) != SIM_RC_OK)
  102. {
  103. free_state (sd);
  104. return 0;
  105. }
  106. if (sim_post_argv_init (sd) != SIM_RC_OK)
  107. {
  108. free_state (sd);
  109. return 0;
  110. }
  111. /* Open a copy of the cpu descriptor table. */
  112. {
  113. CGEN_CPU_DESC cd = iq2000_cgen_cpu_open_1 (STATE_ARCHITECTURE (sd)->printable_name,
  114. CGEN_ENDIAN_BIG);
  115. for (i = 0; i < MAX_NR_PROCESSORS; ++i)
  116. {
  117. SIM_CPU *cpu = STATE_CPU (sd, i);
  118. CPU_CPU_DESC (cpu) = cd;
  119. CPU_DISASSEMBLER (cpu) = iq2000bf_disassemble_insn;
  120. }
  121. iq2000_cgen_init_dis (cd);
  122. }
  123. /* Initialize various cgen things not done by common framework.
  124. Must be done after iq2000_cgen_cpu_open. */
  125. cgen_init (sd);
  126. /* Store in a global so things like sparc32_dump_regs can be invoked
  127. from the gdb command line. */
  128. current_state = sd;
  129. return sd;
  130. }
  131. void
  132. sim_close (sd, quitting)
  133. SIM_DESC sd;
  134. int quitting;
  135. {
  136. iq2000_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd, 0)));
  137. sim_module_uninstall (sd);
  138. }
  139. SIM_RC
  140. sim_create_inferior (sd, abfd, argv, envp)
  141. SIM_DESC sd;
  142. struct bfd *abfd;
  143. char **argv;
  144. char **envp;
  145. {
  146. SIM_CPU *current_cpu = STATE_CPU (sd, 0);
  147. SIM_ADDR addr;
  148. if (abfd != NULL)
  149. addr = bfd_get_start_address (abfd);
  150. else
  151. addr = CPU2INSN(0);
  152. sim_pc_set (current_cpu, addr);
  153. #if 0
  154. STATE_ARGV (sd) = sim_copy_argv (argv);
  155. STATE_ENVP (sd) = sim_copy_argv (envp);
  156. #endif
  157. return SIM_RC_OK;
  158. }