1997-04-22 17:46:07 +00:00
|
|
|
/* This file is part of the program psim.
|
|
|
|
|
|
|
|
Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
|
|
|
|
Copyright (C) 1997, Free Software Foundation
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "bfd.h"
|
|
|
|
#include "sim-main.h"
|
1997-05-02 05:31:34 +00:00
|
|
|
#include "sim-utils.h"
|
|
|
|
#include "sim-options.h"
|
1997-04-22 17:46:07 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#else
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#define SIM_ADDR unsigned
|
|
|
|
|
|
|
|
SIM_DESC
|
1997-05-21 06:54:13 +00:00
|
|
|
sim_open (SIM_OPEN_KIND kind,
|
|
|
|
host_callback *callback,
|
1997-08-25 23:14:25 +00:00
|
|
|
struct _bfd *abfd,
|
1997-05-21 06:54:13 +00:00
|
|
|
char **argv)
|
1997-04-22 17:46:07 +00:00
|
|
|
{
|
1997-09-04 10:08:44 +00:00
|
|
|
char *buf;
|
1997-09-01 03:26:31 +00:00
|
|
|
SIM_DESC sd = sim_state_alloc (kind, callback);
|
1997-04-22 17:46:07 +00:00
|
|
|
|
1997-05-19 13:30:30 +00:00
|
|
|
if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
|
1997-04-22 17:46:07 +00:00
|
|
|
return 0;
|
|
|
|
|
1997-09-04 10:08:44 +00:00
|
|
|
#define TIC80_MEM_START 0x2000000
|
|
|
|
#define TIC80_MEM_SIZE 0x100000
|
|
|
|
|
|
|
|
/* main memory */
|
|
|
|
asprintf (&buf, "memory region 0x%lx,0x%lx",
|
|
|
|
TIC80_MEM_START, TIC80_MEM_SIZE);
|
|
|
|
sim_do_command (sd, buf);
|
|
|
|
free (buf);
|
|
|
|
/* interrupt memory */
|
|
|
|
sim_do_command (sd, "memory region 0x1010000,0x1000");
|
|
|
|
/* some memory at zero */
|
|
|
|
sim_do_command (sd, "memory region 0,0x100000");
|
|
|
|
|
1997-04-22 17:46:07 +00:00
|
|
|
/* getopt will print the error message so we just have to exit if this fails.
|
|
|
|
FIXME: Hmmm... in the case of gdb we need getopt to call
|
|
|
|
print_filtered. */
|
1997-05-19 13:30:30 +00:00
|
|
|
if (sim_parse_args (sd, argv) != SIM_RC_OK)
|
1997-04-24 07:50:16 +00:00
|
|
|
{
|
|
|
|
/* Uninstall the modules to avoid memory leaks,
|
|
|
|
file descriptor leaks, etc. */
|
1997-05-19 13:30:30 +00:00
|
|
|
sim_module_uninstall (sd);
|
1997-04-24 07:50:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-08-27 04:44:41 +00:00
|
|
|
/* check for/establish the a reference program image */
|
|
|
|
if (sim_analyze_program (sd,
|
|
|
|
(STATE_PROG_ARGV (sd) != NULL
|
|
|
|
? *STATE_PROG_ARGV (sd)
|
|
|
|
: NULL),
|
|
|
|
abfd) != SIM_RC_OK)
|
|
|
|
{
|
|
|
|
sim_module_uninstall (sd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* establish any remaining configuration options */
|
|
|
|
if (sim_config (sd) != SIM_RC_OK)
|
1997-08-25 23:14:25 +00:00
|
|
|
{
|
|
|
|
sim_module_uninstall (sd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-05-19 13:30:30 +00:00
|
|
|
if (sim_post_argv_init (sd) != SIM_RC_OK)
|
1997-04-24 07:50:16 +00:00
|
|
|
{
|
|
|
|
/* Uninstall the modules to avoid memory leaks,
|
|
|
|
file descriptor leaks, etc. */
|
1997-05-19 13:30:30 +00:00
|
|
|
sim_module_uninstall (sd);
|
1997-04-24 07:50:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1997-04-22 17:46:07 +00:00
|
|
|
|
|
|
|
/* FIXME: for now */
|
1997-05-19 13:30:30 +00:00
|
|
|
return sd;
|
1997-04-22 17:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
sim_close (SIM_DESC sd, int quitting)
|
|
|
|
{
|
1997-04-24 07:50:16 +00:00
|
|
|
/* Uninstall the modules to avoid memory leaks,
|
|
|
|
file descriptor leaks, etc. */
|
1997-05-19 13:30:30 +00:00
|
|
|
sim_module_uninstall (sd);
|
1997-04-22 17:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-04-24 12:06:27 +00:00
|
|
|
/* FIXME - these magic numbers need to be moved elsewhere */
|
|
|
|
|
|
|
|
#define SP_REGNUM 1 /* Contains address of top of stack */
|
|
|
|
#define FP_REGNUM 31 /* Contains address of executing stack frame */
|
|
|
|
#define PC_REGNUM 32 /* Contains program counter (FIXME?) */
|
|
|
|
#define NPC_REGNUM 33 /* Contains the next program counter (FIXME?) */
|
|
|
|
#define A0_REGNUM 34 /* Accumulator register 0 */
|
|
|
|
#define A3_REGNUM 37 /* Accumulator register 1 */
|
|
|
|
|
|
|
|
#define R0_REGNUM 0 /* General Purpose Register 0 - for sim */
|
|
|
|
#define Rn_REGNUM 31 /* Last General Purpose Register - for sim */
|
|
|
|
#define An_REGNUM A3_REGNUM /* Last Accumulator register - for sim */
|
|
|
|
|
1998-02-17 04:06:38 +00:00
|
|
|
int
|
|
|
|
sim_fetch_register (SIM_DESC sd, int regnr, unsigned char *buf, int length)
|
1997-04-22 17:46:07 +00:00
|
|
|
{
|
1997-05-16 03:27:40 +00:00
|
|
|
if (regnr == R0_REGNUM)
|
|
|
|
memset (buf, 0, sizeof (unsigned32));
|
|
|
|
else if (regnr > R0_REGNUM && regnr <= Rn_REGNUM)
|
1997-05-12 04:57:49 +00:00
|
|
|
*(unsigned32*)buf = H2T_4 (STATE_CPU (sd, 0)->reg[regnr - R0_REGNUM]);
|
1997-04-24 12:06:27 +00:00
|
|
|
else if (regnr == PC_REGNUM)
|
|
|
|
*(unsigned32*)buf = H2T_4 (STATE_CPU (sd, 0)->cia.ip);
|
|
|
|
else if (regnr == NPC_REGNUM)
|
|
|
|
*(unsigned32*)buf = H2T_4 (STATE_CPU (sd, 0)->cia.dp);
|
|
|
|
else if (regnr >= A0_REGNUM && regnr <= An_REGNUM)
|
|
|
|
*(unsigned64*)buf = H2T_8 (STATE_CPU (sd, 0)->acc[regnr - A0_REGNUM]);
|
|
|
|
else
|
|
|
|
sim_io_error (sd, "sim_fetch_register - unknown register nr %d", regnr);
|
1998-02-17 04:06:38 +00:00
|
|
|
return -1;
|
1997-04-22 17:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-02-17 04:06:38 +00:00
|
|
|
int
|
|
|
|
sim_store_register (SIM_DESC sd, int regnr, unsigned char *buf, int length)
|
1997-04-22 17:46:07 +00:00
|
|
|
{
|
1997-04-24 12:06:27 +00:00
|
|
|
if (regnr >= R0_REGNUM && regnr <= Rn_REGNUM)
|
1997-05-12 04:57:49 +00:00
|
|
|
STATE_CPU (sd, 0)->reg[regnr - R0_REGNUM] = T2H_4 (*(unsigned32*)buf);
|
1997-04-24 12:06:27 +00:00
|
|
|
else if (regnr == PC_REGNUM)
|
|
|
|
STATE_CPU (sd, 0)->cia.ip = T2H_4 (*(unsigned32*)buf);
|
|
|
|
else if (regnr == NPC_REGNUM)
|
|
|
|
STATE_CPU (sd, 0)->cia.dp = T2H_4 (*(unsigned32*)buf);
|
1997-08-09 04:54:08 +00:00
|
|
|
else if (regnr >= A0_REGNUM && regnr <= An_REGNUM)
|
1997-05-08 05:28:20 +00:00
|
|
|
STATE_CPU (sd, 0)->acc[regnr - A0_REGNUM] = T2H_8 (*(unsigned64*)buf);
|
1997-04-24 12:06:27 +00:00
|
|
|
else
|
1997-08-09 04:54:08 +00:00
|
|
|
sim_io_error (sd, "sim_store_register - unknown register nr %d", regnr);
|
1998-02-17 04:06:38 +00:00
|
|
|
return -1;
|
1997-04-22 17:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
sim_info (SIM_DESC sd, int verbose)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SIM_RC
|
|
|
|
sim_create_inferior (SIM_DESC sd,
|
1997-08-27 04:44:41 +00:00
|
|
|
struct _bfd *abfd,
|
1997-04-22 17:46:07 +00:00
|
|
|
char **argv,
|
|
|
|
char **envp)
|
|
|
|
{
|
1997-09-04 03:47:39 +00:00
|
|
|
/* clear all registers */
|
|
|
|
memset (&STATE_CPU (sd, 0)->reg, 0, sizeof (STATE_CPU (sd, 0)->reg));
|
|
|
|
memset (&STATE_CPU (sd, 0)->acc, 0, sizeof (STATE_CPU (sd, 0)->acc));
|
|
|
|
memset (&STATE_CPU (sd, 0)->cr, 0, sizeof (STATE_CPU (sd, 0)->cr));
|
|
|
|
STATE_CPU (sd, 0)->is_user_mode = 0;
|
|
|
|
memset (&STATE_CPU (sd, 0)->cia, 0, sizeof (STATE_CPU (sd, 0)->cia));
|
|
|
|
/* initialize any modules */
|
|
|
|
sim_module_init (sd);
|
|
|
|
/* set the stack-pointer/program counter */
|
1997-08-27 04:44:41 +00:00
|
|
|
if (abfd != NULL)
|
|
|
|
STATE_CPU (sd, 0)->cia.ip = bfd_get_start_address (abfd);
|
|
|
|
else
|
|
|
|
STATE_CPU (sd, 0)->cia.ip = 0;
|
|
|
|
STATE_CPU (sd, 0)->cia.dp = (STATE_CPU (sd, 0)->cia.ip
|
1997-04-22 17:46:07 +00:00
|
|
|
+ sizeof (instruction_word));
|
1997-05-07 13:58:52 +00:00
|
|
|
STATE_CPU (sd, 0)->cr[IE_CR] |= IE_CR_IE;
|
1997-04-29 08:41:15 +00:00
|
|
|
STATE_CPU (sd, 0)->reg[1] = TIC80_MEM_START + TIC80_MEM_SIZE - 16;
|
1997-04-22 17:46:07 +00:00
|
|
|
return SIM_RC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
sim_do_command (SIM_DESC sd, char *cmd)
|
|
|
|
{
|
1997-05-08 05:28:20 +00:00
|
|
|
if (sim_args_command (sd, cmd) != SIM_RC_OK)
|
|
|
|
sim_io_eprintf (sd, "Unknown command `%s'\n", cmd);
|
1997-04-22 17:46:07 +00:00
|
|
|
}
|