]> git.proxmox.com Git - qemu.git/blobdiff - target-cris/translate.c
Merge remote-tracking branch 'sweil/for-anthony' into staging
[qemu.git] / target-cris / translate.c
index dd85859c0bf929b57f1a67a409f75870a54a2aff..1ad9ec788e53d7c72ebc825a9b89d0a2daf237aa 100644 (file)
  * The condition code translation is in need of attention.
  */
 
-#include <stdarg.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <inttypes.h>
-
 #include "cpu.h"
 #include "disas.h"
 #include "tcg-op.h"
 #include "helper.h"
 #include "mmu.h"
 #include "crisv32-decode.h"
-#include "qemu-common.h"
 
 #define GEN_HELPER 1
 #include "helper.h"
@@ -81,7 +74,7 @@ static TCGv env_pc;
 
 /* This is the state at translation time.  */
 typedef struct DisasContext {
-       CPUState *env;
+       CPUCRISState *env;
        target_ulong pc, ppc;
 
        /* Decoder.  */
@@ -167,9 +160,9 @@ static int preg_sizes[] = {
 };
 
 #define t_gen_mov_TN_env(tn, member) \
- _t_gen_mov_TN_env((tn), offsetof(CPUState, member))
+ _t_gen_mov_TN_env((tn), offsetof(CPUCRISState, member))
 #define t_gen_mov_env_TN(member, tn) \
- _t_gen_mov_env_TN(offsetof(CPUState, member), (tn))
+ _t_gen_mov_env_TN(offsetof(CPUCRISState, member), (tn))
 
 static inline void t_gen_mov_TN_reg(TCGv tn, int r)
 {
@@ -186,13 +179,13 @@ static inline void t_gen_mov_reg_TN(int r, TCGv tn)
 
 static inline void _t_gen_mov_TN_env(TCGv tn, int offset)
 {
-       if (offset > sizeof (CPUState))
+       if (offset > sizeof (CPUCRISState))
                fprintf(stderr, "wrong load from env from off=%d\n", offset);
        tcg_gen_ld_tl(tn, cpu_env, offset);
 }
 static inline void _t_gen_mov_env_TN(int offset, TCGv tn)
 {
-       if (offset > sizeof (CPUState))
+       if (offset > sizeof (CPUCRISState))
                fprintf(stderr, "wrong store to env at off=%d\n", offset);
        tcg_gen_st_tl(tn, cpu_env, offset);
 }
@@ -3121,7 +3114,7 @@ static unsigned int crisv32_decoder(DisasContext *dc)
        return insn_len;
 }
 
-static void check_breakpoint(CPUState *env, DisasContext *dc)
+static void check_breakpoint(CPUCRISState *env, DisasContext *dc)
 {
        CPUBreakpoint *bp;
 
@@ -3175,7 +3168,7 @@ static void check_breakpoint(CPUState *env, DisasContext *dc)
 
 /* generate intermediate code for basic block 'tb'.  */
 static void
-gen_intermediate_code_internal(CPUState *env, TranslationBlock *tb,
+gen_intermediate_code_internal(CPUCRISState *env, TranslationBlock *tb,
                                int search_pc)
 {
        uint16_t *gen_opc_end;
@@ -3426,17 +3419,17 @@ gen_intermediate_code_internal(CPUState *env, TranslationBlock *tb,
 #endif
 }
 
-void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
+void gen_intermediate_code (CPUCRISState *env, struct TranslationBlock *tb)
 {
     gen_intermediate_code_internal(env, tb, 0);
 }
 
-void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
+void gen_intermediate_code_pc (CPUCRISState *env, struct TranslationBlock *tb)
 {
     gen_intermediate_code_internal(env, tb, 1);
 }
 
-void cpu_dump_state (CPUState *env, FILE *f, fprintf_function cpu_fprintf,
+void cpu_dump_state (CPUCRISState *env, FILE *f, fprintf_function cpu_fprintf,
                      int flags)
 {
        int i;
@@ -3510,100 +3503,80 @@ static uint32_t vr_by_name(const char *name)
     return 32;
 }
 
-CPUCRISState *cpu_cris_init (const char *cpu_model)
+CRISCPU *cpu_cris_init(const char *cpu_model)
 {
-       CPUCRISState *env;
-       static int tcg_initialized = 0;
-       int i;
+    CRISCPU *cpu;
+    CPUCRISState *env;
+    static int tcg_initialized = 0;
+    int i;
+
+    cpu = CRIS_CPU(object_new(TYPE_CRIS_CPU));
+    env = &cpu->env;
 
-       env = qemu_mallocz(sizeof(CPUCRISState));
+    env->pregs[PR_VR] = vr_by_name(cpu_model);
 
-       env->pregs[PR_VR] = vr_by_name(cpu_model);
-       cpu_exec_init(env);
-       cpu_reset(env);
-       qemu_init_vcpu(env);
+    cpu_reset(CPU(cpu));
+    qemu_init_vcpu(env);
 
-       if (tcg_initialized)
-               return env;
+    if (tcg_initialized) {
+        return cpu;
+    }
 
-       tcg_initialized = 1;
+    tcg_initialized = 1;
 
 #define GEN_HELPER 2
 #include "helper.h"
 
-       if (env->pregs[PR_VR] < 32) {
-               cpu_crisv10_init(env);
-               return env; 
-       }
-
-
-       cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
-       cc_x = tcg_global_mem_new(TCG_AREG0,
-                                 offsetof(CPUState, cc_x), "cc_x");
-       cc_src = tcg_global_mem_new(TCG_AREG0,
-                                   offsetof(CPUState, cc_src), "cc_src");
-       cc_dest = tcg_global_mem_new(TCG_AREG0,
-                                    offsetof(CPUState, cc_dest),
-                                    "cc_dest");
-       cc_result = tcg_global_mem_new(TCG_AREG0,
-                                      offsetof(CPUState, cc_result),
-                                      "cc_result");
-       cc_op = tcg_global_mem_new(TCG_AREG0,
-                                  offsetof(CPUState, cc_op), "cc_op");
-       cc_size = tcg_global_mem_new(TCG_AREG0,
-                                    offsetof(CPUState, cc_size),
-                                    "cc_size");
-       cc_mask = tcg_global_mem_new(TCG_AREG0,
-                                    offsetof(CPUState, cc_mask),
-                                    "cc_mask");
-
-       env_pc = tcg_global_mem_new(TCG_AREG0, 
-                                   offsetof(CPUState, pc),
-                                   "pc");
-       env_btarget = tcg_global_mem_new(TCG_AREG0,
-                                        offsetof(CPUState, btarget),
-                                        "btarget");
-       env_btaken = tcg_global_mem_new(TCG_AREG0,
-                                        offsetof(CPUState, btaken),
-                                        "btaken");
-       for (i = 0; i < 16; i++) {
-               cpu_R[i] = tcg_global_mem_new(TCG_AREG0,
-                                             offsetof(CPUState, regs[i]),
-                                             regnames[i]);
-       }
-       for (i = 0; i < 16; i++) {
-               cpu_PR[i] = tcg_global_mem_new(TCG_AREG0,
-                                              offsetof(CPUState, pregs[i]),
-                                              pregnames[i]);
-       }
-
-       return env;
-}
+    if (env->pregs[PR_VR] < 32) {
+        cpu_crisv10_init(env);
+        return cpu;
+    }
 
-void cpu_reset (CPUCRISState *env)
-{
-       uint32_t vr;
 
-       if (qemu_loglevel_mask(CPU_LOG_RESET)) {
-               qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
-               log_cpu_state(env, 0);
-       }
-
-       vr = env->pregs[PR_VR];
-       memset(env, 0, offsetof(CPUCRISState, breakpoints));
-       env->pregs[PR_VR] = vr;
-       tlb_flush(env, 1);
+    cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
+    cc_x = tcg_global_mem_new(TCG_AREG0,
+                              offsetof(CPUCRISState, cc_x), "cc_x");
+    cc_src = tcg_global_mem_new(TCG_AREG0,
+                                offsetof(CPUCRISState, cc_src), "cc_src");
+    cc_dest = tcg_global_mem_new(TCG_AREG0,
+                                 offsetof(CPUCRISState, cc_dest),
+                                 "cc_dest");
+    cc_result = tcg_global_mem_new(TCG_AREG0,
+                                   offsetof(CPUCRISState, cc_result),
+                                   "cc_result");
+    cc_op = tcg_global_mem_new(TCG_AREG0,
+                               offsetof(CPUCRISState, cc_op), "cc_op");
+    cc_size = tcg_global_mem_new(TCG_AREG0,
+                                 offsetof(CPUCRISState, cc_size),
+                                 "cc_size");
+    cc_mask = tcg_global_mem_new(TCG_AREG0,
+                                 offsetof(CPUCRISState, cc_mask),
+                                 "cc_mask");
+
+    env_pc = tcg_global_mem_new(TCG_AREG0,
+                                offsetof(CPUCRISState, pc),
+                                "pc");
+    env_btarget = tcg_global_mem_new(TCG_AREG0,
+                                     offsetof(CPUCRISState, btarget),
+                                     "btarget");
+    env_btaken = tcg_global_mem_new(TCG_AREG0,
+                                    offsetof(CPUCRISState, btaken),
+                                    "btaken");
+    for (i = 0; i < 16; i++) {
+        cpu_R[i] = tcg_global_mem_new(TCG_AREG0,
+                                      offsetof(CPUCRISState, regs[i]),
+                                      regnames[i]);
+    }
+    for (i = 0; i < 16; i++) {
+        cpu_PR[i] = tcg_global_mem_new(TCG_AREG0,
+                                       offsetof(CPUCRISState, pregs[i]),
+                                       pregnames[i]);
+    }
 
-#if defined(CONFIG_USER_ONLY)
-       /* start in user mode with interrupts enabled.  */
-       env->pregs[PR_CCS] |= U_FLAG | I_FLAG | P_FLAG;
-#else
-       cris_mmu_init(env);
-       env->pregs[PR_CCS] = 0;
-#endif
+    return cpu;
 }
 
-void restore_state_to_opc(CPUState *env, TranslationBlock *tb, int pc_pos)
+void restore_state_to_opc(CPUCRISState *env, TranslationBlock *tb, int pc_pos)
 {
        env->pc = gen_opc_pc[pc_pos];
 }