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