]> git.proxmox.com Git - qemu.git/blobdiff - target-cris/helper.c
Merge remote-tracking branch 'bonzini/header-dirs' into staging
[qemu.git] / target-cris / helper.c
index 405454f50f20e05c27caf0f9f750181226649424..8407a6d880f06c5187e15a4f2174718d48d5211b 100644 (file)
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 USA
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <stdio.h>
-#include <string.h>
-
-#include "config.h"
 #include "cpu.h"
 #include "mmu.h"
-#include "exec-all.h"
-#include "host-utils.h"
+#include "qemu/host-utils.h"
 
 
 //#define CRIS_HELPER_DEBUG
 
 #if defined(CONFIG_USER_ONLY)
 
-void do_interrupt (CPUState *env)
+void do_interrupt (CPUCRISState *env)
 {
        env->exception_index = -1;
        env->pregs[PR_ERP] = env->pc;
 }
 
-int cpu_cris_handle_mmu_fault(CPUState * env, target_ulong address, int rw,
-                             int mmu_idx, int is_softmmu)
+int cpu_cris_handle_mmu_fault(CPUCRISState * env, target_ulong address, int rw,
+                              int mmu_idx)
 {
        env->exception_index = 0xaa;
        env->pregs[PR_EDA] = address;
@@ -57,15 +51,10 @@ int cpu_cris_handle_mmu_fault(CPUState * env, target_ulong address, int rw,
        return 1;
 }
 
-target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, target_ulong addr)
-{
-       return addr;
-}
-
 #else /* !CONFIG_USER_ONLY */
 
 
-static void cris_shift_ccs(CPUState *env)
+static void cris_shift_ccs(CPUCRISState *env)
 {
        uint32_t ccs;
        /* Apply the ccs shift.  */
@@ -74,8 +63,8 @@ static void cris_shift_ccs(CPUState *env)
        env->pregs[PR_CCS] = ccs;
 }
 
-int cpu_cris_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
-                               int mmu_idx, int is_softmmu)
+int cpu_cris_handle_mmu_fault (CPUCRISState *env, target_ulong address, int rw,
+                               int mmu_idx)
 {
        struct cris_mmu_result res;
        int prot, miss;
@@ -83,16 +72,17 @@ int cpu_cris_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
        target_ulong phy;
 
        D(printf ("%s addr=%x pc=%x rw=%x\n", __func__, address, env->pc, rw));
-       address &= TARGET_PAGE_MASK;
-       miss = cris_mmu_translate(&res, env, address, rw, mmu_idx);
+       miss = cris_mmu_translate(&res, env, address & TARGET_PAGE_MASK,
+                                 rw, mmu_idx, 0);
        if (miss)
        {
                if (env->exception_index == EXCP_BUSFAULT)
-                       cpu_abort(env, 
+                       cpu_abort(env,
                                  "CRIS: Illegal recursive bus fault."
-                                 "addr=%x rw=%d\n",
-                                 address, rw);
+                                "addr=%x rw=%d\n",
+                                address, rw);
 
+               env->pregs[PR_EDA] = address;
                env->exception_index = EXCP_BUSFAULT;
                env->fault_vector = res.bf_vec;
                r = 1;
@@ -105,20 +95,80 @@ int cpu_cris_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
                 */
                phy = res.phy & ~0x80000000;
                prot = res.prot;
-               r = tlb_set_page(env, address, phy, prot, mmu_idx, is_softmmu);
+               tlb_set_page(env, address & TARGET_PAGE_MASK, phy,
+                             prot, mmu_idx, TARGET_PAGE_SIZE);
+                r = 0;
        }
        if (r > 0)
-               D_LOG("%s returns %d irqreq=%x addr=%x"
-                         " phy=%x ismmu=%d vec=%x pc=%x\n", 
-                         __func__, r, env->interrupt_request, 
-                         address, res.phy, is_softmmu, res.bf_vec, env->pc);
+            D_LOG("%s returns %d irqreq=%x addr=%x phy=%x vec=%x pc=%x\n",
+                  __func__, r, env->interrupt_request, address, res.phy,
+                  res.bf_vec, env->pc);
        return r;
 }
 
