| 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 | struct param_s { |
|---|
| 89 | char *rom_path; |
|---|
| 90 | char *dsk_path; |
|---|
| 91 | bool dummy_boot; |
|---|
| 92 | bool trace_enabled; |
|---|
| 93 | size_t trace_start_cycle; |
|---|
| 94 | }; |
|---|
| 95 | |
|---|
| 96 | #define PARAM_INITIALIZER \ |
|---|
| 97 | { \ |
|---|
| 98 | .rom_path = NULL, \ |
|---|
| 99 | .dsk_path = NULL, \ |
|---|
| 100 | .dummy_boot = false, \ |
|---|
| 101 | .trace_enabled = false, \ |
|---|
| 102 | .trace_start_cycle = 0 \ |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | static inline void print_param(const struct param_s ¶m) |
|---|
| 106 | { |
|---|
| 107 | std::cout << std::endl; |
|---|
| 108 | std::cout << "simulation parameters:" << std::endl; |
|---|
| 109 | std::cout << " rom = " << param.rom_path << std::endl; |
|---|
| 110 | std::cout << " dummy boot = " << param.dummy_boot << std::endl; |
|---|
| 111 | std::cout << " dsk = " << param.dsk_path << std::endl; |
|---|
| 112 | std::cout << " trace = " << param.trace_enabled << std::endl; |
|---|
| 113 | if (param.trace_enabled) |
|---|
| 114 | std::cout << " start cyc = " << param.trace_start_cycle << std::endl; |
|---|
| 115 | |
|---|
| 116 | std::cout << std::endl; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | /* |
|---|
| 121 | * arguments parsing |
|---|
| 122 | */ |
|---|
| 123 | |
|---|
| 124 | void args_parse(unsigned int argc, char *argv[], struct param_s ¶m) |
|---|
| 125 | { |
|---|
| 126 | for (size_t n = 1; n < argc; n = n + 2) |
|---|
| 127 | { |
|---|
| 128 | if ((strcmp(argv[n], "--rom") == 0) && ((n + 1) < argc)) |
|---|
| 129 | { |
|---|
| 130 | assert((param.rom_path = strdup(argv[n + 1])) |
|---|
| 131 | && "insufficient memory"); |
|---|
| 132 | } |
|---|
| 133 | else if ((strcmp(argv[n], "--dsk") == 0) && ((n + 1) < argc)) |
|---|
| 134 | { |
|---|
| 135 | assert((param.dsk_path = strdup(argv[n + 1])) |
|---|
| 136 | && "insufficient memory"); |
|---|
| 137 | } |
|---|
| 138 | else if (strcmp(argv[n], "--dummy-boot") == 0) |
|---|
| 139 | { |
|---|
| 140 | param.dummy_boot = true; |
|---|
| 141 | /* we don't have an extra argument */ |
|---|
| 142 | n = n - 1; |
|---|
| 143 | } |
|---|
| 144 | else if ((strcmp(argv[n], "--trace") == 0) && ((n + 1) < argc)) |
|---|
| 145 | { |
|---|
| 146 | param.trace_enabled = true; |
|---|
| 147 | param.trace_start_cycle = atoi(argv[n + 1]); |
|---|
| 148 | } |
|---|
| 149 | else |
|---|
| 150 | { |
|---|
| 151 | std::cout << "Error: don't understand option " << argv[n] << std::endl; |
|---|
| 152 | std::cout << "Accepted arguments are :" << std::endl; |
|---|
| 153 | std::cout << "--rom pathname" << std::endl; |
|---|
| 154 | std::cout << "--dsk pathname" << std::endl; |
|---|
| 155 | std::cout << "[--dummy-boot]" << std::endl; |
|---|
| 156 | std::cout << "[-trace trace_start_cycle]" << std::endl; |
|---|
| 157 | exit(0); |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | /* check parameters */ |
|---|
| 162 | assert(param.rom_path && "--rom is not optional"); |
|---|
| 163 | assert(param.dsk_path && "--dsk is not optional"); |
|---|
| 164 | |
|---|
| 165 | print_param(param); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | /* |
|---|
| 170 | * netlist |
|---|
| 171 | */ |
|---|
| 172 | |
|---|
| 173 | int _main(int argc, char *argv[]) |
|---|
| 174 | { |
|---|
| 175 | #ifdef _OPENMP |
|---|
| 176 | omp_set_dynamic(false); |
|---|
| 177 | omp_set_num_threads(1); |
|---|
| 178 | std::cerr << "Built with openmp version " << _OPENMP << std::endl; |
|---|
| 179 | #endif |
|---|
| 180 | |
|---|
| 181 | struct param_s param = PARAM_INITIALIZER; |
|---|
| 182 | |
|---|
| 183 | /* parse arguments */ |
|---|
| 184 | args_parse(argc, argv, param); |
|---|
| 185 | |
|---|
| 186 | /* |
|---|
| 187 | * mapping table |
|---|
| 188 | */ |
|---|
| 189 | |
|---|
| 190 | // caches ram bank |
|---|
| 191 | maptabd.add(Segment("memc_d" , MEMC_BASE , MEMC_SIZE , IntTab(0), true)); |
|---|
| 192 | maptabd.add(Segment("boot_d" , BOOT_BASE , BOOT_SIZE , IntTab(1), true)); |
|---|
| 193 | |
|---|
| 194 | // uncached peripherals |
|---|
| 195 | maptabd.add(Segment("exit_d" , EXIT_BASE , EXIT_SIZE , IntTab(2), false)); |
|---|
| 196 | maptabd.add(Segment("mtty_d" , MTTY_BASE , MTTY_SIZE , IntTab(3), false)); |
|---|
| 197 | maptabd.add(Segment("xicu_d" , XICU_BASE , XICU_SIZE , IntTab(4), false)); |
|---|
| 198 | maptabd.add(Segment("iobd_d" , IOBD_BASE , IOBD_SIZE , IntTab(5), false)); |
|---|
| 199 | |
|---|
| 200 | std::cout << maptabd << std::endl; |
|---|
| 201 | |
|---|
| 202 | // procs |
|---|
| 203 | maptabc.add(Segment("proc_c" , 0x0000000 , 0x10 , IntTab(0) , false)); |
|---|
| 204 | maptabc.add(Segment("memc_c" , 1 << (address_width - srcid_width) , 0x10 , IntTab(1) , false)); |
|---|
| 205 | |
|---|
| 206 | std::cout << maptabc << std::endl; |
|---|
| 207 | |
|---|
| 208 | /* |
|---|
| 209 | * components |
|---|
| 210 | */ |
|---|
| 211 | |
|---|
| 212 | Loader loader; |
|---|
| 213 | loader.load_file(param.rom_path); |
|---|
| 214 | |
|---|
| 215 | #ifdef CONFIG_GDB_SERVER |
|---|
| 216 | typedef GdbServer<Mips32ElIss> proc_iss; |
|---|
| 217 | proc_iss::set_loader(loader); |
|---|
| 218 | #else |
|---|
| 219 | typedef Mips32ElIss proc_iss; |
|---|
| 220 | #endif |
|---|
| 221 | |
|---|
| 222 | if (param.dummy_boot == true) |
|---|
| 223 | { |
|---|
| 224 | /* boot linux image directly */ |
|---|
| 225 | const BinaryFileSymbol *bfs = loader.get_symbol_by_name("kernel_entry"); |
|---|
| 226 | std::cout << "setResetAdress: " << std::hex << bfs->address() << std::endl; |
|---|
| 227 | proc_iss::setResetAddress(bfs->address()); |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | VciCcVCacheWrapperV4<vci_param, proc_iss > proc("ccvcache", |
|---|
| 231 | 0, // proc_id |
|---|
| 232 | maptabd, // direct space |
|---|
| 233 | maptabc, // coherence space |
|---|
| 234 | IntTab(0), // srcid_d |
|---|
| 235 | IntTab(0), // srcid_c |
|---|
| 236 | IntTab(0), // tgtid_c |
|---|
| 237 | 8, 8, // itlb size |
|---|
| 238 | 8, 8, // dtlb size |
|---|
| 239 | 4, 64, 16, // icache size |
|---|
| 240 | 4, 64, 16, // dcache size |
|---|
| 241 | 4, 4, // wbuf size |
|---|
| 242 | 0, 0, // x, y Width |
|---|
| 243 | 1, // memory cache local id |
|---|
| 244 | 1000, // max frozen cycles |
|---|
| 245 | param.trace_start_cycle, |
|---|
| 246 | param.trace_enabled); |
|---|
| 247 | |
|---|
| 248 | VciSimpleRam<vci_param> xram("xram", IntTab(0), maptabd, loader); |
|---|
| 249 | |
|---|
| 250 | VciSimpleRam<vci_param> rom("rom", IntTab(1), maptabd, loader); |
|---|
| 251 | |
|---|
| 252 | VciMemCacheV4<vci_param> memc("memc", |
|---|
| 253 | maptabd, maptabc, maptabd, |
|---|
| 254 | IntTab(0), IntTab(1), IntTab(0), IntTab(1), // srcid_d, srcid_c, tgtid_d, tgtid_c |
|---|
| 255 | 16, 256, 16, // cache size |
|---|
| 256 | 1024, 4, 4, // HEAP size, TRT size, UPT size |
|---|
| 257 | param.trace_start_cycle, param.trace_enabled); |
|---|
| 258 | |
|---|
| 259 | VciSimhelper<vci_param> vciexit("vciexit", IntTab(2), maptabd); |
|---|
| 260 | |
|---|
| 261 | VciXicu<vci_param> xicu("xicu", maptabd, IntTab(4), |
|---|
| 262 | 1, 2, 0, 1); // #timers, #hard_irqs, #soft_irqs, # output_irqs |
|---|
| 263 | |
|---|
| 264 | VciMultiTty<vci_param> mtty("mtty", IntTab(3), maptabd, "vcitty0", NULL); |
|---|
| 265 | |
|---|
| 266 | VciBlockDeviceTsarV4<vci_param> iobd("iobd", maptabd, IntTab(1), IntTab(5), |
|---|
| 267 | param.dsk_path); // mapped_file[, block_size=512, latency=0] |
|---|
| 268 | |
|---|
| 269 | VciVgmn<vci_param> ringd("ringd", maptabd, |
|---|
| 270 | 2, 6, // #initiators, #targets |
|---|
| 271 | 2, 8, // min_latency, FIFO depth |
|---|
| 272 | IntTab(1)); // default target |
|---|
| 273 | |
|---|
| 274 | VciVgmn<vci_param> ringc("ringc", maptabc, |
|---|
| 275 | 2, 2, // #initiators, #targets |
|---|
| 276 | 2, 8); // min_latency, FIFO depth |
|---|
| 277 | |
|---|
| 278 | /* |
|---|
| 279 | * signals |
|---|
| 280 | */ |
|---|
| 281 | |
|---|
| 282 | /* clock and reset */ |
|---|
| 283 | sc_clock signal_clk("signal_clk"); |
|---|
| 284 | sc_signal<bool> signal_resetn("signal_resetn"); |
|---|
| 285 | |
|---|
| 286 | /* irq lines */ |
|---|
| 287 | sc_signal<bool> *signal_proc_irq = |
|---|
| 288 | alloc_elems<sc_signal<bool> >("signal_proc_irq", proc_iss::n_irq); |
|---|
| 289 | sc_signal<bool> signal_mtty_irq("signal_mtty_irq"); |
|---|
| 290 | sc_signal<bool> signal_iobd_irq("signal_iobd_irq"); |
|---|
| 291 | |
|---|
| 292 | /* vci */ |
|---|
| 293 | VciSignals<vci_param> signal_vci_ini_d_proc("vci_ini_d_proc"); |
|---|
| 294 | VciSignals<vci_param> signal_vci_ini_c_proc("vci_ini_c_proc"); |
|---|
| 295 | VciSignals<vci_param> signal_vci_tgt_c_proc("vci_tgt_c_proc"); |
|---|
| 296 | |
|---|
| 297 | VciSignals<vci_param> signal_vci_xram("signal_vci_xram"); |
|---|
| 298 | |
|---|
| 299 | VciSignals<vci_param> signal_vci_tgt_d_brom("signal_vci_tgt_d_brom"); |
|---|
| 300 | |
|---|
| 301 | VciSignals<vci_param> signal_vci_ini_c_memc("signal_vci_ini_c_memc"); |
|---|
| 302 | VciSignals<vci_param> signal_vci_tgt_d_memc("signal_vci_tgt_d_memc"); |
|---|
| 303 | VciSignals<vci_param> signal_vci_tgt_c_memc("signal_vci_tgt_c_memc"); |
|---|
| 304 | |
|---|
| 305 | VciSignals<vci_param> signal_vci_tgt_d_exit("signal_vci_tgt_d_exit"); |
|---|
| 306 | |
|---|
| 307 | VciSignals<vci_param> signal_vci_tgt_d_xicu("signal_vci_tgt_d_xicu"); |
|---|
| 308 | |
|---|
| 309 | VciSignals<vci_param> signal_vci_tgt_d_mtty("signal_vci_tgt_d_mtty"); |
|---|
| 310 | |
|---|
| 311 | VciSignals<vci_param> signal_vci_ini_d_iobd("signal_vci_ini_d_iobd"); |
|---|
| 312 | VciSignals<vci_param> signal_vci_tgt_d_iobd("signal_vci_tgt_d_iobd"); |
|---|
| 313 | |
|---|
| 314 | /* |
|---|
| 315 | * netlist |
|---|
| 316 | */ |
|---|
| 317 | |
|---|
| 318 | proc.p_clk(signal_clk); |
|---|
| 319 | proc.p_resetn(signal_resetn); |
|---|
| 320 | for (size_t i = 0; i < proc_iss::n_irq; i++) |
|---|
| 321 | proc.p_irq[i](signal_proc_irq[i]); |
|---|
| 322 | proc.p_vci_ini_d(signal_vci_ini_d_proc); |
|---|
| 323 | proc.p_vci_ini_c(signal_vci_ini_c_proc); |
|---|
| 324 | proc.p_vci_tgt_c(signal_vci_tgt_c_proc); |
|---|
| 325 | |
|---|
| 326 | xram.p_clk(signal_clk); |
|---|
| 327 | xram.p_resetn(signal_resetn); |
|---|
| 328 | xram.p_vci(signal_vci_xram); |
|---|
| 329 | |
|---|
| 330 | rom.p_clk(signal_clk); |
|---|
| 331 | rom.p_resetn(signal_resetn); |
|---|
| 332 | rom.p_vci(signal_vci_tgt_d_brom); |
|---|
| 333 | |
|---|
| 334 | memc.p_clk(signal_clk); |
|---|
| 335 | memc.p_resetn(signal_resetn); |
|---|
| 336 | memc.p_vci_tgt(signal_vci_tgt_d_memc); |
|---|
| 337 | memc.p_vci_tgt_cleanup(signal_vci_tgt_c_memc); |
|---|
| 338 | memc.p_vci_ini(signal_vci_ini_c_memc); |
|---|
| 339 | memc.p_vci_ixr(signal_vci_xram); |
|---|
| 340 | |
|---|
| 341 | vciexit.p_clk(signal_clk); |
|---|
| 342 | vciexit.p_resetn(signal_resetn); |
|---|
| 343 | vciexit.p_vci(signal_vci_tgt_d_exit); |
|---|
| 344 | |
|---|
| 345 | xicu.p_resetn(signal_resetn); |
|---|
| 346 | xicu.p_clk(signal_clk); |
|---|
| 347 | xicu.p_vci(signal_vci_tgt_d_xicu); |
|---|
| 348 | xicu.p_hwi[0](signal_mtty_irq); |
|---|
| 349 | xicu.p_hwi[1](signal_iobd_irq); |
|---|
| 350 | xicu.p_irq[0](signal_proc_irq[0]); |
|---|
| 351 | |
|---|
| 352 | mtty.p_clk(signal_clk); |
|---|
| 353 | mtty.p_resetn(signal_resetn); |
|---|
| 354 | mtty.p_vci(signal_vci_tgt_d_mtty); |
|---|
| 355 | mtty.p_irq[0](signal_mtty_irq); |
|---|
| 356 | |
|---|
| 357 | iobd.p_clk(signal_clk); |
|---|
| 358 | iobd.p_resetn(signal_resetn); |
|---|
| 359 | iobd.p_vci_target(signal_vci_tgt_d_iobd); |
|---|
| 360 | iobd.p_vci_initiator(signal_vci_ini_d_iobd); |
|---|
| 361 | iobd.p_irq(signal_iobd_irq); |
|---|
| 362 | |
|---|
| 363 | ringd.p_clk(signal_clk); |
|---|
| 364 | ringd.p_resetn(signal_resetn); |
|---|
| 365 | ringd.p_to_initiator[0](signal_vci_ini_d_proc); |
|---|
| 366 | ringd.p_to_initiator[1](signal_vci_ini_d_iobd); |
|---|
| 367 | ringd.p_to_target[0](signal_vci_tgt_d_memc); |
|---|
| 368 | ringd.p_to_target[1](signal_vci_tgt_d_brom); |
|---|
| 369 | ringd.p_to_target[2](signal_vci_tgt_d_exit); |
|---|
| 370 | ringd.p_to_target[3](signal_vci_tgt_d_mtty); |
|---|
| 371 | ringd.p_to_target[4](signal_vci_tgt_d_xicu); |
|---|
| 372 | ringd.p_to_target[5](signal_vci_tgt_d_iobd); |
|---|
| 373 | |
|---|
| 374 | ringc.p_clk(signal_clk); |
|---|
| 375 | ringc.p_resetn(signal_resetn); |
|---|
| 376 | ringc.p_to_initiator[0](signal_vci_ini_c_proc); |
|---|
| 377 | ringc.p_to_initiator[1](signal_vci_ini_c_memc); |
|---|
| 378 | ringc.p_to_target[0](signal_vci_tgt_c_proc); |
|---|
| 379 | ringc.p_to_target[1](signal_vci_tgt_c_memc); |
|---|
| 380 | |
|---|
| 381 | /* |
|---|
| 382 | * simulation |
|---|
| 383 | */ |
|---|
| 384 | |
|---|
| 385 | sc_start(sc_time(0, SC_NS)); |
|---|
| 386 | signal_resetn = false; |
|---|
| 387 | |
|---|
| 388 | sc_start(sc_time(1, SC_NS)); |
|---|
| 389 | signal_resetn = true; |
|---|
| 390 | |
|---|
| 391 | if (param.trace_enabled) |
|---|
| 392 | { |
|---|
| 393 | if (param.trace_start_cycle > 1) |
|---|
| 394 | // simulate without output until trace_start_cycle |
|---|
| 395 | sc_start(sc_time(param.trace_start_cycle, SC_NS)); |
|---|
| 396 | |
|---|
| 397 | // enable debugging output |
|---|
| 398 | for (size_t n = param.trace_start_cycle ;; n++) |
|---|
| 399 | { |
|---|
| 400 | std::cout << "****************** cycle " << std::dec << n |
|---|
| 401 | << " ************************************************" << std::endl; |
|---|
| 402 | proc.print_trace(); |
|---|
| 403 | memc.print_trace(); |
|---|
| 404 | signal_vci_ini_d_proc.print_trace("proc_ini_d"); |
|---|
| 405 | signal_vci_tgt_c_proc.print_trace("proc_tgt_c"); |
|---|
| 406 | signal_vci_ini_c_proc.print_trace("proc_ini_c"); |
|---|
| 407 | signal_vci_tgt_d_memc.print_trace("memc_tgt_d"); |
|---|
| 408 | signal_vci_tgt_c_memc.print_trace("memc_tgt_c"); |
|---|
| 409 | signal_vci_ini_c_memc.print_trace("memc_ini_c"); |
|---|
| 410 | if (signal_proc_irq[0].read()) |
|---|
| 411 | std::cout << "---- IRQ ----" << std::endl; |
|---|
| 412 | sc_start(sc_time(1, SC_NS)); |
|---|
| 413 | } |
|---|
| 414 | } else |
|---|
| 415 | sc_start(); |
|---|
| 416 | |
|---|
| 417 | return EXIT_SUCCESS; |
|---|
| 418 | } |
|---|
| 419 | |
|---|
| 420 | int sc_main (int argc, char *argv[]) |
|---|
| 421 | { |
|---|
| 422 | try { |
|---|
| 423 | return _main(argc, argv); |
|---|
| 424 | } catch (std::exception &e) { |
|---|
| 425 | std::cout << e.what() << std::endl; |
|---|
| 426 | } catch (...) { |
|---|
| 427 | std::cout << "Unknown exception occurred" << std::endl; |
|---|
| 428 | throw; |
|---|
| 429 | } |
|---|
| 430 | return EXIT_FAILURE; |
|---|
| 431 | } |
|---|