166e63ce3Schristos /* Generic load for hardware simulator models.
2*1424dfb3Schristos    Copyright (C) 1997-2020 Free Software Foundation, Inc.
366e63ce3Schristos    Contributed by Cygnus Support.
466e63ce3Schristos 
566e63ce3Schristos This file is part of GDB, the GNU debugger.
666e63ce3Schristos 
766e63ce3Schristos This program is free software; you can redistribute it and/or modify
866e63ce3Schristos it under the terms of the GNU General Public License as published by
966e63ce3Schristos the Free Software Foundation; either version 3 of the License, or
1066e63ce3Schristos (at your option) any later version.
1166e63ce3Schristos 
1266e63ce3Schristos This program is distributed in the hope that it will be useful,
1366e63ce3Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
1466e63ce3Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1566e63ce3Schristos GNU General Public License for more details.
1666e63ce3Schristos 
1766e63ce3Schristos You should have received a copy of the GNU General Public License
1866e63ce3Schristos along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
1966e63ce3Schristos 
2066e63ce3Schristos #include "sim-main.h"
2166e63ce3Schristos #include "bfd.h"
2266e63ce3Schristos #include "sim-utils.h"
2366e63ce3Schristos #include "sim-assert.h"
2466e63ce3Schristos 
2566e63ce3Schristos 
2666e63ce3Schristos /* Generic implementation of sim_load that works with simulators
2766e63ce3Schristos    modeling a hardware platform. */
2866e63ce3Schristos 
2966e63ce3Schristos SIM_RC
sim_load(SIM_DESC sd,const char * prog_name,struct bfd * prog_bfd,int from_tty)30eaae8ed5Schristos sim_load (SIM_DESC sd, const char *prog_name, struct bfd *prog_bfd, int from_tty)
3166e63ce3Schristos {
3266e63ce3Schristos   bfd *result_bfd;
3366e63ce3Schristos 
3466e63ce3Schristos   SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
3566e63ce3Schristos   if (sim_analyze_program (sd, prog_name, prog_bfd) != SIM_RC_OK)
3666e63ce3Schristos     return SIM_RC_FAIL;
3766e63ce3Schristos   SIM_ASSERT (STATE_PROG_BFD (sd) != NULL);
3866e63ce3Schristos 
3966e63ce3Schristos   /* NOTE: For historical reasons, older hardware simulators
4066e63ce3Schristos      incorrectly write the program sections at LMA interpreted as a
4166e63ce3Schristos      virtual address.  This is still accommodated for backward
4266e63ce3Schristos      compatibility reasons. */
4366e63ce3Schristos 
4466e63ce3Schristos   result_bfd = sim_load_file (sd, STATE_MY_NAME (sd),
4566e63ce3Schristos 			      STATE_CALLBACK (sd),
4666e63ce3Schristos 			      prog_name,
4766e63ce3Schristos 			      STATE_PROG_BFD (sd),
4866e63ce3Schristos 			      STATE_OPEN_KIND (sd) == SIM_OPEN_DEBUG,
4966e63ce3Schristos 			      STATE_LOAD_AT_LMA_P (sd),
5066e63ce3Schristos 			      sim_write);
5166e63ce3Schristos   if (result_bfd == NULL)
5266e63ce3Schristos     {
5366e63ce3Schristos       bfd_close (STATE_PROG_BFD (sd));
5466e63ce3Schristos       STATE_PROG_BFD (sd) = NULL;
5566e63ce3Schristos       return SIM_RC_FAIL;
5666e63ce3Schristos     }
5766e63ce3Schristos   return SIM_RC_OK;
5866e63ce3Schristos }
59