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