2 * Moxie helper routines.
4 * Copyright (c) 2008, 2009, 2010, 2013 Anthony Green
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.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "exec/exec-all.h"
28 #include "exec/softmmu_exec.h"
29 #include "qemu/host-utils.h"
32 #define MMUSUFFIX _mmu
35 #include "exec/softmmu_template.h"
38 #include "exec/softmmu_template.h"
41 #include "exec/softmmu_template.h"
44 #include "exec/softmmu_template.h"
46 /* Try to fill the TLB and return an exception if error. If retaddr is
47 NULL, it means that the function was called in C code (i.e. not
48 from generated code or from helper.c) */
49 void tlb_fill(CPUState
*cs
, target_ulong addr
, int is_write
, int mmu_idx
,
54 ret
= moxie_cpu_handle_mmu_fault(cs
, addr
, is_write
, mmu_idx
);
57 cpu_restore_state(cs
, retaddr
);
63 void helper_raise_exception(CPUMoxieState
*env
, int ex
)
65 CPUState
*cs
= CPU(moxie_env_get_cpu(env
));
67 cs
->exception_index
= ex
;
68 /* Stash the exception type. */
70 /* Stash the address where the exception occurred. */
71 cpu_restore_state(cs
, GETPC());
72 env
->sregs
[5] = env
->pc
;
73 /* Jump the the exception handline routine. */
74 env
->pc
= env
->sregs
[1];
78 uint32_t helper_div(CPUMoxieState
*env
, uint32_t a
, uint32_t b
)
80 if (unlikely(b
== 0)) {
81 helper_raise_exception(env
, MOXIE_EX_DIV0
);
84 if (unlikely(a
== INT_MIN
&& b
== -1)) {
88 return (int32_t)a
/ (int32_t)b
;
91 uint32_t helper_udiv(CPUMoxieState
*env
, uint32_t a
, uint32_t b
)
93 if (unlikely(b
== 0)) {
94 helper_raise_exception(env
, MOXIE_EX_DIV0
);
100 void helper_debug(CPUMoxieState
*env
)
102 CPUState
*cs
= CPU(moxie_env_get_cpu(env
));
104 cs
->exception_index
= EXCP_DEBUG
;
108 #if defined(CONFIG_USER_ONLY)
110 void moxie_cpu_do_interrupt(CPUState
*cs
)
112 CPUState
*cs
= CPU(moxie_env_get_cpu(env
));
114 cs
->exception_index
= -1;
117 int moxie_cpu_handle_mmu_fault(CPUState
*cs
, vaddr address
,
120 MoxieCPU
*cpu
= MOXIE_CPU(cs
);
122 cs
->exception_index
= 0xaa;
123 cpu
->env
.debug1
= address
;
124 cpu_dump_state(cs
, stderr
, fprintf
, 0);
128 #else /* !CONFIG_USER_ONLY */
130 int moxie_cpu_handle_mmu_fault(CPUState
*cs
, vaddr address
,
133 MoxieCPU
*cpu
= MOXIE_CPU(cs
);
134 CPUMoxieState
*env
= &cpu
->env
;
140 address
&= TARGET_PAGE_MASK
;
141 prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
142 miss
= moxie_mmu_translate(&res
, env
, address
, rw
, mmu_idx
);
144 /* handle the miss. */
146 cs
->exception_index
= MOXIE_EX_MMU_MISS
;
151 tlb_set_page(cs
, address
, phy
, prot
, mmu_idx
, TARGET_PAGE_SIZE
);
156 void moxie_cpu_do_interrupt(CPUState
*cs
)
158 switch (cs
->exception_index
) {
166 hwaddr
moxie_cpu_get_phys_page_debug(CPUState
*cs
, vaddr addr
)
168 MoxieCPU
*cpu
= MOXIE_CPU(cs
);
173 miss
= moxie_mmu_translate(&res
, &cpu
->env
, addr
, 0, 0);