Statistics
| Branch: | Revision:

root / target-cris / helper.c @ 980f8a0b

History | View | Annotate | Download (4.8 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 81fdc5f8 ths
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 e62b5b13 edgar_igl
#define D(x)
32 e62b5b13 edgar_igl
33 81fdc5f8 ths
#if defined(CONFIG_USER_ONLY)
34 81fdc5f8 ths
35 81fdc5f8 ths
void do_interrupt (CPUState *env)
36 81fdc5f8 ths
{
37 bbaf29c7 edgar_igl
        env->exception_index = -1;
38 bbaf29c7 edgar_igl
        env->pregs[PR_ERP] = env->pc;
39 81fdc5f8 ths
}
40 81fdc5f8 ths
41 81fdc5f8 ths
int cpu_cris_handle_mmu_fault(CPUState * env, target_ulong address, int rw,
42 6ebbf390 j_mayer
                             int mmu_idx, int is_softmmu)
43 81fdc5f8 ths
{
44 bbaf29c7 edgar_igl
        env->exception_index = 0xaa;
45 30abcfc7 edgar_igl
        env->pregs[PR_EDA] = address;
46 bbaf29c7 edgar_igl
        cpu_dump_state(env, stderr, fprintf, 0);
47 bbaf29c7 edgar_igl
        return 1;
48 81fdc5f8 ths
}
49 81fdc5f8 ths
50 81fdc5f8 ths
target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, target_ulong addr)
51 81fdc5f8 ths
{
52 bbaf29c7 edgar_igl
        return addr;
53 81fdc5f8 ths
}
54 81fdc5f8 ths
55 81fdc5f8 ths
#else /* !CONFIG_USER_ONLY */
56 81fdc5f8 ths
57 e62b5b13 edgar_igl
58 e62b5b13 edgar_igl
static void cris_shift_ccs(CPUState *env)
59 e62b5b13 edgar_igl
{
60 e62b5b13 edgar_igl
        uint32_t ccs;
61 e62b5b13 edgar_igl
        /* Apply the ccs shift.  */
62 e62b5b13 edgar_igl
        ccs = env->pregs[PR_CCS];
63 b41f7df0 edgar_igl
        ccs = ((ccs & 0xc0000000) | ((ccs << 12) >> 2)) & ~0x3ff;
64 e62b5b13 edgar_igl
        env->pregs[PR_CCS] = ccs;
65 e62b5b13 edgar_igl
}
66 e62b5b13 edgar_igl
67 81fdc5f8 ths
int cpu_cris_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
68 6ebbf390 j_mayer
                               int mmu_idx, int is_softmmu)
