14e98e3e1Schristos /* cpu.h --- declarations for the RX core. 24e98e3e1Schristos 3*1f4e7eb9Schristos Copyright (C) 2005-2024 Free Software Foundation, Inc. 44e98e3e1Schristos Contributed by Red Hat, Inc. 54e98e3e1Schristos 64e98e3e1Schristos This file is part of the GNU simulators. 74e98e3e1Schristos 84e98e3e1Schristos This program is free software; you can redistribute it and/or modify 94e98e3e1Schristos it under the terms of the GNU General Public License as published by 104e98e3e1Schristos the Free Software Foundation; either version 3 of the License, or 114e98e3e1Schristos (at your option) any later version. 124e98e3e1Schristos 134e98e3e1Schristos This program is distributed in the hope that it will be useful, 144e98e3e1Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 154e98e3e1Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 164e98e3e1Schristos GNU General Public License for more details. 174e98e3e1Schristos 184e98e3e1Schristos You should have received a copy of the GNU General Public License 194e98e3e1Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 204e98e3e1Schristos 214e98e3e1Schristos #include <stdint.h> 224e98e3e1Schristos #include <setjmp.h> 234e98e3e1Schristos 244e98e3e1Schristos extern int verbose; 254e98e3e1Schristos extern int trace; 264e98e3e1Schristos extern int enable_counting; 274e98e3e1Schristos 284e98e3e1Schristos typedef uint8_t QI; 294e98e3e1Schristos typedef uint16_t HI; 304e98e3e1Schristos typedef uint32_t SI; 314e98e3e1Schristos typedef uint64_t DI; 324e98e3e1Schristos 334e98e3e1Schristos extern int rx_in_gdb; 344e98e3e1Schristos extern int rx_big_endian; 354e98e3e1Schristos 364e98e3e1Schristos typedef struct 374e98e3e1Schristos { 384e98e3e1Schristos SI r[16]; 394e98e3e1Schristos 404e98e3e1Schristos SI r_psw; 414e98e3e1Schristos SI r_pc; 424e98e3e1Schristos SI r_usp; 434e98e3e1Schristos SI r_fpsw; 444e98e3e1Schristos SI r__reserved_cr_4; 454e98e3e1Schristos SI r__reserved_cr_5; 464e98e3e1Schristos SI r__reserved_cr_6; 474e98e3e1Schristos SI r__reserved_cr_7; 484e98e3e1Schristos 494e98e3e1Schristos SI r_bpsw; 504e98e3e1Schristos SI r_bpc; 514e98e3e1Schristos SI r_isp; 524e98e3e1Schristos SI r_fintv; 534e98e3e1Schristos SI r_intb; 544e98e3e1Schristos SI r__reserved_cr_13; 554e98e3e1Schristos SI r__reserved_cr_14; 564e98e3e1Schristos SI r__reserved_cr_15; 574e98e3e1Schristos 584e98e3e1Schristos SI r__reserved_cr_16; 594e98e3e1Schristos SI r__reserved_cr_17; 604e98e3e1Schristos SI r__reserved_cr_18; 614e98e3e1Schristos SI r__reserved_cr_19; 624e98e3e1Schristos SI r__reserved_cr_20; 634e98e3e1Schristos SI r__reserved_cr_21; 644e98e3e1Schristos SI r__reserved_cr_22; 654e98e3e1Schristos SI r__reserved_cr_23; 664e98e3e1Schristos 674e98e3e1Schristos SI r__reserved_cr_24; 684e98e3e1Schristos SI r__reserved_cr_25; 694e98e3e1Schristos SI r__reserved_cr_26; 704e98e3e1Schristos SI r__reserved_cr_27; 714e98e3e1Schristos SI r__reserved_cr_28; 724e98e3e1Schristos SI r__reserved_cr_29; 734e98e3e1Schristos SI r__reserved_cr_30; 744e98e3e1Schristos SI r__reserved_cr_31; 754e98e3e1Schristos 764e98e3e1Schristos SI r_temp; 774e98e3e1Schristos 784e98e3e1Schristos DI r_acc; 794e98e3e1Schristos 804e98e3e1Schristos #ifdef CYCLE_ACCURATE 814e98e3e1Schristos /* If set, RTS/RTSD take 2 fewer cycles. */ 824e98e3e1Schristos char fast_return; 834e98e3e1Schristos SI link_register; 844e98e3e1Schristos 854e98e3e1Schristos unsigned long long cycle_count; 864e98e3e1Schristos /* Bits saying what kind of memory operands the previous insn had. */ 874e98e3e1Schristos int m2m; 884e98e3e1Schristos /* Target register for load. */ 894e98e3e1Schristos int rt; 904e98e3e1Schristos #endif 914e98e3e1Schristos } regs_type; 924e98e3e1Schristos 934e98e3e1Schristos #define M2M_SRC 0x01 944e98e3e1Schristos #define M2M_DST 0x02 954e98e3e1Schristos #define M2M_BOTH 0x03 964e98e3e1Schristos 974e98e3e1Schristos #define sp 0 984e98e3e1Schristos #define psw 16 994e98e3e1Schristos #define pc 17 1004e98e3e1Schristos #define usp 18 1014e98e3e1Schristos #define fpsw 19 1024e98e3e1Schristos 1034e98e3e1Schristos #define bpsw 24 1044e98e3e1Schristos #define bpc 25 1054e98e3e1Schristos #define isp 26 1064e98e3e1Schristos #define fintv 27 1074e98e3e1Schristos #define intb 28 1084e98e3e1Schristos 1094e98e3e1Schristos #define r_temp_idx 48 1104e98e3e1Schristos #define acc64 49 1114e98e3e1Schristos #define acchi 50 1124e98e3e1Schristos #define accmi 51 1134e98e3e1Schristos #define acclo 52 1144e98e3e1Schristos 1154e98e3e1Schristos extern regs_type regs; 1164e98e3e1Schristos 1174e98e3e1Schristos #define FLAGBIT_C 0x00000001 1184e98e3e1Schristos #define FLAGBIT_Z 0x00000002 1194e98e3e1Schristos #define FLAGBIT_S 0x00000004 1204e98e3e1Schristos #define FLAGBIT_O 0x00000008 1214e98e3e1Schristos #define FLAGBIT_I 0x00010000 1224e98e3e1Schristos #define FLAGBIT_U 0x00020000 1234e98e3e1Schristos #define FLAGBIT_PM 0x00100000 1244e98e3e1Schristos #define FLAGBITS_IPL 0x0f000000 1254e98e3e1Schristos #define FLAGSHIFT_IPL 24 1264e98e3e1Schristos 1274e98e3e1Schristos #define FPSWBITS_RM 0x00000003 1284e98e3e1Schristos #define FPSWBITS_CV 0x00000004 /* invalid operation */ 1294e98e3e1Schristos #define FPSWBITS_CO 0x00000008 /* overflow */ 1304e98e3e1Schristos #define FPSWBITS_CZ 0x00000010 /* divide-by-zero */ 1314e98e3e1Schristos #define FPSWBITS_CU 0x00000020 /* underflow */ 1324e98e3e1Schristos #define FPSWBITS_CX 0x00000040 /* inexact */ 1334e98e3e1Schristos #define FPSWBITS_CE 0x00000080 /* unimplemented processing */ 1344e98e3e1Schristos #define FPSWBITS_CMASK 0x000000fc /* all the above */ 1354e98e3e1Schristos #define FPSWBITS_DN 0x00000100 1364e98e3e1Schristos #define FPSW_CESH 8 1374e98e3e1Schristos #define FPSWBITS_EV 0x00000400 1384e98e3e1Schristos #define FPSWBITS_EO 0x00000800 1394e98e3e1Schristos #define FPSWBITS_EZ 0x00001000 1404e98e3e1Schristos #define FPSWBITS_EU 0x00002000 1414e98e3e1Schristos #define FPSWBITS_EX 0x00004000 1424e98e3e1Schristos #define FPSW_EFSH 16 1434e98e3e1Schristos #define FPSW_CFSH 24 1444e98e3e1Schristos #define FPSWBITS_FV 0x04000000 1454e98e3e1Schristos #define FPSWBITS_FO 0x08000000 1464e98e3e1Schristos #define FPSWBITS_FZ 0x10000000 1474e98e3e1Schristos #define FPSWBITS_FU 0x20000000 1484e98e3e1Schristos #define FPSWBITS_FX 0x40000000 1494e98e3e1Schristos #define FPSWBITS_FSUM 0x80000000 1504e98e3e1Schristos #define FPSWBITS_FMASK 0x7c000000 1514e98e3e1Schristos #define FPSWBITS_CLEAR 0xffffff03 /* masked at start of any FP opcode */ 1524e98e3e1Schristos 1534e98e3e1Schristos #define FPRM_NEAREST 0 1544e98e3e1Schristos #define FPRM_ZERO 1 1554e98e3e1Schristos #define FPRM_PINF 2 1564e98e3e1Schristos #define FPRM_NINF 3 1574e98e3e1Schristos 1584e98e3e1Schristos extern char *reg_names[]; 1594e98e3e1Schristos 1604e98e3e1Schristos extern int rx_flagmask; 1614e98e3e1Schristos extern int rx_flagand; 1624e98e3e1Schristos extern int rx_flagor; 1634e98e3e1Schristos 1644e98e3e1Schristos extern unsigned int b2mask[]; 1654e98e3e1Schristos extern unsigned int b2signbit[]; 1664e98e3e1Schristos extern int b2maxsigned[]; 1674e98e3e1Schristos extern int b2minsigned[]; 1684e98e3e1Schristos 1694e98e3e1Schristos void init_regs (void); 1704e98e3e1Schristos void stack_heap_stats (void); 1714e98e3e1Schristos void set_pointer_width (int bytes); 1724e98e3e1Schristos unsigned int get_reg (int id); 1734e98e3e1Schristos unsigned long long get_reg64 (int id); 1744e98e3e1Schristos void put_reg (int id, unsigned int value); 1754e98e3e1Schristos void put_reg64 (int id, unsigned long long value); 1764e98e3e1Schristos 1774e98e3e1Schristos void set_flags (int mask, int newbits); 1784e98e3e1Schristos void set_oszc (long long value, int bytes, int c); 1794e98e3e1Schristos void set_szc (long long value, int bytes, int c); 1804e98e3e1Schristos void set_osz (long long value, int bytes); 1814e98e3e1Schristos void set_sz (long long value, int bytes); 1824e98e3e1Schristos void set_zc (int z, int c); 1834e98e3e1Schristos void set_c (int c); 1844e98e3e1Schristos 1854e98e3e1Schristos const char *bits (int v, int b); 1864e98e3e1Schristos 1874e98e3e1Schristos int condition_true (int cond_id); 1884e98e3e1Schristos 1894e98e3e1Schristos #define FLAG(f) ((regs.r_psw & f) ? 1 : 0) 1904e98e3e1Schristos #define FLAG_C FLAG(FLAGBIT_C) 1914e98e3e1Schristos #define FLAG_D FLAG(FLAGBIT_D) 1924e98e3e1Schristos #define FLAG_Z FLAG(FLAGBIT_Z) 1934e98e3e1Schristos #define FLAG_S FLAG(FLAGBIT_S) 1944e98e3e1Schristos #define FLAG_B FLAG(FLAGBIT_B) 1954e98e3e1Schristos #define FLAG_O FLAG(FLAGBIT_O) 1964e98e3e1Schristos #define FLAG_I FLAG(FLAGBIT_I) 1974e98e3e1Schristos #define FLAG_U FLAG(FLAGBIT_U) 1984e98e3e1Schristos #define FLAG_PM FLAG(FLAGBIT_PM) 1994e98e3e1Schristos 2004e98e3e1Schristos /* Instruction step return codes. 2014e98e3e1Schristos Suppose one of the decode_* functions below returns a value R: 2024e98e3e1Schristos - If RX_STEPPED (R), then the single-step completed normally. 2034e98e3e1Schristos - If RX_HIT_BREAK (R), then the program hit a breakpoint. 2044e98e3e1Schristos - If RX_EXITED (R), then the program has done an 'exit' system 2054e98e3e1Schristos call, and the exit code is RX_EXIT_STATUS (R). 2064e98e3e1Schristos - If RX_STOPPED (R), then a signal (number RX_STOP_SIG (R)) was 2074e98e3e1Schristos generated. 2084e98e3e1Schristos 2094e98e3e1Schristos For building step return codes: 2104e98e3e1Schristos - RX_MAKE_STEPPED is the return code for finishing a normal step. 2114e98e3e1Schristos - RX_MAKE_HIT_BREAK is the return code for hitting a breakpoint. 2124e98e3e1Schristos - RX_MAKE_EXITED (C) is the return code for exiting with status C. 2134e98e3e1Schristos - RX_MAKE_STOPPED (S) is the return code for stopping on signal S. */ 2144e98e3e1Schristos #define RX_MAKE_STEPPED() (1) 2154e98e3e1Schristos #define RX_MAKE_HIT_BREAK() (2) 2164e98e3e1Schristos #define RX_MAKE_EXITED(c) (((int) (c) << 8) + 3) 2174e98e3e1Schristos #define RX_MAKE_STOPPED(s) (((int) (s) << 8) + 4) 2184e98e3e1Schristos 2194e98e3e1Schristos #define RX_STEPPED(r) ((r) == RX_MAKE_STEPPED ()) 2204e98e3e1Schristos #define RX_HIT_BREAK(r) ((r) == RX_MAKE_HIT_BREAK ()) 2214e98e3e1Schristos #define RX_EXITED(r) (((r) & 0xff) == 3) 2224e98e3e1Schristos #define RX_EXIT_STATUS(r) ((r) >> 8) 2234e98e3e1Schristos #define RX_STOPPED(r) (((r) & 0xff) == 4) 2244e98e3e1Schristos #define RX_STOP_SIG(r) ((r) >> 8) 2254e98e3e1Schristos 2264e98e3e1Schristos /* The step result for the current step. Global to allow 2274e98e3e1Schristos communication between the stepping function and the system 2284e98e3e1Schristos calls. */ 2294e98e3e1Schristos extern int step_result; 2304e98e3e1Schristos 2314e98e3e1Schristos extern unsigned int rx_cycles; 2324e98e3e1Schristos 2334e98e3e1Schristos /* Used to detect heap/stack collisions. */ 2344e98e3e1Schristos extern unsigned int heaptop; 2354e98e3e1Schristos extern unsigned int heapbottom; 2364e98e3e1Schristos 2374e98e3e1Schristos extern int decode_opcode (void); 2384e98e3e1Schristos extern void reset_decoder (void); 2394e98e3e1Schristos extern void reset_pipeline_stats (void); 2404e98e3e1Schristos extern void halt_pipeline_stats (void); 2414e98e3e1Schristos extern void pipeline_stats (void); 2424e98e3e1Schristos 2434b169a6bSchristos extern void trace_register_changes (void); 2444e98e3e1Schristos extern void generate_access_exception (void); 2454e98e3e1Schristos extern jmp_buf decode_jmp_buf; 246