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