2 * x86 memory access helpers
4 * Copyright (c) 2003 Fabrice Bellard
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 Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include "dyngen-exec.h"
24 #if !defined(CONFIG_USER_ONLY)
25 #include "softmmu_exec.h"
26 #endif /* !defined(CONFIG_USER_ONLY) */
28 /* broken thread support */
30 static spinlock_t global_cpu_lock = SPIN_LOCK_UNLOCKED;
32 void helper_lock(void)
34 spin_lock(&global_cpu_lock);
37 void helper_unlock(void)
39 spin_unlock(&global_cpu_lock);
42 void helper_cmpxchg8b(target_ulong a0)
47 eflags = helper_cc_compute_all(CC_OP);
49 if (d == (((uint64_t)EDX << 32) | (uint32_t)EAX)) {
50 stq(a0, ((uint64_t)ECX << 32) | (uint32_t)EBX);
53 /* always do the store */
55 EDX = (uint32_t)(d >> 32);
63 void helper_cmpxchg16b(target_ulong a0)
68 if ((a0 & 0xf) != 0) {
69 raise_exception(env, EXCP0D_GPF);
71 eflags = helper_cc_compute_all(CC_OP);
74 if (d0 == EAX && d1 == EDX) {
79 /* always do the store */
90 void helper_boundw(target_ulong a0, int v)
97 if (v < low || v > high) {
98 raise_exception(env, EXCP05_BOUND);
102 void helper_boundl(target_ulong a0, int v)
108 if (v < low || v > high) {
109 raise_exception(env, EXCP05_BOUND);
113 #if !defined(CONFIG_USER_ONLY)
115 #define MMUSUFFIX _mmu
118 #include "softmmu_template.h"
121 #include "softmmu_template.h"
124 #include "softmmu_template.h"
127 #include "softmmu_template.h"
131 #if !defined(CONFIG_USER_ONLY)
132 /* try to fill the TLB and return an exception if error. If retaddr is
133 NULL, it means that the function was called in C code (i.e. not
134 from generated code or from helper.c) */
135 /* XXX: fix it to restore all registers */
136 void tlb_fill(CPUX86State *env1, target_ulong addr, int is_write, int mmu_idx,
139 TranslationBlock *tb;
141 CPUX86State *saved_env;
146 ret = cpu_x86_handle_mmu_fault(env, addr, is_write, mmu_idx);
149 /* now we have a real cpu fault */
150 tb = tb_find_pc(retaddr);
152 /* the PC is inside the translated code. It means that we have
153 a virtual CPU fault */
154 cpu_restore_state(tb, env, retaddr);
157 raise_exception_err(env, env->exception_index, env->error_code);
163 /* temporary wrappers */
164 #if defined(CONFIG_USER_ONLY)
165 #define ldub_data(addr) ldub_raw(addr)
166 #define lduw_data(addr) lduw_raw(addr)
167 #define ldl_data(addr) ldl_raw(addr)
168 #define ldq_data(addr) ldq_raw(addr)
170 #define stb_data(addr, data) stb_raw(addr, data)
171 #define stw_data(addr, data) stw_raw(addr, data)
172 #define stl_data(addr, data) stl_raw(addr, data)
173 #define stq_data(addr, data) stq_raw(addr, data)
176 #define WRAP_LD(rettype, fn) \
177 rettype cpu_ ## fn(CPUX86State *env1, target_ulong addr) \
179 CPUX86State *saved_env; \
189 WRAP_LD(uint32_t, ldub_data)
190 WRAP_LD(uint32_t, lduw_data)
191 WRAP_LD(uint32_t, ldl_data)
192 WRAP_LD(uint64_t, ldq_data)
195 #define WRAP_ST(datatype, fn) \
196 void cpu_ ## fn(CPUX86State *env1, target_ulong addr, datatype val) \
198 CPUX86State *saved_env; \
206 WRAP_ST(uint32_t, stb_data)
207 WRAP_ST(uint32_t, stw_data)
208 WRAP_ST(uint32_t, stl_data)
209 WRAP_ST(uint64_t, stq_data)