Statistics
| Branch: | Revision:

root / target-sparc / translate.c @ 97eb5b14

History | View | Annotate | Download (22.4 kB)

1 7a3f1944 bellard
/*
2 7a3f1944 bellard
   SPARC translation
3 7a3f1944 bellard

4 7a3f1944 bellard
   Copyright (C) 2003 Thomas M. Ogrisegg <tom@fnord.at>
5 bd497938 bellard
   Copyright (C) 2003 Fabrice Bellard
6 7a3f1944 bellard

7 7a3f1944 bellard
   This library is free software; you can redistribute it and/or
8 7a3f1944 bellard
   modify it under the terms of the GNU Lesser General Public
9 7a3f1944 bellard
   License as published by the Free Software Foundation; either
10 7a3f1944 bellard
   version 2 of the License, or (at your option) any later version.
11 7a3f1944 bellard

12 7a3f1944 bellard
   This library is distributed in the hope that it will be useful,
13 7a3f1944 bellard
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 7a3f1944 bellard
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 7a3f1944 bellard
   Lesser General Public License for more details.
16 7a3f1944 bellard

17 7a3f1944 bellard
   You should have received a copy of the GNU Lesser General Public
18 7a3f1944 bellard
   License along with this library; if not, write to the Free Software
19 7a3f1944 bellard
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 7a3f1944 bellard
 */
21 7a3f1944 bellard
22 7a3f1944 bellard
/*
23 7a3f1944 bellard
   TODO-list:
24 7a3f1944 bellard

25 bd497938 bellard
   NPC/PC static optimisations (use JUMP_TB when possible)
26 7a3f1944 bellard
   FPU-Instructions
27 7a3f1944 bellard
   Privileged instructions
28 bd497938 bellard
   Coprocessor-Instructions
29 7a3f1944 bellard
   Optimize synthetic instructions
30 7a3f1944 bellard
   Optional alignment and privileged instruction check
31 bd497938 bellard
*/
32 7a3f1944 bellard
33 7a3f1944 bellard
#include <stdarg.h>
34 7a3f1944 bellard
#include <stdlib.h>
35 7a3f1944 bellard
#include <stdio.h>
36 7a3f1944 bellard
#include <string.h>
37 7a3f1944 bellard
#include <inttypes.h>
38 7a3f1944 bellard
39 7a3f1944 bellard
#include "cpu.h"
40 7a3f1944 bellard
#include "exec-all.h"
41 7a3f1944 bellard
#include "disas.h"
42 7a3f1944 bellard
43 7a3f1944 bellard
#define DEBUG_DISAS
44 7a3f1944 bellard
45 72cbca10 bellard
#define DYNAMIC_PC  1 /* dynamic pc value */
46 72cbca10 bellard
#define JUMP_PC     2 /* dynamic pc value which takes only two values
47 72cbca10 bellard
                         according to jump_pc[T2] */
48 72cbca10 bellard
49 7a3f1944 bellard
typedef struct DisasContext {
50 72cbca10 bellard
    target_ulong pc;        /* current Program Counter: integer or DYNAMIC_PC */
51 72cbca10 bellard
    target_ulong npc;        /* next PC: integer or DYNAMIC_PC or JUMP_PC */
52 72cbca10 bellard
    target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
53 cf495bcf bellard
    int is_br;
54 cf495bcf bellard
    struct TranslationBlock *tb;
55 7a3f1944 bellard
} DisasContext;
56 7a3f1944 bellard
57 7a3f1944 bellard
static uint16_t *gen_opc_ptr;
58 7a3f1944 bellard
static uint32_t *gen_opparam_ptr;
59 7a3f1944 bellard
extern FILE *logfile;
60 7a3f1944 bellard
extern int loglevel;
61 7a3f1944 bellard
62 7a3f1944 bellard
enum {
63 7a3f1944 bellard
#define DEF(s,n,copy_size) INDEX_op_ ## s,
64 7a3f1944 bellard
#include "opc.h"
65 7a3f1944 bellard
#undef DEF
66 cf495bcf bellard
    NB_OPS
67 7a3f1944 bellard
};
68 7a3f1944 bellard
69 7a3f1944 bellard
#include "gen-op.h"
70 7a3f1944 bellard
71 7a3f1944 bellard
#define GET_FIELD(X, FROM, TO) \
72 7a3f1944 bellard
  ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
