1 /* This file is part of the GDB simulators.
3 Copyright (C) 1997, Free Software Foundation
4 Condtributed by Cyngnus Solutions.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
40 engine_init (SIM_DESC sd
)
42 memset (&STATE_CPU (sd
, 0)->reg
, 0, sizeof STATE_CPU (sd
, 0)->reg
);
43 memset (&STATE_CPU (sd
, 0)->cia
, 0, sizeof STATE_CPU (sd
, 0)->cia
);
44 CPU_STATE (STATE_CPU (sd
, 0)) = sd
;
48 /* Mechanisms for stopping/restarting the simulation */
51 engine_error (SIM_DESC sd
,
53 instruction_address cia
,
59 sim_io_evprintf (sd
, fmt
, ap
);
64 sim_io_eprintf (sd
, "\n");
65 engine_halt (sd
, cpu
, cia
, sim_signalled
, SIGABRT
);
68 sim_io_error (sd
, " - aborting simulation");
72 engine_halt (SIM_DESC sd
,
74 instruction_address cia
,
79 sim_io_error (sd
, "engine_halt - bad longjmp");
81 sd
->siggnal
= siggnal
;
86 longjmp (sd
->path_to_halt
, 1);
90 engine_restart (SIM_DESC sd
,
92 instruction_address cia
)
95 sim_io_error (sd
, "engine_restart - bad longjmp");
98 longjmp(sd
->path_to_restart
, 1);
103 engine_run_until_stop (SIM_DESC sd
,
104 volatile int *keep_running
)
106 if (!setjmp (sd
->path_to_halt
))
108 instruction_address cia
;
109 sim_cpu
*cpu
= STATE_CPU (sd
, 0);
111 setjmp (sd
->path_to_restart
);
118 /* anulled instruction */
120 cia
.dp
= cia
.dp
+ sizeof (instruction_word
);
124 instruction_word insn
= IMEM (cia
.ip
);
125 cia
= idecode_issue (sd
, insn
, cia
);
128 while (*keep_running
);
129 engine_halt (sd
, cpu
, cia
, sim_stopped
, SIGINT
);
134 #if defined(WITH_TRACE)
135 /* Tracing support routines */
137 static char tic80_trace_buffer
[1024];
138 static int tic80_size_name
;
141 #define SIZE_DECIMAL 12
143 /* Initialize tracing by calculating the maximum name size */
145 tic80_init_trace (void)
148 int len
, max_len
= 0;
150 for (i
= 0; i
< (int)nr_itable_entries
; i
++) {
151 len
= strlen (itable
[i
].name
);
156 tic80_size_name
= max_len
+ sizeof(":m") - 1 + sizeof (":s") - 1;
159 /* Trace the result of an ALU operation with 2 integer inputs and an integer output */
161 tic80_trace_alu3 (int indx
,
166 char buf1
[SIZE_DECIMAL
+10], buf2
[SIZE_DECIMAL
+10], bufr
[SIZE_DECIMAL
+10];
168 if (!tic80_size_name
)
171 sprintf (bufr
, "(%ld)", (long) (signed32
) result
);
172 sprintf (buf1
, "(%ld)", (long) (signed32
) input1
);
173 sprintf (buf2
, "(%ld)", (long) (signed32
) input2
);
175 sprintf (tic80_trace_buffer
, "%-*s 0x%.*lx %-*s 0x%.*lx %-*s => 0x%.*lx %-*s",
176 tic80_size_name
, itable
[indx
].name
,
177 SIZE_HEX
, input1
, SIZE_DECIMAL
, buf1
,
178 SIZE_HEX
, input2
, SIZE_DECIMAL
, buf2
,
179 SIZE_HEX
, result
, SIZE_DECIMAL
, bufr
);
181 return tic80_trace_buffer
;
184 /* Trace the result of an ALU operation with 1 integer input and an integer output */
186 tic80_trace_alu2 (int indx
,
190 char bufi
[SIZE_DECIMAL
+10], bufr
[SIZE_DECIMAL
+10];
192 if (!tic80_size_name
)
195 sprintf (bufr
, "(%ld)", (long) (signed32
) result
);
196 sprintf (bufi
, "(%ld)", (long) (signed32
) input
);
198 sprintf (tic80_trace_buffer
, "%-*s 0x%.*lx %-*s %*s => 0x%.*lx %-*s",
199 tic80_size_name
, itable
[indx
].name
,
200 SIZE_HEX
, input
, SIZE_DECIMAL
, bufi
,
201 SIZE_HEX
+ SIZE_DECIMAL
+ 3, "",
202 SIZE_HEX
, result
, SIZE_DECIMAL
, bufr
);
204 return tic80_trace_buffer
;
207 /* Trace the result of a NOP operation */
209 tic80_trace_nop (int indx
)
211 if (!tic80_size_name
)
214 sprintf (tic80_trace_buffer
, "%s:", itable
[indx
].name
);
215 return tic80_trace_buffer
;
218 /* Trace the result of a data sink with one input */
220 tic80_trace_sink1 (int indx
, unsigned32 input
)
222 char buf
[SIZE_DECIMAL
+10];
224 if (!tic80_size_name
)
227 sprintf (buf
, "(%ld)", (long) (signed32
) input
);
228 sprintf (tic80_trace_buffer
, "%-*s: 0x%.*lx %-*s",
229 tic80_size_name
, itable
[indx
].name
,
230 SIZE_HEX
, input
, SIZE_DECIMAL
, buf
);
232 return tic80_trace_buffer
;
235 /* Trace the result of a data sink with two inputs */
237 tic80_trace_sink2 (int indx
, unsigned32 input1
, unsigned32 input2
)
239 char buf1
[SIZE_DECIMAL
+10], buf2
[SIZE_DECIMAL
+10];
241 if (!tic80_size_name
)
244 sprintf (buf1
, "(%ld)", (long) (signed32
) input1
);
245 sprintf (buf2
, "(%ld)", (long) (signed32
) input2
);
246 sprintf (tic80_trace_buffer
, "%-*s: 0x%.*lx %-*s 0x%.*lx %-*s",
247 tic80_size_name
, itable
[indx
].name
,
248 SIZE_HEX
, input1
, SIZE_DECIMAL
, buf1
,
249 SIZE_HEX
, input2
, SIZE_DECIMAL
, buf2
);
251 return tic80_trace_buffer
;
254 /* Trace the result of a conditional branch operation */
256 tic80_trace_cond_br (int indx
,
261 char buf
[SIZE_DECIMAL
+10];
263 if (!tic80_size_name
)
266 sprintf (buf
, "(%ld)", (long) (signed32
) cond
);
269 sprintf (tic80_trace_buffer
,
270 "%-*s 0x%.*lx %*s 0x%.*lx %-*s => 0x%.*lx",
271 tic80_size_name
, itable
[indx
].name
,
272 SIZE_HEX
, target
, SIZE_DECIMAL
, "",
273 SIZE_HEX
, cond
, SIZE_DECIMAL
, buf
,
276 sprintf (tic80_trace_buffer
,
277 "%-*s 0x%.*lx %*s 0x%.*lx %-*s => [fallthrough]",
278 tic80_size_name
, itable
[indx
].name
,
279 SIZE_HEX
, target
, SIZE_DECIMAL
, "",
280 SIZE_HEX
, cond
, SIZE_DECIMAL
, buf
);
282 return tic80_trace_buffer
;
285 /* Trace the result of a unconditional branch operation */
287 tic80_trace_ucond_br (int indx
,
290 if (!tic80_size_name
)
293 sprintf (tic80_trace_buffer
,
294 "%-*s 0x%.*lx %*s => 0x%.*lx",
295 tic80_size_name
, itable
[indx
].name
,
296 SIZE_HEX
, target
, (SIZE_DECIMAL
*2) + SIZE_HEX
+ 4, "",
299 return tic80_trace_buffer
;
302 /* Trace the result of a load or store operation with 2 integer addresses
303 and an integer output or input */
305 tic80_trace_ldst (int indx
,
313 char buf1
[SIZE_DECIMAL
+10], buf2
[SIZE_DECIMAL
+10], bufr
[SIZE_DECIMAL
+10];
316 if (!tic80_size_name
)
319 strcpy (name
, itable
[indx
].name
);
326 sprintf (bufr
, "(%ld)", (long) (signed32
) value
);
327 sprintf (buf1
, "(%ld)", (long) (signed32
) input1
);
328 sprintf (buf2
, "(%ld)", (long) (signed32
) input2
);
330 sprintf (tic80_trace_buffer
, "%-*s 0x%.*lx %-*s 0x%.*lx %-*s %s 0x%.*lx %-*s",
331 tic80_size_name
, name
,
332 SIZE_HEX
, input1
, SIZE_DECIMAL
, buf1
,
333 SIZE_HEX
, input2
, SIZE_DECIMAL
, buf2
,
334 (!st_p
) ? "=>" : "<=",
335 SIZE_HEX
, value
, SIZE_DECIMAL
, bufr
);
337 return tic80_trace_buffer
;
339 #endif /* WITH_TRACE */
This page took 0.036005 seconds and 4 git commands to generate.