system.cc revision 8775
12686Sksewell@umich.edu/*
22100SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan
32754Sksewell@umich.edu * All rights reserved.
42706Sksewell@umich.edu *
52706Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without
62706Sksewell@umich.edu * modification, are permitted provided that the following conditions are
72706Sksewell@umich.edu * met: redistributions of source code must retain the above copyright
82706Sksewell@umich.edu * notice, this list of conditions and the following disclaimer;
92706Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright
102706Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the
112706Sksewell@umich.edu * documentation and/or other materials provided with the distribution;
122706Sksewell@umich.edu * neither the name of the copyright holders nor the names of its
132706Sksewell@umich.edu * contributors may be used to endorse or promote products derived from
142706Sksewell@umich.edu * this software without specific prior written permission.
152706Sksewell@umich.edu *
162706Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172706Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182706Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192706Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202706Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212706Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222706Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232706Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242706Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252706Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262706Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272706Sksewell@umich.edu *
282706Sksewell@umich.edu * Authors: Ali Saidi
292706Sksewell@umich.edu *          Lisa Hsu
302706Sksewell@umich.edu *          Nathan Binkert
312022SN/A */
322022SN/A
332043SN/A/**
342024SN/A * @file
352024SN/A * This code loads the linux kernel, console, pal and patches certain
362043SN/A * functions.  The symbol tables are loaded so that traces can show
372686Sksewell@umich.edu * the executing function and we can skip functions. Various delay
382024SN/A * loops are skipped and their final values manually computed to speed
392022SN/A * up boot time.
402083SN/A */
412686Sksewell@umich.edu
422101SN/A#include "arch/mips/linux/system.hh"
432043SN/A#include "arch/mips/linux/threadinfo.hh"
442043SN/A#include "arch/mips/idle_event.hh"
452101SN/A#include "arch/mips/system.hh"
462101SN/A#include "arch/vtophys.hh"
472686Sksewell@umich.edu#include "base/loader/symtab.hh"
482686Sksewell@umich.edu#include "cpu/base.hh"
492101SN/A#include "cpu/thread_context.hh"
502101SN/A#include "debug/Thread.hh"
512101SN/A#include "dev/platform.hh"
522046SN/A#include "kern/linux/events.hh"
532686Sksewell@umich.edu#include "kern/linux/printk.hh"
542686Sksewell@umich.edu#include "mem/physical.hh"
552686Sksewell@umich.edu#include "mem/port.hh"
562470SN/A#include "sim/arguments.hh"
572686Sksewell@umich.edu#include "sim/byteswap.hh"
582686Sksewell@umich.edu
592686Sksewell@umich.eduusing namespace std;
602686Sksewell@umich.eduusing namespace MipsISA;
612686Sksewell@umich.eduusing namespace Linux;
622686Sksewell@umich.edu
632470SN/ALinuxMipsSystem::LinuxMipsSystem(Params *p)
642241SN/A    : MipsSystem(p)
652101SN/A{
662495SN/A    Addr addr = 0;
672495SN/A
682495SN/A    /**
692101SN/A     * The symbol swapper_pg_dir marks the beginning of the kernel and
702495SN/A     * the location of bootloader passed arguments
712495SN/A     */
722495SN/A    if (!kernelSymtab->findAddress("swapper_pg_dir", KernelStart)) {
732101SN/A        panic("Could not determine start location of kernel");
742101SN/A    }
752495SN/A
762495SN/A    /**
772495SN/A     * Since we aren't using a bootloader, we have to copy the
782495SN/A     * kernel arguments directly into the kernel's memory.
792495SN/A     */
802495SN/A    virtPort->writeBlob(CommandLine(), (uint8_t*)params()->boot_osflags.c_str(),
812495SN/A                params()->boot_osflags.length()+1);
822495SN/A
832495SN/A    /**
842495SN/A     * find the address of the est_cycle_freq variable and insert it
852495SN/A     * so we don't through the lengthly process of trying to
862495SN/A     * calculated it by using the PIT, RTC, etc.
872495SN/A     */
882101SN/A    if (kernelSymtab->findAddress("est_cycle_freq", addr))
892101SN/A        virtPort->write(addr, (uint64_t)(SimClock::Frequency /
902101SN/A                    p->boot_cpu_frequency));
912101SN/A
922101SN/A    /**
932101SN/A     * EV5 only supports 127 ASNs so we are going to tell the kernel that the
942101SN/A     * paritiuclar EV6 we have only supports 127 asns.
952101SN/A     * @todo At some point we should change ev5.hh and the palcode to support
962101SN/A     * 255 ASNs.
972101SN/A     */
982495SN/A    if (kernelSymtab->findAddress("dp264_mv", addr))
992495SN/A        virtPort->write(addr + 0x18, LittleEndianGuest::htog((uint32_t)127));
1002495SN/A    else
1012495SN/A        panic("could not find dp264_mv\n");
1022495SN/A
1032495SN/A#ifndef NDEBUG
1042495SN/A    kernelPanicEvent = addKernelFuncEvent<BreakPCEvent>("panic");
1052495SN/A    if (!kernelPanicEvent)
1062495SN/A        panic("could not find kernel symbol \'panic\'");
1072495SN/A
1082495SN/A#endif
1092495SN/A
1102495SN/A    /**
1112495SN/A     * Any time ide_delay_50ms, calibarte_delay or
1122495SN/A     * determine_cpu_caches is called just skip the
1132043SN/A     * function. Currently determine_cpu_caches only is used put
1142043SN/A     * information in proc, however if that changes in the future we
1152025SN/A     * will have to fill in the cache size variables appropriately.
1162043SN/A     */
1172686Sksewell@umich.edu
1182686Sksewell@umich.edu    skipIdeDelay50msEvent =
1192123SN/A        addKernelFuncEvent<SkipFuncEvent>("ide_delay_50ms");
1202101SN/A    skipDelayLoopEvent =
1212686Sksewell@umich.edu        addKernelFuncEvent<SkipDelayLoopEvent>("calibrate_delay");
1222686Sksewell@umich.edu    skipCacheProbeEvent =
1232101SN/A        addKernelFuncEvent<SkipFuncEvent>("determine_cpu_caches");
1242042SN/A    debugPrintkEvent = addKernelFuncEvent<DebugPrintkEvent>("dprintk");
1252101SN/A    idleStartEvent = addKernelFuncEvent<IdleStartEvent>("cpu_idle");
1262686Sksewell@umich.edu
1272686Sksewell@umich.edu    // Disable for now as it runs into panic() calls in VPTr methods
1282686Sksewell@umich.edu    // (see sim/vptr.hh).  Once those bugs are fixed, we can
1292686Sksewell@umich.edu    // re-enable, but we should find a better way to turn it on than
1302101SN/A    // using DTRACE(Thread), since looking at a trace flag at tick 0
1312101SN/A    // leads to non-intuitive behavior with --trace-start.
1322042SN/A    if (false && kernelSymtab->findAddress("mips_switch_to", addr)) {
1332101SN/A        printThreadEvent = new PrintThreadInfo(&pcEventQueue, "threadinfo",
1342686Sksewell@umich.edu                                               addr + sizeof(MachInst) * 6);
1352686Sksewell@umich.edu    } else {
1362965Sksewell@umich.edu        printThreadEvent = NULL;
1372965Sksewell@umich.edu    }
1382686Sksewell@umich.edu}
1392101SN/A
1402083SN/ALinuxMipsSystem::~LinuxMipsSystem()
1412686Sksewell@umich.edu{
1422686Sksewell@umich.edu#ifndef NDEBUG
1432101SN/A    delete kernelPanicEvent;
1442043SN/A#endif
1452025SN/A    delete skipIdeDelay50msEvent;
1462043SN/A    delete skipDelayLoopEvent;
1472686Sksewell@umich.edu    delete skipCacheProbeEvent;
1482616SN/A    delete debugPrintkEvent;
1492616SN/A    delete idleStartEvent;
1502616SN/A    delete printThreadEvent;
1512616SN/A}
1522101SN/A
1532083SN/A
1542025SN/Avoid
1552043SN/ALinuxMipsSystem::setDelayLoop(ThreadContext *tc)
1562686Sksewell@umich.edu{
1572686Sksewell@umich.edu    panic("setDelayLoop not implemented.\n");
1582686Sksewell@umich.edu}
1592686Sksewell@umich.edu
1602025SN/A
1612686Sksewell@umich.eduvoid
1622742Sksewell@umich.eduLinuxMipsSystem::SkipDelayLoopEvent::process(ThreadContext *tc)
1632742Sksewell@umich.edu{
1642742Sksewell@umich.edu    SkipFuncEvent::process(tc);
1652742Sksewell@umich.edu    // calculate and set loops_per_jiffy
1662742Sksewell@umich.edu    ((LinuxMipsSystem *)tc->getSystemPtr())->setDelayLoop(tc);
1672742Sksewell@umich.edu}
1682742Sksewell@umich.edu
1692742Sksewell@umich.eduvoid
1702742Sksewell@umich.eduLinuxMipsSystem::PrintThreadInfo::process(ThreadContext *tc)
1712742Sksewell@umich.edu{
1722101SN/A    Linux::ThreadInfo ti(tc);
1732084SN/A
1742025SN/A    DPRINTF(Thread, "Currently Executing Thread %s, pid %d, started at: %d\n",
1752495SN/A            ti.curTaskName(), ti.curTaskPID(), ti.curTaskStart());
1762495SN/A}
1772495SN/A
1782616SN/ALinuxMipsSystem *
1792495SN/ALinuxMipsSystemParams::create()
1802616SN/A{
1812495SN/A    return new LinuxMipsSystem(this);
1822495SN/A}
1832495SN/A