]> Git Repo - qemu.git/blame - target-moxie/helper.c
maint: remove / fix many doubled words
[qemu.git] / target-moxie / helper.c
CommitLineData
525bd324
AG
1/*
2 * Moxie helper routines.
3 *
4 * Copyright (c) 2008, 2009, 2010, 2013 Anthony Green
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 General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <stdio.h>
21#include <string.h>
22#include <assert.h>
23
24#include "config.h"
25#include "cpu.h"
26#include "mmu.h"
27#include "exec/exec-all.h"
f08b6170 28#include "exec/cpu_ldst.h"
525bd324 29#include "qemu/host-utils.h"
2ef6175a 30#include "exec/helper-proto.h"
525bd324 31
525bd324
AG
32/* Try to fill the TLB and return an exception if error. If retaddr is
33 NULL, it means that the function was called in C code (i.e. not
34 from generated code or from helper.c) */
d5a11fef 35void tlb_fill(CPUState *cs, target_ulong addr, int is_write, int mmu_idx,
525bd324
AG
36 uintptr_t retaddr)
37{
38 int ret;
39
d5a11fef 40 ret = moxie_cpu_handle_mmu_fault(cs, addr, is_write, mmu_idx);
525bd324
AG
41 if (unlikely(ret)) {
42 if (retaddr) {
3f38f309 43 cpu_restore_state(cs, retaddr);
525bd324
AG
44 }
45 }
5638d180 46 cpu_loop_exit(cs);
525bd324
AG
47}
48
49void helper_raise_exception(CPUMoxieState *env, int ex)
50{
27103424
AF
51 CPUState *cs = CPU(moxie_env_get_cpu(env));
52
53 cs->exception_index = ex;
525bd324
AG
54 /* Stash the exception type. */
55 env->sregs[2] = ex;
56 /* Stash the address where the exception occurred. */
3f38f309 57 cpu_restore_state(cs, GETPC());
525bd324 58 env->sregs[5] = env->pc;
b6af0975 59 /* Jump to the exception handline routine. */
525bd324 60 env->pc = env->sregs[1];
5638d180 61 cpu_loop_exit(cs);
525bd324
AG
62}
63
64uint32_t helper_div(CPUMoxieState *env, uint32_t a, uint32_t b)
65{
66 if (unlikely(b == 0)) {
67 helper_raise_exception(env, MOXIE_EX_DIV0);
68 return 0;
69 }
70 if (unlikely(a == INT_MIN && b == -1)) {
71 return INT_MIN;
72 }
73
74 return (int32_t)a / (int32_t)b;
75}
76
77uint32_t helper_udiv(CPUMoxieState *env, uint32_t a, uint32_t b)
78{
79 if (unlikely(b == 0)) {
80 helper_raise_exception(env, MOXIE_EX_DIV0);
81 return 0;
82 }
83 return a / b;
84}
85
86void helper_debug(CPUMoxieState *env)
87{
27103424
AF
88 CPUState *cs = CPU(moxie_env_get_cpu(env));
89
90 cs->exception_index = EXCP_DEBUG;
5638d180 91 cpu_loop_exit(cs);
525bd324
AG
92}
93
94#if defined(CONFIG_USER_ONLY)
95
7510454e 96void moxie_cpu_do_interrupt(CPUState *cs)
525bd324 97{
27103424
AF
98 CPUState *cs = CPU(moxie_env_get_cpu(env));
99
100 cs->exception_index = -1;
525bd324
AG
101}
102
7510454e 103int moxie_cpu_handle_mmu_fault(CPUState *cs, vaddr address,
525bd324
AG
104 int rw, int mmu_idx)
105{
7510454e 106 MoxieCPU *cpu = MOXIE_CPU(cs);
878096ee 107
27103424 108 cs->exception_index = 0xaa;
7510454e
AF
109 cpu->env.debug1 = address;
110 cpu_dump_state(cs, stderr, fprintf, 0);
525bd324
AG
111 return 1;
112}
113
525bd324
AG
114#else /* !CONFIG_USER_ONLY */
115
7510454e 116int moxie_cpu_handle_mmu_fault(CPUState *cs, vaddr address,
525bd324
AG
117 int rw, int mmu_idx)
118{
7510454e
AF
119 MoxieCPU *cpu = MOXIE_CPU(cs);
120 CPUMoxieState *env = &cpu->env;
525bd324
AG
121 MoxieMMUResult res;
122 int prot, miss;
123 target_ulong phy;
124 int r = 1;
125
126 address &= TARGET_PAGE_MASK;
127 prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
128 miss = moxie_mmu_translate(&res, env, address, rw, mmu_idx);
129 if (miss) {
130 /* handle the miss. */
131 phy = 0;
27103424 132 cs->exception_index = MOXIE_EX_MMU_MISS;
525bd324
AG
133 } else {
134 phy = res.phy;
135 r = 0;
136 }
0c591eb0 137 tlb_set_page(cs, address, phy, prot, mmu_idx, TARGET_PAGE_SIZE);
525bd324
AG
138 return r;
139}
140
141
53574064 142void moxie_cpu_do_interrupt(CPUState *cs)
525bd324 143{
27103424 144 switch (cs->exception_index) {
525bd324
AG
145 case MOXIE_EX_BREAK:
146 break;
147 default:
148 break;
149 }
150}
151
00b941e5 152hwaddr moxie_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
525bd324 153{
00b941e5 154 MoxieCPU *cpu = MOXIE_CPU(cs);
525bd324
AG
155 uint32_t phy = addr;
156 MoxieMMUResult res;
157 int miss;
00b941e5
AF
158
159 miss = moxie_mmu_translate(&res, &cpu->env, addr, 0, 0);
525bd324
AG
160 if (!miss) {
161 phy = res.phy;
162 }
163 return phy;
164}
165#endif
This page took 0.18857 seconds and 4 git commands to generate.