Line 45... |
Line 45... |
#include "targ-vals.h"
|
#include "targ-vals.h"
|
|
|
#include "or1ksim.h"
|
#include "or1ksim.h"
|
#include "or32sim.h"
|
#include "or32sim.h"
|
|
|
|
/* Define this to turn on debug messages */
|
|
/* #define OR32_SIM_DEBUG */
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
/*!Create a fully initialized simulator instance.
|
/*!Create a fully initialized simulator instance.
|
|
|
This function is called when the simulator is selected from the gdb command
|
This function is called when the simulator is selected from the gdb command
|
Line 108... |
Line 111... |
char *argv[])
|
char *argv[])
|
{
|
{
|
/*!A global record of the simulator description */
|
/*!A global record of the simulator description */
|
static SIM_DESC static_sd = NULL;
|
static SIM_DESC static_sd = NULL;
|
|
|
|
#ifdef OR32_SIM_DEBUG
|
|
printf ("sim_open called\n");
|
|
#endif
|
|
|
/* If static_sd is not yet allocated, we allocate it and mark the simulator
|
/* If static_sd is not yet allocated, we allocate it and mark the simulator
|
as not yet open. This is the only time we can process any custom
|
as not yet open. This is the only time we can process any custom
|
arguments and only time we initialize the simulator. */
|
arguments and only time we initialize the simulator. */
|
if (NULL == static_sd)
|
if (NULL == static_sd)
|
{
|
{
|
Line 129... |
Line 136... |
|
|
/* Count the number of arguments and see if we have specified either a
|
/* Count the number of arguments and see if we have specified either a
|
config file or a memory size. */
|
config file or a memory size. */
|
for (argc = 1; NULL != argv[argc]; argc++)
|
for (argc = 1; NULL != argv[argc]; argc++)
|
{
|
{
|
/* printf ("argv[%d] = %s\n", argc, argv[argc]); */
|
#ifdef OR32_SIM_DEBUG
|
|
printf ("argv[%d] = %s\n", argc, argv[argc]);
|
|
#endif
|
if ((0 == strcmp (argv[argc], "-f")) ||
|
if ((0 == strcmp (argv[argc], "-f")) ||
|
(0 == strcmp (argv[argc], "-file")) ||
|
(0 == strcmp (argv[argc], "-file")) ||
|
(0 == strcmp (argv[argc], "-m")) ||
|
(0 == strcmp (argv[argc], "-m")) ||
|
(0 == strcmp (argv[argc], "-memory")))
|
(0 == strcmp (argv[argc], "-memory")))
|
{
|
{
|
Line 162... |
Line 170... |
|
|
local_argv[i] = NULL;
|
local_argv[i] = NULL;
|
|
|
/* Try to initialize, then we can free the local argument vector. If we
|
/* Try to initialize, then we can free the local argument vector. If we
|
fail to initialize return NULL to indicate that failure. */
|
fail to initialize return NULL to indicate that failure. */
|
res == or1ksim_init (local_argc, local_argv, NULL, NULL, NULL);
|
res = or1ksim_init (local_argc, local_argv, NULL, NULL, NULL);
|
free (local_argv);
|
free (local_argv);
|
|
|
if (res)
|
if (res)
|
{
|
{
|
return NULL; /* Failure */
|
return NULL; /* Failure */
|
Line 203... |
Line 211... |
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
void
|
void
|
sim_close (SIM_DESC sd,
|
sim_close (SIM_DESC sd,
|
int quitting)
|
int quitting)
|
{
|
{
|
|
#ifdef OR32_SIM_DEBUG
|
|
printf ("sim_close called\n");
|
|
#endif
|
|
|
if (NULL == sd)
|
if (NULL == sd)
|
{
|
{
|
fprintf (stderr,
|
fprintf (stderr,
|
"Warning: Attempt to close non-open simulation: ignored.\n");
|
"Warning: Attempt to close non-open simulation: ignored.\n");
|
}
|
}
|
Line 254... |
Line 266... |
struct bfd *abfd,
|
struct bfd *abfd,
|
int from_tty)
|
int from_tty)
|
{
|
{
|
bfd *prog_bfd;
|
bfd *prog_bfd;
|
|
|
|
#ifdef OR32_SIM_DEBUG
|
|
printf ("sim_load called\n");
|
|
#endif
|
|
|
/* Use the built in loader, which will in turn use our write function. */
|
/* Use the built in loader, which will in turn use our write function. */
|
prog_bfd = sim_load_file (sd, sd->myname, sd->callback, prog, abfd,
|
prog_bfd = sim_load_file (sd, sd->myname, sd->callback, prog, abfd,
|
sd->is_debug, 0, sim_write);
|
sd->is_debug, 0, sim_write);
|
|
|
if (NULL == prog_bfd)
|
if (NULL == prog_bfd)
|
Line 312... |
Line 328... |
sim_create_inferior (SIM_DESC sd,
|
sim_create_inferior (SIM_DESC sd,
|
struct bfd *abfd,
|
struct bfd *abfd,
|
char **argv ATTRIBUTE_UNUSED,
|
char **argv ATTRIBUTE_UNUSED,
|
char **env ATTRIBUTE_UNUSED)
|
char **env ATTRIBUTE_UNUSED)
|
{
|
{
|
|
#ifdef OR32_SIM_DEBUG
|
|
printf ("sim_create_inferior called\n");
|
|
#endif
|
|
|
or1ksim_set_stall_state (1);
|
or1ksim_set_stall_state (1);
|
sd->entry_point = (NULL == abfd) ? OR32_RESET_EXCEPTION :
|
sd->entry_point = (NULL == abfd) ? OR32_RESET_EXCEPTION :
|
bfd_get_start_address (abfd);
|
bfd_get_start_address (abfd);
|
sd->resume_npc = OR32_RESET_EXCEPTION;
|
sd->resume_npc = OR32_RESET_EXCEPTION;
|
|
|
Line 341... |
Line 361... |
unsigned char *buf,
|
unsigned char *buf,
|
int len)
|
int len)
|
{
|
{
|
int res = or1ksim_read_mem (mem, buf, len);
|
int res = or1ksim_read_mem (mem, buf, len);
|
|
|
/* printf ("Reading %d bytes from 0x%08p\n", len, mem); */
|
#ifdef OR32_SIM_DEBUG
|
|
printf ("Reading %d bytes from 0x%08p\n", len, mem);
|
|
#endif
|
|
|
return res;
|
return res;
|
|
|
} /* sim_read () */
|
} /* sim_read () */
|
|
|
Line 365... |
Line 387... |
sim_write (SIM_DESC sd ATTRIBUTE_UNUSED,
|
sim_write (SIM_DESC sd ATTRIBUTE_UNUSED,
|
SIM_ADDR mem,
|
SIM_ADDR mem,
|
unsigned char *buf,
|
unsigned char *buf,
|
int len)
|
int len)
|
{
|
{
|
/* printf ("Writing %d bytes to 0x%08p\n", len, mem); */
|
#ifdef OR32_SIM_DEBUG
|
|
printf ("Writing %d bytes to 0x%08p\n", len, mem);
|
|
#endif
|
|
|
return or1ksim_write_mem ((unsigned int) mem, buf, len);
|
return or1ksim_write_mem ((unsigned int) mem, buf, len);
|
|
|
} /* sim_write () */
|
} /* sim_write () */
|
|
|
Line 402... |
Line 426... |
int len)
|
int len)
|
{
|
{
|
unsigned long int regval;
|
unsigned long int regval;
|
int res;
|
int res;
|
|
|
|
#ifdef OR32_SIM_DEBUG
|
|
printf ("sim_fetch_register (regno=%d\n) called\n", regno);
|
|
#endif
|
if (4 != len)
|
if (4 != len)
|
{
|
{
|
fprintf (stderr, "Invalid register length %d\n");
|
fprintf (stderr, "Invalid register length %d\n");
|
return 0;
|
return 0;
|
}
|
}
|
Line 425... |
Line 452... |
{
|
{
|
buf[0] = (regval >> 24) & 0xff;
|
buf[0] = (regval >> 24) & 0xff;
|
buf[1] = (regval >> 16) & 0xff;
|
buf[1] = (regval >> 16) & 0xff;
|
buf[2] = (regval >> 8) & 0xff;
|
buf[2] = (regval >> 8) & 0xff;
|
buf[3] = regval & 0xff;
|
buf[3] = regval & 0xff;
|
}
|
|
|
|
/* printf ("Read register 0x%02x, value 0x%08x\n", regno, regval); */
|
|
return res;
|
|
|
|
|
return 4; /* Success */
|
|
}
|
|
else
|
|
{
|
|
return 0; /* Failure */
|
|
}
|
} /* sim_fetch_register () */
|
} /* sim_fetch_register () */
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
/*!Store a register to the simulation
|
/*!Store a register to the simulation
|
Line 462... |
Line 491... |
unsigned char *buf,
|
unsigned char *buf,
|
int len)
|
int len)
|
{
|
{
|
unsigned int regval;
|
unsigned int regval;
|
|
|
|
#ifdef OR32_SIM_DEBUG
|
|
printf ("sim_store_register (regno=%d\n) called\n", regno);
|
|
#endif
|
|
|
if (4 != len)
|
if (4 != len)
|
{
|
{
|
fprintf (stderr, "Invalid register length %d\n");
|
fprintf (stderr, "Invalid register length %d\n");
|
return 0;
|
return 0;
|
}
|
}
|
Line 474... |
Line 507... |
regval = (((unsigned int) buf[0]) << 24) |
|
regval = (((unsigned int) buf[0]) << 24) |
|
(((unsigned int) buf[1]) << 16) |
|
(((unsigned int) buf[1]) << 16) |
|
(((unsigned int) buf[2]) << 8) |
|
(((unsigned int) buf[2]) << 8) |
|
(((unsigned int) buf[3]) );
|
(((unsigned int) buf[3]) );
|
|
|
/* printf ("Writing register 0x%02x, value 0x%08x\n", regno, regval); */
|
#ifdef OR32_SIM_DEBUG
|
|
printf ("Writing register 0x%02x, value 0x%08x\n", regno, regval);
|
|
#endif
|
|
|
if (OR32_NPC_REGNUM == regno)
|
if (OR32_NPC_REGNUM == regno)
|
{
|
{
|
sd->resume_npc = regval;
|
sd->resume_npc = regval;
|
return 4; /* Reg length in bytes */
|
return 4; /* Reg length in bytes */
|
Line 553... |
Line 588... |
|
|
unsigned long int retval; /* Return value on Or1ksim exit */
|
unsigned long int retval; /* Return value on Or1ksim exit */
|
|
|
int res; /* Result of a run. */
|
int res; /* Result of a run. */
|
|
|
|
#ifdef OR32_SIM_DEBUG
|
|
printf ("sim_resume called\n");
|
|
#endif
|
|
|
/* Clear Debug Reason Register and watchpoint break generation in Debug Mode
|
/* Clear Debug Reason Register and watchpoint break generation in Debug Mode
|
Register 2 */
|
Register 2 */
|
(void) or1ksim_write_spr (OR32_SPR_DRR, 0);
|
(void) or1ksim_write_spr (OR32_SPR_DRR, 0);
|
|
|
(void) or1ksim_read_spr (OR32_SPR_DMR2, &dmr2);
|
(void) or1ksim_read_spr (OR32_SPR_DMR2, &dmr2);
|
Line 584... |
Line 623... |
}
|
}
|
|
|
/* Set the NPC if it has changed */
|
/* Set the NPC if it has changed */
|
(void) or1ksim_read_reg (OR32_NPC_REGNUM, &npc);
|
(void) or1ksim_read_reg (OR32_NPC_REGNUM, &npc);
|
|
|
|
#ifdef OR32_SIM_DEBUG
|
|
printf (" npc = 0x%08lx, resume_npc = 0x%08lx\n", npc, sd->resume_npc);
|
|
#endif
|
|
|
if (npc != sd->resume_npc)
|
if (npc != sd->resume_npc)
|
{
|
{
|
(void) or1ksim_write_reg (OR32_NPC_REGNUM, sd->resume_npc);
|
(void) or1ksim_write_reg (OR32_NPC_REGNUM, sd->resume_npc);
|
}
|
}
|
|
|
Line 643... |
Line 686... |
@return Non-zero indicates that the simulator is able to handle the
|
@return Non-zero indicates that the simulator is able to handle the
|
request. */
|
request. */
|
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
int sim_stop (SIM_DESC sd ATTRIBUTE_UNUSED)
|
int sim_stop (SIM_DESC sd ATTRIBUTE_UNUSED)
|
{
|
{
|
|
#ifdef OR32_SIM_DEBUG
|
|
printf ("sim_stop called\n");
|
|
#endif
|
|
|
return 0; /* We don't support this */
|
return 0; /* We don't support this */
|
|
|
} /* sim_stop () */
|
} /* sim_stop () */
|
|
|
|
|