]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/m32c/cpu.h
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / sim / m32c / cpu.h
1 /* cpu.h --- declarations for the M32C core.
2
3 Copyright (C) 2005, 2007 Free Software Foundation, Inc.
4 Contributed by Red Hat, Inc.
5
6 This file is part of the GNU simulators.
7
8 The GNU simulators are free software; you can redistribute them and/or
9 modify them under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
12
13 The GNU simulators are distributed in the hope that they will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with the GNU simulators; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA */
22
23
24 extern int verbose;
25 extern int trace;
26 extern int enable_counting;
27
28 typedef unsigned char QI;
29 typedef unsigned short HI;
30 typedef unsigned long SI;
31 typedef unsigned long long DI;
32
33 #define CPU_R8C 0x11
34 #define CPU_M16C 0x12
35 #define CPU_M32CM 0x23
36 #define CPU_M32C 0x24
37 extern int m32c_cpu;
38 void m32c_set_cpu (int cpu);
39
40 #define A16 (m32c_cpu & 0x10)
41 #define A24 (m32c_cpu & 0x20)
42
43 typedef struct
44 {
45 HI r_r0;
46 HI r_r2;
47 HI r_r1;
48 HI r_r3;
49 SI r_a0;
50 SI r_a1;
51 SI r_sb;
52 SI r_fb;
53 } reg_bank_type;
54
55 typedef struct
56 {
57 reg_bank_type r[2];
58 QI r_intbh;
59 HI r_intbl;
60 SI r_usp;
61 SI r_isp;
62 SI r_pc;
63 HI r_flags;
64 } regs_type;
65
66 extern regs_type regs;
67 extern int addr_mask;
68 extern int membus_mask;
69
70 #define FLAGBIT_C 0x0001
71 #define FLAGBIT_D 0x0002
72 #define FLAGBIT_Z 0x0004
73 #define FLAGBIT_S 0x0008
74 #define FLAGBIT_B 0x0010
75 #define FLAGBIT_O 0x0020
76 #define FLAGBIT_I 0x0040
77 #define FLAGBIT_U 0x0080
78
79 #define REG_BANK (regs.r_flags & FLAG_B ? 1 : 0)
80
81 typedef enum
82 {
83 mem,
84 r0, r0h, r0l,
85 r1, r1h, r1l,
86 r2, r2r0,
87 r3, r3r1,
88 r3r1r2r0,
89 r3r2r1r0,
90 a0,
91 a1, a1a0,
92 sb, fb,
93 intb, intbl, intbh,
94 sp, usp, isp, pc, flags,
95 num_regs
96 } reg_id;
97
98 extern char *reg_names[];
99 extern int reg_bytes[];
100
101 extern unsigned int b2mask[];
102 extern unsigned int b2signbit[];
103 extern int b2maxsigned[];
104 extern int b2minsigned[];
105
106 void init_regs (void);
107 void stack_heap_stats (void);
108 void set_pointer_width (int bytes);
109 unsigned int get_reg (reg_id id);
110 DI get_reg_ll (reg_id id);
111 void put_reg (reg_id id, unsigned int value);
112 void put_reg_ll (reg_id id, DI value);
113
114 void set_flags (int mask, int newbits);
115 void set_oszc (int value, int bytes, int c);
116 void set_szc (int value, int bytes, int c);
117 void set_osz (int value, int bytes);
118 void set_sz (int value, int bytes);
119 void set_zc (int z, int c);
120 void set_c (int c);
121
122 const char *bits (int v, int b);
123
124 typedef struct
125 {
126 QI bytes;
127 QI mem;
128 HI mask;
129 union
130 {
131 unsigned int addr;
132 reg_id reg;
133 } u;
134 } srcdest;
135
136 void decode_indirect (int src_indirect, int dest_indirect);
137 void decode_index (int src_addend, int dest_addend);
138
139 /* r8c */
140 srcdest decode_srcdest4 (int destcode, int bw);
141 srcdest decode_dest3 (int destcode, int bw);
142 srcdest decode_src2 (int srccode, int bw, int d);
143 srcdest decode_dest1 (int destcode, int bw);
144 srcdest decode_jumpdest (int destcode, int w);
145 srcdest decode_cr (int crcode);
146 srcdest decode_cr_b (int crcode, int bank);
147 #define CR_B_DCT0 0
148 #define CR_B_INTB 1
149 #define CR_B_DMA0 2
150
151 /* m32c */
152 srcdest decode_dest23 (int ddd, int dd, int bytes);
153 srcdest decode_src23 (int sss, int ss, int bytes);
154 srcdest decode_src3 (int sss, int bytes);
155 srcdest decode_dest2 (int dd, int bytes);
156
157 srcdest widen_sd (srcdest sd);
158 srcdest reg_sd (reg_id reg);
159
160 /* Mask has the one appropriate bit set. */
161 srcdest decode_bit (int destcode);
162 srcdest decode_bit11 (int op0);
163 int get_bit (srcdest sd);
164 void put_bit (srcdest sd, int val);
165 int get_bit2 (srcdest sd, int bit);
166 void put_bit2 (srcdest sd, int bit, int val);
167
168 int get_src (srcdest sd);
169 void put_dest (srcdest sd, int value);
170
171 int condition_true (int cond_id);
172
173 #define FLAG(f) (regs.r_flags & f ? 1 : 0)
174 #define FLAG_C FLAG(FLAGBIT_C)
175 #define FLAG_D FLAG(FLAGBIT_D)
176 #define FLAG_Z FLAG(FLAGBIT_Z)
177 #define FLAG_S FLAG(FLAGBIT_S)
178 #define FLAG_B FLAG(FLAGBIT_B)
179 #define FLAG_O FLAG(FLAGBIT_O)
180 #define FLAG_I FLAG(FLAGBIT_I)
181 #define FLAG_U FLAG(FLAGBIT_U)
182
183 /* Instruction step return codes.
184 Suppose one of the decode_* functions below returns a value R:
185 - If M32C_STEPPED (R), then the single-step completed normally.
186 - If M32C_HIT_BREAK (R), then the program hit a breakpoint.
187 - If M32C_EXITED (R), then the program has done an 'exit' system
188 call, and the exit code is M32C_EXIT_STATUS (R).
189 - If M32C_STOPPED (R), then a signal (number M32C_STOP_SIG (R)) was
190 generated.
191
192 For building step return codes:
193 - M32C_MAKE_STEPPED is the return code for finishing a normal step.
194 - M32C_MAKE_HIT_BREAK is the return code for hitting a breakpoint.
195 - M32C_MAKE_EXITED (C) is the return code for exiting with status C.
196 - M32C_MAKE_STOPPED (S) is the return code for stopping on signal S. */
197 #define M32C_MAKE_STEPPED() (0)
198 #define M32C_MAKE_HIT_BREAK() (1)
199 #define M32C_MAKE_EXITED(c) (((int) (c) << 8) + 2)
200 #define M32C_MAKE_STOPPED(s) (((int) (s) << 8) + 3)
201
202 #define M32C_STEPPED(r) ((r) == M32C_MAKE_STEPPED ())
203 #define M32C_HIT_BREAK(r) ((r) == M32C_MAKE_HIT_BREAK ())
204 #define M32C_EXITED(r) (((r) & 0xff) == 2)
205 #define M32C_EXIT_STATUS(r) ((r) >> 8)
206 #define M32C_STOPPED(r) (((r) & 0xff) == 3)
207 #define M32C_STOP_SIG(r) ((r) >> 8)
208
209 /* The step result for the current step. Global to allow
210 communication between the stepping function and the system
211 calls. */
212 extern int step_result;
213
214 /* Used to detect heap/stack collisions */
215 extern unsigned int heaptop;
216 extern unsigned int heapbottom;
217
218 /* Points to one of the below functions, set by m32c_load(). */
219 extern int (*decode_opcode) ();
220
221 extern int decode_r8c ();
222 extern int decode_m32c ();
223
224 extern void trace_register_changes ();