/[gxemul]/upstream/0.4.4/src/include/memory.h
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.4/src/include/memory.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (show annotations)
Mon Oct 8 16:21:26 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 5187 byte(s)
0.4.4
1 #ifndef MEMORY_H
2 #define MEMORY_H
3
4 /*
5 * Copyright (C) 2004-2007 Anders Gavare. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 *
31 * $Id: memory.h,v 1.55 2007/02/10 14:04:51 debug Exp $
32 *
33 * Memory related functions.
34 */
35
36 #include <sys/types.h>
37 #include <inttypes.h>
38
39 #include "misc.h"
40
41
42 #define DEFAULT_RAM_IN_MB 32
43
44 struct cpu;
45
46
47 /*
48 * Memory mapped device
49 */
50 struct memory_device {
51 uint64_t baseaddr;
52 uint64_t endaddr; /* NOTE: after the last byte! */
53 uint64_t length;
54 int flags;
55
56 const char *name;
57
58 int (*f)(struct cpu *,struct memory *,
59 uint64_t,unsigned char *,size_t,int,void *);
60 void *extra;
61
62 unsigned char *dyntrans_data;
63
64 uint64_t dyntrans_write_low;
65 uint64_t dyntrans_write_high;
66 };
67
68
69 /*
70 * Memory
71 * ------
72 *
73 * This struct defines a memory object. Most machines only use one memory
74 * object (the main memory), but if necessary, multiple memories can be
75 * used.
76 */
77 struct memory {
78 uint64_t physical_max;
79 void *pagetable;
80
81 int dev_dyntrans_alignment;
82
83 int n_mmapped_devices;
84 int last_accessed_device;
85 /* The following two might speed up things a little bit. */
86 /* (actually maxaddr is the addr after the last address) */
87 uint64_t mmap_dev_minaddr;
88 uint64_t mmap_dev_maxaddr;
89
90 struct memory_device *devices;
91 };
92
93 #define BITS_PER_PAGETABLE 20
94 #define BITS_PER_MEMBLOCK 20
95 #define MAX_BITS 40
96
97
98 /* memory.c: */
99 #define MEM_PCI_LITTLE_ENDIAN 128
100 uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len);
101 void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len,
102 uint64_t data);
103
104 void *zeroed_alloc(size_t s);
105
106 struct memory *memory_new(uint64_t physical_max, int arch);
107
108 int memory_points_to_string(struct cpu *cpu, struct memory *mem,
109 uint64_t addr, int min_string_length);
110 char *memory_conv_to_string(struct cpu *cpu, struct memory *mem,
111 uint64_t addr, char *buf, int bufsize);
112
113 unsigned char *memory_paddr_to_hostaddr(struct memory *mem,
114 uint64_t paddr, int writeflag);
115
116
117 /* Writeflag: */
118 #define MEM_READ 0
119 #define MEM_WRITE 1
120 #define MEM_DOWNGRADE 128
121
122 /* Misc. flags: */
123 #define CACHE_DATA 0
124 #define CACHE_INSTRUCTION 1
125 #define CACHE_NONE 2
126 #define CACHE_FLAGS_MASK 0x3
127 #define NO_EXCEPTIONS 16
128 #define PHYSICAL 32
129 #define MEMORY_USER_ACCESS 64 /* for ARM, at least */
130
131 /* Dyntrans Memory flags: */
132 #define DM_DEFAULT 0
133 #define DM_DYNTRANS_OK 1
134 #define DM_DYNTRANS_WRITE_OK 2
135 #define DM_READS_HAVE_NO_SIDE_EFFECTS 4
136 #define DM_EMULATED_RAM 8
137
138 #define FLAG_WRITEFLAG 1
139 #define FLAG_NOEXCEPTIONS 2
140 #define FLAG_INSTR 4
141
142 int userland_memory_rw(struct cpu *cpu, struct memory *mem, uint64_t vaddr,
143 unsigned char *data, size_t len, int writeflag, int cache);
144 #define MEMORY_ACCESS_FAILED 0
145 #define MEMORY_ACCESS_OK 1
146 #define MEMORY_ACCESS_OK_WRITE 2
147 #define MEMORY_NOT_FULL_PAGE 256
148
149 void memory_device_dyntrans_access(struct cpu *, struct memory *mem,
150 void *extra, uint64_t *low, uint64_t *high);
151
152 #define DEVICE_ACCESS(x) int dev_ ## x ## _access(struct cpu *cpu, \
153 struct memory *mem, uint64_t relative_addr, unsigned char *data, \
154 size_t len, int writeflag, void *extra)
155
156 void memory_device_update_data(struct memory *mem, void *extra,
157 unsigned char *data);
158
159 void memory_device_register(struct memory *mem, const char *,
160 uint64_t baseaddr, uint64_t len, int (*f)(struct cpu *,
161 struct memory *,uint64_t,unsigned char *,size_t,int,void *),
162 void *extra, int flags, unsigned char *dyntrans_data);
163 void memory_device_remove(struct memory *mem, int i);
164
165 uint64_t memory_checksum(struct memory *mem);
166
167 void memory_warn_about_unimplemented_addr(struct cpu *cpu, struct memory *mem,
168 int writeflag, uint64_t paddr, uint8_t *data, size_t len);
169
170
171 #endif /* MEMORY_H */

  ViewVC Help
Powered by ViewVC 1.1.26