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

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

use vci_icu and vci_timer instead of vci_xicu

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_simhelper.h"
32#include "vci_icu.h"
33#include "vci_multi_tty.h"
34#include "vci_timer.h"
35#include "vci_block_device_tsar_v4.h"
36
37#include "vci_vgmn.h"
38
39#include "alloc_elems.h"
40
41
42/*
43 * pf global config
44 */
45
46using namespace sc_core;
47using namespace soclib::caba;
48using namespace soclib::common;
49
50#define cell_width      4
51#define address_width   32
52#define plen_width      8
53#define error_width     2
54#define clen_width      1
55#define rflag_width     1
56#define srcid_width     14
57#define pktid_width     4
58#define trdid_width     4
59#define wrplen_width    1
60
61typedef VciParams<cell_width,
62        plen_width,
63        address_width,
64        error_width,
65        clen_width,
66        rflag_width,
67        srcid_width,
68        pktid_width,
69        trdid_width,
70        wrplen_width> vci_param;
71
72/* mapping table for data */
73MappingTable maptabd(32, IntTab(6), IntTab(6), 0xf0000000);
74/* mapping table for coherence */
75MappingTable maptabc(32, IntTab(srcid_width), IntTab(srcid_width), 0xf0000000);
76
77
78/*
79 * segmentation
80 */
81
82#include "segmentation.h"
83
84
85/*
86 * default parameters
87 */
88
89struct param_s {
90    char *rom_path;
91    char *dsk_path;
92    bool dummy_boot;
93    bool trace_enabled;
94    size_t trace_start_cycle;
95};
96
97#define PARAM_INITIALIZER   \
98{                           \
99    .rom_path = NULL,      \
100    .dsk_path = NULL,        \
101    .dummy_boot = false,    \
102    .trace_enabled = false, \
103    .trace_start_cycle = 0  \
104}
105
106static inline void print_param(const struct param_s &param)
107{
108    std::cout << std::endl;
109    std::cout << "simulation parameters:" << std::endl;
110    std::cout << "  rom         = " << param.rom_path << std::endl;
111    std::cout << "  dummy boot  = " << param.dummy_boot << std::endl;
112    std::cout << "  dsk         = " << param.dsk_path << std::endl;
113    std::cout << "  trace       = " << param.trace_enabled << std::endl;
114    if (param.trace_enabled)
115        std::cout << "    start cyc = " << param.trace_start_cycle << std::endl;
116
117    std::cout << std::endl;
118}
119
120
121/*
122 * arguments parsing
123 */
124
125void args_parse(unsigned int argc, char *argv[], struct param_s &param)
126{
127    for (size_t n = 1; n < argc; n = n + 2)
128    {
129        if ((strcmp(argv[n], "--rom") == 0) && ((n + 1) < argc))
130        {
131            assert((param.rom_path = strdup(argv[n + 1]))
132                    && "insufficient memory");
133        }
134        else if ((strcmp(argv[n], "--dsk") == 0) && ((n + 1) < argc))
135        {
136            assert((param.dsk_path = strdup(argv[n + 1]))
137                    && "insufficient memory");
138        }
139        else if (strcmp(argv[n], "--dummy-boot") == 0)
140        {
141            param.dummy_boot = true;
142            /* we don't have an extra argument */
143            n = n - 1;
144        }
145        else if ((strcmp(argv[n], "--trace") == 0) && ((n + 1) < argc))
146        {
147            param.trace_enabled = true;
148            param.trace_start_cycle = atoi(argv[n + 1]);
149        }
150        else
151        {
152            std::cout << "Error: don't understand option " << argv[n] << std::endl;
153            std::cout << "Accepted arguments are :" << std::endl;
154            std::cout << "--rom pathname" << std::endl;
155            std::cout << "--dsk pathname" << std::endl;
156            std::cout << "[--dummy-boot]" << std::endl;
157            std::cout << "[--trace trace_start_cycle]" << std::endl;
158            exit(0);
159        }
160    }
161
162    /* check parameters */
163    assert(param.rom_path && "--rom is not optional");
164    assert(param.dsk_path && "--dsk is not optional");
165
166    print_param(param);
167}
168
169
170/*
171 * netlist
172 */
173
174int _main(int argc, char *argv[])
175{
176#ifdef _OPENMP
177    omp_set_dynamic(false);
178    omp_set_num_threads(1);
179    std::cerr << "Built with openmp version " << _OPENMP << std::endl;
180#endif
181
182    struct param_s param = PARAM_INITIALIZER;
183
184    /* parse arguments */
185    args_parse(argc, argv, param);
186
187    /*
188     * mapping table (data and coherence)
189     */
190
191    // caches ram bank
192    maptabd.add(Segment("memc_d" , MEMC_BASE , MEMC_SIZE , IntTab(0), true));
193    maptabd.add(Segment("boot_d" , BOOT_BASE , BOOT_SIZE , IntTab(1), true));
194
195    // uncached peripherals
196    maptabd.add(Segment("icu_d"   , ICU_BASE   , ICU_SIZE   , IntTab(2), false));
197    maptabd.add(Segment("mtty_d"  , MTTY_BASE  , MTTY_SIZE  , IntTab(3), false));
198    maptabd.add(Segment("timer_d" , TIMER_BASE , TIMER_SIZE , IntTab(4), false));
199    maptabd.add(Segment("bd_d"    , BD_BASE    , BD_SIZE    , IntTab(5), false));
200
201    std::cout << maptabd << std::endl;
202
203    // procs
204    maptabc.add(Segment("proc_c" , 0x0000000 , 0x10 , IntTab(0) , false));
205    maptabc.add(Segment("memc_c" , 1 << (address_width - srcid_width) , 0x10 , IntTab(1) , false));
206
207    std::cout << maptabc << std::endl;
208
209    /*
210     * components
211     */
212
213    Loader loader;
214    loader.load_file(param.rom_path);
215
216#ifdef CONFIG_GDB_SERVER
217    typedef GdbServer<Mips32ElIss> proc_iss;
218    proc_iss::set_loader(loader);
219#else
220    typedef Mips32ElIss proc_iss;
221#endif
222
223    if (param.dummy_boot == true)
224    {
225        /* boot linux image directly */
226        uint64_t entry_addr = loader.get_entry_point_address();
227        std::cout << "setResetAdress: " << std::hex << entry_addr << std::endl << std::endl;
228        proc_iss::setResetAddress(entry_addr);
229    }
230
231    VciCcVCacheWrapperV4<vci_param, proc_iss > proc("ccvcache",
232                0,          // proc_id
233                maptabd,    // direct space
234                maptabc,    // coherence space
235                IntTab(0),  // srcid_d
236                IntTab(0),  // srcid_c
237                IntTab(0),  // tgtid_c
238                8, 8,       // itlb size
239                8, 8,       // dtlb size
240                4, 64, 16,  // icache size
241                4, 64, 16,  // dcache size
242                4, 4,       // wbuf size
243                0, 0,       // x, y Width
244                1,          // memory cache local id
245                1000,       // max frozen cycles
246                param.trace_start_cycle,
247                param.trace_enabled);
248
249    VciSimpleRam<vci_param> ram("ram", IntTab(0), maptabd, loader);
250
251    VciSimpleRam<vci_param> rom("rom", IntTab(1), maptabd, loader);
252
253    VciMemCacheV4<vci_param> memc("memc",
254            maptabd, maptabc, maptabd,
255            IntTab(0), IntTab(1), IntTab(0), IntTab(1), // srcid_d, srcid_c, tgtid_d, tgtid_c
256            16, 256, 16,    // cache size
257            1024, 4, 4,     // HEAP size, TRT size, UPT size
258            param.trace_start_cycle, param.trace_enabled);
259
260    VciIcu<vci_param> icu("icu", IntTab(2), maptabd,
261            3); // #input_irqs
262
263    VciMultiTty<vci_param> mtty("mtty", IntTab(3), maptabd, "vcitty0", NULL);
264
265    VciTimer<vci_param> timer("timer", IntTab(4), maptabd,
266            1); // #timers
267
268    VciBlockDeviceTsarV4<vci_param> bd("bd", maptabd, IntTab(1), IntTab(5),
269            param.dsk_path); // mapped_file[, block_size=512, latency=0]
270
271    VciVgmn<vci_param> vgmnd("vgmnd", maptabd,
272            2, 6,       // #initiators, #targets
273            2, 8,       // min_latency, FIFO depth
274            IntTab(1)); // default target
275
276    VciVgmn<vci_param> vgmnc("vgmnc", maptabc,
277            2, 2,   // #initiators, #targets
278            2, 8);  // min_latency, FIFO depth
279
280    /*
281     * signals
282     */
283
284    /* clock and reset */
285    sc_clock signal_clk("signal_clk");
286    sc_signal<bool> signal_resetn("signal_resetn");
287
288    /* irq lines */
289    sc_signal<bool> *signal_proc_irq =
290        alloc_elems<sc_signal<bool> >("signal_proc_irq", proc_iss::n_irq);
291    sc_signal<bool> signal_mtty_irq("signal_mtty_irq");
292    sc_signal<bool> signal_timer_irq("signal_timer_irq");
293    sc_signal<bool> signal_bd_irq("signal_bd_irq");
294
295    /* vci */
296    VciSignals<vci_param> signal_vci_ini_d_proc("vci_ini_d_proc");
297    VciSignals<vci_param> signal_vci_ini_c_proc("vci_ini_c_proc");
298    VciSignals<vci_param> signal_vci_tgt_c_proc("vci_tgt_c_proc");
299
300    VciSignals<vci_param> signal_vci_ram("signal_vci_ram");
301
302    VciSignals<vci_param> signal_vci_tgt_d_rom("signal_vci_tgt_d_rom");
303
304    VciSignals<vci_param> signal_vci_ini_c_memc("signal_vci_ini_c_memc");
305    VciSignals<vci_param> signal_vci_tgt_d_memc("signal_vci_tgt_d_memc");
306    VciSignals<vci_param> signal_vci_tgt_c_memc("signal_vci_tgt_c_memc");
307
308    VciSignals<vci_param> signal_vci_tgt_d_icu("signal_vci_tgt_d_icu");
309
310    VciSignals<vci_param> signal_vci_tgt_d_mtty("signal_vci_tgt_d_mtty");
311
312    VciSignals<vci_param> signal_vci_tgt_d_timer("signal_vci_tgt_d_timer");
313
314    VciSignals<vci_param> signal_vci_ini_d_bd("signal_vci_ini_d_bd");
315    VciSignals<vci_param> signal_vci_tgt_d_bd("signal_vci_tgt_d_bd");
316
317    /*
318     * netlist
319     */
320
321    proc.p_clk(signal_clk);
322    proc.p_resetn(signal_resetn);
323    for (size_t i = 0; i < proc_iss::n_irq; i++)
324        proc.p_irq[i](signal_proc_irq[i]);
325    proc.p_vci_ini_d(signal_vci_ini_d_proc);
326    proc.p_vci_ini_c(signal_vci_ini_c_proc);
327    proc.p_vci_tgt_c(signal_vci_tgt_c_proc);
328
329    ram.p_clk(signal_clk);
330    ram.p_resetn(signal_resetn);
331    ram.p_vci(signal_vci_ram);
332
333    rom.p_clk(signal_clk);
334    rom.p_resetn(signal_resetn);
335    rom.p_vci(signal_vci_tgt_d_rom);
336
337    memc.p_clk(signal_clk);
338    memc.p_resetn(signal_resetn);
339    memc.p_vci_tgt(signal_vci_tgt_d_memc);
340    memc.p_vci_tgt_cleanup(signal_vci_tgt_c_memc);
341    memc.p_vci_ini(signal_vci_ini_c_memc);
342    memc.p_vci_ixr(signal_vci_ram);
343
344    icu.p_resetn(signal_resetn);
345    icu.p_clk(signal_clk);
346    icu.p_vci(signal_vci_tgt_d_icu);
347    icu.p_irq_in[0](signal_mtty_irq);
348    icu.p_irq_in[1](signal_timer_irq);
349    icu.p_irq_in[2](signal_bd_irq);
350    icu.p_irq(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    timer.p_clk(signal_clk);
358    timer.p_resetn(signal_resetn);
359    timer.p_vci(signal_vci_tgt_d_timer);
360    timer.p_irq[0](signal_timer_irq);
361
362    bd.p_clk(signal_clk);
363    bd.p_resetn(signal_resetn);
364    bd.p_vci_target(signal_vci_tgt_d_bd);
365    bd.p_vci_initiator(signal_vci_ini_d_bd);
366    bd.p_irq(signal_bd_irq);
367
368    vgmnd.p_clk(signal_clk);
369    vgmnd.p_resetn(signal_resetn);
370    vgmnd.p_to_initiator[0](signal_vci_ini_d_proc);
371    vgmnd.p_to_initiator[1](signal_vci_ini_d_bd);
372    vgmnd.p_to_target[0](signal_vci_tgt_d_memc);
373    vgmnd.p_to_target[1](signal_vci_tgt_d_rom);
374    vgmnd.p_to_target[2](signal_vci_tgt_d_icu);
375    vgmnd.p_to_target[3](signal_vci_tgt_d_mtty);
376    vgmnd.p_to_target[4](signal_vci_tgt_d_timer);
377    vgmnd.p_to_target[5](signal_vci_tgt_d_bd);
378
379    vgmnc.p_clk(signal_clk);
380    vgmnc.p_resetn(signal_resetn);
381    vgmnc.p_to_initiator[0](signal_vci_ini_c_proc);
382    vgmnc.p_to_initiator[1](signal_vci_ini_c_memc);
383    vgmnc.p_to_target[0](signal_vci_tgt_c_proc);
384    vgmnc.p_to_target[1](signal_vci_tgt_c_memc);
385
386    /*
387     * simulation
388     */
389
390    sc_start(sc_time(0, SC_NS));
391    signal_resetn = false;
392
393    sc_start(sc_time(1, SC_NS));
394    signal_resetn = true;
395
396    if (param.trace_enabled)
397    {
398        if (param.trace_start_cycle > 1)
399            // simulate without output until trace_start_cycle
400            sc_start(sc_time(param.trace_start_cycle, SC_NS));
401
402        // enable debugging output
403        for (size_t n = param.trace_start_cycle ;; n++)
404        {
405            std::cout << "****************** cycle " << std::dec << n
406                << " ************************************************" << std::endl;
407            proc.print_trace();
408            memc.print_trace();
409            signal_vci_ini_d_proc.print_trace("proc_ini_d");
410            signal_vci_tgt_c_proc.print_trace("proc_tgt_c");
411            signal_vci_ini_c_proc.print_trace("proc_ini_c");
412            signal_vci_tgt_d_memc.print_trace("memc_tgt_d");
413            signal_vci_tgt_c_memc.print_trace("memc_tgt_c");
414            signal_vci_ini_c_memc.print_trace("memc_ini_c");
415            if (signal_proc_irq[0].read())
416                std::cout << "---- IRQ ----" << std::endl;
417            sc_start(sc_time(1, SC_NS));
418        }
419    } else
420        sc_start();
421
422    return EXIT_SUCCESS;
423}
424
425int sc_main (int argc, char *argv[])
426{
427    try {
428        return _main(argc, argv);
429    } catch (std::exception &e) {
430        std::cout << e.what() << std::endl;
431    } catch (...) {
432        std::cout << "Unknown exception occurred" << std::endl;
433        throw;
434    }
435    return EXIT_FAILURE;
436}
Note: See TracBrowser for help on using the repository browser.