]> Git Repo - qemu.git/blame - target-lm32/helper.c
exec: extract exec/tb-context.h
[qemu.git] / target-lm32 / helper.c
CommitLineData
17c0fa3d
MW
1/*
2 * LatticeMico32 helper routines.
3 *
f7bbcfb5 4 * Copyright (c) 2010-2014 Michael Walle <[email protected]>
17c0fa3d
MW
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
ea99dde1 20#include "qemu/osdep.h"
17c0fa3d 21#include "cpu.h"
1de7afc9 22#include "qemu/host-utils.h"
f7bbcfb5 23#include "sysemu/sysemu.h"
cfe67cef 24#include "exec/semihost.h"
508127e2 25#include "exec/log.h"
17c0fa3d 26
7510454e 27int lm32_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
97b348e7 28 int mmu_idx)
17c0fa3d 29{
7510454e
AF
30 LM32CPU *cpu = LM32_CPU(cs);
31 CPULM32State *env = &cpu->env;
17c0fa3d
MW
32 int prot;
33
34 address &= TARGET_PAGE_MASK;
35 prot = PAGE_BITS;
36 if (env->flags & LM32_FLAG_IGNORE_MSB) {
0c591eb0
AF
37 tlb_set_page(cs, address, address & 0x7fffffff, prot, mmu_idx,
38 TARGET_PAGE_SIZE);
17c0fa3d 39 } else {
0c591eb0 40 tlb_set_page(cs, address, address, prot, mmu_idx, TARGET_PAGE_SIZE);
17c0fa3d
MW
41 }
42
43 return 0;
44}
45
00b941e5 46hwaddr lm32_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
17c0fa3d 47{
00b941e5
AF
48 LM32CPU *cpu = LM32_CPU(cs);
49
b92e062a 50 addr &= TARGET_PAGE_MASK;
00b941e5 51 if (cpu->env.flags & LM32_FLAG_IGNORE_MSB) {
b92e062a
MW
52 return addr & 0x7fffffff;
53 } else {
54 return addr;
55 }
17c0fa3d
MW
56}
57
3dd3a2b9
MW
58void lm32_breakpoint_insert(CPULM32State *env, int idx, target_ulong address)
59{
b3310ab3
AF
60 LM32CPU *cpu = lm32_env_get_cpu(env);
61
62 cpu_breakpoint_insert(CPU(cpu), address, BP_CPU,
63 &env->cpu_breakpoint[idx]);
3dd3a2b9
MW
64}
65
66void lm32_breakpoint_remove(CPULM32State *env, int idx)
67{
b3310ab3
AF
68 LM32CPU *cpu = lm32_env_get_cpu(env);
69
3dd3a2b9
MW
70 if (!env->cpu_breakpoint[idx]) {
71 return;
72 }
73
b3310ab3 74 cpu_breakpoint_remove_by_ref(CPU(cpu), env->cpu_breakpoint[idx]);
3dd3a2b9
MW
75 env->cpu_breakpoint[idx] = NULL;
76}
77
78void lm32_watchpoint_insert(CPULM32State *env, int idx, target_ulong address,
79 lm32_wp_t wp_type)
80{
75a34036 81 LM32CPU *cpu = lm32_env_get_cpu(env);
3dd3a2b9
MW
82 int flags = 0;
83
84 switch (wp_type) {
85 case LM32_WP_DISABLED:
b6af0975 86 /* nothing to do */
3dd3a2b9
MW
87 break;
88 case LM32_WP_READ:
89 flags = BP_CPU | BP_STOP_BEFORE_ACCESS | BP_MEM_READ;
90 break;
91 case LM32_WP_WRITE:
92 flags = BP_CPU | BP_STOP_BEFORE_ACCESS | BP_MEM_WRITE;
93 break;
94 case LM32_WP_READ_WRITE:
95 flags = BP_CPU | BP_STOP_BEFORE_ACCESS | BP_MEM_ACCESS;
96 break;
97 }
98
99 if (flags != 0) {
75a34036 100 cpu_watchpoint_insert(CPU(cpu), address, 1, flags,
3dd3a2b9
MW
101 &env->cpu_watchpoint[idx]);
102 }
103}
104
105void lm32_watchpoint_remove(CPULM32State *env, int idx)
106{
75a34036
AF
107 LM32CPU *cpu = lm32_env_get_cpu(env);
108
3dd3a2b9
MW
109 if (!env->cpu_watchpoint[idx]) {
110 return;
111 }
112
75a34036 113 cpu_watchpoint_remove_by_ref(CPU(cpu), env->cpu_watchpoint[idx]);
3dd3a2b9
MW
114 env->cpu_watchpoint[idx] = NULL;
115}
116
117static bool check_watchpoints(CPULM32State *env)
118{
119 LM32CPU *cpu = lm32_env_get_cpu(env);
120 int i;
121
122 for (i = 0; i < cpu->num_watchpoints; i++) {
123 if (env->cpu_watchpoint[i] &&
124 env->cpu_watchpoint[i]->flags & BP_WATCHPOINT_HIT) {
125 return true;
126 }
127 }
128 return false;
129}
130
86025ee4 131void lm32_debug_excp_handler(CPUState *cs)
3dd3a2b9 132{
86025ee4
PM
133 LM32CPU *cpu = LM32_CPU(cs);
134 CPULM32State *env = &cpu->env;
3dd3a2b9
MW
135 CPUBreakpoint *bp;
136
ff4700b0
AF
137 if (cs->watchpoint_hit) {
138 if (cs->watchpoint_hit->flags & BP_CPU) {
139 cs->watchpoint_hit = NULL;
3dd3a2b9
MW
140 if (check_watchpoints(env)) {
141 raise_exception(env, EXCP_WATCHPOINT);
142 } else {
0ea8cb88 143 cpu_resume_from_signal(cs, NULL);
3dd3a2b9
MW
144 }
145 }
146 } else {
f0c3c505 147 QTAILQ_FOREACH(bp, &cs->breakpoints, entry) {
3dd3a2b9
MW
148 if (bp->pc == env->pc) {
149 if (bp->flags & BP_CPU) {
150 raise_exception(env, EXCP_BREAKPOINT);
151 }
152 break;
153 }
154 }
155 }
156}
157
97a8ea5a 158void lm32_cpu_do_interrupt(CPUState *cs)
17c0fa3d 159{
97a8ea5a
AF
160 LM32CPU *cpu = LM32_CPU(cs);
161 CPULM32State *env = &cpu->env;
162
17c0fa3d 163 qemu_log_mask(CPU_LOG_INT,
27103424 164 "exception at pc=%x type=%x\n", env->pc, cs->exception_index);
17c0fa3d 165
27103424 166 switch (cs->exception_index) {
f7bbcfb5 167 case EXCP_SYSTEMCALL:
cfe67cef 168 if (unlikely(semihosting_enabled())) {
f7bbcfb5
MW
169 /* do_semicall() returns true if call was handled. Otherwise
170 * do the normal exception handling. */
171 if (lm32_cpu_do_semihosting(cs)) {
172 env->pc += 4;
173 break;
174 }
175 }
176 /* fall through */
17c0fa3d
MW
177 case EXCP_INSN_BUS_ERROR:
178 case EXCP_DATA_BUS_ERROR:
179 case EXCP_DIVIDE_BY_ZERO:
180 case EXCP_IRQ:
17c0fa3d
MW
181 /* non-debug exceptions */
182 env->regs[R_EA] = env->pc;
183 env->ie |= (env->ie & IE_IE) ? IE_EIE : 0;
184 env->ie &= ~IE_IE;
185 if (env->dc & DC_RE) {
27103424 186 env->pc = env->deba + (cs->exception_index * 32);
17c0fa3d 187 } else {
27103424 188 env->pc = env->eba + (cs->exception_index * 32);
17c0fa3d 189 }
a0762859 190 log_cpu_state_mask(CPU_LOG_INT, cs, 0);
17c0fa3d
MW
191 break;
192 case EXCP_BREAKPOINT:
193 case EXCP_WATCHPOINT:
194 /* debug exceptions */
195 env->regs[R_BA] = env->pc;
196 env->ie |= (env->ie & IE_IE) ? IE_BIE : 0;
197 env->ie &= ~IE_IE;
27103424 198 env->pc = env->deba + (cs->exception_index * 32);
a0762859 199 log_cpu_state_mask(CPU_LOG_INT, cs, 0);
17c0fa3d
MW
200 break;
201 default:
a47dddd7 202 cpu_abort(cs, "unhandled exception type=%d\n",
27103424 203 cs->exception_index);
17c0fa3d
MW
204 break;
205 }
206}
207
e9854c39
RH
208bool lm32_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
209{
210 LM32CPU *cpu = LM32_CPU(cs);
211 CPULM32State *env = &cpu->env;
212
213 if ((interrupt_request & CPU_INTERRUPT_HARD) && (env->ie & IE_IE)) {
214 cs->exception_index = EXCP_IRQ;
215 lm32_cpu_do_interrupt(cs);
216 return true;
217 }
218 return false;
219}
220
0347d689 221LM32CPU *cpu_lm32_init(const char *cpu_model)
17c0fa3d 222{
9262685b 223 return LM32_CPU(cpu_generic_init(TYPE_LM32_CPU, cpu_model));
17c0fa3d
MW
224}
225
226/* Some soc ignores the MSB on the address bus. Thus creating a shadow memory
227 * area. As a general rule, 0x00000000-0x7fffffff is cached, whereas
228 * 0x80000000-0xffffffff is not cached and used to access IO devices. */
6393c08d 229void cpu_lm32_set_phys_msb_ignore(CPULM32State *env, int value)
17c0fa3d
MW
230{
231 if (value) {
232 env->flags |= LM32_FLAG_IGNORE_MSB;
233 } else {
234 env->flags &= ~LM32_FLAG_IGNORE_MSB;
235 }
236}
This page took 0.44692 seconds and 4 git commands to generate.