]>
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 | ||
b6a0aa05 | 20 | #include "qemu/osdep.h" |
10774999 | 21 | #include "cpu.h" |
2ef6175a | 22 | #include "exec/helper-proto.h" |
f08b6170 | 23 | #include "exec/cpu_ldst.h" |
10774999 BS |
24 | |
25 | /* broken thread support */ | |
26 | ||
677ef623 FK |
27 | #if defined(CONFIG_USER_ONLY) |
28 | QemuMutex global_cpu_lock; | |
10774999 BS |
29 | |
30 | void helper_lock(void) | |
31 | { | |
677ef623 | 32 | qemu_mutex_lock(&global_cpu_lock); |
10774999 BS |
33 | } |
34 | ||
35 | void helper_unlock(void) | |
36 | { | |
677ef623 | 37 | qemu_mutex_unlock(&global_cpu_lock); |
10774999 BS |
38 | } |
39 | ||
677ef623 FK |
40 | void helper_lock_init(void) |
41 | { | |
42 | qemu_mutex_init(&global_cpu_lock); | |
43 | } | |
44 | #else | |
45 | void helper_lock(void) | |
46 | { | |
47 | } | |
48 | ||
49 | void helper_unlock(void) | |
50 | { | |
51 | } | |
52 | ||
53 | void helper_lock_init(void) | |
54 | { | |
55 | } | |
56 | #endif | |
57 | ||
92fc4b58 | 58 | void helper_cmpxchg8b(CPUX86State *env, target_ulong a0) |
10774999 BS |
59 | { |
60 | uint64_t d; | |
61 | int eflags; | |
62 | ||
f0967a1a | 63 | eflags = cpu_cc_compute_all(env, CC_OP); |
2afbdf84 | 64 | d = cpu_ldq_data_ra(env, a0, GETPC()); |
00f5e6f2 | 65 | if (d == (((uint64_t)env->regs[R_EDX] << 32) | (uint32_t)env->regs[R_EAX])) { |
2afbdf84 PD |
66 | cpu_stq_data_ra(env, a0, ((uint64_t)env->regs[R_ECX] << 32) |
67 | | (uint32_t)env->regs[R_EBX], GETPC()); | |
10774999 BS |
68 | eflags |= CC_Z; |
69 | } else { | |
70 | /* always do the store */ | |
2afbdf84 | 71 | cpu_stq_data_ra(env, a0, d, GETPC()); |
00f5e6f2 | 72 | env->regs[R_EDX] = (uint32_t)(d >> 32); |
4b34e3ad | 73 | env->regs[R_EAX] = (uint32_t)d; |
10774999 BS |
74 | eflags &= ~CC_Z; |
75 | } | |
76 | CC_SRC = eflags; | |
77 | } | |
78 | ||
79 | #ifdef TARGET_X86_64 | |
92fc4b58 | 80 | void helper_cmpxchg16b(CPUX86State *env, target_ulong a0) |
10774999 BS |
81 | { |
82 | uint64_t d0, d1; | |
83 | int eflags; | |
84 | ||
85 | if ((a0 & 0xf) != 0) { | |
2afbdf84 | 86 | raise_exception_ra(env, EXCP0D_GPF, GETPC()); |
10774999 | 87 | } |
f0967a1a | 88 | eflags = cpu_cc_compute_all(env, CC_OP); |
2afbdf84 PD |
89 | d0 = cpu_ldq_data_ra(env, a0, GETPC()); |
90 | d1 = cpu_ldq_data_ra(env, a0 + 8, GETPC()); | |
00f5e6f2 | 91 | if (d0 == env->regs[R_EAX] && d1 == env->regs[R_EDX]) { |
2afbdf84 PD |
92 | cpu_stq_data_ra(env, a0, env->regs[R_EBX], GETPC()); |
93 | cpu_stq_data_ra(env, a0 + 8, env->regs[R_ECX], GETPC()); | |
10774999 BS |
94 | eflags |= CC_Z; |
95 | } else { | |
96 | /* always do the store */ | |
2afbdf84 PD |
97 | cpu_stq_data_ra(env, a0, d0, GETPC()); |
98 | cpu_stq_data_ra(env, a0 + 8, d1, GETPC()); | |
00f5e6f2 | 99 | env->regs[R_EDX] = d1; |
4b34e3ad | 100 | env->regs[R_EAX] = d0; |
10774999 BS |
101 | eflags &= ~CC_Z; |
102 | } | |
103 | CC_SRC = eflags; | |
104 | } | |
105 | #endif | |
106 | ||
92fc4b58 | 107 | void helper_boundw(CPUX86State *env, target_ulong a0, int v) |
10774999 BS |
108 | { |
109 | int low, high; | |
110 | ||
2afbdf84 PD |
111 | low = cpu_ldsw_data_ra(env, a0, GETPC()); |
112 | high = cpu_ldsw_data_ra(env, a0 + 2, GETPC()); | |
10774999 BS |
113 | v = (int16_t)v; |
114 | if (v < low || v > high) { | |
75d14edc RH |
115 | if (env->hflags & HF_MPX_EN_MASK) { |
116 | env->bndcs_regs.sts = 0; | |
117 | } | |
2afbdf84 | 118 | raise_exception_ra(env, EXCP05_BOUND, GETPC()); |
10774999 BS |
119 | } |
120 | } | |
121 | ||
92fc4b58 | 122 | void helper_boundl(CPUX86State *env, target_ulong a0, int v) |
10774999 BS |
123 | { |
124 | int low, high; | |
125 | ||
2afbdf84 PD |
126 | low = cpu_ldl_data_ra(env, a0, GETPC()); |
127 | high = cpu_ldl_data_ra(env, a0 + 4, GETPC()); | |
10774999 | 128 | if (v < low || v > high) { |
75d14edc RH |
129 | if (env->hflags & HF_MPX_EN_MASK) { |
130 | env->bndcs_regs.sts = 0; | |
131 | } | |
2afbdf84 | 132 | raise_exception_ra(env, EXCP05_BOUND, GETPC()); |
10774999 BS |
133 | } |
134 | } | |
135 | ||
10774999 BS |
136 | #if !defined(CONFIG_USER_ONLY) |
137 | /* try to fill the TLB and return an exception if error. If retaddr is | |
d5a11fef AF |
138 | * NULL, it means that the function was called in C code (i.e. not |
139 | * from generated code or from helper.c) | |
140 | */ | |
10774999 | 141 | /* XXX: fix it to restore all registers */ |
d5a11fef | 142 | void tlb_fill(CPUState *cs, target_ulong addr, int is_write, int mmu_idx, |
10774999 BS |
143 | uintptr_t retaddr) |
144 | { | |
10774999 | 145 | int ret; |
10774999 | 146 | |
27103424 | 147 | ret = x86_cpu_handle_mmu_fault(cs, addr, is_write, mmu_idx); |
10774999 | 148 | if (ret) { |
d5a11fef AF |
149 | X86CPU *cpu = X86_CPU(cs); |
150 | CPUX86State *env = &cpu->env; | |
151 | ||
2afbdf84 | 152 | raise_exception_err_ra(env, cs->exception_index, env->error_code, retaddr); |
10774999 | 153 | } |
10774999 BS |
154 | } |
155 | #endif |