[410] | 1 | /* |
---|
| 2 | * global config |
---|
| 3 | */ |
---|
| 4 | |
---|
| 5 | #define CONFIG_GDB_SERVER |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | /* |
---|
| 9 | * headers |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | #ifdef _OPENMP |
---|
| 13 | #include <omp.h> |
---|
| 14 | #endif |
---|
| 15 | |
---|
| 16 | #include <systemc> |
---|
| 17 | #include <iostream> |
---|
| 18 | #include <cstdlib> |
---|
| 19 | |
---|
| 20 | #ifdef CONFIG_GDB_SERVER |
---|
| 21 | #include "gdbserver.h" |
---|
| 22 | #endif |
---|
| 23 | |
---|
| 24 | #include "mapping_table.h" |
---|
| 25 | |
---|
| 26 | #include "mips32.h" |
---|
| 27 | #include "vci_cc_vcache_wrapper_v4.h" |
---|
| 28 | #include "vci_simple_ram.h" |
---|
| 29 | #include "vci_mem_cache_v4.h" |
---|
| 30 | |
---|
| 31 | #include "vci_simhelper.h" |
---|
| 32 | #include "vci_multi_tty.h" |
---|
| 33 | #include "vci_xicu.h" |
---|
| 34 | #include "vci_block_device_tsar_v4.h" |
---|
| 35 | |
---|
| 36 | #include "vci_vgmn.h" |
---|
| 37 | |
---|
| 38 | #include "alloc_elems.h" |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | /* |
---|
| 42 | * pf global config |
---|
| 43 | */ |
---|
| 44 | |
---|
| 45 | using namespace sc_core; |
---|
| 46 | using namespace soclib::caba; |
---|
| 47 | using namespace soclib::common; |
---|
| 48 | |
---|
| 49 | #define cell_width 4 |
---|
| 50 | #define address_width 32 |
---|
| 51 | #define plen_width 8 |
---|
| 52 | #define error_width 2 |
---|
| 53 | #define clen_width 1 |
---|
| 54 | #define rflag_width 1 |
---|
| 55 | #define srcid_width 14 |
---|
| 56 | #define pktid_width 4 |
---|
| 57 | #define trdid_width 4 |
---|
| 58 | #define wrplen_width 1 |
---|
| 59 | |
---|
| 60 | typedef VciParams<cell_width, |
---|
| 61 | plen_width, |
---|
| 62 | address_width, |
---|
| 63 | error_width, |
---|
| 64 | clen_width, |
---|
| 65 | rflag_width, |
---|
| 66 | srcid_width, |
---|
| 67 | pktid_width, |
---|
| 68 | trdid_width, |
---|
| 69 | wrplen_width> vci_param; |
---|
| 70 | |
---|
| 71 | /* mapping table for data */ |
---|
| 72 | MappingTable maptabd(32, IntTab(6), IntTab(6), 0xf0000000); |
---|
| 73 | /* mapping table for coherence */ |
---|
| 74 | MappingTable maptabc(32, IntTab(srcid_width), IntTab(srcid_width), 0xf0000000); |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | /* |
---|
| 78 | * segmentation |
---|
| 79 | */ |
---|
| 80 | |
---|
| 81 | #include "segmentation.h" |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | /* |
---|
| 85 | * default parameters |
---|
| 86 | */ |
---|
| 87 | |
---|
| 88 | char *soft_path = NULL; |
---|
| 89 | char *bd_path = NULL; |
---|
| 90 | bool trace_enabled = false; |
---|
| 91 | size_t trace_start_cycle = 0; |
---|
| 92 | |
---|
| 93 | /* |
---|
| 94 | * arguments parsing |
---|
| 95 | */ |
---|
| 96 | |
---|
| 97 | void args_parse(unsigned int argc, char *argv[]) |
---|
| 98 | { |
---|
| 99 | if (argc > 1) |
---|
| 100 | { |
---|
| 101 | for (size_t n = 1; n < argc; n = n + 2) |
---|
| 102 | { |
---|
| 103 | if ((strcmp(argv[n], "-soft") == 0) && ((n + 1) < argc)) |
---|
| 104 | { |
---|
| 105 | assert((soft_path = strdup(argv[n + 1])) |
---|
| 106 | && "insufficient memory"); |
---|
| 107 | } |
---|
| 108 | else if ((strcmp(argv[n], "-img") == 0) && ((n + 1) < argc)) |
---|
| 109 | { |
---|
| 110 | assert((bd_path = strdup(argv[n + 1])) |
---|
| 111 | && "insufficient memory"); |
---|
| 112 | } |
---|
| 113 | else if ((strcmp(argv[n], "-trace") == 0) && ((n + 1) < argc)) |
---|
| 114 | { |
---|
| 115 | trace_enabled = true; |
---|
| 116 | trace_start_cycle = atoi(argv[n + 1]); |
---|
| 117 | } |
---|
| 118 | else |
---|
| 119 | { |
---|
| 120 | std::cout << "Error: don't understand option " << argv[n] << std::endl; |
---|
| 121 | std::cout << "Accepted arguments are :" << std::endl; |
---|
| 122 | std::cout << "-soft pathname" << std::endl; |
---|
| 123 | std::cout << "-img pathname" << std::endl; |
---|
| 124 | std::cout << "[-trace trace_start_cycle]" << std::endl; |
---|
| 125 | exit(0); |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | assert(soft_path && "-soft is not optional"); |
---|
| 131 | assert(bd_path && "-img is not optional"); |
---|
| 132 | std::cout << std::endl; |
---|
| 133 | std::cout << "simulation parameters:" << std::endl; |
---|
| 134 | std::cout << " soft = " << soft_path << std::endl; |
---|
| 135 | std::cout << " img = " << bd_path << std::endl; |
---|
| 136 | std::cout << " trace = " << trace_enabled << std::endl; |
---|
| 137 | std::cout << std::endl; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | /* |
---|
| 142 | * netlist |
---|
| 143 | */ |
---|
| 144 | |
---|
| 145 | int _main(int argc, char *argv[]) |
---|
| 146 | { |
---|
| 147 | #ifdef _OPENMP |
---|
| 148 | omp_set_dynamic(false); |
---|
| 149 | omp_set_num_threads(1); |
---|
| 150 | std::cerr << "Built with openmp version " << _OPENMP << std::endl; |
---|
| 151 | #endif |
---|
| 152 | |
---|
| 153 | /* parse arguments */ |
---|
| 154 | args_parse(argc, argv); |
---|
| 155 | |
---|
| 156 | /* |
---|
| 157 | * mapping table |
---|
| 158 | */ |
---|
| 159 | |
---|
| 160 | // caches ram bank |
---|
| 161 | maptabd.add(Segment("memc_d" , MEMC_BASE , MEMC_SIZE , IntTab(0), true)); |
---|
| 162 | maptabd.add(Segment("boot_d" , BOOT_BASE , BOOT_SIZE , IntTab(1), true)); |
---|
| 163 | |
---|
| 164 | // uncached peripherals |
---|
| 165 | maptabd.add(Segment("exit_d" , EXIT_BASE , EXIT_SIZE , IntTab(2), false)); |
---|
| 166 | maptabd.add(Segment("mtty_d" , MTTY_BASE , MTTY_SIZE , IntTab(3), false)); |
---|
| 167 | maptabd.add(Segment("xicu_d" , XICU_BASE , XICU_SIZE , IntTab(4), false)); |
---|
| 168 | maptabd.add(Segment("iobd_d" , IOBD_BASE , IOBD_SIZE , IntTab(5), false)); |
---|
| 169 | |
---|
| 170 | std::cout << maptabd << std::endl; |
---|
| 171 | |
---|
| 172 | // procs |
---|
| 173 | maptabc.add(Segment("proc_c" , 0x0000000 , 0x10 , IntTab(0) , false)); |
---|
| 174 | maptabc.add(Segment("memc_c" , 1 << (address_width - srcid_width) , 0x10 , IntTab(1) , false)); |
---|
| 175 | |
---|
| 176 | std::cout << maptabc << std::endl; |
---|
| 177 | |
---|
| 178 | /* |
---|
| 179 | * components |
---|
| 180 | */ |
---|
| 181 | |
---|
| 182 | Loader loader; |
---|
| 183 | loader.load_file(soft_path); |
---|
| 184 | |
---|
| 185 | #ifdef CONFIG_GDB_SERVER |
---|
| 186 | typedef GdbServer<Mips32ElIss> proc_iss; |
---|
| 187 | proc_iss::set_loader(loader); |
---|
| 188 | #else |
---|
| 189 | typedef Mips32ElIss proc_iss; |
---|
| 190 | #endif |
---|
| 191 | |
---|
| 192 | VciCcVCacheWrapperV4<vci_param, proc_iss > proc("ccvcache", |
---|
| 193 | 0, // proc_id |
---|
| 194 | maptabd, // direct space |
---|
| 195 | maptabc, // coherence space |
---|
| 196 | IntTab(0), // srcid_d |
---|
| 197 | IntTab(0), // srcid_c |
---|
| 198 | IntTab(0), // tgtid_c |
---|
| 199 | 8, 8, // itlb size |
---|
| 200 | 8, 8, // dtlb size |
---|
| 201 | 4, 64, 16, // icache size |
---|
| 202 | 4, 64, 16, // dcache size |
---|
| 203 | 4, 4, // wbuf size |
---|
| 204 | 0, 0, // x, y Width |
---|
| 205 | 1, // memory cache local id |
---|
| 206 | 1000, // max frozen cycles |
---|
| 207 | trace_start_cycle, |
---|
| 208 | trace_enabled); |
---|
| 209 | |
---|
| 210 | VciSimpleRam<vci_param> xram("xram", IntTab(0), maptabd, loader); |
---|
| 211 | |
---|
| 212 | VciSimpleRam<vci_param> rom("rom", IntTab(1), maptabd, loader); |
---|
| 213 | |
---|
| 214 | VciMemCacheV4<vci_param> memc("memc", |
---|
| 215 | maptabd, maptabc, maptabd, |
---|
| 216 | IntTab(0), IntTab(1), IntTab(0), IntTab(1), // srcid_d, srcid_c, tgtid_d, tgtid_c |
---|
| 217 | 16, 256, 16, // cache size |
---|
| 218 | 1024, 4, 4, // HEAP size, TRT size, UPT size |
---|
| 219 | trace_start_cycle, trace_enabled); |
---|
| 220 | |
---|
| 221 | VciSimhelper<vci_param> vciexit("vciexit", IntTab(2), maptabd); |
---|
| 222 | |
---|
| 223 | VciXicu<vci_param> xicu("xicu", maptabd, IntTab(4), |
---|
| 224 | 1, 2, 0, 1); // #timers, #hard_irqs, #soft_irqs, # output_irqs |
---|
| 225 | |
---|
| 226 | VciMultiTty<vci_param> mtty("mtty", IntTab(3), maptabd, "vcitty0", NULL); |
---|
| 227 | |
---|
| 228 | VciBlockDeviceTsarV4<vci_param> iobd("iobd", maptabd, IntTab(1), IntTab(5), |
---|
| 229 | bd_path); // mapped_file[, block_size=512, latency=0] |
---|
| 230 | |
---|
| 231 | VciVgmn<vci_param> ringd("ringd", maptabd, |
---|
| 232 | 2, 6, // #initiators, #targets |
---|
| 233 | 2, 8); // min_latency, FIFO depth |
---|
| 234 | |
---|
| 235 | VciVgmn<vci_param> ringc("ringc", maptabc, |
---|
| 236 | 2, 2, // #initiators, #targets |
---|
| 237 | 2, 8); // min_latency, FIFO depth |
---|
| 238 | |
---|
| 239 | /* |
---|
| 240 | * signals |
---|
| 241 | */ |
---|
| 242 | |
---|
| 243 | /* clock and reset */ |
---|
| 244 | sc_clock signal_clk("signal_clk"); |
---|
| 245 | sc_signal<bool> signal_resetn("signal_resetn"); |
---|
| 246 | |
---|
| 247 | /* irq lines */ |
---|
| 248 | sc_signal<bool> *signal_proc_irq = |
---|
| 249 | alloc_elems<sc_signal<bool> >("signal_proc_irq", proc_iss::n_irq); |
---|
| 250 | sc_signal<bool> signal_mtty_irq("signal_mtty_irq"); |
---|
| 251 | sc_signal<bool> signal_iobd_irq("signal_iobd_irq"); |
---|
| 252 | |
---|
| 253 | /* vci */ |
---|
| 254 | VciSignals<vci_param> signal_vci_ini_d_proc("vci_ini_d_proc"); |
---|
| 255 | VciSignals<vci_param> signal_vci_ini_c_proc("vci_ini_c_proc"); |
---|
| 256 | VciSignals<vci_param> signal_vci_tgt_c_proc("vci_tgt_c_proc"); |
---|
| 257 | |
---|
| 258 | VciSignals<vci_param> signal_vci_xram("signal_vci_xram"); |
---|
| 259 | |
---|
| 260 | VciSignals<vci_param> signal_vci_tgt_d_brom("signal_vci_tgt_d_brom"); |
---|
| 261 | |
---|
| 262 | VciSignals<vci_param> signal_vci_ini_c_memc("signal_vci_ini_c_memc"); |
---|
| 263 | VciSignals<vci_param> signal_vci_tgt_d_memc("signal_vci_tgt_d_memc"); |
---|
| 264 | VciSignals<vci_param> signal_vci_tgt_c_memc("signal_vci_tgt_c_memc"); |
---|
| 265 | |
---|
| 266 | VciSignals<vci_param> signal_vci_tgt_d_exit("signal_vci_tgt_d_exit"); |
---|
| 267 | |
---|
| 268 | VciSignals<vci_param> signal_vci_tgt_d_xicu("signal_vci_tgt_d_xicu"); |
---|
| 269 | |
---|
| 270 | VciSignals<vci_param> signal_vci_tgt_d_mtty("signal_vci_tgt_d_mtty"); |
---|
| 271 | |
---|
| 272 | VciSignals<vci_param> signal_vci_ini_d_iobd("signal_vci_ini_d_iobd"); |
---|
| 273 | VciSignals<vci_param> signal_vci_tgt_d_iobd("signal_vci_tgt_d_iobd"); |
---|
| 274 | |
---|
| 275 | /* |
---|
| 276 | * netlist |
---|
| 277 | */ |
---|
| 278 | |
---|
| 279 | proc.p_clk(signal_clk); |
---|
| 280 | proc.p_resetn(signal_resetn); |
---|
| 281 | for (size_t i = 0; i < proc_iss::n_irq; i++) |
---|
| 282 | proc.p_irq[i](signal_proc_irq[i]); |
---|
| 283 | proc.p_vci_ini_d(signal_vci_ini_d_proc); |
---|
| 284 | proc.p_vci_ini_c(signal_vci_ini_c_proc); |
---|
| 285 | proc.p_vci_tgt_c(signal_vci_tgt_c_proc); |
---|
| 286 | |
---|
| 287 | xram.p_clk(signal_clk); |
---|
| 288 | xram.p_resetn(signal_resetn); |
---|
| 289 | xram.p_vci(signal_vci_xram); |
---|
| 290 | |
---|
| 291 | rom.p_clk(signal_clk); |
---|
| 292 | rom.p_resetn(signal_resetn); |
---|
| 293 | rom.p_vci(signal_vci_tgt_d_brom); |
---|
| 294 | |
---|
| 295 | memc.p_clk(signal_clk); |
---|
| 296 | memc.p_resetn(signal_resetn); |
---|
| 297 | memc.p_vci_tgt(signal_vci_tgt_d_memc); |
---|
| 298 | memc.p_vci_tgt_cleanup(signal_vci_tgt_c_memc); |
---|
| 299 | memc.p_vci_ini(signal_vci_ini_c_memc); |
---|
| 300 | memc.p_vci_ixr(signal_vci_xram); |
---|
| 301 | |
---|
| 302 | vciexit.p_clk(signal_clk); |
---|
| 303 | vciexit.p_resetn(signal_resetn); |
---|
| 304 | vciexit.p_vci(signal_vci_tgt_d_exit); |
---|
| 305 | |
---|
| 306 | xicu.p_resetn(signal_resetn); |
---|
| 307 | xicu.p_clk(signal_clk); |
---|
| 308 | xicu.p_vci(signal_vci_tgt_d_xicu); |
---|
| 309 | xicu.p_hwi[0](signal_mtty_irq); |
---|
| 310 | xicu.p_hwi[1](signal_iobd_irq); |
---|
| 311 | xicu.p_irq[0](signal_proc_irq[0]); |
---|
| 312 | |
---|
| 313 | mtty.p_clk(signal_clk); |
---|
| 314 | mtty.p_resetn(signal_resetn); |
---|
| 315 | mtty.p_vci(signal_vci_tgt_d_mtty); |
---|
| 316 | mtty.p_irq[0](signal_mtty_irq); |
---|
| 317 | |
---|
| 318 | iobd.p_clk(signal_clk); |
---|
| 319 | iobd.p_resetn(signal_resetn); |
---|
| 320 | iobd.p_vci_target(signal_vci_tgt_d_iobd); |
---|
| 321 | iobd.p_vci_initiator(signal_vci_ini_d_iobd); |
---|
| 322 | iobd.p_irq(signal_iobd_irq); |
---|
| 323 | |
---|
| 324 | ringd.p_clk(signal_clk); |
---|
| 325 | ringd.p_resetn(signal_resetn); |
---|
| 326 | ringd.p_to_initiator[0](signal_vci_ini_d_proc); |
---|
| 327 | ringd.p_to_initiator[1](signal_vci_ini_d_iobd); |
---|
| 328 | ringd.p_to_target[0](signal_vci_tgt_d_memc); |
---|
| 329 | ringd.p_to_target[1](signal_vci_tgt_d_brom); |
---|
| 330 | ringd.p_to_target[2](signal_vci_tgt_d_exit); |
---|
| 331 | ringd.p_to_target[3](signal_vci_tgt_d_mtty); |
---|
| 332 | ringd.p_to_target[4](signal_vci_tgt_d_xicu); |
---|
| 333 | ringd.p_to_target[5](signal_vci_tgt_d_iobd); |
---|
| 334 | |
---|
| 335 | ringc.p_clk(signal_clk); |
---|
| 336 | ringc.p_resetn(signal_resetn); |
---|
| 337 | ringc.p_to_initiator[0](signal_vci_ini_c_proc); |
---|
| 338 | ringc.p_to_initiator[1](signal_vci_ini_c_memc); |
---|
| 339 | ringc.p_to_target[0](signal_vci_tgt_c_proc); |
---|
| 340 | ringc.p_to_target[1](signal_vci_tgt_c_memc); |
---|
| 341 | |
---|
| 342 | /* |
---|
| 343 | * simulation |
---|
| 344 | */ |
---|
| 345 | |
---|
| 346 | sc_start(sc_time(0, SC_NS)); |
---|
| 347 | signal_resetn = false; |
---|
| 348 | |
---|
| 349 | sc_start(sc_time(1, SC_NS)); |
---|
| 350 | signal_resetn = true; |
---|
| 351 | |
---|
| 352 | if (trace_enabled) |
---|
| 353 | { |
---|
| 354 | if (trace_start_cycle > 1) |
---|
| 355 | // simulate without output until trace_start_cycle |
---|
| 356 | sc_start(sc_time(trace_start_cycle, SC_NS)); |
---|
| 357 | |
---|
| 358 | // enable debugging output |
---|
| 359 | for (size_t n = trace_start_cycle ;; n++) |
---|
| 360 | { |
---|
| 361 | std::cout << "****************** cycle " << std::dec << n |
---|
| 362 | << " ************************************************" << std::endl; |
---|
| 363 | proc.print_trace(); |
---|
| 364 | memc.print_trace(); |
---|
| 365 | signal_vci_ini_d_proc.print_trace("proc_ini_d"); |
---|
| 366 | signal_vci_tgt_c_proc.print_trace("proc_tgt_c"); |
---|
| 367 | signal_vci_ini_c_proc.print_trace("proc_ini_c"); |
---|
| 368 | signal_vci_tgt_d_memc.print_trace("memc_tgt_d"); |
---|
| 369 | signal_vci_tgt_c_memc.print_trace("memc_tgt_c"); |
---|
| 370 | signal_vci_ini_c_memc.print_trace("memc_ini_c"); |
---|
| 371 | if (signal_proc_irq[0].read()) |
---|
| 372 | std::cout << "---- IRQ ----" << std::endl; |
---|
| 373 | sc_start(sc_time(1, SC_NS)); |
---|
| 374 | } |
---|
| 375 | } else |
---|
| 376 | sc_start(); |
---|
| 377 | |
---|
| 378 | return EXIT_SUCCESS; |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | int sc_main (int argc, char *argv[]) |
---|
| 382 | { |
---|
| 383 | try { |
---|
| 384 | return _main(argc, argv); |
---|
| 385 | } catch (std::exception &e) { |
---|
| 386 | std::cout << e.what() << std::endl; |
---|
| 387 | } catch (...) { |
---|
| 388 | std::cout << "Unknown exception occurred" << std::endl; |
---|
| 389 | throw; |
---|
| 390 | } |
---|
| 391 | return EXIT_FAILURE; |
---|
| 392 | } |
---|