Statistics
| Branch: | Revision:

root / target-cris / helper.c @ 941db528

History | View | Annotate | Download (4 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 81fdc5f8 ths
#if defined(CONFIG_USER_ONLY)
32 81fdc5f8 ths
33 81fdc5f8 ths
void do_interrupt (CPUState *env)
34 81fdc5f8 ths
{
35 81fdc5f8 ths
  env->exception_index = -1;
36 81fdc5f8 ths
}
37 81fdc5f8 ths
38 81fdc5f8 ths
int cpu_cris_handle_mmu_fault(CPUState * env, target_ulong address, int rw,
39 6ebbf390 j_mayer
                             int mmu_idx, int is_softmmu)
40 81fdc5f8 ths
{
41 81fdc5f8 ths
    env->exception_index = 0xaa;
42 81fdc5f8 ths
    env->debug1 = address;
43 81fdc5f8 ths
    cpu_dump_state(env, stderr, fprintf, 0);
44 81fdc5f8 ths
    printf("%s addr=%x env->pc=%x\n", __func__, address, env->pc);
45 81fdc5f8 ths
    return 1;
46 81fdc5f8 ths
}
47 81fdc5f8 ths
48 81fdc5f8 ths
target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, target_ulong addr)
49 81fdc5f8 ths
{
50 81fdc5f8 ths
    return addr;
51 81fdc5f8 ths
}
52 81fdc5f8 ths
53 81fdc5f8 ths
#else /* !CONFIG_USER_ONLY */
54 81fdc5f8 ths
55 81fdc5f8 ths
int cpu_cris_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
56 6ebbf390 j_mayer
                               int mmu_idx, int is_softmmu)
