1 |
/* |
/* |
2 |
* Cisco 7200 (Predator) simulation platform. |
* Cisco router simulation platform. |
3 |
* Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr) |
* Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr) |
4 |
*/ |
*/ |
5 |
|
|
100 |
|
|
101 |
/* Forward declarations */ |
/* Forward declarations */ |
102 |
typedef struct vm_instance vm_instance_t; |
typedef struct vm_instance vm_instance_t; |
103 |
typedef struct insn_block insn_block_t; |
typedef struct mips64_jit_tcb mips64_jit_tcb_t; |
104 |
|
typedef struct ppc32_jit_tcb ppc32_jit_tcb_t; |
105 |
|
|
106 |
|
/* Translated block function pointer */ |
107 |
|
typedef void (*insn_tblock_fptr)(void); |
108 |
|
|
109 |
|
/* Host executable page */ |
110 |
typedef struct insn_exec_page insn_exec_page_t; |
typedef struct insn_exec_page insn_exec_page_t; |
111 |
|
struct insn_exec_page { |
112 |
|
u_char *ptr; |
113 |
|
insn_exec_page_t *next; |
114 |
|
}; |
115 |
|
|
116 |
/* MIPS instruction */ |
/* MIPS instruction */ |
117 |
typedef m_uint32_t mips_insn_t; |
typedef m_uint32_t mips_insn_t; |
118 |
|
|
119 |
|
/* PowerPC instruction */ |
120 |
|
typedef m_uint32_t ppc_insn_t; |
121 |
|
|
122 |
/* Max and min macro */ |
/* Max and min macro */ |
123 |
#define m_max(a,b) (((a) > (b)) ? (a) : (b)) |
#define m_max(a,b) (((a) > (b)) ? (a) : (b)) |
124 |
#define m_min(a,b) (((a) < (b)) ? (a) : (b)) |
#define m_min(a,b) (((a) < (b)) ? (a) : (b)) |
153 |
m_uint32_t tlb_index; |
m_uint32_t tlb_index; |
154 |
}mts_map_t; |
}mts_map_t; |
155 |
|
|
156 |
|
/* Invalid VTLB entry */ |
157 |
|
#define MTS_INV_ENTRY_MASK 0x00000001 |
158 |
|
|
159 |
|
/* MTS entry flags */ |
160 |
|
#define MTS_FLAG_DEV 0x000000001 /* Virtual device used */ |
161 |
|
#define MTS_FLAG_COW 0x000000002 /* Copy-On-Write */ |
162 |
|
#define MTS_FLAG_EXEC 0x000000004 /* Exec page */ |
163 |
|
|
164 |
|
/* Virtual TLB entry (32-bit MMU) */ |
165 |
|
typedef struct mts32_entry mts32_entry_t; |
166 |
|
struct mts32_entry { |
167 |
|
m_uint32_t gvpa; /* Guest Virtual Page Address */ |
168 |
|
m_uint32_t gppa; /* Guest Physical Page Address */ |
169 |
|
m_iptr_t hpa; /* Host Page Address */ |
170 |
|
m_uint32_t flags; /* Flags */ |
171 |
|
}__attribute__ ((aligned(16))); |
172 |
|
|
173 |
|
/* Virtual TLB entry (64-bit MMU) */ |
174 |
|
typedef struct mts64_entry mts64_entry_t; |
175 |
|
struct mts64_entry { |
176 |
|
m_uint64_t gvpa; /* Guest Virtual Page Address */ |
177 |
|
m_uint64_t gppa; /* Guest Physical Page Address */ |
178 |
|
m_iptr_t hpa; /* Host Page Address */ |
179 |
|
m_uint32_t flags; /* Flags */ |
180 |
|
}__attribute__ ((aligned(16))); |
181 |
|
|
182 |
/* Global logfile */ |
/* Global logfile */ |
183 |
extern FILE *log_file; |
extern FILE *log_file; |
184 |
|
|
204 |
return (x << len) >> len; |
return (x << len) >> len; |
205 |
} |
} |
206 |
|
|
207 |
|
/* Sign-extension (32-bit) */ |
208 |
|
static forced_inline m_int32_t sign_extend_32(m_int32_t x,int len) |
209 |
|
{ |
210 |
|
len = 32 - len; |
211 |
|
return (x << len) >> len; |
212 |
|
} |
213 |
|
|
214 |
/* Extract bits from a 32-bit values */ |
/* Extract bits from a 32-bit values */ |
215 |
static inline int bits(m_uint32_t val,int start,int end) |
static inline int bits(m_uint32_t val,int start,int end) |
216 |
{ |
{ |
339 |
/* Set non-blocking mode on a file descriptor */ |
/* Set non-blocking mode on a file descriptor */ |
340 |
int m_fd_set_non_block(int fd); |
int m_fd_set_non_block(int fd); |
341 |
|
|
342 |
|
/* Map a memory zone from a file */ |
343 |
|
u_char *memzone_map_file(int fd,size_t len); |
344 |
|
|
345 |
|
/* Map a memory zone from a file, with copy-on-write (COW) */ |
346 |
|
u_char *memzone_map_cow_file(int fd,size_t len); |
347 |
|
|
348 |
|
/* Create a file to serve as a memory zone */ |
349 |
|
int memzone_create_file(char *filename,size_t len,u_char **ptr); |
350 |
|
|
351 |
|
/* Open a file to serve as a COW memory zone */ |
352 |
|
int memzone_open_cow_file(char *filename,size_t len,u_char **ptr); |
353 |
|
|
354 |
|
/* Open a file and map it in memory */ |
355 |
|
int memzone_open_file(char *filename,u_char **ptr,off_t *fsize); |
356 |
|
|
357 |
|
/* Compute NVRAM checksum */ |
358 |
|
m_uint16_t nvram_cksum(m_uint16_t *ptr,size_t count); |
359 |
|
|
360 |
|
/* Byte-swap a memory block */ |
361 |
|
void mem_bswap32(void *ptr,size_t len); |
362 |
|
|
363 |
|
/* Reverse a byte */ |
364 |
|
m_uint8_t m_reverse_u8(m_uint8_t val); |
365 |
|
|
366 |
#endif |
#endif |