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
);