57 81fdc5f8 ths
{
58 81fdc5f8 ths
        struct cris_mmu_result_t res;
59 81fdc5f8 ths
        int prot, miss;
60 81fdc5f8 ths
        target_ulong phy;
61 81fdc5f8 ths
62 81fdc5f8 ths
        address &= TARGET_PAGE_MASK;
63 81fdc5f8 ths
        prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
64 81fdc5f8 ths
//        printf ("%s pc=%x %x w=%d smmu=%d\n", __func__, env->pc, address, rw, is_softmmu);
65 6ebbf390 j_mayer
        miss = cris_mmu_translate(&res, env, address, rw, mmu_idx);
66 81fdc5f8 ths
        if (miss)
67 81fdc5f8 ths
        {
68 81fdc5f8 ths
                /* handle the miss.  */
69 81fdc5f8 ths
                phy = 0;
70 81fdc5f8 ths
                env->exception_index = EXCP_MMU_MISS;
71 81fdc5f8 ths
        }
72 81fdc5f8 ths
        else
73 81fdc5f8 ths
        {
74 81fdc5f8 ths
                phy = res.phy;
75 81fdc5f8 ths
        }
76 81fdc5f8 ths
//        printf ("a=%x phy=%x\n", address, phy);
77 6ebbf390 j_mayer
        return tlb_set_page(env, address, phy, prot, mmu_idx, is_softmmu);
78 81fdc5f8 ths
}
79 81fdc5f8 ths
80 81fdc5f8 ths
81 81fdc5f8 ths
static void cris_shift_ccs(CPUState *env)
82 81fdc5f8 ths
{
83 81fdc5f8 ths
        uint32_t ccs;
84 81fdc5f8 ths
        /* Apply the ccs shift.  */
85 81fdc5f8 ths
        ccs = env->pregs[SR_CCS];
86 81fdc5f8 ths
        ccs = (ccs & 0xc0000000) | ((ccs << 12) >> 2);
87 81fdc5f8 ths
//        printf ("ccs=%x %x\n", env->pregs[SR_CCS], ccs);
88 81fdc5f8 ths
        env->pregs[SR_CCS] = ccs;
89 81fdc5f8 ths
}
90 81fdc5f8 ths
91 81fdc5f8 ths
void do_interrupt(CPUState *env)
92 81fdc5f8 ths
{
93 81fdc5f8 ths
        uint32_t ebp, isr;
94 81fdc5f8 ths
        int irqnum;
95 81fdc5f8 ths
96 81fdc5f8 ths
        fflush(NULL);
97 81fdc5f8 ths
98 81fdc5f8 ths
#if 0
99 81fdc5f8 ths
        printf ("exception index=%d interrupt_req=%d\n",
100 81fdc5f8 ths
                env->exception_index,
101 81fdc5f8 ths
                env->interrupt_request);
102 81fdc5f8 ths
#endif
103 81fdc5f8 ths
104 81fdc5f8 ths
        switch (env->exception_index)
105 81fdc5f8 ths
        {
106 81fdc5f8 ths
                case EXCP_BREAK:
107 81fdc5f8 ths
//                        printf ("BREAK! %d\n", env->trapnr);
108 81fdc5f8 ths
                        irqnum = env->trapnr;
109 81fdc5f8 ths
                        ebp = env->pregs[SR_EBP];
110 81fdc5f8 ths
                        isr = ldl_code(ebp + irqnum * 4);
111 81fdc5f8 ths
                        env->pregs[SR_ERP] = env->pc + 2;
112 81fdc5f8 ths
                        env->pc = isr;
113 81fdc5f8 ths
114 81fdc5f8 ths
                        cris_shift_ccs(env);
115 81fdc5f8 ths
116 81fdc5f8 ths
                        break;
117 81fdc5f8 ths
                case EXCP_MMU_MISS:
118 81fdc5f8 ths
//                        printf ("MMU miss\n");
119 81fdc5f8 ths
                        irqnum = 4;
120 81fdc5f8 ths
                        ebp = env->pregs[SR_EBP];
121 81fdc5f8 ths
                        isr = ldl_code(ebp + irqnum * 4);
122 81fdc5f8 ths
                        env->pregs[SR_ERP] = env->pc;
123 81fdc5f8 ths
                        env->pc = isr;
124 81fdc5f8 ths
                        cris_shift_ccs(env);
125 81fdc5f8 ths
                        break;
126 81fdc5f8 ths
127 81fdc5f8 ths
                default:
128 81fdc5f8 ths
                {
129 81fdc5f8 ths
                        /* Maybe the irq was acked by sw before we got a
130 81fdc5f8 ths
                           change to take it.  */
131 81fdc5f8 ths
                        if (env->interrupt_request & CPU_INTERRUPT_HARD) {
132 81fdc5f8 ths
                                if (!env->pending_interrupts)
133 81fdc5f8 ths
                                        return;
134 81fdc5f8 ths
                                if (!(env->pregs[SR_CCS] & I_FLAG)) {
135 81fdc5f8 ths
                                        return;
136 81fdc5f8 ths
                                }
137 81fdc5f8 ths
138 941db528 ths
                                irqnum = 31 - clz32(env->pending_interrupts);
139 81fdc5f8 ths
                                irqnum += 0x30;
140 81fdc5f8 ths
                                ebp = env->pregs[SR_EBP];
141 81fdc5f8 ths
                                isr = ldl_code(ebp + irqnum * 4);
142 81fdc5f8 ths
                                env->pregs[SR_ERP] = env->pc;
143 81fdc5f8 ths
                                env->pc = isr;
144 81fdc5f8 ths
145 81fdc5f8 ths
                                cris_shift_ccs(env);
146 81fdc5f8 ths
#if 0
147 81fdc5f8 ths
                                printf ("%s ebp=%x %x isr=%x %d"
148 81fdc5f8 ths
                                        " ir=%x pending=%x\n",
149 81fdc5f8 ths
                                        __func__,
150 81fdc5f8 ths
                                        ebp, ebp + irqnum * 4,
151 81fdc5f8 ths
                                        isr, env->exception_index,
152 81fdc5f8 ths
                                        env->interrupt_request,
153 81fdc5f8 ths
                                        env->pending_interrupts);
154 81fdc5f8 ths
#endif
155 81fdc5f8 ths
                        }
156 81fdc5f8 ths
157 81fdc5f8 ths
                }
158 81fdc5f8 ths
                break;
159 81fdc5f8 ths
        }
160 81fdc5f8 ths
}
161 81fdc5f8 ths
162 81fdc5f8 ths
target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, target_ulong addr)
163 81fdc5f8 ths
{
164 81fdc5f8 ths
//        printf ("%s\n", __func__);
165 81fdc5f8 ths
        uint32_t phy = addr;
166 81fdc5f8 ths
        struct cris_mmu_result_t res;
167 81fdc5f8 ths
        int miss;
168 81fdc5f8 ths
        miss = cris_mmu_translate(&res, env, addr, 0, 0);
169 81fdc5f8 ths
        if (!miss)
170 81fdc5f8 ths
                phy = res.phy;
171 81fdc5f8 ths
        return phy;
172 81fdc5f8 ths
}
173 81fdc5f8 ths
#endif