2012-05-07 08:04:57 +04:00
|
|
|
/*
|
|
|
|
* i386 memory mapping
|
|
|
|
*
|
|
|
|
* Copyright Fujitsu, Corp. 2011, 2012
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Wen Congyang <wency@cn.fujitsu.com>
|
|
|
|
*
|
2012-06-10 23:49:18 +04:00
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
2012-05-07 08:04:57 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:03 +03:00
|
|
|
#include "qemu/osdep.h"
|
2012-05-07 08:04:57 +04:00
|
|
|
#include "cpu.h"
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/cpu-all.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/memory_mapping.h"
|
2012-05-07 08:04:57 +04:00
|
|
|
|
|
|
|
/* PAE Paging or IA-32e Paging */
|
2013-11-15 17:46:38 +04:00
|
|
|
static void walk_pte(MemoryMappingList *list, AddressSpace *as,
|
|
|
|
hwaddr pte_start_addr,
|
2012-05-07 08:04:57 +04:00
|
|
|
int32_t a20_mask, target_ulong start_line_addr)
|
|
|
|
{
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr pte_addr, start_paddr;
|
2012-05-07 08:04:57 +04:00
|
|
|
uint64_t pte;
|
|
|
|
target_ulong start_vaddr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 512; i++) {
|
|
|
|
pte_addr = (pte_start_addr + i * 8) & a20_mask;
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 18:49:24 +03:00
|
|
|
pte = address_space_ldq(as, pte_addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
2012-05-07 08:04:57 +04:00
|
|
|
if (!(pte & PG_PRESENT_MASK)) {
|
|
|
|
/* not present */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
start_paddr = (pte & ~0xfff) & ~(0x1ULL << 63);
|
|
|
|
if (cpu_physical_memory_is_io(start_paddr)) {
|
|
|
|
/* I/O region */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-05-30 19:07:54 +04:00
|
|
|
start_vaddr = start_line_addr | ((i & 0x1ff) << 12);
|
2012-05-07 08:04:57 +04:00
|
|
|
memory_mapping_list_add_merge_sorted(list, start_paddr,
|
|
|
|
start_vaddr, 1 << 12);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 32-bit Paging */
|
2013-11-15 17:46:38 +04:00
|
|
|
static void walk_pte2(MemoryMappingList *list, AddressSpace *as,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr pte_start_addr, int32_t a20_mask,
|
2012-05-07 08:04:57 +04:00
|
|
|
target_ulong start_line_addr)
|
|
|
|
{
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr pte_addr, start_paddr;
|
2012-05-07 08:04:57 +04:00
|
|
|
uint32_t pte;
|
|
|
|
target_ulong start_vaddr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 1024; i++) {
|
|
|
|
pte_addr = (pte_start_addr + i * 4) & a20_mask;
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 18:49:24 +03:00
|
|
|
pte = address_space_ldl(as, pte_addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
2012-05-07 08:04:57 +04:00
|
|
|
if (!(pte & PG_PRESENT_MASK)) {
|
|
|
|
/* not present */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
start_paddr = pte & ~0xfff;
|
|
|
|
if (cpu_physical_memory_is_io(start_paddr)) {
|
|
|
|
/* I/O region */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
start_vaddr = start_line_addr | ((i & 0x3ff) << 12);
|
|
|
|
memory_mapping_list_add_merge_sorted(list, start_paddr,
|
|
|
|
start_vaddr, 1 << 12);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PAE Paging or IA-32e Paging */
|
2013-09-29 19:55:56 +04:00
|
|
|
#define PLM4_ADDR_MASK 0xffffffffff000ULL /* selects bits 51:12 */
|
2013-05-28 22:19:22 +04:00
|
|
|
|
2013-11-15 17:46:38 +04:00
|
|
|
static void walk_pde(MemoryMappingList *list, AddressSpace *as,
|
|
|
|
hwaddr pde_start_addr,
|
2012-05-07 08:04:57 +04:00
|
|
|
int32_t a20_mask, target_ulong start_line_addr)
|
|
|
|
{
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr pde_addr, pte_start_addr, start_paddr;
|
2012-05-07 08:04:57 +04:00
|
|
|
uint64_t pde;
|
|
|
|
target_ulong line_addr, start_vaddr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 512; i++) {
|
|
|
|
pde_addr = (pde_start_addr + i * 8) & a20_mask;
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 18:49:24 +03:00
|
|
|
pde = address_space_ldq(as, pde_addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
2012-05-07 08:04:57 +04:00
|
|
|
if (!(pde & PG_PRESENT_MASK)) {
|
|
|
|
/* not present */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
line_addr = start_line_addr | ((i & 0x1ff) << 21);
|
|
|
|
if (pde & PG_PSE_MASK) {
|
|
|
|
/* 2 MB page */
|
|
|
|
start_paddr = (pde & ~0x1fffff) & ~(0x1ULL << 63);
|
|
|
|
if (cpu_physical_memory_is_io(start_paddr)) {
|
|
|
|
/* I/O region */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
start_vaddr = line_addr;
|
|
|
|
memory_mapping_list_add_merge_sorted(list, start_paddr,
|
|
|
|
start_vaddr, 1 << 21);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-05-28 22:19:22 +04:00
|
|
|
pte_start_addr = (pde & PLM4_ADDR_MASK) & a20_mask;
|
2013-11-15 17:46:38 +04:00
|
|
|
walk_pte(list, as, pte_start_addr, a20_mask, line_addr);
|
2012-05-07 08:04:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 32-bit Paging */
|
2013-11-15 17:46:38 +04:00
|
|
|
static void walk_pde2(MemoryMappingList *list, AddressSpace *as,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr pde_start_addr, int32_t a20_mask,
|
2012-05-07 08:04:57 +04:00
|
|
|
bool pse)
|
|
|
|
{
|
2012-12-22 11:13:54 +04:00
|
|
|
hwaddr pde_addr, pte_start_addr, start_paddr, high_paddr;
|
2012-05-07 08:04:57 +04:00
|
|
|
uint32_t pde;
|
|
|
|
target_ulong line_addr, start_vaddr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 1024; i++) {
|
|
|
|
pde_addr = (pde_start_addr + i * 4) & a20_mask;
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 18:49:24 +03:00
|
|
|
pde = address_space_ldl(as, pde_addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
2012-05-07 08:04:57 +04:00
|
|
|
if (!(pde & PG_PRESENT_MASK)) {
|
|
|
|
/* not present */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
line_addr = (((unsigned int)i & 0x3ff) << 22);
|
|
|
|
if ((pde & PG_PSE_MASK) && pse) {
|
2012-12-22 11:13:54 +04:00
|
|
|
/*
|
|
|
|
* 4 MB page:
|
|
|
|
* bits 39:32 are bits 20:13 of the PDE
|
|
|
|
* bit3 31:22 are bits 31:22 of the PDE
|
|
|
|
*/
|
|
|
|
high_paddr = ((hwaddr)(pde & 0x1fe000) << 19);
|
|
|
|
start_paddr = (pde & ~0x3fffff) | high_paddr;
|
2012-05-07 08:04:57 +04:00
|
|
|
if (cpu_physical_memory_is_io(start_paddr)) {
|
|
|
|
/* I/O region */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
start_vaddr = line_addr;
|
|
|
|
memory_mapping_list_add_merge_sorted(list, start_paddr,
|
|
|
|
start_vaddr, 1 << 22);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
pte_start_addr = (pde & ~0xfff) & a20_mask;
|
2013-11-15 17:46:38 +04:00
|
|
|
walk_pte2(list, as, pte_start_addr, a20_mask, line_addr);
|
2012-05-07 08:04:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PAE Paging */
|
2013-11-15 17:46:38 +04:00
|
|
|
static void walk_pdpe2(MemoryMappingList *list, AddressSpace *as,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr pdpe_start_addr, int32_t a20_mask)
|
2012-05-07 08:04:57 +04:00
|
|
|
{
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr pdpe_addr, pde_start_addr;
|
2012-05-07 08:04:57 +04:00
|
|
|
uint64_t pdpe;
|
|
|
|
target_ulong line_addr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
pdpe_addr = (pdpe_start_addr + i * 8) & a20_mask;
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 18:49:24 +03:00
|
|
|
pdpe = address_space_ldq(as, pdpe_addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
2012-05-07 08:04:57 +04:00
|
|
|
if (!(pdpe & PG_PRESENT_MASK)) {
|
|
|
|
/* not present */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
line_addr = (((unsigned int)i & 0x3) << 30);
|
|
|
|
pde_start_addr = (pdpe & ~0xfff) & a20_mask;
|
2013-11-15 17:46:38 +04:00
|
|
|
walk_pde(list, as, pde_start_addr, a20_mask, line_addr);
|
2012-05-07 08:04:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
/* IA-32e Paging */
|
2013-11-15 17:46:38 +04:00
|
|
|
static void walk_pdpe(MemoryMappingList *list, AddressSpace *as,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr pdpe_start_addr, int32_t a20_mask,
|
2012-05-07 08:04:57 +04:00
|
|
|
target_ulong start_line_addr)
|
|
|
|
{
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr pdpe_addr, pde_start_addr, start_paddr;
|
2012-05-07 08:04:57 +04:00
|
|
|
uint64_t pdpe;
|
|
|
|
target_ulong line_addr, start_vaddr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 512; i++) {
|
|
|
|
pdpe_addr = (pdpe_start_addr + i * 8) & a20_mask;
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 18:49:24 +03:00
|
|
|
pdpe = address_space_ldq(as, pdpe_addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
2012-05-07 08:04:57 +04:00
|
|
|
if (!(pdpe & PG_PRESENT_MASK)) {
|
|
|
|
/* not present */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
line_addr = start_line_addr | ((i & 0x1ffULL) << 30);
|
|
|
|
if (pdpe & PG_PSE_MASK) {
|
|
|
|
/* 1 GB page */
|
|
|
|
start_paddr = (pdpe & ~0x3fffffff) & ~(0x1ULL << 63);
|
|
|
|
if (cpu_physical_memory_is_io(start_paddr)) {
|
|
|
|
/* I/O region */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
start_vaddr = line_addr;
|
|
|
|
memory_mapping_list_add_merge_sorted(list, start_paddr,
|
|
|
|
start_vaddr, 1 << 30);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-05-28 22:19:22 +04:00
|
|
|
pde_start_addr = (pdpe & PLM4_ADDR_MASK) & a20_mask;
|
2013-11-15 17:46:38 +04:00
|
|
|
walk_pde(list, as, pde_start_addr, a20_mask, line_addr);
|
2012-05-07 08:04:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IA-32e Paging */
|
2013-11-15 17:46:38 +04:00
|
|
|
static void walk_pml4e(MemoryMappingList *list, AddressSpace *as,
|
2016-12-15 03:13:05 +03:00
|
|
|
hwaddr pml4e_start_addr, int32_t a20_mask,
|
|
|
|
target_ulong start_line_addr)
|
2012-05-07 08:04:57 +04:00
|
|
|
{
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr pml4e_addr, pdpe_start_addr;
|
2012-05-07 08:04:57 +04:00
|
|
|
uint64_t pml4e;
|
|
|
|
target_ulong line_addr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 512; i++) {
|
|
|
|
pml4e_addr = (pml4e_start_addr + i * 8) & a20_mask;
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 18:49:24 +03:00
|
|
|
pml4e = address_space_ldq(as, pml4e_addr, MEMTXATTRS_UNSPECIFIED,
|
|
|
|
NULL);
|
2012-05-07 08:04:57 +04:00
|
|
|
if (!(pml4e & PG_PRESENT_MASK)) {
|
|
|
|
/* not present */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-15 03:13:05 +03:00
|
|
|
line_addr = start_line_addr | ((i & 0x1ffULL) << 39);
|
2013-05-28 22:19:22 +04:00
|
|
|
pdpe_start_addr = (pml4e & PLM4_ADDR_MASK) & a20_mask;
|
2013-11-15 17:46:38 +04:00
|
|
|
walk_pdpe(list, as, pdpe_start_addr, a20_mask, line_addr);
|
2012-05-07 08:04:57 +04:00
|
|
|
}
|
|
|
|
}
|
2016-12-15 03:13:05 +03:00
|
|
|
|
|
|
|
static void walk_pml5e(MemoryMappingList *list, AddressSpace *as,
|
|
|
|
hwaddr pml5e_start_addr, int32_t a20_mask)
|
|
|
|
{
|
|
|
|
hwaddr pml5e_addr, pml4e_start_addr;
|
|
|
|
uint64_t pml5e;
|
|
|
|
target_ulong line_addr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 512; i++) {
|
|
|
|
pml5e_addr = (pml5e_start_addr + i * 8) & a20_mask;
|
|
|
|
pml5e = address_space_ldq(as, pml5e_addr, MEMTXATTRS_UNSPECIFIED,
|
|
|
|
NULL);
|
|
|
|
if (!(pml5e & PG_PRESENT_MASK)) {
|
|
|
|
/* not present */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
line_addr = (0x7fULL << 57) | ((i & 0x1ffULL) << 48);
|
|
|
|
pml4e_start_addr = (pml5e & PLM4_ADDR_MASK) & a20_mask;
|
|
|
|
walk_pml4e(list, as, pml4e_start_addr, a20_mask, line_addr);
|
|
|
|
}
|
|
|
|
}
|
2012-05-07 08:04:57 +04:00
|
|
|
#endif
|
|
|
|
|
2013-05-28 15:52:01 +04:00
|
|
|
void x86_cpu_get_memory_mapping(CPUState *cs, MemoryMappingList *list,
|
|
|
|
Error **errp)
|
2012-05-07 08:04:57 +04:00
|
|
|
{
|
2013-05-28 15:52:01 +04:00
|
|
|
X86CPU *cpu = X86_CPU(cs);
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
|
|
|
|
if (!cpu_paging_enabled(cs)) {
|
2012-05-07 08:04:57 +04:00
|
|
|
/* paging is disabled */
|
2013-05-28 15:52:01 +04:00
|
|
|
return;
|
2012-05-07 08:04:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (env->cr[4] & CR4_PAE_MASK) {
|
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
if (env->hflags & HF_LMA_MASK) {
|
2016-12-15 03:13:05 +03:00
|
|
|
if (env->cr[4] & CR4_LA57_MASK) {
|
|
|
|
hwaddr pml5e_addr;
|
|
|
|
|
|
|
|
pml5e_addr = (env->cr[3] & PLM4_ADDR_MASK) & env->a20_mask;
|
|
|
|
walk_pml5e(list, cs->as, pml5e_addr, env->a20_mask);
|
|
|
|
} else {
|
|
|
|
hwaddr pml4e_addr;
|
2012-05-07 08:04:57 +04:00
|
|
|
|
2016-12-15 03:13:05 +03:00
|
|
|
pml4e_addr = (env->cr[3] & PLM4_ADDR_MASK) & env->a20_mask;
|
|
|
|
walk_pml4e(list, cs->as, pml4e_addr, env->a20_mask,
|
|
|
|
0xffffULL << 48);
|
|
|
|
}
|
2012-05-07 08:04:57 +04:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr pdpe_addr;
|
2012-05-07 08:04:57 +04:00
|
|
|
|
|
|
|
pdpe_addr = (env->cr[3] & ~0x1f) & env->a20_mask;
|
2013-11-15 17:46:38 +04:00
|
|
|
walk_pdpe2(list, cs->as, pdpe_addr, env->a20_mask);
|
2012-05-07 08:04:57 +04:00
|
|
|
}
|
|
|
|
} else {
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr pde_addr;
|
2012-05-07 08:04:57 +04:00
|
|
|
bool pse;
|
|
|
|
|
|
|
|
pde_addr = (env->cr[3] & ~0xfff) & env->a20_mask;
|
|
|
|
pse = !!(env->cr[4] & CR4_PSE_MASK);
|
2013-11-15 17:46:38 +04:00
|
|
|
walk_pde2(list, cs->as, pde_addr, env->a20_mask, pse);
|
2012-05-07 08:04:57 +04:00
|
|
|
}
|
|
|
|
}
|
2012-05-07 08:05:42 +04:00
|
|
|
|