system.cc revision 3565
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"
453565Sgblack@eecs.umich.edu#include "arch/alpha/idle_event.hh"
462212SN/A#include "arch/alpha/linux/system.hh"
472212SN/A#include "arch/alpha/linux/threadinfo.hh"
482158SN/A#include "arch/alpha/system.hh"
491180SN/A#include "base/loader/symtab.hh"
502680Sktlim@umich.edu#include "cpu/thread_context.hh"
511717SN/A#include "cpu/base.hh"
522212SN/A#include "dev/platform.hh"
531885SN/A#include "kern/linux/printk.hh"
542212SN/A#include "kern/linux/events.hh"
552521SN/A#include "mem/physical.hh"
562521SN/A#include "mem/port.hh"
57451SN/A#include "sim/builder.hh"
582036SN/A#include "sim/byteswap.hh"
59451SN/A
60451SN/Ausing namespace std;
612212SN/Ausing namespace AlphaISA;
622212SN/Ausing namespace Linux;
63451SN/A
642212SN/ALinuxAlphaSystem::LinuxAlphaSystem(Params *p)
652158SN/A    : AlphaSystem(p)
66451SN/A{
67451SN/A    Addr addr = 0;
681855SN/A
691855SN/A    /**
701855SN/A     * The symbol swapper_pg_dir marks the beginning of the kernel and
711855SN/A     * the location of bootloader passed arguments
721855SN/A     */
731855SN/A    if (!kernelSymtab->findAddress("swapper_pg_dir", KernelStart)) {
741855SN/A        panic("Could not determine start location of kernel");
751855SN/A    }
761855SN/A
771855SN/A    /**
781855SN/A     * Since we aren't using a bootloader, we have to copy the
791855SN/A     * kernel arguments directly into the kernel's memory.
801855SN/A     */
812521SN/A    virtPort.writeBlob(CommandLine(), (uint8_t*)params()->boot_osflags.c_str(),
822548SN/A                params()->boot_osflags.length()+1);
83836SN/A
84885SN/A    /**
851070SN/A     * find the address of the est_cycle_freq variable and insert it
861070SN/A     * so we don't through the lengthly process of trying to
871070SN/A     * calculated it by using the PIT, RTC, etc.
88885SN/A     */
892521SN/A    if (kernelSymtab->findAddress("est_cycle_freq", addr))
902521SN/A        virtPort.write(addr, (uint64_t)(Clock::Frequency /
912521SN/A                    p->boot_cpu_frequency));
92451SN/A
93836SN/A
94885SN/A    /**
95943SN/A     * EV5 only supports 127 ASNs so we are going to tell the kernel that the
96943SN/A     * paritiuclar EV6 we have only supports 127 asns.
97943SN/A     * @todo At some point we should change ev5.hh and the palcode to support
98943SN/A     * 255 ASNs.
99943SN/A     */
1002521SN/A    if (kernelSymtab->findAddress("dp264_mv", addr))
1012521SN/A        virtPort.write(addr + 0x18, LittleEndianGuest::htog((uint32_t)127));
1022521SN/A    else
1031070SN/A        panic("could not find dp264_mv\n");
104943SN/A
1051492SN/A#ifndef NDEBUG
1061885SN/A    kernelPanicEvent = addKernelFuncEvent<BreakPCEvent>("panic");
1071885SN/A    if (!kernelPanicEvent)
108451SN/A        panic("could not find kernel symbol \'panic\'");
1091885SN/A
1101646SN/A#if 0
1111885SN/A    kernelDieEvent = addKernelFuncEvent<BreakPCEvent>("die_if_kernel");
1121885SN/A    if (!kernelDieEvent)
1131492SN/A        panic("could not find kernel symbol \'die_if_kernel\'");
1141646SN/A#endif
1151492SN/A
116860SN/A#endif
117451SN/A
118885SN/A    /**
1191895SN/A     * Any time ide_delay_50ms, calibarte_delay or
1201070SN/A     * determine_cpu_caches is called just skip the
1211070SN/A     * function. Currently determine_cpu_caches only is used put
1221070SN/A     * information in proc, however if that changes in the future we
1231070SN/A     * will have to fill in the cache size variables appropriately.
124885SN/A     */
125848SN/A
1261885SN/A    skipIdeDelay50msEvent =
1271885SN/A        addKernelFuncEvent<SkipFuncEvent>("ide_delay_50ms");
1281885SN/A    skipDelayLoopEvent =
1291885SN/A        addKernelFuncEvent<SkipDelayLoopEvent>("calibrate_delay");
1301885SN/A    skipCacheProbeEvent =
1311885SN/A        addKernelFuncEvent<SkipFuncEvent>("determine_cpu_caches");
1321885SN/A    debugPrintkEvent = addKernelFuncEvent<DebugPrintkEvent>("dprintk");
1331885SN/A    idleStartEvent = addKernelFuncEvent<IdleStartEvent>("cpu_idle");
1341885SN/A
1351885SN/A    if (kernelSymtab->findAddress("alpha_switch_to", addr) && DTRACE(Thread)) {
1361885SN/A        printThreadEvent = new PrintThreadInfo(&pcEventQueue, "threadinfo",
1371885SN/A                                               addr + sizeof(MachInst) * 6);
1381885SN/A    } else {
1391885SN/A        printThreadEvent = NULL;
1401657SN/A    }
141451SN/A}
142451SN/A
1432212SN/ALinuxAlphaSystem::~LinuxAlphaSystem()
144451SN/A{
1451492SN/A#ifndef NDEBUG
146451SN/A    delete kernelPanicEvent;
1471070SN/A#endif
148869SN/A    delete skipIdeDelay50msEvent;
149869SN/A    delete skipDelayLoopEvent;
150869SN/A    delete skipCacheProbeEvent;
1511070SN/A    delete debugPrintkEvent;
1521070SN/A    delete idleStartEvent;
1531082SN/A    delete printThreadEvent;
154451SN/A}
155451SN/A
156882SN/A
157803SN/Avoid
1582680Sktlim@umich.eduLinuxAlphaSystem::setDelayLoop(ThreadContext *tc)
159803SN/A{
160803SN/A    Addr addr = 0;
161803SN/A    if (kernelSymtab->findAddress("loops_per_jiffy", addr)) {
1622680Sktlim@umich.edu        Tick cpuFreq = tc->getCpuPtr()->frequency();
1631634SN/A        Tick intrFreq = platform->intrFrequency();
1642684Ssaidi@eecs.umich.edu        VirtualPort *vp;
1652684Ssaidi@eecs.umich.edu
1662684Ssaidi@eecs.umich.edu        vp = tc->getVirtPort();
1672684Ssaidi@eecs.umich.edu        vp->writeHtoG(addr, (uint32_t)((cpuFreq / intrFreq) * 0.9988));
1682684Ssaidi@eecs.umich.edu        tc->delVirtPort(vp);
169803SN/A    }
170803SN/A}
171803SN/A
1722212SN/A
1731885SN/Avoid
1742680Sktlim@umich.eduLinuxAlphaSystem::SkipDelayLoopEvent::process(ThreadContext *tc)
1751885SN/A{
1762680Sktlim@umich.edu    SkipFuncEvent::process(tc);
1771885SN/A    // calculate and set loops_per_jiffy
1782680Sktlim@umich.edu    ((LinuxAlphaSystem *)tc->getSystemPtr())->setDelayLoop(tc);
1791885SN/A}
1801885SN/A
1811885SN/Avoid
1822680Sktlim@umich.eduLinuxAlphaSystem::PrintThreadInfo::process(ThreadContext *tc)
1831885SN/A{
1842680Sktlim@umich.edu    Linux::ThreadInfo ti(tc);
1851885SN/A
1861885SN/A    DPRINTF(Thread, "Currently Executing Thread %s, pid %d, started at: %d\n",
1871885SN/A            ti.curTaskName(), ti.curTaskPID(), ti.curTaskStart());
1881885SN/A}
1891885SN/A
1901885SN/A
1912212SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(LinuxAlphaSystem)
192451SN/A
1931634SN/A    Param<Tick> boot_cpu_frequency;
194451SN/A    SimObjectParam<PhysicalMemory *> physmem;
1952902Ssaidi@eecs.umich.edu    SimpleEnumParam<System::MemoryMode> mem_mode;
196451SN/A
1971310SN/A    Param<string> kernel;
1981310SN/A    Param<string> console;
1991310SN/A    Param<string> pal;
2001070SN/A
201451SN/A    Param<string> boot_osflags;
2021070SN/A    Param<string> readfile;
2032358SN/A    Param<string> symbolfile;
2041070SN/A    Param<unsigned int> init_param;
2051070SN/A
2061070SN/A    Param<uint64_t> system_type;
2071070SN/A    Param<uint64_t> system_rev;
2081070SN/A
2092212SN/AEND_DECLARE_SIM_OBJECT_PARAMS(LinuxAlphaSystem)
210451SN/A
2112212SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(LinuxAlphaSystem)
212451SN/A
2131634SN/A    INIT_PARAM(boot_cpu_frequency, "Frequency of the boot CPU"),
214451SN/A    INIT_PARAM(physmem, "phsyical memory"),
2152902Ssaidi@eecs.umich.edu    INIT_ENUM_PARAM(mem_mode, "Memory Mode, (1=atomic, 2=timing)",
2162902Ssaidi@eecs.umich.edu            System::MemoryModeStrings),
2171310SN/A    INIT_PARAM(kernel, "file that contains the kernel code"),
2181310SN/A    INIT_PARAM(console, "file that contains the console code"),
2191310SN/A    INIT_PARAM(pal, "file that contains palcode"),
220451SN/A    INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot",
2211070SN/A                    "a"),
2221070SN/A    INIT_PARAM_DFLT(readfile, "file to read startup script from", ""),
2232358SN/A    INIT_PARAM_DFLT(symbolfile, "file to read symbols from", ""),
2241070SN/A    INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0),
2251070SN/A    INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34),
2262343SN/A    INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10)
227451SN/A
2282212SN/AEND_INIT_SIM_OBJECT_PARAMS(LinuxAlphaSystem)
229451SN/A
2302212SN/ACREATE_SIM_OBJECT(LinuxAlphaSystem)
231451SN/A{
2322158SN/A    AlphaSystem::Params *p = new AlphaSystem::Params;
2331070SN/A    p->name = getInstanceName();
2341634SN/A    p->boot_cpu_frequency = boot_cpu_frequency;
2351070SN/A    p->physmem = physmem;
2362902Ssaidi@eecs.umich.edu    p->mem_mode = mem_mode;
2371310SN/A    p->kernel_path = kernel;
2381310SN/A    p->console_path = console;
2391310SN/A    p->palcode = pal;
2401070SN/A    p->boot_osflags = boot_osflags;
2411070SN/A    p->init_param = init_param;
2421070SN/A    p->readfile = readfile;
2432358SN/A    p->symbolfile = symbolfile;
2441070SN/A    p->system_type = system_type;
2451070SN/A    p->system_rev = system_rev;
2462212SN/A    return new LinuxAlphaSystem(p);
247451SN/A}
248451SN/A
2492212SN/AREGISTER_SIM_OBJECT("LinuxAlphaSystem", LinuxAlphaSystem)
2501070SN/A
251