Previous 15994 Revisions Next

r10077 Monday 17th January, 2011 at 20:21:14 UTC by Miodrag Milanović
Removed PPC_MMU_ENABLED check, model3 works same as before in MAME anyway.
[src/emu/cpu/powerpc]ppc_mem.c

src/emu/cpu/powerpc/ppc_mem.c
r10076r10077
119119   PPC_TRANSLATE_NOEXCEPTION = 0x0004
120120};
121121
122#ifdef MESS
123#define PPC_MMU_ENABLED      1
124#else /* !MESS */
125/* MMU not enabled in MAME; model3 drivers don't work properly */
126#define PPC_MMU_ENABLED      0
127#endif /* MESS */
128
129
130
131122static int ppc_is_protected(UINT32 pp, int flags)
132123{
133124   if (flags & PPC_TRANSLATE_WRITE)
r10076r10077
145136
146137static int ppc_translate_address(offs_t *addr_ptr, int flags)
147138{
148   if (PPC_MMU_ENABLED)
149   {
150      const BATENT *bat;
151      UINT32 address;
152      UINT32 sr, vsid, hash;
153      UINT32 pteg_address;
154      UINT32 target_pte, bl, mask;
155      UINT64 pte;
156      UINT64 *pteg_ptr[2];
157      int i, hash_type;
158      UINT32 dsisr = DSISR_PROT;
139   const BATENT *bat;
140   UINT32 address;
141   UINT32 sr, vsid, hash;
142   UINT32 pteg_address;
143   UINT32 target_pte, bl, mask;
144   UINT64 pte;
145   UINT64 *pteg_ptr[2];
146   int i, hash_type;
147   UINT32 dsisr = DSISR_PROT;
159148
160      bat = (flags & PPC_TRANSLATE_CODE) ? ppc.ibat : ppc.dbat;
149   bat = (flags & PPC_TRANSLATE_CODE) ? ppc.ibat : ppc.dbat;
161150
162      address = *addr_ptr;
151   address = *addr_ptr;
163152
164      /* first check the block address translation table */
165      for (i = 0; i < 4; i++)
153   /* first check the block address translation table */
154   for (i = 0; i < 4; i++)
155   {
156      if (bat[i].u & ((MSR & MSR_PR) ? 0x00000001 : 0x00000002))
166157      {
167         if (bat[i].u & ((MSR & MSR_PR) ? 0x00000001 : 0x00000002))
158         bl = bat[i].u & 0x00001FFC;
159         mask = (~bl << 15) & 0xFFFE0000;
160
161         if ((address & mask) == (bat[i].u & 0xFFFE0000))
168162         {
169            bl = bat[i].u & 0x00001FFC;
170            mask = (~bl << 15) & 0xFFFE0000;
163            if (ppc_is_protected(bat[i].l, flags))
164               goto exception;
171165
172            if ((address & mask) == (bat[i].u & 0xFFFE0000))
173            {
174               if (ppc_is_protected(bat[i].l, flags))
175                  goto exception;
176
177               *addr_ptr = (bat[i].l & 0xFFFE0000)
178                  | (address & ((bl << 15) | 0x0001FFFF));
179               return 1;
180            }
166            *addr_ptr = (bat[i].l & 0xFFFE0000)
167               | (address & ((bl << 15) | 0x0001FFFF));
168            return 1;
181169         }
182170      }
171   }
183172
184      /* now try page address translation */
185      sr = ppc.sr[(address >> 28) & 0x0F];
186      if (sr & 0x80000000)
187      {
188         /* direct store translation */
189         if ((flags & PPC_TRANSLATE_NOEXCEPTION) == 0)
190            fatalerror("ppc: direct store translation not yet implemented");
191         return 0;
192      }
193      else
194      {
195         /* is no execute is set? */
196         if ((flags & PPC_TRANSLATE_CODE) && (sr & 0x10000000))
197            goto exception;
173   /* now try page address translation */
174   sr = ppc.sr[(address >> 28) & 0x0F];
175   if (sr & 0x80000000)
176   {
177      /* direct store translation */
178      if ((flags & PPC_TRANSLATE_NOEXCEPTION) == 0)
179         fatalerror("ppc: direct store translation not yet implemented");
180      return 0;
181   }
182   else
183   {
184      /* is no execute is set? */
185      if ((flags & PPC_TRANSLATE_CODE) && (sr & 0x10000000))
186         goto exception;
198187
199         vsid = sr & 0x00FFFFFF;
200         hash = (vsid & 0x0007FFFF) ^ ((address >> 12) & 0xFFFF);
201         target_pte = (vsid << 7) | ((address >> 22) & 0x3F) | 0x80000000;
188      vsid = sr & 0x00FFFFFF;
189      hash = (vsid & 0x0007FFFF) ^ ((address >> 12) & 0xFFFF);
190      target_pte = (vsid << 7) | ((address >> 22) & 0x3F) | 0x80000000;
202191
203         /* we have to try both types of hashes */
204         for (hash_type = 0; hash_type <= 1; hash_type++)
205         {
206            pteg_address = (ppc.sdr1 & 0xFFFF0000)
207               | (((ppc.sdr1 & 0x01FF) & (hash >> 10)) << 16)
208               | ((hash & 0x03FF) << 6);
192      /* we have to try both types of hashes */
193      for (hash_type = 0; hash_type <= 1; hash_type++)
194      {
195         pteg_address = (ppc.sdr1 & 0xFFFF0000)
196            | (((ppc.sdr1 & 0x01FF) & (hash >> 10)) << 16)
197            | ((hash & 0x03FF) << 6);
209198
210            pteg_ptr[hash_type] = ppc->program->get_read_ptr(pteg_address);
211            if (pteg_ptr[hash_type])
199         pteg_ptr[hash_type] = ppc->program->get_read_ptr(pteg_address);
200         if (pteg_ptr[hash_type])
201         {
202            for (i = 0; i < 8; i++)
212203            {
213               for (i = 0; i < 8; i++)
204               pte = pteg_ptr[hash_type][i];
205
206               /* is valid? */
207               if (((pte >> 32) & 0xFFFFFFFF) == target_pte)
214208               {
215                  pte = pteg_ptr[hash_type][i];
209                  if (ppc_is_protected((UINT32) pte, flags))
210                     goto exception;
216211
217                  /* is valid? */
218                  if (((pte >> 32) & 0xFFFFFFFF) == target_pte)
219                  {
220                     if (ppc_is_protected((UINT32) pte, flags))
221                        goto exception;
222
223                     *addr_ptr = ((UINT32) (pte & 0xFFFFF000))
224                        | (address & 0x0FFF);
225                     return 1;
226                  }
212                  *addr_ptr = ((UINT32) (pte & 0xFFFFF000))
213                     | (address & 0x0FFF);
214                  return 1;
227215               }
228216            }
229
230            hash ^= 0x7FFFF;
231            target_pte ^= 0x40;
232217         }
233218
234         if (DUMP_PAGEFAULTS)
219         hash ^= 0x7FFFF;
220         target_pte ^= 0x40;
221      }
222
223      if (DUMP_PAGEFAULTS)
224      {
225         mame_printf_debug("PAGE FAULT: address=%08X PC=%08X SDR1=%08X MSR=%08X\n", address, ppc.pc, ppc.sdr1, ppc.msr);
226         mame_printf_debug("\n");
227
228         for (i = 0; i < 4; i++)
235229         {
236            mame_printf_debug("PAGE FAULT: address=%08X PC=%08X SDR1=%08X MSR=%08X\n", address, ppc.pc, ppc.sdr1, ppc.msr);
237            mame_printf_debug("\n");
230            bl = bat[i].u & 0x00001FFC;
231            mask = (~bl << 15) & 0xFFFE0000;
232            mame_printf_debug("    BAT[%d]=%08X%08X    (A & %08X = %08X)\n", i, bat[i].u, bat[i].l,
233               mask, bat[i].u & 0xFFFE0000);
234         }
235         mame_printf_debug("\n");
236         mame_printf_debug("    VSID=%06X HASH=%05X HASH\'=%05X\n", vsid, hash, hash ^ 0x7FFFF);
238237
239            for (i = 0; i < 4; i++)
238         for (hash_type = 0; hash_type <= 1; hash_type++)
239         {
240            if (pteg_ptr[hash_type])
240241            {
241               bl = bat[i].u & 0x00001FFC;
242               mask = (~bl << 15) & 0xFFFE0000;
243               mame_printf_debug("    BAT[%d]=%08X%08X    (A & %08X = %08X)\n", i, bat[i].u, bat[i].l,
244                  mask, bat[i].u & 0xFFFE0000);
245            }
246            mame_printf_debug("\n");
247            mame_printf_debug("    VSID=%06X HASH=%05X HASH\'=%05X\n", vsid, hash, hash ^ 0x7FFFF);
248
249            for (hash_type = 0; hash_type <= 1; hash_type++)
250            {
251               if (pteg_ptr[hash_type])
242               for (i = 0; i < 8; i++)
252243               {
253                  for (i = 0; i < 8; i++)
254                  {
255                     pte = pteg_ptr[hash_type][i];
256                     mame_printf_debug("    PTE[%i%c]=%08X%08X\n",
257                        i,
258                        hash_type ? '\'' : ' ',
259                        (unsigned) (pte >> 32),
260                        (unsigned) (pte >> 0));
261                  }
244                  pte = pteg_ptr[hash_type][i];
245                  mame_printf_debug("    PTE[%i%c]=%08X%08X\n",
246                     i,
247                     hash_type ? '\'' : ' ',
248                     (unsigned) (pte >> 32),
249                     (unsigned) (pte >> 0));
262250               }
263251            }
264252         }
265253      }
254   }
266255
267      dsisr = DSISR_PAGE;
256   dsisr = DSISR_PAGE;
268257
269258exception:
270      /* lookup failure - exception */
271      if ((flags & PPC_TRANSLATE_NOEXCEPTION) == 0)
259   /* lookup failure - exception */
260   if ((flags & PPC_TRANSLATE_NOEXCEPTION) == 0)
261   {
262      if (flags & PPC_TRANSLATE_CODE)
272263      {
273         if (flags & PPC_TRANSLATE_CODE)
274         {
275            ppc_exception(EXCEPTION_ISI);
276         }
264         ppc_exception(EXCEPTION_ISI);
265      }
266      else
267      {
268         ppc.dar = address;
269         if (flags & PPC_TRANSLATE_WRITE)
270            ppc.dsisr = dsisr | DSISR_STORE;
277271         else
278         {
279            ppc.dar = address;
280            if (flags & PPC_TRANSLATE_WRITE)
281               ppc.dsisr = dsisr | DSISR_STORE;
282            else
283               ppc.dsisr = dsisr;
272            ppc.dsisr = dsisr;
284273
285            ppc_exception(EXCEPTION_DSI);
286         }
274         ppc_exception(EXCEPTION_DSI);
287275      }
288      return 0;
289276   }
290   else
291   {
292      /* MMU not enabled in MAME; model3 drivers don't work properly */
293      return 1;
294   }
277   return 0;
295278}
296279
297280static int ppc_translate_address_cb(int space, offs_t *addr)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team