From 23b8cd9892afd4b90c06856ed4f234596df7efcd Mon Sep 17 00:00:00 2001 From: Jim Date: Sat, 6 Aug 2011 09:01:16 -0400 Subject: [PATCH] Only use 28 bits of physical address in mapva to correct CPUT4 emulator seg fault after LPSW near label RXM in CPUT4. CPUT4 activates Ring 3 by loading the ring bits of the program counter. However, it does not enable segmentation, so we're still accessing memory by physical location - no address mapping occurs. mapva used the entire 32-bit program counter as an offset in the MEM array (physical memory), and because of the ring bits, this caused a Unix seg fault. mapva was changed to only use 28 bits of the address when VA mapping is disabled (28 bits matches the size of the MEM array). Technically, a more accurate mask should be applied based on the CPU model. For example, a P750 could only access 8MB of memory. --- em.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/em.c b/em.c index 8fa1963..6ff8413 100644 --- a/em.c +++ b/em.c @@ -568,8 +568,9 @@ static jmp_buf bootjmp; /* for longjumps to the fetch loop */ speed up system boots and diagnostics during emulator testing. */ -#define MAXMB 512 +#define MAXMB 512 /* must be a power of 2 */ #define MEMSIZE MAXMB/2*1024*1024 +#define MEMMASK MEMSIZE-1 #define MEM physmem static unsigned short physmem[MEMSIZE]; /* system's physical memory */ @@ -1034,7 +1035,7 @@ static pa_t mapva(ea_t ea, ea_t rp, short intacc, unsigned short *access) { pa = stlbp->ppa | (ea & 0x3FF); TRACE(T_MAP," for ea %o/%o, iacc=%d, stlbix=%d, pa=%o loaded at #%lu\n", ea>>16, ea&0xffff, intacc, stlbix, pa, stlbp->load_ic); } else { - pa = ea; + pa = ea & MEMMASK; } stopwatch_pop(&sw_mapva); #ifndef NOMEM