xref: /netbsd-src/external/gpl3/gdb/dist/sim/common/sim-utils.h (revision 88241920d21b339bf319c0e979ffda80c49a2936)
14e98e3e1Schristos /* Miscellaneous simulator utilities.
2*88241920Schristos    Copyright (C) 1997-2024 Free Software Foundation, Inc.
34e98e3e1Schristos    Contributed by Cygnus Support.
44e98e3e1Schristos 
54e98e3e1Schristos This file is part of GDB, the GNU debugger.
64e98e3e1Schristos 
74e98e3e1Schristos This program is free software; you can redistribute it and/or modify
84e98e3e1Schristos it under the terms of the GNU General Public License as published by
94e98e3e1Schristos the Free Software Foundation; either version 3 of the License, or
104e98e3e1Schristos (at your option) any later version.
114e98e3e1Schristos 
124e98e3e1Schristos This program is distributed in the hope that it will be useful,
134e98e3e1Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
144e98e3e1Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
154e98e3e1Schristos GNU General Public License for more details.
164e98e3e1Schristos 
174e98e3e1Schristos You should have received a copy of the GNU General Public License
184e98e3e1Schristos along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
194e98e3e1Schristos 
204e98e3e1Schristos #ifndef SIM_UTILS_H
214e98e3e1Schristos #define SIM_UTILS_H
224e98e3e1Schristos 
234b169a6bSchristos #include "ansidecl.h"
244b169a6bSchristos 
254e98e3e1Schristos /* Memory management with an allocator that clears memory before use. */
264e98e3e1Schristos 
274e98e3e1Schristos void *zalloc (unsigned long size);
284e98e3e1Schristos 
294e98e3e1Schristos #define ZALLOC(TYPE) (TYPE*)zalloc(sizeof (TYPE))
304e98e3e1Schristos #define NZALLOC(TYPE,N) (TYPE*)zalloc(sizeof (TYPE) * (N))
314e98e3e1Schristos 
324e98e3e1Schristos /* Turn VALUE into a string with commas.  */
334e98e3e1Schristos char *sim_add_commas (char *, int, unsigned long);
344e98e3e1Schristos 
354e98e3e1Schristos /* Utilities for elapsed time reporting.  */
364e98e3e1Schristos 
374e98e3e1Schristos /* Opaque type, known only inside sim_elapsed_time_foo fns. Externally
384e98e3e1Schristos    it is known to never have the value zero. */
394e98e3e1Schristos typedef unsigned long SIM_ELAPSED_TIME;
404e98e3e1Schristos 
414e98e3e1Schristos 
424e98e3e1Schristos /* Get reference point for future call to sim_time_elapsed.  */
434e98e3e1Schristos SIM_ELAPSED_TIME sim_elapsed_time_get (void);
444e98e3e1Schristos 
454e98e3e1Schristos /* Elapsed time in milliseconds since START.  */
464e98e3e1Schristos unsigned long sim_elapsed_time_since (SIM_ELAPSED_TIME start);
474e98e3e1Schristos 
484e98e3e1Schristos /* Utilities for manipulating the load image.  */
494e98e3e1Schristos 
50837edd6bSchristos SIM_RC sim_analyze_program (SIM_DESC sd, const char *prog_name,
514e98e3e1Schristos 			    struct bfd *prog_bfd);
524e98e3e1Schristos 
534e98e3e1Schristos /* Load program PROG into the simulator using the function DO_LOAD.
544e98e3e1Schristos    If PROG_BFD is non-NULL, the file has already been opened.
554e98e3e1Schristos    If VERBOSE_P is non-zero statistics are printed of each loaded section
564e98e3e1Schristos    and the transfer rate (for consistency with gdb).
574e98e3e1Schristos    If LMA_P is non-zero the program sections are loaded at the LMA
584e98e3e1Schristos    rather than the VMA
594e98e3e1Schristos    If this fails an error message is printed and NULL is returned.
604e98e3e1Schristos    If it succeeds the bfd is returned.
614e98e3e1Schristos    NOTE: For historical reasons, older hardware simulators incorrectly
624e98e3e1Schristos    write the program sections at LMA interpreted as a virtual address.
634e98e3e1Schristos    This is still accommodated for backward compatibility reasons. */
644e98e3e1Schristos 
654b169a6bSchristos typedef struct host_callback_struct host_callback;
66*88241920Schristos typedef uint64_t sim_write_fn (SIM_DESC sd, uint64_t mem,
67*88241920Schristos 			       const void *buf, uint64_t length);
684e98e3e1Schristos struct bfd *sim_load_file (SIM_DESC sd, const char *myname,
69837edd6bSchristos 			   host_callback *callback, const char *prog,
704e98e3e1Schristos 			   struct bfd *prog_bfd, int verbose_p,
714e98e3e1Schristos 			   int lma_p, sim_write_fn do_load);
724e98e3e1Schristos 
734e98e3e1Schristos /* Internal version of sim_do_command, include formatting */
744b169a6bSchristos void sim_do_commandf (SIM_DESC sd, const char *fmt, ...)
754b169a6bSchristos     ATTRIBUTE_PRINTF (2, 3);
764e98e3e1Schristos 
774e98e3e1Schristos 
784e98e3e1Schristos /* sim-basics.h defines a number of enumerations, convert each of them
794e98e3e1Schristos    to a string representation */
804e98e3e1Schristos const char *map_to_str (unsigned map);
814e98e3e1Schristos const char *access_to_str (unsigned access);
824e98e3e1Schristos const char *transfer_to_str (unsigned transfer);
834e98e3e1Schristos 
844e98e3e1Schristos #endif
85