/[gxemul]/trunk/src/cpus/memory_arm.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_arm.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) 2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2005-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_arm.c,v 1.30 2005/11/05 17:56:46 debug Exp $   *  $Id: memory_arm.c,v 1.36 2006/07/14 16:33:28 debug Exp $
29   *   *
30   *   *
31   *  TODO/NOTE:  The B and/or C bits could also cause the return value to   *  TODO/NOTE:  The B and/or C bits could also cause the return value to
# Line 37  Line 37 
37  #include <stdlib.h>  #include <stdlib.h>
38  #include <string.h>  #include <string.h>
39    
40    #include "arm_cpu_types.h"
41  #include "cpu.h"  #include "cpu.h"
42  #include "memory.h"  #include "memory.h"
43  #include "misc.h"  #include "misc.h"
# Line 47  extern int quiet_mode; Line 48  extern int quiet_mode;
48    
49    
50  /*  /*
51   *  arm_translate_address():   *  arm_translate_v2p():
52   *   *
53   *  Address translation with the MMU disabled.   *  Address translation with the MMU disabled. (Just treat the virtual address
54     *  as a physical address.)
55   */   */
56  int arm_translate_address(struct cpu *cpu, uint64_t vaddr64,  int arm_translate_v2p(struct cpu *cpu, uint64_t vaddr64,
57          uint64_t *return_addr, int flags)          uint64_t *return_paddr, int flags)
58  {  {
59          *return_addr = vaddr64 & 0xffffffff;          *return_paddr = vaddr64 & 0xffffffff;
60    
61          return 2;          return 2;
62  }  }
63    
# Line 100  static int arm_check_access(struct cpu * Line 103  static int arm_check_access(struct cpu *
103    
104    
105  /*  /*
106   *  arm_translate_address_mmu():   *  arm_translate_v2p_mmu():
107   *   *
108   *  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.
109   *   *
# Line 112  static int arm_check_access(struct cpu * Line 115  static int arm_check_access(struct cpu *
115   *  If this is a 1KB page access, then the return value is ORed with   *  If this is a 1KB page access, then the return value is ORed with
116   *  MEMORY_NOT_FULL_PAGE.   *  MEMORY_NOT_FULL_PAGE.
117   */   */
118  int arm_translate_address_mmu(struct cpu *cpu, uint64_t vaddr64,  int arm_translate_v2p_mmu(struct cpu *cpu, uint64_t vaddr64,
119          uint64_t *return_addr, int flags)          uint64_t *return_paddr, int flags)
120  {  {
121          unsigned char *q;          unsigned char *q;
122          uint32_t addr, d=0, d2 = (uint32_t)(int32_t)-1, ptba, vaddr = vaddr64;          uint32_t addr, d=0, d2 = (uint32_t)(int32_t)-1, ptba, vaddr = vaddr64;
# Line 133  int arm_translate_address_mmu(struct cpu Line 136  int arm_translate_address_mmu(struct cpu
136    
137          if (cpu->cd.arm.translation_table == NULL ||          if (cpu->cd.arm.translation_table == NULL ||
138              cpu->cd.arm.ttb != cpu->cd.arm.last_ttb) {              cpu->cd.arm.ttb != cpu->cd.arm.last_ttb) {
                 uint32_t ofs;  
139                  cpu->cd.arm.translation_table = memory_paddr_to_hostaddr(                  cpu->cd.arm.translation_table = memory_paddr_to_hostaddr(
140                      cpu->mem, cpu->cd.arm.ttb & 0x0fffffff, 0);                      cpu->mem, cpu->cd.arm.ttb & 0x0fffffff, 0);
                 if (cpu->cd.arm.translation_table != NULL) {  
                         ofs = cpu->cd.arm.ttb & ((1 << BITS_PER_MEMBLOCK) - 1);  
                         cpu->cd.arm.translation_table += ofs;  
                 }  
141                  cpu->cd.arm.last_ttb = cpu->cd.arm.ttb;                  cpu->cd.arm.last_ttb = cpu->cd.arm.ttb;
142          }          }
143    
# Line 177  int arm_translate_address_mmu(struct cpu Line 175  int arm_translate_address_mmu(struct cpu
175                          printf("arm memory blah blah adfh asfg asdgasdg\n");                          printf("arm memory blah blah adfh asfg asdgasdg\n");
176                          exit(1);                          exit(1);
177                  }                  }
178                  d2 = *(uint32_t *)(q + (addr & ((1 << BITS_PER_MEMBLOCK) - 1)));                  d2 = *(uint32_t *)(q);
179  #ifdef HOST_LITTLE_ENDIAN  #ifdef HOST_LITTLE_ENDIAN
180                  if (cpu->byte_order == EMUL_BIG_ENDIAN)                  if (cpu->byte_order == EMUL_BIG_ENDIAN)
181  #else  #else
# Line 197  int arm_translate_address_mmu(struct cpu Line 195  int arm_translate_address_mmu(struct cpu
195                          case 0xc000:    ap >>= 6; break;                          case 0xc000:    ap >>= 6; break;
196                          }                          }
197                          ap &= 3;                          ap &= 3;
198                          *return_addr = (d2 & 0xffff0000) | (vaddr & 0x0000ffff);                          *return_paddr = (d2 & 0xffff0000)|(vaddr & 0x0000ffff);
199                          break;                          break;
200                  case 3: {                  case 3: if (cpu->cd.arm.cpu_type.flags & ARM_XSCALE) {
201                                  static int first = 1;                                  /*  4KB page (Xscale)  */
202                                  if (first) {                                  subpage = 0;
203                                          fatal("[ WARNING! ARM course second "                          } else {
204                                              "level page table seems to contain"                                  /*  1KB page  */
205                                              " tiny pages; treating as 4K ]\n");                                  subpage = 1;
206                                          first = 0;                                  ap = (d2 >> 4) & 3;
207                                  }                                  *return_paddr = (d2 & 0xfffffc00) |
208                                        (vaddr & 0x000003ff);
209                                    break;
210                          }                          }
211                          subpage = 1;                          /*  NOTE: Fall-through for XScale!  */
212                  case 2: /*  4KB page:  */                  case 2: /*  4KB page:  */
213                          ap3 = (d2 >> 10) & 3;                          ap3 = (d2 >> 10) & 3;
214                          ap2 = (d2 >>  8) & 3;                          ap2 = (d2 >>  8) & 3;
# Line 220  int arm_translate_address_mmu(struct cpu Line 220  int arm_translate_address_mmu(struct cpu
220                          case 0x800: ap = ap2; break;                          case 0x800: ap = ap2; break;
221                          default:    ap = ap3;                          default:    ap = ap3;
222                          }                          }
223                          /*  Ugly hack: (TODO)  */                          /*  NOTE: Ugly hack for XScale:  */
224                          if ((d2 & 3) == 3)                          if ((d2 & 3) == 3) {
225                                    /*  Treated as 4KB page:  */
226                                  ap = ap0;                                  ap = ap0;
227                          if (ap0 != ap1 || ap0 != ap2 || ap0 != ap3)                          } else {
228                                  subpage = 1;                                  if (ap0 != ap1 || ap0 != ap2 || ap0 != ap3)
229                          *return_addr = (d2 & 0xfffff000) | (vaddr & 0x00000fff);                                          subpage = 1;
230                          break;                          }
231  #if 0                          *return_paddr = (d2 & 0xfffff000)|(vaddr & 0x00000fff);
                 case 3: /*  1KB page:  */  
                         subpage = 1;  
                         ap = (d2 >> 4) & 3;  
                         *return_addr = (d2 & 0xfffffc00) | (vaddr & 0x000003ff);  
