Previous 15994 Revisions Next

r1886 Monday 10th March, 2008 at 13:12:53 UTC by Nathan Woods
Changed how the PowerPC MMU is enabled at compile time, to cut down on the
amount of unused functions in MAME.
[src/emu/cpu/powerpc]ppc.c ppc_mem.c

src/emu/cpu/powerpc/ppc_mem.c
r1885r1886
122122};
123123
124124#ifdef MESS
125#define PPC_MMU_ENABLED      1
126#else /* !MESS */
127/* MMU not enabled in MAME; model3 drivers don't work properly */
128#define PPC_MMU_ENABLED      0
129#endif /* MESS */
130
131
132
125133static int ppc_is_protected(UINT32 pp, int flags)
126134{
127135   if (flags & PPC_TRANSLATE_WRITE)
r1885r1886
136144   }
137145   return FALSE;
138146}
139#endif
140147
141148static int ppc_translate_address(offs_t *addr_ptr, int flags)
142149{
143#ifdef MESS
144   const BATENT *bat;
145   UINT32 address;
146   UINT32 sr, vsid, hash;
147   UINT32 pteg_address;
148   UINT32 target_pte, bl, mask;
149   UINT64 pte;
150   UINT64 *pteg_ptr[2];
151   int i, hash_type;
152   UINT32 dsisr = DSISR_PROT;
150   if (PPC_MMU_ENABLED)
151   {
152      const BATENT *bat;
153      UINT32 address;
154      UINT32 sr, vsid, hash;
155      UINT32 pteg_address;
156      UINT32 target_pte, bl, mask;
157      UINT64 pte;
158      UINT64 *pteg_ptr[2];
159      int i, hash_type;
160      UINT32 dsisr = DSISR_PROT;
153161
154   bat = (flags & PPC_TRANSLATE_CODE) ? ppc.ibat : ppc.dbat;
162      bat = (flags & PPC_TRANSLATE_CODE) ? ppc.ibat : ppc.dbat;
155163
156   address = *addr_ptr;
164      address = *addr_ptr;
157165
158   /* first check the block address translation table */
159   for (i = 0; i < 4; i++)
160   {
161      if (bat[i].u & ((MSR & MSR_PR) ? 0x00000001 : 0x00000002))
166      /* first check the block address translation table */
167      for (i = 0; i < 4; i++)
162168      {
163         bl = bat[i].u & 0x00001FFC;
164         mask = (~bl << 15) & 0xFFFE0000;
165
166         if ((address & mask) == (bat[i].u & 0xFFFE0000))
169         if (bat[i].u & ((MSR & MSR_PR) ? 0x00000001 : 0x00000002))
167170         {
168            if (ppc_is_protected(bat[i].l, flags))
169               goto exception;
171            bl = bat[i].u & 0x00001FFC;
172            mask = (~bl << 15) & 0xFFFE0000;
170173
171            *addr_ptr = (bat[i].l & 0xFFFE0000)
172               | (address & ((bl << 15) | 0x0001FFFF));
173            return 1;
174            if ((address & mask) == (bat[i].u & 0xFFFE0000))
175            {
176               if (ppc_is_protected(bat[i].l, flags))
177                  goto exception;
178
179               *addr_ptr = (bat[i].l & 0xFFFE0000)
180                  | (address & ((bl << 15) | 0x0001FFFF));
181               return 1;
182            }
174183         }
175184      }
176   }
177185
178   /* now try page address translation */
179   sr = ppc.sr[(address >> 28) & 0x0F];
180   if (sr & 0x80000000)
181   {
182      /* direct store translation */
183      if ((flags & PPC_TRANSLATE_NOEXCEPTION) == 0)
184         fatalerror("ppc: direct store translation not yet implemented");
185      return 0;
186   }
187   else
188   {
189      /* is no execute is set? */
190      if ((flags & PPC_TRANSLATE_CODE) && (sr & 0x10000000))
191         goto exception;
186      /* now try page address translation */
187      sr = ppc.sr[(address >> 28) & 0x0F];
188      if (sr & 0x80000000)
189      {
190         /* direct store translation */
191         if ((flags & PPC_TRANSLATE_NOEXCEPTION) == 0)
192            fatalerror("ppc: direct store translation not yet implemented");
193         return 0;
194      }
195      else
196      {
197         /* is no execute is set? */
198         if ((flags & PPC_TRANSLATE_CODE) && (sr & 0x10000000))
199            goto exception;
192200
193      vsid = sr & 0x00FFFFFF;
194      hash = (vsid & 0x0007FFFF) ^ ((address >> 12) & 0xFFFF);
195      target_pte = (vsid << 7) | ((address >> 22) & 0x3F) | 0x80000000;
201         vsid = sr & 0x00FFFFFF;
202         hash = (vsid & 0x0007FFFF) ^ ((address >> 12) & 0xFFFF);
203         target_pte = (vsid << 7) | ((address >> 22) & 0x3F) | 0x80000000;
196204
197      /* we have to try both types of hashes */
198      for (hash_type = 0; hash_type <= 1; hash_type++)
199      {
200         pteg_address = (ppc.sdr1 & 0xFFFF0000)
201            | (((ppc.sdr1 & 0x01FF) & (hash >> 10)) << 16)
202            | ((hash & 0x03FF) << 6);
205         /* we have to try both types of hashes */
206         for (hash_type = 0; hash_type <= 1; hash_type++)
207         {
208            pteg_address = (ppc.sdr1 & 0xFFFF0000)
209               | (((ppc.sdr1 & 0x01FF) & (hash >> 10)) << 16)
210               | ((hash & 0x03FF) << 6);
203211
204         pteg_ptr[hash_type] = memory_get_read_ptr(cpu_getactivecpu(), ADDRESS_SPACE_PROGRAM, pteg_address);
205         if (pteg_ptr[hash_type])
206         {
207            for (i = 0; i < 8; i++)
212            pteg_ptr[hash_type] = memory_get_read_ptr(cpu_getactivecpu(), ADDRESS_SPACE_PROGRAM, pteg_address);
213            if (pteg_ptr[hash_type])
208214            {
209               pte = pteg_ptr[hash_type][i];
210
211               /* is valid? */
212               if (((pte >> 32) & 0xFFFFFFFF) == target_pte)
215               for (i = 0; i < 8; i++)
213216               {
214                  if (ppc_is_protected((UINT32) pte, flags))
215                     goto exception;
217                  pte = pteg_ptr[hash_type][i];
216218
217                  *addr_ptr = ((UINT32) (pte & 0xFFFFF000))
218                     | (address & 0x0FFF);
219                  return 1;
219                  /* is valid? */
220                  if (((pte >> 32) & 0xFFFFFFFF) == target_pte)
221                  {
222                     if (ppc_is_protected((UINT32) pte, flags))
223                        goto exception;
224
225                     *addr_ptr = ((UINT32) (pte & 0xFFFFF000))
226                        | (address & 0x0FFF);
227                     return 1;
228                  }
220229               }
221230            }
231
232            hash ^= 0x7FFFF;
233            target_pte ^= 0x40;
222234         }
223235
224         hash ^= 0x7FFFF;
225         target_pte ^= 0x40;
226      }
227
228      if (DUMP_PAGEFAULTS)
229      {
230         mame_printf_debug("PAGE FAULT: address=%08X PC=%08X SDR1=%08X MSR=%08X\n", address, ppc.pc, ppc.sdr1, ppc.msr);
231         mame_printf_debug("\n");
232
233         for (i = 0; i < 4; i++)
236         if (DUMP_PAGEFAULTS)
234237         {
235            bl = bat[i].u & 0x00001FFC;
236            mask = (~bl << 15) & 0xFFFE0000;
237            mame_printf_debug("    BAT[%d]=%08X%08X    (A & %08X = %08X)\n", i, bat[i].u, bat[i].l,
238               mask, bat[i].u & 0xFFFE0000);
239         }
240         mame_printf_debug("\n");
241         mame_printf_debug("    VSID=%06X HASH=%05X HASH\'=%05X\n", vsid, hash, hash ^ 0x7FFFF);
238            mame_printf_debug("PAGE FAULT: address=%08X PC=%08X SDR1=%08X MSR=%08X\n", address, ppc.pc, ppc.sdr1, ppc.msr);
239            mame_printf_debug("\n");
242240
243         for (hash_type = 0; hash_type <= 1; hash_type++)
244         {
245            if (pteg_ptr[hash_type])
241            for (i = 0; i < 4; i++)
246242            {
247               for (i = 0; i < 8; i++)
243               bl = bat[i].u & 0x00001FFC;
244               mask = (~bl << 15) & 0xFFFE0000;
245               mame_printf_debug("    BAT[%d]=%08X%08X    (A & %08X = %08X)\n", i, bat[i].u, bat[i].l,
246                  mask, bat[i].u & 0xFFFE0000);
247            }
248            mame_printf_debug("\n");
249            mame_printf_debug("    VSID=%06X HASH=%05X HASH\'=%05X\n", vsid, hash, hash ^ 0x7FFFF);
250
251            for (hash_type = 0; hash_type <= 1; hash_type++)
252            {
253               if (pteg_ptr[hash_type])
248254               {
249                  pte = pteg_ptr[hash_type][i];
250                  mame_printf_debug("    PTE[%i%c]=%08X%08X\n",
251                     i,
252                     hash_type ? '\'' : ' ',
253                     (unsigned) (pte >> 32),
254                     (unsigned) (pte >> 0));
255                  for (i = 0; i < 8; i++)
256                  {
257                     pte = pteg_ptr[hash_type][i];
258                     mame_printf_debug("    PTE[%i%c]=%08X%08X\n",
259                        i,
260                        hash_type ? '\'' : ' ',
261                        (unsigned) (pte >> 32),
262                        (unsigned) (pte >> 0));
263                  }
255264               }
256265            }
257266         }
258267      }
259   }
260268
261   dsisr = DSISR_PAGE;
269      dsisr = DSISR_PAGE;
262270
263271exception:
264   /* lookup failure - exception */
265   if ((flags & PPC_TRANSLATE_NOEXCEPTION) == 0)
266   {
267      if (flags & PPC_TRANSLATE_CODE)
272      /* lookup failure - exception */
273      if ((flags & PPC_TRANSLATE_NOEXCEPTION) == 0)
268274      {
269         ppc_exception(EXCEPTION_ISI);
270      }
271      else
272      {
273         ppc.dar = address;
274         if (flags & PPC_TRANSLATE_WRITE)
275            ppc.dsisr = dsisr | DSISR_STORE;
275         if (flags & PPC_TRANSLATE_CODE)
276         {
277            ppc_exception(EXCEPTION_ISI);
278         }
276279         else
277            ppc.dsisr = dsisr;
280         {
281            ppc.dar = address;
282            if (flags & PPC_TRANSLATE_WRITE)
283               ppc.dsisr = dsisr | DSISR_STORE;
284            else
285               ppc.dsisr = dsisr;
278286
279         ppc_exception(EXCEPTION_DSI);
287            ppc_exception(EXCEPTION_DSI);
288         }
280289      }
290      return 0;
281291   }
282   return 0;
283#else
284   /* MMU not enabled in MAME; model3 drivers don't work properly */
285   return 1;
286#endif
292   else
293   {
294      /* MMU not enabled in MAME; model3 drivers don't work properly */
295      return 1;
296   }
287297}
288298
289299#if (HAS_PPC602||HAS_PPC603)
src/emu/cpu/powerpc/ppc.c
r1885r1886
817817   return CR(0) << 28 | CR(1) << 24 | CR(2) << 20 | CR(3) << 16 | CR(4) << 12 | CR(5) << 8 | CR(6) << 4 | CR(7);
818818}
819819
820#ifdef UNUSED_FUNCTION
821820INLINE void ppc_exception(int exception_type)
822821{
823822   longjmp(ppc.exception_jmpbuf, exception_type);
824823}
825#endif
826824
827825/***********************************************************************/
828826

Previous 15994 Revisions Next


© 1998-2018 The MESS Team