memory.h Source File

Back to the index.

memory.h
Go to the documentation of this file.
1 #ifndef MEMORY_H
2 #define MEMORY_H
3 
4 /*
5  * Copyright (C) 2004-2010 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  * Memory related functions.
32  */
33 
34 #include <sys/types.h>
35 #include <inttypes.h>
36 
37 #include "misc.h"
38 
39 
40 #define DEFAULT_RAM_IN_MB 32
41 
42 struct cpu;
43 
44 
45 /*
46  * Memory mapped device
47  */
48 struct memory_device {
49  uint64_t baseaddr;
50  uint64_t endaddr; /* NOTE: after the last byte! */
51  uint64_t length;
52  int flags;
53 
54  const char *name;
55 
56  int (*f)(struct cpu *,struct memory *,
57  uint64_t,unsigned char *,size_t,int,void *);
58  void *extra;
59 
60  unsigned char *dyntrans_data;
61 
64 };
65 
66 
67 /*
68  * Memory
69  * ------
70  *
71  * This struct defines a memory object. Most machines only use one memory
72  * object (the main memory), but if necessary, multiple memories can be
73  * used.
74  */
75 struct memory {
76  uint64_t physical_max;
77  void *pagetable;
78 
80 
83  /* The following two might speed up things a little bit. */
84  /* (actually maxaddr is the addr after the last address) */
85  uint64_t mmap_dev_minaddr;
86  uint64_t mmap_dev_maxaddr;
87 
89 };
90 
91 #define BITS_PER_PAGETABLE 20
92 #define BITS_PER_MEMBLOCK 20
93 #define MAX_BITS 40
94 
95 
96 /* memory.c: */
97 #define MEM_PCI_LITTLE_ENDIAN 128
98 uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len);
99 void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len,
100  uint64_t data);
101 
102 void *zeroed_alloc(size_t s);
103 
104 struct memory *memory_new(uint64_t physical_max, int arch);
105 
106 int memory_points_to_string(struct cpu *cpu, struct memory *mem,
107  uint64_t addr, int min_string_length);
108 char *memory_conv_to_string(struct cpu *cpu, struct memory *mem,
109  uint64_t addr, char *buf, int bufsize);
110 
111 unsigned char *memory_paddr_to_hostaddr(struct memory *mem,
112  uint64_t paddr, int writeflag);
113 
114 
115 /* Writeflag: */
116 #define MEM_READ 0
117 #define MEM_WRITE 1
118 #define MEM_DOWNGRADE 128
119 
120 /* Misc. flags: */
121 #define CACHE_DATA 0
122 #define CACHE_INSTRUCTION 1
123 #define CACHE_NONE 2
124 #define CACHE_FLAGS_MASK 0x3
125 #define NO_EXCEPTIONS 16
126 #define PHYSICAL 32
127 #define MEMORY_USER_ACCESS 64 /* for ARM and M88K */
128 
129 /* Dyntrans Memory flags: */
130 #define DM_DEFAULT 0
131 #define DM_DYNTRANS_OK 1
132 #define DM_DYNTRANS_WRITE_OK 2
133 #define DM_READS_HAVE_NO_SIDE_EFFECTS 4
134 #define DM_EMULATED_RAM 8
135 
136 #define FLAG_WRITEFLAG 1
137 #define FLAG_NOEXCEPTIONS 2
138 #define FLAG_INSTR 4
139 
140 #define MEMORY_ACCESS_FAILED 0
141 #define MEMORY_ACCESS_OK 1
142 #define MEMORY_ACCESS_OK_WRITE 2
143 #define MEMORY_NOT_FULL_PAGE 256
144 
145 void memory_device_dyntrans_access(struct cpu *, struct memory *mem,
146  void *extra, uint64_t *low, uint64_t *high);
147 
148 #define DEVICE_ACCESS(x) int dev_ ## x ## _access(struct cpu *cpu, \
149  struct memory *mem, uint64_t relative_addr, unsigned char *data, \
150  size_t len, int writeflag, void *extra)
151 
152 void memory_device_update_data(struct memory *mem, void *extra,
153  unsigned char *data);
154 
155 void memory_device_register(struct memory *mem, const char *,
156  uint64_t baseaddr, uint64_t len, int (*f)(struct cpu *,
157  struct memory *,uint64_t,unsigned char *,size_t,int,void *),
158  void *extra, int flags, unsigned char *dyntrans_data);
159 void memory_device_remove(struct memory *mem, int i);
160 
161 uint64_t memory_checksum(struct memory *mem);
162 
163 void dump_mem_string(struct cpu *cpu, uint64_t addr);
164 void store_string(struct cpu *cpu, uint64_t addr, const char *s);
165 int store_64bit_word(struct cpu *cpu, uint64_t addr, uint64_t data64);
166 int store_32bit_word(struct cpu *cpu, uint64_t addr, uint64_t data32);
167 int store_16bit_word(struct cpu *cpu, uint64_t addr, uint64_t data16);
168 void store_byte(struct cpu *cpu, uint64_t addr, uint8_t data);
169 void store_64bit_word_in_host(struct cpu *cpu, unsigned char *data,
170  uint64_t data32);
171 void store_32bit_word_in_host(struct cpu *cpu, unsigned char *data,
172  uint64_t data32);
173 void store_16bit_word_in_host(struct cpu *cpu, unsigned char *data,
174  uint16_t data16);
175 uint64_t load_64bit_word(struct cpu *cpu, uint64_t addr);
176 uint32_t load_32bit_word(struct cpu *cpu, uint64_t addr);
177 uint16_t load_16bit_word(struct cpu *cpu, uint64_t addr);
178 void store_buf(struct cpu *cpu, uint64_t addr, const char *s, size_t len);
179 void add_environment_string(struct cpu *cpu, const char *s, uint64_t *addr);
180 void add_environment_string_dual(struct cpu *cpu,
181  uint64_t *ptrp, uint64_t *addrp, const char *s1, const char *s2);
182 void store_pointer_and_advance(struct cpu *cpu, uint64_t *addrp,
183  uint64_t data, int flag64);
184 
185 void memory_warn_about_unimplemented_addr(struct cpu *cpu, struct memory *mem,
186  int writeflag, uint64_t paddr, uint8_t *data, size_t len);
187 
188 
189 #endif /* MEMORY_H */
memory::n_mmapped_devices
int n_mmapped_devices
Definition: memory.h:81
data
u_short data
Definition: siireg.h:79
memory_device::name
const char * name
Definition: memory.h:54
f
void f(int s, int func, int only_name)
Definition: generate_arm_r.c:45
memory_device::dyntrans_write_low
uint64_t dyntrans_write_low
Definition: memory.h:62
store_buf
void store_buf(struct cpu *cpu, uint64_t addr, const char *s, size_t len)
Definition: memory.cc:826
memory_device::extra
void * extra
Definition: memory.h:58
memory
Definition: memory.h:75
memory_checksum
uint64_t memory_checksum(struct memory *mem)
Definition: memory.cc:563
store_64bit_word
int store_64bit_word(struct cpu *cpu, uint64_t addr, uint64_t data64)
Definition: memory.cc:752
memory_device::f
int(* f)(struct cpu *, struct memory *, uint64_t, unsigned char *, size_t, int, void *)
Definition: memory.h:56
add_environment_string
void add_environment_string(struct cpu *cpu, const char *s, uint64_t *addr)
Definition: memory.cc:710
memory_device_register
void memory_device_register(struct memory *mem, const char *, uint64_t baseaddr, uint64_t len, int(*f)(struct cpu *, struct memory *, uint64_t, unsigned char *, size_t, int, void *), void *extra, int flags, unsigned char *dyntrans_data)
Definition: memory.cc:339
memory::pagetable
void * pagetable
Definition: memory.h:77
load_16bit_word
uint16_t load_16bit_word(struct cpu *cpu, uint64_t addr)
Definition: memory.cc:923
addr
uint32_t addr
Definition: tmp_arm_multi.cc:52
memory_device::length
uint64_t length
Definition: memory.h:51
memory_device::baseaddr
uint64_t baseaddr
Definition: memory.h:49
memory_device::endaddr
uint64_t endaddr
Definition: memory.h:50
memory::devices
struct memory_device * devices
Definition: memory.h:88
memory_device_remove
void memory_device_remove(struct memory *mem, int i)
Definition: memory.cc:463
memory::mmap_dev_maxaddr
uint64_t mmap_dev_maxaddr
Definition: memory.h:86
misc.h
memory_readmax64
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)
Definition: memory.cc:55
memory::mmap_dev_minaddr
uint64_t mmap_dev_minaddr
Definition: memory.h:85
store_string
void store_string(struct cpu *cpu, uint64_t addr, const char *s)
Definition: memory.cc:695
store_16bit_word_in_host
void store_16bit_word_in_host(struct cpu *cpu, unsigned char *data, uint16_t data16)
Definition: memory.cc:992
memory_device::dyntrans_data
unsigned char * dyntrans_data
Definition: memory.h:60
memory_warn_about_unimplemented_addr
void memory_warn_about_unimplemented_addr(struct cpu *cpu, struct memory *mem, int writeflag, uint64_t paddr, uint8_t *data, size_t len)
Definition: memory.cc:594
memory_device_dyntrans_access
void memory_device_dyntrans_access(struct cpu *, struct memory *mem, void *extra, uint64_t *low, uint64_t *high)
Definition: memory.cc:264
memory_device::dyntrans_write_high
uint64_t dyntrans_write_high
Definition: memory.h:63
dump_mem_string
void dump_mem_string(struct cpu *cpu, uint64_t addr)
Definition: memory.cc:656
add_environment_string_dual
void add_environment_string_dual(struct cpu *cpu, uint64_t *ptrp, uint64_t *addrp, const char *s1, const char *s2)
Definition: memory.cc:723
memory_device
Definition: memory.h:48
zeroed_alloc
void * zeroed_alloc(size_t s)
Definition: memory.cc:118
memory::last_accessed_device
int last_accessed_device
Definition: memory.h:82
store_32bit_word
int store_32bit_word(struct cpu *cpu, uint64_t addr, uint64_t data32)
Definition: memory.cc:783
store_pointer_and_advance
void store_pointer_and_advance(struct cpu *cpu, uint64_t *addrp, uint64_t data, int flag64)
Definition: memory.cc:855
load_32bit_word
uint32_t load_32bit_word(struct cpu *cpu, uint64_t addr)
Definition: memory.cc:902
store_byte
void store_byte(struct cpu *cpu, uint64_t addr, uint8_t data)
Definition: memory.cc:679
memory_device_update_data
void memory_device_update_data(struct memory *mem, void *extra, unsigned char *data)
Definition: memory.cc:318
store_32bit_word_in_host
void store_32bit_word_in_host(struct cpu *cpu, unsigned char *data, uint64_t data32)
Definition: memory.cc:973
memory::physical_max
uint64_t physical_max
Definition: memory.h:76
memory_points_to_string
int memory_points_to_string(struct cpu *cpu, struct memory *mem, uint64_t addr, int min_string_length)
Definition: memory.cc:190
store_64bit_word_in_host
void store_64bit_word_in_host(struct cpu *cpu, unsigned char *data, uint64_t data32)
Definition: memory.cc:945
store_16bit_word
int store_16bit_word(struct cpu *cpu, uint64_t addr, uint64_t data16)
Definition: memory.cc:807
memory::dev_dyntrans_alignment
int dev_dyntrans_alignment
Definition: memory.h:79
memory_writemax64
void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len, uint64_t data)
Definition: memory.cc:89
cpu
Definition: cpu.h:326
memory_new
struct memory * memory_new(uint64_t physical_max, int arch)
Definition: memory.cc:146
memory_conv_to_string
char * memory_conv_to_string(struct cpu *cpu, struct memory *mem, uint64_t addr, char *buf, int bufsize)
Definition: memory.cc:220
load_64bit_word
uint64_t load_64bit_word(struct cpu *cpu, uint64_t addr)
Definition: memory.cc:875
memory_paddr_to_hostaddr
unsigned char * memory_paddr_to_hostaddr(struct memory *mem, uint64_t paddr, int writeflag)
Definition: memory.cc:495
memory_device::flags
int flags
Definition: memory.h:52

Generated on Tue Mar 24 2020 14:04:48 for GXemul by doxygen 1.8.17