232                          break;                          break;
 #endif  
233                  }                  }
234                  access = arm_check_access(cpu, ap, dav, user);                  access = arm_check_access(cpu, ap, dav, user);
235                  if (access > writeflag)                  if (access > writeflag)
# Line 246  int arm_translate_address_mmu(struct cpu Line 242  int arm_translate_address_mmu(struct cpu
242                          fs = FAULT_DOMAIN_S;                          fs = FAULT_DOMAIN_S;
243                          goto exception_return;                          goto exception_return;
244                  }                  }
245                  *return_addr = (d & 0xfff00000) | (vaddr & 0x000fffff);                  *return_paddr = (d & 0xfff00000) | (vaddr & 0x000fffff);
246                  ap = (d >> 10) & 3;                  ap = (d >> 10) & 3;
247                  access = arm_check_access(cpu, ap, dav, user);                  access = arm_check_access(cpu, ap, dav, user);
248                  if (access > writeflag)                  if (access > writeflag)
# Line 267  exception_return: Line 263  exception_return:
263                  fatal("{ arm memory fault: vaddr=0x%08x domain=%i dav=%i ap=%i "                  fatal("{ arm memory fault: vaddr=0x%08x domain=%i dav=%i ap=%i "
264                      "access=%i user=%i", (int)vaddr, domain, dav, ap,                      "access=%i user=%i", (int)vaddr, domain, dav, ap,
265                      access, user);                      access, user);
266                  fatal(" d=0x%08x d2=0x%08x }\n", d, d2);                  fatal(" d=0x%08x d2=0x%08x pc=0x%08x }\n", d, d2, (int)cpu->pc);
267          }          }
268    
269          if (instr)          if (instr)

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

  ViewVC Help
Powered by ViewVC 1.1.26