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