69 81fdc5f8 ths
{
70 81fdc5f8 ths
        struct cris_mmu_result_t res;
71 81fdc5f8 ths
        int prot, miss;
72 e62b5b13 edgar_igl
        int r = -1;
73 81fdc5f8 ths
        target_ulong phy;
74 81fdc5f8 ths
75 b41f7df0 edgar_igl
        D(printf ("%s addr=%x pc=%x rw=%x\n", __func__, address, env->pc, rw));
76 81fdc5f8 ths
        address &= TARGET_PAGE_MASK;
77 6ebbf390 j_mayer
        miss = cris_mmu_translate(&res, env, address, rw, mmu_idx);
78 81fdc5f8 ths
        if (miss)
79 81fdc5f8 ths
        {
80 1b1a38b0 edgar_igl
                if (env->exception_index == EXCP_BUSFAULT)
81 ef29a70d edgar_igl
                        cpu_abort(env, 
82 ef29a70d edgar_igl
                                  "CRIS: Illegal recursive bus fault."
83 ef29a70d edgar_igl
                                  "addr=%x rw=%d\n",
84 ef29a70d edgar_igl
                                  address, rw);
85 ef29a70d edgar_igl
86 1b1a38b0 edgar_igl
                env->exception_index = EXCP_BUSFAULT;
87 e62b5b13 edgar_igl
                env->fault_vector = res.bf_vec;
88 e62b5b13 edgar_igl
                r = 1;
89 81fdc5f8 ths
        }
90 81fdc5f8 ths
        else
91 81fdc5f8 ths
        {
92 980f8a0b edgar_igl
                /*
93 980f8a0b edgar_igl
                 * Mask off the cache selection bit. The ETRAX busses do not
94 980f8a0b edgar_igl
                 * see the top bit.
95 980f8a0b edgar_igl
                 */
96 980f8a0b edgar_igl
                phy = res.phy & ~0x80000000;
97 b41f7df0 edgar_igl
                prot = res.prot;
98 e62b5b13 edgar_igl
                r = tlb_set_page(env, address, phy, prot, mmu_idx, is_softmmu);
99 81fdc5f8 ths
        }
100 b41f7df0 edgar_igl
        if (r > 0)
101 cf1d97f0 edgar_igl
                D(fprintf(logfile, "%s returns %d irqreq=%x addr=%x"
102 cf1d97f0 edgar_igl
                          " phy=%x ismmu=%d vec=%x pc=%x\n", 
103 cf1d97f0 edgar_igl
                          __func__, r, env->interrupt_request, 
104 cf1d97f0 edgar_igl
                          address, res.phy, is_softmmu, res.bf_vec, env->pc));
105 e62b5b13 edgar_igl
        return r;
106 81fdc5f8 ths
}
107 81fdc5f8 ths
108 81fdc5f8 ths
void do_interrupt(CPUState *env)
109 81fdc5f8 ths
{
110 e62b5b13 edgar_igl
        int ex_vec = -1;
111 81fdc5f8 ths
112 ef29a70d edgar_igl
        D(fprintf (logfile, "exception index=%d interrupt_req=%d\n",
113 b41f7df0 edgar_igl
                   env->exception_index,
114 b41f7df0 edgar_igl
                   env->interrupt_request));
115 81fdc5f8 ths
116 81fdc5f8 ths
        switch (env->exception_index)
117 81fdc5f8 ths
        {
118 81fdc5f8 ths
                case EXCP_BREAK:
119 e62b5b13 edgar_igl
                        /* These exceptions are genereated by the core itself.
120 e62b5b13 edgar_igl
                           ERP should point to the insn following the brk.  */
121 e62b5b13 edgar_igl
                        ex_vec = env->trap_vector;
122 9004627f edgar_igl
                        env->pregs[PR_ERP] = env->pc + 2;
123 81fdc5f8 ths
                        break;
124 e62b5b13 edgar_igl
125 1b1a38b0 edgar_igl
                case EXCP_NMI:
126 1b1a38b0 edgar_igl
                        /* NMI is hardwired to vector zero.  */
127 1b1a38b0 edgar_igl
                        ex_vec = 0;
128 1b1a38b0 edgar_igl
                        env->pregs[PR_CCS] &= ~M_FLAG;
129 1b1a38b0 edgar_igl
                        env->pregs[PR_NRP] = env->pc;
130 1b1a38b0 edgar_igl
                        break;
131 1b1a38b0 edgar_igl
132 1b1a38b0 edgar_igl
                case EXCP_BUSFAULT:
133 e62b5b13 edgar_igl
                        ex_vec = env->fault_vector;
134 b41f7df0 edgar_igl
                        env->pregs[PR_ERP] = env->pc;
135 81fdc5f8 ths
                        break;
136 81fdc5f8 ths
137 81fdc5f8 ths
                default:
138 1b1a38b0 edgar_igl
                        /* The interrupt controller gives us the vector.  */
139 b41f7df0 edgar_igl
                        ex_vec = env->interrupt_vector;
140 b41f7df0 edgar_igl
                        /* Normal interrupts are taken between
141 b41f7df0 edgar_igl
                           TB's.  env->pc is valid here.  */
142 b41f7df0 edgar_igl
                        env->pregs[PR_ERP] = env->pc;
143 b41f7df0 edgar_igl
                        break;
144 b41f7df0 edgar_igl
        }
145 b41f7df0 edgar_igl
146 cf1d97f0 edgar_igl
        if (env->dslot) {
147 cf1d97f0 edgar_igl
                D(fprintf(logfile, "excp isr=%x PC=%x ds=%d SP=%x"
148 cf1d97f0 edgar_igl
                          " ERP=%x pid=%x ccs=%x cc=%d %x\n",
149 cf1d97f0 edgar_igl
                          ex_vec, env->pc, env->dslot,
150 ef29a70d edgar_igl
                          env->regs[R_SP],
151 b41f7df0 edgar_igl
                          env->pregs[PR_ERP], env->pregs[PR_PID],
152 b41f7df0 edgar_igl
                          env->pregs[PR_CCS],
153 b41f7df0 edgar_igl
                          env->cc_op, env->cc_mask));
154 cf1d97f0 edgar_igl
                /* We loose the btarget, btaken state here so rexec the
155 cf1d97f0 edgar_igl
                   branch.  */
156 cf1d97f0 edgar_igl
                env->pregs[PR_ERP] -= env->dslot;
157 cf1d97f0 edgar_igl
                /* Exception starts with dslot cleared.  */
158 cf1d97f0 edgar_igl
                env->dslot = 0;
159 81fdc5f8 ths
        }
160 b41f7df0 edgar_igl
        
161 e62b5b13 edgar_igl
        env->pc = ldl_code(env->pregs[PR_EBP] + ex_vec * 4);
162 b41f7df0 edgar_igl
163 b41f7df0 edgar_igl
        if (env->pregs[PR_CCS] & U_FLAG) {
164 b41f7df0 edgar_igl
                /* Swap stack pointers.  */
165 b41f7df0 edgar_igl
                env->pregs[PR_USP] = env->regs[R_SP];
166 b41f7df0 edgar_igl
                env->regs[R_SP] = env->ksp;
167 b41f7df0 edgar_igl
        }
168 b41f7df0 edgar_igl
169 b41f7df0 edgar_igl
        /* Apply the CRIS CCS shift. Clears U if set.  */
170 e62b5b13 edgar_igl
        cris_shift_ccs(env);
171 b41f7df0 edgar_igl
        D(fprintf (logfile, "%s isr=%x vec=%x ccs=%x pid=%d erp=%x\n", 
172 b41f7df0 edgar_igl
                   __func__, env->pc, ex_vec, 
173 b41f7df0 edgar_igl
                   env->pregs[PR_CCS],
174 b41f7df0 edgar_igl
                   env->pregs[PR_PID], 
175 b41f7df0 edgar_igl
                   env->pregs[PR_ERP]));
176 81fdc5f8 ths
}
177 81fdc5f8 ths
178 81fdc5f8 ths
target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, target_ulong addr)
179 81fdc5f8 ths
{
180 81fdc5f8 ths
        uint32_t phy = addr;
181 81fdc5f8 ths
        struct cris_mmu_result_t res;
182 81fdc5f8 ths
        int miss;
183 81fdc5f8 ths
        miss = cris_mmu_translate(&res, env, addr, 0, 0);
184 81fdc5f8 ths
        if (!miss)
185 81fdc5f8 ths
                phy = res.phy;
186 e62b5b13 edgar_igl
        D(fprintf(stderr, "%s %x -> %x\n", __func__, addr, phy));
187 81fdc5f8 ths
        return phy;
188 81fdc5f8 ths
}
189 81fdc5f8 ths
#endif