1 /* IQ2000 simulator support code
2 Copyright (C) 2000-2019 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of the GNU simulators.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #define WANT_CPU_IQ2000BF
53 SYS_gettimeofday = 19,
57 /* Read a null terminated string from memory, return in a buffer */
59 fetch_str (current_cpu, pc, addr)
66 while (sim_core_read_1 (current_cpu,
67 pc, read_map, CPU2DATA(addr + nr)) != 0)
69 buf = NZALLOC (char, nr + 1);
70 sim_read (CPU_STATE (current_cpu), CPU2DATA(addr), buf, nr);
75 do_syscall (SIM_CPU *current_cpu, PCADDR pc)
78 int syscall = H2T_4 (iq2000bf_h_gr_get (current_cpu, 11));
80 int syscall_function = iq2000bf_h_gr_get (current_cpu, 4);
83 int PARM1 = iq2000bf_h_gr_get (current_cpu, 5);
84 int PARM2 = iq2000bf_h_gr_get (current_cpu, 6);
85 int PARM3 = iq2000bf_h_gr_get (current_cpu, 7);
86 const int ret_reg = 2;
88 switch (syscall_function)
91 switch (H2T_4 (iq2000bf_h_gr_get (current_cpu, 11)))
104 buf = zalloc (PARM3);
105 sim_read (CPU_STATE (current_cpu), CPU2DATA(PARM2), buf, PARM3);
107 sim_io_write (CPU_STATE (current_cpu),
114 sim_io_lseek (CPU_STATE (current_cpu),
115 PARM1, PARM2, PARM3));
119 sim_engine_halt (CPU_STATE (current_cpu), current_cpu,
120 NULL, pc, sim_exited, PARM1);
124 buf = zalloc (PARM3);
126 sim_io_read (CPU_STATE (current_cpu),
128 sim_write (CPU_STATE (current_cpu), CPU2DATA(PARM2), buf, PARM3);
133 buf = fetch_str (current_cpu, pc, PARM1);
135 sim_io_open (CPU_STATE (current_cpu),
142 sim_io_close (CPU_STATE (current_cpu), PARM1));
146 SET_H_GR (ret_reg, time (0));
150 SET_H_GR (ret_reg, -1);
155 do_break (SIM_CPU *current_cpu, PCADDR pc)
157 SIM_DESC sd = CPU_STATE (current_cpu);
158 sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);
161 /* The semantic code invokes this for invalid (unrecognized) instructions. */
164 sim_engine_invalid_insn (SIM_CPU *current_cpu, IADDR cia, SEM_PC vpc)
166 SIM_DESC sd = CPU_STATE (current_cpu);
167 sim_engine_halt (sd, current_cpu, NULL, cia, sim_stopped, SIM_SIGILL);
173 /* Process an address exception. */
176 iq2000_core_signal (SIM_DESC sd, SIM_CPU *current_cpu, sim_cia cia,
177 unsigned int map, int nr_bytes, address_word addr,
178 transfer_type transfer, sim_core_signals sig)
180 sim_core_signal (sd, current_cpu, cia, map, nr_bytes, addr,
185 /* Initialize cycle counting for an insn.
186 FIRST_P is non-zero if this is the first insn in a set of parallel
190 iq2000bf_model_insn_before (SIM_CPU *cpu, int first_p)
196 /* Record the cycles computed for an insn.
197 LAST_P is non-zero if this is the last insn in a set of parallel insns,
198 and we update the total cycle count.
199 CYCLES is the cycle count of the insn. */
202 iq2000bf_model_insn_after(SIM_CPU *cpu, int last_p, int cycles)
209 iq2000bf_model_iq2000_u_exec (SIM_CPU *cpu, const IDESC *idesc,
210 int unit_num, int referenced)
212 return idesc->timing->units[unit_num].done;
216 get_h_pc (SIM_CPU *cpu)
218 return CPU_CGEN_HW(cpu)->h_pc;
222 set_h_pc (SIM_CPU *cpu, PCADDR addr)
224 CPU_CGEN_HW(cpu)->h_pc = addr | IQ2000_INSN_MASK;
228 iq2000bf_fetch_register (SIM_CPU *cpu, int nr, unsigned char *buf, int len)
230 if (nr >= GPR0_REGNUM
231 && nr < (GPR0_REGNUM + NR_GPR)
234 *((unsigned32*)buf) =
235 H2T_4 (iq2000bf_h_gr_get (cpu, nr - GPR0_REGNUM));
238 else if (nr == PC_REGNUM
241 *((unsigned32*)buf) = H2T_4 (get_h_pc (cpu));
249 iq2000bf_store_register (SIM_CPU *cpu, int nr, unsigned char *buf, int len)
251 if (nr >= GPR0_REGNUM
252 && nr < (GPR0_REGNUM + NR_GPR)
255 iq2000bf_h_gr_set (cpu, nr - GPR0_REGNUM, T2H_4 (*((unsigned32*)buf)));
258 else if (nr == PC_REGNUM
261 set_h_pc (cpu, T2H_4 (*((unsigned32*)buf)));