73 7a3f1944 bellard
74 7a3f1944 bellard
#define IS_IMM (insn & (1<<13))
75 7a3f1944 bellard
76 cf495bcf bellard
static void disas_sparc_insn(DisasContext * dc);
77 7a3f1944 bellard
78 7a3f1944 bellard
static GenOpFunc *gen_op_movl_TN_reg[2][32] = {
79 cf495bcf bellard
    {
80 cf495bcf bellard
     gen_op_movl_g0_T0,
81 cf495bcf bellard
     gen_op_movl_g1_T0,
82 cf495bcf bellard
     gen_op_movl_g2_T0,
83 cf495bcf bellard
     gen_op_movl_g3_T0,
84 cf495bcf bellard
     gen_op_movl_g4_T0,
85 cf495bcf bellard
     gen_op_movl_g5_T0,
86 cf495bcf bellard
     gen_op_movl_g6_T0,
87 cf495bcf bellard
     gen_op_movl_g7_T0,
88 cf495bcf bellard
     gen_op_movl_o0_T0,
89 cf495bcf bellard
     gen_op_movl_o1_T0,
90 cf495bcf bellard
     gen_op_movl_o2_T0,
91 cf495bcf bellard
     gen_op_movl_o3_T0,
92 cf495bcf bellard
     gen_op_movl_o4_T0,
93 cf495bcf bellard
     gen_op_movl_o5_T0,
94 cf495bcf bellard
     gen_op_movl_o6_T0,
95 cf495bcf bellard
     gen_op_movl_o7_T0,
96 cf495bcf bellard
     gen_op_movl_l0_T0,
97 cf495bcf bellard
     gen_op_movl_l1_T0,
98 cf495bcf bellard
     gen_op_movl_l2_T0,
99 cf495bcf bellard
     gen_op_movl_l3_T0,
100 cf495bcf bellard
     gen_op_movl_l4_T0,
101 cf495bcf bellard
     gen_op_movl_l5_T0,
102 cf495bcf bellard
     gen_op_movl_l6_T0,
103 cf495bcf bellard
     gen_op_movl_l7_T0,
104 cf495bcf bellard
     gen_op_movl_i0_T0,
105 cf495bcf bellard
     gen_op_movl_i1_T0,
106 cf495bcf bellard
     gen_op_movl_i2_T0,
107 cf495bcf bellard
     gen_op_movl_i3_T0,
108 cf495bcf bellard
     gen_op_movl_i4_T0,
109 cf495bcf bellard
     gen_op_movl_i5_T0,
110 cf495bcf bellard
     gen_op_movl_i6_T0,
111 cf495bcf bellard
     gen_op_movl_i7_T0,
112 cf495bcf bellard
     },
113 cf495bcf bellard
    {
114 cf495bcf bellard
     gen_op_movl_g0_T1,
115 cf495bcf bellard
     gen_op_movl_g1_T1,
116 cf495bcf bellard
     gen_op_movl_g2_T1,
117 cf495bcf bellard
     gen_op_movl_g3_T1,
118 cf495bcf bellard
     gen_op_movl_g4_T1,
119 cf495bcf bellard
     gen_op_movl_g5_T1,
120 cf495bcf bellard
     gen_op_movl_g6_T1,
121 cf495bcf bellard
     gen_op_movl_g7_T1,
122 cf495bcf bellard
     gen_op_movl_o0_T1,
123 cf495bcf bellard
     gen_op_movl_o1_T1,
124 cf495bcf bellard
     gen_op_movl_o2_T1,
125 cf495bcf bellard
     gen_op_movl_o3_T1,
126 cf495bcf bellard
     gen_op_movl_o4_T1,
127 cf495bcf bellard
     gen_op_movl_o5_T1,
128 cf495bcf bellard
     gen_op_movl_o6_T1,
129 cf495bcf bellard
     gen_op_movl_o7_T1,
130 cf495bcf bellard
     gen_op_movl_l0_T1,
131 cf495bcf bellard
     gen_op_movl_l1_T1,
132 cf495bcf bellard
     gen_op_movl_l2_T1,
133 cf495bcf bellard
     gen_op_movl_l3_T1,
134 cf495bcf bellard
     gen_op_movl_l4_T1,
135 cf495bcf bellard
     gen_op_movl_l5_T1,
136 cf495bcf bellard
     gen_op_movl_l6_T1,
137 cf495bcf bellard
     gen_op_movl_l7_T1,
138 cf495bcf bellard
     gen_op_movl_i0_T1,
139 cf495bcf bellard
     gen_op_movl_i1_T1,
140 cf495bcf bellard
     gen_op_movl_i2_T1,
141 cf495bcf bellard
     gen_op_movl_i3_T1,
142 cf495bcf bellard
     gen_op_movl_i4_T1,
143 cf495bcf bellard
     gen_op_movl_i5_T1,
144 cf495bcf bellard
     gen_op_movl_i6_T1,
145 cf495bcf bellard
     gen_op_movl_i7_T1,
146 cf495bcf bellard
     }
147 7a3f1944 bellard
};
148 7a3f1944 bellard
149 7a3f1944 bellard
static GenOpFunc *gen_op_movl_reg_TN[3][32] = {
150 cf495bcf bellard
    {
151 cf495bcf bellard
     gen_op_movl_T0_g0,
152 cf495bcf bellard
     gen_op_movl_T0_g1,
153 cf495bcf bellard
     gen_op_movl_T0_g2,
154 cf495bcf bellard
     gen_op_movl_T0_g3,
155 cf495bcf bellard
     gen_op_movl_T0_g4,
156 cf495bcf bellard
     gen_op_movl_T0_g5,
157 cf495bcf bellard
     gen_op_movl_T0_g6,
158 cf495bcf bellard
     gen_op_movl_T0_g7,
159 cf495bcf bellard
     gen_op_movl_T0_o0,
160 cf495bcf bellard
     gen_op_movl_T0_o1,
161 cf495bcf bellard
     gen_op_movl_T0_o2,
162 cf495bcf bellard
     gen_op_movl_T0_o3,
163 cf495bcf bellard
     gen_op_movl_T0_o4,
164 cf495bcf bellard
     gen_op_movl_T0_o5,
165 cf495bcf bellard
     gen_op_movl_T0_o6,
166 cf495bcf bellard
     gen_op_movl_T0_o7,
167 cf495bcf bellard
     gen_op_movl_T0_l0,
168 cf495bcf bellard
     gen_op_movl_T0_l1,
169 cf495bcf bellard
     gen_op_movl_T0_l2,
170 cf495bcf bellard
     gen_op_movl_T0_l3,
171 cf495bcf bellard
     gen_op_movl_T0_l4,
172 cf495bcf bellard
     gen_op_movl_T0_l5,
173 cf495bcf bellard
     gen_op_movl_T0_l6,
174 cf495bcf bellard
     gen_op_movl_T0_l7,
175 cf495bcf bellard
     gen_op_movl_T0_i0,
176 cf495bcf bellard
     gen_op_movl_T0_i1,
177 cf495bcf bellard
     gen_op_movl_T0_i2,
178 cf495bcf bellard
     gen_op_movl_T0_i3,
179 cf495bcf bellard
     gen_op_movl_T0_i4,
180 cf495bcf bellard
     gen_op_movl_T0_i5,
181 cf495bcf bellard
     gen_op_movl_T0_i6,
182 cf495bcf bellard
     gen_op_movl_T0_i7,
183 cf495bcf bellard
     },
184 cf495bcf bellard
    {
185 cf495bcf bellard
     gen_op_movl_T1_g0,
186 cf495bcf bellard
     gen_op_movl_T1_g1,
187 cf495bcf bellard
     gen_op_movl_T1_g2,
188 cf495bcf bellard
     gen_op_movl_T1_g3,
189 cf495bcf bellard
     gen_op_movl_T1_g4,
190 cf495bcf bellard
     gen_op_movl_T1_g5,
191 cf495bcf bellard
     gen_op_movl_T1_g6,
192 cf495bcf bellard
     gen_op_movl_T1_g7,
193 cf495bcf bellard
     gen_op_movl_T1_o0,
194 cf495bcf bellard
     gen_op_movl_T1_o1,
195 cf495bcf bellard
     gen_op_movl_T1_o2,
196 cf495bcf bellard
     gen_op_movl_T1_o3,
197 cf495bcf bellard
     gen_op_movl_T1_o4,
198 cf495bcf bellard
     gen_op_movl_T1_o5,
199 cf495bcf bellard
     gen_op_movl_T1_o6,
200 cf495bcf bellard
     gen_op_movl_T1_o7,
201 cf495bcf bellard
     gen_op_movl_T1_l0,
202 cf495bcf bellard
     gen_op_movl_T1_l1,
203 cf495bcf bellard
     gen_op_movl_T1_l2,
204 cf495bcf bellard
     gen_op_movl_T1_l3,
205 cf495bcf bellard
     gen_op_movl_T1_l4,
206 cf495bcf bellard
     gen_op_movl_T1_l5,
207 cf495bcf bellard
     gen_op_movl_T1_l6,
208 cf495bcf bellard
     gen_op_movl_T1_l7,
209 cf495bcf bellard
     gen_op_movl_T1_i0,
210 cf495bcf bellard
     gen_op_movl_T1_i1,
211 cf495bcf bellard
     gen_op_movl_T1_i2,
212 cf495bcf bellard
     gen_op_movl_T1_i3,
213 cf495bcf bellard
     gen_op_movl_T1_i4,
214 cf495bcf bellard
     gen_op_movl_T1_i5,
215 cf495bcf bellard
     gen_op_movl_T1_i6,
216 cf495bcf bellard
     gen_op_movl_T1_i7,
217 cf495bcf bellard
     },
218 cf495bcf bellard
    {
219 cf495bcf bellard
     gen_op_movl_T2_g0,
220 cf495bcf bellard
     gen_op_movl_T2_g1,
221 cf495bcf bellard
     gen_op_movl_T2_g2,
222 cf495bcf bellard
     gen_op_movl_T2_g3,
223 cf495bcf bellard
     gen_op_movl_T2_g4,
224 cf495bcf bellard
     gen_op_movl_T2_g5,
225 cf495bcf bellard
     gen_op_movl_T2_g6,
226 cf495bcf bellard
     gen_op_movl_T2_g7,
227 cf495bcf bellard
     gen_op_movl_T2_o0,
228 cf495bcf bellard
     gen_op_movl_T2_o1,
229 cf495bcf bellard
     gen_op_movl_T2_o2,
230 cf495bcf bellard
     gen_op_movl_T2_o3,
231 cf495bcf bellard
     gen_op_movl_T2_o4,
232 cf495bcf bellard
     gen_op_movl_T2_o5,
233 cf495bcf bellard
     gen_op_movl_T2_o6,
234 cf495bcf bellard
     gen_op_movl_T2_o7,
235 cf495bcf bellard
     gen_op_movl_T2_l0,
236 cf495bcf bellard
     gen_op_movl_T2_l1,
237 cf495bcf bellard
     gen_op_movl_T2_l2,
238 cf495bcf bellard
     gen_op_movl_T2_l3,
239 cf495bcf bellard
     gen_op_movl_T2_l4,
240 cf495bcf bellard
     gen_op_movl_T2_l5,
241 cf495bcf bellard
     gen_op_movl_T2_l6,
242 cf495bcf bellard
     gen_op_movl_T2_l7,
243 cf495bcf bellard
     gen_op_movl_T2_i0,
244 cf495bcf bellard
     gen_op_movl_T2_i1,
245 cf495bcf bellard
     gen_op_movl_T2_i2,
246 cf495bcf bellard
     gen_op_movl_T2_i3,
247 cf495bcf bellard
     gen_op_movl_T2_i4,
248 cf495bcf bellard
     gen_op_movl_T2_i5,
249 cf495bcf bellard
     gen_op_movl_T2_i6,
250 cf495bcf bellard
     gen_op_movl_T2_i7,
251 cf495bcf bellard
     }
252 7a3f1944 bellard
};
253 7a3f1944 bellard
254 7a3f1944 bellard
static GenOpFunc1 *gen_op_movl_TN_im[3] = {
255 cf495bcf bellard
    gen_op_movl_T0_im,
256 cf495bcf bellard
    gen_op_movl_T1_im,
257 cf495bcf bellard
    gen_op_movl_T2_im
258 7a3f1944 bellard
};
259 7a3f1944 bellard
260 cf495bcf bellard
static inline void gen_movl_imm_TN(int reg, int imm)
261 7a3f1944 bellard
{
262 cf495bcf bellard
    gen_op_movl_TN_im[reg] (imm);
263 7a3f1944 bellard
}
264 7a3f1944 bellard
265 cf495bcf bellard
static inline void gen_movl_imm_T1(int val)
266 7a3f1944 bellard
{
267 cf495bcf bellard
    gen_movl_imm_TN(1, val);
268 7a3f1944 bellard
}
269 7a3f1944 bellard
270 cf495bcf bellard
static inline void gen_movl_imm_T0(int val)
271 7a3f1944 bellard
{
272 cf495bcf bellard
    gen_movl_imm_TN(0, val);
273 7a3f1944 bellard
}
274 7a3f1944 bellard
275 cf495bcf bellard
static inline void gen_movl_reg_TN(int reg, int t)
276 7a3f1944 bellard
{
277 cf495bcf bellard
    if (reg)
278 cf495bcf bellard
        gen_op_movl_reg_TN[t][reg] ();
279 cf495bcf bellard
    else
280 cf495bcf bellard
        gen_movl_imm_TN(t, 0);
281 7a3f1944 bellard
}
282 7a3f1944 bellard
283 cf495bcf bellard
static inline void gen_movl_reg_T0(int reg)
284 7a3f1944 bellard
{
285 cf495bcf bellard
    gen_movl_reg_TN(reg, 0);
286 7a3f1944 bellard
}
287 7a3f1944 bellard
288 cf495bcf bellard
static inline void gen_movl_reg_T1(int reg)
289 7a3f1944 bellard
{
290 cf495bcf bellard
    gen_movl_reg_TN(reg, 1);
291 7a3f1944 bellard
}
292 7a3f1944 bellard
293 cf495bcf bellard
static inline void gen_movl_reg_T2(int reg)
294 7a3f1944 bellard
{
295 cf495bcf bellard
    gen_movl_reg_TN(reg, 2);
296 7a3f1944 bellard
}
297 7a3f1944 bellard
298 cf495bcf bellard
static inline void gen_movl_TN_reg(int reg, int t)
299 7a3f1944 bellard
{
300 cf495bcf bellard
    if (reg)
301 cf495bcf bellard
        gen_op_movl_TN_reg[t][reg] ();
302 7a3f1944 bellard
}
303 7a3f1944 bellard
304 cf495bcf bellard
static inline void gen_movl_T0_reg(int reg)
305 7a3f1944 bellard
{
306 cf495bcf bellard
    gen_movl_TN_reg(reg, 0);
307 7a3f1944 bellard
}
308 7a3f1944 bellard
309 cf495bcf bellard
static inline void gen_movl_T1_reg(int reg)
310 7a3f1944 bellard
{
311 cf495bcf bellard
    gen_movl_TN_reg(reg, 1);
312 7a3f1944 bellard
}
313 7a3f1944 bellard
314 72cbca10 bellard
/* call this function before using T2 as it may have been set for a jump */
315 72cbca10 bellard
static inline void flush_T2(DisasContext * dc)
316 72cbca10 bellard
{
317 72cbca10 bellard
    if (dc->npc == JUMP_PC) {
318 72cbca10 bellard
        gen_op_generic_branch(dc->jump_pc[0], dc->jump_pc[1]);
319 72cbca10 bellard
        dc->npc = DYNAMIC_PC;
320 72cbca10 bellard
    }
321 72cbca10 bellard
}
322 72cbca10 bellard
323 72cbca10 bellard
static inline void save_npc(DisasContext * dc)
324 72cbca10 bellard
{
325 72cbca10 bellard
    if (dc->npc == JUMP_PC) {
326 72cbca10 bellard
        gen_op_generic_branch(dc->jump_pc[0], dc->jump_pc[1]);
327 72cbca10 bellard
        dc->npc = DYNAMIC_PC;
328 72cbca10 bellard
    } else if (dc->npc != DYNAMIC_PC) {
329 72cbca10 bellard
        gen_op_movl_npc_im(dc->npc);
330 72cbca10 bellard
    }
331 72cbca10 bellard
}
332 72cbca10 bellard
333 72cbca10 bellard
static inline void save_state(DisasContext * dc)
334 72cbca10 bellard
{
335 72cbca10 bellard
    gen_op_jmp_im((uint32_t)dc->pc);
336 72cbca10 bellard
    save_npc(dc);
337 72cbca10 bellard
}
338 72cbca10 bellard
339 cf495bcf bellard
static void gen_cond(int cond)
340 7a3f1944 bellard
{
341 7a3f1944 bellard
        switch (cond) {
342 cf495bcf bellard
        case 0x0:
343 cf495bcf bellard
            gen_op_movl_T2_0();
344 cf495bcf bellard
            break;
345 cf495bcf bellard
        case 0x1:
346 cf495bcf bellard
            gen_op_eval_be();
347 cf495bcf bellard
            break;
348 cf495bcf bellard
        case 0x2:
349 cf495bcf bellard
            gen_op_eval_ble();
350 cf495bcf bellard
            break;
351 cf495bcf bellard
        case 0x3:
352 cf495bcf bellard
            gen_op_eval_bl();
353 cf495bcf bellard
            break;
354 cf495bcf bellard
        case 0x4:
355 cf495bcf bellard
            gen_op_eval_bleu();
356 cf495bcf bellard
            break;
357 cf495bcf bellard
        case 0x5:
358 cf495bcf bellard
            gen_op_eval_bcs();
359 cf495bcf bellard
            break;
360 cf495bcf bellard
        case 0x6:
361 cf495bcf bellard
            gen_op_eval_bneg();
362 cf495bcf bellard
            break;
363 cf495bcf bellard
        case 0x7:
364 cf495bcf bellard
            gen_op_eval_bvs();
365 cf495bcf bellard
            break;
366 cf495bcf bellard
        case 0x8:
367 cf495bcf bellard
            gen_op_movl_T2_1();
368 cf495bcf bellard
            break;
369 cf495bcf bellard
        case 0x9:
370 cf495bcf bellard
            gen_op_eval_bne();
371 cf495bcf bellard
            break;
372 cf495bcf bellard
        case 0xa:
373 cf495bcf bellard
            gen_op_eval_bg();
374 cf495bcf bellard
            break;
375 cf495bcf bellard
        case 0xb:
376 cf495bcf bellard
            gen_op_eval_bge();
377 cf495bcf bellard
            break;
378 cf495bcf bellard
        case 0xc:
379 cf495bcf bellard
            gen_op_eval_bgu();
380 cf495bcf bellard
            break;
381 cf495bcf bellard
        case 0xd:
382 cf495bcf bellard
            gen_op_eval_bcc();
383 cf495bcf bellard
            break;
384 cf495bcf bellard
        case 0xe:
385 cf495bcf bellard
            gen_op_eval_bpos();
386 cf495bcf bellard
            break;
387 cf495bcf bellard
        default:
388 cf495bcf bellard
        case 0xf:
389 cf495bcf bellard
            gen_op_eval_bvc();
390 cf495bcf bellard
            break;
391 7a3f1944 bellard
        }
392 7a3f1944 bellard
}
393 7a3f1944 bellard
394 cf495bcf bellard
395 cf495bcf bellard
static void do_branch(DisasContext * dc, uint32_t target, uint32_t insn)
396 7a3f1944 bellard
{
397 cf495bcf bellard
    unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
398 cf495bcf bellard
    target += (uint32_t) dc->pc;
399 cf495bcf bellard
    if (cond == 0x0) {
400 cf495bcf bellard
        /* unconditional not taken */
401 cf495bcf bellard
        if (a) {
402 cf495bcf bellard
            dc->pc = dc->npc + 4;
403 cf495bcf bellard
            dc->npc = dc->pc + 4;
404 cf495bcf bellard
        } else {
405 cf495bcf bellard
            dc->pc = dc->npc;
406 cf495bcf bellard
            dc->npc = dc->pc + 4;
407 cf495bcf bellard
        }
408 cf495bcf bellard
    } else if (cond == 0x8) {
409 cf495bcf bellard
        /* unconditional taken */
410 cf495bcf bellard
        if (a) {
411 72cbca10 bellard
            dc->pc = target;
412 cf495bcf bellard
            dc->npc = dc->pc + 4;
413 cf495bcf bellard
        } else {
414 cf495bcf bellard
            dc->pc = dc->npc;
415 72cbca10 bellard
            dc->npc = target;
416 cf495bcf bellard
        }
417 cf495bcf bellard
    } else {
418 72cbca10 bellard
        flush_T2(dc);
419 cf495bcf bellard
        gen_cond(cond);
420 cf495bcf bellard
        if (a) {
421 72cbca10 bellard
            gen_op_branch_a((long)dc->tb, target, dc->npc);
422 cf495bcf bellard
            dc->is_br = 1;
423 cf495bcf bellard
        } else {
424 cf495bcf bellard
            dc->pc = dc->npc;
425 72cbca10 bellard
            dc->jump_pc[0] = target;
426 72cbca10 bellard
            dc->jump_pc[1] = dc->npc + 4;
427 72cbca10 bellard
            dc->npc = JUMP_PC;
428 cf495bcf bellard
        }
429 cf495bcf bellard
    }
430 7a3f1944 bellard
}
431 7a3f1944 bellard
432 cf495bcf bellard
#define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
433 7a3f1944 bellard
434 cf495bcf bellard
static int sign_extend(int x, int len)
435 7a3f1944 bellard
{
436 cf495bcf bellard
    len = 32 - len;
437 cf495bcf bellard
    return (x << len) >> len;
438 7a3f1944 bellard
}
439 7a3f1944 bellard
440 cf495bcf bellard
static void disas_sparc_insn(DisasContext * dc)
441 cf495bcf bellard
{
442 cf495bcf bellard
    unsigned int insn, opc, rs1, rs2, rd;
443 7a3f1944 bellard
444 72cbca10 bellard
    insn = ldl_code((uint8_t *)dc->pc);
445 cf495bcf bellard
    opc = GET_FIELD(insn, 0, 1);
446 7a3f1944 bellard
447 cf495bcf bellard
    rd = GET_FIELD(insn, 2, 6);
448 cf495bcf bellard
    switch (opc) {
449 cf495bcf bellard
    case 0:                        /* branches/sethi */
450 cf495bcf bellard
        {
451 cf495bcf bellard
            unsigned int xop = GET_FIELD(insn, 7, 9);
452 cf495bcf bellard
            int target;
453 cf495bcf bellard
            target = GET_FIELD(insn, 10, 31);
454 cf495bcf bellard
            switch (xop) {
455 cf495bcf bellard
            case 0x0:
456 cf495bcf bellard
            case 0x1:                /* UNIMPL */
457 cf495bcf bellard
                goto illegal_insn;
458 cf495bcf bellard
            case 0x2:                /* BN+x */
459 7a3f1944 bellard
                {
460 cf495bcf bellard
                    target <<= 2;
461 cf495bcf bellard
                    target = sign_extend(target, 22);
462 cf495bcf bellard
                    do_branch(dc, target, insn);
463 cf495bcf bellard
                    goto jmp_insn;
464 7a3f1944 bellard
                }
465 cf495bcf bellard
            case 0x3:                /* FBN+x */
466 cf495bcf bellard
                break;
467 cf495bcf bellard
            case 0x4:                /* SETHI */
468 cf495bcf bellard
                gen_movl_imm_T0(target << 10);
469 cf495bcf bellard
                gen_movl_T0_reg(rd);
470 cf495bcf bellard
                break;
471 cf495bcf bellard
            case 0x5:                /*CBN+x */
472 cf495bcf bellard
                break;
473 cf495bcf bellard
            }
474 cf495bcf bellard
            break;
475 cf495bcf bellard
        }
476 cf495bcf bellard
    case 1:
477 cf495bcf bellard
        /*CALL*/ {
478 cf495bcf bellard
            unsigned int target = GET_FIELDs(insn, 2, 31) << 2;
479 cf495bcf bellard
480 cf495bcf bellard
            gen_op_movl_T0_im((long) (dc->pc));
481 cf495bcf bellard
            gen_movl_T0_reg(15);
482 72cbca10 bellard
            target = dc->pc + target;
483 cf495bcf bellard
            dc->pc = dc->npc;
484 72cbca10 bellard
            dc->npc = target;
485 cf495bcf bellard
        }
486 cf495bcf bellard
        goto jmp_insn;
487 cf495bcf bellard
    case 2:                        /* FPU & Logical Operations */
488 cf495bcf bellard
        {
489 cf495bcf bellard
            unsigned int xop = GET_FIELD(insn, 7, 12);
490 cf495bcf bellard
            if (xop == 0x3a) {        /* generate trap */
491 cf495bcf bellard
                int cond;
492 cf495bcf bellard
                rs1 = GET_FIELD(insn, 13, 17);
493 cf495bcf bellard
                gen_movl_reg_T0(rs1);
494 cf495bcf bellard
                if (IS_IMM) {
495 cf495bcf bellard
                    gen_movl_imm_T1(GET_FIELD(insn, 25, 31));
496 cf495bcf bellard
                } else {
497 cf495bcf bellard
                    rs2 = GET_FIELD(insn, 27, 31);
498 cf495bcf bellard
                    gen_movl_reg_T1(rs2);
499 cf495bcf bellard
                }
500 cf495bcf bellard
                gen_op_add_T1_T0();
501 cf495bcf bellard
                save_state(dc);
502 cf495bcf bellard
                cond = GET_FIELD(insn, 3, 6);
503 cf495bcf bellard
                if (cond == 0x8) {
504 cf495bcf bellard
                    gen_op_trap_T0();
505 cf495bcf bellard
                    dc->is_br = 1;
506 cf495bcf bellard
                    goto jmp_insn;
507 cf495bcf bellard
                } else {
508 cf495bcf bellard
                    gen_op_trapcc_T0();
509 cf495bcf bellard
                }
510 cf495bcf bellard
            } else if (xop == 0x28) {
511 cf495bcf bellard
                rs1 = GET_FIELD(insn, 13, 17);
512 cf495bcf bellard
                switch(rs1) {
513 cf495bcf bellard
                case 0: /* rdy */
514 cf495bcf bellard
                    gen_op_rdy();
515 cf495bcf bellard
                    gen_movl_T0_reg(rd);
516 cf495bcf bellard
                    break;
517 cf495bcf bellard
                default:
518 cf495bcf bellard
                    goto illegal_insn;
519 cf495bcf bellard
                }
520 cf495bcf bellard
            } else if (xop == 0x34 || xop == 0x35) {        /* FPU Operations */
521 cf495bcf bellard
                goto illegal_insn;
522 cf495bcf bellard
            } else {
523 cf495bcf bellard
                rs1 = GET_FIELD(insn, 13, 17);
524 cf495bcf bellard
                gen_movl_reg_T0(rs1);
525 cf495bcf bellard
                if (IS_IMM) {        /* immediate */
526 cf495bcf bellard
                    rs2 = GET_FIELDs(insn, 19, 31);
527 cf495bcf bellard
                    gen_movl_imm_T1(rs2);
528 cf495bcf bellard
                } else {                /* register */
529 cf495bcf bellard
                    rs2 = GET_FIELD(insn, 27, 31);
530 cf495bcf bellard
                    gen_movl_reg_T1(rs2);
531 cf495bcf bellard
                }
532 cf495bcf bellard
                if (xop < 0x20) {
533 cf495bcf bellard
                    switch (xop & ~0x10) {
534 cf495bcf bellard
                    case 0x0:
535 cf495bcf bellard
                        if (xop & 0x10)
536 cf495bcf bellard
                            gen_op_add_T1_T0_cc();
537 cf495bcf bellard
                        else
538 cf495bcf bellard
                            gen_op_add_T1_T0();
539 cf495bcf bellard
                        break;
540 cf495bcf bellard
                    case 0x1:
541 cf495bcf bellard
                        gen_op_and_T1_T0();
542 cf495bcf bellard
                        if (xop & 0x10)
543 cf495bcf bellard
                            gen_op_logic_T0_cc();
544 cf495bcf bellard
                        break;
545 cf495bcf bellard
                    case 0x2:
546 cf495bcf bellard
                        gen_op_or_T1_T0();
547 cf495bcf bellard
                        if (xop & 0x10)
548 cf495bcf bellard
                            gen_op_logic_T0_cc();
549 cf495bcf bellard
                        break;
550 cf495bcf bellard
                    case 0x3:
551 cf495bcf bellard
                        gen_op_xor_T1_T0();
552 cf495bcf bellard
                        if (xop & 0x10)
553 cf495bcf bellard
                            gen_op_logic_T0_cc();
554 cf495bcf bellard
                        break;
555 cf495bcf bellard
                    case 0x4:
556 cf495bcf bellard
                        if (xop & 0x10)
557 cf495bcf bellard
                            gen_op_sub_T1_T0_cc();
558 cf495bcf bellard
                        else
559 cf495bcf bellard
                            gen_op_sub_T1_T0();
560 cf495bcf bellard
                        break;
561 cf495bcf bellard
                    case 0x5:
562 cf495bcf bellard
                        gen_op_andn_T1_T0();
563 cf495bcf bellard
                        if (xop & 0x10)
564 cf495bcf bellard
                            gen_op_logic_T0_cc();
565 cf495bcf bellard
                        break;
566 cf495bcf bellard
                    case 0x6:
567 cf495bcf bellard
                        gen_op_orn_T1_T0();
568 cf495bcf bellard
                        if (xop & 0x10)
569 cf495bcf bellard
                            gen_op_logic_T0_cc();
570 cf495bcf bellard
                        break;
571 cf495bcf bellard
                    case 0x7:
572 cf495bcf bellard
                        gen_op_xnor_T1_T0();
573 cf495bcf bellard
                        if (xop & 0x10)
574 cf495bcf bellard
                            gen_op_logic_T0_cc();
575 cf495bcf bellard
                        break;
576 cf495bcf bellard
                    case 0x8:
577 cf495bcf bellard
                        gen_op_addx_T1_T0();
578 cf495bcf bellard
                        if (xop & 0x10)
579 cf495bcf bellard
                            gen_op_set_flags();
580 cf495bcf bellard
                        break;
581 cf495bcf bellard
                    case 0xa:
582 cf495bcf bellard
                        gen_op_umul_T1_T0();
583 cf495bcf bellard
                        if (xop & 0x10)
584 cf495bcf bellard
                            gen_op_logic_T0_cc();
585 cf495bcf bellard
                        break;
586 cf495bcf bellard
                    case 0xb:
587 cf495bcf bellard
                        gen_op_smul_T1_T0();
588 cf495bcf bellard
                        if (xop & 0x10)
589 cf495bcf bellard
                            gen_op_logic_T0_cc();
590 cf495bcf bellard
                        break;
591 cf495bcf bellard
                    case 0xc:
592 cf495bcf bellard
                        gen_op_subx_T1_T0();
593 cf495bcf bellard
                        if (xop & 0x10)
594 cf495bcf bellard
                            gen_op_set_flags();
595 cf495bcf bellard
                        break;
596 cf495bcf bellard
                    case 0xe:
597 cf495bcf bellard
                        gen_op_udiv_T1_T0();
598 cf495bcf bellard
                        if (xop & 0x10)
599 cf495bcf bellard
                            gen_op_div_cc();
600 cf495bcf bellard
                        break;
601 cf495bcf bellard
                    case 0xf:
602 cf495bcf bellard
                        gen_op_sdiv_T1_T0();
603 cf495bcf bellard
                        if (xop & 0x10)
604 cf495bcf bellard
                            gen_op_div_cc();
605 cf495bcf bellard
                        break;
606 cf495bcf bellard
                    default:
607 cf495bcf bellard
                        goto illegal_insn;
608 cf495bcf bellard
                    }
609 cf495bcf bellard
                    gen_movl_T0_reg(rd);
610 cf495bcf bellard
                } else {
611 cf495bcf bellard
                    switch (xop) {
612 cf495bcf bellard
                    case 0x24: /* mulscc */
613 cf495bcf bellard
                        gen_op_mulscc_T1_T0();
614 cf495bcf bellard
                        gen_movl_T0_reg(rd);
615 cf495bcf bellard
                        break;
616 cf495bcf bellard
                    case 0x25:        /* SLL */
617 cf495bcf bellard
                        gen_op_sll();
618 cf495bcf bellard
                        gen_movl_T0_reg(rd);
619 cf495bcf bellard
                        break;
620 cf495bcf bellard
                    case 0x26:
621 cf495bcf bellard
                        gen_op_srl();
622 cf495bcf bellard
                        gen_movl_T0_reg(rd);
623 cf495bcf bellard
                        break;
624 cf495bcf bellard
                    case 0x27:
625 cf495bcf bellard
                        gen_op_sra();
626 cf495bcf bellard
                        gen_movl_T0_reg(rd);
627 cf495bcf bellard
                        break;
628 cf495bcf bellard
                    case 0x30:
629 cf495bcf bellard
                        {
630 cf495bcf bellard
                            gen_op_xor_T1_T0();
631 cf495bcf bellard
                            switch(rd) {
632 cf495bcf bellard
                            case 0:
633 cf495bcf bellard
                                gen_op_wry();
634 cf495bcf bellard
                                break;
635 cf495bcf bellard
                            default:
636 cf495bcf bellard
                                goto illegal_insn;
637 cf495bcf bellard
                            }
638 cf495bcf bellard
                        }
639 cf495bcf bellard
                        break;
640 cf495bcf bellard
                    case 0x38:        /* jmpl */
641 cf495bcf bellard
                        {
642 cf495bcf bellard
                            gen_op_add_T1_T0();
643 cf495bcf bellard
                            gen_op_movl_npc_T0();
644 cf495bcf bellard
                            if (rd != 0) {
645 cf495bcf bellard
                                gen_op_movl_T0_im((long) (dc->pc));
646 cf495bcf bellard
                                gen_movl_T0_reg(rd);
647 cf495bcf bellard
                            }
648 cf495bcf bellard
                            dc->pc = dc->npc;
649 72cbca10 bellard
                            dc->npc = DYNAMIC_PC;
650 cf495bcf bellard
                        }
651 cf495bcf bellard
                        goto jmp_insn;
652 cf495bcf bellard
                    case 0x3b: /* flush */
653 cf495bcf bellard
                        /* nothing to do */
654 cf495bcf bellard
                        break;
655 cf495bcf bellard
                    case 0x3c:        /* save */
656 cf495bcf bellard
                        save_state(dc);
657 cf495bcf bellard
                        gen_op_add_T1_T0();
658 cf495bcf bellard
                        gen_op_save();
659 cf495bcf bellard
                        gen_movl_T0_reg(rd);
660 cf495bcf bellard
                        break;
661 cf495bcf bellard
                    case 0x3d:        /* restore */
662 cf495bcf bellard
                        save_state(dc);
663 cf495bcf bellard
                        gen_op_add_T1_T0();
664 cf495bcf bellard
                        gen_op_restore();
665 cf495bcf bellard
                        gen_movl_T0_reg(rd);
666 cf495bcf bellard
                        break;
667 cf495bcf bellard
                    default:
668 cf495bcf bellard
                        goto illegal_insn;
669 cf495bcf bellard
                    }
670 cf495bcf bellard
                }
671 cf495bcf bellard
            }
672 cf495bcf bellard
            break;
673 cf495bcf bellard
        }
674 cf495bcf bellard
    case 3:                        /* load/store instructions */
675 cf495bcf bellard
        {
676 cf495bcf bellard
            unsigned int xop = GET_FIELD(insn, 7, 12);
677 cf495bcf bellard
            rs1 = GET_FIELD(insn, 13, 17);
678 cf495bcf bellard
            gen_movl_reg_T0(rs1);
679 cf495bcf bellard
            if (IS_IMM) {        /* immediate */
680 cf495bcf bellard
                rs2 = GET_FIELDs(insn, 19, 31);
681 cf495bcf bellard
                gen_movl_imm_T1(rs2);
682 cf495bcf bellard
            } else {                /* register */
683 cf495bcf bellard
                rs2 = GET_FIELD(insn, 27, 31);
684 cf495bcf bellard
                gen_movl_reg_T1(rs2);
685 cf495bcf bellard
            }
686 cf495bcf bellard
            gen_op_add_T1_T0();
687 cf495bcf bellard
            if (xop < 4 || xop > 7) {
688 cf495bcf bellard
                switch (xop) {
689 cf495bcf bellard
                case 0x0:        /* load word */
690 cf495bcf bellard
                    gen_op_ld();
691 cf495bcf bellard
                    break;
692 cf495bcf bellard
                case 0x1:        /* load unsigned byte */
693 cf495bcf bellard
                    gen_op_ldub();
694 cf495bcf bellard
                    break;
695 cf495bcf bellard
                case 0x2:        /* load unsigned halfword */
696 cf495bcf bellard
                    gen_op_lduh();
697 cf495bcf bellard
                    break;
698 cf495bcf bellard
                case 0x3:        /* load double word */
699 cf495bcf bellard
                    gen_op_ldd();
700 cf495bcf bellard
                    gen_movl_T0_reg(rd + 1);
701 cf495bcf bellard
                    break;
702 cf495bcf bellard
                case 0x9:        /* load signed byte */
703 cf495bcf bellard
                    gen_op_ldsb();
704 cf495bcf bellard
                    break;
705 cf495bcf bellard
                case 0xa:        /* load signed halfword */
706 cf495bcf bellard
                    gen_op_ldsh();
707 cf495bcf bellard
                    break;
708 cf495bcf bellard
                case 0xd:        /* ldstub -- XXX: should be atomically */
709 cf495bcf bellard
                    gen_op_ldstub();
710 cf495bcf bellard
                    break;
711 cf495bcf bellard
                case 0x0f:        /* swap register with memory. Also atomically */
712 cf495bcf bellard
                    gen_op_swap();
713 cf495bcf bellard
                    break;
714 7a3f1944 bellard
                }
715 cf495bcf bellard
                gen_movl_T1_reg(rd);
716 cf495bcf bellard
            } else if (xop < 8) {
717 cf495bcf bellard
                gen_movl_reg_T1(rd);
718 cf495bcf bellard
                switch (xop) {
719 cf495bcf bellard
                case 0x4:
720 cf495bcf bellard
                    gen_op_st();
721 cf495bcf bellard
                    break;
722 cf495bcf bellard
                case 0x5:
723 cf495bcf bellard
                    gen_op_stb();
724 cf495bcf bellard
                    break;
725 cf495bcf bellard
                case 0x6:
726 cf495bcf bellard
                    gen_op_sth();
727 cf495bcf bellard
                    break;
728 cf495bcf bellard
                case 0x7:
729 72cbca10 bellard
                    flush_T2(dc);
730 cf495bcf bellard
                    gen_movl_reg_T2(rd + 1);
731 cf495bcf bellard
                    gen_op_std();
732 cf495bcf bellard
                    break;
733 7a3f1944 bellard
                }
734 cf495bcf bellard
            }
735 7a3f1944 bellard
        }
736 cf495bcf bellard
    }
737 cf495bcf bellard
    /* default case for non jump instructions */
738 72cbca10 bellard
    if (dc->npc == DYNAMIC_PC) {
739 72cbca10 bellard
        dc->pc = DYNAMIC_PC;
740 72cbca10 bellard
        gen_op_next_insn();
741 72cbca10 bellard
    } else if (dc->npc == JUMP_PC) {
742 72cbca10 bellard
        /* we can do a static jump */
743 72cbca10 bellard
        gen_op_branch2((long)dc->tb, dc->jump_pc[0], dc->jump_pc[1]);
744 72cbca10 bellard
        dc->is_br = 1;
745 72cbca10 bellard
    } else {
746 cf495bcf bellard
        dc->pc = dc->npc;
747 cf495bcf bellard
        dc->npc = dc->npc + 4;
748 cf495bcf bellard
    }
749 cf495bcf bellard
  jmp_insn:;
750 cf495bcf bellard
    return;
751 cf495bcf bellard
 illegal_insn:
752 72cbca10 bellard
    save_state(dc);
753 cf495bcf bellard
    gen_op_exception(TT_ILL_INSN);
754 cf495bcf bellard
    dc->is_br = 1;
755 7a3f1944 bellard
}
756 7a3f1944 bellard
757 cf495bcf bellard
static inline int gen_intermediate_code_internal(TranslationBlock * tb,
758 cf495bcf bellard
                                                 int spc)
