]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/iq2000/iq2000.c
Do not use old-style definitions in sim
[thirdparty/binutils-gdb.git] / sim / iq2000 / iq2000.c
CommitLineData
edece237 1/* IQ2000 simulator support code
3666a048 2 Copyright (C) 2000-2021 Free Software Foundation, Inc.
edece237
CV
3 Contributed by Cygnus Support.
4
5 This file is part of the GNU simulators.
6
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
4744ac1b
JB
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
edece237
CV
11
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.
16
4744ac1b
JB
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/>. */
edece237
CV
19
20#define WANT_CPU
21#define WANT_CPU_IQ2000BF
22
23#include "sim-main.h"
24#include "cgen-mem.h"
25#include "cgen-ops.h"
26
27enum
28{
29 GPR0_REGNUM = 0,
30 NR_GPR = 32,
31 PC_REGNUM = 32
32};
33
34enum libgloss_syscall
35{
36 SYS_exit = 1,
37 SYS_open = 2,
38 SYS_close = 3,
39 SYS_read = 4,
40 SYS_write = 5,
41 SYS_lseek = 6,
42 SYS_unlink = 7,
43 SYS_getpid = 8,
44 SYS_kill = 9,
45 SYS_fstat = 10,
46 SYS_argvlen = 12,
47 SYS_argv = 13,
48 SYS_chdir = 14,
49 SYS_stat = 15,
50 SYS_chmod = 16,
51 SYS_utime = 17,
52 SYS_time = 18,
53 SYS_gettimeofday = 19,
54 SYS_times = 20
55};
56
57/* Read a null terminated string from memory, return in a buffer */
58static char *
81e6e8ae 59fetch_str (SIM_CPU *current_cpu, PCADDR pc, DI addr)
edece237
CV
60{
61 char *buf;
62 int nr = 0;
63 while (sim_core_read_1 (current_cpu,
64 pc, read_map, CPU2DATA(addr + nr)) != 0)
65 nr++;
66 buf = NZALLOC (char, nr + 1);
67 sim_read (CPU_STATE (current_cpu), CPU2DATA(addr), buf, nr);
68 return buf;
69}
70
71void
72do_syscall (SIM_CPU *current_cpu, PCADDR pc)
73{
74#if 0
75 int syscall = H2T_4 (iq2000bf_h_gr_get (current_cpu, 11));
76#endif
77 int syscall_function = iq2000bf_h_gr_get (current_cpu, 4);
78 int i;
79 char *buf;
80 int PARM1 = iq2000bf_h_gr_get (current_cpu, 5);
81 int PARM2 = iq2000bf_h_gr_get (current_cpu, 6);
82 int PARM3 = iq2000bf_h_gr_get (current_cpu, 7);
83 const int ret_reg = 2;
84
85 switch (syscall_function)
86 {
87 case 0:
88 switch (H2T_4 (iq2000bf_h_gr_get (current_cpu, 11)))
89 {
90 case 0:
91 /* Pass. */
92 puts ("pass");
93 exit (0);
94 case 1:
95 /* Fail. */
96 puts ("fail");
97 exit (1);
98 }
99
100 case SYS_write:
101 buf = zalloc (PARM3);
102 sim_read (CPU_STATE (current_cpu), CPU2DATA(PARM2), buf, PARM3);
103 SET_H_GR (ret_reg,
104 sim_io_write (CPU_STATE (current_cpu),
105 PARM1, buf, PARM3));
d79fe0d6 106 free (buf);
edece237
CV
107 break;
108
109 case SYS_lseek:
110 SET_H_GR (ret_reg,
111 sim_io_lseek (CPU_STATE (current_cpu),
112 PARM1, PARM2, PARM3));
113 break;
114
115 case SYS_exit:
116 sim_engine_halt (CPU_STATE (current_cpu), current_cpu,
117 NULL, pc, sim_exited, PARM1);
118 break;
119
120 case SYS_read:
121 buf = zalloc (PARM3);
122 SET_H_GR (ret_reg,
123 sim_io_read (CPU_STATE (current_cpu),
124 PARM1, buf, PARM3));
125 sim_write (CPU_STATE (current_cpu), CPU2DATA(PARM2), buf, PARM3);
d79fe0d6 126 free (buf);
edece237
CV
127 break;
128
129 case SYS_open:
130 buf = fetch_str (current_cpu, pc, PARM1);
131 SET_H_GR (ret_reg,
132 sim_io_open (CPU_STATE (current_cpu),
133 buf, PARM2));
d79fe0d6 134 free (buf);
edece237
CV
135 break;
136
137 case SYS_close:
138 SET_H_GR (ret_reg,
139 sim_io_close (CPU_STATE (current_cpu), PARM1));
140 break;
141
142 case SYS_time:
143 SET_H_GR (ret_reg, time (0));
144 break;
145
146 default:
147 SET_H_GR (ret_reg, -1);
148 }
149}
150
151void
152do_break (SIM_CPU *current_cpu, PCADDR pc)
153{
154 SIM_DESC sd = CPU_STATE (current_cpu);
155 sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);
156}
157
158/* The semantic code invokes this for invalid (unrecognized) instructions. */
159
160SEM_PC
161sim_engine_invalid_insn (SIM_CPU *current_cpu, IADDR cia, SEM_PC vpc)
162{
163 SIM_DESC sd = CPU_STATE (current_cpu);
164 sim_engine_halt (sd, current_cpu, NULL, cia, sim_stopped, SIM_SIGILL);
165
166 return vpc;
167}
168
169
170/* Process an address exception. */
171
172void
173iq2000_core_signal (SIM_DESC sd, SIM_CPU *current_cpu, sim_cia cia,
174 unsigned int map, int nr_bytes, address_word addr,
175 transfer_type transfer, sim_core_signals sig)
176{
177 sim_core_signal (sd, current_cpu, cia, map, nr_bytes, addr,
178 transfer, sig);
179}
180
181
182/* Initialize cycle counting for an insn.
183 FIRST_P is non-zero if this is the first insn in a set of parallel
184 insns. */
185
186void
187iq2000bf_model_insn_before (SIM_CPU *cpu, int first_p)
188{
189 /* Do nothing. */
190}
191
192
193/* Record the cycles computed for an insn.
194 LAST_P is non-zero if this is the last insn in a set of parallel insns,
195 and we update the total cycle count.
196 CYCLES is the cycle count of the insn. */
197
198void
199iq2000bf_model_insn_after(SIM_CPU *cpu, int last_p, int cycles)
200{
201 /* Do nothing. */
202}
203
204
205int
206iq2000bf_model_iq2000_u_exec (SIM_CPU *cpu, const IDESC *idesc,
207 int unit_num, int referenced)
208{
209 return idesc->timing->units[unit_num].done;
210}
211
212PCADDR
213get_h_pc (SIM_CPU *cpu)
214{
215 return CPU_CGEN_HW(cpu)->h_pc;
216}
217
218void
219set_h_pc (SIM_CPU *cpu, PCADDR addr)
220{
221 CPU_CGEN_HW(cpu)->h_pc = addr | IQ2000_INSN_MASK;
222}
223
224int
225iq2000bf_fetch_register (SIM_CPU *cpu, int nr, unsigned char *buf, int len)
226{
227 if (nr >= GPR0_REGNUM
228 && nr < (GPR0_REGNUM + NR_GPR)
229 && len == 4)
230 {
231 *((unsigned32*)buf) =
232 H2T_4 (iq2000bf_h_gr_get (cpu, nr - GPR0_REGNUM));
233 return 4;
234 }
235 else if (nr == PC_REGNUM
236 && len == 4)
237 {
238 *((unsigned32*)buf) = H2T_4 (get_h_pc (cpu));
239 return 4;
240 }
241 else
242 return 0;
243}
244
245int
246iq2000bf_store_register (SIM_CPU *cpu, int nr, unsigned char *buf, int len)
247{
248 if (nr >= GPR0_REGNUM
249 && nr < (GPR0_REGNUM + NR_GPR)
250 && len == 4)
251 {
252 iq2000bf_h_gr_set (cpu, nr - GPR0_REGNUM, T2H_4 (*((unsigned32*)buf)));
253 return 4;
254 }
255 else if (nr == PC_REGNUM
256 && len == 4)
257 {
258 set_h_pc (cpu, T2H_4 (*((unsigned32*)buf)));
259 return 4;
260 }
261 else
262 return 0;
263}