system.cc revision 803
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 (!console->loadGlobalSymbols(consoleSymtab))
81        panic("could not load console symbols\n");
82
83    if (!bootloader->loadGlobalSymbols(bootloaderSymtab))
84        panic("could not load bootloader symbols\n");
85
86    // Load pal file
87    ObjectFile *pal = createObjectFile(palcode);
88    if (pal == NULL)
89        fatal("Could not load PALcode file %s", palcode);
90    pal->loadSections(physmem, true);
91
92    // Load console file
93    console->loadSections(physmem, true);
94
95    // Load kernel file
96    kernel->loadSections(physmem, true);
97    kernelStart = kernel->textBase();
98    kernelEnd = kernel->bssBase() + kernel->bssSize();
99    /* FIXME: entrypoint not in kernel, but in bootloader,
100       variable should be re-named appropriately */
101    kernelEntry = kernel->entryPoint();
102
103
104    DPRINTF(Loader, "Kernel start = %#x\n"
105            "Kernel end   = %#x\n"
106            "Kernel entry = %#x\n",
107            kernelStart, kernelEnd, kernelEntry);
108
109    DPRINTF(Loader, "Kernel loaded...\n");
110
111    // Load bootloader file
112    bootloader->loadSections(physmem, true);
113    kernelEntry = bootloader->entryPoint();
114    kernelStart = bootloader->textBase();
115    DPRINTF(Loader, "Bootloader entry at %#x\n", kernelEntry);
116
117#ifdef FS_MEASURE
118    //INSTRUMENTATION CODEGEN BEGIN ONE
119    if (bin == true) {
120        esIntrBin = new Statistics::MainBin(name() + " es_intr");
121        fnBins.insert(make_pair("es_intr", esIntrBin));
122
123        esRxeofBin = new Statistics::MainBin(name() + " es_rxeof");
124        fnBins.insert(make_pair("es_rxeof", esRxeofBin));
125
126        esNewbufBin = new Statistics::MainBin(name() + " es_newbuf");
127        fnBins.insert(make_pair("es_newbuf", esNewbufBin));
128
129        esDmaLoadBin = new Statistics::MainBin(name() + " es_dma_load");
130        fnBins.insert(make_pair("es_dma_load", esDmaLoadBin));
131
132        dmaMapLoadBin = new Statistics::MainBin(name() + " dma_map_load");
133        fnBins.insert(make_pair("dma_map_load", dmaMapLoadBin));
134
135        etherInputBin = new Statistics::MainBin(name() + " ether_input");
136        fnBins.insert(make_pair("ether_input", etherInputBin));
137
138        netisrInputBin = new Statistics::MainBin(name() + " netisr_input");
139        fnBins.insert(make_pair("netisr_input", netisrInputBin));
140
141        schednetisrIsrBin = new Statistics::MainBin(name() + " schednetisr_isr");
142        fnBins.insert(make_pair("schednetisr_isr", schednetisrIsrBin));
143
144        ipintrBin = new Statistics::MainBin(name() + " ipintr");
145        fnBins.insert(make_pair("ipintr", ipintrBin));
146
147        ipDooptionsBin = new Statistics::MainBin(name() + " ip_dooptions");
148        fnBins.insert(make_pair("ip_dooptions", ipDooptionsBin));
149
150        ipReassBin = new Statistics::MainBin(name() + " ip_reass");
151        fnBins.insert(make_pair("ip_reass", ipReassBin));
152
153        tcpInputBin = new Statistics::MainBin(name() + " tcp_input");
154        fnBins.insert(make_pair("tcp_input", tcpInputBin));
155
156        sbappendBin = new Statistics::MainBin(name() + " sbappend");
157        fnBins.insert(make_pair("sbappend", sbappendBin));
158
159        readBin = new Statistics::MainBin(name() + " read");
160        fnBins.insert(make_pair("read", readBin));
161
162        sooReadBin = new Statistics::MainBin(name() + " soo_read");
163        fnBins.insert(make_pair("soo_read", sooReadBin));
164
165        orecvBin = new Statistics::MainBin(name() + " orecv");
166        fnBins.insert(make_pair("orecv", orecvBin));
167
168        recvitBin = new Statistics::MainBin(name() + " recvit");
169        fnBins.insert(make_pair("recvit", recvitBin));
170
171        soreceiveBin = new Statistics::MainBin(name() + " soreceive");
172        fnBins.insert(make_pair("soreceive", soreceiveBin));
173
174        osendBin = new Statistics::MainBin(name() + " osend");
175        fnBins.insert(make_pair("osend", osendBin));
176
177        writeBin = new Statistics::MainBin(name() + " write");
178        fnBins.insert(make_pair("write", writeBin));
179
180        sooWriteBin = new Statistics::MainBin(name() + " soo_write");
181        fnBins.insert(make_pair("soo_write", sooWriteBin));
182
183        senditBin = new Statistics::MainBin(name() + " sendit");
184        fnBins.insert(make_pair("sendit", senditBin));
185
186        sosendBin = new Statistics::MainBin(name() + " sosend");
187        fnBins.insert(make_pair("sosend", sosendBin));
188
189        tcpSosendBin = new Statistics::MainBin(name() + " tcp_sosend");
190        fnBins.insert(make_pair("tcp_sosend", tcpSosendBin));
191
192        tcpOutputBin = new Statistics::MainBin(name() + " tcp_output");
193        fnBins.insert(make_pair("tcp_output", tcpOutputBin));
194
195        ipOutputBin = new Statistics::MainBin(name() + " ip_output");
196        fnBins.insert(make_pair("ip_output", ipOutputBin));
197
198        etherOutputBin = new Statistics::MainBin(name() + " ether_output");
199        fnBins.insert(make_pair("ether_output", etherOutputBin));
200
201        esStartBin = new Statistics::MainBin(name() + " es_start");
202        fnBins.insert(make_pair("es_start", esStartBin));
203
204        esTransmitBin = new Statistics::MainBin(name() + " es_transmit");
205        fnBins.insert(make_pair("es_transmit", esTransmitBin));
206
207        esTxeofBin = new Statistics::MainBin(name() + " es_txeof");
208        fnBins.insert(make_pair("es_txeof", esTxeofBin));
209
210        idleThreadBin = new Statistics::MainBin(name() + " idle_thread");
211        fnBins.insert(make_pair("idle_thread", idleThreadBin));
212
213    }
214    //INSTRUMENTATION CODEGEN END
215#endif //FS_MEASURE
216
217    kernelPanicEvent = new BreakPCEvent(&pcEventQueue, "kernel panic");
218    consolePanicEvent = new BreakPCEvent(&pcEventQueue, "console panic");
219    badaddrEvent = new LinuxBadAddrEvent(&pcEventQueue, "badaddr");
220    skipPowerStateEvent = new LinuxSkipFuncEvent(&pcEventQueue,
221                                            "tl_v48_capture_power_state");
222    skipScavengeBootEvent = new LinuxSkipFuncEvent(&pcEventQueue,
223                                              "pmap_scavenge_boot");
224    printfEvent = new LinuxPrintfEvent(&pcEventQueue, "printf");
225
226    skipDelayLoopEvent = new LinuxSkipDelayLoopEvent(&pcEventQueue,
227                                                     "calibrate_delay");
228
229   /* debugPrintfEvent = new DebugPrintfEvent(&pcEventQueue,
230                                            "debug_printf", false);
231    debugPrintfrEvent = new DebugPrintfEvent(&pcEventQueue,
232                                             "debug_printfr", true);
233    dumpMbufEvent = new DumpMbufEvent(&pcEventQueue, "dump_mbuf");
234*/
235#ifdef FS_MEASURE
236    //INSTRUMENTATION CODEGEN BEGIN TWO
237    if (bin == true) {
238          esIntrEvent = new FnEvent(&pcEventQueue, "es_intr", this);
239          esRxeofEvent = new FnEvent(&pcEventQueue, "es_rxeof", this);
240          esNewbufEvent = new FnEvent(&pcEventQueue, "es_newbuf", this);
241          esDmaLoadEvent = new FnEvent(&pcEventQueue, "es_dma_load", this);
242          dmaMapLoadEvent = new FnEvent(&pcEventQueue, "dma_map_load", this);
243          etherInputEvent = new FnEvent(&pcEventQueue, "ether_input", this);
244          netisrInputEvent = new FnEvent(&pcEventQueue, "netisr_input", this);
245          schednetisrIsrEvent = new FnEvent(&pcEventQueue, "schednetisr_isr", this);
246          ipintrEvent = new FnEvent(&pcEventQueue, "ipintr", this);
247          ipDooptionsEvent = new FnEvent(&pcEventQueue, "ip_dooptions", this);
248          ipReassEvent = new FnEvent(&pcEventQueue, "ip_reass", this);
249          tcpInputEvent = new FnEvent(&pcEventQueue, "tcp_input", this);
250          sbappendEvent = new FnEvent(&pcEventQueue, "sbappend", this);
251          readEvent = new FnEvent(&pcEventQueue, "read", this);
252          sooReadEvent = new FnEvent(&pcEventQueue, "soo_read", this);
253          orecvEvent = new FnEvent(&pcEventQueue, "orecv", this);
254          recvitEvent = new FnEvent(&pcEventQueue, "recvit", this);
255          soreceiveEvent = new FnEvent(&pcEventQueue, "soreceive", this);
256          osendEvent = new FnEvent(&pcEventQueue, "osend", this);
257          writeEvent = new FnEvent(&pcEventQueue, "write", this);
258          sooWriteEvent = new FnEvent(&pcEventQueue, "soo_write", this);
259          senditEvent = new FnEvent(&pcEventQueue, "sendit", this);
260          sosendEvent = new FnEvent(&pcEventQueue, "sosend", this);
261          tcpSosendEvent = new FnEvent(&pcEventQueue, "tcp_sosend", this);
262          tcpOutputEvent = new FnEvent(&pcEventQueue, "tcp_output", this);
263          ipOutputEvent = new FnEvent(&pcEventQueue, "ip_output", this);
264          etherOutputEvent = new FnEvent(&pcEventQueue, "ether_output", this);
265          esStartEvent = new FnEvent(&pcEventQueue, "es_start", this);
266          esTransmitEvent = new FnEvent(&pcEventQueue, "es_transmit", this);
267          esTxeofEvent = new FnEvent(&pcEventQueue, "es_txeof", this);
268          idleThreadEvent = new FnEvent(&pcEventQueue, "idle_thread", this);
269    }
270    //INSTRUMENTATION CODEGEN END
271#endif //FS_MEASURE
272
273    Addr addr = 0;
274    if (kernelSymtab->findAddress("est_cycle_freq", addr)) {
275        Addr paddr = vtophys(physmem, addr);
276        uint8_t *est_cycle_frequency =
277            physmem->dma_addr(paddr, sizeof(uint64_t));
278
279        if (est_cycle_frequency)
280            *(uint64_t *)est_cycle_frequency = ticksPerSecond;
281    }
282
283    if (consoleSymtab->findAddress("env_booted_osflags", addr)) {
284        Addr paddr = vtophys(physmem, addr);
285        char *osflags = (char *)physmem->dma_addr(paddr, sizeof(uint32_t));
286
287        if (osflags)
288            strcpy(osflags, boot_osflags.c_str());
289    }
290
291    if (kernelSymtab->findAddress("panic", addr))
292        kernelPanicEvent->schedule(addr);
293    else
294        panic("could not find kernel symbol \'panic\'");
295
296    if (consoleSymtab->findAddress("panic", addr))
297        consolePanicEvent->schedule(addr);
298
299    if (kernelSymtab->findAddress("badaddr", addr))
300        badaddrEvent->schedule(addr);
301   // else
302        //panic("could not find kernel symbol \'badaddr\'");
303
304    if (kernelSymtab->findAddress("tl_v48_capture_power_state", addr))
305        skipPowerStateEvent->schedule(addr);
306
307    if (kernelSymtab->findAddress("pmap_scavenge_boot", addr))
308        skipScavengeBootEvent->schedule(addr);
309
310    if (kernelSymtab->findAddress("calibrate_delay", addr))
311        skipDelayLoopEvent->schedule(addr+8);
312
313#if TRACING_ON
314    if (kernelSymtab->findAddress("printk", addr))
315        printfEvent->schedule(addr);
316
317    if (kernelSymtab->findAddress("m5printf", addr))
318        debugPrintfEvent->schedule(addr);
319
320    if (kernelSymtab->findAddress("m5printfr", addr))
321        debugPrintfrEvent->schedule(addr);
322
323    if (kernelSymtab->findAddress("m5_dump_mbuf", addr))
324        dumpMbufEvent->schedule(addr);
325#endif
326
327#ifdef FS_MEASURE
328    //INSTRUMENTATION CODEGEN BEGIN THREE
329    if (bin == true) {
330        if (kernelSymtab->findAddress("es_intr", addr))
331            esIntrEvent->schedule(addr);
332        else
333            panic("could not find kernel symbol \'es_intr\'");
334
335        if (kernelSymtab->findAddress("es_rxeof", addr))
336            esRxeofEvent->schedule(addr);
337        else
338            panic("could not find kernel symbol \'es_rxeof\'");
339
340        if (kernelSymtab->findAddress("es_newbuf", addr))
341            esNewbufEvent->schedule(addr);
342        else
343            panic("could not find kernel symbol \'es_newbuf\'");
344
345        if (kernelSymtab->findAddress("es_dma_load", addr))
346            esDmaLoadEvent->schedule(addr);
347        else
348            panic("could not find kernel symbol \'es_dma_load\'");
349
350        if (kernelSymtab->findAddress("dma_map_load", addr))
351            dmaMapLoadEvent->schedule(addr);
352        else
353            panic("could not find kernel symbol \'dma_map_load\'");
354
355        if (kernelSymtab->findAddress("ether_input", addr))
356            etherInputEvent->schedule(addr);
357        else
358            panic("could not find kernel symbol \'ether_input\'");
359
360        if (kernelSymtab->findAddress("netisr_input", addr))
361            netisrInputEvent->schedule(addr);
362        else
363            panic("could not find kernel symbol \'netisr_input\'");
364
365        if (kernelSymtab->findAddress("schednetisr_isr", addr))
366            schednetisrIsrEvent->schedule(addr);
367        else
368            panic("could not find kernel symbol \'schednetisr_isr\'");
369
370        if (kernelSymtab->findAddress("ipintr", addr))
371            ipintrEvent->schedule(addr);
372        else
373            panic("could not find kernel symbol \'ipintr\'");
374
375        if (kernelSymtab->findAddress("ip_dooptions", addr))
376            ipDooptionsEvent->schedule(addr);
377        else
378            panic("could not find kernel symbol \'ip_dooptions\'");
379
380        if (kernelSymtab->findAddress("ip_reass", addr))
381            ipReassEvent->schedule(addr);
382        else
383            panic("could not find kernel symbol \'ip_reass\'");
384
385        if (kernelSymtab->findAddress("tcp_input", addr))
386            tcpInputEvent->schedule(addr);
387        else
388            panic("could not find kernel symbol \'tcp_input\'");
389
390        if (kernelSymtab->findAddress("sbappend", addr))
391            sbappendEvent->schedule(addr);
392        else
393            panic("could not find kernel symbol \'sbappend\'");
394
395        if (kernelSymtab->findAddress("read", addr))
396            readEvent->schedule(addr);
397        else
398            panic("could not find kernel symbol \'read\'");
399
400        if (kernelSymtab->findAddress("soo_read", addr))
401            sooReadEvent->schedule(addr);
402        else
403            panic("could not find kernel symbol \'soo_read\'");
404
405        if (kernelSymtab->findAddress("orecv", addr))
406            orecvEvent->schedule(addr);
407        else
408            panic("could not find kernel symbol \'orecv\'");
409
410        if (kernelSymtab->findAddress("recvit", addr))
411            recvitEvent->schedule(addr);
412        else
413            panic("could not find kernel symbol \'recvit\'");
414
415        if (kernelSymtab->findAddress("soreceive", addr))
416            soreceiveEvent->schedule(addr);
417        else
418            panic("could not find kernel symbol \'soreceive\'");
419
420        if (kernelSymtab->findAddress("osend", addr))
421            osendEvent->schedule(addr);
422        else
423            panic("could not find kernel symbol \'osend\'");
424
425        if (kernelSymtab->findAddress("write", addr))
426            writeEvent->schedule(addr);
427        else
428            panic("could not find kernel symbol \'write\'");
429
430        if (kernelSymtab->findAddress("soo_write", addr))
431            sooWriteEvent->schedule(addr);
432        else
433            panic("could not find kernel symbol \'soo_write\'");
434
435        if (kernelSymtab->findAddress("sendit", addr))
436            senditEvent->schedule(addr);
437        else
438            panic("could not find kernel symbol \'sendit\'");
439
440        if (kernelSymtab->findAddress("sosend", addr))
441            sosendEvent->schedule(addr);
442        else
443            panic("could not find kernel symbol \'sosend\'");
444
445        if (kernelSymtab->findAddress("tcp_sosend", addr))
446            tcpSosendEvent->schedule(addr);
447        else
448            panic("could not find kernel symbol \'tcp_sosend\'");
449
450        if (kernelSymtab->findAddress("tcp_output", addr))
451            tcpOutputEvent->schedule(addr);
452        else
453            panic("could not find kernel symbol \'tcp_output\'");
454
455        if (kernelSymtab->findAddress("ip_output", addr))
456            ipOutputEvent->schedule(addr);
457        else
458            panic("could not find kernel symbol \'ip_output\'");
459
460        if (kernelSymtab->findAddress("ether_output", addr))
461            etherOutputEvent->schedule(addr);
462        else
463            panic("could not find kernel symbol \'ether_output\'");
464
465        if (kernelSymtab->findAddress("es_start", addr))
466            esStartEvent->schedule(addr);
467        else
468            panic("could not find kernel symbol \'es_start\'");
469
470        if (kernelSymtab->findAddress("es_transmit", addr))
471            esTransmitEvent->schedule(addr);
472        else
473            panic("could not find kernel symbol \'es_transmit\'");
474
475        if (kernelSymtab->findAddress("es_txeof", addr))
476            esTxeofEvent->schedule(addr);
477        else
478            panic("could not find kernel symbol \'es_txeof\'");
479
480        if (kernelSymtab->findAddress("idle_thread", addr))
481            idleThreadEvent->schedule(addr);
482        else
483            panic("could not find kernel symbol \'idle_thread\'");
484
485    }
486    //INSTRUMENTATION CODEGEN END
487     if (bin == true) {
488        fnCalls
489            .name(name() + ":fnCalls")
490            .desc("all fn calls being tracked")
491            ;
492
493        populateMap("es_intr", "");
494        populateMap("es_rxeof", "es_intr");
495        populateMap("es_newbuf", "es_rxeof");
496        populateMap("es_dma_load", "es_newbuf");
497        populateMap("dma_map_load", "es_dma_load");
498        populateMap("ether_input", "es_rxeof");
499        populateMap("netisr_input", "ether_input");
500        populateMap("schednetisr_isr", "netisr_input");
501
502        populateMap("ipintr", "");
503        populateMap("ip_dooptions", "ipintr");
504        populateMap("ip_reass", "ipintr");
505        populateMap("tcp_input", "ipintr");
506        populateMap("sbappend", "tcp_input");
507
508        populateMap("read", "");
509        populateMap("orecv", "");
510        populateMap("soo_read", "read");
511        populateMap("recvit", "orecv");
512        populateMap("soreceive", "recvit");
513        populateMap("soreceive", "soo_read");
514
515        populateMap("write", "");
516        populateMap("osend", "");
517        populateMap("soo_write", "write");
518        populateMap("sendit", "osend");
519        populateMap("sosend", "sendit");
520        populateMap("sosend", "soo_write");
521        populateMap("tcp_sosend", "sosend");
522        populateMap("tcp_output", "tcp_sosend");
523        populateMap("ip_output", "tcp_output");
524        populateMap("ether_output", "ip_output");
525        populateMap("es_start", "ether_output");
526        populateMap("es_transmit", "es_start");
527
528        populateMap("es_txeof", "es_intr");
529
530        populateMap("idle_thread", "");
531    }
532#endif //FS_MEASURE
533}
534
535LinuxSystem::~LinuxSystem()
536{
537    delete kernel;
538    delete console;
539
540    delete kernelSymtab;
541    delete consoleSymtab;
542    delete bootloaderSymtab;
543
544    delete kernelPanicEvent;
545    delete consolePanicEvent;
546    delete badaddrEvent;
547    delete skipPowerStateEvent;
548    delete skipScavengeBootEvent;
549    delete printfEvent;
550    /*delete debugPrintfEvent;
551    delete debugPrintfrEvent;
552    delete dumpMbufEvent;
553*/
554#ifdef FS_MEASURE
555    //INSTRUMENTATION CODEGEN BEGIN FOUR
556    if (bin == true) {
557        delete esIntrEvent;
558        delete esRxeofEvent;
559        delete esNewbufEvent;
560        delete esDmaLoadEvent;
561        delete dmaMapLoadEvent;
562        delete etherInputEvent;
563        delete netisrInputEvent;
564        delete schednetisrIsrEvent;
565        delete ipintrEvent;
566        delete ipDooptionsEvent;
567        delete ipReassEvent;
568        delete tcpInputEvent;
569        delete sbappendEvent;
570        delete readEvent;
571        delete sooReadEvent;
572        delete orecvEvent;
573        delete recvitEvent;
574        delete soreceiveEvent;
575        delete osendEvent;
576        delete writeEvent;
577        delete sooWriteEvent;
578        delete senditEvent;
579        delete sosendEvent;
580        delete tcpSosendEvent;
581        delete tcpOutputEvent;
582        delete ipOutputEvent;
583        delete etherOutputEvent;
584        delete esStartEvent;
585        delete esTransmitEvent;
586        delete esTxeofEvent;
587        delete idleThreadEvent;
588    }
589    //INSTRUMENTATION CODEGEN END
590#endif //FS_MEASURE
591}
592
593void
594LinuxSystem::setDelayLoop(ExecContext *xc)
595{
596    Addr addr = 0;
597    if (kernelSymtab->findAddress("loops_per_jiffy", addr)) {
598        Addr paddr = vtophys(physmem, addr);
599
600        uint8_t *loops_per_jiffy =
601            physmem->dma_addr(paddr, sizeof(uint32_t));
602
603        Tick cpuFreq = xc->cpu->getFreq();
604        Tick intrFreq = platform->interrupt_frequency;
605        *(uint32_t *)loops_per_jiffy =
606            (uint32_t)((cpuFreq / intrFreq) * 0.9988);
607    }
608}
609
610int
611LinuxSystem::registerExecContext(ExecContext *xc)
612{
613    int xcIndex = System::registerExecContext(xc);
614
615    if (xcIndex == 0) {
616        // activate with zero delay so that we start ticking right
617        // away on cycle 0
618        xc->activate(0);
619    }
620
621    RemoteGDB *rgdb = new RemoteGDB(this, xc);
622    GDBListener *gdbl = new GDBListener(rgdb, 7000 + xcIndex);
623    gdbl->listen();
624
625    if (remoteGDB.size() <= xcIndex) {
626        remoteGDB.resize(xcIndex+1);
627    }
628
629    remoteGDB[xcIndex] = rgdb;
630
631    return xcIndex;
632}
633
634
635void
636LinuxSystem::replaceExecContext(ExecContext *xc, int xcIndex)
637{
638    System::replaceExecContext(xcIndex, xc);
639    remoteGDB[xcIndex]->replaceExecContext(xc);
640}
641
642bool
643LinuxSystem::breakpoint()
644{
645    return remoteGDB[0]->trap(ALPHA_KENTRY_IF);
646}
647
648#ifdef FS_MEASURE
649void
650LinuxSystem::populateMap(std::string callee, std::string caller)
651{
652    multimap<const string, string>::const_iterator i;
653    i = callerMap.insert(make_pair(callee, caller));
654    assert(i != callerMap.end() && "should not fail populating callerMap");
655}
656
657bool
658LinuxSystem::findCaller(std::string callee, std::string caller) const
659{
660    typedef multimap<const std::string, std::string>::const_iterator iter;
661    pair<iter, iter> range;
662
663    range = callerMap.equal_range(callee);
664    for (iter i = range.first; i != range.second; ++i) {
665        if ((*i).second == caller)
666            return true;
667    }
668    return false;
669}
670
671void
672LinuxSystem::dumpState(ExecContext *xc) const
673{
674#ifndef SW_DEBUG
675    return;
676#endif
677    if (xc->swCtx) {
678        stack<fnCall *> copy(xc->swCtx->callStack);
679        if (copy.empty())
680            return;
681        cprintf("xc->swCtx:\n");
682        fnCall *top;
683        cprintf("||   call: %d\n",xc->swCtx->calls);
684        for (top = copy.top(); !copy.empty(); copy.pop() ) {
685            top = copy.top();
686            cprintf("||  %13s : %s \n", top->name, top->myBin->name());
687        }
688    }
689}
690#endif //FS_MEASURE
691
692BEGIN_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem)
693
694    Param<bool> bin;
695    SimObjectParam<MemoryController *> mem_ctl;
696    SimObjectParam<PhysicalMemory *> physmem;
697    Param<uint64_t> init_param;
698
699    Param<string> kernel_code;
700    Param<string> console_code;
701    Param<string> pal_code;
702    Param<string> boot_osflags;
703    Param<string> bootloader_code;
704
705END_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem)
706
707BEGIN_INIT_SIM_OBJECT_PARAMS(LinuxSystem)
708
709    INIT_PARAM_DFLT(bin, "is this system to be binned", false),
710    INIT_PARAM(mem_ctl, "memory controller"),
711    INIT_PARAM(physmem, "phsyical memory"),
712    INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0),
713    INIT_PARAM(kernel_code, "file that contains the kernel code"),
714    INIT_PARAM(console_code, "file that contains the console code"),
715    INIT_PARAM(pal_code, "file that contains palcode"),
716    INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot",
717                                   "a"),
718    INIT_PARAM(bootloader_code, "file that contains the bootloader")
719
720
721END_INIT_SIM_OBJECT_PARAMS(LinuxSystem)
722
723CREATE_SIM_OBJECT(LinuxSystem)
724{
725    LinuxSystem *sys = new LinuxSystem(getInstanceName(), init_param, mem_ctl,
726                                       physmem, kernel_code, console_code,
727                                       pal_code, boot_osflags, bootloader_code, bin);
728
729    return sys;
730}
731
732REGISTER_SIM_OBJECT("LinuxSystem", LinuxSystem)
733