xref: /netbsd-src/external/gpl3/gdb.old/dist/sim/common/sim-cpu.c (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
1 /* CPU support.
2    Copyright (C) 1998-2023 Free Software Foundation, Inc.
3    Contributed by Cygnus Solutions.
4 
5 This file is part of GDB, the GNU debugger.
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
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
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 
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/>.  */
19 
20 /* This must come before any other includes.  */
21 #include "defs.h"
22 
23 #include <stdlib.h>
24 
25 #include "bfd.h"
26 
27 #include "sim-main.h"
28 
29 /* Allocate space for all cpus in the simulator.
30    Space for the cpu must currently exist prior to parsing ARGV.  */
31 /* ??? wip.  better solution must wait.  */
32 
33 SIM_RC
34 sim_cpu_alloc_all (SIM_DESC sd, int ncpus)
35 {
36   int c;
37 
38   for (c = 0; c < ncpus; ++c)
39     STATE_CPU (sd, c) = sim_cpu_alloc (sd);
40   return SIM_RC_OK;
41 }
42 
43 /* Allocate space for a cpu object.
44    EXTRA_BYTES is additional space to allocate for the sim_cpu struct.  */
45 
46 sim_cpu *
47 sim_cpu_alloc (SIM_DESC sd)
48 {
49   int extra_bytes = 0;
50 
51 #ifdef CGEN_ARCH
52   extra_bytes += cgen_cpu_max_extra_bytes (sd);
53 #endif
54 
55   return zalloc (sizeof (sim_cpu) + extra_bytes);
56 }
57 
58 /* Free all resources held by all cpus.  */
59 
60 void
61 sim_cpu_free_all (SIM_DESC sd)
62 {
63   int c;
64 
65   for (c = 0; c < MAX_NR_PROCESSORS; ++c)
66     if (STATE_CPU (sd, c))
67       sim_cpu_free (STATE_CPU (sd, c));
68 }
69 
70 /* Free all resources used by CPU.  */
71 
72 void
73 sim_cpu_free (sim_cpu *cpu)
74 {
75   free (cpu);
76 }
77 
78 /* PC utilities.  */
79 
80 sim_cia
81 sim_pc_get (sim_cpu *cpu)
82 {
83   return (* CPU_PC_FETCH (cpu)) (cpu);
84 }
85 
86 void
87 sim_pc_set (sim_cpu *cpu, sim_cia newval)
88 {
89   (* CPU_PC_STORE (cpu)) (cpu, newval);
90 }
91