/[gxemul]/upstream/0.4.6/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

Annotation of /upstream/0.4.6/src/memory_rw.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 42 - (hide annotations)
Mon Oct 8 16:22:32 2007 UTC (16 years, 8 months ago) by dpavlin
Original Path: trunk/src/memory_rw.c
File MIME type: text/plain
File size: 11814 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.1613 2007/06/15 20:11:26 debug Exp $
20070501	Continuing a little on m88k disassembly (control registers,
		more instructions).
		Adding a dummy mvme88k machine mode.
20070502	Re-adding MIPS load/store alignment exceptions.
20070503	Implementing more of the M88K disassembly code.
20070504	Adding disassembly of some more M88K load/store instructions.
		Implementing some relatively simple M88K instructions (br.n,
		xor[.u] imm, and[.u] imm).
20070505	Implementing M88K three-register and, or, xor, and jmp[.n],
		bsr[.n] including function call trace stuff.
		Applying a patch from Bruce M. Simpson which implements the
		SYSCON_BOARD_CPU_CLOCK_FREQ_ID object of the syscon call in
		the yamon PROM emulation.
20070506	Implementing M88K bb0[.n] and bb1[.n], and skeletons for
		ldcr and stcr (although no control regs are implemented yet).
20070509	Found and fixed the bug which caused Linux for QEMU_MIPS to
		stop working in 0.4.5.1: It was a faulty change to the MIPS
		'sc' and 'scd' instructions I made while going through gcc -W
		warnings on 20070428.
20070510	Updating the Linux/QEMU_MIPS section in guestoses.html to
		use mips-test-0.2.tar.gz instead of 0.1.
		A big thank you to Miod Vallat for sending me M88K manuals.
		Implementing more M88K instructions (addu, subu, div[u], mulu,
		ext[u], clr, set, cmp).
20070511	Fixing bugs in the M88K "and" and "and.u" instructions (found
		by comparing against the manual).
		Implementing more M88K instructions (mask[.u], mak, bcnd (auto-
		generated)) and some more control register details.
		Cleanup: Removing the experimental AVR emulation mode and
		corresponding devices; AVR emulation wasn't really meaningful.
		Implementing autogeneration of most M88K loads/stores. The
		rectangle drawing demo (with -O0) for M88K runs :-)
		Beginning on M88K exception handling.
		More M88K instructions: tb0, tb1, rte, sub, jsr[.n].
		Adding some skeleton MVME PROM ("BUG") emulation.
20070512	Fixing a bug in the M88K cmp instruction.
		Adding the M88K lda (scaled register) instruction.
		Fixing bugs in 64-bit (32-bit pairs) M88K loads/stores.
		Removing the unused tick_hz stuff from the machine struct.
		Implementing the M88K xmem instruction. OpenBSD/mvme88k gets
		far enough to display the Copyright banner :-)
		Implementing subu.co (guess), addu.co, addu.ci, ff0, and ff1.
		Adding a dev_mvme187, for MVME187-specific devices/registers.
		OpenBSD/mvme88k prints more boot messages. :)
20070515	Continuing on MVME187 emulation (adding more devices, beginning
		on the CMMUs, etc).
		Adding the M88K and.c, xor.c, and or.c instructions, and making
		sure that mul, div, etc cause exceptions if executed when SFD1
		is disabled.
20070517	Continuing on M88K and MVME187 emulation in general; moving
		the CMMU registers to the CPU struct, separating dev_pcc2 from
		dev_mvme187, and beginning on memory_m88k.c (BATC and PATC).
		Fixing a bug in 64-bit (32-bit pairs) M88K fast stores.
		Implementing the clock part of dev_mk48txx.
		Implementing the M88K fstcr and xcr instructions.
		Implementing m88k_cpu_tlbdump().
		Beginning on the implementation of a separate address space
		for M88K .usr loads/stores.
20070520	Removing the non-working (skeleton) Sandpoint, SonyNEWS, SHARK
		Dnard, and Zaurus machine modes.
		Experimenting with dyntrans to_be_translated read-ahead. It
		seems to give a very small performance increase for MIPS
		emulation, but a large performance degradation for SuperH. Hm.
20070522	Disabling correct SuperH ITLB emulation; it does not seem to be
		necessary in order to let SH4 guest OSes run, and it slows down
		userspace code.
		Implementing "samepage" branches for SuperH emulation, and some
		other minor speed hacks.
