| 1 | |
|---|
| 2 | #include <systemc> |
|---|
| 3 | #include <sys/time.h> |
|---|
| 4 | #include <iostream> |
|---|
| 5 | #include <cstdlib> |
|---|
| 6 | #include <cstdarg> |
|---|
| 7 | |
|---|
| 8 | #ifdef _OPENMP |
|---|
| 9 | #include <omp.h> |
|---|
| 10 | #endif |
|---|
| 11 | |
|---|
| 12 | #include "mapping_table.h" |
|---|
| 13 | #include "mips32.h" |
|---|
| 14 | #include "vci_simple_ram.h" |
|---|
| 15 | #include "vci_multi_tty.h" |
|---|
| 16 | #include "vci_vgmn.h" |
|---|
| 17 | #include "vci_mem_cache_v4.h" |
|---|
| 18 | #include "vci_cc_vcache_wrapper_v4.h" |
|---|
| 19 | #include "vci_xicu.h" |
|---|
| 20 | #include "vci_simhelper.h" |
|---|
| 21 | #include "vci_multi_dma.h" |
|---|
| 22 | |
|---|
| 23 | // VCI format |
|---|
| 24 | |
|---|
| 25 | #define cell_width 4 |
|---|
| 26 | #define address_width 32 |
|---|
| 27 | #define plen_width 8 |
|---|
| 28 | #define error_width 2 |
|---|
| 29 | #define clen_width 1 |
|---|
| 30 | #define rflag_width 1 |
|---|
| 31 | #define srcid_width 14 |
|---|
| 32 | #define pktid_width 4 |
|---|
| 33 | #define trdid_width 4 |
|---|
| 34 | #define wrplen_width 1 |
|---|
| 35 | |
|---|
| 36 | // segments definition in direct space |
|---|
| 37 | |
|---|
| 38 | #define XICU_BASE 0xd8200000 |
|---|
| 39 | #define XICU_SIZE 0x00001000 |
|---|
| 40 | |
|---|
| 41 | #define MDMA_BASE 0xe8000000 |
|---|
| 42 | #define MDMA_SIZE 0x00000014 |
|---|
| 43 | |
|---|
| 44 | #define MTTY_BASE 0xd0200000 |
|---|
| 45 | #define MTTY_SIZE 0x00000010 |
|---|
| 46 | |
|---|
| 47 | #define EXIT_BASE 0xe0000000 |
|---|
| 48 | #define EXIT_SIZE 0x00000010 |
|---|
| 49 | |
|---|
| 50 | #define BOOT_BASE 0xbfc00000 |
|---|
| 51 | #define BOOT_SIZE 0x00040000 |
|---|
| 52 | |
|---|
| 53 | #define MEMC_BASE 0x00000000 |
|---|
| 54 | #define MEMC_SIZE 0x02000000 |
|---|
| 55 | |
|---|
| 56 | // segments definition in coherence space |
|---|
| 57 | |
|---|
| 58 | #define C_L1_BASE 0x10000000 |
|---|
| 59 | #define C_L1_SIZE 0x00000010 |
|---|
| 60 | |
|---|
| 61 | #define C_MC_BASE 0x00000000 |
|---|
| 62 | #define C_MC_SIZE 0x02000010 |
|---|
| 63 | |
|---|
| 64 | #define C_BR_BASE 0xbfc00000 |
|---|
| 65 | #define C_BR_SIZE 0x00040000 |
|---|
| 66 | |
|---|
| 67 | ///////////////////////////////// |
|---|
| 68 | int _main(int argc, char *argv[]) |
|---|
| 69 | { |
|---|
| 70 | |
|---|
| 71 | using namespace sc_core; |
|---|
| 72 | using namespace soclib::common; |
|---|
| 73 | using namespace soclib::caba; |
|---|
| 74 | |
|---|
| 75 | #ifdef _OPENMP |
|---|
| 76 | omp_set_dynamic(false); |
|---|
| 77 | omp_set_num_threads(1); |
|---|
| 78 | std::cerr << "Built with openmp version " << _OPENMP << std::endl; |
|---|
| 79 | #endif |
|---|
| 80 | |
|---|
| 81 | char soft_name[256] = "test.elf"; // pathname to binary code |
|---|
| 82 | size_t ncycles = 1000000000; // max number of simulation cycles |
|---|
| 83 | bool trace_ok = false; |
|---|
| 84 | size_t from_cycle = 0; // debug start cycle |
|---|
| 85 | size_t max_frozen = 1000; // max number of frozen cycles |
|---|
| 86 | |
|---|
| 87 | /////////////// command line arguments //////////////// |
|---|
| 88 | if (argc > 1) |
|---|
| 89 | { |
|---|
| 90 | for( int n=1 ; n<argc ; n=n+2 ) |
|---|
| 91 | { |
|---|
| 92 | if( (strcmp(argv[n],"-NCYCLES") == 0) && (n+1<argc) ) |
|---|
| 93 | { |
|---|
| 94 | ncycles = atoi(argv[n+1]); |
|---|
| 95 | } |
|---|
| 96 | else if( (strcmp(argv[n],"-SOFT") == 0) && (n+1<argc) ) |
|---|
| 97 | { |
|---|
| 98 | strcpy(soft_name, argv[n+1]); |
|---|
| 99 | } |
|---|
| 100 | else if( (strcmp(argv[n],"-TRACE") == 0) && (n+1<argc) ) |
|---|
| 101 | { |
|---|
| 102 | trace_ok = true; |
|---|
| 103 | from_cycle = atoi(argv[n+1]); |
|---|
| 104 | } |
|---|
| 105 | else if( (strcmp(argv[n],"-MAXFROZEN") == 0) && (n+1<argc) ) |
|---|
| 106 | { |
|---|
| 107 | max_frozen = atoi(argv[n+1]); |
|---|
| 108 | } |
|---|
| 109 | else |
|---|
| 110 | { |
|---|
| 111 | std::cout << " Arguments on the command line are (key,value) couples." << std::endl; |
|---|
| 112 | std::cout << " The order is not important." << std::endl; |
|---|
| 113 | std::cout << " Accepted arguments are :" << std::endl << std::endl; |
|---|
| 114 | std::cout << " -SOFT pathname_for_embedded_soft" << std::endl; |
|---|
| 115 | std::cout << " -NCYCLES number_of_simulated_cycles" << std::endl; |
|---|
| 116 | std::cout << " -TRACE debug_start_cycle" << std::endl; |
|---|
| 117 | exit(0); |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | // Define VCI parameters |
|---|
| 123 | typedef VciParams<cell_width, |
|---|
| 124 | plen_width, |
|---|
| 125 | address_width, |
|---|
| 126 | error_width, |
|---|
| 127 | clen_width, |
|---|
| 128 | rflag_width, |
|---|
| 129 | srcid_width, |
|---|
| 130 | pktid_width, |
|---|
| 131 | trdid_width, |
|---|
| 132 | wrplen_width> vci_param; |
|---|
| 133 | |
|---|
| 134 | // Define processor type |
|---|
| 135 | typedef soclib::common::Mips32ElIss proc_iss; |
|---|
| 136 | |
|---|
| 137 | // Mapping table for direct network |
|---|
| 138 | soclib::common::MappingTable maptabd(32, IntTab(6), IntTab(6), 0xF0000000); |
|---|
| 139 | maptabd.add(Segment("memc_d" , MEMC_BASE , MEMC_SIZE , IntTab(0), true)); |
|---|
| 140 | maptabd.add(Segment("boot_d" , BOOT_BASE , BOOT_SIZE , IntTab(1), true)); |
|---|
| 141 | maptabd.add(Segment("exit_d" , EXIT_BASE , EXIT_SIZE , IntTab(2), false)); |
|---|
| 142 | maptabd.add(Segment("mtty_d" , MTTY_BASE , MTTY_SIZE , IntTab(3), false)); |
|---|
| 143 | maptabd.add(Segment("xicu_d" , XICU_BASE , XICU_SIZE , IntTab(4), false)); |
|---|
| 144 | maptabd.add(Segment("mdma_d" , MDMA_BASE , MDMA_SIZE , IntTab(5), false)); |
|---|
| 145 | std::cout << maptabd << std::endl; |
|---|
| 146 | |
|---|
| 147 | // Mapping table for coherence network |
|---|
| 148 | soclib::common::MappingTable maptabc(32, IntTab(6), IntTab(6), 0xF0000000); |
|---|
| 149 | maptabc.add(Segment("proc_c" , C_L1_BASE , C_L1_SIZE , IntTab(0), false, true, IntTab(0))); |
|---|
| 150 | maptabc.add(Segment("memc_c" , C_MC_BASE , C_MC_SIZE , IntTab(1), false )); |
|---|
| 151 | maptabc.add(Segment("brom_c" , C_BR_BASE , C_BR_SIZE , IntTab(1), false )); |
|---|
| 152 | std::cout << maptabc << std::endl; |
|---|
| 153 | |
|---|
| 154 | // Signals |
|---|
| 155 | |
|---|
| 156 | sc_clock signal_clk ("signal_clk"); |
|---|
| 157 | sc_signal<bool> signal_resetn ("isgnal_resetn"); |
|---|
| 158 | |
|---|
| 159 | sc_signal<bool> signal_mdma_irq ("signal_mdma_irq"); |
|---|
| 160 | sc_signal<bool> signal_mtty_irq ("signal_mtty_irq"); |
|---|
| 161 | sc_signal<bool> signal_proc_irq ("signal_proc_irq"); |
|---|
| 162 | sc_signal<bool> signal_false ("signal_false"); |
|---|
| 163 | |
|---|
| 164 | VciSignals<vci_param> signal_vci_ini_d_proc ("vci_ini_d_proc"); |
|---|
| 165 | VciSignals<vci_param> signal_vci_ini_c_proc ("vci_ini_c_proc"); |
|---|
| 166 | VciSignals<vci_param> signal_vci_tgt_c_proc ("vci_tgt_c_proc"); |
|---|
| 167 | |
|---|
| 168 | VciSignals<vci_param> signal_vci_tgt_d_mtty ("signal_vci_tgt_d_mtty"); |
|---|
| 169 | |
|---|
| 170 | VciSignals<vci_param> signal_vci_tgt_d_exit ("signal_vci_tgt_d_exit"); |
|---|
| 171 | |
|---|
| 172 | VciSignals<vci_param> signal_vci_tgt_d_xicu ("signal_vci_tgt_d_xicu"); |
|---|
| 173 | |
|---|
| 174 | VciSignals<vci_param> signal_vci_ini_d_mdma ("signal_vci_ini_d_mdma"); |
|---|
| 175 | VciSignals<vci_param> signal_vci_tgt_d_mdma ("signal_vci_tgt_d_mdma"); |
|---|
| 176 | |
|---|
| 177 | VciSignals<vci_param> signal_vci_tgt_d_brom ("signal_vci_tgt_d_brom"); |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | VciSignals<vci_param> signal_vci_ini_c_memc ("signal_vci_ini_c_memc"); |
|---|
| 181 | VciSignals<vci_param> signal_vci_tgt_d_memc ("signal_vci_tgt_d_memc"); |
|---|
| 182 | VciSignals<vci_param> signal_vci_tgt_c_memc ("signal_vci_tgt_c_memc"); |
|---|
| 183 | |
|---|
| 184 | VciSignals<vci_param> signal_vci_xram ("signal_vci_xram"); |
|---|
| 185 | |
|---|
| 186 | // Components |
|---|
| 187 | |
|---|
| 188 | soclib::common::Loader loader(soft_name); |
|---|
| 189 | |
|---|
| 190 | VciCcVCacheWrapperV4<vci_param, proc_iss > |
|---|
| 191 | proc("proc", |
|---|
| 192 | 0, // proc_id |
|---|
| 193 | maptabd, // direct space |
|---|
| 194 | maptabc, // coherence space |
|---|
| 195 | IntTab(0), // srcid_d |
|---|
| 196 | IntTab(0), // srcid_c |
|---|
| 197 | IntTab(0), // tgtid_c |
|---|
| 198 | 8,8, // itlb size |
|---|
| 199 | 8,8, // dtlb size |
|---|
| 200 | 4,64,16, // icache size |
|---|
| 201 | 4,64,16, // dcache size |
|---|
| 202 | 4, 4, // wbuf size |
|---|
| 203 | max_frozen, // max frozen cycles |
|---|
| 204 | from_cycle, trace_ok); |
|---|
| 205 | |
|---|
| 206 | VciSimpleRam<vci_param> |
|---|
| 207 | rom("rom", |
|---|
| 208 | IntTab(1), // tgtid_d |
|---|
| 209 | maptabd, |
|---|
| 210 | loader); |
|---|
| 211 | |
|---|
| 212 | VciSimpleRam<vci_param> |
|---|
| 213 | xram("xram", |
|---|
| 214 | IntTab(0), // tgtid_d(RAM) = tgtid_d(MEMC) |
|---|
| 215 | maptabd, |
|---|
| 216 | loader); |
|---|
| 217 | |
|---|
| 218 | VciMemCacheV4<vci_param> |
|---|
| 219 | memc("memc", |
|---|
| 220 | maptabd, |
|---|
| 221 | maptabc, |
|---|
| 222 | maptabd, |
|---|
| 223 | IntTab(0), // srcid_x |
|---|
| 224 | IntTab(1), // srcid_c |
|---|
| 225 | IntTab(0), // tgtid_d |
|---|
| 226 | IntTab(1), // tgtid_c |
|---|
| 227 | 16,256,16, // cache size |
|---|
| 228 | 1024, // HEAP size |
|---|
| 229 | 4, // TRT size |
|---|
| 230 | 4, // UPT size |
|---|
| 231 | from_cycle, trace_ok); |
|---|
| 232 | |
|---|
| 233 | VciSimhelper<vci_param> |
|---|
| 234 | vciexit("vciexit", |
|---|
| 235 | IntTab(2), // tgtid_d |
|---|
| 236 | maptabd); |
|---|
| 237 | |
|---|
| 238 | VciXicu<vci_param> |
|---|
| 239 | xicu("xicu", |
|---|
| 240 | maptabd, |
|---|
| 241 | IntTab(4), // tgtid_d |
|---|
| 242 | 1, // number of timers |
|---|
| 243 | 2, // number of hard interrupts |
|---|
| 244 | 0, // number of soft interrupts |
|---|
| 245 | 1); // number of output IRQs |
|---|
| 246 | |
|---|
| 247 | VciMultiTty<vci_param> |
|---|
| 248 | mtty("mtty", |
|---|
| 249 | IntTab(3), // tgtid_d |
|---|
| 250 | maptabd, |
|---|
| 251 | "mtty0", NULL); |
|---|
| 252 | |
|---|
| 253 | VciMultiDma<vci_param> |
|---|
| 254 | mdma("mdma", |
|---|
| 255 | maptabd, |
|---|
| 256 | IntTab(1), // srcid_d |
|---|
| 257 | IntTab(5), // tgtid_d |
|---|
| 258 | 64, // burst size |
|---|
| 259 | 1); // number of channels |
|---|
| 260 | |
|---|
| 261 | VciVgmn<vci_param> |
|---|
| 262 | ringd("ringd", |
|---|
| 263 | maptabd, |
|---|
| 264 | 2, // number of initiators |
|---|
| 265 | 6, // number of targets |
|---|
| 266 | 2, |
|---|
| 267 | 8); |
|---|
| 268 | |
|---|
| 269 | VciVgmn<vci_param> |
|---|
| 270 | ringc("ringc", |
|---|
| 271 | maptabc, |
|---|
| 272 | 2, // number of initiators |
|---|
| 273 | 2, // number of targets |
|---|
| 274 | 2, |
|---|
| 275 | 8); |
|---|
| 276 | |
|---|
| 277 | // net-list |
|---|
| 278 | proc.p_clk(signal_clk); |
|---|
| 279 | proc.p_resetn (signal_resetn); |
|---|
| 280 | proc.p_irq[0] (signal_proc_irq); |
|---|
| 281 | proc.p_irq[1] (signal_false); |
|---|
| 282 | proc.p_irq[2] (signal_false); |
|---|
| 283 | proc.p_irq[3] (signal_false); |
|---|
| 284 | proc.p_irq[4] (signal_false); |
|---|
| 285 | proc.p_irq[5] (signal_false); |
|---|
| 286 | proc.p_vci_ini_d (signal_vci_ini_d_proc); |
|---|
| 287 | proc.p_vci_ini_c (signal_vci_ini_c_proc); |
|---|
| 288 | proc.p_vci_tgt_c (signal_vci_tgt_c_proc); |
|---|
| 289 | |
|---|
| 290 | rom.p_clk (signal_clk); |
|---|
| 291 | rom.p_resetn (signal_resetn); |
|---|
| 292 | rom.p_vci (signal_vci_tgt_d_brom); |
|---|
| 293 | |
|---|
| 294 | xicu.p_resetn (signal_resetn); |
|---|
| 295 | xicu.p_clk (signal_clk); |
|---|
| 296 | xicu.p_vci (signal_vci_tgt_d_xicu); |
|---|
| 297 | xicu.p_hwi[0] (signal_mtty_irq); |
|---|
| 298 | xicu.p_hwi[1] (signal_mdma_irq); |
|---|
| 299 | xicu.p_irq[0] (signal_proc_irq); |
|---|
| 300 | |
|---|
| 301 | mdma.p_clk (signal_clk); |
|---|
| 302 | mdma.p_resetn (signal_resetn); |
|---|
| 303 | mdma.p_vci_target (signal_vci_tgt_d_mdma); |
|---|
| 304 | mdma.p_vci_initiator (signal_vci_ini_d_mdma); |
|---|
| 305 | mdma.p_irq[0] (signal_mdma_irq); |
|---|
| 306 | |
|---|
| 307 | mtty.p_clk (signal_clk); |
|---|
| 308 | mtty.p_resetn (signal_resetn); |
|---|
| 309 | mtty.p_vci (signal_vci_tgt_d_mtty); |
|---|
| 310 | mtty.p_irq[0] (signal_mtty_irq); |
|---|
| 311 | |
|---|
| 312 | vciexit.p_clk (signal_clk); |
|---|
| 313 | vciexit.p_resetn (signal_resetn); |
|---|
| 314 | vciexit.p_vci (signal_vci_tgt_d_exit); |
|---|
| 315 | |
|---|
| 316 | memc.p_clk (signal_clk); |
|---|
| 317 | memc.p_resetn (signal_resetn); |
|---|
| 318 | memc.p_vci_tgt (signal_vci_tgt_d_memc); |
|---|
| 319 | memc.p_vci_tgt_cleanup (signal_vci_tgt_c_memc); |
|---|
| 320 | memc.p_vci_ini (signal_vci_ini_c_memc); |
|---|
| 321 | memc.p_vci_ixr (signal_vci_xram); |
|---|
| 322 | |
|---|
| 323 | xram.p_clk (signal_clk); |
|---|
| 324 | xram.p_resetn (signal_resetn); |
|---|
| 325 | xram.p_vci (signal_vci_xram); |
|---|
| 326 | |
|---|
| 327 | ringc.p_clk (signal_clk); |
|---|
| 328 | ringc.p_resetn (signal_resetn); |
|---|
| 329 | ringc.p_to_initiator[0] (signal_vci_ini_c_proc); |
|---|
| 330 | ringc.p_to_initiator[1] (signal_vci_ini_c_memc); |
|---|
| 331 | ringc.p_to_target[0] (signal_vci_tgt_c_proc); |
|---|
| 332 | ringc.p_to_target[1] (signal_vci_tgt_c_memc); |
|---|
| 333 | |
|---|
| 334 | ringd.p_clk (signal_clk); |
|---|
| 335 | ringd.p_resetn (signal_resetn); |
|---|
| 336 | ringd.p_to_initiator[0] (signal_vci_ini_d_proc); |
|---|
| 337 | ringd.p_to_initiator[1] (signal_vci_ini_d_mdma); |
|---|
| 338 | ringd.p_to_target[0] (signal_vci_tgt_d_memc); |
|---|
| 339 | ringd.p_to_target[1] (signal_vci_tgt_d_brom); |
|---|
| 340 | ringd.p_to_target[2] (signal_vci_tgt_d_exit); |
|---|
| 341 | ringd.p_to_target[3] (signal_vci_tgt_d_mtty); |
|---|
| 342 | ringd.p_to_target[4] (signal_vci_tgt_d_xicu); |
|---|
| 343 | ringd.p_to_target[5] (signal_vci_tgt_d_mdma); |
|---|
| 344 | |
|---|
| 345 | // simulation loop |
|---|
| 346 | |
|---|
| 347 | sc_start(sc_core::sc_time(0, SC_NS)); |
|---|
| 348 | signal_resetn = false; |
|---|
| 349 | |
|---|
| 350 | sc_start(sc_core::sc_time(1, SC_NS)); |
|---|
| 351 | signal_resetn = true; |
|---|
| 352 | |
|---|
| 353 | signal_false = false; |
|---|
| 354 | |
|---|
| 355 | for ( size_t n=1 ; n<ncycles ; n++ ) |
|---|
| 356 | { |
|---|
| 357 | if ( trace_ok and (n > from_cycle) ) |
|---|
| 358 | { |
|---|
| 359 | std::cout << "****************** cycle " << std::dec << n |
|---|
| 360 | << " ************************************************" << std::endl; |
|---|
| 361 | proc.print_trace(); |
|---|
| 362 | memc.print_trace(); |
|---|
| 363 | signal_vci_ini_d_proc.print_trace("proc_ini_d"); |
|---|
| 364 | signal_vci_tgt_c_proc.print_trace("proc_tgt_c"); |
|---|
| 365 | signal_vci_ini_c_proc.print_trace("proc_ini_c"); |
|---|
| 366 | signal_vci_tgt_d_memc.print_trace("memc_tgt_d"); |
|---|
| 367 | signal_vci_tgt_c_memc.print_trace("memc_tgt_c"); |
|---|
| 368 | signal_vci_ini_c_memc.print_trace("memc_ini_c"); |
|---|
| 369 | if ( signal_proc_irq.read() ) std::cout << "---- IRQ ----" << std::endl; |
|---|
| 370 | } |
|---|
| 371 | sc_start(sc_core::sc_time(1, SC_NS)); |
|---|
| 372 | } |
|---|
| 373 | return EXIT_SUCCESS; |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | int sc_main (int argc, char *argv[]) |
|---|
| 377 | { |
|---|
| 378 | try { |
|---|
| 379 | return _main(argc, argv); |
|---|
| 380 | } catch (std::exception &e) { |
|---|
| 381 | std::cout << e.what() << std::endl; |
|---|
| 382 | } catch (...) { |
|---|
| 383 | std::cout << "Unknown exception occured" << std::endl; |
|---|
| 384 | throw; |
|---|
| 385 | } |
|---|
| 386 | return 1; |
|---|
| 387 | } |
|---|