/[gxemul]/upstream/0.4.5/src/cpus/memory_alpha.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

Contents of /upstream/0.4.5/src/cpus/memory_alpha.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 39 - (show annotations)
Mon Oct 8 16:22:02 2007 UTC (16 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 3847 byte(s)
0.4.5
1 /*
2 * Copyright (C) 2006-2007 Anders Gavare. All rights reserved.
3 *
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 * $Id: memory_alpha.c,v 1.8 2006/12/30 13:30:56 debug Exp $
29 */
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 #include "cpu.h"
36 #include "machine.h"
37 #include "memory.h"
38 #include "misc.h"
39
40 #include "alpha_rpb.h"
41
42
43 /*
44 * alpha_translate_v2p():
45 */
46 int alpha_translate_v2p(struct cpu *cpu, uint64_t vaddr,
47 uint64_t *return_paddr, int flags)
48 {
49 uint64_t base = cpu->cd.alpha.pcb.apcb_ptbr << ALPHA_PAGESHIFT;
50 uint64_t addr, pte1, pte2, pte3;
51 int i1, i2, i3;
52 unsigned char *pt_entry_ptr;
53
54 /* Kernel direct-mapped space: */
55 if ((vaddr & ~0x1ffffffffffULL) == 0xfffffc0000000000ULL) {
56 *return_paddr = vaddr & 0x000003ffffffffffULL;
57 return 2;
58 }
59
60 i1 = (vaddr >> 33) & 0x3ff;
61 i2 = (vaddr >> 23) & 0x3ff;
62 i3 = (vaddr >> 13) & 0x3ff;
63
64 debug("base = 0x%016"PRIx64"\n", base);
65 debug("i1=0x%x i2=0x%x i3=0x%x\n", i1, i2, i3);
66
67 addr = base + i1 * sizeof(uint64_t);
68
69 pt_entry_ptr = memory_paddr_to_hostaddr(cpu->mem, addr, 0);
70 if (pt_entry_ptr == NULL)
71 goto not_found;
72
73 pte1 = *(uint64_t *)(pt_entry_ptr);
74 pte1 = LE64_TO_HOST(pte1);
75
76 debug("pte1 = 0x%016"PRIx64"\n", pte1);
77
78 addr = ((pte1 >> 32) << ALPHA_PAGESHIFT) + (i2 * sizeof(uint64_t));
79
80 pt_entry_ptr = memory_paddr_to_hostaddr(cpu->mem, addr, 0);
81 if (pt_entry_ptr == NULL)
82 goto not_found;
83
84 pte2 = *(uint64_t *)(pt_entry_ptr);
85 pte2 = LE64_TO_HOST(pte2);
86
87 debug("pte2 = 0x%016"PRIx64"\n", pte2);
88
89 addr = ((pte2 >> 32) << ALPHA_PAGESHIFT) + (i3 * sizeof(uint64_t));
90
91 pt_entry_ptr = memory_paddr_to_hostaddr(cpu->mem, addr, 0);
92 if (pt_entry_ptr == NULL)
93 goto not_found;
94
95 pte3 = *(uint64_t *)(pt_entry_ptr);
96 pte3 = LE64_TO_HOST(pte3);
97
98 debug("pte3 = 0x%016"PRIx64"\n", pte3);
99
100 not_found:
101 /* No match. */
102 debug("[ alpha_translate_v2p: 0x%016"PRIx64" wasn't found ]\n", vaddr);
103
104 #if 1
105 /* UGLY hack for now: */
106 /* TODO: Real virtual memory support. */
107 *return_paddr = vaddr & 0x000003ffffffffffULL;
108
109 if ((vaddr & ~0x7fff) == 0x0000000010000000ULL)
110 *return_paddr = (vaddr & 0x7fff) + HWRPB_PADDR;
111
112 if ((vaddr & ~0xffffff) == 0xfffffe0000000000ULL)
113 *return_paddr = 0x7efa000 + (vaddr & 0xffffff);
114
115 /* At 0x20000000, NetBSD stores 8KB temp prom data */
116 if ((vaddr & ~0x1fff) == 0x0000000020000000ULL)
117 *return_paddr = (vaddr & 0x1fff) + PROM_ARGSPACE_PADDR;
118
119 return 2;
120 #else
121 return 0;
122 #endif
123 }
124

  ViewVC Help
Powered by ViewVC 1.1.26