/[gxemul]/trunk/src/memory_rw.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/memory_rw.c

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

revision 2 by dpavlin, Mon Oct 8 16:17:48 2007 UTC revision 18 by dpavlin, Mon Oct 8 16:19:11 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: memory_rw.c,v 1.10 2005/03/01 08:23:55 debug Exp $   *  $Id: memory_rw.c,v 1.75 2005/10/27 14:01:12 debug Exp $
29   *   *
30   *  Generic memory_rw(), with special hacks for specific CPU families.   *  Generic memory_rw(), with special hacks for specific CPU families.
31   *   *
# Line 68  Line 68 
68  int MEMORY_RW(struct cpu *cpu, struct memory *mem, uint64_t vaddr,  int MEMORY_RW(struct cpu *cpu, struct memory *mem, uint64_t vaddr,
69          unsigned char *data, size_t len, int writeflag, int cache_flags)          unsigned char *data, size_t len, int writeflag, int cache_flags)
70  {  {
71    #ifdef MEM_ALPHA
72            const int offset_mask = 0x1fff;
73    #else
74            const int offset_mask = 0xfff;
75    #endif
76    
77  #ifndef MEM_USERLAND  #ifndef MEM_USERLAND
78          int ok = 1;          int ok = 1;
79  #endif  #endif
80          uint64_t paddr;          uint64_t paddr;
81          int cache, no_exceptions, offset;          int cache, no_exceptions, offset;
82          unsigned char *memblock;          unsigned char *memblock;
83  #ifdef BINTRANS  #ifdef MEM_MIPS
84          int bintrans_cached = cpu->machine->bintrans_enable;          int bintrans_cached = cpu->machine->bintrans_enable;
85  #endif  #endif
86            int bintrans_device_danger = 0;
87    
88          no_exceptions = cache_flags & NO_EXCEPTIONS;          no_exceptions = cache_flags & NO_EXCEPTIONS;
89          cache = cache_flags & CACHE_FLAGS_MASK;          cache = cache_flags & CACHE_FLAGS_MASK;
90    
91  #ifdef MEM_PPC  #ifdef MEM_X86
92          if (cpu->cd.ppc.bits == 32)          /*  Real-mode wrap-around:  */
93                  vaddr &= 0xffffffff;          if (REAL_MODE && !(cache_flags & PHYSICAL)) {
94  #endif                  if ((vaddr & 0xffff) + len > 0x10000) {
95                            /*  Do one byte at a time:  */
96                            int res = 0, i;
97                            for (i=0; i<len; i++)
98                                    res = MEMORY_RW(cpu, mem, vaddr+i, &data[i], 1,
99                                        writeflag, cache_flags);
100                            return res;
101                    }
102            }
103    
104  #ifdef MEM_URISC          /*  Crossing a page boundary? Then do one byte at a time:  */
105          {          if ((vaddr & 0xfff) + len > 0x1000 && !(cache_flags & PHYSICAL)
106                  uint64_t mask = (uint64_t) -1;              && cpu->cd.x86.cr[0] & X86_CR0_PG) {
107                  if (cpu->cd.urisc.wordlen < 64)                  /*  For WRITES: Read ALL BYTES FIRST and write them back!!!
108                          mask = ((int64_t)1 << cpu->cd.urisc.wordlen) - 1;                      Then do a write of all the new bytes. This is to make sure
109                  vaddr &= mask;                      than both pages around the boundary are writable so we don't
110                        do a partial write.  */
111                    int res = 0, i;
112                    if (writeflag == MEM_WRITE) {
113                            unsigned char tmp;
114                            for (i=0; i<len; i++) {
115                                    res = MEMORY_RW(cpu, mem, vaddr+i, &tmp, 1,
116                                        MEM_READ, cache_flags);
117                                    if (!res)
118                                            return 0;
119                                    res = MEMORY_RW(cpu, mem, vaddr+i, &tmp, 1,
120                                        MEM_WRITE, cache_flags);
121                                    if (!res)
122                                            return 0;
123                            }
124                            for (i=0; i<len; i++) {
125                                    res = MEMORY_RW(cpu, mem, vaddr+i, &data[i], 1,
126                                        MEM_WRITE, cache_flags);
127                                    if (!res)
128                                            return 0;
129                            }
130                    } else {
131                            for (i=0; i<len; i++) {
132                                    /*  Do one byte at a time:  */
133                                    res = MEMORY_RW(cpu, mem, vaddr+i, &data[i], 1,
134                                        writeflag, cache_flags);
135                                    if (!res) {
136                                            if (cache == CACHE_INSTRUCTION) {
137                                                    fatal("FAILED instruction "
138                                                        "fetch across page boundar"
139                                                        "y: todo. vaddr=0x%08x\n",
140                                                        (int)vaddr);
141                                                    cpu->running = 0;
142                                            }
143                                            return 0;
144                                    }
145                            }
146                    }
147                    return res;
148          }          }
149  #endif  #endif  /*  X86  */
150    
151  #ifdef MEM_MIPS  #ifdef MEM_MIPS
 #ifdef BINTRANS  
152          if (bintrans_cached) {          if (bintrans_cached) {
153                  if (cache == CACHE_INSTRUCTION) {                  if (cache == CACHE_INSTRUCTION) {
154                          cpu->cd.mips.pc_bintrans_host_4kpage = NULL;                          cpu->cd.mips.pc_bintrans_host_4kpage = NULL;
155                          cpu->cd.mips.pc_bintrans_paddr_valid = 0;                          cpu->cd.mips.pc_bintrans_paddr_valid = 0;
156                  }                  }
157          }          }
 #endif  
158  #endif  /*  MEM_MIPS  */  #endif  /*  MEM_MIPS  */
159    
160  #ifdef MEM_USERLAND  #ifdef MEM_USERLAND
161    #ifdef MEM_ALPHA
162            paddr = vaddr;
163    #else
164          paddr = vaddr & 0x7fffffff;          paddr = vaddr & 0x7fffffff;
165    #endif
166          goto have_paddr;          goto have_paddr;
167  #endif  #endif
168    
# Line 130  int MEMORY_RW(struct cpu *cpu, struct me Line 186  int MEMORY_RW(struct cpu *cpu, struct me
186    
187          if (cache_flags & PHYSICAL || cpu->translate_address == NULL) {          if (cache_flags & PHYSICAL || cpu->translate_address == NULL) {
188                  paddr = vaddr;                  paddr = vaddr;
189    
190    #ifdef MEM_ALPHA
191                    /*  paddr &= 0x1fffffff;  For testalpha  */
192                    paddr &= 0x000003ffffffffffULL;
193    #endif
194    
195    #ifdef MEM_IA64
196                    /*  For testia64  */
197                    paddr &= 0x3fffffff;
198    #endif
199    
200    #ifdef MEM_PPC
201                    if (cpu->cd.ppc.bits == 32)
202                            paddr &= 0xffffffff;
203    #endif
204    
205    #ifdef MEM_SH
206                    paddr &= 0xffffffff;
207    #endif
208          } else {          } else {
209                  ok = cpu->translate_address(cpu, vaddr, &paddr,                  ok = cpu->translate_address(cpu, vaddr, &paddr,
210                      (writeflag? FLAG_WRITEFLAG : 0) +                      (writeflag? FLAG_WRITEFLAG : 0) +
211                      (no_exceptions? FLAG_NOEXCEPTIONS : 0)                      (no_exceptions? FLAG_NOEXCEPTIONS : 0)
212    #ifdef MEM_X86
213                        + (cache_flags & NO_SEGMENTATION)
214    #endif
215    #ifdef MEM_ARM
216                        + (cache_flags & MEMORY_USER_ACCESS)
217    #endif
218                      + (cache==CACHE_INSTRUCTION? FLAG_INSTR : 0));                      + (cache==CACHE_INSTRUCTION? FLAG_INSTR : 0));
219                  /*  If the translation caused an exception, or was invalid in                  /*  If the translation caused an exception, or was invalid in
220                      some way, we simply return without doing the memory                      some way, we simply return without doing the memory
# Line 143  int MEMORY_RW(struct cpu *cpu, struct me Line 224  int MEMORY_RW(struct cpu *cpu, struct me
224          }          }
225    
226    
227    #ifdef MEM_X86
228            /*  DOS debugging :-)  */
229            if (!quiet_mode && !(cache_flags & PHYSICAL)) {
230                    if (paddr >= 0x400 && paddr <= 0x4ff)
231                            debug("{ PC BIOS DATA AREA: %s 0x%x }\n", writeflag ==
232                                MEM_WRITE? "writing to" : "reading from",
233                                (int)paddr);
234    #if 0
235                    if (paddr >= 0xf0000 && paddr <= 0xfffff)
236                            debug("{ BIOS ACCESS: %s 0x%x }\n",
237                                writeflag == MEM_WRITE? "writing to" :
238                                "reading from", (int)paddr);
239    #endif
240            }
241    #endif
242    
243  #ifdef MEM_MIPS  #ifdef MEM_MIPS
244          /*          /*
245           *  If correct cache emulation is enabled, and we need to simluate           *  If correct cache emulation is enabled, and we need to simluate
# Line 164  int MEMORY_RW(struct cpu *cpu, struct me Line 261  int MEMORY_RW(struct cpu *cpu, struct me
261  #endif  /*  ifndef MEM_USERLAND  */  #endif  /*  ifndef MEM_USERLAND  */
262    
263    
264    #if defined(MEM_MIPS) || defined(MEM_USERLAND)
265  have_paddr:  have_paddr:
266    #endif
267    
268    
269  #ifdef MEM_MIPS  #ifdef MEM_MIPS
270          /*  TODO: How about bintrans vs cache emulation?  */          /*  TODO: How about bintrans vs cache emulation?  */
 #ifdef BINTRANS  
271          if (bintrans_cached) {          if (bintrans_cached) {
272                  if (cache == CACHE_INSTRUCTION) {                  if (cache == CACHE_INSTRUCTION) {
273                          cpu->cd.mips.pc_bintrans_paddr_valid = 1;                          cpu->cd.mips.pc_bintrans_paddr_valid = 1;
274                          cpu->cd.mips.pc_bintrans_paddr = paddr;                          cpu->cd.mips.pc_bintrans_paddr = paddr;
275                  }                  }
276          }          }
 #endif  
277  #endif  /*  MEM_MIPS  */  #endif  /*  MEM_MIPS  */
278    
279    
         if (!(cache_flags & PHYSICAL))  
                 if (no_exceptions)  
                         goto no_exception_access;  
   
280    
281  #ifndef MEM_USERLAND  #ifndef MEM_USERLAND
282          /*          /*
# Line 194  have_paddr: Line 287  have_paddr:
287           *  to a device to           *  to a device to
288           */           */
289          if (paddr >= mem->mmap_dev_minaddr && paddr < mem->mmap_dev_maxaddr) {          if (paddr >= mem->mmap_dev_minaddr && paddr < mem->mmap_dev_maxaddr) {
 #ifdef BINTRANS  
290                  uint64_t orig_paddr = paddr;                  uint64_t orig_paddr = paddr;
 #endif  
291                  int i, start, res;                  int i, start, res;
292    
293                    /*
294                     *  Really really slow, but unfortunately necessary. This is
295                     *  to avoid the folowing scenario:
296                     *
297                     *      a) offsets 0x000..0x123 are normal memory
298                     *      b) offsets 0x124..0x777 are a device
299                     *
300                     *      1) a read is done from offset 0x100. the page is
301                     *         added to the bintrans system as a "RAM" page
302                     *      2) a bintranslated read is done from offset 0x200,
303                     *         which should access the device, but since the
304                     *         entire page is added, it will access non-existant
305                     *         RAM instead, without warning.
306                     *
307                     *  Setting bintrans_device_danger = 1 on accesses which are
308                     *  on _any_ offset on pages that are device mapped avoids
309                     *  this problem, but it is probably not very fast.
310                     */
311                    for (i=0; i<mem->n_mmapped_devices; i++)
312                            if (paddr >= (mem->dev_baseaddr[i] & ~offset_mask) &&
313                                paddr <= ((mem->dev_endaddr[i]-1) | offset_mask)) {
314                                    bintrans_device_danger = 1;
315                                    break;
316                            }
317    
318                  i = start = mem->last_accessed_device;                  i = start = mem->last_accessed_device;
319    
320                  /*  Scan through all devices:  */                  /*  Scan through all devices:  */
321                  do {                  do {
322                          if (paddr >= mem->dev_baseaddr[i] &&                          if (paddr >= mem->dev_baseaddr[i] &&
323                              paddr < mem->dev_baseaddr[i] + mem->dev_length[i]) {                              paddr < mem->dev_endaddr[i]) {
324                                  /*  Found a device, let's access it:  */                                  /*  Found a device, let's access it:  */
325                                  mem->last_accessed_device = i;                                  mem->last_accessed_device = i;
326    
# Line 211  have_paddr: Line 328  have_paddr:
328                                  if (paddr + len > mem->dev_length[i])                                  if (paddr + len > mem->dev_length[i])
329                                          len = mem->dev_length[i] - paddr;                                          len = mem->dev_length[i] - paddr;
330    
331  #ifdef BINTRANS                                  if (cpu->update_translation_table != NULL &&
332                                  if (bintrans_cached && mem->dev_flags[i] &                                      mem->dev_flags[i] & MEM_DYNTRANS_OK) {
                                     MEM_BINTRANS_OK) {  
333                                          int wf = writeflag == MEM_WRITE? 1 : 0;                                          int wf = writeflag == MEM_WRITE? 1 : 0;
334                                            unsigned char *host_addr;
335    
336                                          if (writeflag) {                                          if (!(mem->dev_flags[i] &
337                                                MEM_DYNTRANS_WRITE_OK))
338                                                    wf = 0;
339    
340                                            if (writeflag && wf) {
341                                                  if (paddr < mem->                                                  if (paddr < mem->
342                                                      dev_bintrans_write_low[i])                                                      dev_dyntrans_write_low[i])
343                                                          mem->                                                          mem->
344                                                          dev_bintrans_write_low                                                          dev_dyntrans_write_low
345                                                              [i] =                                                              [i] = paddr &
346                                                              paddr & ~0xfff;                                                              ~offset_mask;
347                                                  if (paddr > mem->                                                  if (paddr >= mem->
348                                                      dev_bintrans_write_high[i])                                                      dev_dyntrans_write_high[i])
349                                                          mem->                                                          mem->
350                                                          dev_bintrans_write_high                                                          dev_dyntrans_write_high
351                                                              [i] = paddr | 0xfff;                                                              [i] = paddr |
352                                                                offset_mask;
353                                          }                                          }
354    
355                                          if (!(mem->dev_flags[i] &                                          if (mem->dev_flags[i] &
356                                              MEM_BINTRANS_WRITE_OK))                                              MEM_EMULATED_RAM) {
357                                                  wf = 0;                                                  /*  MEM_WRITE to force the page
358                                                        to be allocated, if it
359                                          update_translation_table(cpu,                                                      wasn't already  */
360                                              vaddr & ~0xfff,                                                  uint64_t *pp = (uint64_t *)
361                                              mem->dev_bintrans_data[i] +                                                      mem->dev_dyntrans_data[i];
362                                              (paddr & ~0xfff),                                                  uint64_t p = orig_paddr - *pp;
363                                              wf, orig_paddr & ~0xfff);                                                  host_addr =
364                                                        memory_paddr_to_hostaddr(
365                                                        mem, p, MEM_WRITE)
366                                                        + (p & ~offset_mask
367                                                        & ((1 <<
368                                                        BITS_PER_MEMBLOCK) - 1));
369                                            } else {
370                                                    host_addr =
371                                                        mem->dev_dyntrans_data[i] +
372                                                        (paddr & ~offset_mask);
373                                            }
374                                            cpu->update_translation_table(cpu,
375                                                vaddr & ~offset_mask, host_addr,
376                                                wf, orig_paddr & ~offset_mask);
377                                  }                                  }
 #endif  
378    
379                                  res = mem->dev_f[i](cpu, mem, paddr, data, len,                                  res = 0;
380                                      writeflag, mem->dev_extra[i]);                                  if (!no_exceptions || (mem->dev_flags[i] &
381                                        MEM_READING_HAS_NO_SIDE_EFFECTS))
382                                            res = mem->dev_f[i](cpu, mem, paddr,
383                                                data, len, writeflag,
384                                                mem->dev_extra[i]);
385    
386  #ifdef ENABLE_INSTRUCTION_DELAYS  #ifdef ENABLE_INSTRUCTION_DELAYS
387                                  if (res == 0)                                  if (res == 0)
388                                          res = -1;                                          res = -1;
389    
390    #ifdef MEM_MIPS
391                                  cpu->cd.mips.instruction_delay +=                                  cpu->cd.mips.instruction_delay +=
392                                      ( (abs(res) - 1) *                                      ( (abs(res) - 1) *
393                                       cpu->cd.mips.cpu_type.instrs_per_cycle );                                       cpu->cd.mips.cpu_type.instrs_per_cycle );
394  #endif  #endif
395    #endif
396    
397    #ifndef MEM_X86
398                                  /*                                  /*
399                                   *  If accessing the memory mapped device                                   *  If accessing the memory mapped device
400                                   *  failed, then return with a DBE exception.                                   *  failed, then return with a DBE exception.
401                                   */                                   */
402                                  if (res <= 0) {                                  if (res <= 0 && !no_exceptions) {
403                                          debug("%s device '%s' addr %08lx "                                          debug("%s device '%s' addr %08lx "
404                                              "failed\n", writeflag?                                              "failed\n", writeflag?
405                                              "writing to" : "reading from",                                              "writing to" : "reading from",
# Line 268  have_paddr: Line 410  have_paddr:
410  #endif  #endif
411                                          return MEMORY_ACCESS_FAILED;                                          return MEMORY_ACCESS_FAILED;
412                                  }                                  }
413    #endif
414                                  goto do_return_ok;                                  goto do_return_ok;
415                          }                          }
416    
# Line 295  have_paddr: Line 437  have_paddr:
437                                  goto do_return_ok;                                  goto do_return_ok;
438                  }                  }
439                  break;                  break;
 #if 0  
 /*  Remove this, it doesn't work anyway  */  
         case MMU10K:  
                 /*  other cpus:  */  
                 /*  
                  *  SUPER-UGLY HACK for SGI-IP32 PROM, R10000:  
                  *  K0 bits == 0x3 means uncached...  
                  *  
                  *  It seems that during bootup, the SGI-IP32 prom  
                  *  stores a return pointers a 0x80000f10, then tests  
                  *  memory by writing bit patterns to 0xa0000xxx, and  
                  *  then when it's done, reads back the return pointer  
                  *  from 0x80000f10.  
                  *  
                  *  I need to find the correct way to disconnect the  
                  *  cache from the main memory for R10000.  (TODO !!!)  
                  */  
 /*              if ((cpu->cd.mips.coproc[0]->reg[COP0_CONFIG] & 7) == 3) {  */  
 /*  
                 if (cache == CACHE_DATA &&  
                     cpu->r10k_cache_disable_TODO) {  
                         paddr &= ((512*1024)-1);  
                         paddr += 512*1024;  
                 }  
 */  
                 break;  
 #endif  
440          default:          default:
441                  /*  R4000 etc  */                  /*  R4000 etc  */
442                  /*  TODO  */                  /*  TODO  */
# Line 332  have_paddr: Line 447  have_paddr:
447    
448          /*  Outside of physical RAM?  */          /*  Outside of physical RAM?  */
449          if (paddr >= mem->physical_max) {          if (paddr >= mem->physical_max) {
450                  if ((paddr & 0xffff000000ULL) == 0x1f000000) {  #ifdef MEM_MIPS
451                    if ((paddr & 0xffffc00000ULL) == 0x1fc00000) {
452                          /*  Ok, this is PROM stuff  */                          /*  Ok, this is PROM stuff  */
453                  } else if ((paddr & 0xfffff00000ULL) == 0x1ff00000) {                  } else if ((paddr & 0xfffff00000ULL) == 0x1ff00000) {
454                          /*  Sprite reads from this area of memory...  */                          /*  Sprite reads from this area of memory...  */
# Line 340  have_paddr: Line 456  have_paddr:
456                          if (writeflag == MEM_READ)                          if (writeflag == MEM_READ)
457                                  memset(data, 0, len);                                  memset(data, 0, len);
458                          goto do_return_ok;                          goto do_return_ok;
459                  } else {                  } else
460                          if (paddr >= mem->physical_max + 0 * 1024) {  #endif /* MIPS */
461                    {
462                            if (paddr >= mem->physical_max) {
463                                  char *symbol;                                  char *symbol;
464  #ifdef MEM_MIPS                                  uint64_t old_pc;
465                                  uint64_t offset;                                  uint64_t offset;
466    
467    #ifdef MEM_MIPS
468                                    old_pc = cpu->cd.mips.pc_last;
469    #else
470                                    /*  Default instruction size on most
471                                        RISC archs is 32 bits:  */
472                                    old_pc = cpu->pc - sizeof(uint32_t);
473  #endif  #endif
474                                  if (!quiet_mode) {  
475                                    /*  This allows for example OS kernels to probe
476                                        memory a few KBs past the end of memory,
477                                        without giving too many warnings.  */
478                                    if (!quiet_mode && !no_exceptions && paddr >=
479                                        mem->physical_max + 0x40000) {
480                                          fatal("[ memory_rw(): writeflag=%i ",                                          fatal("[ memory_rw(): writeflag=%i ",
481                                              writeflag);                                              writeflag);
482                                          if (writeflag) {                                          if (writeflag) {
# Line 373  have_paddr: Line 503  have_paddr:
503                                                                      data[i]);                                                                      data[i]);
504                                                  debug("}");                                                  debug("}");
505                                          }                                          }
506  #ifdef MEM_MIPS  
507                                            fatal(" paddr=0x%llx >= physical_max"
508                                                "; pc=", (long long)paddr);
509                                            if (cpu->is_32bit)
510                                                    fatal("0x%08x",(int)old_pc);
511                                            else
512                                                    fatal("0x%016llx",
513                                                        (long long)old_pc);
514                                          symbol = get_symbol_name(                                          symbol = get_symbol_name(
515                                              &cpu->machine->symbol_context,                                              &cpu->machine->symbol_context,
516                                              cpu->cd.mips.pc_last, &offset);                                              old_pc, &offset);
517  #else                                          fatal(" <%s> ]\n",
518                                          symbol = "(unimpl for non-MIPS)";                                              symbol? symbol : " no symbol ");
 #endif  
   
 /*  TODO: fix! not mips.pc_last for for example ppc  */  
   
                                         fatal(" paddr=%llx >= physical_max pc="  
                                             "0x%08llx <%s> ]\n",  
                                             (long long)paddr,  
                                             (long long)cpu->cd.mips.pc_last,  
                                             symbol? symbol : "no symbol");  
519                                  }                                  }
520    
521                                  if (cpu->machine->single_step_on_bad_addr) {                                  if (cpu->machine->single_step_on_bad_addr) {
522                                          fatal("[ unimplemented access to "                                          fatal("[ unimplemented access to "
523                                              "0x%016llx, pc = 0x%016llx ]\n",                                              "0x%llx, pc=0x",(long long)paddr);
524                                              (long long)paddr,                                          if (cpu->is_32bit)
525                                              (long long)cpu->pc);                                                  fatal("%08x ]\n",
526                                                        (int)old_pc);
527                                            else
528                                                    fatal("%016llx ]\n",
529                                                        (long long)old_pc);
530                                          single_step = 1;                                          single_step = 1;
531                                  }                                  }
532                          }                          }
533    
534                          if (writeflag == MEM_READ) {                          if (writeflag == MEM_READ) {
535    #ifdef MEM_X86
536                                    /*  Reading non-existant memory on x86:  */
537                                    memset(data, 0xff, len);
538    #else
539                                  /*  Return all zeroes? (Or 0xff? TODO)  */                                  /*  Return all zeroes? (Or 0xff? TODO)  */
540                                  memset(data, 0, len);                                  memset(data, 0, len);
541    #endif
542    
543  #ifdef MEM_MIPS  #ifdef MEM_MIPS
544                                  /*                                  /*
# Line 409  have_paddr: Line 546  have_paddr:
546                                   *  an exceptions on an illegal read:                                   *  an exceptions on an illegal read:
547                                   */                                   */
548                                  if (cache != CACHE_NONE && cpu->machine->                                  if (cache != CACHE_NONE && cpu->machine->
549                                      dbe_on_nonexistant_memaccess) {                                      dbe_on_nonexistant_memaccess &&
550                                        !no_exceptions) {
551                                          if (paddr >= mem->physical_max &&                                          if (paddr >= mem->physical_max &&
552                                              paddr < mem->physical_max+1048576)                                              paddr < mem->physical_max+1048576)
553                                                  mips_cpu_exception(cpu,                                                  mips_cpu_exception(cpu,
# Line 429  have_paddr: Line 567  have_paddr:
567  #endif  /*  ifndef MEM_USERLAND  */  #endif  /*  ifndef MEM_USERLAND  */
568    
569    
 no_exception_access:  
   
570          /*          /*
571           *  Uncached access:           *  Uncached access:
572             *
573             *  1)  Translate the physical address to a host address.
574             *
575             *  2)  Insert this virtual->physical->host translation into the
576             *      fast translation arrays (using update_translation_table()).
577             *
578             *  3)  If this was a Write, then invalidate any code translations
579             *      in that page.
580           */           */
581          memblock = memory_paddr_to_hostaddr(mem, paddr, writeflag);          memblock = memory_paddr_to_hostaddr(mem, paddr, writeflag);
582          if (memblock == NULL) {          if (memblock == NULL) {
# Line 443  no_exception_access: Line 587  no_exception_access:
587    
588          offset = paddr & ((1 << BITS_PER_MEMBLOCK) - 1);          offset = paddr & ((1 << BITS_PER_MEMBLOCK) - 1);
589    
590  #ifdef BINTRANS          if (cpu->update_translation_table != NULL && !bintrans_device_danger
591          if (bintrans_cached)  #ifndef MEM_MIPS
592                  update_translation_table(cpu, vaddr & ~0xfff,  /*          && !(cache_flags & MEMORY_USER_ACCESS)  */
593                      memblock + (offset & ~0xfff),  #ifndef MEM_USERLAND
594                && !(ok & MEMORY_NOT_FULL_PAGE)
595    #endif
596    #endif
597                && !no_exceptions)
598                    cpu->update_translation_table(cpu, vaddr & ~offset_mask,
599                        memblock + (offset & ~offset_mask),
600                        (cache_flags & MEMORY_USER_ACCESS) |
601    #ifndef MEM_MIPS
602                        (cache == CACHE_INSTRUCTION? TLB_CODE : 0) |
603    #endif
604  #if 0  #if 0
605                      cache == CACHE_INSTRUCTION?                      (cache == CACHE_INSTRUCTION?
606                          (writeflag == MEM_WRITE? 1 : 0)                          (writeflag == MEM_WRITE? 1 : 0)
607                          : ok - 1,                          : ok - 1),
608  #else  #else
609                      writeflag == MEM_WRITE? 1 : 0,                      (writeflag == MEM_WRITE? 1 : 0),
 #endif  
                     paddr & ~0xfff);  
610  #endif  #endif
611                        paddr & ~offset_mask);
612    
613            /*  Invalidate code translations for the page we are writing to.  */
614            if (writeflag == MEM_WRITE &&
615                cpu->invalidate_code_translation != NULL)
616                    cpu->invalidate_code_translation(cpu, paddr, INVALIDATE_PADDR);
617    
618          if (writeflag == MEM_WRITE) {          if (writeflag == MEM_WRITE) {
619                  if (len == sizeof(uint32_t) && (offset & 3)==0)                  /*  Ugly optimization, but it works:  */
620                    if (len == sizeof(uint32_t) && (offset & 3)==0
621                        && ((size_t)data&3)==0)
622                          *(uint32_t *)(memblock + offset) = *(uint32_t *)data;                          *(uint32_t *)(memblock + offset) = *(uint32_t *)data;
623                  else if (len == sizeof(uint8_t))                  else if (len == sizeof(uint8_t))
624                          *(uint8_t *)(memblock + offset) = *(uint8_t *)data;                          *(uint8_t *)(memblock + offset) = *(uint8_t *)data;
625                  else                  else
626                          memcpy(memblock + offset, data, len);                          memcpy(memblock + offset, data, len);
627          } else {          } else {
628                  if (len == sizeof(uint32_t) && (offset & 3)==0)                  /*  Ugly optimization, but it works:  */
629                    if (len == sizeof(uint32_t) && (offset & 3)==0
630                        && ((size_t)data&3)==0)
631                          *(uint32_t *)data = *(uint32_t *)(memblock + offset);                          *(uint32_t *)data = *(uint32_t *)(memblock + offset);
632                  else if (len == sizeof(uint8_t))                  else if (len == sizeof(uint8_t))
633                          *(uint8_t *)data = *(uint8_t *)(memblock + offset);                          *(uint8_t *)data = *(uint8_t *)(memblock + offset);
634                  else                  else
635                          memcpy(data, memblock + offset, len);                          memcpy(data, memblock + offset, len);
636    
637    #ifdef MEM_MIPS
638                  if (cache == CACHE_INSTRUCTION) {                  if (cache == CACHE_INSTRUCTION) {
639                          cpu->cd.mips.pc_last_host_4k_page = memblock                          cpu->cd.mips.pc_last_host_4k_page = memblock
640                              + (offset & ~0xfff);                              + (offset & ~offset_mask);
 #ifdef BINTRANS  
641                          if (bintrans_cached) {                          if (bintrans_cached) {
642                                  cpu->cd.mips.pc_bintrans_host_4kpage =                                  cpu->cd.mips.pc_bintrans_host_4kpage =
643                                      cpu->cd.mips.pc_last_host_4k_page;                                      cpu->cd.mips.pc_last_host_4k_page;
644                          }                          }
 #endif  
645                  }                  }
646    #endif  /*  MIPS  */
647          }          }
648    
649    

Legend:
Removed from v.2  
changed lines
  Added in v.18

  ViewVC Help
Powered by ViewVC 1.1.26