1 1.1 christos /* cpu.h --- declarations for the RX core. 2 1.1 christos 3 1.11 christos Copyright (C) 2005-2024 Free Software Foundation, Inc. 4 1.1 christos Contributed by Red Hat, Inc. 5 1.1 christos 6 1.1 christos This file is part of the GNU simulators. 7 1.1 christos 8 1.1 christos This program is free software; you can redistribute it and/or modify 9 1.1 christos it under the terms of the GNU General Public License as published by 10 1.1 christos the Free Software Foundation; either version 3 of the License, or 11 1.1 christos (at your option) any later version. 12 1.1 christos 13 1.1 christos This program is distributed in the hope that it will be useful, 14 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 15 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 1.1 christos GNU General Public License for more details. 17 1.1 christos 18 1.1 christos You should have received a copy of the GNU General Public License 19 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20 1.1 christos 21 1.1 christos #include <stdint.h> 22 1.1 christos #include <setjmp.h> 23 1.1 christos 24 1.1 christos extern int verbose; 25 1.1 christos extern int trace; 26 1.1 christos extern int enable_counting; 27 1.1 christos 28 1.1 christos typedef uint8_t QI; 29 1.1 christos typedef uint16_t HI; 30 1.1 christos typedef uint32_t SI; 31 1.1 christos typedef uint64_t DI; 32 1.1 christos 33 1.1 christos extern int rx_in_gdb; 34 1.1 christos extern int rx_big_endian; 35 1.1 christos 36 1.1 christos typedef struct 37 1.1 christos { 38 1.1 christos SI r[16]; 39 1.1 christos 40 1.1 christos SI r_psw; 41 1.1 christos SI r_pc; 42 1.1 christos SI r_usp; 43 1.1 christos SI r_fpsw; 44 1.1 christos SI r__reserved_cr_4; 45 1.1 christos SI r__reserved_cr_5; 46 1.1 christos SI r__reserved_cr_6; 47 1.1 christos SI r__reserved_cr_7; 48 1.1 christos 49 1.1 christos SI r_bpsw; 50 1.1 christos SI r_bpc; 51 1.1 christos SI r_isp; 52 1.1 christos SI r_fintv; 53 1.1 christos SI r_intb; 54 1.1 christos SI r__reserved_cr_13; 55 1.1 christos SI r__reserved_cr_14; 56 1.1 christos SI r__reserved_cr_15; 57 1.1 christos 58 1.1 christos SI r__reserved_cr_16; 59 1.1 christos SI r__reserved_cr_17; 60 1.1 christos SI r__reserved_cr_18; 61 1.1 christos SI r__reserved_cr_19; 62 1.1 christos SI r__reserved_cr_20; 63 1.1 christos SI r__reserved_cr_21; 64 1.1 christos SI r__reserved_cr_22; 65 1.1 christos SI r__reserved_cr_23; 66 1.1 christos 67 1.1 christos SI r__reserved_cr_24; 68 1.1 christos SI r__reserved_cr_25; 69 1.1 christos SI r__reserved_cr_26; 70 1.1 christos SI r__reserved_cr_27; 71 1.1 christos SI r__reserved_cr_28; 72 1.1 christos SI r__reserved_cr_29; 73 1.1 christos SI r__reserved_cr_30; 74 1.1 christos SI r__reserved_cr_31; 75 1.1 christos 76 1.1 christos SI r_temp; 77 1.1 christos 78 1.1 christos DI r_acc; 79 1.1 christos 80 1.1 christos #ifdef CYCLE_ACCURATE 81 1.1 christos /* If set, RTS/RTSD take 2 fewer cycles. */ 82 1.1 christos char fast_return; 83 1.1 christos SI link_register; 84 1.1 christos 85 1.1 christos unsigned long long cycle_count; 86 1.1 christos /* Bits saying what kind of memory operands the previous insn had. */ 87 1.1 christos int m2m; 88 1.1 christos /* Target register for load. */ 89 1.1 christos int rt; 90 1.1 christos #endif 91 1.1 christos } regs_type; 92 1.1 christos 93 1.1 christos #define M2M_SRC 0x01 94 1.1 christos #define M2M_DST 0x02 95 1.1 christos #define M2M_BOTH 0x03 96 1.1 christos 97 1.1 christos #define sp 0 98 1.1 christos #define psw 16 99 1.1 christos #define pc 17 100 1.1 christos #define usp 18 101 1.1 christos #define fpsw 19 102 1.1 christos 103 1.1 christos #define bpsw 24 104 1.1 christos #define bpc 25 105 1.1 christos #define isp 26 106 1.1 christos #define fintv 27 107 1.1 christos #define intb 28 108 1.1 christos 109 1.1 christos #define r_temp_idx 48 110 1.1 christos #define acc64 49 111 1.1 christos #define acchi 50 112 1.1 christos #define accmi 51 113 1.1 christos #define acclo 52 114 1.1 christos 115 1.1 christos extern regs_type regs; 116 1.1 christos 117 1.1 christos #define FLAGBIT_C 0x00000001 118 1.1 christos #define FLAGBIT_Z 0x00000002 119 1.1 christos #define FLAGBIT_S 0x00000004 120 1.1 christos #define FLAGBIT_O 0x00000008 121 1.1 christos #define FLAGBIT_I 0x00010000 122 1.1 christos #define FLAGBIT_U 0x00020000 123 1.1 christos #define FLAGBIT_PM 0x00100000 124 1.1 christos #define FLAGBITS_IPL 0x0f000000 125 1.1 christos #define FLAGSHIFT_IPL 24 126 1.1 christos 127 1.1 christos #define FPSWBITS_RM 0x00000003 128 1.1 christos #define FPSWBITS_CV 0x00000004 /* invalid operation */ 129 1.1 christos #define FPSWBITS_CO 0x00000008 /* overflow */ 130 1.1 christos #define FPSWBITS_CZ 0x00000010 /* divide-by-zero */ 131 1.1 christos #define FPSWBITS_CU 0x00000020 /* underflow */ 132 1.1 christos #define FPSWBITS_CX 0x00000040 /* inexact */ 133 1.1 christos #define FPSWBITS_CE 0x00000080 /* unimplemented processing */ 134 1.1 christos #define FPSWBITS_CMASK 0x000000fc /* all the above */ 135 1.1 christos #define FPSWBITS_DN 0x00000100 136 1.1 christos #define FPSW_CESH 8 137 1.1 christos #define FPSWBITS_EV 0x00000400 138 1.1 christos #define FPSWBITS_EO 0x00000800 139 1.1 christos #define FPSWBITS_EZ 0x00001000 140 1.1 christos #define FPSWBITS_EU 0x00002000 141 1.1 christos #define FPSWBITS_EX 0x00004000 142 1.1 christos #define FPSW_EFSH 16 143 1.1 christos #define FPSW_CFSH 24 144 1.1 christos #define FPSWBITS_FV 0x04000000 145 1.1 christos #define FPSWBITS_FO 0x08000000 146 1.1 christos #define FPSWBITS_FZ 0x10000000 147 1.1 christos #define FPSWBITS_FU 0x20000000 148 1.1 christos #define FPSWBITS_FX 0x40000000 149 1.1 christos #define FPSWBITS_FSUM 0x80000000 150 1.1 christos #define FPSWBITS_FMASK 0x7c000000 151 1.1 christos #define FPSWBITS_CLEAR 0xffffff03 /* masked at start of any FP opcode */ 152 1.1 christos 153 1.1 christos #define FPRM_NEAREST 0 154 1.1 christos #define FPRM_ZERO 1 155 1.1 christos #define FPRM_PINF 2 156 1.1 christos #define FPRM_NINF 3 157 1.1 christos 158 1.1 christos extern char *reg_names[]; 159 1.1 christos 160 1.1 christos extern int rx_flagmask; 161 1.1 christos extern int rx_flagand; 162 1.1 christos extern int rx_flagor; 163 1.1 christos 164 1.1 christos extern unsigned int b2mask[]; 165 1.1 christos extern unsigned int b2signbit[]; 166 1.1 christos extern int b2maxsigned[]; 167 1.1 christos extern int b2minsigned[]; 168 1.1 christos 169 1.1 christos void init_regs (void); 170 1.1 christos void stack_heap_stats (void); 171 1.1 christos void set_pointer_width (int bytes); 172 1.1 christos unsigned int get_reg (int id); 173 1.1 christos unsigned long long get_reg64 (int id); 174 1.1 christos void put_reg (int id, unsigned int value); 175 1.1 christos void put_reg64 (int id, unsigned long long value); 176 1.1 christos 177 1.1 christos void set_flags (int mask, int newbits); 178 1.1 christos void set_oszc (long long value, int bytes, int c); 179 1.1 christos void set_szc (long long value, int bytes, int c); 180 1.1 christos void set_osz (long long value, int bytes); 181 1.1 christos void set_sz (long long value, int bytes); 182 1.1 christos void set_zc (int z, int c); 183 1.1 christos void set_c (int c); 184 1.1 christos 185 1.1 christos const char *bits (int v, int b); 186 1.1 christos 187 1.1 christos int condition_true (int cond_id); 188 1.1 christos 189 1.1 christos #define FLAG(f) ((regs.r_psw & f) ? 1 : 0) 190 1.1 christos #define FLAG_C FLAG(FLAGBIT_C) 191 1.1 christos #define FLAG_D FLAG(FLAGBIT_D) 192 1.1 christos #define FLAG_Z FLAG(FLAGBIT_Z) 193 1.1 christos #define FLAG_S FLAG(FLAGBIT_S) 194 1.1 christos #define FLAG_B FLAG(FLAGBIT_B) 195 1.1 christos #define FLAG_O FLAG(FLAGBIT_O) 196 1.1 christos #define FLAG_I FLAG(FLAGBIT_I) 197 1.1 christos #define FLAG_U FLAG(FLAGBIT_U) 198 1.1 christos #define FLAG_PM FLAG(FLAGBIT_PM) 199 1.1 christos 200 1.1 christos /* Instruction step return codes. 201 1.1 christos Suppose one of the decode_* functions below returns a value R: 202 1.1 christos - If RX_STEPPED (R), then the single-step completed normally. 203 1.1 christos - If RX_HIT_BREAK (R), then the program hit a breakpoint. 204 1.1 christos - If RX_EXITED (R), then the program has done an 'exit' system 205 1.1 christos call, and the exit code is RX_EXIT_STATUS (R). 206 1.1 christos - If RX_STOPPED (R), then a signal (number RX_STOP_SIG (R)) was 207 1.1 christos generated. 208 1.1 christos 209 1.1 christos For building step return codes: 210 1.1 christos - RX_MAKE_STEPPED is the return code for finishing a normal step. 211 1.1 christos - RX_MAKE_HIT_BREAK is the return code for hitting a breakpoint. 212 1.1 christos - RX_MAKE_EXITED (C) is the return code for exiting with status C. 213 1.1 christos - RX_MAKE_STOPPED (S) is the return code for stopping on signal S. */ 214 1.1 christos #define RX_MAKE_STEPPED() (1) 215 1.1 christos #define RX_MAKE_HIT_BREAK() (2) 216 1.1 christos #define RX_MAKE_EXITED(c) (((int) (c) << 8) + 3) 217 1.1 christos #define RX_MAKE_STOPPED(s) (((int) (s) << 8) + 4) 218 1.1 christos 219 1.1 christos #define RX_STEPPED(r) ((r) == RX_MAKE_STEPPED ()) 220 1.1 christos #define RX_HIT_BREAK(r) ((r) == RX_MAKE_HIT_BREAK ()) 221 1.1 christos #define RX_EXITED(r) (((r) & 0xff) == 3) 222 1.1 christos #define RX_EXIT_STATUS(r) ((r) >> 8) 223 1.1 christos #define RX_STOPPED(r) (((r) & 0xff) == 4) 224 1.1 christos #define RX_STOP_SIG(r) ((r) >> 8) 225 1.1 christos 226 1.1 christos /* The step result for the current step. Global to allow 227 1.1 christos communication between the stepping function and the system 228 1.1 christos calls. */ 229 1.1 christos extern int step_result; 230 1.1 christos 231 1.1 christos extern unsigned int rx_cycles; 232 1.1 christos 233 1.1 christos /* Used to detect heap/stack collisions. */ 234 1.1 christos extern unsigned int heaptop; 235 1.1 christos extern unsigned int heapbottom; 236 1.1 christos 237 1.1 christos extern int decode_opcode (void); 238 1.1 christos extern void reset_decoder (void); 239 1.1 christos extern void reset_pipeline_stats (void); 240 1.1 christos extern void halt_pipeline_stats (void); 241 1.1 christos extern void pipeline_stats (void); 242 1.1 christos 243 1.10 christos extern void trace_register_changes (void); 244 1.1 christos extern void generate_access_exception (void); 245 1.1 christos extern jmp_buf decode_jmp_buf; 246