-void do_interrupt(CPUState *env)
+static void do_interruptv10(CPUCRISState *env)
+{
+       int ex_vec = -1;
+
+       D_LOG( "exception index=%d interrupt_req=%d\n",
+                  env->exception_index,
+                  env->interrupt_request);
+
+       assert(!(env->pregs[PR_CCS] & PFIX_FLAG));
+       switch (env->exception_index)
+       {
+               case EXCP_BREAK:
+                       /* These exceptions are genereated by the core itself.
+                          ERP should point to the insn following the brk.  */
+                       ex_vec = env->trap_vector;
+                       env->pregs[PRV10_BRP] = env->pc;
+                       break;
+
+               case EXCP_NMI:
+                       /* NMI is hardwired to vector zero.  */
+                       ex_vec = 0;
+                       env->pregs[PR_CCS] &= ~M_FLAG_V10;
+                       env->pregs[PRV10_BRP] = env->pc;
+                       break;
+
+               case EXCP_BUSFAULT:
+                        cpu_abort(env, "Unhandled busfault");
+                       break;
+
+               default:
+                       /* The interrupt controller gives us the vector.  */
+                       ex_vec = env->interrupt_vector;
+                       /* Normal interrupts are taken between
+                          TB's.  env->pc is valid here.  */
+                       env->pregs[PR_ERP] = env->pc;
+                       break;
+       }
+
+       if (env->pregs[PR_CCS] & U_FLAG) {
+               /* Swap stack pointers.  */
+               env->pregs[PR_USP] = env->regs[R_SP];
+               env->regs[R_SP] = env->ksp;
+       }
+
+       /* Now that we are in kernel mode, load the handlers address.  */
+        env->pc = cpu_ldl_code(env, env->pregs[PR_EBP] + ex_vec * 4);
+       env->locked_irq = 1;
+       env->pregs[PR_CCS] |= F_FLAG_V10; /* set F.  */
+
+       qemu_log_mask(CPU_LOG_INT, "%s isr=%x vec=%x ccs=%x pid=%d erp=%x\n", 
+                     __func__, env->pc, ex_vec, 
+                     env->pregs[PR_CCS],
+                     env->pregs[PR_PID], 
+                     env->pregs[PR_ERP]);
+}
+
+void do_interrupt(CPUCRISState *env)
 {
        int ex_vec = -1;
 
+       if (env->pregs[PR_VR] < 32)
+               return do_interruptv10(env);
+
        D_LOG( "exception index=%d interrupt_req=%d\n",
                   env->exception_index,
                   env->interrupt_request);
@@ -135,7 +185,7 @@ void do_interrupt(CPUState *env)
                case EXCP_NMI:
                        /* NMI is hardwired to vector zero.  */
                        ex_vec = 0;
-                       env->pregs[PR_CCS] &= ~M_FLAG;
+                       env->pregs[PR_CCS] &= ~M_FLAG_V32;
                        env->pregs[PR_NRP] = env->pc;
                        break;
 
@@ -171,8 +221,6 @@ void do_interrupt(CPUState *env)
                env->dslot = 0;
        }
        
-       env->pc = ldl_code(env->pregs[PR_EBP] + ex_vec * 4);
-
        if (env->pregs[PR_CCS] & U_FLAG) {
                /* Swap stack pointers.  */
                env->pregs[PR_USP] = env->regs[R_SP];
@@ -181,19 +229,35 @@ void do_interrupt(CPUState *env)
 
        /* Apply the CRIS CCS shift. Clears U if set.  */
        cris_shift_ccs(env);
-       D_LOG("%s isr=%x vec=%x ccs=%x pid=%d erp=%x\n", 
-                  __func__, env->pc, ex_vec, 
+
+       /* Now that we are in kernel mode, load the handlers address.
+          This load may not fault, real hw leaves that behaviour as
+          undefined.  */
+        env->pc = cpu_ldl_code(env, env->pregs[PR_EBP] + ex_vec * 4);
+
+       /* Clear the excption_index to avoid spurios hw_aborts for recursive
+          bus faults.  */
+       env->exception_index = -1;
+
+       D_LOG("%s isr=%x vec=%x ccs=%x pid=%d erp=%x\n",
+                  __func__, env->pc, ex_vec,
                   env->pregs[PR_CCS],
                   env->pregs[PR_PID], 
                   env->pregs[PR_ERP]);
 }
 
-target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, target_ulong addr)
+hwaddr cpu_get_phys_page_debug(CPUCRISState * env, target_ulong addr)
 {
        uint32_t phy = addr;
        struct cris_mmu_result res;
        int miss;
-       miss = cris_mmu_translate(&res, env, addr, 0, 0);
+
+       miss = cris_mmu_translate(&res, env, addr, 0, 0, 1);
+       /* If D TLB misses, try I TLB.  */
+       if (miss) {
+               miss = cris_mmu_translate(&res, env, addr, 2, 0, 1);
+       }
+
        if (!miss)
                phy = res.phy;
        D(fprintf(stderr, "%s %x -> %x\n", __func__, addr, phy));