]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/common/sim-utils.h
sim: switch sim_{read,write} APIs to 64-bit all the time [PR sim/7504]
[thirdparty/binutils-gdb.git] / sim / common / sim-utils.h
CommitLineData
c906108c 1/* Miscellaneous simulator utilities.
4a94e368 2 Copyright (C) 1997-2022 Free Software Foundation, Inc.
c906108c
SS
3 Contributed by Cygnus Support.
4
5This file is part of GDB, the GNU debugger.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
4744ac1b
JB
9the Free Software Foundation; either version 3 of the License, or
10(at your option) any later version.
c906108c
SS
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
4744ac1b
JB
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
19
20#ifndef SIM_UTILS_H
21#define SIM_UTILS_H
22
843bf754
MF
23#include "ansidecl.h"
24
c906108c
SS
25/* Memory management with an allocator that clears memory before use. */
26
27void *zalloc (unsigned long size);
28
29#define ZALLOC(TYPE) (TYPE*)zalloc(sizeof (TYPE))
30#define NZALLOC(TYPE,N) (TYPE*)zalloc(sizeof (TYPE) * (N))
31
c906108c
SS
32/* Turn VALUE into a string with commas. */
33char *sim_add_commas (char *, int, unsigned long);
34
35/* Utilities for elapsed time reporting. */
36
37/* Opaque type, known only inside sim_elapsed_time_foo fns. Externally
38 it is known to never have the value zero. */
39typedef unsigned long SIM_ELAPSED_TIME;
40
41
42/* Get reference point for future call to sim_time_elapsed. */
43SIM_ELAPSED_TIME sim_elapsed_time_get (void);
44
45/* Elapsed time in milliseconds since START. */
46unsigned long sim_elapsed_time_since (SIM_ELAPSED_TIME start);
47
48/* Utilities for manipulating the load image. */
49
b2b255bd 50SIM_RC sim_analyze_program (SIM_DESC sd, const char *prog_name,
6b4a8935 51 struct bfd *prog_bfd);
c906108c
SS
52
53/* Load program PROG into the simulator using the function DO_LOAD.
54 If PROG_BFD is non-NULL, the file has already been opened.
55 If VERBOSE_P is non-zero statistics are printed of each loaded section
56 and the transfer rate (for consistency with gdb).
57 If LMA_P is non-zero the program sections are loaded at the LMA
58 rather than the VMA
59 If this fails an error message is printed and NULL is returned.
60 If it succeeds the bfd is returned.
61 NOTE: For historical reasons, older hardware simulators incorrectly
62 write the program sections at LMA interpreted as a virtual address.
63 This is still accommodated for backward compatibility reasons. */
64
ef5058ae 65typedef struct host_callback_struct host_callback;
63fd5b5d
MF
66typedef uint64_t sim_write_fn (SIM_DESC sd, uint64_t mem,
67 const void *buf, uint64_t length);
6b4a8935 68struct bfd *sim_load_file (SIM_DESC sd, const char *myname,
b2b255bd 69 host_callback *callback, const char *prog,
6b4a8935
AC
70 struct bfd *prog_bfd, int verbose_p,
71 int lma_p, sim_write_fn do_load);
c906108c
SS
72
73/* Internal version of sim_do_command, include formatting */
f08708cb
SM
74void sim_do_commandf (SIM_DESC sd, const char *fmt, ...)
75 ATTRIBUTE_PRINTF (2, 3);
c906108c
SS
76
77
c906108c
SS
78/* sim-basics.h defines a number of enumerations, convert each of them
79 to a string representation */
80const char *map_to_str (unsigned map);
81const char *access_to_str (unsigned access);
82const char *transfer_to_str (unsigned transfer);
83
84#endif