YARI bugfix: the shadow of a ld/st hazard wasn't flushed
[yari.git] / shared / yarisim / runmips.h
blobe018eef2a9c6ed8bb27c649f8e3218eee2750d95
1 #ifndef _RUNMIPS_H_
2 #define _RUNMIPS_H_ 1
4 #include <SDL.h>
5 #include <sys/time.h>
6 #include <stdint.h>
8 /* Basic latencies */
9 #define LOAD_LATENCY 0
10 #define MULT_LATENCY 0
11 #define DIV_LATENCY 0
12 #define SH_LATENCY 0
14 extern int enable_disass;
15 extern int enable_disass_user;
16 extern int enable_verb_elf;
17 extern int enable_forwarding;
18 extern int enable_fastbranch;
19 extern int enable_testcases;
20 extern int enable_regwrites;
21 extern int enable_firmware_mode;
22 extern int enable_cosimulation;
23 extern int enable_register_dump;
25 extern int endian_is_big;
27 extern struct timeval stat_start_time, stat_stop_time;
29 /* The hazards here count def-use cases with no intervening cycles,
30 not all hazards today */
31 uint64_t stat_gen_load_hazard;
32 uint64_t stat_load_use_hazard_rs;
33 uint64_t stat_load_use_hazard_rt;
34 uint64_t stat_load32_use_hazard;
35 uint64_t stat_shift_use_hazard;
36 uint64_t stat_nop;
37 uint64_t stat_nop_delay_slots;
38 uint64_t stat_nop_useless;
41 The simulation space address to physical address translation is a
42 key operation, so it has been optimized slightly.
44 First off, we can't implement a 1-1 mapping as the virtual address
45 space on the host is smaller than the target (both are 32-bit), so
46 we have to live with some sort of segmentation. An obvious first
47 approach is to divide the simulation space into 2^S segments with a
48 mapping from segments to physical segments:
50 N = 32 - S
51 segment(x) = x >> N
52 offset(x) = x & ((1 << N) - 1)
53 Inv: for all x, (segment(x) << N) + offset(x) == x
55 addr2phys(x) = memory_segment[segment(x)] + offset(x)
57 As we can't map all segments, we represent the "holes" as areas
58 laying outside the segment space:
60 addr_mapped(x) = offset(x) < memory_segment_size[segment(x)]
62 OPTIMIZATION
64 Note, the offset(x) can also be written
66 offset(x) = x - (segment(x) << N)
68 thus
70 addr2phys(x) = memory_segment[segment(x)] + x - (segment(x) << N)
72 or by arranging for memory_segment'[s] = memory_segment[s] - (s << N)
74 addr2phys(x) = memory_segment'[segment(x)] + x
76 BUT we don't do it like that below, for clairity.
79 #define SEGMENTBITS 4
80 #define OFFSETBITS (32 - SEGMENTBITS)
81 #define NSEGMENT (1 << SEGMENTBITS)
83 extern void *memory_segment[NSEGMENT];
84 extern unsigned memory_segment_size[NSEGMENT];
86 #define segment(x) (((unsigned)(x)) >> OFFSETBITS)
87 #define seg2virt(s) (((unsigned)(s)) << OFFSETBITS)
88 #define offset(x) (((unsigned)(x)) & ((1 << OFFSETBITS) - 1))
89 #define addr2phys(x) (memory_segment[segment(x)] + offset(x))
90 #define addr_mapped(x) (offset(x) < memory_segment_size[segment(x)])
92 #define EXT8(b) ((int8_t) (u_int8_t) (b))
93 #define EXT16(h)((int16_t)(u_int16_t)(h))
94 #define LD8(a) load(a,1,0)
95 #define LD16(a) load(a,2,0)
96 #define LD32(a) load(a,4,0)
98 #define ST8(a,v) store(a,v,1)
99 #define ST16(a,v) store(a,v,2)
100 #define ST32(a,v) store(a,v,4)
102 #define fatal(msg...) ({printf(msg); exit(1);})
104 extern unsigned program_entry;
105 extern unsigned text_start, text_size;
106 extern unsigned mif_size;
108 long long unsigned n_cycle, n_stall;
109 long long unsigned n_issue;
110 long long unsigned n_call;
111 long long unsigned n_icache_hits, n_icache_misses;
113 extern int rs232in_fd;
114 extern int rs232out_fd;
116 unsigned keys;
118 unsigned segfault;
119 uint32_t framebuffer_start, framebuffer_size;
120 unsigned framebuffer_generation;
122 // Cache parameters in words log2
123 uint32_t icache_way_lines_log2, icache_words_in_line_log2;
124 uint32_t dcache_way_lines_log2, dcache_words_in_line_log2;
126 void exception(char *kind);
127 void loadsection(FILE *f, unsigned f_offset, unsigned f_len, unsigned m_addr, unsigned m_len);
128 void readelf(char *name);
129 void initialize_memory(void);
130 void ensure_mapped_memory_range(unsigned addr, unsigned len);
131 void dis_load_store(char *buf, char *name, inst_t i);
132 unsigned load(unsigned a, int c, int fetch);
133 void store(unsigned a, unsigned v, int c);
134 void disass(unsigned pc, inst_t i);
136 void init_reg_use_map(void);
137 void run_simple(MIPS_state_t *s);
138 void dump(const char *filename, char kind, uint32_t width, uint32_t *memory, uint32_t start, uint32_t size);
139 void dump_tinymon(void);
141 // Local Variables:
142 // mode: C
143 // c-style-variables-are-local-p: t
144 // c-file-style: "linux"
145 // End:
147 #endif