]> git.proxmox.com Git - qemu.git/blame - target-cris/helper.c
Use tcg_const_tl for zero constant
[qemu.git] / target-cris / helper.c
CommitLineData
81fdc5f8
TS
1/*
2 * CRIS helper routines.
3 *
4 * Copyright (c) 2007 AXIS Communications AB
5 * Written by Edgar E. Iglesias.
6 *
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.
11 *
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.
16 *
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
20 */
21
22#include <stdio.h>
23#include <string.h>
24
25#include "config.h"
26#include "cpu.h"
27#include "mmu.h"
28#include "exec-all.h"
941db528 29#include "host-utils.h"
81fdc5f8
TS
30
31#if defined(CONFIG_USER_ONLY)
32
33void do_interrupt (CPUState *env)
34{
bbaf29c7
EI
35 env->exception_index = -1;
36 env->pregs[PR_ERP] = env->pc;
81fdc5f8
TS
37}
38
39int cpu_cris_handle_mmu_fault(CPUState * env, target_ulong address, int rw,
6ebbf390 40 int mmu_idx, int is_softmmu)
81fdc5f8 41{
bbaf29c7
EI
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;
81fdc5f8
TS
47}
48
49target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, target_ulong addr)
50{
bbaf29c7 51 return addr;
81fdc5f8
TS
52}
53
54#else /* !CONFIG_USER_ONLY */
55
56int cpu_cris_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
6ebbf390 57 int mmu_idx, int is_softmmu)
81fdc5f8
TS
58{
59 struct cris_mmu_result_t res;
60 int prot, miss;
61 target_ulong phy;
62
63 address &= TARGET_PAGE_MASK;
64 prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
6ebbf390 65 miss = cris_mmu_translate(&res, env, address, rw, mmu_idx);
81fdc5f8
TS
66 if (miss)
67 {
68 /* handle the miss. */
69 phy = 0;
70 env->exception_index = EXCP_MMU_MISS;
71 }
72 else
73 {
74 phy = res.phy;
75 }
6ebbf390 76 return tlb_set_page(env, address, phy, prot, mmu_idx, is_softmmu);
81fdc5f8
TS
77}
78
79
80static void cris_shift_ccs(CPUState *env)
81{
82 uint32_t ccs;
83 /* Apply the ccs shift. */
9004627f 84 ccs = env->pregs[PR_CCS];
81fdc5f8 85 ccs = (ccs & 0xc0000000) | ((ccs << 12) >> 2);
9004627f 86 env->pregs[PR_CCS] = ccs;
81fdc5f8
TS
87}
88
89void do_interrupt(CPUState *env)
90{
91 uint32_t ebp, isr;
92 int irqnum;
93
94 fflush(NULL);
95
96#if 0
97 printf ("exception index=%d interrupt_req=%d\n",
98 env->exception_index,
99 env->interrupt_request);
100#endif
101
102 switch (env->exception_index)
103 {
104 case EXCP_BREAK:
81fdc5f8 105 irqnum = env->trapnr;
9004627f 106 ebp = env->pregs[PR_EBP];
81fdc5f8 107 isr = ldl_code(ebp + irqnum * 4);
9004627f 108 env->pregs[PR_ERP] = env->pc + 2;
81fdc5f8
TS
109 env->pc = isr;
110
111 cris_shift_ccs(env);
112
113 break;
114 case EXCP_MMU_MISS:
81fdc5f8 115 irqnum = 4;
9004627f 116 ebp = env->pregs[PR_EBP];
81fdc5f8 117 isr = ldl_code(ebp + irqnum * 4);
9004627f 118 env->pregs[PR_ERP] = env->pc;
81fdc5f8
TS
119 env->pc = isr;
120 cris_shift_ccs(env);
121 break;
122
123 default:
124 {
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;
9004627f 130 if (!(env->pregs[PR_CCS] & I_FLAG)) {
81fdc5f8
TS
131 return;
132 }
133
941db528 134 irqnum = 31 - clz32(env->pending_interrupts);
81fdc5f8 135 irqnum += 0x30;
9004627f 136 ebp = env->pregs[PR_EBP];
81fdc5f8 137 isr = ldl_code(ebp + irqnum * 4);
9004627f 138 env->pregs[PR_ERP] = env->pc;
81fdc5f8
TS
139 env->pc = isr;
140
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
151 }
152
153 }
154 break;
155 }
156}
157
158target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, target_ulong addr)
159{
81fdc5f8
TS
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;
167}
168#endif