Previous 15994 Revisions Next

r9860 Friday 31st December, 2010 at 16:15:44 UTC by R. Belmont
ARM7+: Add 26-bit and enhanced MMU support [Tim Schuerewegen]
[src/emu/cpu/arm7]arm7.c arm7.h arm7core.c arm7core.h arm7exec.c

src/emu/cpu/arm7/arm7core.c
r9859r9860
131131{
132132    if( COPRO_CTRL & COPRO_CTRL_MMU_EN )
133133    {
134        addr = arm7_tlb_translate( cpustate, addr );
134        addr = arm7_tlb_translate( cpustate, addr, 0 );
135135    }
136136
137137    addr &= ~3;
r9859r9860
146146{
147147    if( COPRO_CTRL & COPRO_CTRL_MMU_EN )
148148    {
149        addr = arm7_tlb_translate( cpustate, addr );
149        addr = arm7_tlb_translate( cpustate, addr, 0 );
150150    }
151151
152152    addr &= ~1;
r9859r9860
160160{
161161    if( COPRO_CTRL & COPRO_CTRL_MMU_EN )
162162    {
163        addr = arm7_tlb_translate( cpustate, addr );
163        addr = arm7_tlb_translate( cpustate, addr, 0 );
164164    }
165165
166166   if ( cpustate->endian == ENDIANNESS_BIG )
r9859r9860
175175
176176    if( COPRO_CTRL & COPRO_CTRL_MMU_EN )
177177    {
178        addr = arm7_tlb_translate( cpustate, addr );
178        addr = arm7_tlb_translate( cpustate, addr, 0 );
179179    }
180180
181181    if (addr & 3)
r9859r9860
203203
204204    if( COPRO_CTRL & COPRO_CTRL_MMU_EN )
205205    {
206        addr = arm7_tlb_translate( cpustate, addr );
206        addr = arm7_tlb_translate( cpustate, addr, 0 );
207207    }
208208
209209   if ( cpustate->endian == ENDIANNESS_BIG )
r9859r9860
223223{
224224    if( COPRO_CTRL & COPRO_CTRL_MMU_EN )
225225    {
226        addr = arm7_tlb_translate( cpustate, addr );
226        addr = arm7_tlb_translate( cpustate, addr, 0 );
227227    }
228228
229229    // Handle through normal 8 bit handler (for 32 bit cpu)
r9859r9860
460460static int loadInc(arm_state *cpustate, UINT32 pat, UINT32 rbv, UINT32 s)
461461{
462462    int i, result;
463    UINT32 data;
463464
464465    result = 0;
465466    rbv &= ~3;
r9859r9860
467468    {
468469        if ((pat >> i) & 1)
469470        {
471            data = READ32(rbv += 4);
472            if (cpustate->pendingAbtD != 0) break;
470473            if (i == 15) {
471474                if (s) /* Pull full contents from stack */
472                    SET_REGISTER(cpustate, 15, READ32(rbv += 4));
475                    SET_REGISTER(cpustate, 15, data);
473476                else /* Pull only address, preserve mode & status flags */
474                    SET_REGISTER(cpustate, 15, READ32(rbv += 4));
477                    SET_REGISTER(cpustate, 15, data);
475478            } else
476                SET_REGISTER(cpustate, i, READ32(rbv += 4));
479                SET_REGISTER(cpustate, i, data);
477480
478481            result++;
479482        }
r9859r9860
484487static int loadDec(arm_state *cpustate, UINT32 pat, UINT32 rbv, UINT32 s)
485488{
486489    int i, result;
490    UINT32 data;
487491
488492    result = 0;
489493    rbv &= ~3;
r9859r9860
491495    {
492496        if ((pat >> i) & 1)
493497        {
498            data = READ32(rbv -= 4);
499            if (cpustate->pendingAbtD != 0) break;
494500            if (i == 15) {
495501                if (s) /* Pull full contents from stack */
496                    SET_REGISTER(cpustate, 15, READ32(rbv -= 4));
502                    SET_REGISTER(cpustate, 15, data);
497503                else /* Pull only address, preserve mode & status flags */
498                    SET_REGISTER(cpustate, 15, READ32(rbv -= 4));
504                    SET_REGISTER(cpustate, 15, data);
499505            }
500506            else
501                SET_REGISTER(cpustate, i, READ32(rbv -= 4));
507                SET_REGISTER(cpustate, i, data);
502508            result++;
503509        }
504510    }
r9859r9860
606612    // Data Abort
607613    if (cpustate->pendingAbtD) {
608614        SwitchMode(cpustate, eARM7_MODE_ABT);             /* Set ABT mode so PC is saved to correct R14 bank */
609        SET_REGISTER(cpustate, 14, pc);                   /* save PC to R14 */
615        SET_REGISTER(cpustate, 14, pc - 8 + 8);                   /* save PC to R14 */
610616        SET_REGISTER(cpustate, SPSR, cpsr);               /* Save current CPSR */
611617        SET_CPSR(GET_CPSR | I_MASK);            /* Mask IRQ */
612618        SET_CPSR(GET_CPSR & ~T_MASK);
613619        R15 = 0x10;                             /* IRQ Vector address */
620        if ((COPRO_CTRL & COPRO_CTRL_MMU_EN) && (COPRO_CTRL & COPRO_CTRL_INTVEC_ADJUST)) R15 |= 0xFFFF0000;
614621        cpustate->pendingAbtD = 0;
615622        return;
616623    }
r9859r9860
618625    // FIQ
619626    if (cpustate->pendingFiq && (cpsr & F_MASK) == 0) {
620627        SwitchMode(cpustate, eARM7_MODE_FIQ);             /* Set FIQ mode so PC is saved to correct R14 bank */
621        SET_REGISTER(cpustate, 14, pc);                   /* save PC to R14 */
628        SET_REGISTER(cpustate, 14, pc - 4 + 4);                   /* save PC to R14 */
622629        SET_REGISTER(cpustate, SPSR, cpsr);               /* Save current CPSR */
623630        SET_CPSR(GET_CPSR | I_MASK | F_MASK);   /* Mask both IRQ & FIQ */
624631        SET_CPSR(GET_CPSR & ~T_MASK);
625632        R15 = 0x1c;                             /* IRQ Vector address */
633        if ((COPRO_CTRL & COPRO_CTRL_MMU_EN) && (COPRO_CTRL & COPRO_CTRL_INTVEC_ADJUST)) R15 |= 0xFFFF0000;
626634        return;
627635    }
628636
629637    // IRQ
630638    if (cpustate->pendingIrq && (cpsr & I_MASK) == 0) {
631639        SwitchMode(cpustate, eARM7_MODE_IRQ);             /* Set IRQ mode so PC is saved to correct R14 bank */
632        SET_REGISTER(cpustate, 14, pc);                   /* save PC to R14 */
640        SET_REGISTER(cpustate, 14, pc - 4 + 4);                   /* save PC to R14 */
633641        SET_REGISTER(cpustate, SPSR, cpsr);               /* Save current CPSR */
634642        SET_CPSR(GET_CPSR | I_MASK);            /* Mask IRQ */
635643        SET_CPSR(GET_CPSR & ~T_MASK);
636644        R15 = 0x18;                             /* IRQ Vector address */
645        if ((COPRO_CTRL & COPRO_CTRL_MMU_EN) && (COPRO_CTRL & COPRO_CTRL_INTVEC_ADJUST)) R15 |= 0xFFFF0000;
637646        return;
638647    }
639648
640649    // Prefetch Abort
641650    if (cpustate->pendingAbtP) {
642651        SwitchMode(cpustate, eARM7_MODE_ABT);             /* Set ABT mode so PC is saved to correct R14 bank */
643        SET_REGISTER(cpustate, 14, pc);                   /* save PC to R14 */
652        SET_REGISTER(cpustate, 14, pc - 4 + 4);                   /* save PC to R14 */
644653        SET_REGISTER(cpustate, SPSR, cpsr);               /* Save current CPSR */
645654        SET_CPSR(GET_CPSR | I_MASK);            /* Mask IRQ */
646655        SET_CPSR(GET_CPSR & ~T_MASK);
647656        R15 = 0x0c;                             /* IRQ Vector address */
657        if ((COPRO_CTRL & COPRO_CTRL_MMU_EN) && (COPRO_CTRL & COPRO_CTRL_INTVEC_ADJUST)) R15 |= 0xFFFF0000;
648658        cpustate->pendingAbtP = 0;
649659        return;
650660    }
r9859r9860
652662    // Undefined instruction
653663    if (cpustate->pendingUnd) {
654664        SwitchMode(cpustate, eARM7_MODE_UND);             /* Set UND mode so PC is saved to correct R14 bank */
655        SET_REGISTER(cpustate, 14, pc);                   /* save PC to R14 */
665        if (T_IS_SET(GET_CPSR))
666        {
667                SET_REGISTER(cpustate, 14, pc - 4 + 2);         /* save PC to R14 */
668        }
669        else
670        {
671                SET_REGISTER(cpustate, 14, pc - 4 + 4 - 4);           /* save PC to R14 */
672        }
656673        SET_REGISTER(cpustate, SPSR, cpsr);               /* Save current CPSR */
657674        SET_CPSR(GET_CPSR | I_MASK);            /* Mask IRQ */
658675        SET_CPSR(GET_CPSR & ~T_MASK);
659676        R15 = 0x04;                             /* IRQ Vector address */
677        if ((COPRO_CTRL & COPRO_CTRL_MMU_EN) && (COPRO_CTRL & COPRO_CTRL_INTVEC_ADJUST)) R15 |= 0xFFFF0000;
660678        cpustate->pendingUnd = 0;
661679        return;
662680    }
r9859r9860
667685        // compensate for prefetch (should this also be done for normal IRQ?)
668686        if (T_IS_SET(GET_CPSR))
669687        {
670                SET_REGISTER(cpustate, 14, pc-2);         /* save PC to R14 */
688                SET_REGISTER(cpustate, 14, pc - 4 + 2);         /* save PC to R14 */
671689        }
672690        else
673691        {
674                SET_REGISTER(cpustate, 14, pc);           /* save PC to R14 */
692                SET_REGISTER(cpustate, 14, pc - 4 + 4);           /* save PC to R14 */
675693        }
676694        SET_REGISTER(cpustate, SPSR, cpsr);               /* Save current CPSR */
677695        SET_CPSR(GET_CPSR | I_MASK);            /* Mask IRQ */
678696        SET_CPSR(GET_CPSR & ~T_MASK);           /* Go to ARM mode */
679697        R15 = 0x08;                             /* Jump to the SWI vector */
698        if ((COPRO_CTRL & COPRO_CTRL_MMU_EN) && (COPRO_CTRL & COPRO_CTRL_INTVEC_ADJUST)) R15 |= 0xFFFF0000;
680699        cpustate->pendingSwi = 0;
681700        return;
682701    }
r9859r9860
744763    // Store (MCR) data from ARM7 to Co-Proc register
745764    else
746765    {
747        if (arm7_coproc_rt_r_callback)
766        if (arm7_coproc_rt_w_callback)
748767            arm7_coproc_rt_w_callback(cpustate->device, insn, GET_REGISTER(cpustate, (insn >> 12) & 0xf), 0);
749768        else
750769            LOG(("%08x: Co-Processor Register Transfer executed, but no RT Write callback defined!\n", R15));
r9859r9860
837856
838857static void HandleMemSingle(arm_state *cpustate, UINT32 insn)
839858{
840    UINT32 rn, rnv, off, rd;
859    UINT32 rn, rnv, off, rd, rnv_old = 0;
841860
842861    /* Fetch the offset */
843862    if (insn & INSN_I)
r9859r9860
868887
869888        if (insn & INSN_SDT_W)
870889        {
890            rnv_old = GET_REGISTER(cpustate, rn);
871891            SET_REGISTER(cpustate, rn, rnv);
872892
873893    // check writeback???
r9859r9860
897917        /* Load */
898918        if (insn & INSN_SDT_B)
899919        {
900            SET_REGISTER(cpustate, rd, (UINT32)READ8(rnv));
920            UINT32 data = READ8(rnv);
921            if (cpustate->pendingAbtD == 0)
922            {
923                SET_REGISTER(cpustate, rd, data);
924            }
901925        }
902926        else
903927        {
904            if (rd == eR15)
928            UINT32 data = READ32(rnv);
929            if (cpustate->pendingAbtD == 0)
905930            {
906                R15 = READ32(rnv);
907                R15 -= 4;
908                // LDR, PC takes 2S + 2N + 1I (5 total cycles)
909                ARM7_ICOUNT -= 2;
931                if (rd == eR15)
932                {
933                    R15 = data - 4;
934                    // LDR, PC takes 2S + 2N + 1I (5 total cycles)
935                    ARM7_ICOUNT -= 2;
936                }
937                else
938                {
939                    SET_REGISTER(cpustate, rd, data);
940                }
910941            }
911            else
912            {
913                SET_REGISTER(cpustate, rd, READ32(rnv));
914            }
915942        }
916943    }
917944    else
r9859r9860
940967        ARM7_ICOUNT += 1;
941968    }
942969
970   if (cpustate->pendingAbtD != 0)
971   {
972      if ((insn & INSN_SDT_P) && (insn & INSN_SDT_W))
973      {
974         SET_REGISTER(cpustate, rn, rnv_old);
975      }
976   }
977   else
978   {
979
943980    /* Do post-indexing writeback */
944981    if (!(insn & INSN_SDT_P)/* && (insn & INSN_SDT_W)*/)
945982    {
r9859r9860
9751012        }
9761013    }
9771014
1015   }
1016
9781017//  ARM7_CHECKIRQ
9791018
9801019} /* HandleMemSingle */
9811020
9821021static void HandleHalfWordDT(arm_state *cpustate, UINT32 insn)
9831022{
984    UINT32 rn, rnv, off, rd;
1023    UINT32 rn, rnv, off, rd, rnv_old = 0;
9851024
9861025    // Immediate or Register Offset?
9871026    if (insn & 0x400000) {               // Bit 22 - 1 = immediate, 0 = register
r9859r9860
10101049
10111050        if (insn & INSN_SDT_W)
10121051        {
1052            rnv_old = GET_REGISTER(cpustate, rn);
10131053            SET_REGISTER(cpustate, rn, rnv);
10141054
10151055        // check writeback???
r9859r9860
10591099                newval = (UINT32)(signbyte << 8)|databyte;
10601100            }
10611101
1102         if (cpustate->pendingAbtD == 0)
1103         {
1104
10621105            // PC?
10631106            if (rd == eR15)
10641107            {
r9859r9860
10721115                SET_REGISTER(cpustate, rd, newval);
10731116                R15 += 4;
10741117            }
1118
1119            }
1120            else
1121            {
1122                R15 += 4;
1123            }
1124
10751125        }
10761126        // Unsigned Half Word
10771127        else
10781128        {
1129         UINT32 newval = READ16(rnv);
1130
1131         if (cpustate->pendingAbtD == 0)
1132         {
1133
10791134            if (rd == eR15)
10801135            {
1081                R15 = READ16(rnv) + 8;
1136                R15 = newval + 8;
10821137            }
10831138            else
10841139            {
1085                SET_REGISTER(cpustate, rd, READ16(rnv));
1140                SET_REGISTER(cpustate, rd, newval);
10861141                R15 += 4;
10871142            }
1143
1144            }
1145            else
1146            {
1147                R15 += 4;
1148            }
1149
10881150        }
10891151
10901152
r9859r9860
11091171           // WRITE16(rnv, rd == eR15 ? R15 + 8 : GET_REGISTER(cpustate, rd));
11101172           WRITE16(rnv, rd == eR15 ? R15 + 8 + 4 : GET_REGISTER(cpustate, rd)); // manual says STR RD=PC, +12 of address
11111173
1112// if R15 is not increased then e.g. "STRH R10, [R15,#$10]" will be executed over and over again
1113#if 0
1114           if (rn != eR15)
1115#endif
1116               R15 += 4;
1174         // if R15 is not increased then e.g. "STRH R10, [R15,#$10]" will be executed over and over again             
1175         //if (rn != eR15)
1176           R15 += 4;
11171177
11181178           // STRH takes 2 cycles, so we add + 1
11191179           ARM7_ICOUNT += 1;
11201180   }
11211181    }
11221182
1183   if (cpustate->pendingAbtD != 0)
1184   {
1185      if ((insn & INSN_SDT_P) && (insn & INSN_SDT_W))
1186      {
1187         SET_REGISTER(cpustate, rn, rnv_old);
1188      }
1189   }
1190   else
1191   {
11231192
1124
11251193    // SJE: No idea if this writeback code works or makes sense here..
11261194
11271195    /* Do post-indexing writeback */
r9859r9860
11581226            }
11591227        }
11601228    }
1229   
1230    }
1231
11611232}
11621233
11631234static void HandleSwap(arm_state *cpustate, UINT32 insn)
r9859r9860
14161487        else
14171488        {
14181489            // Rd = 15 and S Flag IS set, Result is placed in R15, and current mode SPSR moved to CPSR
1419            if (rdn == eR15) {
1420
1421            // When Rd is R15 and the S flag is set the result of the operation is placed in R15 and the SPSR corresponding to
1422            // the current mode is moved to the CPSR. This allows state changes which automatically restore both PC and
1423            // CPSR. --> This form of instruction should not be used in User mode. <--
1424
1490            if (rdn == eR15)
1491         {
1492               // When Rd is R15 and the S flag is set the result of the operation is placed in R15 and the SPSR corresponding to
1493               // the current mode is moved to the CPSR. This allows state changes which automatically restore both PC and
1494               // CPSR. --> This form of instruction should not be used in User mode. <--
14251495            if (GET_MODE != eARM7_MODE_USER)
14261496            {
1427                   // Update CPSR from SPSR
1428                   SET_CPSR(GET_REGISTER(cpustate, SPSR));
1429                   SwitchMode(cpustate, GET_MODE);
1430               }
1431
1497                  // Update CPSR from SPSR
1498                  SET_CPSR(GET_REGISTER(cpustate, SPSR));
1499                  SwitchMode(cpustate, GET_MODE);
1500            }
14321501                R15 = rd;
14331502
14341503                /* IRQ masks may have changed in this instruction */
r9859r9860
16041673            else
16051674                result = loadInc(cpustate, insn & 0xffff, rbp, insn & INSN_BDT_S);
16061675
1607            if (insn & INSN_BDT_W)
1676            if ((insn & INSN_BDT_W) && (cpustate->pendingAbtD == 0))
16081677            {
16091678#if ARM7_DEBUG_CORE
16101679                    if (rb == 15)
r9859r9860
16141683            }
16151684
16161685            // R15 included? (NOTE: CPSR restore must occur LAST otherwise wrong registers restored!)
1617            if (insn & 0x8000) {
1686            if ((insn & 0x8000) && (cpustate->pendingAbtD == 0)) {
16181687                R15 -= 4;     // SJE: I forget why i did this?
16191688                // S - Flag Set? Signals transfer of current mode SPSR->CPSR
1620                if (insn & INSN_BDT_S) {
1689                if (insn & INSN_BDT_S)
1690            {
16211691                    SET_CPSR(GET_REGISTER(cpustate, SPSR));
16221692                    SwitchMode(cpustate, GET_MODE);
16231693                }
1624               // LDM PC - takes 1 extra cycle
1625               ARM7_ICOUNT -= 1;
1694
1695            // LDM PC - takes 1 extra cycle
1696            ARM7_ICOUNT -= 1;
16261697            }
16271698        }
16281699        else
r9859r9860
16471718            else
16481719                result = loadDec(cpustate, insn & 0xffff, rbp, insn & INSN_BDT_S);
16491720
1650            if (insn & INSN_BDT_W)
1721            if ((insn & INSN_BDT_W) && (cpustate->pendingAbtD == 0))
16511722            {
16521723                if (rb == 0xf)
16531724                    LOG(("%08x:  Illegal LDRM writeback to r15\n", R15));
r9859r9860
16551726            }
16561727
16571728            // R15 included? (NOTE: CPSR restore must occur LAST otherwise wrong registers restored!)
1658            if (insn & 0x8000) {
1729            if ((insn & 0x8000) && (cpustate->pendingAbtD == 0)) {
16591730                R15 -= 4;     // SJE: I forget why i did this?
16601731                // S - Flag Set? Signals transfer of current mode SPSR->CPSR
1661                if (insn & INSN_BDT_S) {
1732                if (insn & INSN_BDT_S)
1733            {
16621734                    SET_CPSR(GET_REGISTER(cpustate, SPSR));
16631735                    SwitchMode(cpustate, GET_MODE);
16641736                }
r9859r9860
16891761                rbp = rbp + (- 4);
16901762            }
16911763
1692            // S Flag Set, but R15 not in list = User Bank Transfer
1693            if (insn & INSN_BDT_S && (insn & 0x8000) == 0)
1764            // S Flag Set = User Bank Transfer
1765            if (insn & INSN_BDT_S)
16941766            {
16951767                // todo: needs to be tested..
16961768
r9859r9860
17051777            else
17061778                result = storeInc(cpustate, insn & 0xffff, rbp);
17071779
1708            if (insn & INSN_BDT_W)
1780            if ((insn & INSN_BDT_W) && (cpustate->pendingAbtD == 0))
17091781            {
17101782                SET_REGISTER(cpustate, rb, GET_REGISTER(cpustate, rb) + result * 4);
17111783            }
r9859r9860
17181790                rbp = rbp - (-4);
17191791            }
17201792
1721            // S Flag Set, but R15 not in list = User Bank Transfer
1722            if (insn & INSN_BDT_S && (insn & 0x8000) == 0)
1793            // S Flag Set = User Bank Transfer
1794            if (insn & INSN_BDT_S)
17231795            {
17241796                // set to user mode - then do the transfer, and set back
17251797                int curmode = GET_MODE;
r9859r9860
17321804            else
17331805                result = storeDec(cpustate, insn & 0xffff, rbp);
17341806
1735            if (insn & INSN_BDT_W)
1807            if ((insn & INSN_BDT_W) && (cpustate->pendingAbtD == 0))
17361808            {
17371809                SET_REGISTER(cpustate, rb, GET_REGISTER(cpustate, rb) - result * 4);
17381810            }
src/emu/cpu/arm7/arm7core.h
r9859r9860
136136#define COPRO_CTRL_INTVEC_F                 1
137137#define COPRO_CTRL_MASK                     0x0000338f
138138
139#define COPRO_DOMAIN_ACCESS_CONTROL           cpustate->domainAccessControl
140
141#define COPRO_FAULT_STATUS           cpustate->faultStatus
142
143#define COPRO_FAULT_ADDRESS          cpustate->faultAddress
144
145#define COPRO_FCSE_PID          cpustate->fcsePID
146
139147/* Coprocessor Registers */
140148#define ARM7COPRO_REGS \
141149    UINT32 control; \
142    UINT32 tlbBase;
150    UINT32 tlbBase; \
151    UINT32 faultStatus; \
152    UINT32 faultAddress; \
153    UINT32 fcsePID; \
154    UINT32 domainAccessControl;
143155
144156enum
145157{
src/emu/cpu/arm7/arm7.c
r9859r9860
7171INLINE arm_state *get_safe_token(running_device *device)
7272{
7373   assert(device != NULL);
74   assert(device->type() == ARM7 || device->type() == ARM7_BE || device->type() == ARM9 || device->type() == PXA255);
74   assert(device->type() == ARM7 || device->type() == ARM7_BE || device->type() == ARM9 || device->type() == ARM920T || device->type() == PXA255);
7575   return (arm_state *)downcast<legacy_cpu_device *>(device)->token();
7676}
7777
r9859r9860
128128    return cpustate->program->read_dword( desc_lvl2 );
129129}
130130
131INLINE UINT32 arm7_tlb_translate(arm_state *cpustate, UINT32 vaddr)
131static UINT32 r15_mmu_enable_addr = 1;
132
133INLINE UINT32 arm7_tlb_translate(arm_state *cpustate, UINT32 vaddr, int mode)
132134{
133    UINT32 desc_lvl1 = arm7_tlb_get_first_level_descriptor( cpustate, vaddr );
135    UINT32 desc_lvl1;
134136    UINT32 desc_lvl2 = 0;
135    UINT32 paddr = vaddr;
137    UINT32 paddr;
138    UINT8 domain, permission;
136139
140    if (vaddr < 32 * 1024 * 1024)
141    {
142       UINT32 pid = ((COPRO_FCSE_PID >> 25) & 0x7F);
143       if (pid > 0)
144       {
145            //LOG( ( "ARM7: FCSE PID vaddr %08X -> %08X\n", vaddr, vaddr + (pid * (32 * 1024 * 1024))) );
146            vaddr = vaddr + (((COPRO_FCSE_PID >> 25) & 0x7F) * (32 * 1024 * 1024));
147         }
148    }
149   
150    desc_lvl1 = arm7_tlb_get_first_level_descriptor( cpustate, vaddr );
151
152    paddr = vaddr;
153
154    if ((R15 == (r15_mmu_enable_addr + 4)) || (R15 == (r15_mmu_enable_addr + 8)))
155    {
156        LOG( ( "ARM7: fetch flat, PC = %08x, vaddr = %08x\n", R15, vaddr ) );
157       return vaddr;
158    }
159    else
160    {
161       r15_mmu_enable_addr = 1;
162    }
163
164   domain = (desc_lvl1 >> 5) & 0xF;
165   permission = (COPRO_DOMAIN_ACCESS_CONTROL >> (domain << 1)) & 3;
166
137167    switch( desc_lvl1 & 3 )
138168    {
139169        case COPRO_TLB_UNMAPPED:
140170            // Unmapped, generate a translation fault
141            LOG( ( "ARM7: Not Yet Implemented: Translation fault on unmapped virtual address, PC = %08x, vaddr = %08x\n", R15, vaddr ) );
171            if (mode == 0)
172            {
173               LOG( ( "ARM7: Not Yet Implemented: Translation fault on unmapped virtual address, PC = %08x, vaddr = %08x\n", R15, vaddr ) );
174               COPRO_FAULT_STATUS = (5 << 0);
175               COPRO_FAULT_ADDRESS = vaddr;
176               cpustate->pendingAbtD = 1;
177            }
178            else if (mode == 1)
179            {
180               LOG( ( "ARM7: Not Yet Implemented: Translation fault on unmapped virtual address, PC = %08x, vaddr = %08x\n", R15, vaddr ) );
181               cpustate->pendingAbtP = 1;
182            }
142183            break;
143184        case COPRO_TLB_COARSE_TABLE:
144185            // Entry is the physical address of a coarse second-level table
145            desc_lvl2 = arm7_tlb_get_second_level_descriptor( cpustate, TLB_COARSE, desc_lvl1, vaddr );
186            if (permission == 1)
187            {
188               desc_lvl2 = arm7_tlb_get_second_level_descriptor( cpustate, TLB_COARSE, desc_lvl1, vaddr );
189            }
190            else
191            {
192                 LOG( ( "domain %d permission = %d\n", domain, permission ) );
193                LOG( ( "ARM7: Coarse Table, Section Domain fault on virtual address, vaddr = %08x, domain = %08x, PC = %08x\n", vaddr, domain, R15 ) );
194            }
146195            break;
147196        case COPRO_TLB_SECTION_TABLE:
148197            // Entry is a section
149            paddr = ( desc_lvl1 & COPRO_TLB_SECTION_PAGE_MASK ) | ( vaddr & ~COPRO_TLB_SECTION_PAGE_MASK );
198            if ((permission == 1) || (permission == 3))
199            {
200               paddr = ( desc_lvl1 & COPRO_TLB_SECTION_PAGE_MASK ) | ( vaddr & ~COPRO_TLB_SECTION_PAGE_MASK );
201            }
202            else
203            {
204                if (mode == 0)
205                {
206                    LOG( ( "domain %d permission = %d\n", domain, permission ) );
207                   LOG( ( "ARM7: Section Table, Section Domain fault on virtual address, vaddr = %08x, domain = %08x, PC = %08x\n", vaddr, domain, R15 ) );
208                   COPRO_FAULT_STATUS = (9 << 0);
209                   COPRO_FAULT_ADDRESS = vaddr;
210                   cpustate->pendingAbtD = 1;
211               }
212               else if (mode == 1)
213               {
214                    LOG( ( "domain %d permission = %d\n", domain, permission ) );
215                   LOG( ( "ARM7: Section Table, Section Domain fault on virtual address, vaddr = %08x, domain = %08x, PC = %08x\n", vaddr, domain, R15 ) );
216                   cpustate->pendingAbtP = 1;
217               }
218            }
150219            break;
151220        case COPRO_TLB_FINE_TABLE:
152221            // Entry is the physical address of a fine second-level table
r9859r9860
163232        {
164233            case COPRO_TLB_UNMAPPED:
165234                // Unmapped, generate a translation fault
166                LOG( ( "ARM7: Not Yet Implemented: Translation fault on unmapped virtual address, vaddr = %08x\n", vaddr ) );
235                if (mode == 0)
236                {
237                   LOG( ( "ARM7: Not Yet Implemented: Translation fault on unmapped virtual address, vaddr = %08x, PC %08X\n", vaddr, R15 ) );
238                   COPRO_FAULT_STATUS = (7 << 0);
239                   COPRO_FAULT_ADDRESS = vaddr;
240                  cpustate->pendingAbtD = 1;
241               }
242               else if (mode == 1)
243               {
244                   LOG( ( "ARM7: Not Yet Implemented: Translation fault on unmapped virtual address, vaddr = %08x, PC %08X\n", vaddr, R15 ) );
245                  cpustate->pendingAbtP = 1;
246              }
167247                break;
168248            case COPRO_TLB_LARGE_PAGE:
169249                // Large page descriptor
r9859r9860
194274   /* only applies to the program address space and only does something if the MMU's enabled */
195275   if( space == ADDRESS_SPACE_PROGRAM && ( COPRO_CTRL & COPRO_CTRL_MMU_EN ) )
196276   {
197      *address = arm7_tlb_translate(cpustate, *address);
277      *address = arm7_tlb_translate(cpustate, *address, 2);
198278   }
199279   return TRUE;
200280}
r9859r9860
256336   cpustate->archFlags = eARM_ARCHFLAGS_T | eARM_ARCHFLAGS_E;   // has TE extensions
257337}
258338
339static CPU_RESET( arm920t )
340{
341   arm_state *cpustate = get_safe_token(device);
342
343   // must call core reset
344   arm7_core_reset(device);
345
346   cpustate->archRev = 4;   // ARMv4
347   cpustate->archFlags = eARM_ARCHFLAGS_T;   // has T extension
348}
349
259350static CPU_RESET( pxa255 )
260351{
261352   arm_state *cpustate = get_safe_token(device);
r9859r9860
599690    }
600691}
601692
693CPU_GET_INFO( arm920t )
694{
695    switch (state)
696    {
697        case CPUINFO_FCT_RESET:                 info->reset = CPU_RESET_NAME(arm920t);                       break;
698        case DEVINFO_STR_NAME:             strcpy(info->s, "ARM920T");                        break;
699   default:   CPU_GET_INFO_CALL(arm7);
700      break;
701    }
702}
703
602704CPU_GET_INFO( pxa255 )
603705{
604706    switch (state)
r9859r9860
666768   }
667769   else
668770   {
669      fatalerror("ARM7: Unhandled coprocessor %d (archFlags %x)\n", cpnum, cpustate->archFlags);
771      LOG( ("ARM7: Unhandled coprocessor %d (archFlags %x)\n", cpnum, cpustate->archFlags) );
772      cpustate->pendingUnd = 1;
773      return 0;
670774   }
671775    }
672776
r9859r9860
703807            else
704808            {
705809               data = 0x41 | (1 << 23) | (7 << 12);
810               //data = (0x41 << 24) | (1 << 20) | (2 << 16) | (0x920 << 4) | (0 << 0); // ARM920T (S3C24xx)
706811            }
707812            break;
708813
r9859r9860
735840          break;
736841          case 1:   // cache type
737842         data = 0x0f0d2112;   // HACK: value expected by ARMWrestler (probably Nintendo DS ARM9's value)
843         //data = (6 << 25) | (1 << 24) | (0x172 << 12) | (0x172 << 0); // ARM920T (S3C24xx)
738844         break;
739845      case 2: // TCM type
740846         data = 0;
r9859r9860
756862            break;
757863        case 3:             // Domain Access Control
758864            LOG( ( "arm7_rt_r_callback, Domain Access Control\n" ) );
865            data = COPRO_DOMAIN_ACCESS_CONTROL;
759866            break;
760867        case 5:             // Fault Status
761868            LOG( ( "arm7_rt_r_callback, Fault Status\n" ) );
869            data = COPRO_FAULT_STATUS;
762870            break;
763871        case 6:             // Fault Address
764872            LOG( ( "arm7_rt_r_callback, Fault Address\n" ) );
873            data = COPRO_FAULT_ADDRESS;
765874            break;
766875        case 13:            // Read Process ID (PID)
767876            LOG( ( "arm7_rt_r_callback, Read PID\n" ) );
877            data = COPRO_FCSE_PID;
768878            break;
769879        case 14:            // Read Breakpoint
770880            LOG( ( "arm7_rt_r_callback, Read Breakpoint\n" ) );
r9859r9860
825935                   ( data & COPRO_CTRL_ROM ) >> COPRO_CTRL_ROM_SHIFT,
826936                   ( data & COPRO_CTRL_ICACHE_EN ) >> COPRO_CTRL_ICACHE_EN_SHIFT ) );
827937            LOG( ( "    Int Vector Adjust:%d\n", ( data & COPRO_CTRL_INTVEC_ADJUST ) >> COPRO_CTRL_INTVEC_ADJUST_SHIFT ) );
938            if (((data & COPRO_CTRL_MMU_EN) != 0) && ((COPRO_CTRL & COPRO_CTRL_MMU_EN) == 0))
939            {
940               r15_mmu_enable_addr = R15;
941            }
942            if (((data & COPRO_CTRL_MMU_EN) == 0) && ((COPRO_CTRL & COPRO_CTRL_MMU_EN) != 0))
943            {
944               R15 = arm7_tlb_translate( cpustate, R15, 0);
945            }
828946            COPRO_CTRL = data & COPRO_CTRL_MASK;
829947            break;
830948        case 2:             // Translation Table Base
r9859r9860
833951            break;
834952        case 3:             // Domain Access Control
835953            LOG( ( "arm7_rt_w_callback Domain Access Control = %08x (%d) (%d)\n", data, op2, op3 ) );
954            COPRO_DOMAIN_ACCESS_CONTROL = data;
836955            break;
837956        case 5:             // Fault Status
838957            LOG( ( "arm7_rt_w_callback Fault Status = %08x (%d) (%d)\n", data, op2, op3 ) );
958            COPRO_FAULT_STATUS = data;
839959            break;
840960        case 6:             // Fault Address
841961            LOG( ( "arm7_rt_w_callback Fault Address = %08x (%d) (%d)\n", data, op2, op3 ) );
962            COPRO_FAULT_ADDRESS = data;
842963            break;
843964        case 7:             // Cache Operations
844965//            LOG( ( "arm7_rt_w_callback Cache Ops = %08x (%d) (%d)\n", data, op2, op3 ) );
r9859r9860
851972            break;
852973        case 13:            // Write Process ID (PID)
853974            LOG( ( "arm7_rt_w_callback Write PID = %08x (%d) (%d)\n", data, op2, op3 ) );
975            COPRO_FCSE_PID = data;
854976            break;
855977        case 14:            // Write Breakpoint
856978            LOG( ( "arm7_rt_w_callback Write Breakpoint = %08x (%d) (%d)\n", data, op2, op3 ) );
r9859r9860
874996DEFINE_LEGACY_CPU_DEVICE(ARM7, arm7);
875997DEFINE_LEGACY_CPU_DEVICE(ARM7_BE, arm7_be);
876998DEFINE_LEGACY_CPU_DEVICE(ARM9, arm9);
999DEFINE_LEGACY_CPU_DEVICE(ARM920T, arm920t);
8771000DEFINE_LEGACY_CPU_DEVICE(PXA255, pxa255);
8781001DEFINE_LEGACY_CPU_DEVICE(SA1110, sa1110);
src/emu/cpu/arm7/arm7.h
r9859r9860
4141DECLARE_LEGACY_CPU_DEVICE(ARM7, arm7);
4242DECLARE_LEGACY_CPU_DEVICE(ARM7_BE, arm7_be);
4343DECLARE_LEGACY_CPU_DEVICE(ARM9, arm9);
44DECLARE_LEGACY_CPU_DEVICE(ARM920T, arm920t);
4445DECLARE_LEGACY_CPU_DEVICE(PXA255, pxa255);
4546DECLARE_LEGACY_CPU_DEVICE(SA1110, sa1110);
4647
src/emu/cpu/arm7/arm7exec.c
r9859r9860
6060       raddr = pc & (~1);
6161       if ( COPRO_CTRL & COPRO_CTRL_MMU_EN )
6262       {
63          raddr = arm7_tlb_translate(cpustate, raddr);
63          raddr = arm7_tlb_translate(cpustate, raddr, 1);
64          if (cpustate->pendingAbtP != 0)
65          {
66             goto skip_exec;
67          }
6468       }
6569            insn = cpustate->direct->read_decrypted_word(raddr);
6670            ARM7_ICOUNT -= (3 - thumbCycles[insn >> 8]);
r9859r9860
11701174            pc = R15;
11711175       if ( COPRO_CTRL & COPRO_CTRL_MMU_EN )
11721176       {
1173          pc = arm7_tlb_translate(cpustate, pc);
1177          pc = arm7_tlb_translate(cpustate, pc, 1);
1178          if (cpustate->pendingAbtP != 0)
1179          {
1180             goto skip_exec;
1181          }
11741182       }
11751183            insn = cpustate->direct->read_decrypted_dword(pc);
11761184
r9859r9860
15971605            }
15981606        }
15991607
1608skip_exec:
1609
16001610        ARM7_CHECKIRQ;
16011611
16021612        /* All instructions remove 3 cycles.. Others taking less / more will have adjusted this # prior to here */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team