20070525	Continuing on M88K memory-related stuff: exceptions, memory
		transaction register contents, etc.
		Implementing the M88K subu.ci instruction.
		Removing the non-working (skeleton) Iyonix machine mode.
		OpenBSD/mvme88k reaches userland :-), starts executing
		/sbin/init's instructions, and issues a few syscalls, before
		crashing.
20070526	Fixing bugs in dev_mk48txx, so that OpenBSD/mvme88k detects
		the correct time-of-day.
		Implementing a generic IRQ controller for the test machines
		(dev_irqc), similar to a proposed patch from Petr Stepan.
		Experimenting some more with translation read-ahead.
		Adding an "expect" script for automated OpenBSD/landisk
		install regression/performance tests.
20070527	Adding a dummy mmEye (SH3) machine mode skeleton.
		FINALLY found the strange M88K bug I have been hunting: I had
		not emulated the SNIP value for exceptions occurring in
		branch delay slots correctly.
		Implementing correct exceptions for 64-bit M88K loads/stores.
		Address to symbol lookups are now disabled when M88K is
		running in usermode (because usermode addresses don't have
		anything to do with supervisor addresses).
20070531	Removing the mmEye machine mode skeleton.
20070604	Some minor code cleanup.
20070605	Moving src/useremul.c into a subdir (src/useremul/), and
		cleaning up some more legacy constructs.
		Adding -Wstrict-aliasing and -fstrict-aliasing detection to
		the configure script.
20070606	Adding a check for broken GCC on Solaris to the configure
		script. (GCC 3.4.3 on Solaris cannot handle static variables
		which are initialized to 0 or NULL. :-/)
		Removing the old (non-working) ARC emulation modes: NEC RD94,
		R94, R96, and R98, and the last traces of Olivetti M700 and
		Deskstation Tyne.
		Removing the non-working skeleton WDSC device (dev_wdsc).
20070607	Thinking about how to use the host's cc + ld at runtime to
		generate native code. (See experiments/native_cc_ld_test.i
		for an example.)
20070608	Adding a program counter sampling timer, which could be useful
		for native code generation experiments.
		The KN02_CSR_NRMMOD bit in the DECstation 5000/200 (KN02) CSR
		should always be set, to allow a 5000/200 PROM to boot.
20070609	Moving out breakpoint details from the machine struct into
		a helper struct, and removing the limit on max nr of
		breakpoints.
20070610	Moving out tick functions into a helper struct as well (which
		also gets rid of the max limit).
20070612	FINALLY figured out why Debian/DECstation stopped working when
		translation read-ahead was enabled: in src/memory_rw.c, the
		call to invalidate_code_translation was made also if the
		memory access was an instruction load (if the page was mapped
		as writable); it shouldn't be called in that case.
20070613	Implementing some more MIPS32/64 revision 2 instructions: di,
		ei, ext, dext, dextm, dextu, and ins.
20070614	Implementing an instruction combination for the NetBSD/arm
		idle loop (making the host not use any cpu if NetBSD/arm
		inside the emulator is not using any cpu).
		Increasing the nr of ARM VPH entries from 128 to 384.
20070615	Removing the ENABLE_arch stuff from the configure script, so
		that all included architectures are included in both release
		and development builds.
		Moving memory related helper functions from misc.c to memory.c.
		Adding preliminary instructions for netbooting NetBSD/pmppc to
		guestoses.html; it doesn't work yet, there are weird timeouts.
		Beginning a total rewrite of the userland emulation modes
		(removing all emulation modes, beginning from scratch with
		NetBSD/MIPS and FreeBSD/Alpha only).
20070616	After fixing a bug in the DEC21143 NIC (the TDSTAT_OWN bit was
		only cleared for the last segment when transmitting, not all
		segments), NetBSD/pmppc boots with root-on-nfs without the
		timeouts. Updating guestoses.html.
		Removing the skeleton PSP (Playstation Portable) mode.
		Moving X11-related stuff in the machine struct into a helper
		struct.
		Cleanup of out-of-memory checks, to use a new CHECK_ALLOCATION
		macro (which prints a meaningful error message).
		Adding a COMMENT to each machine and device (for automagic
		.index comment generation).
		Doing regression testing for the next release.

==============  RELEASE 0.4.6  ==============


