--- upstream/dynamips-0.2.6-RC1/utils.h 2007/10/06 16:03:58 2 +++ upstream/dynamips-0.2.7-RC2/utils.h 2007/10/06 16:24:54 8 @@ -1,5 +1,5 @@ /* - * Cisco 7200 (Predator) simulation platform. + * Cisco router simulation platform. * Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr) */ @@ -100,12 +100,25 @@ /* Forward declarations */ typedef struct vm_instance vm_instance_t; -typedef struct insn_block insn_block_t; +typedef struct mips64_jit_tcb mips64_jit_tcb_t; +typedef struct ppc32_jit_tcb ppc32_jit_tcb_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)) @@ -140,6 +153,32 @@ m_uint32_t tlb_index; }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))); + /* Global logfile */ extern FILE *log_file; @@ -165,6 +204,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) { @@ -223,6 +269,34 @@ return(((m_tmcnt_t)tvp.tv_sec * 1000000) + (m_tmcnt_t)tvp.tv_usec); } +#ifdef __CYGWIN__ +#define GET_TIMEZONE _timezone +#else +#define GET_TIMEZONE timezone +#endif + +/* Get current time in number of ms (localtime) */ +static inline m_tmcnt_t m_gettime_adj(void) +{ + struct timeval tvp; + struct tm tmx; + time_t gmt_adjust; + time_t ct; + + gettimeofday(&tvp,NULL); + ct = tvp.tv_sec; + localtime_r(&ct,&tmx); + +#if defined(__CYGWIN__) || defined(SUNOS) + gmt_adjust = -(tmx.tm_isdst ? GET_TIMEZONE - 3600 : GET_TIMEZONE); +#else + gmt_adjust = tmx.tm_gmtoff; +#endif + + tvp.tv_sec += gmt_adjust; + return(((m_tmcnt_t)tvp.tv_sec * 1000) + ((m_tmcnt_t)tvp.tv_usec / 1000)); +} + /* Add an element to a list */ m_list_t *m_list_add(m_list_t **head,void *data); @@ -256,4 +330,37 @@ /* Allocate aligned memory */ void *m_memalign(size_t boundary,size_t size); +/* Block specified signal for calling thread */ +int m_signal_block(int sig); + +/* Unblock specified signal for calling thread */ +int m_signal_unblock(int sig); + +/* Set non-blocking mode on a file descriptor */ +int m_fd_set_non_block(int fd); + +/* Map a memory zone from a file */ +u_char *memzone_map_file(int fd,size_t len); + +/* Map a memory zone from a file, with copy-on-write (COW) */ +u_char *memzone_map_cow_file(int fd,size_t len); + +/* Create a file to serve as a memory zone */ +int memzone_create_file(char *filename,size_t len,u_char **ptr); + +/* Open a file to serve as a COW memory zone */ +int memzone_open_cow_file(char *filename,size_t len,u_char **ptr); + +/* Open a file and map it in memory */ +int memzone_open_file(char *filename,u_char **ptr,off_t *fsize); + +/* 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