sim-hload.c revision 1.1.1.4 1 1.1 christos /* Generic load for hardware simulator models.
2 1.1.1.4 christos Copyright (C) 1997-2015 Free Software Foundation, Inc.
3 1.1 christos Contributed by Cygnus Support.
4 1.1 christos
5 1.1 christos This file is part of GDB, the GNU debugger.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1 christos
20 1.1 christos #include "sim-main.h"
21 1.1 christos #include "bfd.h"
22 1.1 christos #include "sim-utils.h"
23 1.1 christos #include "sim-assert.h"
24 1.1 christos
25 1.1 christos
26 1.1 christos /* Generic implementation of sim_load that works with simulators
27 1.1 christos modeling a hardware platform. */
28 1.1 christos
29 1.1 christos SIM_RC
30 1.1.1.4 christos sim_load (SIM_DESC sd, const char *prog_name, struct bfd *prog_bfd, int from_tty)
31 1.1 christos {
32 1.1 christos bfd *result_bfd;
33 1.1 christos
34 1.1 christos SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
35 1.1 christos if (sim_analyze_program (sd, prog_name, prog_bfd) != SIM_RC_OK)
36 1.1 christos return SIM_RC_FAIL;
37 1.1 christos SIM_ASSERT (STATE_PROG_BFD (sd) != NULL);
38 1.1 christos
39 1.1 christos /* NOTE: For historical reasons, older hardware simulators
40 1.1 christos incorrectly write the program sections at LMA interpreted as a
41 1.1 christos virtual address. This is still accommodated for backward
42 1.1 christos compatibility reasons. */
43 1.1 christos
44 1.1 christos result_bfd = sim_load_file (sd, STATE_MY_NAME (sd),
45 1.1 christos STATE_CALLBACK (sd),
46 1.1 christos prog_name,
47 1.1 christos STATE_PROG_BFD (sd),
48 1.1 christos STATE_OPEN_KIND (sd) == SIM_OPEN_DEBUG,
49 1.1 christos STATE_LOAD_AT_LMA_P (sd),
50 1.1 christos sim_write);
51 1.1 christos if (result_bfd == NULL)
52 1.1 christos {
53 1.1 christos bfd_close (STATE_PROG_BFD (sd));
54 1.1 christos STATE_PROG_BFD (sd) = NULL;
55 1.1 christos return SIM_RC_FAIL;
56 1.1 christos }
57 1.1 christos return SIM_RC_OK;
58 1.1 christos }
59