2 * CRIS helper routines.
4 * Copyright (c) 2007 AXIS Communications AB
5 * Written by Edgar E. Iglesias.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "host-utils.h"
31 #if defined(CONFIG_USER_ONLY)
33 void do_interrupt (CPUState *env)
35 env->exception_index = -1;
38 int cpu_cris_handle_mmu_fault(CPUState * env, target_ulong address, int rw,
39 int mmu_idx, int is_softmmu)
41 env->exception_index = 0xaa;
42 env->debug1 = address;
43 cpu_dump_state(env, stderr, fprintf, 0);
44 printf("%s addr=%x env->pc=%x\n", __func__, address, env->pc);
48 target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, target_ulong addr)
53 #else /* !CONFIG_USER_ONLY */
55 int cpu_cris_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
56 int mmu_idx, int is_softmmu)
58 struct cris_mmu_result_t res;
62 address &= TARGET_PAGE_MASK;
63 prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
64 // printf ("%s pc=%x %x w=%d smmu=%d\n", __func__, env->pc, address, rw, is_softmmu);
65 miss = cris_mmu_translate(&res, env, address, rw, mmu_idx);
68 /* handle the miss. */
70 env->exception_index = EXCP_MMU_MISS;
76 // printf ("a=%x phy=%x\n", address, phy);
77 return tlb_set_page(env, address, phy, prot, mmu_idx, is_softmmu);
81 static void cris_shift_ccs(CPUState *env)
84 /* Apply the ccs shift. */
85 ccs = env->pregs[SR_CCS];
86 ccs = (ccs & 0xc0000000) | ((ccs << 12) >> 2);
87 // printf ("ccs=%x %x\n", env->pregs[SR_CCS], ccs);
88 env->pregs[SR_CCS] = ccs;
91 void do_interrupt(CPUState *env)
99 printf ("exception index=%d interrupt_req=%d\n",
100 env->exception_index,
101 env->interrupt_request);
104 switch (env->exception_index)
107 // printf ("BREAK! %d\n", env->trapnr);
108 irqnum = env->trapnr;
109 ebp = env->pregs[SR_EBP];
110 isr = ldl_code(ebp + irqnum * 4);
111 env->pregs[SR_ERP] = env->pc + 2;
118 // printf ("MMU miss\n");
120 ebp = env->pregs[SR_EBP];
121 isr = ldl_code(ebp + irqnum * 4);
122 env->pregs[SR_ERP] = env->pc;
129 /* Maybe the irq was acked by sw before we got a
130 change to take it. */
131 if (env->interrupt_request & CPU_INTERRUPT_HARD) {
132 if (!env->pending_interrupts)
134 if (!(env->pregs[SR_CCS] & I_FLAG)) {
138 irqnum = 31 - clz32(env->pending_interrupts);
140 ebp = env->pregs[SR_EBP];
141 isr = ldl_code(ebp + irqnum * 4);
142 env->pregs[SR_ERP] = env->pc;
147 printf ("%s ebp=%x %x isr=%x %d"
148 " ir=%x pending=%x\n",
150 ebp, ebp + irqnum * 4,
151 isr, env->exception_index,
152 env->interrupt_request,
153 env->pending_interrupts);
162 target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, target_ulong addr)
164 // printf ("%s\n", __func__);
166 struct cris_mmu_result_t res;
168 miss = cris_mmu_translate(&res, env, addr, 0, 0);