--- upstream/dynamips-0.2.6-RC4/utils.h 2007/10/06 16:08:03 5 +++ upstream/dynamips-0.2.8-RC1/utils.h 2007/10/06 16:33:40 11 @@ -1,5 +1,5 @@ /* - * Cisco 7200 (Predator) simulation platform. + * Cisco router simulation platform. * Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr) */ @@ -12,6 +12,8 @@ #include #include #include +#include +#include /* True/False definitions */ #ifndef FALSE @@ -22,6 +24,20 @@ #define TRUE 1 #endif +/* Host CPU Types */ +#define CPU_x86 0 +#define CPU_amd64 1 +#define CPU_nojit 2 + +/* Number of host registers available for JIT */ +#if JIT_CPU == CPU_x86 +#define JIT_HOST_NREG 8 +#elif JIT_CPU == CPU_amd64 +#define JIT_HOST_NREG 16 +#else +#define JIT_HOST_NREG 0 +#endif + /* Endianness */ #define ARCH_BIG_ENDIAN 0x4321 #define ARCH_LITTLE_ENDIAN 0x1234 @@ -36,6 +52,8 @@ #define ARCH_BYTE_ORDER ARCH_LITTLE_ENDIAN #elif defined(__x86_64__) #define ARCH_BYTE_ORDER ARCH_LITTLE_ENDIAN +#elif defined(__ia64__) +#define ARCH_BYTE_ORDER ARCH_LITTLE_ENDIAN #endif #ifndef ARCH_BYTE_ORDER @@ -75,7 +93,7 @@ #if __GNUC__ > 2 /* http://kerneltrap.org/node/4705 */ -#define likely(x) __builtin_expect((x),1) +#define likely(x) __builtin_expect(!!(x),1) #define unlikely(x) __builtin_expect((x),0) #else #define likely(x) (x) @@ -99,13 +117,29 @@ typedef m_uint64_t m_tmcnt_t; /* Forward declarations */ +typedef struct cpu_gen cpu_gen_t; typedef struct vm_instance vm_instance_t; -typedef struct insn_block insn_block_t; +typedef struct vm_platform vm_platform_t; +typedef struct mips64_jit_tcb mips64_jit_tcb_t; +typedef struct ppc32_jit_tcb ppc32_jit_tcb_t; +typedef struct jit_op jit_op_t; + +/* Translated block function pointer */ +typedef void (*insn_tblock_fptr)(void); + +/* Host executable page */ typedef struct insn_exec_page insn_exec_page_t; +struct insn_exec_page { + u_char *ptr; + insn_exec_page_t *next; +}; /* MIPS instruction */ typedef m_uint32_t mips_insn_t; +/* PowerPC instruction */ +typedef m_uint32_t ppc_insn_t; + /* Max and min macro */ #define m_max(a,b) (((a) > (b)) ? (a) : (b)) #define m_min(a,b) (((a) < (b)) ? (a) : (b)) @@ -138,8 +172,45 @@ m_uint64_t len; m_uint32_t cached; m_uint32_t tlb_index; + m_uint32_t offset; }mts_map_t; +/* Invalid VTLB entry */ +#define MTS_INV_ENTRY_MASK 0x00000001 + +/* MTS entry flags */ +#define MTS_FLAG_DEV 0x000000001 /* Virtual device used */ +#define MTS_FLAG_COW 0x000000002 /* Copy-On-Write */ +#define MTS_FLAG_EXEC 0x000000004 /* Exec page */ + +/* Virtual TLB entry (32-bit MMU) */ +typedef struct mts32_entry mts32_entry_t; +struct mts32_entry { + m_uint32_t gvpa; /* Guest Virtual Page Address */ + m_uint32_t gppa; /* Guest Physical Page Address */ + m_iptr_t hpa; /* Host Page Address */ + m_uint32_t flags; /* Flags */ +}__attribute__ ((aligned(16))); + +/* Virtual TLB entry (64-bit MMU) */ +typedef struct mts64_entry mts64_entry_t; +struct mts64_entry { + m_uint64_t gvpa; /* Guest Virtual Page Address */ + m_uint64_t gppa; /* Guest Physical Page Address */ + m_iptr_t hpa; /* Host Page Address */ + m_uint32_t flags; /* Flags */ +}__attribute__ ((aligned(16))); + +/* Host register allocation */ +#define HREG_FLAG_ALLOC_LOCKED 1 +#define HREG_FLAG_ALLOC_FORCED 2 + +struct hreg_map { + int hreg,vreg; + int flags; + struct hreg_map *prev,*next; +}; + /* Global logfile */ extern FILE *log_file; @@ -165,6 +236,13 @@ return (x << len) >> len; } +/* Sign-extension (32-bit) */ +static forced_inline m_int32_t sign_extend_32(m_int32_t x,int len) +{ + len = 32 - len; + return (x << len) >> len; +} + /* Extract bits from a 32-bit values */ static inline int bits(m_uint32_t val,int start,int end) { @@ -279,7 +357,7 @@ char *m_fgets(char *buffer,int size,FILE *fd); /* Read a file and returns it in a buffer */ -ssize_t m_read_file(char *filename,char **buffer); +ssize_t m_read_file(char *filename,u_char **buffer); /* Allocate aligned memory */ void *m_memalign(size_t boundary,size_t size); @@ -311,4 +389,10 @@ /* Compute NVRAM checksum */ m_uint16_t nvram_cksum(m_uint16_t *ptr,size_t count); +/* Byte-swap a memory block */ +void mem_bswap32(void *ptr,size_t len); + +/* Reverse a byte */ +m_uint8_t m_reverse_u8(m_uint8_t val); + #endif