]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* CPU support. |
213516ef | 2 | Copyright (C) 1998-2023 Free Software Foundation, Inc. |
c906108c SS |
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 | |
4744ac1b JB |
9 | the Free Software Foundation; either version 3 of the License, or |
10 | (at your option) any later version. | |
c906108c SS |
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 | ||
4744ac1b JB |
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/>. */ | |
c906108c | 19 | |
6df01ab8 MF |
20 | /* This must come before any other includes. */ |
21 | #include "defs.h" | |
22 | ||
b3f8962b TV |
23 | #include <stdlib.h> |
24 | ||
c906108c SS |
25 | #include "bfd.h" |
26 | ||
20a8e078 MF |
27 | #include "sim-main.h" |
28 | ||
c906108c | 29 | /* Allocate space for all cpus in the simulator. |
d5a71b11 | 30 | Space for the cpu must currently exist prior to parsing ARGV. */ |
c906108c SS |
31 | /* ??? wip. better solution must wait. */ |
32 | ||
33 | SIM_RC | |
ffeb72b4 | 34 | sim_cpu_alloc_all_extra (SIM_DESC sd, int ncpus, size_t extra_bytes) |
c906108c SS |
35 | { |
36 | int c; | |
37 | ||
883be197 MF |
38 | /* TODO: This should be a command line option for users to control. */ |
39 | if (ncpus == 0) | |
40 | ncpus = MAX_NR_PROCESSORS; | |
41 | ||
c906108c | 42 | for (c = 0; c < ncpus; ++c) |
ffeb72b4 | 43 | STATE_CPU (sd, c) = sim_cpu_alloc_extra (sd, extra_bytes); |
883be197 | 44 | |
c906108c SS |
45 | return SIM_RC_OK; |
46 | } | |
47 | ||
48 | /* Allocate space for a cpu object. | |
49 | EXTRA_BYTES is additional space to allocate for the sim_cpu struct. */ | |
50 | ||
51 | sim_cpu * | |
ffeb72b4 | 52 | sim_cpu_alloc_extra (SIM_DESC sd, size_t extra_bytes) |
c906108c | 53 | { |
4a21ad1e | 54 | sim_cpu *cpu = zalloc (sizeof (*cpu)); |
ffeb72b4 MF |
55 | |
56 | #ifndef CGEN_ARCH | |
57 | # define cgen_cpu_max_extra_bytes(sd) 0 | |
58 | #endif | |
1c636da0 | 59 | extra_bytes += cgen_cpu_max_extra_bytes (sd); |
ffeb72b4 MF |
60 | if (extra_bytes) |
61 | CPU_ARCH_DATA (cpu) = zalloc (extra_bytes); | |
d5a71b11 | 62 | |
ffeb72b4 | 63 | return cpu; |
c906108c SS |
64 | } |
65 | ||
66 | /* Free all resources held by all cpus. */ | |
67 | ||
68 | void | |
69 | sim_cpu_free_all (SIM_DESC sd) | |
70 | { | |
71 | int c; | |
72 | ||
73 | for (c = 0; c < MAX_NR_PROCESSORS; ++c) | |
74 | if (STATE_CPU (sd, c)) | |
75 | sim_cpu_free (STATE_CPU (sd, c)); | |
76 | } | |
77 | ||
78 | /* Free all resources used by CPU. */ | |
79 | ||
80 | void | |
81 | sim_cpu_free (sim_cpu *cpu) | |
82 | { | |
ffeb72b4 | 83 | free (CPU_ARCH_DATA (cpu)); |
d79fe0d6 | 84 | free (cpu); |
c906108c SS |
85 | } |
86 | \f | |
87 | /* PC utilities. */ | |
88 | ||
89 | sim_cia | |
90 | sim_pc_get (sim_cpu *cpu) | |
91 | { | |
92 | return (* CPU_PC_FETCH (cpu)) (cpu); | |
93 | } | |
94 | ||
95 | void | |
96 | sim_pc_set (sim_cpu *cpu, sim_cia newval) | |
97 | { | |
98 | (* CPU_PC_STORE (cpu)) (cpu, newval); | |
99 | } |