system.cc revision 836
1/*
2 * Copyright (c) 2003 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include "base/loader/aout_object.hh"
30#include "base/loader/elf_object.hh"
31#include "base/loader/object_file.hh"
32#include "base/loader/symtab.hh"
33#include "base/remote_gdb.hh"
34#include "base/trace.hh"
35#include "cpu/exec_context.hh"
36#include "cpu/base_cpu.hh"
37#include "kern/linux/linux_events.hh"
38#include "kern/linux/linux_system.hh"
39#include "mem/functional_mem/memory_control.hh"
40#include "mem/functional_mem/physical_memory.hh"
41#include "sim/builder.hh"
42#include "dev/platform.hh"
43#include "targetarch/isa_traits.hh"
44#include "targetarch/vtophys.hh"
45
46extern SymbolTable *debugSymbolTable;
47
48//un-comment this to see the state of call stack when it changes.
49//#define SW_DEBUG
50
51using namespace std;
52
53LinuxSystem::LinuxSystem(const string _name, const uint64_t _init_param,
54                         MemoryController *_memCtrl, PhysicalMemory *_physmem,
55                         const string &kernel_path, const string &console_path,
56                         const string &palcode, const string &boot_osflags,
57                         const string &bootloader_path, const bool _bin)
58     : System(_name, _init_param, _memCtrl, _physmem, _bin), bin(_bin)
59{
60    kernelSymtab = new SymbolTable;
61    consoleSymtab = new SymbolTable;
62    bootloaderSymtab = new SymbolTable;
63
64    ObjectFile *kernel = createObjectFile(kernel_path);
65    if (kernel == NULL)
66        fatal("Could not load kernel file %s", kernel_path);
67
68    ObjectFile *console = createObjectFile(console_path);
69    if (console == NULL)
70        fatal("Could not load console file %s", console_path);
71
72    ObjectFile *bootloader = createObjectFile(bootloader_path);
73    if (bootloader == NULL)
74        fatal("Could not load bootloader file %s", bootloader_path);
75
76    if (!kernel->loadGlobalSymbols(kernelSymtab))
77        panic("could not load kernel symbols\n");
78    debugSymbolTable = kernelSymtab;
79
80    if (!kernel->loadLocalSymbols(kernelSymtab))
81        panic("could not load kernel local symbols\n");
82
83    if (!console->loadGlobalSymbols(consoleSymtab))
84        panic("could not load console symbols\n");
85
86    if (!bootloader->loadGlobalSymbols(bootloaderSymtab))
87        panic("could not load bootloader symbols\n");
88
89    // Load pal file
90    ObjectFile *pal = createObjectFile(palcode);
91    if (pal == NULL)
92        fatal("Could not load PALcode file %s", palcode);
93    pal->loadSections(physmem, true);
94
95    // Load console file
96    console->loadSections(physmem, true);
97
98    // Load kernel file
99    kernel->loadSections(physmem, true);
100    kernelStart = kernel->textBase();
101    kernelEnd = kernel->bssBase() + kernel->bssSize();
102    /* FIXME: entrypoint not in kernel, but in bootloader,
103       variable should be re-named appropriately */
104    kernelEntry = kernel->entryPoint();
105
106
107    DPRINTF(Loader, "Kernel start = %#x\n"
108            "Kernel end   = %#x\n"
109            "Kernel entry = %#x\n",
110            kernelStart, kernelEnd, kernelEntry);
111
112    DPRINTF(Loader, "Kernel loaded...\n");
113
114    // Load bootloader file
115    bootloader->loadSections(physmem, true);
116    kernelEntry = bootloader->entryPoint();
117    kernelStart = bootloader->textBase();
118    DPRINTF(Loader, "Bootloader entry at %#x\n", kernelEntry);
119
120#ifdef FS_MEASURE
121    //INSTRUMENTATION CODEGEN BEGIN ONE
122    if (bin == true) {
123        esIntrBin = new Statistics::MainBin(name() + " es_intr");
124        fnBins.insert(make_pair("es_intr", esIntrBin));
125
126        esRxeofBin = new Statistics::MainBin(name() + " es_rxeof");
127        fnBins.insert(make_pair("es_rxeof", esRxeofBin));
128
129        esNewbufBin = new Statistics::MainBin(name() + " es_newbuf");
130        fnBins.insert(make_pair("es_newbuf", esNewbufBin));
131
132        esDmaLoadBin = new Statistics::MainBin(name() + " es_dma_load");
133        fnBins.insert(make_pair("es_dma_load", esDmaLoadBin));
134
135        dmaMapLoadBin = new Statistics::MainBin(name() + " dma_map_load");
136        fnBins.insert(make_pair("dma_map_load", dmaMapLoadBin));
137
138        etherInputBin = new Statistics::MainBin(name() + " ether_input");
139        fnBins.insert(make_pair("ether_input", etherInputBin));
140
141        netisrInputBin = new Statistics::MainBin(name() + " netisr_input");
142        fnBins.insert(make_pair("netisr_input", netisrInputBin));
143
144        schednetisrIsrBin = new Statistics::MainBin(name() + " schednetisr_isr");
145        fnBins.insert(make_pair("schednetisr_isr", schednetisrIsrBin));
146
147        ipintrBin = new Statistics::MainBin(name() + " ipintr");
148        fnBins.insert(make_pair("ipintr", ipintrBin));
149
150        ipDooptionsBin = new Statistics::MainBin(name() + " ip_dooptions");
151        fnBins.insert(make_pair("ip_dooptions", ipDooptionsBin));
152
153        ipReassBin = new Statistics::MainBin(name() + " ip_reass");
154        fnBins.insert(make_pair("ip_reass", ipReassBin));
155
156        tcpInputBin = new Statistics::MainBin(name() + " tcp_input");
157        fnBins.insert(make_pair("tcp_input", tcpInputBin));
158
159        sbappendBin = new Statistics::MainBin(name() + " sbappend");
160        fnBins.insert(make_pair("sbappend", sbappendBin));
161
162        readBin = new Statistics::MainBin(name() + " read");
163        fnBins.insert(make_pair("read", readBin));
164
165        sooReadBin = new Statistics::MainBin(name() + " soo_read");
166        fnBins.insert(make_pair("soo_read", sooReadBin));
167
168        orecvBin = new Statistics::MainBin(name() + " orecv");
169        fnBins.insert(make_pair("orecv", orecvBin));
170
171        recvitBin = new Statistics::MainBin(name() + " recvit");
172        fnBins.insert(make_pair("recvit", recvitBin));
173
174        soreceiveBin = new Statistics::MainBin(name() + " soreceive");
175        fnBins.insert(make_pair("soreceive", soreceiveBin));
176
177        osendBin = new Statistics::MainBin(name() + " osend");
178        fnBins.insert(make_pair("osend", osendBin));
179
180        writeBin = new Statistics::MainBin(name() + " write");
181        fnBins.insert(make_pair("write", writeBin));
182
183        sooWriteBin = new Statistics::MainBin(name() + " soo_write");
184        fnBins.insert(make_pair("soo_write", sooWriteBin));
185
186        senditBin = new Statistics::MainBin(name() + " sendit");
187        fnBins.insert(make_pair("sendit", senditBin));
188
189        sosendBin = new Statistics::MainBin(name() + " sosend");
190        fnBins.insert(make_pair("sosend", sosendBin));
191
192        tcpSosendBin = new Statistics::MainBin(name() + " tcp_sosend");
193        fnBins.insert(make_pair("tcp_sosend", tcpSosendBin));
194
195        tcpOutputBin = new Statistics::MainBin(name() + " tcp_output");
196        fnBins.insert(make_pair("tcp_output", tcpOutputBin));
197
198        ipOutputBin = new Statistics::MainBin(name() + " ip_output");
199        fnBins.insert(make_pair("ip_output", ipOutputBin));
200
201        etherOutputBin = new Statistics::MainBin(name() + " ether_output");
202        fnBins.insert(make_pair("ether_output", etherOutputBin));
203
204        esStartBin = new Statistics::MainBin(name() + " es_start");
205        fnBins.insert(make_pair("es_start", esStartBin));
206
207        esTransmitBin = new Statistics::MainBin(name() + " es_transmit");
208        fnBins.insert(make_pair("es_transmit", esTransmitBin));
209
210        esTxeofBin = new Statistics::MainBin(name() + " es_txeof");
211        fnBins.insert(make_pair("es_txeof", esTxeofBin));
212
213        idleThreadBin = new Statistics::MainBin(name() + " idle_thread");
214        fnBins.insert(make_pair("idle_thread", idleThreadBin));
215
216    }
217    //INSTRUMENTATION CODEGEN END
218#endif //FS_MEASURE
219
220    kernelPanicEvent = new BreakPCEvent(&pcEventQueue, "kernel panic");
221    consolePanicEvent = new BreakPCEvent(&pcEventQueue, "console panic");
222    badaddrEvent = new LinuxBadAddrEvent(&pcEventQueue, "badaddr");
223    skipPowerStateEvent = new LinuxSkipFuncEvent(&pcEventQueue,
224                                            "tl_v48_capture_power_state");
225    skipScavengeBootEvent = new LinuxSkipFuncEvent(&pcEventQueue,
226                                              "pmap_scavenge_boot");
227    printfEvent = new LinuxPrintfEvent(&pcEventQueue, "printf");
228
229    skipDelayLoopEvent = new LinuxSkipDelayLoopEvent(&pcEventQueue,
230                                                     "calibrate_delay");
231
232   /* debugPrintfEvent = new DebugPrintfEvent(&pcEventQueue,
233                                            "debug_printf", false);
234    debugPrintfrEvent = new DebugPrintfEvent(&pcEventQueue,
235                                             "debug_printfr", true);
236    dumpMbufEvent = new DumpMbufEvent(&pcEventQueue, "dump_mbuf");
237*/
238#ifdef FS_MEASURE
239    //INSTRUMENTATION CODEGEN BEGIN TWO
240    if (bin == true) {
241          esIntrEvent = new FnEvent(&pcEventQueue, "es_intr", this);
242          esRxeofEvent = new FnEvent(&pcEventQueue, "es_rxeof", this);
243          esNewbufEvent = new FnEvent(&pcEventQueue, "es_newbuf", this);
244          esDmaLoadEvent = new FnEvent(&pcEventQueue, "es_dma_load", this);
245          dmaMapLoadEvent = new FnEvent(&pcEventQueue, "dma_map_load", this);
246          etherInputEvent = new FnEvent(&pcEventQueue, "ether_input", this);
247          netisrInputEvent = new FnEvent(&pcEventQueue, "netisr_input", this);
248          schednetisrIsrEvent = new FnEvent(&pcEventQueue, "schednetisr_isr", this);
249          ipintrEvent = new FnEvent(&pcEventQueue, "ipintr", this);
250          ipDooptionsEvent = new FnEvent(&pcEventQueue, "ip_dooptions", this);
251          ipReassEvent = new FnEvent(&pcEventQueue, "ip_reass", this);
252          tcpInputEvent = new FnEvent(&pcEventQueue, "tcp_input", this);
253          sbappendEvent = new FnEvent(&pcEventQueue, "sbappend", this);
254          readEvent = new FnEvent(&pcEventQueue, "read", this);
255          sooReadEvent = new FnEvent(&pcEventQueue, "soo_read", this);
256          orecvEvent = new FnEvent(&pcEventQueue, "orecv", this);
257          recvitEvent = new FnEvent(&pcEventQueue, "recvit", this);
258          soreceiveEvent = new FnEvent(&pcEventQueue, "soreceive", this);
259          osendEvent = new FnEvent(&pcEventQueue, "osend", this);
260          writeEvent = new FnEvent(&pcEventQueue, "write", this);
261          sooWriteEvent = new FnEvent(&pcEventQueue, "soo_write", this);
262          senditEvent = new FnEvent(&pcEventQueue, "sendit", this);
263          sosendEvent = new FnEvent(&pcEventQueue, "sosend", this);
264          tcpSosendEvent = new FnEvent(&pcEventQueue, "tcp_sosend", this);
265          tcpOutputEvent = new FnEvent(&pcEventQueue, "tcp_output", this);
266          ipOutputEvent = new FnEvent(&pcEventQueue, "ip_output", this);
267          etherOutputEvent = new FnEvent(&pcEventQueue, "ether_output", this);
268          esStartEvent = new FnEvent(&pcEventQueue, "es_start", this);
269          esTransmitEvent = new FnEvent(&pcEventQueue, "es_transmit", this);
270          esTxeofEvent = new FnEvent(&pcEventQueue, "es_txeof", this);
271          idleThreadEvent = new FnEvent(&pcEventQueue, "idle_thread", this);
272    }
273    //INSTRUMENTATION CODEGEN END
274#endif //FS_MEASURE
275
276    Addr addr = 0;
277
278    if (kernelSymtab->findAddress("est_cycle_freq", addr)) {
279        Addr paddr = vtophys(physmem, addr);
280        uint8_t *est_cycle_frequency =
281            physmem->dma_addr(paddr, sizeof(uint64_t));
282
283        if (est_cycle_frequency)
284            *(uint64_t *)est_cycle_frequency = ticksPerSecond;
285    }
286
287    if (kernelSymtab->findAddress("aic7xxx_no_reset", addr)) {
288        Addr paddr = vtophys(physmem, addr);
289        uint8_t *aic7xxx_no_reset =
290            physmem->dma_addr(paddr, sizeof(uint32_t));
291
292        if (aic7xxx_no_reset) {
293            *(uint32_t *)aic7xxx_no_reset = 1;
294        }
295    }
296
297    if (consoleSymtab->findAddress("env_booted_osflags", addr)) {
298        Addr paddr = vtophys(physmem, addr);
299        char *osflags = (char *)physmem->dma_addr(paddr, sizeof(uint32_t));
300
301        if (osflags)
302            strcpy(osflags, boot_osflags.c_str());
303    }
304
305    if (kernelSymtab->findAddress("panic", addr))
306        kernelPanicEvent->schedule(addr);
307    else
308        panic("could not find kernel symbol \'panic\'");
309
310    if (consoleSymtab->findAddress("panic", addr))
311        consolePanicEvent->schedule(addr);
312
313    if (kernelSymtab->findAddress("badaddr", addr))
314        badaddrEvent->schedule(addr);
315   // else
316        //panic("could not find kernel symbol \'badaddr\'");
317
318    if (kernelSymtab->findAddress("tl_v48_capture_power_state", addr))
319        skipPowerStateEvent->schedule(addr);
320
321    if (kernelSymtab->findAddress("pmap_scavenge_boot", addr))
322        skipScavengeBootEvent->schedule(addr);
323
324    if (kernelSymtab->findAddress("calibrate_delay", addr))
325        skipDelayLoopEvent->schedule(addr+8);
326
327#if TRACING_ON
328    if (kernelSymtab->findAddress("printk", addr))
329        printfEvent->schedule(addr);
330
331    if (kernelSymtab->findAddress("m5printf", addr))
332        debugPrintfEvent->schedule(addr);
333
334    if (kernelSymtab->findAddress("m5printfr", addr))
335        debugPrintfrEvent->schedule(addr);
336
337    if (kernelSymtab->findAddress("m5_dump_mbuf", addr))
338        dumpMbufEvent->schedule(addr);
339#endif
340
341#ifdef FS_MEASURE
342    //INSTRUMENTATION CODEGEN BEGIN THREE
343    if (bin == true) {
344        if (kernelSymtab->findAddress("es_intr", addr))
345            esIntrEvent->schedule(addr);
346        else
347            panic("could not find kernel symbol \'es_intr\'");
348
349        if (kernelSymtab->findAddress("es_rxeof", addr))
350            esRxeofEvent->schedule(addr);
351        else
352            panic("could not find kernel symbol \'es_rxeof\'");
353
354        if (kernelSymtab->findAddress("es_newbuf", addr))
355            esNewbufEvent->schedule(addr);
356        else
357            panic("could not find kernel symbol \'es_newbuf\'");
358
359        if (kernelSymtab->findAddress("es_dma_load", addr))
360            esDmaLoadEvent->schedule(addr);
361        else
362            panic("could not find kernel symbol \'es_dma_load\'");
363
364        if (kernelSymtab->findAddress("dma_map_load", addr))
365            dmaMapLoadEvent->schedule(addr);
366        else
367            panic("could not find kernel symbol \'dma_map_load\'");
368
369        if (kernelSymtab->findAddress("ether_input", addr))
370            etherInputEvent->schedule(addr);
371        else
372            panic("could not find kernel symbol \'ether_input\'");
373
374        if (kernelSymtab->findAddress("netisr_input", addr))
375            netisrInputEvent->schedule(addr);
376        else
377            panic("could not find kernel symbol \'netisr_input\'");
378
379        if (kernelSymtab->findAddress("schednetisr_isr", addr))
380            schednetisrIsrEvent->schedule(addr);
381        else
382            panic("could not find kernel symbol \'schednetisr_isr\'");
383
384        if (kernelSymtab->findAddress("ipintr", addr))
385            ipintrEvent->schedule(addr);
386        else
387            panic("could not find kernel symbol \'ipintr\'");
388
389        if (kernelSymtab->findAddress("ip_dooptions", addr))
390            ipDooptionsEvent->schedule(addr);
391        else
392            panic("could not find kernel symbol \'ip_dooptions\'");
393
394        if (kernelSymtab->findAddress("ip_reass", addr))
395            ipReassEvent->schedule(addr);
396        else
397            panic("could not find kernel symbol \'ip_reass\'");
398
399        if (kernelSymtab->findAddress("tcp_input", addr))
400            tcpInputEvent->schedule(addr);
401        else
402            panic("could not find kernel symbol \'tcp_input\'");
403
404        if (kernelSymtab->findAddress("sbappend", addr))
405            sbappendEvent->schedule(addr);
406        else
407            panic("could not find kernel symbol \'sbappend\'");
408
409        if (kernelSymtab->findAddress("read", addr))
410            readEvent->schedule(addr);
411        else
412            panic("could not find kernel symbol \'read\'");
413
414        if (kernelSymtab->findAddress("soo_read", addr))
415            sooReadEvent->schedule(addr);
416        else
417            panic("could not find kernel symbol \'soo_read\'");
418
419        if (kernelSymtab->findAddress("orecv", addr))
420            orecvEvent->schedule(addr);
421        else
422            panic("could not find kernel symbol \'orecv\'");
423
424        if (kernelSymtab->findAddress("recvit", addr))
425            recvitEvent->schedule(addr);
426        else
427            panic("could not find kernel symbol \'recvit\'");
428
429        if (kernelSymtab->findAddress("soreceive", addr))
430            soreceiveEvent->schedule(addr);
431        else
432            panic("could not find kernel symbol \'soreceive\'");
433
434        if (kernelSymtab->findAddress("osend", addr))
435            osendEvent->schedule(addr);
436        else
437            panic("could not find kernel symbol \'osend\'");
438
439        if (kernelSymtab->findAddress("write", addr))
440            writeEvent->schedule(addr);
441        else
442            panic("could not find kernel symbol \'write\'");
443
444        if (kernelSymtab->findAddress("soo_write", addr))
445            sooWriteEvent->schedule(addr);
446        else
447            panic("could not find kernel symbol \'soo_write\'");
448
449        if (kernelSymtab->findAddress("sendit", addr))
450            senditEvent->schedule(addr);
451        else
452            panic("could not find kernel symbol \'sendit\'");
453
454        if (kernelSymtab->findAddress("sosend", addr))
455            sosendEvent->schedule(addr);
456        else
457            panic("could not find kernel symbol \'sosend\'");
458
459        if (kernelSymtab->findAddress("tcp_sosend", addr))
460            tcpSosendEvent->schedule(addr);
461        else
462            panic("could not find kernel symbol \'tcp_sosend\'");
463
464        if (kernelSymtab->findAddress("tcp_output", addr))
465            tcpOutputEvent->schedule(addr);
466        else
467            panic("could not find kernel symbol \'tcp_output\'");
468
469        if (kernelSymtab->findAddress("ip_output", addr))
470            ipOutputEvent->schedule(addr);
471        else
472            panic("could not find kernel symbol \'ip_output\'");
473
474        if (kernelSymtab->findAddress("ether_output", addr))
475            etherOutputEvent->schedule(addr);
476        else
477            panic("could not find kernel symbol \'ether_output\'");
478
479        if (kernelSymtab->findAddress("es_start", addr))
480            esStartEvent->schedule(addr);
481        else
482            panic("could not find kernel symbol \'es_start\'");
483
484        if (kernelSymtab->findAddress("es_transmit", addr))
485            esTransmitEvent->schedule(addr);
486        else
487            panic("could not find kernel symbol \'es_transmit\'");
488
489        if (kernelSymtab->findAddress("es_txeof", addr))
490            esTxeofEvent->schedule(addr);
491        else
492            panic("could not find kernel symbol \'es_txeof\'");
493
494        if (kernelSymtab->findAddress("idle_thread", addr))
495            idleThreadEvent->schedule(addr);
496        else
497            panic("could not find kernel symbol \'idle_thread\'");
498
499    }
500    //INSTRUMENTATION CODEGEN END
501     if (bin == true) {
502        fnCalls
503            .name(name() + ":fnCalls")
504            .desc("all fn calls being tracked")
505            ;
506
507        populateMap("es_intr", "");
508        populateMap("es_rxeof", "es_intr");
509        populateMap("es_newbuf", "es_rxeof");
510        populateMap("es_dma_load", "es_newbuf");
511        populateMap("dma_map_load", "es_dma_load");
512        populateMap("ether_input", "es_rxeof");
513        populateMap("netisr_input", "ether_input");
514        populateMap("schednetisr_isr", "netisr_input");
515
516        populateMap("ipintr", "");
517        populateMap("ip_dooptions", "ipintr");
518        populateMap("ip_reass", "ipintr");
519        populateMap("tcp_input", "ipintr");
520        populateMap("sbappend", "tcp_input");
521
522        populateMap("read", "");
523        populateMap("orecv", "");
524        populateMap("soo_read", "read");
525        populateMap("recvit", "orecv");
526        populateMap("soreceive", "recvit");
527        populateMap("soreceive", "soo_read");
528
529        populateMap("write", "");
530        populateMap("osend", "");
531        populateMap("soo_write", "write");
532        populateMap("sendit", "osend");
533        populateMap("sosend", "sendit");
534        populateMap("sosend", "soo_write");
535        populateMap("tcp_sosend", "sosend");
536        populateMap("tcp_output", "tcp_sosend");
537        populateMap("ip_output", "tcp_output");
538        populateMap("ether_output", "ip_output");
539        populateMap("es_start", "ether_output");
540        populateMap("es_transmit", "es_start");
541
542        populateMap("es_txeof", "es_intr");
543
544        populateMap("idle_thread", "");
545    }
546#endif //FS_MEASURE
547}
548
549LinuxSystem::~LinuxSystem()
550{
551    delete kernel;
552    delete console;
553
554    delete kernelSymtab;
555    delete consoleSymtab;
556    delete bootloaderSymtab;
557
558    delete kernelPanicEvent;
559    delete consolePanicEvent;
560    delete badaddrEvent;
561    delete skipPowerStateEvent;
562    delete skipScavengeBootEvent;
563    delete printfEvent;
564    /*delete debugPrintfEvent;
565    delete debugPrintfrEvent;
566    delete dumpMbufEvent;
567*/
568#ifdef FS_MEASURE
569    //INSTRUMENTATION CODEGEN BEGIN FOUR
570    if (bin == true) {
571        delete esIntrEvent;
572        delete esRxeofEvent;
573        delete esNewbufEvent;
574        delete esDmaLoadEvent;
575        delete dmaMapLoadEvent;
576        delete etherInputEvent;
577        delete netisrInputEvent;
578        delete schednetisrIsrEvent;
579        delete ipintrEvent;
580        delete ipDooptionsEvent;
581        delete ipReassEvent;
582        delete tcpInputEvent;
583        delete sbappendEvent;
584        delete readEvent;
585        delete sooReadEvent;
586        delete orecvEvent;
587        delete recvitEvent;
588        delete soreceiveEvent;
589        delete osendEvent;
590        delete writeEvent;
591        delete sooWriteEvent;
592        delete senditEvent;
593        delete sosendEvent;
594        delete tcpSosendEvent;
595        delete tcpOutputEvent;
596        delete ipOutputEvent;
597        delete etherOutputEvent;
598        delete esStartEvent;
599        delete esTransmitEvent;
600        delete esTxeofEvent;
601        delete idleThreadEvent;
602    }
603    //INSTRUMENTATION CODEGEN END
604#endif //FS_MEASURE
605}
606
607void
608LinuxSystem::setDelayLoop(ExecContext *xc)
609{
610    Addr addr = 0;
611    if (kernelSymtab->findAddress("loops_per_jiffy", addr)) {
612        Addr paddr = vtophys(physmem, addr);
613
614        uint8_t *loops_per_jiffy =
615            physmem->dma_addr(paddr, sizeof(uint32_t));
616
617        Tick cpuFreq = xc->cpu->getFreq();
618        Tick intrFreq = platform->interrupt_frequency;
619        *(uint32_t *)loops_per_jiffy =
620            (uint32_t)((cpuFreq / intrFreq) * 0.9988);
621    }
622}
623
624int
625LinuxSystem::registerExecContext(ExecContext *xc)
626{
627    int xcIndex = System::registerExecContext(xc);
628
629    if (xcIndex == 0) {
630        // activate with zero delay so that we start ticking right
631        // away on cycle 0
632        xc->activate(0);
633    }
634
635    RemoteGDB *rgdb = new RemoteGDB(this, xc);
636    GDBListener *gdbl = new GDBListener(rgdb, 7000 + xcIndex);
637    gdbl->listen();
638
639    if (remoteGDB.size() <= xcIndex) {
640        remoteGDB.resize(xcIndex+1);
641    }
642
643    remoteGDB[xcIndex] = rgdb;
644
645    return xcIndex;
646}
647
648
649void
650LinuxSystem::replaceExecContext(ExecContext *xc, int xcIndex)
651{
652    System::replaceExecContext(xcIndex, xc);
653    remoteGDB[xcIndex]->replaceExecContext(xc);
654}
655
656bool
657LinuxSystem::breakpoint()
658{
659    return remoteGDB[0]->trap(ALPHA_KENTRY_IF);
660}
661
662#ifdef FS_MEASURE
663void
664LinuxSystem::populateMap(std::string callee, std::string caller)
665{
666    multimap<const string, string>::const_iterator i;
667    i = callerMap.insert(make_pair(callee, caller));
668    assert(i != callerMap.end() && "should not fail populating callerMap");
669}
670
671bool
672LinuxSystem::findCaller(std::string callee, std::string caller) const
673{
674    typedef multimap<const std::string, std::string>::const_iterator iter;
675    pair<iter, iter> range;
676
677    range = callerMap.equal_range(callee);
678    for (iter i = range.first; i != range.second; ++i) {
679        if ((*i).second == caller)
680            return true;
681    }
682    return false;
683}
684
685void
686LinuxSystem::dumpState(ExecContext *xc) const
687{
688#ifndef SW_DEBUG
689    return;
690#endif
691    if (xc->swCtx) {
692        stack<fnCall *> copy(xc->swCtx->callStack);
693        if (copy.empty())
694            return;
695        cprintf("xc->swCtx:\n");
696        fnCall *top;
697        cprintf("||   call: %d\n",xc->swCtx->calls);
698        for (top = copy.top(); !copy.empty(); copy.pop() ) {
699            top = copy.top();
700            cprintf("||  %13s : %s \n", top->name, top->myBin->name());
701        }
702    }
703}
704#endif //FS_MEASURE
705
706BEGIN_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem)
707
708    Param<bool> bin;
709    SimObjectParam<MemoryController *> mem_ctl;
710    SimObjectParam<PhysicalMemory *> physmem;
711    Param<uint64_t> init_param;
712
713    Param<string> kernel_code;
714    Param<string> console_code;
715    Param<string> pal_code;
716    Param<string> boot_osflags;
717    Param<string> bootloader_code;
718
719END_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem)
720
721BEGIN_INIT_SIM_OBJECT_PARAMS(LinuxSystem)
722
723    INIT_PARAM_DFLT(bin, "is this system to be binned", false),
724    INIT_PARAM(mem_ctl, "memory controller"),
725    INIT_PARAM(physmem, "phsyical memory"),
726    INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0),
727    INIT_PARAM(kernel_code, "file that contains the kernel code"),
728    INIT_PARAM(console_code, "file that contains the console code"),
729    INIT_PARAM(pal_code, "file that contains palcode"),
730    INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot",
731                                   "a"),
732    INIT_PARAM(bootloader_code, "file that contains the bootloader")
733
734
735END_INIT_SIM_OBJECT_PARAMS(LinuxSystem)
736
737CREATE_SIM_OBJECT(LinuxSystem)
738{
739    LinuxSystem *sys = new LinuxSystem(getInstanceName(), init_param, mem_ctl,
740                                       physmem, kernel_code, console_code,
741                                       pal_code, boot_osflags, bootloader_code, bin);
742
743    return sys;
744}
745
746REGISTER_SIM_OBJECT("LinuxSystem", LinuxSystem)
747