Home | History | Annotate | Line # | Download | only in common
      1       1.1  christos /* Generic load for hardware simulator models.
      2  1.1.1.10  christos    Copyright (C) 1997-2024 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.1.9  christos /* This must come before any other includes.  */
     21   1.1.1.9  christos #include "defs.h"
     22   1.1.1.9  christos 
     23       1.1  christos #include "bfd.h"
     24   1.1.1.9  christos 
     25   1.1.1.9  christos #include "sim-main.h"
     26       1.1  christos #include "sim-utils.h"
     27       1.1  christos #include "sim-assert.h"
     28       1.1  christos 
     29       1.1  christos 
     30       1.1  christos /* Generic implementation of sim_load that works with simulators
     31       1.1  christos    modeling a hardware platform. */
     32       1.1  christos 
     33       1.1  christos SIM_RC
     34   1.1.1.4  christos sim_load (SIM_DESC sd, const char *prog_name, struct bfd *prog_bfd, int from_tty)
     35       1.1  christos {
     36       1.1  christos   bfd *result_bfd;
     37       1.1  christos 
     38       1.1  christos   SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
     39       1.1  christos   if (sim_analyze_program (sd, prog_name, prog_bfd) != SIM_RC_OK)
     40       1.1  christos     return SIM_RC_FAIL;
     41       1.1  christos   SIM_ASSERT (STATE_PROG_BFD (sd) != NULL);
     42       1.1  christos 
     43       1.1  christos   /* NOTE: For historical reasons, older hardware simulators
     44       1.1  christos      incorrectly write the program sections at LMA interpreted as a
     45       1.1  christos      virtual address.  This is still accommodated for backward
     46       1.1  christos      compatibility reasons. */
     47       1.1  christos 
     48       1.1  christos   result_bfd = sim_load_file (sd, STATE_MY_NAME (sd),
     49       1.1  christos 			      STATE_CALLBACK (sd),
     50       1.1  christos 			      prog_name,
     51       1.1  christos 			      STATE_PROG_BFD (sd),
     52       1.1  christos 			      STATE_OPEN_KIND (sd) == SIM_OPEN_DEBUG,
     53       1.1  christos 			      STATE_LOAD_AT_LMA_P (sd),
     54       1.1  christos 			      sim_write);
     55       1.1  christos   if (result_bfd == NULL)
     56       1.1  christos     {
     57       1.1  christos       bfd_close (STATE_PROG_BFD (sd));
     58       1.1  christos       STATE_PROG_BFD (sd) = NULL;
     59       1.1  christos       return SIM_RC_FAIL;
     60       1.1  christos     }
     61       1.1  christos   return SIM_RC_OK;
     62       1.1  christos }
     63