exec: Make ldl_*_phys input an AddressSpace
[qemu.git] / target-alpha / mem_helper.c
1 /*
2 * Helpers for loads and stores
3 *
4 * Copyright (c) 2007 Jocelyn Mayer
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
20 #include "cpu.h"
21 #include "helper.h"
22
23
24 /* Softmmu support */
25 #ifndef CONFIG_USER_ONLY
26
27 uint64_t helper_ldl_phys(CPUAlphaState *env, uint64_t p)
28 {
29 CPUState *cs = ENV_GET_CPU(env);
30 return (int32_t)ldl_phys(cs->as, p);
31 }
32
33 uint64_t helper_ldq_phys(uint64_t p)
34 {
35 return ldq_phys(p);
36 }
37
38 uint64_t helper_ldl_l_phys(CPUAlphaState *env, uint64_t p)
39 {
40 CPUState *cs = ENV_GET_CPU(env);
41 env->lock_addr = p;
42 return env->lock_value = (int32_t)ldl_phys(cs->as, p);
43 }
44
45 uint64_t helper_ldq_l_phys(CPUAlphaState *env, uint64_t p)
46 {
47 env->lock_addr = p;
48 return env->lock_value = ldq_phys(p);
49 }
50
51 void helper_stl_phys(uint64_t p, uint64_t v)
52 {
53 stl_phys(p, v);
54 }
55
56 void helper_stq_phys(uint64_t p, uint64_t v)
57 {
58 stq_phys(p, v);
59 }
60
61 uint64_t helper_stl_c_phys(CPUAlphaState *env, uint64_t p, uint64_t v)
62 {
63 CPUState *cs = ENV_GET_CPU(env);
64 uint64_t ret = 0;
65
66 if (p == env->lock_addr) {
67 int32_t old = ldl_phys(cs->as, p);
68 if (old == (int32_t)env->lock_value) {
69 stl_phys(p, v);
70 ret = 1;
71 }
72 }
73 env->lock_addr = -1;
74
75 return ret;
76 }
77
78 uint64_t helper_stq_c_phys(CPUAlphaState *env, uint64_t p, uint64_t v)
79 {
80 uint64_t ret = 0;
81
82 if (p == env->lock_addr) {
83 uint64_t old = ldq_phys(p);
84 if (old == env->lock_value) {
85 stq_phys(p, v);
86 ret = 1;
87 }
88 }
89 env->lock_addr = -1;
90
91 return ret;
92 }
93
94 static void do_unaligned_access(CPUAlphaState *env, target_ulong addr,
95 int is_write, int is_user, uintptr_t retaddr)
96 {
97 uint64_t pc;
98 uint32_t insn;
99
100 if (retaddr) {
101 cpu_restore_state(env, retaddr);
102 }
103
104 pc = env->pc;
105 insn = cpu_ldl_code(env, pc);
106
107 env->trap_arg0 = addr;
108 env->trap_arg1 = insn >> 26; /* opcode */
109 env->trap_arg2 = (insn >> 21) & 31; /* dest regno */
110 env->exception_index = EXCP_UNALIGN;
111 env->error_code = 0;
112 cpu_loop_exit(env);
113 }
114
115 void alpha_cpu_unassigned_access(CPUState *cs, hwaddr addr,
116 bool is_write, bool is_exec, int unused,
117 unsigned size)
118 {
119 AlphaCPU *cpu = ALPHA_CPU(cs);
120 CPUAlphaState *env = &cpu->env;
121
122 env->trap_arg0 = addr;
123 env->trap_arg1 = is_write ? 1 : 0;
124 dynamic_excp(env, 0, EXCP_MCHK, 0);
125 }
126
127 #include "exec/softmmu_exec.h"
128
129 #define MMUSUFFIX _mmu
130 #define ALIGNED_ONLY
131
132 #define SHIFT 0
133 #include "exec/softmmu_template.h"
134
135 #define SHIFT 1
136 #include "exec/softmmu_template.h"
137
138 #define SHIFT 2
139 #include "exec/softmmu_template.h"
140
141 #define SHIFT 3
142 #include "exec/softmmu_template.h"
143
144 /* try to fill the TLB and return an exception if error. If retaddr is
145 NULL, it means that the function was called in C code (i.e. not
146 from generated code or from helper.c) */
147 /* XXX: fix it to restore all registers */
148 void tlb_fill(CPUAlphaState *env, target_ulong addr, int is_write,
149 int mmu_idx, uintptr_t retaddr)
150 {
151 int ret;
152
153 ret = cpu_alpha_handle_mmu_fault(env, addr, is_write, mmu_idx);
154 if (unlikely(ret != 0)) {
155 if (retaddr) {
156 cpu_restore_state(env, retaddr);
157 }
158 /* Exception index and error code are already set */
159 cpu_loop_exit(env);
160 }
161 }
162 #endif /* CONFIG_USER_ONLY */