14e98e3e1Schristos /* CPU support. 2*88241920Schristos Copyright (C) 1998-2024 Free Software Foundation, Inc. 34e98e3e1Schristos Contributed by Cygnus Solutions. 44e98e3e1Schristos 54e98e3e1Schristos This file is part of GDB, the GNU debugger. 64e98e3e1Schristos 74e98e3e1Schristos This program is free software; you can redistribute it and/or modify 84e98e3e1Schristos it under the terms of the GNU General Public License as published by 94e98e3e1Schristos the Free Software Foundation; either version 3 of the License, or 104e98e3e1Schristos (at your option) any later version. 114e98e3e1Schristos 124e98e3e1Schristos This program is distributed in the hope that it will be useful, 134e98e3e1Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 144e98e3e1Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 154e98e3e1Schristos GNU General Public License for more details. 164e98e3e1Schristos 174e98e3e1Schristos You should have received a copy of the GNU General Public License 184e98e3e1Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 194e98e3e1Schristos 204e98e3e1Schristos /* This file is intended to be included by sim-base.h. 214e98e3e1Schristos 224e98e3e1Schristos This file provides an interface between the simulator framework and 234e98e3e1Schristos the selected cpu. */ 244e98e3e1Schristos 254e98e3e1Schristos #ifndef SIM_CPU_H 264e98e3e1Schristos #define SIM_CPU_H 274e98e3e1Schristos 284e98e3e1Schristos /* Type of function to return an insn name. */ 294e98e3e1Schristos typedef const char * (CPU_INSN_NAME_FN) (sim_cpu *, int); 304e98e3e1Schristos 31*88241920Schristos #ifdef CGEN_ARCH 32*88241920Schristos # include "cgen-cpu.h" 33*88241920Schristos #endif 34*88241920Schristos 354e98e3e1Schristos /* Types for register access functions. 364e98e3e1Schristos These routines implement the sim_{fetch,store}_register interface. */ 374b169a6bSchristos typedef int (CPUREG_FETCH_FN) (sim_cpu *, int, void *, int); 384b169a6bSchristos typedef int (CPUREG_STORE_FN) (sim_cpu *, int, const void *, int); 394e98e3e1Schristos 404e98e3e1Schristos /* Types for PC access functions. 414e98e3e1Schristos Some simulators require a functional interface to access the program 424e98e3e1Schristos counter [a macro is insufficient as the PC is kept in a cpu-specific part 434e98e3e1Schristos of the sim_cpu struct]. */ 444e98e3e1Schristos typedef sim_cia (PC_FETCH_FN) (sim_cpu *); 454e98e3e1Schristos typedef void (PC_STORE_FN) (sim_cpu *, sim_cia); 464e98e3e1Schristos 474e98e3e1Schristos /* Pseudo baseclass for each cpu. */ 484e98e3e1Schristos 49*88241920Schristos struct _sim_cpu { 504e98e3e1Schristos /* Backlink to main state struct. */ 514e98e3e1Schristos SIM_DESC state; 52*88241920Schristos #define CPU_STATE(cpu) ((cpu)->state) 534e98e3e1Schristos 544e98e3e1Schristos /* Processor index within the SD_DESC */ 554e98e3e1Schristos int index; 56*88241920Schristos #define CPU_INDEX(cpu) ((cpu)->index) 574e98e3e1Schristos 584e98e3e1Schristos /* The name of the cpu. */ 594e98e3e1Schristos const char *name; 60*88241920Schristos #define CPU_NAME(cpu) ((cpu)->name) 614e98e3e1Schristos 624e98e3e1Schristos /* Options specific to this cpu. */ 634e98e3e1Schristos struct option_list *options; 64*88241920Schristos #define CPU_OPTIONS(cpu) ((cpu)->options) 654e98e3e1Schristos 664e98e3e1Schristos /* Processor specific core data */ 674e98e3e1Schristos sim_cpu_core core; 68*88241920Schristos #define CPU_CORE(cpu) (& (cpu)->core) 694e98e3e1Schristos 704e98e3e1Schristos /* Number of instructions (used to iterate over CPU_INSN_NAME). */ 714e98e3e1Schristos unsigned int max_insns; 72*88241920Schristos #define CPU_MAX_INSNS(cpu) ((cpu)->max_insns) 734e98e3e1Schristos 744e98e3e1Schristos /* Function to return the name of an insn. */ 754e98e3e1Schristos CPU_INSN_NAME_FN *insn_name; 76*88241920Schristos #define CPU_INSN_NAME(cpu) ((cpu)->insn_name) 774e98e3e1Schristos 784e98e3e1Schristos /* Trace data. See sim-trace.h. */ 794e98e3e1Schristos TRACE_DATA trace_data; 80*88241920Schristos #define CPU_TRACE_DATA(cpu) (& (cpu)->trace_data) 814e98e3e1Schristos 824e98e3e1Schristos /* Maximum number of debuggable entities. 834e98e3e1Schristos This debugging is not intended for normal use. 844e98e3e1Schristos It is only enabled when the simulator is configured with --with-debug 854e98e3e1Schristos which shouldn't normally be specified. */ 864e98e3e1Schristos #ifndef MAX_DEBUG_VALUES 874e98e3e1Schristos #define MAX_DEBUG_VALUES 4 884e98e3e1Schristos #endif 894e98e3e1Schristos 904e98e3e1Schristos /* Boolean array of specified debugging flags. */ 914e98e3e1Schristos char debug_flags[MAX_DEBUG_VALUES]; 92*88241920Schristos #define CPU_DEBUG_FLAGS(cpu) ((cpu)->debug_flags) 934e98e3e1Schristos /* Standard values. */ 944e98e3e1Schristos #define DEBUG_INSN_IDX 0 954e98e3e1Schristos #define DEBUG_NEXT_IDX 2 /* simulator specific debug bits begin here */ 964e98e3e1Schristos 974e98e3e1Schristos /* Debugging output goes to this or stderr if NULL. 984e98e3e1Schristos We can't store `stderr' here as stderr goes through a callback. */ 994e98e3e1Schristos FILE *debug_file; 100*88241920Schristos #define CPU_DEBUG_FILE(cpu) ((cpu)->debug_file) 1014e98e3e1Schristos 1024e98e3e1Schristos /* Profile data. See sim-profile.h. */ 1034e98e3e1Schristos PROFILE_DATA profile_data; 104*88241920Schristos #define CPU_PROFILE_DATA(cpu) (& (cpu)->profile_data) 1054e98e3e1Schristos 1064e98e3e1Schristos /* Machine tables for this cpu. See sim-model.h. */ 107ba340e45Schristos const SIM_MACH *mach; 108*88241920Schristos #define CPU_MACH(cpu) ((cpu)->mach) 1094e98e3e1Schristos /* The selected model. */ 110ba340e45Schristos const SIM_MODEL *model; 111*88241920Schristos #define CPU_MODEL(cpu) ((cpu)->model) 1124e98e3e1Schristos /* Model data (profiling state, etc.). */ 1134e98e3e1Schristos void *model_data; 114*88241920Schristos #define CPU_MODEL_DATA(cpu) ((cpu)->model_data) 1154e98e3e1Schristos 1164e98e3e1Schristos /* Routines to fetch/store registers. */ 1174e98e3e1Schristos CPUREG_FETCH_FN *reg_fetch; 118*88241920Schristos #define CPU_REG_FETCH(c) ((c)->reg_fetch) 1194e98e3e1Schristos CPUREG_STORE_FN *reg_store; 120*88241920Schristos #define CPU_REG_STORE(c) ((c)->reg_store) 1214e98e3e1Schristos PC_FETCH_FN *pc_fetch; 122*88241920Schristos #define CPU_PC_FETCH(c) ((c)->pc_fetch) 1234e98e3e1Schristos PC_STORE_FN *pc_store; 124*88241920Schristos #define CPU_PC_STORE(c) ((c)->pc_store) 1254e98e3e1Schristos 126*88241920Schristos #ifdef CGEN_ARCH 127*88241920Schristos /* Static parts of cgen. */ 128*88241920Schristos CGEN_CPU cgen_cpu; 129*88241920Schristos #define CPU_CGEN_CPU(cpu) ((cpu)->cgen_cpu) 130*88241920Schristos #endif 131*88241920Schristos 132*88241920Schristos /* Pointer for sim target to store arbitrary cpu data. Normally the 133*88241920Schristos target should define a struct and use it here. */ 134*88241920Schristos void *arch_data; 135*88241920Schristos #define CPU_ARCH_DATA(cpu) ((cpu)->arch_data) 136*88241920Schristos }; 1374e98e3e1Schristos 1384e98e3e1Schristos /* Create all cpus. */ 139*88241920Schristos extern SIM_RC sim_cpu_alloc_all_extra (SIM_DESC, int, size_t); 140*88241920Schristos #define sim_cpu_alloc_all(state, ncpus) sim_cpu_alloc_all_extra (state, ncpus, 0) 1414e98e3e1Schristos /* Create a cpu. */ 142*88241920Schristos extern sim_cpu *sim_cpu_alloc_extra (SIM_DESC, size_t); 143*88241920Schristos #define sim_cpu_alloc(sd) sim_cpu_alloc_extra (sd, 0) 1444e98e3e1Schristos /* Release resources held by all cpus. */ 1454e98e3e1Schristos extern void sim_cpu_free_all (SIM_DESC); 1464e98e3e1Schristos /* Release resources held by a cpu. */ 1474e98e3e1Schristos extern void sim_cpu_free (sim_cpu *); 1484e98e3e1Schristos 1494e98e3e1Schristos /* Return a pointer to the cpu data for CPU_NAME, or NULL if not found. */ 1504e98e3e1Schristos extern sim_cpu *sim_cpu_lookup (SIM_DESC, const char *); 1514e98e3e1Schristos 1524e98e3e1Schristos /* Return prefix to use in cpu specific messages. */ 1534e98e3e1Schristos extern const char *sim_cpu_msg_prefix (sim_cpu *); 1544e98e3e1Schristos /* Cover fn to sim_io_eprintf. */ 1554b169a6bSchristos extern void sim_io_eprintf_cpu (sim_cpu *, const char *, ...) 1564b169a6bSchristos ATTRIBUTE_PRINTF (2, 3); 1574e98e3e1Schristos 1584e98e3e1Schristos /* Get/set a pc value. */ 1594e98e3e1Schristos #define CPU_PC_GET(cpu) ((* CPU_PC_FETCH (cpu)) (cpu)) 1604e98e3e1Schristos #define CPU_PC_SET(cpu,newval) ((* CPU_PC_STORE (cpu)) ((cpu), (newval))) 1614e98e3e1Schristos /* External interface to accessing the pc. */ 1624e98e3e1Schristos sim_cia sim_pc_get (sim_cpu *); 1634e98e3e1Schristos void sim_pc_set (sim_cpu *, sim_cia); 1644e98e3e1Schristos 1654e98e3e1Schristos #endif /* SIM_CPU_H */ 166