source: branches/v4/platforms/tsarv4_mono_mmu_ioc/top.cpp @ 639

Last change on this file since 639 was 639, checked in by porquet, 10 years ago

remove unused simhelper

File size: 12.4 KB
Line 
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_icu.h"
32#include "vci_multi_tty.h"
33#include "vci_timer.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
45using namespace sc_core;
46using namespace soclib::caba;
47using 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
60typedef 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 */
72MappingTable maptabd(32, IntTab(6), IntTab(6), 0xf0000000);
73/* mapping table for coherence */
74MappingTable 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
88struct 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
105static inline void print_param(const struct param_s &param)
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
124void args_parse(unsigned int argc, char *argv[], struct param_s &param)
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
173int _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 (data and coherence)
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("icu_d"   , ICU_BASE   , ICU_SIZE   , IntTab(2), false));
196    maptabd.add(Segment("mtty_d"  , MTTY_BASE  , MTTY_SIZE  , IntTab(3), false));
197    maptabd.add(Segment("timer_d" , TIMER_BASE , TIMER_SIZE , IntTab(4), false));
198    maptabd.add(Segment("bd_d"    , BD_BASE    , BD_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        uint64_t entry_addr = loader.get_entry_point_address();
226        std::cout << "setResetAdress: " << std::hex << entry_addr << std::endl << std::endl;
227        proc_iss::setResetAddress(entry_addr);
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> ram("ram", 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    VciIcu<vci_param> icu("icu", IntTab(2), maptabd,
260            3); // #input_irqs
261
262    VciMultiTty<vci_param> mtty("mtty", IntTab(3), maptabd, "vcitty0", NULL);
263
264    VciTimer<vci_param> timer("timer", IntTab(4), maptabd,
265            1); // #timers
266
267    VciBlockDeviceTsarV4<vci_param> bd("bd", maptabd, IntTab(1), IntTab(5),
268            param.dsk_path); // mapped_file[, block_size=512, latency=0]
269
270    VciVgmn<vci_param> vgmnd("vgmnd", maptabd,
271            2, 6,       // #initiators, #targets
272            2, 8,       // min_latency, FIFO depth
273            IntTab(1)); // default target
274
275    VciVgmn<vci_param> vgmnc("vgmnc", maptabc,
276            2, 2,   // #initiators, #targets
277            2, 8);  // min_latency, FIFO depth
278
279    /*
280     * signals
281     */
282
283    /* clock and reset */
284    sc_clock signal_clk("signal_clk");
285    sc_signal<bool> signal_resetn("signal_resetn");
286
287    /* irq lines */
288    sc_signal<bool> *signal_proc_irq =
289        alloc_elems<sc_signal<bool> >("signal_proc_irq", proc_iss::n_irq);
290    sc_signal<bool> signal_mtty_irq("signal_mtty_irq");
291    sc_signal<bool> signal_timer_irq("signal_timer_irq");
292    sc_signal<bool> signal_bd_irq("signal_bd_irq");
293
294    /* vci */
295    VciSignals<vci_param> signal_vci_ini_d_proc("vci_ini_d_proc");
296    VciSignals<vci_param> signal_vci_ini_c_proc("vci_ini_c_proc");
297    VciSignals<vci_param> signal_vci_tgt_c_proc("vci_tgt_c_proc");
298
299    VciSignals<vci_param> signal_vci_ram("signal_vci_ram");
300
301    VciSignals<vci_param> signal_vci_tgt_d_rom("signal_vci_tgt_d_rom");
302
303    VciSignals<vci_param> signal_vci_ini_c_memc("signal_vci_ini_c_memc");
304    VciSignals<vci_param> signal_vci_tgt_d_memc("signal_vci_tgt_d_memc");
305    VciSignals<vci_param> signal_vci_tgt_c_memc("signal_vci_tgt_c_memc");
306
307    VciSignals<vci_param> signal_vci_tgt_d_icu("signal_vci_tgt_d_icu");
308
309    VciSignals<vci_param> signal_vci_tgt_d_mtty("signal_vci_tgt_d_mtty");
310
311    VciSignals<vci_param> signal_vci_tgt_d_timer("signal_vci_tgt_d_timer");
312
313    VciSignals<vci_param> signal_vci_ini_d_bd("signal_vci_ini_d_bd");
314    VciSignals<vci_param> signal_vci_tgt_d_bd("signal_vci_tgt_d_bd");
315
316    /*
317     * netlist
318     */
319
320    proc.p_clk(signal_clk);
321    proc.p_resetn(signal_resetn);
322    for (size_t i = 0; i < proc_iss::n_irq; i++)
323        proc.p_irq[i](signal_proc_irq[i]);
324    proc.p_vci_ini_d(signal_vci_ini_d_proc);
325    proc.p_vci_ini_c(signal_vci_ini_c_proc);
326    proc.p_vci_tgt_c(signal_vci_tgt_c_proc);
327
328    ram.p_clk(signal_clk);
329    ram.p_resetn(signal_resetn);
330    ram.p_vci(signal_vci_ram);
331
332    rom.p_clk(signal_clk);
333    rom.p_resetn(signal_resetn);
334    rom.p_vci(signal_vci_tgt_d_rom);
335
336    memc.p_clk(signal_clk);
337    memc.p_resetn(signal_resetn);
338    memc.p_vci_tgt(signal_vci_tgt_d_memc);
339    memc.p_vci_tgt_cleanup(signal_vci_tgt_c_memc);
340    memc.p_vci_ini(signal_vci_ini_c_memc);
341    memc.p_vci_ixr(signal_vci_ram);
342
343    icu.p_resetn(signal_resetn);
344    icu.p_clk(signal_clk);
345    icu.p_vci(signal_vci_tgt_d_icu);
346    icu.p_irq_in[0](signal_mtty_irq);
347    icu.p_irq_in[1](signal_timer_irq);
348    icu.p_irq_in[2](signal_bd_irq);
349    icu.p_irq(signal_proc_irq[0]);
350
351    mtty.p_clk(signal_clk);
352    mtty.p_resetn(signal_resetn);
353    mtty.p_vci(signal_vci_tgt_d_mtty);
354    mtty.p_irq[0](signal_mtty_irq);
355
356    timer.p_clk(signal_clk);
357    timer.p_resetn(signal_resetn);
358    timer.p_vci(signal_vci_tgt_d_timer);
359    timer.p_irq[0](signal_timer_irq);
360
361    bd.p_clk(signal_clk);
362    bd.p_resetn(signal_resetn);
363    bd.p_vci_target(signal_vci_tgt_d_bd);
364    bd.p_vci_initiator(signal_vci_ini_d_bd);
365    bd.p_irq(signal_bd_irq);
366
367    vgmnd.p_clk(signal_clk);
368    vgmnd.p_resetn(signal_resetn);
369    vgmnd.p_to_initiator[0](signal_vci_ini_d_proc);
370    vgmnd.p_to_initiator[1](signal_vci_ini_d_bd);
371    vgmnd.p_to_target[0](signal_vci_tgt_d_memc);
372    vgmnd.p_to_target[1](signal_vci_tgt_d_rom);
373    vgmnd.p_to_target[2](signal_vci_tgt_d_icu);
374    vgmnd.p_to_target[3](signal_vci_tgt_d_mtty);
375    vgmnd.p_to_target[4](signal_vci_tgt_d_timer);
376    vgmnd.p_to_target[5](signal_vci_tgt_d_bd);
377
378    vgmnc.p_clk(signal_clk);
379    vgmnc.p_resetn(signal_resetn);
380    vgmnc.p_to_initiator[0](signal_vci_ini_c_proc);
381    vgmnc.p_to_initiator[1](signal_vci_ini_c_memc);
382    vgmnc.p_to_target[0](signal_vci_tgt_c_proc);
383    vgmnc.p_to_target[1](signal_vci_tgt_c_memc);
384
385    /*
386     * simulation
387     */
388
389    sc_start(sc_time(0, SC_NS));
390    signal_resetn = false;
391
392    sc_start(sc_time(1, SC_NS));
393    signal_resetn = true;
394
395    if (param.trace_enabled)
396    {
397        if (param.trace_start_cycle > 1)
398            // simulate without output until trace_start_cycle
399            sc_start(sc_time(param.trace_start_cycle, SC_NS));
400
401        // enable debugging output
402        for (size_t n = param.trace_start_cycle ;; n++)
403        {
404            std::cout << "****************** cycle " << std::dec << n
405                << " ************************************************" << std::endl;
406            proc.print_trace();
407            memc.print_trace();
408            signal_vci_ini_d_proc.print_trace("proc_ini_d");
409            signal_vci_tgt_c_proc.print_trace("proc_tgt_c");
410            signal_vci_ini_c_proc.print_trace("proc_ini_c");
411            signal_vci_tgt_d_memc.print_trace("memc_tgt_d");
412            signal_vci_tgt_c_memc.print_trace("memc_tgt_c");
413            signal_vci_ini_c_memc.print_trace("memc_ini_c");
414            if (signal_proc_irq[0].read())
415                std::cout << "---- IRQ ----" << std::endl;
416            sc_start(sc_time(1, SC_NS));
417        }
418    } else
419        sc_start();
420
421    return EXIT_SUCCESS;
422}
423
424int sc_main (int argc, char *argv[])
425{
426    try {
427        return _main(argc, argv);
428    } catch (std::exception &e) {
429        std::cout << e.what() << std::endl;
430    } catch (...) {
431        std::cout << "Unknown exception occurred" << std::endl;
432        throw;
433    }
434    return EXIT_FAILURE;
435}
Note: See TracBrowser for help on using the repository browser.