Merge branch 'master' of /home/nchip/public_html/qemu into garage-push
[qemu] / target-cris / translate.c
index c536635..6a44281 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include <inttypes.h>
-#include <assert.h>
 
 #include "cpu.h"
 #include "exec-all.h"
 #include "disas.h"
 #include "tcg-op.h"
 #include "helper.h"
+#include "mmu.h"
 #include "crisv32-decode.h"
 #include "qemu-common.h"
 
 
 #define DISAS_CRIS 0
 #if DISAS_CRIS
-#  define LOG_DIS(...) do {               \
-     if (loglevel & CPU_LOG_TB_IN_ASM)    \
-       fprintf(logfile, ## __VA_ARGS__);  \
-   } while (0)
+#  define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
 #else
 #  define LOG_DIS(...) do { } while (0)
 #endif
@@ -131,7 +128,7 @@ typedef struct DisasContext {
 static void gen_BUG(DisasContext *dc, const char *file, int line)
 {
        printf ("BUG: pc=%x %s %d\n", dc->pc, file, line);
-       fprintf (logfile, "BUG: pc=%x %s %d\n", dc->pc, file, line);
+       qemu_log("BUG: pc=%x %s %d\n", dc->pc, file, line);
        cpu_abort(dc->env, "%s:%d\n", file, line);
 }
 
@@ -798,7 +795,7 @@ static void cris_alu_op_exec(DisasContext *dc, int op,
                        t_gen_subx_carry(dc, dst);
                        break;
                default:
-                       fprintf (logfile, "illegal ALU op.\n");
+                       qemu_log("illegal ALU op.\n");
                        BUG();
                        break;
        }
@@ -959,7 +956,8 @@ static void gen_tst_cc (DisasContext *dc, TCGv cc, int cond)
                                else if (dc->cc_size == 2)
                                        bits = 15;      
 
-                               tcg_gen_shri_tl(cc, cc_result, 31);
+                               tcg_gen_shri_tl(cc, cc_result, bits);
+                               tcg_gen_andi_tl(cc, cc, 1);
                        }
                        else {
                                cris_evaluate_flags(dc);
@@ -2635,7 +2633,8 @@ static unsigned int dec_movem_mr(DisasContext *dc)
                tmp32 = tcg_temp_new_i32();
                tcg_gen_addi_tl(addr, cpu_R[dc->op1], i * 8);
                gen_load(dc, tmp32, addr, 4, 0);
-       }
+       } else
+               TCGV_UNUSED(tmp32);
        tcg_temp_free(addr);
 
        for (i = 0; i < (nr >> 1); i++) {
@@ -3038,7 +3037,7 @@ cris_decoder(DisasContext *dc)
        unsigned int insn_len = 2;
        int i;
 
-       if (unlikely(loglevel & CPU_LOG_TB_OP))
+       if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP)))
                tcg_gen_debug_insn_start(dc->pc);
 
        /* Load a halfword onto the instruction register.  */
@@ -3147,8 +3146,7 @@ gen_intermediate_code_internal(CPUState *env, TranslationBlock *tb,
         int num_insns;
         int max_insns;
 
-       if (!logfile)
-               logfile = stderr;
+       qemu_log_try_set_file(stderr);
 
        /* Odd PC indicates that branch is rexecuting due to exception in the
         * delayslot, like in real hw.
@@ -3183,8 +3181,8 @@ gen_intermediate_code_internal(CPUState *env, TranslationBlock *tb,
 
        dc->cpustate_changed = 0;
 
-       if (loglevel & CPU_LOG_TB_IN_ASM) {
-               fprintf(logfile,
+       if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
+               qemu_log(
                        "srch=%d pc=%x %x flg=%llx bt=%x ds=%u ccs=%x\n"
                        "pid=%x usp=%x\n"
                        "%x.%x.%x.%x\n"
@@ -3202,8 +3200,8 @@ gen_intermediate_code_internal(CPUState *env, TranslationBlock *tb,
                        env->regs[10], env->regs[11],
                        env->regs[12], env->regs[13],
                        env->regs[14], env->regs[15]);
-               fprintf(logfile, "--------------\n");
-               fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
+               qemu_log("--------------\n");
+               qemu_log("IN: %s\n", lookup_symbol(pc_start));
        }
 
        next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
@@ -3274,6 +3272,7 @@ gen_intermediate_code_internal(CPUState *env, TranslationBlock *tb,
                        break;
        } while (!dc->is_jmp && !dc->cpustate_changed
                 && gen_opc_ptr < gen_opc_end
+                 && !singlestep
                 && (dc->pc < next_page_start)
                  && num_insns < max_insns);
 
@@ -3335,9 +3334,9 @@ gen_intermediate_code_internal(CPUState *env, TranslationBlock *tb,
 
 #ifdef DEBUG_DISAS
 #if !DISAS_CRIS
-       if (loglevel & CPU_LOG_TB_IN_ASM) {
-               target_disas(logfile, pc_start, dc->pc - pc_start, 0);
-               fprintf(logfile, "\nisize=%d osize=%zd\n",
+       if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
+               log_target_disas(pc_start, dc->pc - pc_start, 0);
+               qemu_log("\nisize=%d osize=%zd\n",
                        dc->pc - pc_start, gen_opc_ptr - gen_opc_buf);
        }
 #endif
@@ -3403,11 +3402,10 @@ CPUCRISState *cpu_cris_init (const char *cpu_model)
        int i;
 
        env = qemu_mallocz(sizeof(CPUCRISState));
-       if (!env)
-               return NULL;
 
        cpu_exec_init(env);
        cpu_reset(env);
+       qemu_init_vcpu(env);
 
        if (tcg_initialized)
                return env;
@@ -3462,6 +3460,11 @@ CPUCRISState *cpu_cris_init (const char *cpu_model)
 
 void cpu_reset (CPUCRISState *env)
 {
+       if (qemu_loglevel_mask(CPU_LOG_RESET)) {
+               qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
+               log_cpu_state(env, 0);
+       }
+
        memset(env, 0, offsetof(CPUCRISState, breakpoints));
        tlb_flush(env, 1);
 
@@ -3470,6 +3473,7 @@ void cpu_reset (CPUCRISState *env)
        /* start in user mode with interrupts enabled.  */
        env->pregs[PR_CCS] |= U_FLAG | I_FLAG;
 #else
+       cris_mmu_init(env);
        env->pregs[PR_CCS] = 0;
 #endif
 }