2 |
#define MEMORY_H |
#define MEMORY_H |
3 |
|
|
4 |
/* |
/* |
5 |
* Copyright (C) 2004-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2004-2007 Anders Gavare. All rights reserved. |
6 |
* |
* |
7 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
8 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
28 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
29 |
* |
* |
30 |
* |
* |
31 |
* $Id: memory.h,v 1.35 2005/07/19 10:48:07 debug Exp $ |
* $Id: memory.h,v 1.57 2007/06/14 16:13:30 debug Exp $ |
32 |
* |
* |
33 |
* Memory controller related functions. |
* Memory related functions. |
34 |
*/ |
*/ |
35 |
|
|
36 |
#include <sys/types.h> |
#include <sys/types.h> |
40 |
|
|
41 |
|
|
42 |
#define DEFAULT_RAM_IN_MB 32 |
#define DEFAULT_RAM_IN_MB 32 |
|
#define MAX_DEVICES 24 |
|
|
|
|
|
#define DEVICE_STATE_TYPE_INT 1 |
|
|
#define DEVICE_STATE_TYPE_UINT64_T 2 |
|
43 |
|
|
44 |
struct cpu; |
struct cpu; |
|
struct translation_page_entry; |
|
45 |
|
|
|
/* For bintrans: */ |
|
|
#define MAX_QUICK_JUMPS 8 |
|
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 { |
struct memory { |
78 |
uint64_t physical_max; |
uint64_t physical_max; |
79 |
void *pagetable; |
void *pagetable; |
80 |
|
|
81 |
|
int dev_dyntrans_alignment; |
82 |
|
|
83 |
int n_mmapped_devices; |
int n_mmapped_devices; |
84 |
int last_accessed_device; |
int last_accessed_device; |
85 |
/* The following two might speed up things a little bit. */ |
/* The following two might speed up things a little bit. */ |
87 |
uint64_t mmap_dev_minaddr; |
uint64_t mmap_dev_minaddr; |
88 |
uint64_t mmap_dev_maxaddr; |
uint64_t mmap_dev_maxaddr; |
89 |
|
|
90 |
const char *dev_name[MAX_DEVICES]; |
struct memory_device *devices; |
|
uint64_t dev_baseaddr[MAX_DEVICES]; |
|
|
uint64_t dev_length[MAX_DEVICES]; |
|
|
int dev_flags[MAX_DEVICES]; |
|
|
void *dev_extra[MAX_DEVICES]; |
|
|
int (*dev_f[MAX_DEVICES])(struct cpu *,struct memory *, |
|
|
uint64_t,unsigned char *,size_t,int,void *); |
|
|
int (*dev_f_state[MAX_DEVICES])(struct cpu *, |
|
|
struct memory *, void *extra, int wf, int nr, |
|
|
int *type, char **namep, void **data, size_t *len); |
|
|
unsigned char *dev_dyntrans_data[MAX_DEVICES]; |
|
|
|
|
|
int dev_dyntrans_alignment; |
|
|
|
|
|
uint64_t dev_dyntrans_write_low[MAX_DEVICES]; |
|
|
uint64_t dev_dyntrans_write_high[MAX_DEVICES]; |
|
|
|
|
|
|
|
|
/* |
|
|
* NOTE/TODO: This bintrans was for MIPS only. Ugly. :-/ |
|
|
*/ |
|
|
|
|
|
/* |
|
|
* translation_code_chunk_space is a large chunk of (linear) memory |
|
|
* where translated code chunks and translation_entrys are stored. |
|
|
* When this is filled, translation is restart from scratch (by |
|
|
* resetting translation_code_chunk_space_head to 0, and removing all |
|
|
* translation entries). |
|
|
* |
|
|
* (Using a static memory region like this is somewhat inspired by |
|
|
* the QEMU web pages, |
|
|
* http://fabrice.bellard.free.fr/qemu/qemu-tech.html#SEC13) |
|
|
*/ |
|
|
|
|
|
unsigned char *translation_code_chunk_space; |
|
|
size_t translation_code_chunk_space_head; |
|
|
|
|
|
int bintrans_32bit_only; |
|
|
|
|
|
struct translation_page_entry **translation_page_entry_array; |
|
|
|
|
|
unsigned char *quick_jump_host_address[MAX_QUICK_JUMPS]; |
|
|
int quick_jump_page_offset[MAX_QUICK_JUMPS]; |
|
|
int n_quick_jumps; |
|
|
int quick_jumps_index; |
|
91 |
}; |
}; |
92 |
|
|
93 |
#define BITS_PER_PAGETABLE 20 |
#define BITS_PER_PAGETABLE 20 |
94 |
#define BITS_PER_MEMBLOCK 20 |
#define BITS_PER_MEMBLOCK 20 |
95 |
#define MAX_BITS 40 |
#define MAX_BITS 40 |
96 |
|
|
|
#define MEM_READ 0 |
|
|
#define MEM_WRITE 1 |
|
|
|
|
|
|
|
|
#define CACHE_DATA 0 |
|
|
#define CACHE_INSTRUCTION 1 |
|
|
#define CACHE_NONE 2 |
|
|
|
|
|
#define CACHE_FLAGS_MASK 0x3 |
|
|
|
|
|
#define NO_EXCEPTIONS 16 |
|
|
#define PHYSICAL 32 |
|
|
#define NO_SEGMENTATION 64 /* for X86 */ |
|
|
|
|
97 |
|
|
98 |
/* memory.c: */ |
/* memory.c: */ |
99 |
|
#define MEM_PCI_LITTLE_ENDIAN 128 |
100 |
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len); |
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len); |
101 |
void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len, |
void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len, |
102 |
uint64_t data); |
uint64_t data); |
113 |
unsigned char *memory_paddr_to_hostaddr(struct memory *mem, |
unsigned char *memory_paddr_to_hostaddr(struct memory *mem, |
114 |
uint64_t paddr, int writeflag); |
uint64_t paddr, int writeflag); |
115 |
|
|
|
/* memory_fast_v2h.c: */ |
|
|
unsigned char *fast_vaddr_to_hostaddr(struct cpu *cpu, uint64_t vaddr, |
|
|
int writeflag); |
|
|
|
|
|
/* MIPS stuff: */ |
|
|
int translate_address_mmu3k(struct cpu *cpu, uint64_t vaddr, |
|
|
uint64_t *return_addr, int flags); |
|
|
int translate_address_mmu8k(struct cpu *cpu, uint64_t vaddr, |
|
|
uint64_t *return_addr, int flags); |
|
|
int translate_address_mmu10k(struct cpu *cpu, uint64_t vaddr, |
|
|
uint64_t *return_addr, int flags); |
|
|
int translate_address_mmu4100(struct cpu *cpu, uint64_t vaddr, |
|
|
uint64_t *return_addr, int flags); |
|
|
int translate_address_generic(struct cpu *cpu, uint64_t vaddr, |
|
|
uint64_t *return_addr, int flags); |
|
|
|
|
|
/* X86 stuff: */ |
|
|
int translate_address_x86(struct cpu *cpu, uint64_t vaddr, |
|
|
uint64_t *return_addr, int flags); |
|
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 and M88K */ |
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 |
#define FLAG_WRITEFLAG 1 |
139 |
#define FLAG_NOEXCEPTIONS 2 |
#define FLAG_NOEXCEPTIONS 2 |
141 |
|
|
142 |
int userland_memory_rw(struct cpu *cpu, struct memory *mem, uint64_t vaddr, |
int userland_memory_rw(struct cpu *cpu, struct memory *mem, uint64_t vaddr, |
143 |
unsigned char *data, size_t len, int writeflag, int cache); |
unsigned char *data, size_t len, int writeflag, int cache); |
144 |
#define MEMORY_ACCESS_FAILED 0 |
#define MEMORY_ACCESS_FAILED 0 |
145 |
#define MEMORY_ACCESS_OK 1 |
#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, |
void memory_device_dyntrans_access(struct cpu *, struct memory *mem, |
150 |
void *extra, uint64_t *low, uint64_t *high); |
void *extra, uint64_t *low, uint64_t *high); |
151 |
|
|
152 |
void memory_device_register_statefunction( |
#define DEVICE_ACCESS(x) int dev_ ## x ## _access(struct cpu *cpu, \ |
153 |
struct memory *mem, void *extra, |
struct memory *mem, uint64_t relative_addr, unsigned char *data, \ |
154 |
int (*dev_f_state)(struct cpu *, |
size_t len, int writeflag, void *extra) |
155 |
struct memory *, void *extra, int wf, int nr, |
|
156 |
int *type, char **namep, void **data, size_t *len)); |
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 *, |
void memory_device_register(struct memory *mem, const char *, |
160 |
uint64_t baseaddr, uint64_t len, int (*f)(struct cpu *, |
uint64_t baseaddr, uint64_t len, int (*f)(struct cpu *, |
162 |
void *extra, int flags, unsigned char *dyntrans_data); |
void *extra, int flags, unsigned char *dyntrans_data); |
163 |
void memory_device_remove(struct memory *mem, int i); |
void memory_device_remove(struct memory *mem, int i); |
164 |
|
|
165 |
/* Bit flags: */ |
uint64_t memory_checksum(struct memory *mem); |
166 |
#define MEM_DEFAULT 0 |
|
167 |
#define MEM_DYNTRANS_OK 1 |
void dump_mem_string(struct cpu *cpu, uint64_t addr); |
168 |
#define MEM_DYNTRANS_WRITE_OK 2 |
void store_string(struct cpu *cpu, uint64_t addr, char *s); |
169 |
#define MEM_READING_HAS_NO_SIDE_EFFECTS 4 |
int store_64bit_word(struct cpu *cpu, uint64_t addr, uint64_t data64); |
170 |
|
int store_32bit_word(struct cpu *cpu, uint64_t addr, uint64_t data32); |
171 |
|
int store_16bit_word(struct cpu *cpu, uint64_t addr, uint64_t data16); |
172 |
|
void store_byte(struct cpu *cpu, uint64_t addr, uint8_t data); |
173 |
|
void store_64bit_word_in_host(struct cpu *cpu, unsigned char *data, |
174 |
|
uint64_t data32); |
175 |
|
void store_32bit_word_in_host(struct cpu *cpu, unsigned char *data, |
176 |
|
uint64_t data32); |
177 |
|
void store_16bit_word_in_host(struct cpu *cpu, unsigned char *data, |
178 |
|
uint16_t data16); |
179 |
|
uint64_t load_64bit_word(struct cpu *cpu, uint64_t addr); |
180 |
|
uint32_t load_32bit_word(struct cpu *cpu, uint64_t addr); |
181 |
|
uint16_t load_16bit_word(struct cpu *cpu, uint64_t addr); |
182 |
|
void store_buf(struct cpu *cpu, uint64_t addr, char *s, size_t len); |
183 |
|
void add_environment_string(struct cpu *cpu, char *s, uint64_t *addr); |
184 |
|
void add_environment_string_dual(struct cpu *cpu, |
185 |
|
uint64_t *ptrp, uint64_t *addrp, char *s1, char *s2); |
186 |
|
void store_pointer_and_advance(struct cpu *cpu, uint64_t *addrp, |
187 |
|
uint64_t data, int flag64); |
188 |
|
|
189 |
|
void memory_warn_about_unimplemented_addr(struct cpu *cpu, struct memory *mem, |
190 |
|
int writeflag, uint64_t paddr, uint8_t *data, size_t len); |
191 |
|
|
192 |
|
|
193 |
#endif /* MEMORY_H */ |
#endif /* MEMORY_H */ |