1 dpavlin 2 /*
2 dpavlin 34 * Copyright (C) 2003-2007 Anders Gavare. All rights reserved.
3 dpavlin 2 *
4     * Redistribution and use in source and binary forms, with or without
5     * modification, are permitted provided that the following conditions are met:
6     *
7     * 1. Redistributions of source code must retain the above copyright
8     * notice, this list of conditions and the following disclaimer.
9     * 2. Redistributions in binary form must reproduce the above copyright
10     * notice, this list of conditions and the following disclaimer in the
11     * documentation and/or other materials provided with the distribution.
12     * 3. The name of the author may not be used to endorse or promote products
13     * derived from this software without specific prior written permission.
14     *
15     * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16     * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17     * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18     * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19     * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20     * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21     * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24     * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25     * SUCH DAMAGE.
26     *
27     *
28 dpavlin 42 * $Id: memory_rw.c,v 1.107 2007/06/12 03:49:11 debug Exp $
29 dpavlin 2 *
30     * Generic memory_rw(), with special hacks for specific CPU families.
31     *
32     * Example for inclusion from memory_mips.c:
33     *
34     * MEMORY_RW should be mips_memory_rw
35     * MEM_MIPS should be defined
36 dpavlin 42 *
37     *
38     * TODO: Cleanup the "ok" variable usage!
39 dpavlin 2 */
40    
41    
42     /*
43     * memory_rw():
44     *
45     * Read or write data from/to memory.
46     *
47     * cpu the cpu doing the read/write
48     * mem the memory object to use
49     * vaddr the virtual address
50     * data a pointer to the data to be written to memory, or
51     * a placeholder for data when reading from memory
52     * len the length of the 'data' buffer
53     * writeflag set to MEM_READ or MEM_WRITE
54 dpavlin 20 * misc_flags CACHE_{NONE,DATA,INSTRUCTION} | other flags
55 dpavlin 2 *
56     * If the address indicates access to a memory mapped device, that device'
57     * read/write access function is called.
58     *
59     * This function should not be called with cpu == NULL.
60     *
61     * Returns one of the following:
62     * MEMORY_ACCESS_FAILED
63     * MEMORY_ACCESS_OK
64     *
65     * (MEMORY_ACCESS_FAILED is 0.)
66     */
67     int MEMORY_RW(struct cpu *cpu, struct memory *mem, uint64_t vaddr,
68 dpavlin 20 unsigned char *data, size_t len, int writeflag, int misc_flags)
69 dpavlin 2 {
70 dpavlin 12 #ifdef MEM_ALPHA
71     const int offset_mask = 0x1fff;
72     #else
73     const int offset_mask = 0xfff;
74     #endif
75    
76 dpavlin 2 #ifndef MEM_USERLAND
77 dpavlin 42 int ok = 2;
78 dpavlin 2 #endif
79     uint64_t paddr;
80     int cache, no_exceptions, offset;
81     unsigned char *memblock;
82 dpavlin 22 int dyntrans_device_danger = 0;
83 dpavlin 12
84 dpavlin 20 no_exceptions = misc_flags & NO_EXCEPTIONS;
85     cache = misc_flags & CACHE_FLAGS_MASK;
86 dpavlin 2
87 dpavlin 4
88 dpavlin 2 #ifdef MEM_USERLAND
89 dpavlin 12 #ifdef MEM_ALPHA
90     paddr = vaddr;
91     #else
92 dpavlin 2 paddr = vaddr & 0x7fffffff;
93 dpavlin 12 #endif
94 dpavlin 24 #else /* !MEM_USERLAND */
95 dpavlin 26 if (misc_flags & PHYSICAL || cpu->translate_v2p == NULL) {
96 dpavlin 2 paddr = vaddr;
97     } else {
98 dpavlin 26 ok = cpu->translate_v2p(cpu, vaddr, &paddr,
99 dpavlin 2 (writeflag? FLAG_WRITEFLAG : 0) +
100     (no_exceptions? FLAG_NOEXCEPTIONS : 0)
101 dpavlin 20 + (misc_flags & MEMORY_USER_ACCESS)
102 dpavlin 2 + (cache==CACHE_INSTRUCTION? FLAG_INSTR : 0));
103 dpavlin 32
104     /*
105     * If the translation caused an exception, or was invalid in
106     * some way, then simply return without doing the memory
107     * access:
108     */
109 dpavlin 2 if (!ok)
110     return MEMORY_ACCESS_FAILED;
111     }
112    
113 dpavlin 24 #endif /* !MEM_USERLAND */
114 dpavlin 6
115 dpavlin 2
116     #ifndef MEM_USERLAND
117     /*
118     * Memory mapped device?
119     *
120 dpavlin 22 * TODO: if paddr < base, but len enough, then the device should
121     * still be written to!
122 dpavlin 2 */
123     if (paddr >= mem->mmap_dev_minaddr && paddr < mem->mmap_dev_maxaddr) {
124     uint64_t orig_paddr = paddr;
125 dpavlin 22 int i, start, end, res;
126 dpavlin 4
127 dpavlin 34 #if 0
128    
129     TODO: The correct solution for this is to add RAM devices _around_ the
130     dangerous device. The solution below incurs a slowdown for _everything_,
131     not just the device in question.
132    
133 dpavlin 4 /*
134     * Really really slow, but unfortunately necessary. This is
135     * to avoid the folowing scenario:
136     *
137     * a) offsets 0x000..0x123 are normal memory
138     * b) offsets 0x124..0x777 are a device
139     *
140     * 1) a read is done from offset 0x100. the page is
141 dpavlin 22 * added to the dyntrans system as a "RAM" page
142     * 2) a dyntranslated read is done from offset 0x200,
143 dpavlin 4 * which should access the device, but since the
144     * entire page is added, it will access non-existant
145     * RAM instead, without warning.
146     *
147 dpavlin 22 * Setting dyntrans_device_danger = 1 on accesses which are
148 dpavlin 4 * on _any_ offset on pages that are device mapped avoids
149     * this problem, but it is probably not very fast.
150 dpavlin 22 *
151     * TODO: Convert this into a quick (multi-level, 64-bit)
152     * address space lookup, to find dangerous pages.
153 dpavlin 4 */
154 dpavlin 12 for (i=0; i<mem->n_mmapped_devices; i++)
155 dpavlin 32 if (paddr >= (mem->devices[i].baseaddr & ~offset_mask)&&
156     paddr <= ((mem->devices[i].endaddr-1)|offset_mask)){
157 dpavlin 22 dyntrans_device_danger = 1;
158 dpavlin 12 break;
159     }
160 dpavlin 22 #endif
161 dpavlin 4
162 dpavlin 22 start = 0; end = mem->n_mmapped_devices - 1;
163     i = mem->last_accessed_device;
164 dpavlin 2
165     /* Scan through all devices: */
166     do {
167 dpavlin 32 if (paddr >= mem->devices[i].baseaddr &&
168     paddr < mem->devices[i].endaddr) {
169 dpavlin 2 /* Found a device, let's access it: */
170     mem->last_accessed_device = i;
171    
172 dpavlin 32 paddr -= mem->devices[i].baseaddr;
173     if (paddr + len > mem->devices[i].length)
174     len = mem->devices[i].length - paddr;
175 dpavlin 2
176 dpavlin 12 if (cpu->update_translation_table != NULL &&
177 dpavlin 20 !(ok & MEMORY_NOT_FULL_PAGE) &&
178 dpavlin 32 mem->devices[i].flags & DM_DYNTRANS_OK) {
179 dpavlin 2 int wf = writeflag == MEM_WRITE? 1 : 0;
180 dpavlin 18 unsigned char *host_addr;
181 dpavlin 2
182 dpavlin 32 if (!(mem->devices[i].flags &
183 dpavlin 20 DM_DYNTRANS_WRITE_OK))
184 dpavlin 18 wf = 0;
185    
186     if (writeflag && wf) {
187 dpavlin 32 if (paddr < mem->devices[i].
188     dyntrans_write_low)
189     mem->devices[i].
190     dyntrans_write_low =
191     paddr &~offset_mask;
192     if (paddr >= mem->devices[i].
193     dyntrans_write_high)
194     mem->devices[i].
195     dyntrans_write_high =
196     paddr | offset_mask;
197 dpavlin 2 }
198    
199 dpavlin 32 if (mem->devices[i].flags &
200 dpavlin 20 DM_EMULATED_RAM) {
201 dpavlin 18 /* MEM_WRITE to force the page
202     to be allocated, if it
203     wasn't already */
204 dpavlin 32 uint64_t *pp = (uint64_t *)mem->
205     devices[i].dyntrans_data;
206 dpavlin 18 uint64_t p = orig_paddr - *pp;
207     host_addr =
208     memory_paddr_to_hostaddr(
209 dpavlin 28 mem, p & ~offset_mask,
210     MEM_WRITE);
211 dpavlin 18 } else {
212 dpavlin 32 host_addr = mem->devices[i].
213     dyntrans_data +
214 dpavlin 18 (paddr & ~offset_mask);
215     }
216 dpavlin 28
217 dpavlin 12 cpu->update_translation_table(cpu,
218 dpavlin 18 vaddr & ~offset_mask, host_addr,
219 dpavlin 12 wf, orig_paddr & ~offset_mask);
220 dpavlin 2 }
221    
222 dpavlin 6 res = 0;
223 dpavlin 32 if (!no_exceptions || (mem->devices[i].flags &
224 dpavlin 20 DM_READS_HAVE_NO_SIDE_EFFECTS))
225 dpavlin 32 res = mem->devices[i].f(cpu, mem, paddr,
226 dpavlin 6 data, len, writeflag,
227 dpavlin 32 mem->devices[i].extra);
228 dpavlin 2
229     if (res == 0)
230     res = -1;
231    
232     /*
233     * If accessing the memory mapped device
234     * failed, then return with a DBE exception.
235     */
236 dpavlin 6 if (res <= 0 && !no_exceptions) {
237 dpavlin 2 debug("%s device '%s' addr %08lx "
238     "failed\n", writeflag?
239     "writing to" : "reading from",
240 dpavlin 32 mem->devices[i].name, (long)paddr);
241 dpavlin 2 #ifdef MEM_MIPS
242 dpavlin 42 mips_cpu_exception(cpu,
243     cache == CACHE_INSTRUCTION?
244     EXCEPTION_IBE : EXCEPTION_DBE,
245 dpavlin 2 0, vaddr, 0, 0, 0, 0);
246     #endif
247     return MEMORY_ACCESS_FAILED;
248     }
249     goto do_return_ok;
250     }
251    
252 dpavlin 32 if (paddr < mem->devices[i].baseaddr)
253 dpavlin 22 end = i - 1;
254 dpavlin 32 if (paddr >= mem->devices[i].endaddr)
255 dpavlin 22 start = i + 1;
256     i = (start + end) >> 1;
257     } while (start <= end);
258 dpavlin 2 }
259    
260    
261     #ifdef MEM_MIPS
262     /*
263     * Data and instruction cache emulation:
264     */
265    
266     switch (cpu->cd.mips.cpu_type.mmu_model) {
267     case MMU3K:
268     /* if not uncached addess (TODO: generalize this) */
269 dpavlin 20 if (!(misc_flags & PHYSICAL) && cache != CACHE_NONE &&
270 dpavlin 2 !((vaddr & 0xffffffffULL) >= 0xa0000000ULL &&
271     (vaddr & 0xffffffffULL) <= 0xbfffffffULL)) {
272     if (memory_cache_R3000(cpu, cache, paddr,
273     writeflag, len, data))
274     goto do_return_ok;
275     }
276     break;
277     default:
278     /* R4000 etc */
279     /* TODO */
280     ;
281     }
282     #endif /* MEM_MIPS */
283    
284    
285     /* Outside of physical RAM? */
286     if (paddr >= mem->physical_max) {
287 dpavlin 6 #ifdef MEM_MIPS
288     if ((paddr & 0xffffc00000ULL) == 0x1fc00000) {
289 dpavlin 2 /* Ok, this is PROM stuff */
290     } else if ((paddr & 0xfffff00000ULL) == 0x1ff00000) {
291     /* Sprite reads from this area of memory... */
292     /* TODO: is this still correct? */
293     if (writeflag == MEM_READ)
294     memset(data, 0, len);
295     goto do_return_ok;
296 dpavlin 6 } else
297     #endif /* MIPS */
298     {
299 dpavlin 34 if (paddr >= mem->physical_max && !no_exceptions)
300     memory_warn_about_unimplemented_addr
301     (cpu, mem, writeflag, paddr, data, len);
302 dpavlin 12
303 dpavlin 2 if (writeflag == MEM_READ) {
304     /* Return all zeroes? (Or 0xff? TODO) */
305     memset(data, 0, len);
306    
307 dpavlin 42 #if 0
308     /*
309     * NOTE: This code prevents a PROM image from a real 5000/200 from booting.
310     * I think I introduced it because it was how some guest OS (NetBSD?) detected
311     * the amount of RAM on some machine.
312     *
313     * TODO: Figure out if it is not needed anymore, and remove it completely.
314     */
315 dpavlin 2 #ifdef MEM_MIPS
316     /*
317     * For real data/instruction accesses, cause
318     * an exceptions on an illegal read:
319     */
320 dpavlin 42 if (cache != CACHE_NONE && !no_exceptions &&
321     paddr >= mem->physical_max &&
322     paddr < mem->physical_max+1048576) {
323     mips_cpu_exception(cpu,
324     EXCEPTION_DBE, 0, vaddr, 0,
325     0, 0, 0);
326 dpavlin 2 }
327     #endif /* MEM_MIPS */
328 dpavlin 42 #endif
329 dpavlin 2 }
330    
331     /* Hm? Shouldn't there be a DBE exception for
332     invalid writes as well? TODO */
333    
334     goto do_return_ok;
335     }
336     }
337    
338     #endif /* ifndef MEM_USERLAND */
339    
340    
341     /*
342     * Uncached access:
343 dpavlin 18 *
344     * 1) Translate the physical address to a host address.
345     *
346     * 2) Insert this virtual->physical->host translation into the
347     * fast translation arrays (using update_translation_table()).
348     *
349     * 3) If this was a Write, then invalidate any code translations
350     * in that page.
351 dpavlin 2 */
352 dpavlin 28 memblock = memory_paddr_to_hostaddr(mem, paddr & ~offset_mask,
353     writeflag);
354 dpavlin 2 if (memblock == NULL) {
355     if (writeflag == MEM_READ)
356     memset(data, 0, len);
357     goto do_return_ok;
358     }
359    
360 dpavlin 28 offset = paddr & offset_mask;
361 dpavlin 2
362 dpavlin 22 if (cpu->update_translation_table != NULL && !dyntrans_device_danger
363 dpavlin 26 #ifdef MEM_MIPS
364     /* Ugly hack for R2000/R3000 caches: */
365     && (cpu->cd.mips.cpu_type.mmu_model != MMU3K ||
366     !(cpu->cd.mips.coproc[0]->reg[COP0_STATUS] & MIPS1_ISOL_CACHES))
367     #endif
368 dpavlin 18 #ifndef MEM_USERLAND
369     && !(ok & MEMORY_NOT_FULL_PAGE)
370     #endif
371 dpavlin 16 && !no_exceptions)
372 dpavlin 12 cpu->update_translation_table(cpu, vaddr & ~offset_mask,
373 dpavlin 28 memblock, (misc_flags & MEMORY_USER_ACCESS) |
374 dpavlin 42 #if !defined(MEM_USERLAND)
375 dpavlin 18 (cache == CACHE_INSTRUCTION?
376 dpavlin 20 (writeflag == MEM_WRITE? 1 : 0) : ok - 1),
377 dpavlin 2 #else
378 dpavlin 18 (writeflag == MEM_WRITE? 1 : 0),
379 dpavlin 2 #endif
380 dpavlin 12 paddr & ~offset_mask);
381 dpavlin 2
382 dpavlin 32 /*
383 dpavlin 40 * If writing, or if mapping a page where writing is ok later on,
384     * then invalidate code translations for the (physical) page address:
385 dpavlin 32 */
386 dpavlin 42
387 dpavlin 40 if ((writeflag == MEM_WRITE
388     #if !defined(MEM_USERLAND)
389 dpavlin 42 || (ok == 2 && cache == CACHE_DATA)
390 dpavlin 40 #endif
391     ) && cpu->invalidate_code_translation != NULL)
392 dpavlin 14 cpu->invalidate_code_translation(cpu, paddr, INVALIDATE_PADDR);
393    
394 dpavlin 28 if ((paddr&((1<<BITS_PER_MEMBLOCK)-1)) + len > (1<<BITS_PER_MEMBLOCK)) {
395     printf("Write over memblock boundary?\n");
396     exit(1);
397     }
398    
399 dpavlin 40 /* And finally, read or write the data: */
400     if (writeflag == MEM_WRITE)
401     memcpy(memblock + offset, data, len);
402     else
403     memcpy(data, memblock + offset, len);
404 dpavlin 2
405     do_return_ok:
406     return MEMORY_ACCESS_OK;
407     }
408    

  ViewVC Help
Powered by ViewVC 1.1.26