look only on valid tlb entries in check_addr_in_tlb_buffers and tlb invalidation methods

This commit is contained in:
Stanislav Shwartsman 2016-05-06 06:57:00 +00:00
parent dff5e9587b
commit 12ece81e19
2 changed files with 23 additions and 14 deletions

View File

@ -391,11 +391,13 @@ void BX_CPU_C::TLB_flushNonGlobal(void)
for (unsigned n=0; n<BX_TLB_SIZE; n++) { for (unsigned n=0; n<BX_TLB_SIZE; n++) {
bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[n]; bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[n];
if (!(tlbEntry->accessBits & TLB_GlobalPage)) { if (tlbEntry->valid()) {
tlbEntry->invalidate(); if (!(tlbEntry->accessBits & TLB_GlobalPage)) {
} tlbEntry->invalidate();
else { }
lpf_mask |= tlbEntry->lpf_mask; else {
lpf_mask |= tlbEntry->lpf_mask;
}
} }
} }
@ -430,12 +432,14 @@ void BX_CPU_C::TLB_invlpg(bx_address laddr)
// make sure INVLPG handles correctly large pages // make sure INVLPG handles correctly large pages
for (unsigned n=0; n<BX_TLB_SIZE; n++) { for (unsigned n=0; n<BX_TLB_SIZE; n++) {
bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[n]; bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[n];
bx_address entry_lpf_mask = tlbEntry->lpf_mask; if (tlbEntry->valid()) {
if ((laddr & ~entry_lpf_mask) == (tlbEntry->lpf & ~entry_lpf_mask)) { bx_address entry_lpf_mask = tlbEntry->lpf_mask;
tlbEntry->invalidate(); if ((laddr & ~entry_lpf_mask) == (tlbEntry->lpf & ~entry_lpf_mask)) {
} tlbEntry->invalidate();
else { }
lpf_mask |= entry_lpf_mask; else {
lpf_mask |= entry_lpf_mask;
}
} }
} }
@ -2376,9 +2380,12 @@ bx_hostpageaddr_t BX_CPU_C::getHostMemAddr(bx_phy_address paddr, unsigned rw)
bx_bool BX_CPU_C::check_addr_in_tlb_buffers(const Bit8u *addr, const Bit8u *end) bx_bool BX_CPU_C::check_addr_in_tlb_buffers(const Bit8u *addr, const Bit8u *end)
{ {
for (unsigned tlb_entry_num=0; tlb_entry_num < BX_TLB_SIZE; tlb_entry_num++) { for (unsigned tlb_entry_num=0; tlb_entry_num < BX_TLB_SIZE; tlb_entry_num++) {
if (((BX_CPU_THIS_PTR TLB.entry[tlb_entry_num].hostPageAddr)>=(const bx_hostpageaddr_t)addr) && bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[tlb_entry_num];
((BX_CPU_THIS_PTR TLB.entry[tlb_entry_num].hostPageAddr)<(const bx_hostpageaddr_t)end)) if (tlbEntry->valid()) {
return true; if (((tlbEntry->hostPageAddr) >= (const bx_hostpageaddr_t)addr) &&
((tlbEntry->hostPageAddr) < (const bx_hostpageaddr_t)end))
return true;
}
} }
return false; return false;
} }

View File

@ -109,6 +109,8 @@ typedef struct {
Bit32u memtype; // keep it Bit32u for alignment Bit32u memtype; // keep it Bit32u for alignment
#endif #endif
BX_CPP_INLINE bx_bool valid() const { return lpf != BX_INVALID_TLB_ENTRY; }
BX_CPP_INLINE void invalidate() { BX_CPP_INLINE void invalidate() {
lpf = BX_INVALID_TLB_ENTRY; lpf = BX_INVALID_TLB_ENTRY;
accessBits = 0; accessBits = 0;