/[dynamips]/trunk/utils.h
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/utils.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

upstream/dynamips-0.2.6-RC4/utils.h revision 5 by dpavlin, Sat Oct 6 16:08:03 2007 UTC upstream/dynamips-0.2.8-RC1/utils.h revision 11 by dpavlin, Sat Oct 6 16:33:40 2007 UTC
# Line 1  Line 1 
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    
# Line 12  Line 12 
12  #include <sys/time.h>  #include <sys/time.h>
13  #include <time.h>  #include <time.h>
14  #include <netinet/in.h>  #include <netinet/in.h>
15    #include <pthread.h>
16    #include <signal.h>
17    
18  /* True/False definitions */  /* True/False definitions */
19  #ifndef FALSE  #ifndef FALSE
# Line 22  Line 24 
24  #define TRUE  1  #define TRUE  1
25  #endif  #endif
26    
27    /* Host CPU Types */
28    #define CPU_x86    0
29    #define CPU_amd64  1
30    #define CPU_nojit  2
31    
32    /* Number of host registers available for JIT */
33    #if JIT_CPU == CPU_x86
34    #define JIT_HOST_NREG  8
35    #elif JIT_CPU == CPU_amd64
36    #define JIT_HOST_NREG  16
37    #else
38    #define JIT_HOST_NREG  0
39    #endif
40    
41  /* Endianness */  /* Endianness */
42  #define ARCH_BIG_ENDIAN     0x4321  #define ARCH_BIG_ENDIAN     0x4321
43  #define ARCH_LITTLE_ENDIAN  0x1234  #define ARCH_LITTLE_ENDIAN  0x1234
# Line 36  Line 52 
52  #define ARCH_BYTE_ORDER ARCH_LITTLE_ENDIAN  #define ARCH_BYTE_ORDER ARCH_LITTLE_ENDIAN
53  #elif defined(__x86_64__)  #elif defined(__x86_64__)
54  #define ARCH_BYTE_ORDER ARCH_LITTLE_ENDIAN  #define ARCH_BYTE_ORDER ARCH_LITTLE_ENDIAN
55    #elif defined(__ia64__)
56    #define ARCH_BYTE_ORDER ARCH_LITTLE_ENDIAN
57  #endif  #endif
58    
59  #ifndef ARCH_BYTE_ORDER  #ifndef ARCH_BYTE_ORDER
# Line 75  Line 93 
93    
94  #if __GNUC__ > 2  #if __GNUC__ > 2
95  /* http://kerneltrap.org/node/4705 */  /* http://kerneltrap.org/node/4705 */
96  #define likely(x)    __builtin_expect((x),1)  #define likely(x)    __builtin_expect(!!(x),1)
97  #define unlikely(x)  __builtin_expect((x),0)  #define unlikely(x)  __builtin_expect((x),0)
98  #else  #else
99  #define likely(x)    (x)  #define likely(x)    (x)
# Line 99  typedef unsigned long m_iptr_t; Line 117  typedef unsigned long m_iptr_t;
117  typedef m_uint64_t m_tmcnt_t;  typedef m_uint64_t m_tmcnt_t;
118    
119  /* Forward declarations */  /* Forward declarations */
120    typedef struct cpu_gen cpu_gen_t;
121  typedef struct vm_instance vm_instance_t;  typedef struct vm_instance vm_instance_t;
122  typedef struct insn_block insn_block_t;  typedef struct vm_platform vm_platform_t;
123    typedef struct mips64_jit_tcb mips64_jit_tcb_t;
124    typedef struct ppc32_jit_tcb ppc32_jit_tcb_t;
125    typedef struct jit_op jit_op_t;
126    
127    /* Translated block function pointer */
128    typedef void (*insn_tblock_fptr)(void);
129    
130    /* Host executable page */
131  typedef struct insn_exec_page insn_exec_page_t;  typedef struct insn_exec_page insn_exec_page_t;
132    struct insn_exec_page {
133       u_char *ptr;
134       insn_exec_page_t *next;
135    };
136    
137  /* MIPS instruction */  /* MIPS instruction */
138  typedef m_uint32_t mips_insn_t;  typedef m_uint32_t mips_insn_t;
139    
140    /* PowerPC instruction */
141    typedef m_uint32_t ppc_insn_t;
142    
143  /* Max and min macro */  /* Max and min macro */
144  #define m_max(a,b) (((a) > (b)) ? (a) : (b))  #define m_max(a,b) (((a) > (b)) ? (a) : (b))
145  #define m_min(a,b) (((a) < (b)) ? (a) : (b))  #define m_min(a,b) (((a) < (b)) ? (a) : (b))
# Line 138  typedef struct { Line 172  typedef struct {
172     m_uint64_t len;     m_uint64_t len;
173     m_uint32_t cached;     m_uint32_t cached;
174     m_uint32_t tlb_index;     m_uint32_t tlb_index;
175       m_uint32_t offset;
176  }mts_map_t;  }mts_map_t;
177    
178    /* Invalid VTLB entry */
179    #define MTS_INV_ENTRY_MASK  0x00000001
180    
181    /* MTS entry flags */
182    #define MTS_FLAG_DEV   0x000000001   /* Virtual device used */
183    #define MTS_FLAG_COW   0x000000002   /* Copy-On-Write */
184    #define MTS_FLAG_EXEC  0x000000004   /* Exec page */
185    
186    /* Virtual TLB entry (32-bit MMU) */
187    typedef struct mts32_entry mts32_entry_t;
188    struct mts32_entry {
189       m_uint32_t gvpa;   /* Guest Virtual Page Address */
190       m_uint32_t gppa;   /* Guest Physical Page Address */
191       m_iptr_t   hpa;    /* Host Page Address */
192       m_uint32_t flags;  /* Flags */
193    }__attribute__ ((aligned(16)));
194    
195    /* Virtual TLB entry (64-bit MMU) */
196    typedef struct mts64_entry mts64_entry_t;
197    struct mts64_entry {
198       m_uint64_t gvpa;   /* Guest Virtual Page Address */
199       m_uint64_t gppa;   /* Guest Physical Page Address */
200       m_iptr_t   hpa;    /* Host Page Address */
201       m_uint32_t flags;  /* Flags */
202    }__attribute__ ((aligned(16)));
203    
204    /* Host register allocation */
205    #define HREG_FLAG_ALLOC_LOCKED  1
206    #define HREG_FLAG_ALLOC_FORCED  2
207    
208    struct hreg_map {
209       int hreg,vreg;
210       int flags;
211       struct hreg_map *prev,*next;
212    };
213    
214  /* Global logfile */  /* Global logfile */
215  extern FILE *log_file;  extern FILE *log_file;
216    
# Line 165  static forced_inline m_int64_t sign_exte Line 236  static forced_inline m_int64_t sign_exte
236     return (x << len) >> len;     return (x << len) >> len;
237  }  }
238    
239    /* Sign-extension (32-bit) */
240    static forced_inline m_int32_t sign_extend_32(m_int32_t x,int len)
241    {
242       len = 32 - len;
243       return (x << len) >> len;
244    }
245    
246  /* Extract bits from a 32-bit values */  /* Extract bits from a 32-bit values */
247  static inline int bits(m_uint32_t val,int start,int end)  static inline int bits(m_uint32_t val,int start,int end)
248  {  {
# Line 279  void m_log(char *module,char *fmt,...); Line 357  void m_log(char *module,char *fmt,...);
357  char *m_fgets(char *buffer,int size,FILE *fd);  char *m_fgets(char *buffer,int size,FILE *fd);
358    
359  /* Read a file and returns it in a buffer */  /* Read a file and returns it in a buffer */
360  ssize_t m_read_file(char *filename,char **buffer);  ssize_t m_read_file(char *filename,u_char **buffer);
361    
362  /* Allocate aligned memory */  /* Allocate aligned memory */
363  void *m_memalign(size_t boundary,size_t size);  void *m_memalign(size_t boundary,size_t size);
# Line 311  int memzone_open_file(char *filename,u_c Line 389  int memzone_open_file(char *filename,u_c
389  /* Compute NVRAM checksum */  /* Compute NVRAM checksum */
390  m_uint16_t nvram_cksum(m_uint16_t *ptr,size_t count);  m_uint16_t nvram_cksum(m_uint16_t *ptr,size_t count);
391    
392    /* Byte-swap a memory block */
393    void mem_bswap32(void *ptr,size_t len);
394    
395    /* Reverse a byte */
396    m_uint8_t m_reverse_u8(m_uint8_t val);
397    
398  #endif  #endif

Legend:
Removed from v.5  
changed lines
  Added in v.11

  ViewVC Help
Powered by ViewVC 1.1.26