]>
Commit | Line | Data |
---|---|---|
10774999 BS |
1 | /* |
2 | * x86 memory access helpers | |
3 | * | |
4 | * Copyright (c) 2003 Fabrice Bellard | |
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" | |
2ef6175a | 21 | #include "exec/helper-proto.h" |
f08b6170 | 22 | #include "exec/cpu_ldst.h" |
10774999 BS |
23 | |
24 | /* broken thread support */ | |
25 | ||
26 | static spinlock_t global_cpu_lock = SPIN_LOCK_UNLOCKED; | |
27 | ||
28 | void helper_lock(void) | |
29 | { | |
30 | spin_lock(&global_cpu_lock); | |
31 | } | |
32 | ||
33 | void helper_unlock(void) | |
34 | { | |
35 | spin_unlock(&global_cpu_lock); | |
36 | } | |
37 | ||
92fc4b58 | 38 | void helper_cmpxchg8b(CPUX86State *env, target_ulong a0) |
10774999 BS |
39 | { |
40 | uint64_t d; | |
41 | int eflags; | |
42 | ||
f0967a1a | 43 | eflags = cpu_cc_compute_all(env, CC_OP); |
92fc4b58 | 44 | d = cpu_ldq_data(env, a0); |
00f5e6f2 | 45 | if (d == (((uint64_t)env->regs[R_EDX] << 32) | (uint32_t)env->regs[R_EAX])) { |
a4165610 | 46 | cpu_stq_data(env, a0, ((uint64_t)env->regs[R_ECX] << 32) | (uint32_t)env->regs[R_EBX]); |
10774999 BS |
47 | eflags |= CC_Z; |
48 | } else { | |
49 | /* always do the store */ | |
92fc4b58 | 50 | cpu_stq_data(env, a0, d); |
00f5e6f2 | 51 | env->regs[R_EDX] = (uint32_t)(d >> 32); |
4b34e3ad | 52 | env->regs[R_EAX] = (uint32_t)d; |
10774999 BS |
53 | eflags &= ~CC_Z; |
54 | } | |
55 | CC_SRC = eflags; | |
56 | } | |
57 | ||
58 | #ifdef TARGET_X86_64 | |
92fc4b58 | 59 | void helper_cmpxchg16b(CPUX86State *env, target_ulong a0) |
10774999 BS |
60 | { |
61 | uint64_t d0, d1; | |
62 | int eflags; | |
63 | ||
64 | if ((a0 & 0xf) != 0) { | |
65 | raise_exception(env, EXCP0D_GPF); | |
66 | } | |
f0967a1a | 67 | eflags = cpu_cc_compute_all(env, CC_OP); |
92fc4b58 BS |
68 | d0 = cpu_ldq_data(env, a0); |
69 | d1 = cpu_ldq_data(env, a0 + 8); | |
00f5e6f2 | 70 | if (d0 == env->regs[R_EAX] && d1 == env->regs[R_EDX]) { |
70b51365 | 71 | cpu_stq_data(env, a0, env->regs[R_EBX]); |
a4165610 | 72 | cpu_stq_data(env, a0 + 8, env->regs[R_ECX]); |
10774999 BS |
73 | eflags |= CC_Z; |
74 | } else { | |
75 | /* always do the store */ | |
92fc4b58 BS |
76 | cpu_stq_data(env, a0, d0); |
77 | cpu_stq_data(env, a0 + 8, d1); | |
00f5e6f2 | 78 | env->regs[R_EDX] = d1; |
4b34e3ad | 79 | env->regs[R_EAX] = d0; |
10774999 BS |
80 | eflags &= ~CC_Z; |
81 | } | |
82 | CC_SRC = eflags; | |
83 | } | |
84 | #endif | |
85 | ||
92fc4b58 | 86 | void helper_boundw(CPUX86State *env, target_ulong a0, int v) |
10774999 BS |
87 | { |
88 | int low, high; | |
89 | ||
92fc4b58 BS |
90 | low = cpu_ldsw_data(env, a0); |
91 | high = cpu_ldsw_data(env, a0 + 2); | |
10774999 BS |
92 | v = (int16_t)v; |
93 | if (v < low || v > high) { | |
94 | raise_exception(env, EXCP05_BOUND); | |
95 | } | |
96 | } | |
97 | ||
92fc4b58 | 98 | void helper_boundl(CPUX86State *env, target_ulong a0, int v) |
10774999 BS |
99 | { |
100 | int low, high; | |
101 | ||
92fc4b58 BS |
102 | low = cpu_ldl_data(env, a0); |
103 | high = cpu_ldl_data(env, a0 + 4); | |
10774999 BS |
104 | if (v < low || v > high) { |
105 | raise_exception(env, EXCP05_BOUND); | |
106 | } | |
107 | } | |
108 | ||
10774999 BS |
109 | #if !defined(CONFIG_USER_ONLY) |
110 | /* try to fill the TLB and return an exception if error. If retaddr is | |
d5a11fef AF |
111 | * NULL, it means that the function was called in C code (i.e. not |
112 | * from generated code or from helper.c) | |
113 | */ | |
10774999 | 114 | /* XXX: fix it to restore all registers */ |
d5a11fef | 115 | void tlb_fill(CPUState *cs, target_ulong addr, int is_write, int mmu_idx, |
10774999 BS |
116 | uintptr_t retaddr) |
117 | { | |
10774999 | 118 | int ret; |
10774999 | 119 | |
27103424 | 120 | ret = x86_cpu_handle_mmu_fault(cs, addr, is_write, mmu_idx); |
10774999 | 121 | if (ret) { |
d5a11fef AF |
122 | X86CPU *cpu = X86_CPU(cs); |
123 | CPUX86State *env = &cpu->env; | |
124 | ||
10774999 BS |
125 | if (retaddr) { |
126 | /* now we have a real cpu fault */ | |
3f38f309 | 127 | cpu_restore_state(cs, retaddr); |
10774999 | 128 | } |
27103424 | 129 | raise_exception_err(env, cs->exception_index, env->error_code); |
10774999 | 130 | } |
10774999 BS |
131 | } |
132 | #endif |