14e98e3e1Schristos /* collection of junk waiting time to sort out 2*05fa0856Schristos Copyright (C) 1996-2024 Free Software Foundation, Inc. 34e98e3e1Schristos Contributed by Cygnus Support. 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 #ifndef M32R_SIM_H 214e98e3e1Schristos #define M32R_SIM_H 224e98e3e1Schristos 23*05fa0856Schristos #include "symcat.h" 24*05fa0856Schristos 254e98e3e1Schristos /* GDB register numbers. */ 264e98e3e1Schristos #define PSW_REGNUM 16 274e98e3e1Schristos #define CBR_REGNUM 17 284e98e3e1Schristos #define SPI_REGNUM 18 294e98e3e1Schristos #define SPU_REGNUM 19 304e98e3e1Schristos #define BPC_REGNUM 20 314e98e3e1Schristos #define PC_REGNUM 21 324e98e3e1Schristos #define ACCL_REGNUM 22 334e98e3e1Schristos #define ACCH_REGNUM 23 344e98e3e1Schristos #define ACC1L_REGNUM 24 354e98e3e1Schristos #define ACC1H_REGNUM 25 364e98e3e1Schristos #define BBPSW_REGNUM 26 374e98e3e1Schristos #define BBPC_REGNUM 27 384e98e3e1Schristos #define EVB_REGNUM 28 394e98e3e1Schristos 404e98e3e1Schristos extern int m32r_decode_gdb_ctrl_regnum (int); 414e98e3e1Schristos 42*05fa0856Schristos /* The other cpu cores reuse m32rbf funcs to avoid duplication, but they don't 43*05fa0856Schristos provide externs to access, and we can't e.g. include decode.h in decodex.h 44*05fa0856Schristos because of all the redefinitions of cgen macros. */ 45*05fa0856Schristos 46*05fa0856Schristos extern void m32rbf_model_insn_before (SIM_CPU *, int); 47*05fa0856Schristos extern void m32rbf_model_insn_after (SIM_CPU *, int, int); 48*05fa0856Schristos extern CPUREG_FETCH_FN m32rbf_fetch_register; 49*05fa0856Schristos extern CPUREG_STORE_FN m32rbf_store_register; 50*05fa0856Schristos extern UQI m32rbf_h_psw_get (SIM_CPU *); 51*05fa0856Schristos extern void m32rbf_h_psw_set (SIM_CPU *, UQI); 52*05fa0856Schristos extern UQI m32r2f_h_psw_get (SIM_CPU *); 53*05fa0856Schristos extern void m32r2f_h_psw_set (SIM_CPU *, UQI); 54*05fa0856Schristos extern UQI m32rxf_h_psw_get (SIM_CPU *); 55*05fa0856Schristos extern void m32rxf_h_psw_set (SIM_CPU *, UQI); 56*05fa0856Schristos extern void m32rbf_h_bpsw_set (SIM_CPU *, UQI); 57*05fa0856Schristos extern void m32r2f_h_bpsw_set (SIM_CPU *, UQI); 58*05fa0856Schristos extern void m32rxf_h_bpsw_set (SIM_CPU *, UQI); 59*05fa0856Schristos extern SI m32rbf_h_gr_get (SIM_CPU *, UINT); 60*05fa0856Schristos extern void m32rbf_h_gr_set (SIM_CPU *, UINT, SI); 61*05fa0856Schristos extern USI m32rbf_h_cr_get (SIM_CPU *, UINT); 62*05fa0856Schristos extern void m32rbf_h_cr_set (SIM_CPU *, UINT, USI); 63*05fa0856Schristos 644e98e3e1Schristos /* Cover macros for hardware accesses. 654e98e3e1Schristos FIXME: Eventually move to cgen. */ 664e98e3e1Schristos #define GET_H_SM() ((CPU (h_psw) & 0x80) != 0) 674e98e3e1Schristos 684e98e3e1Schristos extern USI m32rbf_h_cr_get_handler (SIM_CPU *, UINT); 694e98e3e1Schristos extern void m32rbf_h_cr_set_handler (SIM_CPU *, UINT, USI); 70*05fa0856Schristos extern USI m32r2f_h_cr_get_handler (SIM_CPU *, UINT); 71*05fa0856Schristos extern void m32r2f_h_cr_set_handler (SIM_CPU *, UINT, USI); 72*05fa0856Schristos extern USI m32rxf_h_cr_get_handler (SIM_CPU *, UINT); 73*05fa0856Schristos extern void m32rxf_h_cr_set_handler (SIM_CPU *, UINT, USI); 744e98e3e1Schristos 75*05fa0856Schristos #ifndef GET_H_CR 764e98e3e1Schristos #define GET_H_CR(regno) \ 774e98e3e1Schristos XCONCAT2 (WANT_CPU,_h_cr_get_handler) (current_cpu, (regno)) 784e98e3e1Schristos #define SET_H_CR(regno, val) \ 794e98e3e1Schristos XCONCAT2 (WANT_CPU,_h_cr_set_handler) (current_cpu, (regno), (val)) 804e98e3e1Schristos #endif 814e98e3e1Schristos 824e98e3e1Schristos extern UQI m32rbf_h_psw_get_handler (SIM_CPU *); 834e98e3e1Schristos extern void m32rbf_h_psw_set_handler (SIM_CPU *, UQI); 84*05fa0856Schristos extern UQI m32r2f_h_psw_get_handler (SIM_CPU *); 85*05fa0856Schristos extern void m32r2f_h_psw_set_handler (SIM_CPU *, UQI); 86*05fa0856Schristos extern UQI m32rxf_h_psw_get_handler (SIM_CPU *); 87*05fa0856Schristos extern void m32rxf_h_psw_set_handler (SIM_CPU *, UQI); 884e98e3e1Schristos 89*05fa0856Schristos #ifndef GET_H_PSW 904e98e3e1Schristos #define GET_H_PSW() \ 914e98e3e1Schristos XCONCAT2 (WANT_CPU,_h_psw_get_handler) (current_cpu) 924e98e3e1Schristos #define SET_H_PSW(val) \ 934e98e3e1Schristos XCONCAT2 (WANT_CPU,_h_psw_set_handler) (current_cpu, (val)) 944e98e3e1Schristos #endif 954e98e3e1Schristos 964b169a6bSchristos /* FIXME: These prototypes are necessary because the cgen generated 974b169a6bSchristos cpu.h, cpux.h and cpu2.h headers do not provide them, and functions 984b169a6bSchristos which take or return parameters that are larger than an int must be 994b169a6bSchristos prototyed in order for them to work correctly. 1004b169a6bSchristos 1014b169a6bSchristos The correct solution is to fix the code in cgen/sim.scm to generate 1024b169a6bSchristos prototypes for each of the functions it generates. */ 1034e98e3e1Schristos extern DI m32rbf_h_accum_get_handler (SIM_CPU *); 1044e98e3e1Schristos extern void m32rbf_h_accum_set_handler (SIM_CPU *, DI); 105*05fa0856Schristos extern DI m32r2f_h_accum_get_handler (SIM_CPU *); 106*05fa0856Schristos extern void m32r2f_h_accum_set_handler (SIM_CPU *, DI); 107*05fa0856Schristos extern DI m32rxf_h_accum_get_handler (SIM_CPU *); 108*05fa0856Schristos extern void m32rxf_h_accum_set_handler (SIM_CPU *, DI); 109*05fa0856Schristos 1104b169a6bSchristos extern DI m32r2f_h_accums_get_handler (SIM_CPU *, UINT); 1114b169a6bSchristos extern void m32r2f_h_accums_set_handler (SIM_CPU *, UINT, DI); 112*05fa0856Schristos extern DI m32rxf_h_accums_get_handler (SIM_CPU *, UINT); 113*05fa0856Schristos extern void m32rxf_h_accums_set_handler (SIM_CPU *, UINT, DI); 1144e98e3e1Schristos 1154b169a6bSchristos #ifndef GET_H_ACCUM 1164e98e3e1Schristos #define GET_H_ACCUM() \ 1174e98e3e1Schristos XCONCAT2 (WANT_CPU,_h_accum_get_handler) (current_cpu) 1184e98e3e1Schristos #define SET_H_ACCUM(val) \ 1194e98e3e1Schristos XCONCAT2 (WANT_CPU,_h_accum_set_handler) (current_cpu, (val)) 1204e98e3e1Schristos #endif 1214e98e3e1Schristos 1224e98e3e1Schristos /* Misc. profile data. */ 1234e98e3e1Schristos 1244e98e3e1Schristos typedef struct { 1254e98e3e1Schristos /* nop insn slot filler count */ 1264e98e3e1Schristos unsigned int fillnop_count; 1274e98e3e1Schristos /* number of parallel insns */ 1284e98e3e1Schristos unsigned int parallel_count; 1294e98e3e1Schristos 1304e98e3e1Schristos /* FIXME: generalize this to handle all insn lengths, move to common. */ 1314e98e3e1Schristos /* number of short insns, not including parallel ones */ 1324e98e3e1Schristos unsigned int short_count; 1334e98e3e1Schristos /* number of long insns */ 1344e98e3e1Schristos unsigned int long_count; 1354e98e3e1Schristos 1364e98e3e1Schristos /* Working area for computing cycle counts. */ 1374e98e3e1Schristos unsigned long insn_cycles; /* FIXME: delete */ 1384e98e3e1Schristos unsigned long cti_stall; 1394e98e3e1Schristos unsigned long load_stall; 1404e98e3e1Schristos unsigned long biggest_cycles; 1414e98e3e1Schristos 1424e98e3e1Schristos /* Bitmask of registers loaded by previous insn. */ 1434e98e3e1Schristos unsigned int load_regs; 1444e98e3e1Schristos /* Bitmask of registers loaded by current insn. */ 1454e98e3e1Schristos unsigned int load_regs_pending; 1464e98e3e1Schristos } M32R_MISC_PROFILE; 1474e98e3e1Schristos 1484e98e3e1Schristos /* Initialize the working area. */ 1494e98e3e1Schristos void m32r_init_insn_cycles (SIM_CPU *, int); 1504e98e3e1Schristos /* Update the totals for the insn. */ 1514e98e3e1Schristos void m32r_record_insn_cycles (SIM_CPU *, int); 1524e98e3e1Schristos 1534e98e3e1Schristos /* This is invoked by the nop pattern in the .cpu file. */ 1544e98e3e1Schristos #define PROFILE_COUNT_FILLNOPS(cpu, addr) \ 1554e98e3e1Schristos do { \ 1564e98e3e1Schristos if (PROFILE_INSN_P (cpu) \ 1574e98e3e1Schristos && (addr & 3) != 0) \ 1584e98e3e1Schristos ++ CPU_M32R_MISC_PROFILE (cpu)->fillnop_count; \ 1594e98e3e1Schristos } while (0) 1604e98e3e1Schristos 1614e98e3e1Schristos /* This is invoked by the execute section of mloop{,x}.in. */ 1624e98e3e1Schristos #define PROFILE_COUNT_PARINSNS(cpu) \ 1634e98e3e1Schristos do { \ 1644e98e3e1Schristos if (PROFILE_INSN_P (cpu)) \ 1654e98e3e1Schristos ++ CPU_M32R_MISC_PROFILE (cpu)->parallel_count; \ 1664e98e3e1Schristos } while (0) 1674e98e3e1Schristos 1684e98e3e1Schristos /* This is invoked by the execute section of mloop{,x}.in. */ 1694e98e3e1Schristos #define PROFILE_COUNT_SHORTINSNS(cpu) \ 1704e98e3e1Schristos do { \ 1714e98e3e1Schristos if (PROFILE_INSN_P (cpu)) \ 1724e98e3e1Schristos ++ CPU_M32R_MISC_PROFILE (cpu)->short_count; \ 1734e98e3e1Schristos } while (0) 1744e98e3e1Schristos 1754e98e3e1Schristos /* This is invoked by the execute section of mloop{,x}.in. */ 1764e98e3e1Schristos #define PROFILE_COUNT_LONGINSNS(cpu) \ 1774e98e3e1Schristos do { \ 1784e98e3e1Schristos if (PROFILE_INSN_P (cpu)) \ 1794e98e3e1Schristos ++ CPU_M32R_MISC_PROFILE (cpu)->long_count; \ 1804e98e3e1Schristos } while (0) 1814e98e3e1Schristos 1824e98e3e1Schristos #define GETTWI GETTSI 1834e98e3e1Schristos #define SETTWI SETTSI 1844e98e3e1Schristos 1854e98e3e1Schristos /* Additional execution support. */ 1864e98e3e1Schristos 1874e98e3e1Schristos 1884e98e3e1Schristos /* Hardware/device support. 1894e98e3e1Schristos ??? Will eventually want to move device stuff to config files. */ 1904e98e3e1Schristos 1914e98e3e1Schristos /* Exception, Interrupt, and Trap addresses */ 1924e98e3e1Schristos #define EIT_SYSBREAK_ADDR 0x10 1934e98e3e1Schristos #define EIT_RSVD_INSN_ADDR 0x20 1944e98e3e1Schristos #define EIT_ADDR_EXCP_ADDR 0x30 1954e98e3e1Schristos #define EIT_TRAP_BASE_ADDR 0x40 1964e98e3e1Schristos #define EIT_EXTERN_ADDR 0x80 1974e98e3e1Schristos #define EIT_RESET_ADDR 0x7ffffff0 1984e98e3e1Schristos #define EIT_WAKEUP_ADDR 0x7ffffff0 1994e98e3e1Schristos 2004e98e3e1Schristos /* Special purpose traps. */ 2014e98e3e1Schristos #define TRAP_SYSCALL 0 2024e98e3e1Schristos #define TRAP_BREAKPOINT 1 2034e98e3e1Schristos 2044e98e3e1Schristos /* Handle the trap insn. */ 2054e98e3e1Schristos USI m32r_trap (SIM_CPU *, PCADDR, int); 206*05fa0856Schristos 207*05fa0856Schristos struct m32r_sim_cpu { 208*05fa0856Schristos M32R_MISC_PROFILE m32r_misc_profile; 209*05fa0856Schristos #define CPU_M32R_MISC_PROFILE(cpu) (& M32R_SIM_CPU (cpu)->m32r_misc_profile) 210*05fa0856Schristos 211*05fa0856Schristos /* CPU specific parts go here. 212*05fa0856Schristos Note that in files that don't need to access these pieces WANT_CPU_FOO 213*05fa0856Schristos won't be defined and thus these parts won't appear. This is ok in the 214*05fa0856Schristos sense that things work. It is a source of bugs though. 215*05fa0856Schristos One has to of course be careful to not take the size of this 216*05fa0856Schristos struct and no structure members accessed in non-cpu specific files can 217*05fa0856Schristos go after here. Oh for a better language. */ 218*05fa0856Schristos #if defined (WANT_CPU_M32RBF) 219*05fa0856Schristos M32RBF_CPU_DATA cpu_data; 220*05fa0856Schristos #endif 221*05fa0856Schristos #if defined (WANT_CPU_M32RXF) 222*05fa0856Schristos M32RXF_CPU_DATA cpu_data; 223*05fa0856Schristos #elif defined (WANT_CPU_M32R2F) 224*05fa0856Schristos M32R2F_CPU_DATA cpu_data; 225*05fa0856Schristos #endif 226*05fa0856Schristos }; 227*05fa0856Schristos #define M32R_SIM_CPU(cpu) ((struct m32r_sim_cpu *) CPU_ARCH_DATA (cpu)) 2284e98e3e1Schristos 2294e98e3e1Schristos #endif /* M32R_SIM_H */ 230