kvm: qemu: LSI SCSI and e1000 unregister callbacks
[kvm-userspace.git] / qemu / target-cris / helper.c
blob7482e0893f514d5f42e2f7d1766f878316da1d7b
1 /*
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
22 #include <stdio.h>
23 #include <string.h>
25 #include "config.h"
26 #include "cpu.h"
27 #include "mmu.h"
28 #include "exec-all.h"
29 #include "host-utils.h"
31 #if defined(CONFIG_USER_ONLY)
33 void do_interrupt (CPUState *env)
35 env->exception_index = -1;
36 env->pregs[PR_ERP] = env->pc;
39 int cpu_cris_handle_mmu_fault(CPUState * env, target_ulong address, int rw,
40 int mmu_idx, int is_softmmu)
42 env->exception_index = 0xaa;
43 env->debug1 = address;
44 cpu_dump_state(env, stderr, fprintf, 0);
45 env->pregs[PR_ERP] = env->pc;
46 return 1;
49 target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, target_ulong addr)
51 return addr;
54 #else /* !CONFIG_USER_ONLY */
56 int cpu_cris_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
57 int mmu_idx, int is_softmmu)
59 struct cris_mmu_result_t res;
60 int prot, miss;
61 target_ulong phy;
63 address &= TARGET_PAGE_MASK;
64 prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
65 miss = cris_mmu_translate(&res, env, address, rw, mmu_idx);
66 if (miss)
68 /* handle the miss. */
69 phy = 0;
70 env->exception_index = EXCP_MMU_MISS;
72 else
74 phy = res.phy;
76 return tlb_set_page(env, address, phy, prot, mmu_idx, is_softmmu);
80 static void cris_shift_ccs(CPUState *env)
82 uint32_t ccs;
83 /* Apply the ccs shift. */
84 ccs = env->pregs[PR_CCS];
85 ccs = (ccs & 0xc0000000) | ((ccs << 12) >> 2);
86 env->pregs[PR_CCS] = ccs;
89 void do_interrupt(CPUState *env)
91 uint32_t ebp, isr;
92 int irqnum;
94 fflush(NULL);
96 #if 0
97 printf ("exception index=%d interrupt_req=%d\n",
98 env->exception_index,
99 env->interrupt_request);
100 #endif
102 switch (env->exception_index)
104 case EXCP_BREAK:
105 irqnum = env->trapnr;
106 ebp = env->pregs[PR_EBP];
107 isr = ldl_code(ebp + irqnum * 4);
108 env->pregs[PR_ERP] = env->pc + 2;
109 env->pc = isr;
111 cris_shift_ccs(env);
113 break;
114 case EXCP_MMU_MISS:
115 irqnum = 4;
116 ebp = env->pregs[PR_EBP];
117 isr = ldl_code(ebp + irqnum * 4);
118 env->pregs[PR_ERP] = env->pc;
119 env->pc = isr;
120 cris_shift_ccs(env);
121 break;
123 default:
125 /* Maybe the irq was acked by sw before we got a
126 change to take it. */
127 if (env->interrupt_request & CPU_INTERRUPT_HARD) {
128 if (!env->pending_interrupts)
129 return;
130 if (!(env->pregs[PR_CCS] & I_FLAG)) {
131 return;
134 irqnum = 31 - clz32(env->pending_interrupts);
135 irqnum += 0x30;
136 ebp = env->pregs[PR_EBP];
137 isr = ldl_code(ebp + irqnum * 4);
138 env->pregs[PR_ERP] = env->pc;
139 env->pc = isr;
141 cris_shift_ccs(env);
142 #if 0
143 printf ("%s ebp=%x %x isr=%x %d"
144 " ir=%x pending=%x\n",
145 __func__,
146 ebp, ebp + irqnum * 4,
147 isr, env->exception_index,
148 env->interrupt_request,
149 env->pending_interrupts);
150 #endif
154 break;
158 target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, target_ulong addr)
160 uint32_t phy = addr;
161 struct cris_mmu_result_t res;
162 int miss;
163 miss = cris_mmu_translate(&res, env, addr, 0, 0);
164 if (!miss)
165 phy = res.phy;
166 return phy;
168 #endif