1 /* CPU support.
2    Copyright (C) 1998, 2007, 2008, 2009, 2010, 2011
3    Free Software Foundation, Inc.
4    Contributed by Cygnus Solutions.
5 
6 This file is part of GDB, the GNU debugger.
7 
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20 
21 #include "sim-main.h"
22 #include "bfd.h"
23 
24 /* Allocate space for all cpus in the simulator.
25    Space for the cpu must currently exist prior to parsing ARGV.
26    EXTRA_BYTES is additional space to allocate for the sim_cpu struct.  */
27 /* ??? wip.  better solution must wait.  */
28 
29 SIM_RC
sim_cpu_alloc_all(SIM_DESC sd,int ncpus,int extra_bytes)30 sim_cpu_alloc_all (SIM_DESC sd, int ncpus, int extra_bytes)
31 {
32   int c;
33 
34   for (c = 0; c < ncpus; ++c)
35     STATE_CPU (sd, c) = sim_cpu_alloc (sd, extra_bytes);
36   return SIM_RC_OK;
37 }
38 
39 /* Allocate space for a cpu object.
40    EXTRA_BYTES is additional space to allocate for the sim_cpu struct.  */
41 
42 sim_cpu *
sim_cpu_alloc(SIM_DESC sd,int extra_bytes)43 sim_cpu_alloc (SIM_DESC sd, int extra_bytes)
44 {
45   return zalloc (sizeof (sim_cpu) + extra_bytes);
46 }
47 
48 /* Free all resources held by all cpus.  */
49 
50 void
sim_cpu_free_all(SIM_DESC sd)51 sim_cpu_free_all (SIM_DESC sd)
52 {
53   int c;
54 
55   for (c = 0; c < MAX_NR_PROCESSORS; ++c)
56     if (STATE_CPU (sd, c))
57       sim_cpu_free (STATE_CPU (sd, c));
58 }
59 
60 /* Free all resources used by CPU.  */
61 
62 void
sim_cpu_free(sim_cpu * cpu)63 sim_cpu_free (sim_cpu *cpu)
64 {
65   free (cpu);
66 }
67 
68 /* PC utilities.  */
69 
70 sim_cia
sim_pc_get(sim_cpu * cpu)71 sim_pc_get (sim_cpu *cpu)
72 {
73   return (* CPU_PC_FETCH (cpu)) (cpu);
74 }
75 
76 void
sim_pc_set(sim_cpu * cpu,sim_cia newval)77 sim_pc_set (sim_cpu *cpu, sim_cia newval)
78 {
79   (* CPU_PC_STORE (cpu)) (cpu, newval);
80 }
81