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