home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gdb-4.16-base.tgz / gdb-4.16-base.tar / fsf / gdb / sim / arm / wrapper.c < prev   
C/C++ Source or Header  |  1995-11-20  |  5KB  |  311 lines

  1. /* run front end support for arm
  2.    Copyright (C) 1995 Free Software Foundation, Inc.
  3.  
  4. This file is part of ARM SIM
  5.  
  6. GNU CC 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, or (at your option)
  9. any later version.
  10.  
  11. GNU CC 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, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  19.  
  20. /* This file provides the interface between the simulator and run.c and gdb
  21.    (when the simulator is linked with gdb).
  22.    All simulator interaction should go through this file.
  23.  
  24.    Functions that begin with sim_ belong to the standard simulator interface.
  25.    Functions that begin with ARMul_ belong to the ARM simulator.
  26.    Functions that begin with arm_sim_ are additional functions necessary to
  27.    implement the interface.
  28. */
  29.  
  30. #include <stdio.h>
  31. #include <stdarg.h>
  32. #include <bfd.h>
  33. #include <signal.h>
  34. #include "callback.h"
  35. #include "remote-sim.h"
  36. #include "armdefs.h"
  37. #include "armemu.h"
  38. #include "dbg_rdi.h"
  39.  
  40. static struct ARMul_State *state;
  41.  
  42. /* Memory size (log2 (n)).  */
  43. static int mem_size = 21;
  44.  
  45. /* Non-zero to display start up banner, and maybe other things.  */
  46. static int verbosity;
  47.  
  48. static void 
  49. init ()
  50. {
  51.   static int done;
  52.  
  53.   if (!done)
  54.     {
  55.       ARMul_EmulateInit();
  56.       state = ARMul_NewState ();
  57.       ARMul_MemoryInit(state, 1 << mem_size);
  58.       ARMul_OSInit(state);
  59.       ARMul_CoProInit(state); 
  60.       state->verbose = verbosity;
  61.       done = 1;
  62.     }
  63. }
  64.  
  65. /* Must be called before initializing simulator.  */
  66.  
  67. void
  68. arm_sim_set_verbosity (v)
  69.      int v;
  70. {
  71.   verbosity = v;
  72. }
  73.  
  74. /* Must be called before initializing simulator.  */
  75.  
  76. void 
  77. arm_sim_set_mem_size (size)
  78.      int size;
  79. {
  80.   mem_size = size;
  81. }
  82.  
  83. void 
  84. arm_sim_set_profile ()
  85. {
  86. }
  87.  
  88. void 
  89. arm_sim_set_profile_size ()
  90. {
  91. }
  92.  
  93. void 
  94. ARMul_ConsolePrint (ARMul_State * state, const char *format,...)
  95. {
  96.   va_list ap;
  97.  
  98.   if (state->verbose)
  99.     {
  100.       va_start (ap, format);
  101.       vprintf (format, ap);
  102.       va_end (ap);
  103.     }
  104. }
  105.  
  106. ARMword 
  107. ARMul_Debug (ARMul_State * state, ARMword pc, ARMword instr)
  108. {
  109.  
  110. }
  111.  
  112. int
  113. sim_write (addr, buffer, size)
  114.      SIM_ADDR addr;
  115.      unsigned char *buffer;
  116.      int size;
  117. {
  118.   int i;
  119.   init ();
  120.   for (i = 0; i < size; i++)
  121.     {
  122.       ARMul_WriteByte (state, addr+i, buffer[i]);
  123.     }
  124.   return size;
  125. }
  126.  
  127. int
  128. sim_read (addr, buffer, size)
  129.      SIM_ADDR addr;
  130.      unsigned char *buffer;
  131.      int size;
  132. {
  133.   int i;
  134.   init ();
  135.   for (i = 0; i < size; i++)
  136.     {
  137.       buffer[i] = ARMul_ReadByte (state, addr + i);
  138.     }
  139.   return size;
  140. }
  141.  
  142. void 
  143. sim_trace ()
  144. {
  145. }
  146.  
  147. void
  148. sim_resume (step, siggnal)
  149.      int step, siggnal;
  150. {
  151.   state->EndCondition = 0;
  152.  
  153.   if (step)
  154.     {
  155.       state->Reg[15] = ARMul_DoInstr (state);
  156.       if (state->EndCondition == 0)
  157.     state->EndCondition = RDIError_BreakpointReached;
  158.     }
  159.   else
  160.     {
  161.       state->Reg[15] = ARMul_DoProg (state);
  162.     }
  163.  
  164.   FLUSHPIPE;
  165. }
  166.  
  167. void
  168. sim_create_inferior (start_address, argv, env)
  169.      SIM_ADDR start_address;
  170.      char **argv;
  171.      char **env;
  172. {
  173.   ARMul_SetPC(state, start_address);
  174. }
  175.  
  176. void
  177. sim_info (verbose)
  178.      int verbose;
  179. {
  180. }
  181.  
  182.  
  183. int 
  184. frommem (state, memory)
  185.      struct ARMul_State *state;
  186.      unsigned char *memory;
  187. {
  188.   if (state->bigendSig == HIGH)
  189.     {
  190.       return (memory[0] << 24)
  191.     | (memory[1] << 16)
  192.     | (memory[2] << 8)
  193.     | (memory[3] << 0);
  194.     }
  195.   else
  196.     {
  197.       return (memory[3] << 24)
  198.     | (memory[2] << 16)
  199.     | (memory[1] << 8)
  200.     | (memory[0] << 0);
  201.     }
  202. }
  203.  
  204.  
  205. void 
  206. tomem (state, memory,  val)
  207.      struct ARMul_State *state;
  208.      unsigned char *memory;
  209.      int val;
  210. {
  211.   if (state->bigendSig == HIGH)
  212.     {
  213.       memory[0] = val >> 24;
  214.       memory[1] = val >> 16;
  215.       memory[2] = val >> 8;
  216.       memory[3] = val >> 0;
  217.     }
  218.   else
  219.     {
  220.       memory[3] = val >> 24;
  221.       memory[2] = val >> 16;
  222.       memory[1] = val >> 8;
  223.       memory[0] = val >> 0;
  224.     }
  225. }
  226.  
  227. void
  228. sim_store_register (rn, memory)
  229.      int rn;
  230.      unsigned char *memory;
  231. {
  232.   init ();
  233.   ARMul_SetReg(state, state->Mode, rn, frommem (state, memory));
  234. }
  235.  
  236. void
  237. sim_fetch_register (rn, memory)
  238.      int rn;
  239.      unsigned char *memory;
  240. {
  241.   init ();
  242.   tomem (state, memory, ARMul_GetReg(state, state->Mode, rn));
  243. }
  244.  
  245.  
  246.  
  247.  
  248. void
  249. sim_open (name)
  250.      char *name;
  251. {
  252.   /* nothing to do */
  253. }
  254.  
  255. void
  256. sim_close (quitting)
  257.      int quitting;
  258. {
  259.   /* nothing to do */
  260. }
  261.  
  262. int
  263. sim_load (prog, from_tty)
  264.      char *prog;
  265.      int from_tty;
  266. {
  267.   /* Return nonzero so GDB will handle it.  */
  268.   return 1;
  269. }
  270.  
  271. void
  272. sim_stop_reason (reason, sigrc)
  273.      enum sim_stop *reason;
  274.      int *sigrc;
  275. {
  276.   if (state->EndCondition == 0)
  277.     {
  278.       *reason = sim_exited;
  279.       *sigrc = state->Reg[0] & 255;
  280.     }
  281.   else
  282.     {
  283.       *reason = sim_stopped;
  284.       if (state->EndCondition == RDIError_BreakpointReached)
  285.     *sigrc = SIGTRAP;
  286.       else
  287.     *sigrc = 0;
  288.     }
  289. }
  290.  
  291. void
  292. sim_kill ()
  293. {
  294.   /* nothing to do */
  295. }
  296.  
  297. void
  298. sim_do_command (cmd)
  299.      char *cmd;
  300. {
  301.   printf_filtered ("This simulator does not accept any commands.\n");
  302. }
  303.  
  304.  
  305. void
  306. sim_set_callbacks (ptr)
  307. struct host_callback_struct *ptr;
  308. {
  309.  
  310. }
  311.