Search
lxdream.org :: lxdream/src/sh4/mmu.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/mmu.c
changeset 952:18e579840923
prev951:63483914846f
next1067:d3c00ffccfcd
author nkeynes
date Wed Jan 07 06:01:33 2009 +0000 (11 years ago)
branchlxdream-mem
permissions -rw-r--r--
last change Handle URC/URB case where URC is initialized >= URB
file annotate diff log raw
1.1 --- a/src/sh4/mmu.c Wed Jan 07 05:45:15 2009 +0000
1.2 +++ b/src/sh4/mmu.c Wed Jan 07 06:01:33 2009 +0000
1.3 @@ -44,6 +44,7 @@
1.4 /* Accessed from the UTLB accessor methods */
1.5 uint32_t mmu_urc;
1.6 uint32_t mmu_urb;
1.7 +static gboolean mmu_urc_overflow; /* If true, urc was set >= urb */
1.8
1.9 /* Module globals */
1.10 static struct itlb_entry mmu_itlb[ITLB_ENTRY_COUNT];
1.11 @@ -76,6 +77,7 @@
1.12 static void mmu_utlb_1k_init();
1.13 static struct utlb_1k_entry *mmu_utlb_1k_alloc();
1.14 static void mmu_utlb_1k_free( struct utlb_1k_entry *entry );
1.15 +static void mmu_fix_urc();
1.16
1.17 static void FASTCALL tlb_miss_read( sh4addr_t addr, void *exc );
1.18 static int32_t FASTCALL tlb_protected_read( sh4addr_t addr, void *exc );
1.19 @@ -156,6 +158,7 @@
1.20
1.21 void MMU_save_state( FILE *f )
1.22 {
1.23 + mmu_fix_urc();
1.24 fwrite( &mmu_itlb, sizeof(mmu_itlb), 1, f );
1.25 fwrite( &mmu_utlb, sizeof(mmu_utlb), 1, f );
1.26 fwrite( &mmu_urc, sizeof(mmu_urc), 1, f );
1.27 @@ -186,6 +189,7 @@
1.28 }
1.29
1.30 uint32_t mmucr = MMIO_READ(MMU,MMUCR);
1.31 + mmu_urc_overflow = mmu_urc >= mmu_urb;
1.32 mmu_set_tlb_enabled(mmucr&MMUCR_AT);
1.33 mmu_set_storequeue_protected(mmucr&MMUCR_SQMD, mmucr&MMUCR_AT);
1.34 return 0;
1.35 @@ -197,7 +201,7 @@
1.36 */
1.37 void MMU_ldtlb()
1.38 {
1.39 - mmu_urc %= mmu_urb;
1.40 + mmu_fix_urc();
1.41 if( mmu_utlb[mmu_urc].flags & TLB_VALID )
1.42 mmu_utlb_remove_entry( mmu_urc );
1.43 mmu_utlb[mmu_urc].vpn = MMIO_READ(MMU, PTEH) & 0xFFFFFC00;
1.44 @@ -216,7 +220,7 @@
1.45 reg &= 0xFFF;
1.46 switch( reg ) {
1.47 case MMUCR:
1.48 - mmu_urc %= mmu_urb;
1.49 + mmu_fix_urc();
1.50 return MMIO_READ( MMU, MMUCR) | (mmu_urc<<10) | ((mmu_urb&0x3F)<<18) | (mmu_lrui<<26);
1.51 default:
1.52 return MMIO_READ( MMU, reg );
1.53 @@ -258,6 +262,8 @@
1.54 mmu_urb = (val >> 18) & 0x3F;
1.55 if( mmu_urb == 0 ) {
1.56 mmu_urb = 0x40;
1.57 + } else if( mmu_urc >= mmu_urb ) {
1.58 + mmu_urc_overflow = TRUE;
1.59 }
1.60 mmu_lrui = (val >> 26) & 0x3F;
1.61 val &= 0x00000301;
1.62 @@ -343,9 +349,17 @@
1.63 /**
1.64 * MMU accessor functions just increment URC - fixup here if necessary
1.65 */
1.66 -static inline void mmu_urc_fixup()
1.67 +static inline void mmu_fix_urc()
1.68 {
1.69 - mmu_urc %= mmu_urb;
1.70 + if( mmu_urc_overflow ) {
1.71 + if( mmu_urc >= 0x40 ) {
1.72 + mmu_urc_overflow = FALSE;
1.73 + mmu_urc -= 0x40;
1.74 + mmu_urc %= mmu_urb;
1.75 + }
1.76 + } else {
1.77 + mmu_urc %= mmu_urb;
1.78 + }
1.79 }
1.80
1.81 static void mmu_register_mem_region( uint32_t start, uint32_t end, mem_region_fn_t fn )
.