/[dynamips]/trunk/insn_lookup.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

Contents of /trunk/insn_lookup.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (show annotations)
Sat Oct 6 16:45:40 2007 UTC (11 years, 7 months ago) by dpavlin
File MIME type: text/plain
File size: 2766 byte(s)
make working copy

1 /*
2 * Cisco router simulation platform.
3 * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
4 *
5 * MIPS Instruction Lookup Tables.
6 */
7
8 #ifndef __INSN_LOOKUP_H__
9 #define __INSN_LOOKUP_H__
10
11 #include "utils.h"
12 #include "hash.h"
13
14 /* Forward declaration for instruction lookup table */
15 typedef struct insn_lookup insn_lookup_t;
16
17 /* CBM (Class BitMap) array */
18 #define CBM_SHIFT 5 /* log2(32) */
19 #define CBM_SIZE (1 << CBM_SHIFT) /* Arrays of 32-bits Integers */
20 #define CBM_HASH_SIZE 256 /* Size for Hash Tables */
21
22 typedef struct cbm_array cbm_array_t;
23 struct cbm_array {
24 int nr_entries; /* Number of entries */
25 int tab[0]; /* Values... */
26 };
27
28 #define CBM_ARRAY(array,i) ((array)->tab[(i)])
29 #define CBM_CSIZE(count) (((count)*sizeof(int))+sizeof(cbm_array_t))
30
31 /* callback function prototype for instruction checking */
32 typedef int (*ilt_check_cbk_t)(void *,int value);
33 typedef void *(*ilt_get_insn_cbk_t)(int index);
34
35 /* RFC (Recursive Flow Classification) arrays */
36 #define RFC_ARRAY_MAXSIZE 65536
37 #define RFC_ARRAY_MAXBITS 16
38 #define RFC_ARRAY_NUMBER 3
39
40 typedef struct rfc_array rfc_array_t;
41 struct rfc_array {
42 rfc_array_t *parent0,*parent1;
43 int nr_elements;
44
45 /* Number of Equivalent ID */
46 int nr_eqid;
47
48 /* Hash Table for Class Bitmaps */
49 hash_table_t *cbm_hash;
50
51 /* Array to get Class Bitmaps from IDs */
52 cbm_array_t **id2cbm;
53
54 /* Equivalent ID (eqID) array */
55 int eqID[0];
56 };
57
58 /* Equivalent Classes */
59 typedef struct rfc_eqclass rfc_eqclass_t;
60 struct rfc_eqclass {
61 cbm_array_t *cbm; /* Class Bitmap */
62 int eqID; /* Index associated to this class */
63 };
64
65 /* Instruction lookup table */
66 struct insn_lookup {
67 int nr_insn; /* Number of instructions */
68 int cbm_size; /* Size of Class Bitmaps */
69
70 ilt_get_insn_cbk_t get_insn;
71 ilt_check_cbk_t chk_lo,chk_hi;
72
73 /* RFC tables */
74 rfc_array_t *rfct[RFC_ARRAY_NUMBER];
75 };
76
77 /* Instruction lookup */
78 static forced_inline int ilt_get_index(rfc_array_t *a1,rfc_array_t *a2,
79 int i1,int i2)
80 {
81 return((a1->eqID[i1]*a2->nr_eqid) + a2->eqID[i2]);
82 }
83
84 static forced_inline int ilt_get_idx(insn_lookup_t *ilt,int a1,int a2,
85 int i1,int i2)
86 {
87 return(ilt_get_index(ilt->rfct[a1],ilt->rfct[a2],i1,i2));
88 }
89
90 static forced_inline int ilt_lookup(insn_lookup_t *ilt,mips_insn_t insn)
91 {
92 int id_i;
93
94 id_i = ilt_get_idx(ilt,0,1,insn >> 16,insn & 0xFFFF);
95 return(ilt->rfct[2]->eqID[id_i]);
96 }
97
98 /* Create an instruction lookup table */
99 insn_lookup_t *ilt_create(char *table_name,
100 int nr_insn,ilt_get_insn_cbk_t get_insn,
101 ilt_check_cbk_t chk_lo,ilt_check_cbk_t chk_hi);
102
103 #endif

  ViewVC Help
Powered by ViewVC 1.1.26