xref: /openbmc/qemu/target/i386/helper.c (revision cd617484)
1 /*
2  *  i386 helpers (without register variable usage)
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.1 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 "qemu/osdep.h"
21 #include "qapi/qapi-events-run-state.h"
22 #include "cpu.h"
23 #include "exec/exec-all.h"
24 #include "sysemu/runstate.h"
25 #include "kvm/kvm_i386.h"
26 #ifndef CONFIG_USER_ONLY
27 #include "sysemu/hw_accel.h"
28 #include "monitor/monitor.h"
29 #endif
30 #include "qemu/log.h"
31 
32 void cpu_sync_bndcs_hflags(CPUX86State *env)
33 {
34     uint32_t hflags = env->hflags;
35     uint32_t hflags2 = env->hflags2;
36     uint32_t bndcsr;
37 
38     if ((hflags & HF_CPL_MASK) == 3) {
39         bndcsr = env->bndcs_regs.cfgu;
40     } else {
41         bndcsr = env->msr_bndcfgs;
42     }
43 
44     if ((env->cr[4] & CR4_OSXSAVE_MASK)
45         && (env->xcr0 & XSTATE_BNDCSR_MASK)
46         && (bndcsr & BNDCFG_ENABLE)) {
47         hflags |= HF_MPX_EN_MASK;
48     } else {
49         hflags &= ~HF_MPX_EN_MASK;
50     }
51 
52     if (bndcsr & BNDCFG_BNDPRESERVE) {
53         hflags2 |= HF2_MPX_PR_MASK;
54     } else {
55         hflags2 &= ~HF2_MPX_PR_MASK;
56     }
57 
58     env->hflags = hflags;
59     env->hflags2 = hflags2;
60 }
61 
62 static void cpu_x86_version(CPUX86State *env, int *family, int *model)
63 {
64     int cpuver = env->cpuid_version;
65 
66     if (family == NULL || model == NULL) {
67         return;
68     }
69 
70     *family = (cpuver >> 8) & 0x0f;
71     *model = ((cpuver >> 12) & 0xf0) + ((cpuver >> 4) & 0x0f);
72 }
73 
74 /* Broadcast MCA signal for processor version 06H_EH and above */
75 int cpu_x86_support_mca_broadcast(CPUX86State *env)
76 {
77     int family = 0;
78     int model = 0;
79 
80     cpu_x86_version(env, &family, &model);
81     if ((family == 6 && model >= 14) || family > 6) {
82         return 1;
83     }
84 
85     return 0;
86 }
87 
88 /***********************************************************/
89 /* x86 mmu */
90 /* XXX: add PGE support */
91 
92 void x86_cpu_set_a20(X86CPU *cpu, int a20_state)
93 {
94     CPUX86State *env = &cpu->env;
95 
96     a20_state = (a20_state != 0);
97     if (a20_state != ((env->a20_mask >> 20) & 1)) {
98         CPUState *cs = CPU(cpu);
99 
100         qemu_log_mask(CPU_LOG_MMU, "A20 update: a20=%d\n", a20_state);
101         /* if the cpu is currently executing code, we must unlink it and
102            all the potentially executing TB */
103         cpu_interrupt(cs, CPU_INTERRUPT_EXITTB);
104 
105         /* when a20 is changed, all the MMU mappings are invalid, so
106            we must flush everything */
107         tlb_flush(cs);
108         env->a20_mask = ~(1 << 20) | (a20_state << 20);
109     }
110 }
111 
112 void cpu_x86_update_cr0(CPUX86State *env, uint32_t new_cr0)
113 {
114     X86CPU *cpu = env_archcpu(env);
115     int pe_state;
116 
117     qemu_log_mask(CPU_LOG_MMU, "CR0 update: CR0=0x%08x\n", new_cr0);
118     if ((new_cr0 & (CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK)) !=
119         (env->cr[0] & (CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK))) {
120         tlb_flush(CPU(cpu));
121     }
122 
123 #ifdef TARGET_X86_64
124     if (!(env->cr[0] & CR0_PG_MASK) && (new_cr0 & CR0_PG_MASK) &&
125         (env->efer & MSR_EFER_LME)) {
126         /* enter in long mode */
127         /* XXX: generate an exception */
128         if (!(env->cr[4] & CR4_PAE_MASK))
129             return;
130         env->efer |= MSR_EFER_LMA;
131         env->hflags |= HF_LMA_MASK;
132     } else if ((env->cr[0] & CR0_PG_MASK) && !(new_cr0 & CR0_PG_MASK) &&
133                (env->efer & MSR_EFER_LMA)) {
134         /* exit long mode */
135         env->efer &= ~MSR_EFER_LMA;
136         env->hflags &= ~(HF_LMA_MASK | HF_CS64_MASK);
137         env->eip &= 0xffffffff;
138     }
139 #endif
140     env->cr[0] = new_cr0 | CR0_ET_MASK;
141 
142     /* update PE flag in hidden flags */
143     pe_state = (env->cr[0] & CR0_PE_MASK);
144     env->hflags = (env->hflags & ~HF_PE_MASK) | (pe_state << HF_PE_SHIFT);
145     /* ensure that ADDSEG is always set in real mode */
146     env->hflags |= ((pe_state ^ 1) << HF_ADDSEG_SHIFT);
147     /* update FPU flags */
148     env->hflags = (env->hflags & ~(HF_MP_MASK | HF_EM_MASK | HF_TS_MASK)) |
149         ((new_cr0 << (HF_MP_SHIFT - 1)) & (HF_MP_MASK | HF_EM_MASK | HF_TS_MASK));
150 }
151 
152 /* XXX: in legacy PAE mode, generate a GPF if reserved bits are set in
153    the PDPT */
154 void cpu_x86_update_cr3(CPUX86State *env, target_ulong new_cr3)
155 {
156     env->cr[3] = new_cr3;
157     if (env->cr[0] & CR0_PG_MASK) {
158         qemu_log_mask(CPU_LOG_MMU,
159                         "CR3 update: CR3=" TARGET_FMT_lx "\n", new_cr3);
160         tlb_flush(env_cpu(env));
161     }
162 }
163 
164 void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4)
165 {
166     uint32_t hflags;
167 
168 #if defined(DEBUG_MMU)
169     printf("CR4 update: %08x -> %08x\n", (uint32_t)env->cr[4], new_cr4);
170 #endif
171     if ((new_cr4 ^ env->cr[4]) &
172         (CR4_PGE_MASK | CR4_PAE_MASK | CR4_PSE_MASK |
173          CR4_SMEP_MASK | CR4_SMAP_MASK | CR4_LA57_MASK)) {
174         tlb_flush(env_cpu(env));
175     }
176 
177     /* Clear bits we're going to recompute.  */
178     hflags = env->hflags & ~(HF_OSFXSR_MASK | HF_SMAP_MASK);
179 
180     /* SSE handling */
181     if (!(env->features[FEAT_1_EDX] & CPUID_SSE)) {
182         new_cr4 &= ~CR4_OSFXSR_MASK;
183     }
184     if (new_cr4 & CR4_OSFXSR_MASK) {
185         hflags |= HF_OSFXSR_MASK;
186     }
187 
188     if (!(env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_SMAP)) {
189         new_cr4 &= ~CR4_SMAP_MASK;
190     }
191     if (new_cr4 & CR4_SMAP_MASK) {
192         hflags |= HF_SMAP_MASK;
193     }
194 
195     if (!(env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_PKU)) {
196         new_cr4 &= ~CR4_PKE_MASK;
197     }
198     if (!(env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_PKS)) {
199         new_cr4 &= ~CR4_PKS_MASK;
200     }
201 
202     env->cr[4] = new_cr4;
203     env->hflags = hflags;
204 
205     cpu_sync_bndcs_hflags(env);
206 }
207 
208 #if !defined(CONFIG_USER_ONLY)
209 hwaddr x86_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr,
210                                          MemTxAttrs *attrs)
211 {
212     X86CPU *cpu = X86_CPU(cs);
213     CPUX86State *env = &cpu->env;
214     target_ulong pde_addr, pte_addr;
215     uint64_t pte;
216     int32_t a20_mask;
217     uint32_t page_offset;
218     int page_size;
219 
220     *attrs = cpu_get_mem_attrs(env);
221 
222     a20_mask = x86_get_a20_mask(env);
223     if (!(env->cr[0] & CR0_PG_MASK)) {
224         pte = addr & a20_mask;
225         page_size = 4096;
226     } else if (env->cr[4] & CR4_PAE_MASK) {
227         target_ulong pdpe_addr;
228         uint64_t pde, pdpe;
229 
230 #ifdef TARGET_X86_64
231         if (env->hflags & HF_LMA_MASK) {
232             bool la57 = env->cr[4] & CR4_LA57_MASK;
233             uint64_t pml5e_addr, pml5e;
234             uint64_t pml4e_addr, pml4e;
235             int32_t sext;
236 
237             /* test virtual address sign extension */
238             sext = la57 ? (int64_t)addr >> 56 : (int64_t)addr >> 47;
239             if (sext != 0 && sext != -1) {
240                 return -1;
241             }
242 
243             if (la57) {
244                 pml5e_addr = ((env->cr[3] & ~0xfff) +
245                         (((addr >> 48) & 0x1ff) << 3)) & a20_mask;
246                 pml5e = x86_ldq_phys(cs, pml5e_addr);
247                 if (!(pml5e & PG_PRESENT_MASK)) {
248                     return -1;
249                 }
250             } else {
251                 pml5e = env->cr[3];
252             }
253 
254             pml4e_addr = ((pml5e & PG_ADDRESS_MASK) +
255                     (((addr >> 39) & 0x1ff) << 3)) & a20_mask;
256             pml4e = x86_ldq_phys(cs, pml4e_addr);
257             if (!(pml4e & PG_PRESENT_MASK)) {
258                 return -1;
259             }
260             pdpe_addr = ((pml4e & PG_ADDRESS_MASK) +
261                          (((addr >> 30) & 0x1ff) << 3)) & a20_mask;
262             pdpe = x86_ldq_phys(cs, pdpe_addr);
263             if (!(pdpe & PG_PRESENT_MASK)) {
264                 return -1;
265             }
266             if (pdpe & PG_PSE_MASK) {
267                 page_size = 1024 * 1024 * 1024;
268                 pte = pdpe;
269                 goto out;
270             }
271 
272         } else
273 #endif
274         {
275             pdpe_addr = ((env->cr[3] & ~0x1f) + ((addr >> 27) & 0x18)) &
276                 a20_mask;
277             pdpe = x86_ldq_phys(cs, pdpe_addr);
278             if (!(pdpe & PG_PRESENT_MASK))
279                 return -1;
280         }
281 
282         pde_addr = ((pdpe & PG_ADDRESS_MASK) +
283                     (((addr >> 21) & 0x1ff) << 3)) & a20_mask;
284         pde = x86_ldq_phys(cs, pde_addr);
285         if (!(pde & PG_PRESENT_MASK)) {
286             return -1;
287         }
288         if (pde & PG_PSE_MASK) {
289             /* 2 MB page */
290             page_size = 2048 * 1024;
291             pte = pde;
292         } else {
293             /* 4 KB page */
294             pte_addr = ((pde & PG_ADDRESS_MASK) +
295                         (((addr >> 12) & 0x1ff) << 3)) & a20_mask;
296             page_size = 4096;
297             pte = x86_ldq_phys(cs, pte_addr);
298         }
299         if (!(pte & PG_PRESENT_MASK)) {
300             return -1;
301         }
302     } else {
303         uint32_t pde;
304 
305         /* page directory entry */
306         pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) & a20_mask;
307         pde = x86_ldl_phys(cs, pde_addr);
308         if (!(pde & PG_PRESENT_MASK))
309             return -1;
310         if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
311             pte = pde | ((pde & 0x1fe000LL) << (32 - 13));
312             page_size = 4096 * 1024;
313         } else {
314             /* page directory entry */
315             pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & a20_mask;
316             pte = x86_ldl_phys(cs, pte_addr);
317             if (!(pte & PG_PRESENT_MASK)) {
318                 return -1;
319             }
320             page_size = 4096;
321         }
322         pte = pte & a20_mask;
323     }
324 
325 #ifdef TARGET_X86_64
326 out:
327 #endif
328     pte &= PG_ADDRESS_MASK & ~(page_size - 1);
329     page_offset = (addr & TARGET_PAGE_MASK) & (page_size - 1);
330     return pte | page_offset;
331 }
332 
333 typedef struct MCEInjectionParams {
334     Monitor *mon;
335     int bank;
336     uint64_t status;
337     uint64_t mcg_status;
338     uint64_t addr;
339     uint64_t misc;
340     int flags;
341 } MCEInjectionParams;
342 
343 static void emit_guest_memory_failure(MemoryFailureAction action, bool ar,
344                                       bool recursive)
345 {
346     MemoryFailureFlags mff = {.action_required = ar, .recursive = recursive};
347 
348     qapi_event_send_memory_failure(MEMORY_FAILURE_RECIPIENT_GUEST, action,
349                                    &mff);
350 }
351 
352 static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
353 {
354     MCEInjectionParams *params = data.host_ptr;
355     X86CPU *cpu = X86_CPU(cs);
356     CPUX86State *cenv = &cpu->env;
357     uint64_t *banks = cenv->mce_banks + 4 * params->bank;
358     g_autofree char *msg = NULL;
359     bool need_reset = false;
360     bool recursive;
361     bool ar = !!(params->status & MCI_STATUS_AR);
362 
363     cpu_synchronize_state(cs);
364     recursive = !!(cenv->mcg_status & MCG_STATUS_MCIP);
365 
366     /*
367      * If there is an MCE exception being processed, ignore this SRAO MCE
368      * unless unconditional injection was requested.
369      */
370     if (!(params->flags & MCE_INJECT_UNCOND_AO) && !ar && recursive) {
371         emit_guest_memory_failure(MEMORY_FAILURE_ACTION_IGNORE, ar, recursive);
372         return;
373     }
374 
375     if (params->status & MCI_STATUS_UC) {
376         /*
377          * if MSR_MCG_CTL is not all 1s, the uncorrected error
378          * reporting is disabled
379          */
380         if ((cenv->mcg_cap & MCG_CTL_P) && cenv->mcg_ctl != ~(uint64_t)0) {
381             monitor_printf(params->mon,
382                            "CPU %d: Uncorrected error reporting disabled\n",
383                            cs->cpu_index);
384             return;
385         }
386 
387         /*
388          * if MSR_MCi_CTL is not all 1s, the uncorrected error
389          * reporting is disabled for the bank
390          */
391         if (banks[0] != ~(uint64_t)0) {
392             monitor_printf(params->mon,
393                            "CPU %d: Uncorrected error reporting disabled for"
394                            " bank %d\n",
395                            cs->cpu_index, params->bank);
396             return;
397         }
398 
399         if (!(cenv->cr[4] & CR4_MCE_MASK)) {
400             need_reset = true;
401             msg = g_strdup_printf("CPU %d: MCE capability is not enabled, "
402                                   "raising triple fault", cs->cpu_index);
403         } else if (recursive) {
404             need_reset = true;
405             msg = g_strdup_printf("CPU %d: Previous MCE still in progress, "
406                                   "raising triple fault", cs->cpu_index);
407         }
408 
409         if (need_reset) {
410             emit_guest_memory_failure(MEMORY_FAILURE_ACTION_RESET, ar,
411                                       recursive);
412             monitor_printf(params->mon, "%s", msg);
413             qemu_log_mask(CPU_LOG_RESET, "%s\n", msg);
414             qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
415             return;
416         }
417 
418         if (banks[1] & MCI_STATUS_VAL) {
419             params->status |= MCI_STATUS_OVER;
420         }
421         banks[2] = params->addr;
422         banks[3] = params->misc;
423         cenv->mcg_status = params->mcg_status;
424         banks[1] = params->status;
425         cpu_interrupt(cs, CPU_INTERRUPT_MCE);
426     } else if (!(banks[1] & MCI_STATUS_VAL)
427                || !(banks[1] & MCI_STATUS_UC)) {
428         if (banks[1] & MCI_STATUS_VAL) {
429             params->status |= MCI_STATUS_OVER;
430         }
431         banks[2] = params->addr;
432         banks[3] = params->misc;
433         banks[1] = params->status;
434     } else {
435         banks[1] |= MCI_STATUS_OVER;
436     }
437 
438     emit_guest_memory_failure(MEMORY_FAILURE_ACTION_INJECT, ar, recursive);
439 }
440 
441 void cpu_x86_inject_mce(Monitor *mon, X86CPU *cpu, int bank,
442                         uint64_t status, uint64_t mcg_status, uint64_t addr,
443                         uint64_t misc, int flags)
444 {
445     CPUState *cs = CPU(cpu);
446     CPUX86State *cenv = &cpu->env;
447     MCEInjectionParams params = {
448         .mon = mon,
449         .bank = bank,
450         .status = status,
451         .mcg_status = mcg_status,
452         .addr = addr,
453         .misc = misc,
454         .flags = flags,
455     };
456     unsigned bank_num = cenv->mcg_cap & 0xff;
457 
458     if (!cenv->mcg_cap) {
459         monitor_printf(mon, "MCE injection not supported\n");
460         return;
461     }
462     if (bank >= bank_num) {
463         monitor_printf(mon, "Invalid MCE bank number\n");
464         return;
465     }
466     if (!(status & MCI_STATUS_VAL)) {
467         monitor_printf(mon, "Invalid MCE status code\n");
468         return;
469     }
470     if ((flags & MCE_INJECT_BROADCAST)
471         && !cpu_x86_support_mca_broadcast(cenv)) {
472         monitor_printf(mon, "Guest CPU does not support MCA broadcast\n");
473         return;
474     }
475 
476     run_on_cpu(cs, do_inject_x86_mce, RUN_ON_CPU_HOST_PTR(&params));
477     if (flags & MCE_INJECT_BROADCAST) {
478         CPUState *other_cs;
479 
480         params.bank = 1;
481         params.status = MCI_STATUS_VAL | MCI_STATUS_UC;
482         params.mcg_status = MCG_STATUS_MCIP | MCG_STATUS_RIPV;
483         params.addr = 0;
484         params.misc = 0;
485         CPU_FOREACH(other_cs) {
486             if (other_cs == cs) {
487                 continue;
488             }
489             run_on_cpu(other_cs, do_inject_x86_mce, RUN_ON_CPU_HOST_PTR(&params));
490         }
491     }
492 }
493 
494 void cpu_report_tpr_access(CPUX86State *env, TPRAccess access)
495 {
496     X86CPU *cpu = env_archcpu(env);
497     CPUState *cs = env_cpu(env);
498 
499     if (kvm_enabled() || whpx_enabled() || nvmm_enabled()) {
500         env->tpr_access_type = access;
501 
502         cpu_interrupt(cs, CPU_INTERRUPT_TPR);
503     } else if (tcg_enabled()) {
504         cpu_restore_state(cs, cs->mem_io_pc, false);
505 
506         apic_handle_tpr_access_report(cpu->apic_state, env->eip, access);
507     }
508 }
509 #endif /* !CONFIG_USER_ONLY */
510 
511 int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector,
512                             target_ulong *base, unsigned int *limit,
513                             unsigned int *flags)
514 {
515     CPUState *cs = env_cpu(env);
516     SegmentCache *dt;
517     target_ulong ptr;
518     uint32_t e1, e2;
519     int index;
520 
521     if (selector & 0x4)
522         dt = &env->ldt;
523     else
524         dt = &env->gdt;
525     index = selector & ~7;
526     ptr = dt->base + index;
527     if ((index + 7) > dt->limit
528         || cpu_memory_rw_debug(cs, ptr, (uint8_t *)&e1, sizeof(e1), 0) != 0
529         || cpu_memory_rw_debug(cs, ptr+4, (uint8_t *)&e2, sizeof(e2), 0) != 0)
530         return 0;
531 
532     *base = ((e1 >> 16) | ((e2 & 0xff) << 16) | (e2 & 0xff000000));
533     *limit = (e1 & 0xffff) | (e2 & 0x000f0000);
534     if (e2 & DESC_G_MASK)
535         *limit = (*limit << 12) | 0xfff;
536     *flags = e2;
537 
538     return 1;
539 }
540 
541 #if !defined(CONFIG_USER_ONLY)
542 void do_cpu_init(X86CPU *cpu)
543 {
544     CPUState *cs = CPU(cpu);
545     CPUX86State *env = &cpu->env;
546     CPUX86State *save = g_new(CPUX86State, 1);
547     int sipi = cs->interrupt_request & CPU_INTERRUPT_SIPI;
548 
549     *save = *env;
550 
551     cpu_reset(cs);
552     cs->interrupt_request = sipi;
553     memcpy(&env->start_init_save, &save->start_init_save,
554            offsetof(CPUX86State, end_init_save) -
555            offsetof(CPUX86State, start_init_save));
556     g_free(save);
557 
558     if (kvm_enabled()) {
559         kvm_arch_do_init_vcpu(cpu);
560     }
561     apic_init_reset(cpu->apic_state);
562 }
563 
564 void do_cpu_sipi(X86CPU *cpu)
565 {
566     apic_sipi(cpu->apic_state);
567 }
568 #else
569 void do_cpu_init(X86CPU *cpu)
570 {
571 }
572 void do_cpu_sipi(X86CPU *cpu)
573 {
574 }
575 #endif
576 
577 #ifndef CONFIG_USER_ONLY
578 
579 void cpu_load_efer(CPUX86State *env, uint64_t val)
580 {
581     env->efer = val;
582     env->hflags &= ~(HF_LMA_MASK | HF_SVME_MASK);
583     if (env->efer & MSR_EFER_LMA) {
584         env->hflags |= HF_LMA_MASK;
585     }
586     if (env->efer & MSR_EFER_SVME) {
587         env->hflags |= HF_SVME_MASK;
588     }
589 }
590 
591 uint8_t x86_ldub_phys(CPUState *cs, hwaddr addr)
592 {
593     X86CPU *cpu = X86_CPU(cs);
594     CPUX86State *env = &cpu->env;
595     MemTxAttrs attrs = cpu_get_mem_attrs(env);
596     AddressSpace *as = cpu_addressspace(cs, attrs);
597 
598     return address_space_ldub(as, addr, attrs, NULL);
599 }
600 
601 uint32_t x86_lduw_phys(CPUState *cs, hwaddr addr)
602 {
603     X86CPU *cpu = X86_CPU(cs);
604     CPUX86State *env = &cpu->env;
605     MemTxAttrs attrs = cpu_get_mem_attrs(env);
606     AddressSpace *as = cpu_addressspace(cs, attrs);
607 
608     return address_space_lduw(as, addr, attrs, NULL);
609 }
610 
611 uint32_t x86_ldl_phys(CPUState *cs, hwaddr addr)
612 {
613     X86CPU *cpu = X86_CPU(cs);
614     CPUX86State *env = &cpu->env;
615     MemTxAttrs attrs = cpu_get_mem_attrs(env);
616     AddressSpace *as = cpu_addressspace(cs, attrs);
617 
618     return address_space_ldl(as, addr, attrs, NULL);
619 }
620 
621 uint64_t x86_ldq_phys(CPUState *cs, hwaddr addr)
622 {
623     X86CPU *cpu = X86_CPU(cs);
624     CPUX86State *env = &cpu->env;
625     MemTxAttrs attrs = cpu_get_mem_attrs(env);
626     AddressSpace *as = cpu_addressspace(cs, attrs);
627 
628     return address_space_ldq(as, addr, attrs, NULL);
629 }
630 
631 void x86_stb_phys(CPUState *cs, hwaddr addr, uint8_t val)
632 {
633     X86CPU *cpu = X86_CPU(cs);
634     CPUX86State *env = &cpu->env;
635     MemTxAttrs attrs = cpu_get_mem_attrs(env);
636     AddressSpace *as = cpu_addressspace(cs, attrs);
637 
638     address_space_stb(as, addr, val, attrs, NULL);
639 }
640 
641 void x86_stl_phys_notdirty(CPUState *cs, hwaddr addr, uint32_t val)
642 {
643     X86CPU *cpu = X86_CPU(cs);
644     CPUX86State *env = &cpu->env;
645     MemTxAttrs attrs = cpu_get_mem_attrs(env);
646     AddressSpace *as = cpu_addressspace(cs, attrs);
647 
648     address_space_stl_notdirty(as, addr, val, attrs, NULL);
649 }
650 
651 void x86_stw_phys(CPUState *cs, hwaddr addr, uint32_t val)
652 {
653     X86CPU *cpu = X86_CPU(cs);
654     CPUX86State *env = &cpu->env;
655     MemTxAttrs attrs = cpu_get_mem_attrs(env);
656     AddressSpace *as = cpu_addressspace(cs, attrs);
657 
658     address_space_stw(as, addr, val, attrs, NULL);
659 }
660 
661 void x86_stl_phys(CPUState *cs, hwaddr addr, uint32_t val)
662 {
663     X86CPU *cpu = X86_CPU(cs);
664     CPUX86State *env = &cpu->env;
665     MemTxAttrs attrs = cpu_get_mem_attrs(env);
666     AddressSpace *as = cpu_addressspace(cs, attrs);
667 
668     address_space_stl(as, addr, val, attrs, NULL);
669 }
670 
671 void x86_stq_phys(CPUState *cs, hwaddr addr, uint64_t val)
672 {
673     X86CPU *cpu = X86_CPU(cs);
674     CPUX86State *env = &cpu->env;
675     MemTxAttrs attrs = cpu_get_mem_attrs(env);
676     AddressSpace *as = cpu_addressspace(cs, attrs);
677 
678     address_space_stq(as, addr, val, attrs, NULL);
679 }
680 #endif
681