2005-03-08 16:55:34 +08:00
|
|
|
/* IQ2000 simulator support code
|
2022-01-01 22:56:03 +08:00
|
|
|
Copyright (C) 2000-2022 Free Software Foundation, Inc.
|
2005-03-08 16:55:34 +08:00
|
|
|
Contributed by Cygnus Support.
|
|
|
|
|
|
|
|
This file is part of the GNU simulators.
|
|
|
|
|
|
|
|
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
|
2007-08-24 22:30:15 +08:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2005-03-08 16:55:34 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2007-08-24 22:30:15 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2005-03-08 16:55:34 +08:00
|
|
|
|
2021-05-02 06:05:23 +08:00
|
|
|
/* This must come before any other includes. */
|
|
|
|
#include "defs.h"
|
|
|
|
|
2005-03-08 16:55:34 +08:00
|
|
|
#define WANT_CPU
|
|
|
|
#define WANT_CPU_IQ2000BF
|
|
|
|
|
|
|
|
#include "sim-main.h"
|
2021-06-14 11:16:32 +08:00
|
|
|
#include "sim-signal.h"
|
2005-03-08 16:55:34 +08:00
|
|
|
#include "cgen-mem.h"
|
|
|
|
#include "cgen-ops.h"
|
2021-11-28 13:18:18 +08:00
|
|
|
#include "target-newlib-syscall.h"
|
2021-04-08 22:52:50 +08:00
|
|
|
#include <stdlib.h>
|
2005-03-08 16:55:34 +08:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
GPR0_REGNUM = 0,
|
|
|
|
NR_GPR = 32,
|
|
|
|
PC_REGNUM = 32
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Read a null terminated string from memory, return in a buffer */
|
|
|
|
static char *
|
Do not use old-style definitions in sim
This changes all the non-generated (hand-written) code in sim to use
"new" (post-K&R) style function definitions.
2021-04-08 Tom Tromey <tom@tromey.com>
* bpf.c (bpf_def_model_init): Use new-style declaration.
sim/common/ChangeLog
2021-04-08 Tom Tromey <tom@tromey.com>
* cgen-utils.c (RORQI, ROLQI, RORHI, ROLHI, RORSI, ROLSI): Use
new-style declaration.
sim/erc32/ChangeLog
2021-04-08 Tom Tromey <tom@tromey.com>
* sis.c (run_sim, main): Use new-style declaration.
* interf.c (run_sim, sim_open, sim_close, sim_load)
(sim_create_inferior, sim_store_register, sim_fetch_register)
(sim_info, sim_stop_reason, flush_windows, sim_do_command): Use
new-style declaration.
* help.c (usage, gen_help): Use new-style declaration.
* func.c (batch, set_regi, set_rega, disp_reg, limcalc)
(reset_stat, show_stat, init_bpt, int_handler, init_signals)
(disp_fpu, disp_regs, disp_ctrl, disp_mem, dis_mem, event)
(init_event, set_int, advance_time, now, wait_for_irq, check_bpt)
(reset_all, sys_reset, sys_halt): Use new-style declaration.
* float.c (get_accex, clear_accex, set_fsr): Use new-style
declaration.
* exec.c (sub_cc, add_cc, log_cc, dispatch_instruction, fpexec)
(chk_asi, execute_trap, check_interrupts, init_regs): Use
new-style declaration.
* erc32.c (init_sim, reset, decode_ersr, mecparerror)
(error_mode, decode_memcfg, decode_wcr, decode_mcr, sim_halt)
(close_port, exit_sim, mec_reset, mec_intack, chk_irq, mec_irq)
(set_sfsr, mec_read, mec_write, init_stdio, restore_stdio)
(port_init, read_uart, write_uart, flush_uart, uarta_tx)
(uartb_tx, uart_rx, uart_intr, uart_irq_start, wdog_intr)
(wdog_start, rtc_intr, rtc_start, rtc_counter_read)
(rtc_scaler_set, rtc_reload_set, gpt_intr, gpt_start)
(gpt_counter_read, gpt_scaler_set, gpt_reload_set, timer_ctrl)
(memory_read, memory_write, get_mem_ptr, sis_memory_write)
(sis_memory_read): Use new-style declaration.
sim/frv/ChangeLog
2021-04-08 Tom Tromey <tom@tromey.com>
* sim-if.c (sim_open, frv_sim_close, sim_create_inferior): Use
new-style declaration.
sim/h8300/ChangeLog
2021-04-08 Tom Tromey <tom@tromey.com>
* compile.c (cmdline_location): Use new-style declaration.
sim/iq2000/ChangeLog
2021-04-08 Tom Tromey <tom@tromey.com>
* sim-if.c (sim_open, sim_create_inferior): Use new-style
declaration.
* iq2000.c (fetch_str): Use new-style declaration.
sim/lm32/ChangeLog
2021-04-08 Tom Tromey <tom@tromey.com>
* sim-if.c (sim_open, sim_create_inferior): Use new-style
declaration.
sim/m32r/ChangeLog
2021-04-08 Tom Tromey <tom@tromey.com>
* sim-if.c (sim_open, sim_create_inferior): Use new-style
declaration.
2021-04-08 20:41:25 +08:00
|
|
|
fetch_str (SIM_CPU *current_cpu, PCADDR pc, DI addr)
|
2005-03-08 16:55:34 +08:00
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
int nr = 0;
|
|
|
|
while (sim_core_read_1 (current_cpu,
|
|
|
|
pc, read_map, CPU2DATA(addr + nr)) != 0)
|
|
|
|
nr++;
|
|
|
|
buf = NZALLOC (char, nr + 1);
|
2022-10-27 00:08:30 +08:00
|
|
|
sim_read (CPU_STATE (current_cpu), CPU2DATA(addr), buf, nr);
|
2005-03-08 16:55:34 +08:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
do_syscall (SIM_CPU *current_cpu, PCADDR pc)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
int syscall = H2T_4 (iq2000bf_h_gr_get (current_cpu, 11));
|
|
|
|
#endif
|
|
|
|
int syscall_function = iq2000bf_h_gr_get (current_cpu, 4);
|
|
|
|
int i;
|
|
|
|
char *buf;
|
|
|
|
int PARM1 = iq2000bf_h_gr_get (current_cpu, 5);
|
|
|
|
int PARM2 = iq2000bf_h_gr_get (current_cpu, 6);
|
|
|
|
int PARM3 = iq2000bf_h_gr_get (current_cpu, 7);
|
|
|
|
const int ret_reg = 2;
|
|
|
|
|
|
|
|
switch (syscall_function)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
switch (H2T_4 (iq2000bf_h_gr_get (current_cpu, 11)))
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
/* Pass. */
|
|
|
|
puts ("pass");
|
|
|
|
exit (0);
|
|
|
|
case 1:
|
|
|
|
/* Fail. */
|
|
|
|
puts ("fail");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2021-11-28 13:18:18 +08:00
|
|
|
case TARGET_NEWLIB_SYS_write:
|
2005-03-08 16:55:34 +08:00
|
|
|
buf = zalloc (PARM3);
|
2022-10-27 00:08:30 +08:00
|
|
|
sim_read (CPU_STATE (current_cpu), CPU2DATA(PARM2), buf, PARM3);
|
2005-03-08 16:55:34 +08:00
|
|
|
SET_H_GR (ret_reg,
|
|
|
|
sim_io_write (CPU_STATE (current_cpu),
|
|
|
|
PARM1, buf, PARM3));
|
2011-02-14 13:14:28 +08:00
|
|
|
free (buf);
|
2005-03-08 16:55:34 +08:00
|
|
|
break;
|
|
|
|
|
2021-11-28 13:18:18 +08:00
|
|
|
case TARGET_NEWLIB_SYS_lseek:
|
2005-03-08 16:55:34 +08:00
|
|
|
SET_H_GR (ret_reg,
|
|
|
|
sim_io_lseek (CPU_STATE (current_cpu),
|
|
|
|
PARM1, PARM2, PARM3));
|
|
|
|
break;
|
|
|
|
|
2021-11-28 13:18:18 +08:00
|
|
|
case TARGET_NEWLIB_SYS_exit:
|
2005-03-08 16:55:34 +08:00
|
|
|
sim_engine_halt (CPU_STATE (current_cpu), current_cpu,
|
|
|
|
NULL, pc, sim_exited, PARM1);
|
|
|
|
break;
|
|
|
|
|
2021-11-28 13:18:18 +08:00
|
|
|
case TARGET_NEWLIB_SYS_read:
|
2005-03-08 16:55:34 +08:00
|
|
|
buf = zalloc (PARM3);
|
|
|
|
SET_H_GR (ret_reg,
|
|
|
|
sim_io_read (CPU_STATE (current_cpu),
|
|
|
|
PARM1, buf, PARM3));
|
2022-10-12 19:46:42 +08:00
|
|
|
sim_write (CPU_STATE (current_cpu), CPU2DATA(PARM2),
|
|
|
|
(unsigned char *) buf, PARM3);
|
2011-02-14 13:14:28 +08:00
|
|
|
free (buf);
|
2005-03-08 16:55:34 +08:00
|
|
|
break;
|
|
|
|
|
2021-11-28 13:18:18 +08:00
|
|
|
case TARGET_NEWLIB_SYS_open:
|
2005-03-08 16:55:34 +08:00
|
|
|
buf = fetch_str (current_cpu, pc, PARM1);
|
|
|
|
SET_H_GR (ret_reg,
|
|
|
|
sim_io_open (CPU_STATE (current_cpu),
|
|
|
|
buf, PARM2));
|
2011-02-14 13:14:28 +08:00
|
|
|
free (buf);
|
2005-03-08 16:55:34 +08:00
|
|
|
break;
|
|
|
|
|
2021-11-28 13:18:18 +08:00
|
|
|
case TARGET_NEWLIB_SYS_close:
|
2005-03-08 16:55:34 +08:00
|
|
|
SET_H_GR (ret_reg,
|
|
|
|
sim_io_close (CPU_STATE (current_cpu), PARM1));
|
|
|
|
break;
|
|
|
|
|
2021-11-28 13:18:18 +08:00
|
|
|
case TARGET_NEWLIB_SYS_time:
|
2005-03-08 16:55:34 +08:00
|
|
|
SET_H_GR (ret_reg, time (0));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
SET_H_GR (ret_reg, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
do_break (SIM_CPU *current_cpu, PCADDR pc)
|
|
|
|
{
|
|
|
|
SIM_DESC sd = CPU_STATE (current_cpu);
|
|
|
|
sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The semantic code invokes this for invalid (unrecognized) instructions. */
|
|
|
|
|
|
|
|
SEM_PC
|
|
|
|
sim_engine_invalid_insn (SIM_CPU *current_cpu, IADDR cia, SEM_PC vpc)
|
|
|
|
{
|
|
|
|
SIM_DESC sd = CPU_STATE (current_cpu);
|
|
|
|
sim_engine_halt (sd, current_cpu, NULL, cia, sim_stopped, SIM_SIGILL);
|
|
|
|
|
|
|
|
return vpc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Process an address exception. */
|
|
|
|
|
|
|
|
void
|
|
|
|
iq2000_core_signal (SIM_DESC sd, SIM_CPU *current_cpu, sim_cia cia,
|
|
|
|
unsigned int map, int nr_bytes, address_word addr,
|
|
|
|
transfer_type transfer, sim_core_signals sig)
|
|
|
|
{
|
|
|
|
sim_core_signal (sd, current_cpu, cia, map, nr_bytes, addr,
|
|
|
|
transfer, sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize cycle counting for an insn.
|
|
|
|
FIRST_P is non-zero if this is the first insn in a set of parallel
|
|
|
|
insns. */
|
|
|
|
|
|
|
|
void
|
|
|
|
iq2000bf_model_insn_before (SIM_CPU *cpu, int first_p)
|
|
|
|
{
|
|
|
|
/* Do nothing. */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Record the cycles computed for an insn.
|
|
|
|
LAST_P is non-zero if this is the last insn in a set of parallel insns,
|
|
|
|
and we update the total cycle count.
|
|
|
|
CYCLES is the cycle count of the insn. */
|
|
|
|
|
|
|
|
void
|
|
|
|
iq2000bf_model_insn_after(SIM_CPU *cpu, int last_p, int cycles)
|
|
|
|
{
|
|
|
|
/* Do nothing. */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
iq2000bf_model_iq2000_u_exec (SIM_CPU *cpu, const IDESC *idesc,
|
|
|
|
int unit_num, int referenced)
|
|
|
|
{
|
|
|
|
return idesc->timing->units[unit_num].done;
|
|
|
|
}
|
|
|
|
|
|
|
|
PCADDR
|
|
|
|
get_h_pc (SIM_CPU *cpu)
|
|
|
|
{
|
|
|
|
return CPU_CGEN_HW(cpu)->h_pc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
set_h_pc (SIM_CPU *cpu, PCADDR addr)
|
|
|
|
{
|
|
|
|
CPU_CGEN_HW(cpu)->h_pc = addr | IQ2000_INSN_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2022-10-31 23:58:10 +08:00
|
|
|
iq2000bf_fetch_register (SIM_CPU *cpu, int nr, void *buf, int len)
|
2005-03-08 16:55:34 +08:00
|
|
|
{
|
|
|
|
if (nr >= GPR0_REGNUM
|
|
|
|
&& nr < (GPR0_REGNUM + NR_GPR)
|
|
|
|
&& len == 4)
|
|
|
|
{
|
2021-12-06 15:16:02 +08:00
|
|
|
*((uint32_t*)buf) =
|
2005-03-08 16:55:34 +08:00
|
|
|
H2T_4 (iq2000bf_h_gr_get (cpu, nr - GPR0_REGNUM));
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
else if (nr == PC_REGNUM
|
|
|
|
&& len == 4)
|
|
|
|
{
|
2021-12-06 15:16:02 +08:00
|
|
|
*((uint32_t*)buf) = H2T_4 (get_h_pc (cpu));
|
2005-03-08 16:55:34 +08:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2022-10-31 23:58:10 +08:00
|
|
|
iq2000bf_store_register (SIM_CPU *cpu, int nr, const void *buf, int len)
|
2005-03-08 16:55:34 +08:00
|
|
|
{
|
|
|
|
if (nr >= GPR0_REGNUM
|
|
|
|
&& nr < (GPR0_REGNUM + NR_GPR)
|
|
|
|
&& len == 4)
|
|
|
|
{
|
2021-12-06 15:16:02 +08:00
|
|
|
iq2000bf_h_gr_set (cpu, nr - GPR0_REGNUM, T2H_4 (*((uint32_t*)buf)));
|
2005-03-08 16:55:34 +08:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
else if (nr == PC_REGNUM
|
|
|
|
&& len == 4)
|
|
|
|
{
|
2021-12-06 15:16:02 +08:00
|
|
|
set_h_pc (cpu, T2H_4 (*((uint32_t*)buf)));
|
2005-03-08 16:55:34 +08:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|