759 7a3f1944 bellard
{
760 72cbca10 bellard
    target_ulong pc_start, last_pc;
761 cf495bcf bellard
    uint16_t *gen_opc_end;
762 cf495bcf bellard
    DisasContext dc1, *dc = &dc1;
763 cf495bcf bellard
764 cf495bcf bellard
    memset(dc, 0, sizeof(DisasContext));
765 cf495bcf bellard
    if (spc) {
766 cf495bcf bellard
        printf("SearchPC not yet supported\n");
767 cf495bcf bellard
        exit(0);
768 cf495bcf bellard
    }
769 cf495bcf bellard
    dc->tb = tb;
770 72cbca10 bellard
    pc_start = tb->pc;
771 cf495bcf bellard
    dc->pc = pc_start;
772 72cbca10 bellard
    dc->npc = (target_ulong) tb->cs_base;
773 cf495bcf bellard
774 cf495bcf bellard
    gen_opc_ptr = gen_opc_buf;
775 cf495bcf bellard
    gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
776 cf495bcf bellard
    gen_opparam_ptr = gen_opparam_buf;
777 cf495bcf bellard
778 cf495bcf bellard
    do {
779 cf495bcf bellard
        last_pc = dc->pc;
780 cf495bcf bellard
        disas_sparc_insn(dc);
781 cf495bcf bellard
        if (dc->is_br)
782 cf495bcf bellard
            break;
783 cf495bcf bellard
        /* if the next PC is different, we abort now */
784 cf495bcf bellard
        if (dc->pc != (last_pc + 4))
785 cf495bcf bellard
            break;
786 cf495bcf bellard
    } while ((gen_opc_ptr < gen_opc_end) &&
787 cf495bcf bellard
             (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32));
788 72cbca10 bellard
    if (!dc->is_br) {
789 72cbca10 bellard
        if (dc->pc != DYNAMIC_PC && 
790 72cbca10 bellard
            (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
791 72cbca10 bellard
            /* static PC and NPC: we can use direct chaining */
792 72cbca10 bellard
            gen_op_branch((long)tb, dc->pc, dc->npc);
793 72cbca10 bellard
        } else {
794 72cbca10 bellard
            if (dc->pc != DYNAMIC_PC)
795 72cbca10 bellard
                gen_op_jmp_im(dc->pc);
796 72cbca10 bellard
            save_npc(dc);
797 72cbca10 bellard
            gen_op_movl_T0_0();
798 72cbca10 bellard
            gen_op_exit_tb();
799 72cbca10 bellard
        }
800 72cbca10 bellard
    }
801 cf495bcf bellard
    *gen_opc_ptr = INDEX_op_end;
802 7a3f1944 bellard
#ifdef DEBUG_DISAS
803 cf495bcf bellard
    if (loglevel) {
804 cf495bcf bellard
        fprintf(logfile, "--------------\n");
805 72cbca10 bellard
        fprintf(logfile, "IN: %s\n", lookup_symbol((uint8_t *)pc_start));
806 72cbca10 bellard
        disas(logfile, (uint8_t *)pc_start, last_pc + 4 - pc_start, 0, 0);
807 cf495bcf bellard
        fprintf(logfile, "\n");
808 cf495bcf bellard
        fprintf(logfile, "OP:\n");
809 cf495bcf bellard
        dump_ops(gen_opc_buf, gen_opparam_buf);
810 cf495bcf bellard
        fprintf(logfile, "\n");
811 cf495bcf bellard
    }
812 7a3f1944 bellard
#endif
813 7a3f1944 bellard
814 cf495bcf bellard
    return 0;
815 7a3f1944 bellard
}
816 7a3f1944 bellard
817 cf495bcf bellard
int gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
818 7a3f1944 bellard
{
819 cf495bcf bellard
    return gen_intermediate_code_internal(tb, 0);
820 7a3f1944 bellard
}
821 7a3f1944 bellard
822 cf495bcf bellard
int gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
823 7a3f1944 bellard
{
824 cf495bcf bellard
    return gen_intermediate_code_internal(tb, 1);
825 7a3f1944 bellard
}
826 7a3f1944 bellard
827 cf495bcf bellard
CPUSPARCState *cpu_sparc_init(void)
828 7a3f1944 bellard
{
829 cf495bcf bellard
    CPUSPARCState *env;
830 cf495bcf bellard
831 cf495bcf bellard
    cpu_exec_init();
832 cf495bcf bellard
833 cf495bcf bellard
    if (!(env = malloc(sizeof(CPUSPARCState))))
834 cf495bcf bellard
        return (NULL);
835 cf495bcf bellard
    memset(env, 0, sizeof(*env));
836 cf495bcf bellard
    env->cwp = 0;
837 cf495bcf bellard
    env->wim = 1;
838 cf495bcf bellard
    env->regwptr = env->regbase + (env->cwp * 16);
839 cf495bcf bellard
    env->user_mode_only = 1;
840 cf495bcf bellard
    return (env);
841 7a3f1944 bellard
}
842 7a3f1944 bellard
843 7a3f1944 bellard
#define GET_FLAG(a,b) ((env->psr & a)?b:'-')
844 7a3f1944 bellard
845 cf495bcf bellard
void cpu_sparc_dump_state(CPUSPARCState * env, FILE * f, int flags)
846 7a3f1944 bellard
{
847 cf495bcf bellard
    int i, x;
848 cf495bcf bellard
849 cf495bcf bellard
    fprintf(f, "pc: 0x%08x  npc: 0x%08x\n", (int) env->pc, (int) env->npc);
850 cf495bcf bellard
    fprintf(f, "General Registers:\n");
851 cf495bcf bellard
    for (i = 0; i < 4; i++)
852 cf495bcf bellard
        fprintf(f, "%%g%c: 0x%08x\t", i + '0', env->gregs[i]);
853 cf495bcf bellard
    fprintf(f, "\n");
854 cf495bcf bellard
    for (; i < 8; i++)
855 cf495bcf bellard
        fprintf(f, "%%g%c: 0x%08x\t", i + '0', env->gregs[i]);
856 cf495bcf bellard
    fprintf(f, "\nCurrent Register Window:\n");
857 cf495bcf bellard
    for (x = 0; x < 3; x++) {
858 cf495bcf bellard
        for (i = 0; i < 4; i++)
859 cf495bcf bellard
            fprintf(f, "%%%c%d: 0x%08x\t",
860 cf495bcf bellard
                    (x == 0 ? 'o' : (x == 1 ? 'l' : 'i')), i,
861 cf495bcf bellard
                    env->regwptr[i + x * 8]);
862 cf495bcf bellard
        fprintf(f, "\n");
863 cf495bcf bellard
        for (; i < 8; i++)
864 cf495bcf bellard
            fprintf(f, "%%%c%d: 0x%08x\t",
865 cf495bcf bellard
                    (x == 0 ? 'o' : x == 1 ? 'l' : 'i'), i,
866 cf495bcf bellard
                    env->regwptr[i + x * 8]);
867 cf495bcf bellard
        fprintf(f, "\n");
868 cf495bcf bellard
    }
869 cf495bcf bellard
    fprintf(f, "psr: 0x%08x -> %c%c%c%c wim: 0x%08x\n", env->psr | env->cwp,
870 cf495bcf bellard
            GET_FLAG(PSR_ZERO, 'Z'), GET_FLAG(PSR_OVF, 'V'),
871 cf495bcf bellard
            GET_FLAG(PSR_NEG, 'N'), GET_FLAG(PSR_CARRY, 'C'),
872 cf495bcf bellard
            env->wim);
873 7a3f1944 bellard
}
874 edfcbd99 bellard
875 edfcbd99 bellard
target_ulong cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
876 edfcbd99 bellard
{
877 edfcbd99 bellard
    return addr;
878 edfcbd99 bellard
}