| 1 | /*
|
|---|
| 2 | * SOCLIB_LGPL_HEADER_BEGIN
|
|---|
| 3 | *
|
|---|
| 4 | * This file is part of SoCLib, GNU LGPLv2.1.
|
|---|
| 5 | *
|
|---|
| 6 | * SoCLib is free software; you can redistribute it and/or modify it
|
|---|
| 7 | * under the terms of the GNU Lesser General Public License as published
|
|---|
| 8 | * by the Free Software Foundation; version 2.1 of the License.
|
|---|
| 9 | *
|
|---|
| 10 | * SoCLib is distributed in the hope that it will be useful, but
|
|---|
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 13 | * Lesser General Public License for more details.
|
|---|
| 14 | *
|
|---|
| 15 | * You should have received a copy of the GNU Lesser General Public
|
|---|
| 16 | * License along with SoCLib; if not, write to the Free Software
|
|---|
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|---|
| 18 | * 02110-1301 USA
|
|---|
| 19 | *
|
|---|
| 20 | * SOCLIB_LGPL_HEADER_END
|
|---|
| 21 | *
|
|---|
| 22 | * Copyright (c) UPMC, Lip6, SoC
|
|---|
| 23 | * Nicolas Pouillon <nipo@ssji.net>, 2006-2007
|
|---|
| 24 | *
|
|---|
| 25 | * Maintainers: nipo
|
|---|
| 26 | */
|
|---|
| 27 |
|
|---|
| 28 | #include <iostream>
|
|---|
| 29 | #include <cstdlib>
|
|---|
| 30 | #include <cstdio>
|
|---|
| 31 |
|
|---|
| 32 | #include "mips32.h"
|
|---|
| 33 | #include "mapping_table.h"
|
|---|
| 34 | #include "gdbserver.h"
|
|---|
| 35 | #include "vci_xcache_wrapper.h"
|
|---|
| 36 | #include "vci_timer.h"
|
|---|
| 37 | #include "vci_framebuffer.h"
|
|---|
| 38 | #include "vci_fd_access.h"
|
|---|
| 39 | #include "vci_ram.h"
|
|---|
| 40 | #include "vci_multi_tty.h"
|
|---|
| 41 | #include "vci_vgmn.h"
|
|---|
| 42 | #include "vci_locks.h"
|
|---|
| 43 | #include "vci_dma.h"
|
|---|
| 44 |
|
|---|
| 45 | #include "segmentation.h"
|
|---|
| 46 |
|
|---|
| 47 | #define FB_WIDTH 256
|
|---|
| 48 | #define FB_HEIGHT 144
|
|---|
| 49 |
|
|---|
| 50 | using namespace std;
|
|---|
| 51 | using namespace sc_core;
|
|---|
| 52 | using namespace soclib::caba;
|
|---|
| 53 | using namespace soclib::common;
|
|---|
| 54 |
|
|---|
| 55 | typedef VciParams<4,6,32,1,1,1,8,1,1,1> vci_param;
|
|---|
| 56 |
|
|---|
| 57 | int _main(int argc, char *argv[])
|
|---|
| 58 | {
|
|---|
| 59 | char * simulation_ncycles_var = getenv ("SIMULATION_N_CYCLES");
|
|---|
| 60 | char * simulation_ncpus_var = getenv ("SIMULATION_N_CPUS");
|
|---|
| 61 | long int n_cycles = 0, n_cpus = 0;
|
|---|
| 62 |
|
|---|
| 63 | /*
|
|---|
| 64 | * Check the parameters : param 1 is the name of the simulated application.
|
|---|
| 65 | */
|
|---|
| 66 |
|
|---|
| 67 | if (argc != 2)
|
|---|
| 68 | {
|
|---|
| 69 | cout << "[PLATFORM] Wrong number of arguments." << endl;
|
|---|
| 70 | cout << "Usage : ./simulation application_name" << endl;
|
|---|
| 71 | exit (-1);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | /*
|
|---|
| 75 | * Simulation cycles
|
|---|
| 76 | */
|
|---|
| 77 |
|
|---|
| 78 | if (simulation_ncycles_var == NULL)
|
|---|
| 79 | {
|
|---|
| 80 | cout << "[PLATFORM] SIMULATION_N_CYCLES not defined." << endl;
|
|---|
| 81 | n_cycles = -1;
|
|---|
| 82 | }
|
|---|
| 83 | else
|
|---|
| 84 | {
|
|---|
| 85 | n_cycles = strtol(simulation_ncycles_var, (char **)NULL, 10);
|
|---|
| 86 | if (n_cycles == 0)
|
|---|
| 87 | {
|
|---|
| 88 | cout << "[PLATFORM] Invalid SIMULATION_N_CYCLES value, defaulting to infinite." << endl;
|
|---|
| 89 | n_cycles = -1;
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | if (n_cycles == -1)
|
|---|
| 94 | {
|
|---|
| 95 | cout << "[PLATFORM] Infinite simulation." << endl;
|
|---|
| 96 | }
|
|---|
| 97 | else
|
|---|
| 98 | {
|
|---|
| 99 | cout << "[PLATFORM] Simulating " << n_cycles << " cycle(s)." << endl;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | /*
|
|---|
| 103 | * Number of CPUs
|
|---|
| 104 | */
|
|---|
| 105 |
|
|---|
| 106 | if (simulation_ncpus_var == NULL)
|
|---|
| 107 | {
|
|---|
| 108 | cout << "[PLATFORM] SIMULATION_N_CPUS not defined." << endl;
|
|---|
| 109 | n_cpus = 1;
|
|---|
| 110 | }
|
|---|
| 111 | else
|
|---|
| 112 | {
|
|---|
| 113 | n_cpus = strtol(simulation_ncpus_var, (char **)NULL, 10);
|
|---|
| 114 | if (n_cpus == 0)
|
|---|
| 115 | {
|
|---|
| 116 | cout << "[PLATFORM] Invalid SIMULATION_N_CPUS value, defaulting to 1." << endl;
|
|---|
| 117 | n_cpus = 1;
|
|---|
| 118 | }
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | cout << "[PLATFORM] Using " << n_cpus << " CPU(s)." << endl;
|
|---|
| 122 |
|
|---|
| 123 | /*
|
|---|
| 124 | * Mapping table for the mips
|
|---|
| 125 | */
|
|---|
| 126 |
|
|---|
| 127 | MappingTable maptab(32, IntTab(8), IntTab(8), 0x00300000);
|
|---|
| 128 |
|
|---|
| 129 | maptab.add(Segment("reset", RESET_BASE, RESET_SIZE, IntTab(0), false));
|
|---|
| 130 | maptab.add(Segment("excep", EXCEP_BASE, EXCEP_SIZE, IntTab(0), false));
|
|---|
| 131 | maptab.add(Segment("memory", MEMORY_BASE, MEMORY_SIZE , IntTab(0), false));
|
|---|
| 132 | maptab.add(Segment("cmemory", CHANNEL_MEMORY_BASE, CHANNEL_MEMORY_SIZE , IntTab(1), false));
|
|---|
| 133 | maptab.add(Segment("tty", TTY_BASE, TTY_SIZE, IntTab(2), false));
|
|---|
| 134 | maptab.add(Segment("timer", TIMER_BASE, TIMER_SIZE, IntTab(3), false));
|
|---|
| 135 | maptab.add(Segment("fb", FB_BASE, FB_SIZE, IntTab(4), false));
|
|---|
| 136 | maptab.add(Segment("fd", FD_BASE, FD_SIZE, IntTab(5), false, true, IntTab(n_cpus)));
|
|---|
| 137 | maptab.add(Segment("dma", DMA_BASE, DMA_SIZE, IntTab(6), false));
|
|---|
| 138 | maptab.add(Segment("locks", LOCKS_BASE, LOCKS_SIZE, IntTab(7), false));
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 | /*
|
|---|
| 142 | * Signals
|
|---|
| 143 | */
|
|---|
| 144 |
|
|---|
| 145 | sc_clock signal_clk("signal_clk");
|
|---|
| 146 | sc_signal<bool> signal_resetn("signal_resetn");
|
|---|
| 147 |
|
|---|
| 148 | sc_signal<bool> signal_fd_it("signal_fd_it");
|
|---|
| 149 | sc_signal<bool> * signal_mips_it[n_cpus][6];
|
|---|
| 150 | VciSignals<vci_param> * signal_vci_m[n_cpus];
|
|---|
| 151 |
|
|---|
| 152 | for (int i = 0; i < n_cpus; i++)
|
|---|
| 153 | {
|
|---|
| 154 | char m_name[32];
|
|---|
| 155 |
|
|---|
| 156 | sprintf (m_name, "signal_vci_m%d", i);
|
|---|
| 157 | signal_vci_m[i] = new VciSignals<vci_param> (m_name);
|
|---|
| 158 |
|
|---|
| 159 | for (int j = 0; j < 6; j++)
|
|---|
| 160 | {
|
|---|
| 161 | char it_name[32];
|
|---|
| 162 |
|
|---|
| 163 | sprintf (it_name, "signal_mips%d_it%d", i, j);
|
|---|
| 164 | signal_mips_it[i][j] = new sc_signal<bool> (it_name);
|
|---|
| 165 | }
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | VciSignals<vci_param> signal_vci_vcimultiram0("signal_vci_vcimultiram0");
|
|---|
| 169 | VciSignals<vci_param> signal_vci_vcicram0("signal_vci_vcicram0");
|
|---|
| 170 | VciSignals<vci_param> signal_vci_tty("signal_vci_tty");
|
|---|
| 171 | VciSignals<vci_param> signal_vci_timer("signal_vci_timer");
|
|---|
| 172 | VciSignals<vci_param> signal_vci_framebuffer("signal_vci_framebuffer");
|
|---|
| 173 | VciSignals<vci_param> signal_vci_fd_i("signal_vci_fd_i");
|
|---|
| 174 | VciSignals<vci_param> signal_vci_fd_t("signal_vci_fd_t");
|
|---|
| 175 | soclib::caba::VciSignals<vci_param> signal_vci_dmai("signal_vci_dmai");
|
|---|
| 176 | soclib::caba::VciSignals<vci_param> signal_vci_dmat("signal_vci_dmat");
|
|---|
| 177 | soclib::caba::VciSignals<vci_param> signal_vci_locks("signal_vci_locks");
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 | /*
|
|---|
| 181 | * Processors
|
|---|
| 182 | */
|
|---|
| 183 |
|
|---|
| 184 | VciXcacheWrapper<vci_param, GdbServer<Mips32ElIss> > * cache[n_cpus];
|
|---|
| 185 |
|
|---|
| 186 | for (int i = 0; i < n_cpus; i++)
|
|---|
| 187 | {
|
|---|
| 188 | char cache_name[32];
|
|---|
| 189 |
|
|---|
| 190 | sprintf (cache_name, "CPU%d", i);
|
|---|
| 191 | cache[i] = new VciXcacheWrapper<vci_param, GdbServer<Mips32ElIss> > (cache_name, i, maptab, IntTab(i), 4, 1, 8, 4, 1, 8);
|
|---|
| 192 |
|
|---|
| 193 | cache[i] -> p_clk (signal_clk);
|
|---|
| 194 | cache[i] -> p_resetn (signal_resetn);
|
|---|
| 195 | cache[i] -> p_vci (*signal_vci_m[i]);
|
|---|
| 196 |
|
|---|
| 197 | for (int j = 0; j < 6; j ++)
|
|---|
| 198 | {
|
|---|
| 199 | cache[i] -> p_irq[j] (*signal_mips_it[i][j]);
|
|---|
| 200 | }
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | /*
|
|---|
| 204 | * Memory
|
|---|
| 205 | */
|
|---|
| 206 |
|
|---|
| 207 | Loader loader(argv[1]);
|
|---|
| 208 | VciRam<vci_param> vcimultiram0("vcimultiram0", IntTab(0), maptab, loader);
|
|---|
| 209 |
|
|---|
| 210 | vcimultiram0 . p_clk(signal_clk);
|
|---|
| 211 | vcimultiram0 . p_resetn(signal_resetn);
|
|---|
| 212 | vcimultiram0 . p_vci(signal_vci_vcimultiram0);
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 | /*
|
|---|
| 216 | * Channel Memory
|
|---|
| 217 | */
|
|---|
| 218 |
|
|---|
| 219 | VciRam<vci_param> vcicram0("vcicmemory", IntTab(1), maptab, loader);
|
|---|
| 220 |
|
|---|
| 221 | vcicram0 . p_clk(signal_clk);
|
|---|
| 222 | vcicram0 . p_resetn(signal_resetn);
|
|---|
| 223 | vcicram0 . p_vci(signal_vci_vcicram0);
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 | /*
|
|---|
| 228 | * TTY
|
|---|
| 229 | */
|
|---|
| 230 |
|
|---|
| 231 | VciMultiTty<vci_param> vcitty("vcitty", IntTab(2), maptab, "tty0", "tty1", NULL);
|
|---|
| 232 |
|
|---|
| 233 | vcitty . p_clk (signal_clk);
|
|---|
| 234 | vcitty . p_resetn (signal_resetn);
|
|---|
| 235 | vcitty . p_vci (signal_vci_tty);
|
|---|
| 236 | vcitty . p_irq[0] (*signal_mips_it[0][1]);
|
|---|
| 237 | vcitty . p_irq[1] (*signal_mips_it[0][2]);
|
|---|
| 238 |
|
|---|
| 239 | /*
|
|---|
| 240 | * Timer
|
|---|
| 241 | */
|
|---|
| 242 |
|
|---|
| 243 | VciTimer<vci_param> vcitimer("vcittimer", IntTab(3), maptab, n_cpus);
|
|---|
| 244 |
|
|---|
| 245 | vcitimer . p_clk (signal_clk);
|
|---|
| 246 | vcitimer . p_resetn (signal_resetn);
|
|---|
| 247 | vcitimer . p_vci (signal_vci_timer);
|
|---|
| 248 |
|
|---|
| 249 | for (int i = 0; i < n_cpus; i += 1)
|
|---|
| 250 | {
|
|---|
| 251 | vcitimer . p_irq[i] (*signal_mips_it[i][0]);
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | /*
|
|---|
| 255 | <<<<<<< HEAD:top.cpp
|
|---|
| 256 | * Framebuffer
|
|---|
| 257 | */
|
|---|
| 258 |
|
|---|
| 259 | VciFrameBuffer<vci_param> vcifb("fb0", IntTab(4), maptab, FB_WIDTH, FB_HEIGHT);
|
|---|
| 260 |
|
|---|
| 261 | vcifb . p_clk (signal_clk);
|
|---|
| 262 | vcifb . p_resetn (signal_resetn);
|
|---|
| 263 | vcifb . p_vci (signal_vci_framebuffer);
|
|---|
| 264 |
|
|---|
| 265 | /*
|
|---|
| 266 | * FD
|
|---|
| 267 | */
|
|---|
| 268 |
|
|---|
| 269 | VciFdAccess<vci_param> vcifd("vcifd", maptab, IntTab(n_cpus), IntTab(5));
|
|---|
| 270 |
|
|---|
| 271 | vcifd . p_clk (signal_clk);
|
|---|
| 272 | vcifd . p_resetn (signal_resetn);
|
|---|
| 273 | vcifd . p_vci_initiator (signal_vci_fd_i);
|
|---|
| 274 | vcifd . p_vci_target (signal_vci_fd_t);
|
|---|
| 275 | vcifd . p_irq (signal_fd_it);
|
|---|
| 276 |
|
|---|
| 277 | /*
|
|---|
| 278 | * DMA
|
|---|
| 279 | */
|
|---|
| 280 |
|
|---|
| 281 | soclib::caba::VciDma<vci_param> vcidma("vcidma", maptab, IntTab(n_cpus+2), IntTab(6), (1<<(vci_param::K-1)));
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 | vcidma.p_clk(signal_clk);
|
|---|
| 285 | vcidma.p_resetn(signal_resetn);
|
|---|
| 286 | vcidma.p_vci_target(signal_vci_dmat);
|
|---|
| 287 | vcidma.p_vci_initiator(signal_vci_dmai);
|
|---|
| 288 | vcidma.p_irq(*signal_mips_it[0][3]);
|
|---|
| 289 |
|
|---|
| 290 | /*
|
|---|
| 291 | * LOCKS
|
|---|
| 292 | */
|
|---|
| 293 |
|
|---|
| 294 | soclib::caba::VciLocks<vci_param> vcilocks("vcilocks", IntTab(7), maptab);
|
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 | vcilocks.p_clk(signal_clk);
|
|---|
| 298 | vcilocks.p_resetn(signal_resetn);
|
|---|
| 299 | vcilocks.p_vci(signal_vci_locks);
|
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 | /*
|
|---|
| 303 | * Network
|
|---|
| 304 | */
|
|---|
| 305 |
|
|---|
| 306 | VciVgmn<vci_param> vgmn("vgmn",maptab, n_cpus + 2, 8, 1, 8);
|
|---|
| 307 |
|
|---|
| 308 | vgmn . p_clk (signal_clk);
|
|---|
| 309 | vgmn . p_resetn (signal_resetn);
|
|---|
| 310 |
|
|---|
| 311 | for (int i = 0; i < n_cpus; i++)
|
|---|
| 312 | {
|
|---|
| 313 | vgmn . p_to_initiator[i] (*signal_vci_m[i]);
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 | vgmn . p_to_initiator[n_cpus] (signal_vci_fd_i);
|
|---|
| 317 | vgmn . p_to_initiator[n_cpus+1] (signal_vci_dmai);
|
|---|
| 318 |
|
|---|
| 319 | vgmn . p_to_target[0] (signal_vci_vcimultiram0);
|
|---|
| 320 | vgmn . p_to_target[1] (signal_vci_vcicram0);
|
|---|
| 321 | vgmn . p_to_target[2] (signal_vci_tty);
|
|---|
| 322 | vgmn . p_to_target[3] (signal_vci_timer);
|
|---|
| 323 | vgmn . p_to_target[4] (signal_vci_framebuffer);
|
|---|
| 324 | vgmn . p_to_target[5] (signal_vci_fd_t);
|
|---|
| 325 | vgmn . p_to_target[6] (signal_vci_dmat);
|
|---|
| 326 | vgmn . p_to_target[7] (signal_vci_locks);
|
|---|
| 327 |
|
|---|
| 328 | /*
|
|---|
| 329 | * Start of simulation
|
|---|
| 330 | */
|
|---|
| 331 |
|
|---|
| 332 | sc_start(sc_core::sc_time(0, SC_NS));
|
|---|
| 333 | signal_resetn = false;
|
|---|
| 334 |
|
|---|
| 335 | sc_start(sc_core::sc_time(1, SC_NS));
|
|---|
| 336 | signal_resetn = true;
|
|---|
| 337 |
|
|---|
| 338 | if (n_cycles == -1)
|
|---|
| 339 | {
|
|---|
| 340 | sc_start();
|
|---|
| 341 | }
|
|---|
| 342 | else
|
|---|
| 343 | {
|
|---|
| 344 | sc_start(sc_core::sc_time(n_cycles, SC_NS));
|
|---|
| 345 | }
|
|---|
| 346 |
|
|---|
| 347 | return EXIT_SUCCESS;
|
|---|
| 348 | }
|
|---|
| 349 |
|
|---|
| 350 | int sc_main (int argc, char *argv[])
|
|---|
| 351 | {
|
|---|
| 352 | try
|
|---|
| 353 | {
|
|---|
| 354 | return _main(argc, argv);
|
|---|
| 355 | }
|
|---|
| 356 | catch (exception &e)
|
|---|
| 357 | {
|
|---|
| 358 | cout << e.what() << endl;
|
|---|
| 359 | }
|
|---|
| 360 | catch (...)
|
|---|
| 361 | {
|
|---|
| 362 | cout << "Unknown exception occured" << endl;
|
|---|
| 363 | throw;
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | return 1;
|
|---|
| 367 | }
|
|---|