main.cc revision 11821
111818SChristian.Menard@tu-dresden.de/*
211818SChristian.Menard@tu-dresden.de * Copyright (c) 2015, University of Kaiserslautern
311818SChristian.Menard@tu-dresden.de * Copyright (c) 2016, Dresden University of Technology (TU Dresden)
411818SChristian.Menard@tu-dresden.de * All rights reserved.
511818SChristian.Menard@tu-dresden.de *
611818SChristian.Menard@tu-dresden.de * Redistribution and use in source and binary forms, with or without
711818SChristian.Menard@tu-dresden.de * modification, are permitted provided that the following conditions are
811818SChristian.Menard@tu-dresden.de * met:
911818SChristian.Menard@tu-dresden.de *
1011818SChristian.Menard@tu-dresden.de * 1. Redistributions of source code must retain the above copyright notice,
1111818SChristian.Menard@tu-dresden.de *    this list of conditions and the following disclaimer.
1211818SChristian.Menard@tu-dresden.de *
1311818SChristian.Menard@tu-dresden.de * 2. Redistributions in binary form must reproduce the above copyright
1411818SChristian.Menard@tu-dresden.de *    notice, this list of conditions and the following disclaimer in the
1511818SChristian.Menard@tu-dresden.de *    documentation and/or other materials provided with the distribution.
1611818SChristian.Menard@tu-dresden.de *
1711818SChristian.Menard@tu-dresden.de * 3. Neither the name of the copyright holder nor the names of its
1811818SChristian.Menard@tu-dresden.de *    contributors may be used to endorse or promote products derived from
1911818SChristian.Menard@tu-dresden.de *    this software without specific prior written permission.
2011818SChristian.Menard@tu-dresden.de *
2111818SChristian.Menard@tu-dresden.de * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2211818SChristian.Menard@tu-dresden.de * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2311818SChristian.Menard@tu-dresden.de * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2411818SChristian.Menard@tu-dresden.de * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
2511818SChristian.Menard@tu-dresden.de * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2611818SChristian.Menard@tu-dresden.de * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2711818SChristian.Menard@tu-dresden.de * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2811818SChristian.Menard@tu-dresden.de * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2911818SChristian.Menard@tu-dresden.de * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3011818SChristian.Menard@tu-dresden.de * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3111818SChristian.Menard@tu-dresden.de * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3211818SChristian.Menard@tu-dresden.de *
3311818SChristian.Menard@tu-dresden.de * Authors: Matthias Jung
3411818SChristian.Menard@tu-dresden.de *          Christian Menard
3511818SChristian.Menard@tu-dresden.de *          Abdul Mutaal Ahmad
3611818SChristian.Menard@tu-dresden.de */
3711818SChristian.Menard@tu-dresden.de
3811818SChristian.Menard@tu-dresden.de/**
3911818SChristian.Menard@tu-dresden.de * @file
4011818SChristian.Menard@tu-dresden.de *
4111818SChristian.Menard@tu-dresden.de *  Example top level file for SystemC-TLM integration with C++-only
4211818SChristian.Menard@tu-dresden.de *  instantiation.
4311818SChristian.Menard@tu-dresden.de *
4411818SChristian.Menard@tu-dresden.de */
4511818SChristian.Menard@tu-dresden.de
4611818SChristian.Menard@tu-dresden.de#include <systemc>
4711818SChristian.Menard@tu-dresden.de#include <tlm>
4811818SChristian.Menard@tu-dresden.de
4911821SChristian.Menard@tu-dresden.de#include "cli_parser.hh"
5011821SChristian.Menard@tu-dresden.de#include "report_handler.hh"
5111818SChristian.Menard@tu-dresden.de#include "sc_target.hh"
5211818SChristian.Menard@tu-dresden.de#include "sim_control.hh"
5311818SChristian.Menard@tu-dresden.de#include "stats.hh"
5411818SChristian.Menard@tu-dresden.de
5511818SChristian.Menard@tu-dresden.deint
5611818SChristian.Menard@tu-dresden.desc_main(int argc, char **argv)
5711818SChristian.Menard@tu-dresden.de{
5811821SChristian.Menard@tu-dresden.de    CliParser parser;
5911821SChristian.Menard@tu-dresden.de    parser.parse(argc, argv);
6011821SChristian.Menard@tu-dresden.de
6111818SChristian.Menard@tu-dresden.de    sc_core::sc_report_handler::set_handler(reportHandler);
6211818SChristian.Menard@tu-dresden.de
6311821SChristian.Menard@tu-dresden.de    Gem5SystemC::Gem5SimControl simControl("gem5",
6411821SChristian.Menard@tu-dresden.de                                           parser.getConfigFile(),
6511821SChristian.Menard@tu-dresden.de                                           parser.getSimulationEnd(),
6611821SChristian.Menard@tu-dresden.de                                           parser.getDebugFlags());
6711818SChristian.Menard@tu-dresden.de    Target *memory;
6811818SChristian.Menard@tu-dresden.de
6911821SChristian.Menard@tu-dresden.de    unsigned long long int memorySize = 512*1024*1024ULL;
7011818SChristian.Menard@tu-dresden.de
7111818SChristian.Menard@tu-dresden.de    tlm::tlm_initiator_socket <> *mem_port =
7211818SChristian.Menard@tu-dresden.de        dynamic_cast<tlm::tlm_initiator_socket<> *>(
7311818SChristian.Menard@tu-dresden.de                    sc_core::sc_find_object("gem5.memory")
7411818SChristian.Menard@tu-dresden.de                );
7511818SChristian.Menard@tu-dresden.de
7611818SChristian.Menard@tu-dresden.de    if (mem_port) {
7711818SChristian.Menard@tu-dresden.de        SC_REPORT_INFO("sc_main", "Port Found");
7811818SChristian.Menard@tu-dresden.de        memory = new Target("memory",
7911821SChristian.Menard@tu-dresden.de                            parser.getVerboseFlag(),
8011821SChristian.Menard@tu-dresden.de                            memorySize,
8111821SChristian.Menard@tu-dresden.de                            parser.getMemoryOffset());
8211818SChristian.Menard@tu-dresden.de
8311818SChristian.Menard@tu-dresden.de        memory->socket.bind(*mem_port);
8411818SChristian.Menard@tu-dresden.de    } else {
8511818SChristian.Menard@tu-dresden.de        SC_REPORT_FATAL("sc_main", "Port Not Found");
8611818SChristian.Menard@tu-dresden.de        std::exit(EXIT_FAILURE);
8711818SChristian.Menard@tu-dresden.de    }
8811818SChristian.Menard@tu-dresden.de
8911821SChristian.Menard@tu-dresden.de    SC_REPORT_INFO("sc_main", "Start of Simulation");
9011821SChristian.Menard@tu-dresden.de
9111818SChristian.Menard@tu-dresden.de    sc_core::sc_start();
9211818SChristian.Menard@tu-dresden.de
9311818SChristian.Menard@tu-dresden.de    SC_REPORT_INFO("sc_main", "End of Simulation");
9411818SChristian.Menard@tu-dresden.de
9511818SChristian.Menard@tu-dresden.de    CxxConfig::statsDump();
9611818SChristian.Menard@tu-dresden.de
9711818SChristian.Menard@tu-dresden.de    return EXIT_SUCCESS;
9811818SChristian.Menard@tu-dresden.de}
99