CACAO: Update the pre-cooked .txt files to base-85 encoding
[yari.git] / yarisim / runmips.h
blobba52626b694bcab5bcc131574f43148ee4a3b0f1
1 #ifndef _RUNMIPS_H_
2 #define _RUNMIPS_H_ 1
4 #include <sys/time.h>
5 #include <stdint.h>
7 /* Basic latencies */
8 #define LOAD_LATENCY 0
9 #define MULT_LATENCY 0
10 #define DIV_LATENCY 0
11 #define SH_LATENCY 0
13 extern int enable_disass;
14 extern int enable_disass_user;
15 extern int enable_verb_elf;
16 extern int enable_forwarding;
17 extern int enable_fastbranch;
18 extern int enable_testcases;
19 extern int enable_regwrites;
20 extern int enable_firmware_mode;
21 extern int enable_cosimulation;
23 extern int endian_is_big;
25 extern struct timeval stat_start_time, stat_stop_time;
27 /* The hazards here count def-use cases with no intervening cycles,
28 not all hazards today */
29 uint64_t stat_gen_load_hazard;
30 uint64_t stat_load_use_hazard_rs;
31 uint64_t stat_load_use_hazard_rt;
32 uint64_t stat_load32_use_hazard;
33 uint64_t stat_shift_use_hazard;
34 uint64_t stat_nop;
35 uint64_t stat_nop_delay_slots;
36 uint64_t stat_nop_useless;
39 The simulation space address to physical address translation is a
40 key operation, so it has been optimized slightly.
42 First off, we can't implement a 1-1 mapping as the virtual address
43 space on the host is smaller than the target (both are 32-bit), so
44 we have to live with some sort of segmentation. An obvious first
45 approach is to divide the simulation space into 2^S segments with a
46 mapping from segments to physical segments:
48 N = 32 - S
49 segment(x) = x >> N
50 offset(x) = x & ((1 << N) - 1)
51 Inv: for all x, (segment(x) << N) + offset(x) == x
53 addr2phys(x) = memory_segment[segment(x)] + offset(x)
55 As we can't map all segments, we represent the "holes" as areas
56 laying outside the segment space:
58 addr_mapped(x) = offset(x) < memory_segment_size[segment(x)]
60 OPTIMIZATION
62 Note, the offset(x) can also be written
64 offset(x) = x - (segment(x) << N)
66 thus
68 addr2phys(x) = memory_segment[segment(x)] + x - (segment(x) << N)
70 or by arranging for memory_segment'[s] = memory_segment[s] - (s << N)
72 addr2phys(x) = memory_segment'[segment(x)] + x
74 BUT we don't do it like that below, for clairity.
77 #define SEGMENTBITS 4
78 #define OFFSETBITS (32 - SEGMENTBITS)
79 #define NSEGMENT (1 << SEGMENTBITS)
81 extern void *memory_segment[NSEGMENT];
82 extern unsigned memory_segment_size[NSEGMENT];
84 #define segment(x) (((unsigned)(x)) >> OFFSETBITS)
85 #define seg2virt(s) (((unsigned)(s)) << OFFSETBITS)
86 #define offset(x) (((unsigned)(x)) & ((1 << OFFSETBITS) - 1))
87 #define addr2phys(x) (memory_segment[segment(x)] + offset(x))
88 #define addr_mapped(x) (offset(x) < memory_segment_size[segment(x)])
90 #define EXT8(b) ((int8_t) (u_int8_t) (b))
91 #define EXT16(h)((int16_t)(u_int16_t)(h))
92 #define LD8(a) load(a,1,0)
93 #define LD16(a) load(a,2,0)
94 #define LD32(a) load(a,4,0)
96 #define ST8(a,v) store(a,v,1)
97 #define ST16(a,v) store(a,v,2)
98 #define ST32(a,v) store(a,v,4)
100 #define fatal(msg...) ({printf(msg); exit(1);})
102 extern unsigned program_entry;
103 extern unsigned text_start, text_size;
104 extern unsigned mif_size;
106 long long unsigned n_cycle, n_stall;
107 long long unsigned n_issue;
108 long long unsigned n_call;
109 long long unsigned n_icache_hits, n_icache_misses;
111 extern int rs232in_fd;
112 extern int rs232out_fd;
114 unsigned segfault;
116 void exception(char *kind);
117 void loadsection(FILE *f, unsigned f_offset, unsigned f_len, unsigned m_addr, unsigned m_len);
118 void readelf(char *name);
119 void initialize_memory(void);
120 void ensure_mapped_memory_range(unsigned addr, unsigned len);
121 void dis_load_store(char *buf, char *name, inst_t i);
122 unsigned load(unsigned a, int c, int fetch);
123 void store(unsigned a, unsigned v, int c);
124 void disass(unsigned pc, inst_t i);
126 void init_reg_use_map(void);
127 void run_simple(MIPS_state_t *s);
128 void dump(char);
129 void dump_tinymon(void);
131 // Local Variables:
132 // mode: C
133 // c-style-variables-are-local-p: t
134 // c-file-style: "linux"
135 // End:
137 #endif