root / target-cris / helper.c @ 2ada0ed7
History | View | Annotate | Download (5 kB)
1 | 81fdc5f8 | ths | /*
|
---|---|---|---|
2 | 81fdc5f8 | ths | * CRIS helper routines.
|
3 | 81fdc5f8 | ths | *
|
4 | 81fdc5f8 | ths | * Copyright (c) 2007 AXIS Communications AB
|
5 | 81fdc5f8 | ths | * Written by Edgar E. Iglesias.
|
6 | 81fdc5f8 | ths | *
|
7 | 81fdc5f8 | ths | * This library is free software; you can redistribute it and/or
|
8 | 81fdc5f8 | ths | * modify it under the terms of the GNU Lesser General Public
|
9 | 81fdc5f8 | ths | * License as published by the Free Software Foundation; either
|
10 | 81fdc5f8 | ths | * version 2 of the License, or (at your option) any later version.
|
11 | 81fdc5f8 | ths | *
|
12 | 81fdc5f8 | ths | * This library is distributed in the hope that it will be useful,
|
13 | 81fdc5f8 | ths | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | 81fdc5f8 | ths | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15 | 81fdc5f8 | ths | * Lesser General Public License for more details.
|
16 | 81fdc5f8 | ths | *
|
17 | 81fdc5f8 | ths | * You should have received a copy of the GNU Lesser General Public
|
18 | 81fdc5f8 | ths | * License along with this library; if not, write to the Free Software
|
19 | fad6cb1a | aurel32 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
|
20 | 81fdc5f8 | ths | */
|
21 | 81fdc5f8 | ths | |
22 | 81fdc5f8 | ths | #include <stdio.h> |
23 | 81fdc5f8 | ths | #include <string.h> |
24 | 81fdc5f8 | ths | |
25 | 81fdc5f8 | ths | #include "config.h" |
26 | 81fdc5f8 | ths | #include "cpu.h" |
27 | 81fdc5f8 | ths | #include "mmu.h" |
28 | 81fdc5f8 | ths | #include "exec-all.h" |
29 | 941db528 | ths | #include "host-utils.h" |
30 | 81fdc5f8 | ths | |
31 | d12d51d5 | aliguori | |
32 | d12d51d5 | aliguori | //#define CRIS_HELPER_DEBUG
|
33 | d12d51d5 | aliguori | |
34 | d12d51d5 | aliguori | |
35 | d12d51d5 | aliguori | #ifdef CRIS_HELPER_DEBUG
|
36 | d12d51d5 | aliguori | #define D(x) x
|
37 | 93fcfe39 | aliguori | #define D_LOG(...) qemu_log(__VA__ARGS__)
|
38 | d12d51d5 | aliguori | #else
|
39 | e62b5b13 | edgar_igl | #define D(x)
|
40 | d12d51d5 | aliguori | #define D_LOG(...) do { } while (0) |
41 | d12d51d5 | aliguori | #endif
|
42 | e62b5b13 | edgar_igl | |
43 | 81fdc5f8 | ths | #if defined(CONFIG_USER_ONLY)
|
44 | 81fdc5f8 | ths | |
45 | 81fdc5f8 | ths | void do_interrupt (CPUState *env)
|
46 | 81fdc5f8 | ths | { |
47 | bbaf29c7 | edgar_igl | env->exception_index = -1;
|
48 | bbaf29c7 | edgar_igl | env->pregs[PR_ERP] = env->pc; |
49 | 81fdc5f8 | ths | } |
50 | 81fdc5f8 | ths | |
51 | 81fdc5f8 | ths | int cpu_cris_handle_mmu_fault(CPUState * env, target_ulong address, int rw, |
52 | 6ebbf390 | j_mayer | int mmu_idx, int is_softmmu) |
53 | 81fdc5f8 | ths | { |
54 | bbaf29c7 | edgar_igl | env->exception_index = 0xaa;
|
55 | 30abcfc7 | edgar_igl | env->pregs[PR_EDA] = address; |
56 | bbaf29c7 | edgar_igl | cpu_dump_state(env, stderr, fprintf, 0);
|
57 | bbaf29c7 | edgar_igl | return 1; |
58 | 81fdc5f8 | ths | } |
59 | 81fdc5f8 | ths | |
60 | 81fdc5f8 | ths | target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, target_ulong addr) |
61 | 81fdc5f8 | ths | { |
62 | bbaf29c7 | edgar_igl | return addr;
|
63 | 81fdc5f8 | ths | } |
64 | 81fdc5f8 | ths | |
65 | 81fdc5f8 | ths | #else /* !CONFIG_USER_ONLY */ |
66 | 81fdc5f8 | ths | |
67 | e62b5b13 | edgar_igl | |
68 | e62b5b13 | edgar_igl | static void cris_shift_ccs(CPUState *env) |
69 | e62b5b13 | edgar_igl | { |
70 | e62b5b13 | edgar_igl | uint32_t ccs; |
71 | e62b5b13 | edgar_igl | /* Apply the ccs shift. */
|
72 | e62b5b13 | edgar_igl | ccs = env->pregs[PR_CCS]; |
73 | b41f7df0 | edgar_igl | ccs = ((ccs & 0xc0000000) | ((ccs << 12) >> 2)) & ~0x3ff; |
74 | e62b5b13 | edgar_igl | env->pregs[PR_CCS] = ccs; |
75 | e62b5b13 | edgar_igl | } |
76 | e62b5b13 | edgar_igl | |
77 | 81fdc5f8 | ths | int cpu_cris_handle_mmu_fault (CPUState *env, target_ulong address, int rw, |
78 | 6ebbf390 | j_mayer | int mmu_idx, int is_softmmu) |
79 | 81fdc5f8 | ths | { |
80 | 81fdc5f8 | ths | struct cris_mmu_result_t res;
|
81 | 81fdc5f8 | ths | int prot, miss;
|
82 | e62b5b13 | edgar_igl | int r = -1; |
83 | 81fdc5f8 | ths | target_ulong phy; |
84 | 81fdc5f8 | ths | |
85 | b41f7df0 | edgar_igl | D(printf ("%s addr=%x pc=%x rw=%x\n", __func__, address, env->pc, rw));
|
86 | 81fdc5f8 | ths | address &= TARGET_PAGE_MASK; |
87 | 6ebbf390 | j_mayer | miss = cris_mmu_translate(&res, env, address, rw, mmu_idx); |
88 | 81fdc5f8 | ths | if (miss)
|
89 | 81fdc5f8 | ths | { |
90 | 1b1a38b0 | edgar_igl | if (env->exception_index == EXCP_BUSFAULT)
|
91 | ef29a70d | edgar_igl | cpu_abort(env, |
92 | ef29a70d | edgar_igl | "CRIS: Illegal recursive bus fault."
|
93 | ef29a70d | edgar_igl | "addr=%x rw=%d\n",
|
94 | ef29a70d | edgar_igl | address, rw); |
95 | ef29a70d | edgar_igl | |
96 | 1b1a38b0 | edgar_igl | env->exception_index = EXCP_BUSFAULT; |
97 | e62b5b13 | edgar_igl | env->fault_vector = res.bf_vec; |
98 | e62b5b13 | edgar_igl | r = 1;
|
99 | 81fdc5f8 | ths | } |
100 | 81fdc5f8 | ths | else
|
101 | 81fdc5f8 | ths | { |
102 | 980f8a0b | edgar_igl | /*
|
103 | 980f8a0b | edgar_igl | * Mask off the cache selection bit. The ETRAX busses do not
|
104 | 980f8a0b | edgar_igl | * see the top bit.
|
105 | 980f8a0b | edgar_igl | */
|
106 | 980f8a0b | edgar_igl | phy = res.phy & ~0x80000000;
|
107 | b41f7df0 | edgar_igl | prot = res.prot; |
108 | e62b5b13 | edgar_igl | r = tlb_set_page(env, address, phy, prot, mmu_idx, is_softmmu); |
109 | 81fdc5f8 | ths | } |
110 | b41f7df0 | edgar_igl | if (r > 0) |
111 | d12d51d5 | aliguori | D_LOG("%s returns %d irqreq=%x addr=%x"
|
112 | cf1d97f0 | edgar_igl | " phy=%x ismmu=%d vec=%x pc=%x\n",
|
113 | cf1d97f0 | edgar_igl | __func__, r, env->interrupt_request, |
114 | d12d51d5 | aliguori | address, res.phy, is_softmmu, res.bf_vec, env->pc); |
115 | e62b5b13 | edgar_igl | return r;
|
116 | 81fdc5f8 | ths | } |
117 | 81fdc5f8 | ths | |
118 | 81fdc5f8 | ths | void do_interrupt(CPUState *env)
|
119 | 81fdc5f8 | ths | { |
120 | e62b5b13 | edgar_igl | int ex_vec = -1; |
121 | 81fdc5f8 | ths | |
122 | d12d51d5 | aliguori | D_LOG( "exception index=%d interrupt_req=%d\n",
|
123 | b41f7df0 | edgar_igl | env->exception_index, |
124 | d12d51d5 | aliguori | env->interrupt_request); |
125 | 81fdc5f8 | ths | |
126 | 81fdc5f8 | ths | switch (env->exception_index)
|
127 | 81fdc5f8 | ths | { |
128 | 81fdc5f8 | ths | case EXCP_BREAK:
|
129 | e62b5b13 | edgar_igl | /* These exceptions are genereated by the core itself.
|
130 | e62b5b13 | edgar_igl | ERP should point to the insn following the brk. */
|
131 | e62b5b13 | edgar_igl | ex_vec = env->trap_vector; |
132 | a1aebcb8 | edgar_igl | env->pregs[PR_ERP] = env->pc; |
133 | 81fdc5f8 | ths | break;
|
134 | e62b5b13 | edgar_igl | |
135 | 1b1a38b0 | edgar_igl | case EXCP_NMI:
|
136 | 1b1a38b0 | edgar_igl | /* NMI is hardwired to vector zero. */
|
137 | 1b1a38b0 | edgar_igl | ex_vec = 0;
|
138 | 1b1a38b0 | edgar_igl | env->pregs[PR_CCS] &= ~M_FLAG; |
139 | 1b1a38b0 | edgar_igl | env->pregs[PR_NRP] = env->pc; |
140 | 1b1a38b0 | edgar_igl | break;
|
141 | 1b1a38b0 | edgar_igl | |
142 | 1b1a38b0 | edgar_igl | case EXCP_BUSFAULT:
|
143 | e62b5b13 | edgar_igl | ex_vec = env->fault_vector; |
144 | b41f7df0 | edgar_igl | env->pregs[PR_ERP] = env->pc; |
145 | 81fdc5f8 | ths | break;
|
146 | 81fdc5f8 | ths | |
147 | 81fdc5f8 | ths | default:
|
148 | 1b1a38b0 | edgar_igl | /* The interrupt controller gives us the vector. */
|
149 | b41f7df0 | edgar_igl | ex_vec = env->interrupt_vector; |
150 | b41f7df0 | edgar_igl | /* Normal interrupts are taken between
|
151 | b41f7df0 | edgar_igl | TB's. env->pc is valid here. */
|
152 | b41f7df0 | edgar_igl | env->pregs[PR_ERP] = env->pc; |
153 | b41f7df0 | edgar_igl | break;
|
154 | b41f7df0 | edgar_igl | } |
155 | b41f7df0 | edgar_igl | |
156 | cddffe37 | edgar_igl | /* Fill in the IDX field. */
|
157 | cddffe37 | edgar_igl | env->pregs[PR_EXS] = (ex_vec & 0xff) << 8; |
158 | cddffe37 | edgar_igl | |
159 | cf1d97f0 | edgar_igl | if (env->dslot) {
|
160 | d12d51d5 | aliguori | D_LOG("excp isr=%x PC=%x ds=%d SP=%x"
|
161 | cf1d97f0 | edgar_igl | " ERP=%x pid=%x ccs=%x cc=%d %x\n",
|
162 | cf1d97f0 | edgar_igl | ex_vec, env->pc, env->dslot, |
163 | ef29a70d | edgar_igl | env->regs[R_SP], |
164 | b41f7df0 | edgar_igl | env->pregs[PR_ERP], env->pregs[PR_PID], |
165 | b41f7df0 | edgar_igl | env->pregs[PR_CCS], |
166 | d12d51d5 | aliguori | env->cc_op, env->cc_mask); |
167 | cf1d97f0 | edgar_igl | /* We loose the btarget, btaken state here so rexec the
|
168 | cf1d97f0 | edgar_igl | branch. */
|
169 | cf1d97f0 | edgar_igl | env->pregs[PR_ERP] -= env->dslot; |
170 | cf1d97f0 | edgar_igl | /* Exception starts with dslot cleared. */
|
171 | cf1d97f0 | edgar_igl | env->dslot = 0;
|
172 | 81fdc5f8 | ths | } |
173 | b41f7df0 | edgar_igl | |
174 | e62b5b13 | edgar_igl | env->pc = ldl_code(env->pregs[PR_EBP] + ex_vec * 4);
|
175 | b41f7df0 | edgar_igl | |
176 | b41f7df0 | edgar_igl | if (env->pregs[PR_CCS] & U_FLAG) {
|
177 | b41f7df0 | edgar_igl | /* Swap stack pointers. */
|
178 | b41f7df0 | edgar_igl | env->pregs[PR_USP] = env->regs[R_SP]; |
179 | b41f7df0 | edgar_igl | env->regs[R_SP] = env->ksp; |
180 | b41f7df0 | edgar_igl | } |
181 | b41f7df0 | edgar_igl | |
182 | b41f7df0 | edgar_igl | /* Apply the CRIS CCS shift. Clears U if set. */
|
183 | e62b5b13 | edgar_igl | cris_shift_ccs(env); |
184 | d12d51d5 | aliguori | D_LOG("%s isr=%x vec=%x ccs=%x pid=%d erp=%x\n",
|
185 | b41f7df0 | edgar_igl | __func__, env->pc, ex_vec, |
186 | b41f7df0 | edgar_igl | env->pregs[PR_CCS], |
187 | b41f7df0 | edgar_igl | env->pregs[PR_PID], |
188 | d12d51d5 | aliguori | env->pregs[PR_ERP]); |
189 | 81fdc5f8 | ths | } |
190 | 81fdc5f8 | ths | |
191 | 81fdc5f8 | ths | target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, target_ulong addr) |
192 | 81fdc5f8 | ths | { |
193 | 81fdc5f8 | ths | uint32_t phy = addr; |
194 | 81fdc5f8 | ths | struct cris_mmu_result_t res;
|
195 | 81fdc5f8 | ths | int miss;
|
196 | 81fdc5f8 | ths | miss = cris_mmu_translate(&res, env, addr, 0, 0); |
197 | 81fdc5f8 | ths | if (!miss)
|
198 | 81fdc5f8 | ths | phy = res.phy; |
199 | e62b5b13 | edgar_igl | D(fprintf(stderr, "%s %x -> %x\n", __func__, addr, phy));
|
200 | 81fdc5f8 | ths | return phy;
|
201 | 81fdc5f8 | ths | } |
202 | 81fdc5f8 | ths | #endif |