system.cc revision 2665
1451SN/A/*
21762SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
3451SN/A * All rights reserved.
4451SN/A *
5451SN/A * Redistribution and use in source and binary forms, with or without
6451SN/A * modification, are permitted provided that the following conditions are
7451SN/A * met: redistributions of source code must retain the above copyright
8451SN/A * notice, this list of conditions and the following disclaimer;
9451SN/A * redistributions in binary form must reproduce the above copyright
10451SN/A * notice, this list of conditions and the following disclaimer in the
11451SN/A * documentation and/or other materials provided with the distribution;
12451SN/A * neither the name of the copyright holders nor the names of its
13451SN/A * contributors may be used to endorse or promote products derived from
14451SN/A * this software without specific prior written permission.
15451SN/A *
16451SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17451SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18451SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19451SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20451SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21451SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22451SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23451SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24451SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25451SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26451SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Ali Saidi
292665Ssaidi@eecs.umich.edu *          Lisa Hsu
302665Ssaidi@eecs.umich.edu *          Nathan Binkert
312665Ssaidi@eecs.umich.edu *          Steve Reinhardt
32451SN/A */
33451SN/A
34885SN/A/**
35885SN/A * @file
361040SN/A * This code loads the linux kernel, console, pal and patches certain
371040SN/A * functions.  The symbol tables are loaded so that traces can show
381040SN/A * the executing function and we can skip functions. Various delay
391040SN/A * loops are skipped and their final values manually computed to speed
401040SN/A * up boot time.
41885SN/A */
42885SN/A
432212SN/A#include "arch/arguments.hh"
442212SN/A#include "arch/vtophys.hh"
452212SN/A#include "arch/alpha/linux/system.hh"
462212SN/A#include "arch/alpha/linux/threadinfo.hh"
472158SN/A#include "arch/alpha/system.hh"
481180SN/A#include "base/loader/symtab.hh"
49451SN/A#include "cpu/exec_context.hh"
501717SN/A#include "cpu/base.hh"
512212SN/A#include "dev/platform.hh"
521885SN/A#include "kern/linux/printk.hh"
532212SN/A#include "kern/linux/events.hh"
542521SN/A#include "mem/physical.hh"
552521SN/A#include "mem/port.hh"
56451SN/A#include "sim/builder.hh"
572036SN/A#include "sim/byteswap.hh"
58451SN/A
59451SN/Ausing namespace std;
602212SN/Ausing namespace AlphaISA;
612212SN/Ausing namespace Linux;
62451SN/A
632212SN/ALinuxAlphaSystem::LinuxAlphaSystem(Params *p)
642158SN/A    : AlphaSystem(p)
65451SN/A{
66451SN/A    Addr addr = 0;
671855SN/A
681855SN/A    /**
691855SN/A     * The symbol swapper_pg_dir marks the beginning of the kernel and
701855SN/A     * the location of bootloader passed arguments
711855SN/A     */
721855SN/A    if (!kernelSymtab->findAddress("swapper_pg_dir", KernelStart)) {
731855SN/A        panic("Could not determine start location of kernel");
741855SN/A    }
751855SN/A
761855SN/A    /**
771855SN/A     * Since we aren't using a bootloader, we have to copy the
781855SN/A     * kernel arguments directly into the kernel's memory.
791855SN/A     */
802521SN/A    virtPort.writeBlob(CommandLine(), (uint8_t*)params()->boot_osflags.c_str(),
812548SN/A                params()->boot_osflags.length()+1);
82836SN/A
83885SN/A    /**
841070SN/A     * find the address of the est_cycle_freq variable and insert it
851070SN/A     * so we don't through the lengthly process of trying to
861070SN/A     * calculated it by using the PIT, RTC, etc.
87885SN/A     */
882521SN/A    if (kernelSymtab->findAddress("est_cycle_freq", addr))
892521SN/A        virtPort.write(addr, (uint64_t)(Clock::Frequency /
902521SN/A                    p->boot_cpu_frequency));
91451SN/A
92836SN/A
93885SN/A    /**
94943SN/A     * EV5 only supports 127 ASNs so we are going to tell the kernel that the
95943SN/A     * paritiuclar EV6 we have only supports 127 asns.
96943SN/A     * @todo At some point we should change ev5.hh and the palcode to support
97943SN/A     * 255 ASNs.
98943SN/A     */
992521SN/A    if (kernelSymtab->findAddress("dp264_mv", addr))
1002521SN/A        virtPort.write(addr + 0x18, LittleEndianGuest::htog((uint32_t)127));
1012521SN/A    else
1021070SN/A        panic("could not find dp264_mv\n");
103943SN/A
1041492SN/A#ifndef NDEBUG
1051885SN/A    kernelPanicEvent = addKernelFuncEvent<BreakPCEvent>("panic");
1061885SN/A    if (!kernelPanicEvent)
107451SN/A        panic("could not find kernel symbol \'panic\'");
1081885SN/A
1091646SN/A#if 0
1101885SN/A    kernelDieEvent = addKernelFuncEvent<BreakPCEvent>("die_if_kernel");
1111885SN/A    if (!kernelDieEvent)
1121492SN/A        panic("could not find kernel symbol \'die_if_kernel\'");
1131646SN/A#endif
1141492SN/A
115860SN/A#endif
116451SN/A
117885SN/A    /**
1181895SN/A     * Any time ide_delay_50ms, calibarte_delay or
1191070SN/A     * determine_cpu_caches is called just skip the
1201070SN/A     * function. Currently determine_cpu_caches only is used put
1211070SN/A     * information in proc, however if that changes in the future we
1221070SN/A     * will have to fill in the cache size variables appropriately.
123885SN/A     */
124848SN/A
1251885SN/A    skipIdeDelay50msEvent =
1261885SN/A        addKernelFuncEvent<SkipFuncEvent>("ide_delay_50ms");
1271885SN/A    skipDelayLoopEvent =
1281885SN/A        addKernelFuncEvent<SkipDelayLoopEvent>("calibrate_delay");
1291885SN/A    skipCacheProbeEvent =
1301885SN/A        addKernelFuncEvent<SkipFuncEvent>("determine_cpu_caches");
1311885SN/A    debugPrintkEvent = addKernelFuncEvent<DebugPrintkEvent>("dprintk");
1321885SN/A    idleStartEvent = addKernelFuncEvent<IdleStartEvent>("cpu_idle");
1331885SN/A
1341885SN/A    if (kernelSymtab->findAddress("alpha_switch_to", addr) && DTRACE(Thread)) {
1351885SN/A        printThreadEvent = new PrintThreadInfo(&pcEventQueue, "threadinfo",
1361885SN/A                                               addr + sizeof(MachInst) * 6);
1371885SN/A    } else {
1381885SN/A        printThreadEvent = NULL;
1391657SN/A    }
140803SN/A
1412158SN/A    if (params()->bin_int) {
1421885SN/A        intStartEvent = addPalFuncEvent<InterruptStartEvent>("sys_int_21");
1431885SN/A        if (!intStartEvent)
1441088SN/A            panic("could not find symbol: sys_int_21\n");
1451084SN/A
1461885SN/A        intEndEvent = addPalFuncEvent<InterruptEndEvent>("rti_to_kern");
1471885SN/A        if (!intEndEvent)
1481088SN/A            panic("could not find symbol: rti_to_kern\n");
1491084SN/A
1501885SN/A        intEndEvent2 = addPalFuncEvent<InterruptEndEvent>("rti_to_user");
1511885SN/A        if (!intEndEvent2)
1521088SN/A            panic("could not find symbol: rti_to_user\n");
1531084SN/A
1541885SN/A        intEndEvent3 = addKernelFuncEvent<InterruptEndEvent>("do_softirq");
1551885SN/A        if (!intEndEvent3)
1561088SN/A            panic("could not find symbol: do_softirq\n");
1571088SN/A    }
158451SN/A}
159451SN/A
1602212SN/ALinuxAlphaSystem::~LinuxAlphaSystem()
161451SN/A{
1621492SN/A#ifndef NDEBUG
163451SN/A    delete kernelPanicEvent;
1641070SN/A#endif
165869SN/A    delete skipIdeDelay50msEvent;
166869SN/A    delete skipDelayLoopEvent;
167869SN/A    delete skipCacheProbeEvent;
1681070SN/A    delete debugPrintkEvent;
1691070SN/A    delete idleStartEvent;
1701082SN/A    delete printThreadEvent;
1711082SN/A    delete intStartEvent;
1721084SN/A    delete intEndEvent;
1731084SN/A    delete intEndEvent2;
174451SN/A}
175451SN/A
176882SN/A
177803SN/Avoid
1782212SN/ALinuxAlphaSystem::setDelayLoop(ExecContext *xc)
179803SN/A{
180803SN/A    Addr addr = 0;
181803SN/A    if (kernelSymtab->findAddress("loops_per_jiffy", addr)) {
1822190SN/A        Tick cpuFreq = xc->getCpuPtr()->frequency();
1831634SN/A        Tick intrFreq = platform->intrFrequency();
1842521SN/A        xc->getVirtPort(xc)->write(addr,
1852521SN/A                (uint32_t)((cpuFreq / intrFreq) * 0.9988));
186803SN/A    }
187803SN/A}
188803SN/A
1892212SN/A
1901885SN/Avoid
1912212SN/ALinuxAlphaSystem::SkipDelayLoopEvent::process(ExecContext *xc)
1921885SN/A{
1931885SN/A    SkipFuncEvent::process(xc);
1941885SN/A    // calculate and set loops_per_jiffy
1952234SN/A    ((LinuxAlphaSystem *)xc->getSystemPtr())->setDelayLoop(xc);
1961885SN/A}
1971885SN/A
1981885SN/Avoid
1992212SN/ALinuxAlphaSystem::PrintThreadInfo::process(ExecContext *xc)
2001885SN/A{
2011885SN/A    Linux::ThreadInfo ti(xc);
2021885SN/A
2031885SN/A    DPRINTF(Thread, "Currently Executing Thread %s, pid %d, started at: %d\n",
2041885SN/A            ti.curTaskName(), ti.curTaskPID(), ti.curTaskStart());
2051885SN/A}
2061885SN/A
2071885SN/A
2082212SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(LinuxAlphaSystem)
209451SN/A
2101634SN/A    Param<Tick> boot_cpu_frequency;
211451SN/A    SimObjectParam<PhysicalMemory *> physmem;
212451SN/A
2131310SN/A    Param<string> kernel;
2141310SN/A    Param<string> console;
2151310SN/A    Param<string> pal;
2161070SN/A
217451SN/A    Param<string> boot_osflags;
2181070SN/A    Param<string> readfile;
2191070SN/A    Param<unsigned int> init_param;
2201070SN/A
2211070SN/A    Param<uint64_t> system_type;
2221070SN/A    Param<uint64_t> system_rev;
2231070SN/A
2241070SN/A    Param<bool> bin;
225869SN/A    VectorParam<string> binned_fns;
2261082SN/A    Param<bool> bin_int;
227451SN/A
2282212SN/AEND_DECLARE_SIM_OBJECT_PARAMS(LinuxAlphaSystem)
229451SN/A
2302212SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(LinuxAlphaSystem)
231451SN/A
2321634SN/A    INIT_PARAM(boot_cpu_frequency, "Frequency of the boot CPU"),
233451SN/A    INIT_PARAM(physmem, "phsyical memory"),
2341310SN/A    INIT_PARAM(kernel, "file that contains the kernel code"),
2351310SN/A    INIT_PARAM(console, "file that contains the console code"),
2361310SN/A    INIT_PARAM(pal, "file that contains palcode"),
237451SN/A    INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot",
2381070SN/A                    "a"),
2391070SN/A    INIT_PARAM_DFLT(readfile, "file to read startup script from", ""),
2401070SN/A    INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0),
2411070SN/A    INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34),
2421070SN/A    INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10),
2431070SN/A    INIT_PARAM_DFLT(bin, "is this system to be binned", false),
2441082SN/A    INIT_PARAM(binned_fns, "functions to be broken down and binned"),
2451161SN/A    INIT_PARAM_DFLT(bin_int, "is interrupt code binned seperately?", true)
246451SN/A
2472212SN/AEND_INIT_SIM_OBJECT_PARAMS(LinuxAlphaSystem)
248451SN/A
2492212SN/ACREATE_SIM_OBJECT(LinuxAlphaSystem)
250451SN/A{
2512158SN/A    AlphaSystem::Params *p = new AlphaSystem::Params;
2521070SN/A    p->name = getInstanceName();
2531634SN/A    p->boot_cpu_frequency = boot_cpu_frequency;
2541070SN/A    p->physmem = physmem;
2551310SN/A    p->kernel_path = kernel;
2561310SN/A    p->console_path = console;
2571310SN/A    p->palcode = pal;
2581070SN/A    p->boot_osflags = boot_osflags;
2591070SN/A    p->init_param = init_param;
2601070SN/A    p->readfile = readfile;
2611070SN/A    p->system_type = system_type;
2621070SN/A    p->system_rev = system_rev;
2631070SN/A    p->bin = bin;
2641070SN/A    p->binned_fns = binned_fns;
2651082SN/A    p->bin_int = bin_int;
2662212SN/A    return new LinuxAlphaSystem(p);
267451SN/A}
268451SN/A
2692212SN/AREGISTER_SIM_OBJECT("LinuxAlphaSystem", LinuxAlphaSystem)
2701070SN/A
271