mirror of
https://git.proxmox.com/git/qemu
synced 2025-08-15 02:39:19 +00:00
use qemu memory allocation - added dirty bit support when using host MMU
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@619 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
parent
bf3e8bf11e
commit
59817ccb2c
91
exec.c
91
exec.c
@ -143,7 +143,7 @@ static inline PageDesc *page_find_alloc(unsigned int index)
|
|||||||
p = *lp;
|
p = *lp;
|
||||||
if (!p) {
|
if (!p) {
|
||||||
/* allocate if not found */
|
/* allocate if not found */
|
||||||
p = malloc(sizeof(PageDesc) * L2_SIZE);
|
p = qemu_malloc(sizeof(PageDesc) * L2_SIZE);
|
||||||
memset(p, 0, sizeof(PageDesc) * L2_SIZE);
|
memset(p, 0, sizeof(PageDesc) * L2_SIZE);
|
||||||
*lp = p;
|
*lp = p;
|
||||||
}
|
}
|
||||||
@ -173,7 +173,7 @@ static inline VirtPageDesc *virt_page_find_alloc(unsigned int index)
|
|||||||
p = *lp;
|
p = *lp;
|
||||||
if (!p) {
|
if (!p) {
|
||||||
/* allocate if not found */
|
/* allocate if not found */
|
||||||
p = malloc(sizeof(VirtPageDesc) * L2_SIZE);
|
p = qemu_malloc(sizeof(VirtPageDesc) * L2_SIZE);
|
||||||
memset(p, 0, sizeof(VirtPageDesc) * L2_SIZE);
|
memset(p, 0, sizeof(VirtPageDesc) * L2_SIZE);
|
||||||
*lp = p;
|
*lp = p;
|
||||||
}
|
}
|
||||||
@ -226,7 +226,7 @@ void cpu_exec_init(void)
|
|||||||
static inline void invalidate_page_bitmap(PageDesc *p)
|
static inline void invalidate_page_bitmap(PageDesc *p)
|
||||||
{
|
{
|
||||||
if (p->code_bitmap) {
|
if (p->code_bitmap) {
|
||||||
free(p->code_bitmap);
|
qemu_free(p->code_bitmap);
|
||||||
p->code_bitmap = NULL;
|
p->code_bitmap = NULL;
|
||||||
}
|
}
|
||||||
p->code_write_count = 0;
|
p->code_write_count = 0;
|
||||||
@ -501,7 +501,7 @@ static void build_page_bitmap(PageDesc *p)
|
|||||||
int n, tb_start, tb_end;
|
int n, tb_start, tb_end;
|
||||||
TranslationBlock *tb;
|
TranslationBlock *tb;
|
||||||
|
|
||||||
p->code_bitmap = malloc(TARGET_PAGE_SIZE / 8);
|
p->code_bitmap = qemu_malloc(TARGET_PAGE_SIZE / 8);
|
||||||
if (!p->code_bitmap)
|
if (!p->code_bitmap)
|
||||||
return;
|
return;
|
||||||
memset(p->code_bitmap, 0, TARGET_PAGE_SIZE / 8);
|
memset(p->code_bitmap, 0, TARGET_PAGE_SIZE / 8);
|
||||||
@ -585,7 +585,13 @@ static inline void tb_invalidate_phys_page_fast(target_ulong start, int len, tar
|
|||||||
{
|
{
|
||||||
PageDesc *p;
|
PageDesc *p;
|
||||||
int offset, b;
|
int offset, b;
|
||||||
|
#if 0
|
||||||
|
if (cpu_single_env->cr[0] & CR0_PE_MASK) {
|
||||||
|
printf("modifying code at 0x%x size=%d EIP=%x\n",
|
||||||
|
(vaddr & TARGET_PAGE_MASK) | (start & ~TARGET_PAGE_MASK), len,
|
||||||
|
cpu_single_env->eip);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
p = page_find(start >> TARGET_PAGE_BITS);
|
p = page_find(start >> TARGET_PAGE_BITS);
|
||||||
if (!p)
|
if (!p)
|
||||||
return;
|
return;
|
||||||
@ -775,7 +781,12 @@ void tb_link(TranslationBlock *tb)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
vp->phys_addr = tb->page_addr[0];
|
vp->phys_addr = tb->page_addr[0];
|
||||||
|
if (vp->valid_tag != virt_valid_tag) {
|
||||||
vp->valid_tag = virt_valid_tag;
|
vp->valid_tag = virt_valid_tag;
|
||||||
|
#if !defined(CONFIG_SOFTMMU)
|
||||||
|
vp->prot = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (tb->page_addr[1] != -1) {
|
if (tb->page_addr[1] != -1) {
|
||||||
addr += TARGET_PAGE_SIZE;
|
addr += TARGET_PAGE_SIZE;
|
||||||
@ -788,7 +799,12 @@ void tb_link(TranslationBlock *tb)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
vp->phys_addr = tb->page_addr[1];
|
vp->phys_addr = tb->page_addr[1];
|
||||||
|
if (vp->valid_tag != virt_valid_tag) {
|
||||||
vp->valid_tag = virt_valid_tag;
|
vp->valid_tag = virt_valid_tag;
|
||||||
|
#if !defined(CONFIG_SOFTMMU)
|
||||||
|
vp->prot = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1172,7 +1188,7 @@ static inline void tlb_reset_dirty_range(CPUTLBEntry *tlb_entry,
|
|||||||
void cpu_physical_memory_reset_dirty(target_ulong start, target_ulong end)
|
void cpu_physical_memory_reset_dirty(target_ulong start, target_ulong end)
|
||||||
{
|
{
|
||||||
CPUState *env;
|
CPUState *env;
|
||||||
target_ulong length;
|
target_ulong length, start1;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
start &= TARGET_PAGE_MASK;
|
start &= TARGET_PAGE_MASK;
|
||||||
@ -1186,11 +1202,39 @@ void cpu_physical_memory_reset_dirty(target_ulong start, target_ulong end)
|
|||||||
env = cpu_single_env;
|
env = cpu_single_env;
|
||||||
/* we modify the TLB cache so that the dirty bit will be set again
|
/* we modify the TLB cache so that the dirty bit will be set again
|
||||||
when accessing the range */
|
when accessing the range */
|
||||||
start += (unsigned long)phys_ram_base;
|
start1 = start + (unsigned long)phys_ram_base;
|
||||||
for(i = 0; i < CPU_TLB_SIZE; i++)
|
for(i = 0; i < CPU_TLB_SIZE; i++)
|
||||||
tlb_reset_dirty_range(&env->tlb_write[0][i], start, length);
|
tlb_reset_dirty_range(&env->tlb_write[0][i], start1, length);
|
||||||
for(i = 0; i < CPU_TLB_SIZE; i++)
|
for(i = 0; i < CPU_TLB_SIZE; i++)
|
||||||
tlb_reset_dirty_range(&env->tlb_write[1][i], start, length);
|
tlb_reset_dirty_range(&env->tlb_write[1][i], start1, length);
|
||||||
|
|
||||||
|
#if !defined(CONFIG_SOFTMMU)
|
||||||
|
/* XXX: this is expensive */
|
||||||
|
{
|
||||||
|
VirtPageDesc *p;
|
||||||
|
int j;
|
||||||
|
target_ulong addr;
|
||||||
|
|
||||||
|
for(i = 0; i < L1_SIZE; i++) {
|
||||||
|
p = l1_virt_map[i];
|
||||||
|
if (p) {
|
||||||
|
addr = i << (TARGET_PAGE_BITS + L2_BITS);
|
||||||
|
for(j = 0; j < L2_SIZE; j++) {
|
||||||
|
if (p->valid_tag == virt_valid_tag &&
|
||||||
|
p->phys_addr >= start && p->phys_addr < end &&
|
||||||
|
(p->prot & PROT_WRITE)) {
|
||||||
|
if (addr < MMAP_AREA_END) {
|
||||||
|
mprotect((void *)addr, TARGET_PAGE_SIZE,
|
||||||
|
p->prot & ~PROT_WRITE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addr += TARGET_PAGE_SIZE;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void tlb_set_dirty1(CPUTLBEntry *tlb_entry,
|
static inline void tlb_set_dirty1(CPUTLBEntry *tlb_entry,
|
||||||
@ -1220,8 +1264,10 @@ static inline void tlb_set_dirty(unsigned long addr, target_ulong vaddr)
|
|||||||
tlb_set_dirty1(&env->tlb_write[1][i], addr);
|
tlb_set_dirty1(&env->tlb_write[1][i], addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add a new TLB entry. At most one entry for a given virtual
|
/* add a new TLB entry. At most one entry for a given virtual address
|
||||||
address is permitted. */
|
is permitted. Return 0 if OK or 2 if the page could not be mapped
|
||||||
|
(can only happen in non SOFTMMU mode for I/O pages or pages
|
||||||
|
conflicting with the host address space). */
|
||||||
int tlb_set_page(CPUState *env, uint32_t vaddr, uint32_t paddr, int prot,
|
int tlb_set_page(CPUState *env, uint32_t vaddr, uint32_t paddr, int prot,
|
||||||
int is_user, int is_softmmu)
|
int is_user, int is_softmmu)
|
||||||
{
|
{
|
||||||
@ -1301,8 +1347,15 @@ int tlb_set_page(CPUState *env, uint32_t vaddr, uint32_t paddr, int prot,
|
|||||||
ret = 2;
|
ret = 2;
|
||||||
} else {
|
} else {
|
||||||
void *map_addr;
|
void *map_addr;
|
||||||
|
|
||||||
|
if (vaddr >= MMAP_AREA_END) {
|
||||||
|
ret = 2;
|
||||||
|
} else {
|
||||||
if (prot & PROT_WRITE) {
|
if (prot & PROT_WRITE) {
|
||||||
if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_ROM || first_tb) {
|
if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_ROM ||
|
||||||
|
first_tb ||
|
||||||
|
((pd & ~TARGET_PAGE_MASK) == IO_MEM_RAM &&
|
||||||
|
!cpu_physical_memory_is_dirty(pd))) {
|
||||||
/* ROM: we do as if code was inside */
|
/* ROM: we do as if code was inside */
|
||||||
/* if code is present, we only map as read only and save the
|
/* if code is present, we only map as read only and save the
|
||||||
original mapping */
|
original mapping */
|
||||||
@ -1323,6 +1376,7 @@ int tlb_set_page(CPUState *env, uint32_t vaddr, uint32_t paddr, int prot,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1338,6 +1392,10 @@ int page_unprotect(unsigned long addr)
|
|||||||
printf("page_unprotect: addr=0x%08x\n", addr);
|
printf("page_unprotect: addr=0x%08x\n", addr);
|
||||||
#endif
|
#endif
|
||||||
addr &= TARGET_PAGE_MASK;
|
addr &= TARGET_PAGE_MASK;
|
||||||
|
|
||||||
|
/* if it is not mapped, no need to worry here */
|
||||||
|
if (addr >= MMAP_AREA_END)
|
||||||
|
return 0;
|
||||||
vp = virt_page_find(addr >> TARGET_PAGE_BITS);
|
vp = virt_page_find(addr >> TARGET_PAGE_BITS);
|
||||||
if (!vp)
|
if (!vp)
|
||||||
return 0;
|
return 0;
|
||||||
@ -1351,8 +1409,13 @@ int page_unprotect(unsigned long addr)
|
|||||||
printf("page_unprotect: addr=0x%08x phys_addr=0x%08x prot=%x\n",
|
printf("page_unprotect: addr=0x%08x phys_addr=0x%08x prot=%x\n",
|
||||||
addr, vp->phys_addr, vp->prot);
|
addr, vp->phys_addr, vp->prot);
|
||||||
#endif
|
#endif
|
||||||
|
/* set the dirty bit */
|
||||||
|
phys_ram_dirty[vp->phys_addr >> TARGET_PAGE_BITS] = 1;
|
||||||
|
/* flush the code inside */
|
||||||
tb_invalidate_phys_page(vp->phys_addr);
|
tb_invalidate_phys_page(vp->phys_addr);
|
||||||
mprotect((void *)addr, TARGET_PAGE_SIZE, vp->prot);
|
if (mprotect((void *)addr, TARGET_PAGE_SIZE, vp->prot) < 0)
|
||||||
|
cpu_abort(cpu_single_env, "error mprotect addr=0x%lx prot=%d\n",
|
||||||
|
(unsigned long)addr, vp->prot);
|
||||||
return 1;
|
return 1;
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
@ -1642,7 +1705,7 @@ static void io_mem_init(void)
|
|||||||
io_mem_nb = 5;
|
io_mem_nb = 5;
|
||||||
|
|
||||||
/* alloc dirty bits array */
|
/* alloc dirty bits array */
|
||||||
phys_ram_dirty = malloc(phys_ram_size >> TARGET_PAGE_BITS);
|
phys_ram_dirty = qemu_malloc(phys_ram_size >> TARGET_PAGE_BITS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mem_read and mem_write are arrays of functions containing the
|
/* mem_read and mem_write are arrays of functions containing the
|
||||||
|
Loading…
Reference in New Issue
Block a user