/[gxemul]/trunk/src/cpus/memory_mips_v2p.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/cpus/memory_mips_v2p.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 20 by dpavlin, Mon Oct 8 16:19:23 2007 UTC revision 28 by dpavlin, Mon Oct 8 16:20:26 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2006  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: memory_mips_v2p.c,v 1.2 2005/11/11 13:23:16 debug Exp $   *  $Id: memory_mips_v2p.c,v 1.7 2006/07/16 13:32:26 debug Exp $
  *  
  *  Included from memory.c.  
29   */   */
30    
31    
32  /*  /*
33   *  translate_address():   *  translate_v2p():
34   *   *
35   *  Don't call this function is userland_emul is non-NULL, or cpu is NULL.   *  Don't call this function is userland_emul is non-NULL, or cpu is NULL.
36   *   *
# Line 44  Line 42 
42   *      2  Success, the page is read/write   *      2  Success, the page is read/write
43   */   */
44  int TRANSLATE_ADDRESS(struct cpu *cpu, uint64_t vaddr,  int TRANSLATE_ADDRESS(struct cpu *cpu, uint64_t vaddr,
45          uint64_t *return_addr, int flags)          uint64_t *return_paddr, int flags)
46  {  {
47          int writeflag = flags & FLAG_WRITEFLAG? MEM_WRITE : MEM_READ;          int writeflag = flags & FLAG_WRITEFLAG? MEM_WRITE : MEM_READ;
48          int no_exceptions = flags & FLAG_NOEXCEPTIONS;          int no_exceptions = flags & FLAG_NOEXCEPTIONS;
         int instr = flags & FLAG_INSTR;  
49          int ksu, use_tlb, status, i;          int ksu, use_tlb, status, i;
50          uint64_t vaddr_vpn2=0, vaddr_asid=0;          uint64_t vaddr_vpn2=0, vaddr_asid=0;
51          int exccode, tlb_refill;          int exccode, tlb_refill;
52          struct mips_coproc *cp0;          struct mips_coproc *cp0;
         int bintrans_cached = cpu->machine->bintrans_enable;  
53    
54  #ifdef V2P_MMU3K  #ifdef V2P_MMU3K
55          const int x_64 = 0;          const int x_64 = 0;
# Line 85  int TRANSLATE_ADDRESS(struct cpu *cpu, u Line 81  int TRANSLATE_ADDRESS(struct cpu *cpu, u
81  #endif  /*  !V2P_MMU3K  */  #endif  /*  !V2P_MMU3K  */
82    
83    
 #ifdef USE_TINY_CACHE  
         /*  
          *  Check the tiny translation cache first:  
          *  
          *  Only userland addresses are checked, because other addresses  
          *  are probably better of being statically translated, or through  
          *  the TLB.  (Note: When running with 64-bit addresses, this  
          *  will still produce the correct result. At worst, we check the  
          *  cache in vain, but the result should still be correct.)  
          */  
         if (!bintrans_cached &&  
             (vaddr & 0xc0000000ULL) != 0x80000000ULL) {  
                 int i, wf = 1 + (writeflag == MEM_WRITE);  
                 uint64_t vaddr_shift_12 = vaddr >> 12;  
   
                 if (instr) {  
                         /*  Code:  */  
                         for (i=0; i<N_TRANSLATION_CACHE_INSTR; i++) {  
                                 if (cpu->cd.mips.translation_cache_instr[i].wf  
                                     >= wf && vaddr_shift_12 == (cpu->cd.mips.  
                                     translation_cache_instr[i].vaddr_pfn)) {  
                                         *return_addr = cpu->cd.mips.  
                                             translation_cache_instr[i].paddr  
                                             | (vaddr & 0xfff);  
                                         return cpu->cd.mips.  
                                             translation_cache_instr[i].wf;  
                                 }  
                         }  
                 } else {  
                         /*  Data:  */  
                         for (i=0; i<N_TRANSLATION_CACHE_DATA; i++) {  
                                 if (cpu->cd.mips.translation_cache_data[i].wf  
                                     >= wf && vaddr_shift_12 == (cpu->cd.mips.  
                                     translation_cache_data[i].vaddr_pfn)) {  
                                         *return_addr = cpu->cd.mips.  
                                             translation_cache_data[i].paddr  
                                             | (vaddr & 0xfff);  
                                         return cpu->cd.mips.  
                                             translation_cache_data[i].wf;  
                                 }  
                         }  
                 }  
         }  
 #endif  
   
84          exccode = -1;          exccode = -1;
85          tlb_refill = 1;          tlb_refill = 1;
86    
# Line 242  int TRANSLATE_ADDRESS(struct cpu *cpu, u Line 193  int TRANSLATE_ADDRESS(struct cpu *cpu, u
193                   *  On IP27 (and probably others), addresses such as                   *  On IP27 (and probably others), addresses such as
194                   *  0x92... and 0x96... have to do with NUMA stuff.                   *  0x92... and 0x96... have to do with NUMA stuff.
195                   */                   */
196                  *return_addr = vaddr & (((uint64_t)1 << 44) - 1);                  *return_paddr = vaddr & (((uint64_t)1 << 44) - 1);
197                  return 2;                  return 2;
198          }          }
199    
# Line 266  bugs are triggered.  */ Line 217  bugs are triggered.  */
217                          /*  kseg0, kseg1:  */                          /*  kseg0, kseg1:  */
218                          if (vaddr >= (uint64_t)0xffffffff80000000ULL &&                          if (vaddr >= (uint64_t)0xffffffff80000000ULL &&
219                              vaddr <= (uint64_t)0xffffffffbfffffffULL) {                              vaddr <= (uint64_t)0xffffffffbfffffffULL) {
220                                  *return_addr = vaddr & 0x1fffffff;                                  *return_paddr = vaddr & 0x1fffffff;
221                                  return 2;                                  return 2;
222                          }                          }
223    
# Line 280  bugs are triggered.  */ Line 231  bugs are triggered.  */
231    
232          if (use_tlb) {          if (use_tlb) {
233  #ifndef V2P_MMU3K  #ifndef V2P_MMU3K
234                  int odd = 0, cached_lo1 = 0;                  int odd = 0;
235                    uint64_t cached_lo1 = 0;
236  #endif  #endif
237                  int g_bit, v_bit, d_bit;                  int g_bit, v_bit, d_bit;
238                  uint64_t cached_hi, cached_lo0;                  uint64_t cached_hi, cached_lo0;
# Line 378  bugs are triggered.  */ Line 330  bugs are triggered.  */
330                          /*  Is there a VPN and ASID match?  */                          /*  Is there a VPN and ASID match?  */
331                          if (entry_vpn2 == vaddr_vpn2 &&                          if (entry_vpn2 == vaddr_vpn2 &&
332                              (entry_asid == vaddr_asid || g_bit)) {                              (entry_asid == vaddr_asid || g_bit)) {
333                                  /*  debug("OK MAP 1, i=%i { vaddr=%016llx "                                  /*  debug("OK MAP 1, i=%i { vaddr=%016"PRIx64" "
334                                      "==> paddr %016llx v=%i d=%i "                                      "==> paddr %016"PRIx64" v=%i d=%i "
335                                      "asid=0x%02x }\n", i, (long long)vaddr,                                      "asid=0x%02x }\n", i, (uint64_t) vaddr,
336                                      (long long) *return_addr, v_bit?1:0,                                      (uint64_t) *return_paddr, v_bit?1:0,
337                                      d_bit?1:0, vaddr_asid);  */                                      d_bit?1:0, vaddr_asid);  */
338                                  if (v_bit) {                                  if (v_bit) {
339                                          if (d_bit || (!d_bit &&                                          if (d_bit || (!d_bit &&
340                                              writeflag == MEM_READ)) {                                              writeflag == MEM_READ)) {
341                                                  uint64_t paddr;                                                  uint64_t paddr;
342                                                  /*  debug("OK MAP 2!!! { w=%i "                                                  /*  debug("OK MAP 2!!! { w=%i "
343                                                      "vaddr=%016llx ==> d=%i v="                                                      "vaddr=%016"PRIx64" ==> "
344                                                      "%i paddr %016llx ",                                                      "d=%i v=%i paddr %016"
345                                                      writeflag, (long long)vaddr,                                                      PRIx64" ",
346                                                        writeflag, (uint64_t)vaddr,
347                                                      d_bit?1:0, v_bit?1:0,                                                      d_bit?1:0, v_bit?1:0,
348                                                      (long long) *return_addr);                                                      (uint64_t) *return_paddr);
349                                                      debug(", tlb entry %2i: ma"                                                      debug(", tlb entry %2i: ma"
350                                                      "sk=%016llx hi=%016llx lo0"                                                      "sk=%016"PRIx64" hi=%016"
351                                                      "=%016llx lo1=%016llx\n",                                                      PRIx64" lo0=%016"PRIx64
352                                                        " lo1=%016"PRIx64"\n",
353                                                      i, cp0->tlbs[i].mask, cp0->                                                      i, cp0->tlbs[i].mask, cp0->
354                                                      tlbs[i].hi, cp0->tlbs[i].                                                      tlbs[i].hi, cp0->tlbs[i].
355                                                      lo0, cp0->tlbs[i].lo1);                                                      lo0, cp0->tlbs[i].lo1);
# Line 413  bugs are triggered.  */ Line 367  bugs are triggered.  */
367                                                      (vaddr & pmask);                                                      (vaddr & pmask);
368  #endif  #endif
369    
370                                                  /*                                                  *return_paddr = paddr;
                                                  *  Enter into the tiny trans-  
                                                  *  lation cache (if enabled)  
                                                  *  and return:  
                                                  */  
                                                 if (!bintrans_cached)  
                                                         insert_into_tiny_cache(  
                                                             cpu, instr, d_bit?  
                                                             MEM_WRITE :  
                                                             MEM_READ,  
                                                             vaddr, paddr);  
   
                                                 *return_addr = paddr;  
371                                                  return d_bit? 2 : 1;                                                  return d_bit? 2 : 1;
372                                          } else {                                          } else {
373                                                  /*  TLB modif. exception  */                                                  /*  TLB modif. exception  */

Legend:
Removed from v.20  
changed lines
  Added in v.28

  ViewVC Help
Powered by ViewVC 1.1.26