]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/common/sim-cpu.c
sim: cgen: move cgen_cpu_max_extra_bytes logic into the common code
[thirdparty/binutils-gdb.git] / sim / common / sim-cpu.c
CommitLineData
c906108c 1/* CPU support.
3666a048 2 Copyright (C) 1998-2021 Free Software Foundation, Inc.
c906108c
SS
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
4744ac1b
JB
9the Free Software Foundation; either version 3 of the License, or
10(at your option) any later version.
c906108c
SS
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
4744ac1b
JB
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 19
b3f8962b
TV
20#include <stdlib.h>
21
c906108c
SS
22#include "sim-main.h"
23#include "bfd.h"
24
25/* Allocate space for all cpus in the simulator.
d5a71b11 26 Space for the cpu must currently exist prior to parsing ARGV. */
c906108c
SS
27/* ??? wip. better solution must wait. */
28
29SIM_RC
d5a71b11 30sim_cpu_alloc_all (SIM_DESC sd, int ncpus)
c906108c
SS
31{
32 int c;
33
34 for (c = 0; c < ncpus; ++c)
d5a71b11 35 STATE_CPU (sd, c) = sim_cpu_alloc (sd);
c906108c
SS
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
42sim_cpu *
d5a71b11 43sim_cpu_alloc (SIM_DESC sd)
c906108c 44{
d5a71b11
MF
45 int extra_bytes = 0;
46
47#ifdef CGEN_ARCH
48 extra_bytes += cgen_cpu_max_extra_bytes ();
49#endif
50
c906108c
SS
51 return zalloc (sizeof (sim_cpu) + extra_bytes);
52}
53
54/* Free all resources held by all cpus. */
55
56void
57sim_cpu_free_all (SIM_DESC sd)
58{
59 int c;
60
61 for (c = 0; c < MAX_NR_PROCESSORS; ++c)
62 if (STATE_CPU (sd, c))
63 sim_cpu_free (STATE_CPU (sd, c));
64}
65
66/* Free all resources used by CPU. */
67
68void
69sim_cpu_free (sim_cpu *cpu)
70{
d79fe0d6 71 free (cpu);
c906108c
SS
72}
73\f
74/* PC utilities. */
75
76sim_cia
77sim_pc_get (sim_cpu *cpu)
78{
79 return (* CPU_PC_FETCH (cpu)) (cpu);
80}
81
82void
83sim_pc_set (sim_cpu *cpu, sim_cia newval)
84{
85 (* CPU_PC_STORE (cpu)) (cpu, newval);
86}