system.cc revision 1084
1/*
2 * Copyright (c) 2004 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/**
30 * @file
31 * This code loads the linux kernel, console, pal and patches certain
32 * functions.  The symbol tables are loaded so that traces can show
33 * the executing function and we can skip functions. Various delay
34 * loops are skipped and their final values manually computed to speed
35 * up boot time.
36 */
37
38#include "base/trace.hh"
39#include "cpu/exec_context.hh"
40#include "cpu/base_cpu.hh"
41#include "kern/linux/linux_events.hh"
42#include "kern/linux/linux_system.hh"
43#include "kern/system_events.hh"
44#include "mem/functional_mem/memory_control.hh"
45#include "mem/functional_mem/physical_memory.hh"
46#include "sim/builder.hh"
47#include "dev/platform.hh"
48#include "targetarch/isa_traits.hh"
49#include "targetarch/vtophys.hh"
50#include "sim/debug.hh"
51
52extern SymbolTable *debugSymbolTable;
53
54using namespace std;
55
56LinuxSystem::LinuxSystem(Params *p)
57    : System(p)
58{
59    Addr addr = 0;
60
61    /**
62     * find the address of the est_cycle_freq variable and insert it
63     * so we don't through the lengthly process of trying to
64     * calculated it by using the PIT, RTC, etc.
65     */
66    if (kernelSymtab->findAddress("est_cycle_freq", addr)) {
67        Addr paddr = vtophys(physmem, addr);
68        uint8_t *est_cycle_frequency =
69            physmem->dma_addr(paddr, sizeof(uint64_t));
70
71        if (est_cycle_frequency)
72            *(uint64_t *)est_cycle_frequency = htoa(ticksPerSecond);
73    }
74
75
76    /**
77     * Since we aren't using a bootloader, we have to copy the kernel arguments
78     * directly into the kernels memory.
79     */
80    {
81        Addr paddr = vtophys(physmem, PARAM_ADDR);
82        char *commandline = (char*)physmem->dma_addr(paddr, sizeof(uint64_t));
83        if (commandline)
84            strcpy(commandline, params->boot_osflags.c_str());
85    }
86
87
88    /**
89     * EV5 only supports 127 ASNs so we are going to tell the kernel that the
90     * paritiuclar EV6 we have only supports 127 asns.
91     * @todo At some point we should change ev5.hh and the palcode to support
92     * 255 ASNs.
93     */
94    if (kernelSymtab->findAddress("dp264_mv", addr)) {
95        Addr paddr = vtophys(physmem, addr);
96        char *dp264_mv = (char *)physmem->dma_addr(paddr, sizeof(uint64_t));
97
98        if (dp264_mv) {
99            *(uint32_t*)(dp264_mv+0x18) = htoa((uint32_t)127);
100        } else
101            panic("could not translate dp264_mv addr\n");
102
103    } else
104        panic("could not find dp264_mv\n");
105
106#ifdef DEBUG
107    kernelPanicEvent = new BreakPCEvent(&pcEventQueue, "kernel panic");
108    if (kernelSymtab->findAddress("panic", addr))
109        kernelPanicEvent->schedule(addr);
110    else
111        panic("could not find kernel symbol \'panic\'");
112#endif
113
114    /**
115     * Any time ide_delay_50ms, calibarte_delay or
116     * determine_cpu_caches is called just skip the
117     * function. Currently determine_cpu_caches only is used put
118     * information in proc, however if that changes in the future we
119     * will have to fill in the cache size variables appropriately.
120     */
121    skipIdeDelay50msEvent = new SkipFuncEvent(&pcEventQueue, "ide_delay_50ms");
122    if (kernelSymtab->findAddress("ide_delay_50ms", addr))
123        skipIdeDelay50msEvent->schedule(addr+sizeof(MachInst));
124
125    skipDelayLoopEvent = new LinuxSkipDelayLoopEvent(&pcEventQueue,
126                                                     "calibrate_delay");
127    if (kernelSymtab->findAddress("calibrate_delay", addr))
128        skipDelayLoopEvent->schedule(addr+sizeof(MachInst));
129
130    skipCacheProbeEvent = new SkipFuncEvent(&pcEventQueue,
131                                            "determine_cpu_caches");
132    if (kernelSymtab->findAddress("determine_cpu_caches", addr))
133        skipCacheProbeEvent->schedule(addr+sizeof(MachInst));
134
135    debugPrintkEvent = new DebugPrintkEvent(&pcEventQueue, "dprintk");
136    if (kernelSymtab->findAddress("dprintk", addr))
137        debugPrintkEvent->schedule(addr+8);
138
139    idleStartEvent = new IdleStartEvent(&pcEventQueue, "cpu_idle", this);
140    if (kernelSymtab->findAddress("cpu_idle", addr))
141        idleStartEvent->schedule(addr);
142
143    printThreadEvent = new PrintThreadInfo(&pcEventQueue, "threadinfo");
144    if (kernelSymtab->findAddress("alpha_switch_to", addr) && DTRACE(Thread))
145        printThreadEvent->schedule(addr + sizeof(MachInst) * 6);
146
147    intStartEvent = new InterruptStartEvent(&pcEventQueue, "intStartEvent");
148    if (palSymtab->findAddress("sys_int_21", addr))
149        intStartEvent->schedule(addr + sizeof(MachInst) * 2);
150    else
151        panic("could not find symbol\n");
152
153    intEndEvent = new InterruptEndEvent(&pcEventQueue, "intEndEvent");
154    if (palSymtab->findAddress("rti_to_kern", addr))
155        intEndEvent->schedule(addr + sizeof(MachInst));
156    else
157        panic("could not find symbol\n");
158
159    intEndEvent2 = new InterruptEndEvent(&pcEventQueue, "intEndEvent2");
160    if (palSymtab->findAddress("rti_to_user", addr))
161        intEndEvent2->schedule(addr + sizeof(MachInst));
162    else
163        panic("could not find symbol\n");
164
165
166    intEndEvent3 = new InterruptEndEvent(&pcEventQueue, "intEndEvent3");
167    if (kernelSymtab->findAddress("do_softirq", addr))
168        intEndEvent3->schedule(addr + sizeof(MachInst));
169    else
170        panic("could not find symbol\n");
171}
172
173LinuxSystem::~LinuxSystem()
174{
175#ifdef DEBUG
176    delete kernelPanicEvent;
177#endif
178    delete skipIdeDelay50msEvent;
179    delete skipDelayLoopEvent;
180    delete skipCacheProbeEvent;
181    delete debugPrintkEvent;
182    delete idleStartEvent;
183    delete printThreadEvent;
184    delete intStartEvent;
185    delete intEndEvent;
186    delete intEndEvent2;
187}
188
189
190void
191LinuxSystem::setDelayLoop(ExecContext *xc)
192{
193    Addr addr = 0;
194    if (kernelSymtab->findAddress("loops_per_jiffy", addr)) {
195        Addr paddr = vtophys(physmem, addr);
196
197        uint8_t *loops_per_jiffy =
198            physmem->dma_addr(paddr, sizeof(uint32_t));
199
200        Tick cpuFreq = xc->cpu->getFreq();
201        Tick intrFreq = platform->interrupt_frequency;
202        *(uint32_t *)loops_per_jiffy =
203            (uint32_t)((cpuFreq / intrFreq) * 0.9988);
204    }
205}
206
207BEGIN_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem)
208
209    SimObjectParam<MemoryController *> mem_ctl;
210    SimObjectParam<PhysicalMemory *> physmem;
211
212    Param<string> kernel_code;
213    Param<string> console_code;
214    Param<string> pal_code;
215
216    Param<string> boot_osflags;
217    Param<string> readfile;
218    Param<unsigned int> init_param;
219
220    Param<uint64_t> system_type;
221    Param<uint64_t> system_rev;
222
223    Param<bool> bin;
224    VectorParam<string> binned_fns;
225    Param<bool> bin_int;
226
227END_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem)
228
229BEGIN_INIT_SIM_OBJECT_PARAMS(LinuxSystem)
230
231    INIT_PARAM(mem_ctl, "memory controller"),
232    INIT_PARAM(physmem, "phsyical memory"),
233    INIT_PARAM(kernel_code, "file that contains the kernel code"),
234    INIT_PARAM(console_code, "file that contains the console code"),
235    INIT_PARAM(pal_code, "file that contains palcode"),
236    INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot",
237                    "a"),
238    INIT_PARAM_DFLT(readfile, "file to read startup script from", ""),
239    INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0),
240    INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34),
241    INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10),
242    INIT_PARAM_DFLT(bin, "is this system to be binned", false),
243    INIT_PARAM(binned_fns, "functions to be broken down and binned"),
244    INIT_PARAM_DFLT(bin_int, "is interrupt code binned seperately?", false)
245
246END_INIT_SIM_OBJECT_PARAMS(LinuxSystem)
247
248CREATE_SIM_OBJECT(LinuxSystem)
249{
250    System::Params *p = new System::Params;
251    p->name = getInstanceName();
252    p->memctrl = mem_ctl;
253    p->physmem = physmem;
254    p->kernel_path = kernel_code;
255    p->console_path = console_code;
256    p->palcode = pal_code;
257    p->boot_osflags = boot_osflags;
258    p->init_param = init_param;
259    p->readfile = readfile;
260    p->system_type = system_type;
261    p->system_rev = system_rev;
262    p->bin = bin;
263    p->binned_fns = binned_fns;
264    p->bin_int = bin_int;
265    return new LinuxSystem(p);
266}
267
268REGISTER_SIM_OBJECT("LinuxSystem", LinuxSystem)
269
270