system.cc revision 5268
15222Sksewell@umich.edu/*
25268Sksewell@umich.edu * Copyright (c) 2004-2006 The Regents of The University of Michigan
35254Sksewell@umich.edu * All rights reserved.
45222Sksewell@umich.edu *
55254Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without
65254Sksewell@umich.edu * modification, are permitted provided that the following conditions are
75254Sksewell@umich.edu * met: redistributions of source code must retain the above copyright
85254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer;
95254Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright
105254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the
115254Sksewell@umich.edu * documentation and/or other materials provided with the distribution;
125254Sksewell@umich.edu * neither the name of the copyright holders nor the names of its
135254Sksewell@umich.edu * contributors may be used to endorse or promote products derived from
145254Sksewell@umich.edu * this software without specific prior written permission.
155222Sksewell@umich.edu *
165254Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175254Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185254Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195254Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205254Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215254Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225254Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235254Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245254Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255254Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265254Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275222Sksewell@umich.edu *
285254Sksewell@umich.edu * Authors: Ali Saidi
295254Sksewell@umich.edu *          Lisa Hsu
305254Sksewell@umich.edu *          Nathan Binkert
315222Sksewell@umich.edu */
325222Sksewell@umich.edu
335222Sksewell@umich.edu/**
345222Sksewell@umich.edu * @file
355222Sksewell@umich.edu * This code loads the linux kernel, console, pal and patches certain
365222Sksewell@umich.edu * functions.  The symbol tables are loaded so that traces can show
375222Sksewell@umich.edu * the executing function and we can skip functions. Various delay
385222Sksewell@umich.edu * loops are skipped and their final values manually computed to speed
395222Sksewell@umich.edu * up boot time.
405222Sksewell@umich.edu */
415222Sksewell@umich.edu
425222Sksewell@umich.edu#include "arch/vtophys.hh"
435222Sksewell@umich.edu#include "arch/mips/idle_event.hh"
445222Sksewell@umich.edu#include "arch/mips/linux/system.hh"
455222Sksewell@umich.edu#include "arch/mips/linux/threadinfo.hh"
465222Sksewell@umich.edu#include "arch/mips/system.hh"
475222Sksewell@umich.edu#include "base/loader/symtab.hh"
485222Sksewell@umich.edu#include "cpu/thread_context.hh"
495222Sksewell@umich.edu#include "cpu/base.hh"
505222Sksewell@umich.edu#include "dev/platform.hh"
515222Sksewell@umich.edu#include "kern/linux/printk.hh"
525222Sksewell@umich.edu#include "kern/linux/events.hh"
535222Sksewell@umich.edu#include "mem/physical.hh"
545222Sksewell@umich.edu#include "mem/port.hh"
555222Sksewell@umich.edu#include "sim/arguments.hh"
565222Sksewell@umich.edu#include "sim/byteswap.hh"
575222Sksewell@umich.edu
585222Sksewell@umich.eduusing namespace std;
595222Sksewell@umich.eduusing namespace MipsISA;
605222Sksewell@umich.eduusing namespace Linux;
615222Sksewell@umich.edu
625222Sksewell@umich.eduLinuxMipsSystem::LinuxMipsSystem(Params *p)
635222Sksewell@umich.edu    : MipsSystem(p)
645222Sksewell@umich.edu{
655222Sksewell@umich.edu    Addr addr = 0;
665222Sksewell@umich.edu
675222Sksewell@umich.edu    /**
685222Sksewell@umich.edu     * The symbol swapper_pg_dir marks the beginning of the kernel and
695222Sksewell@umich.edu     * the location of bootloader passed arguments
705222Sksewell@umich.edu     */
715222Sksewell@umich.edu    if (!kernelSymtab->findAddress("swapper_pg_dir", KernelStart)) {
725222Sksewell@umich.edu        panic("Could not determine start location of kernel");
735222Sksewell@umich.edu    }
745222Sksewell@umich.edu
755222Sksewell@umich.edu    /**
765222Sksewell@umich.edu     * Since we aren't using a bootloader, we have to copy the
775222Sksewell@umich.edu     * kernel arguments directly into the kernel's memory.
785222Sksewell@umich.edu     */
795222Sksewell@umich.edu    virtPort.writeBlob(CommandLine(), (uint8_t*)params()->boot_osflags.c_str(),
805222Sksewell@umich.edu                params()->boot_osflags.length()+1);
815222Sksewell@umich.edu
825222Sksewell@umich.edu    /**
835222Sksewell@umich.edu     * find the address of the est_cycle_freq variable and insert it
845222Sksewell@umich.edu     * so we don't through the lengthly process of trying to
855222Sksewell@umich.edu     * calculated it by using the PIT, RTC, etc.
865222Sksewell@umich.edu     */
875222Sksewell@umich.edu    if (kernelSymtab->findAddress("est_cycle_freq", addr))
885222Sksewell@umich.edu        virtPort.write(addr, (uint64_t)(Clock::Frequency /
895222Sksewell@umich.edu                    p->boot_cpu_frequency));
905222Sksewell@umich.edu
915222Sksewell@umich.edu
925222Sksewell@umich.edu    /**
935222Sksewell@umich.edu     * EV5 only supports 127 ASNs so we are going to tell the kernel that the
945222Sksewell@umich.edu     * paritiuclar EV6 we have only supports 127 asns.
955222Sksewell@umich.edu     * @todo At some point we should change ev5.hh and the palcode to support
965222Sksewell@umich.edu     * 255 ASNs.
975222Sksewell@umich.edu     */
985222Sksewell@umich.edu    if (kernelSymtab->findAddress("dp264_mv", addr))
995222Sksewell@umich.edu        virtPort.write(addr + 0x18, LittleEndianGuest::htog((uint32_t)127));
1005222Sksewell@umich.edu    else
1015222Sksewell@umich.edu        panic("could not find dp264_mv\n");
1025222Sksewell@umich.edu
1035222Sksewell@umich.edu#ifndef NDEBUG
1045222Sksewell@umich.edu    kernelPanicEvent = addKernelFuncEvent<BreakPCEvent>("panic");
1055222Sksewell@umich.edu    if (!kernelPanicEvent)
1065222Sksewell@umich.edu        panic("could not find kernel symbol \'panic\'");
1075222Sksewell@umich.edu
1085222Sksewell@umich.edu#if 0
1095222Sksewell@umich.edu    kernelDieEvent = addKernelFuncEvent<BreakPCEvent>("die_if_kernel");
1105222Sksewell@umich.edu    if (!kernelDieEvent)
1115222Sksewell@umich.edu        panic("could not find kernel symbol \'die_if_kernel\'");
1125222Sksewell@umich.edu#endif
1135222Sksewell@umich.edu
1145222Sksewell@umich.edu#endif
1155222Sksewell@umich.edu
1165222Sksewell@umich.edu    /**
1175222Sksewell@umich.edu     * Any time ide_delay_50ms, calibarte_delay or
1185222Sksewell@umich.edu     * determine_cpu_caches is called just skip the
1195222Sksewell@umich.edu     * function. Currently determine_cpu_caches only is used put
1205222Sksewell@umich.edu     * information in proc, however if that changes in the future we
1215222Sksewell@umich.edu     * will have to fill in the cache size variables appropriately.
1225222Sksewell@umich.edu     */
1235222Sksewell@umich.edu
1245222Sksewell@umich.edu    skipIdeDelay50msEvent =
1255222Sksewell@umich.edu        addKernelFuncEvent<SkipFuncEvent>("ide_delay_50ms");
1265222Sksewell@umich.edu    skipDelayLoopEvent =
1275222Sksewell@umich.edu        addKernelFuncEvent<SkipDelayLoopEvent>("calibrate_delay");
1285222Sksewell@umich.edu    skipCacheProbeEvent =
1295222Sksewell@umich.edu        addKernelFuncEvent<SkipFuncEvent>("determine_cpu_caches");
1305222Sksewell@umich.edu    debugPrintkEvent = addKernelFuncEvent<DebugPrintkEvent>("dprintk");
1315222Sksewell@umich.edu    idleStartEvent = addKernelFuncEvent<IdleStartEvent>("cpu_idle");
1325222Sksewell@umich.edu
1335222Sksewell@umich.edu    // Disable for now as it runs into panic() calls in VPTr methods
1345222Sksewell@umich.edu    // (see sim/vptr.hh).  Once those bugs are fixed, we can
1355222Sksewell@umich.edu    // re-enable, but we should find a better way to turn it on than
1365222Sksewell@umich.edu    // using DTRACE(Thread), since looking at a trace flag at tick 0
1375222Sksewell@umich.edu    // leads to non-intuitive behavior with --trace-start.
1385222Sksewell@umich.edu    if (false && kernelSymtab->findAddress("mips_switch_to", addr)) {
1395222Sksewell@umich.edu        printThreadEvent = new PrintThreadInfo(&pcEventQueue, "threadinfo",
1405222Sksewell@umich.edu                                               addr + sizeof(MachInst) * 6);
1415222Sksewell@umich.edu    } else {
1425222Sksewell@umich.edu        printThreadEvent = NULL;
1435222Sksewell@umich.edu    }
1445222Sksewell@umich.edu}
1455222Sksewell@umich.edu
1465222Sksewell@umich.eduLinuxMipsSystem::~LinuxMipsSystem()
1475222Sksewell@umich.edu{
1485222Sksewell@umich.edu#ifndef NDEBUG
1495222Sksewell@umich.edu    delete kernelPanicEvent;
1505222Sksewell@umich.edu#endif
1515222Sksewell@umich.edu    delete skipIdeDelay50msEvent;
1525222Sksewell@umich.edu    delete skipDelayLoopEvent;
1535222Sksewell@umich.edu    delete skipCacheProbeEvent;
1545222Sksewell@umich.edu    delete debugPrintkEvent;
1555222Sksewell@umich.edu    delete idleStartEvent;
1565222Sksewell@umich.edu    delete printThreadEvent;
1575222Sksewell@umich.edu}
1585222Sksewell@umich.edu
1595222Sksewell@umich.edu
1605222Sksewell@umich.eduvoid
1615222Sksewell@umich.eduLinuxMipsSystem::setDelayLoop(ThreadContext *tc)
1625222Sksewell@umich.edu{
1635222Sksewell@umich.edu    Addr addr = 0;
1645222Sksewell@umich.edu    if (kernelSymtab->findAddress("loops_per_jiffy", addr)) {
1655222Sksewell@umich.edu        Tick cpuFreq = tc->getCpuPtr()->frequency();
1665222Sksewell@umich.edu        Tick intrFreq = platform->intrFrequency();
1675222Sksewell@umich.edu        VirtualPort *vp;
1685222Sksewell@umich.edu
1695222Sksewell@umich.edu        vp = tc->getVirtPort();
1705222Sksewell@umich.edu        vp->writeHtoG(addr, (uint32_t)((cpuFreq / intrFreq) * 0.9988));
1715222Sksewell@umich.edu        tc->delVirtPort(vp);
1725222Sksewell@umich.edu    }
1735222Sksewell@umich.edu}
1745222Sksewell@umich.edu
1755222Sksewell@umich.edu
1765222Sksewell@umich.eduvoid
1775222Sksewell@umich.eduLinuxMipsSystem::SkipDelayLoopEvent::process(ThreadContext *tc)
1785222Sksewell@umich.edu{
1795222Sksewell@umich.edu    SkipFuncEvent::process(tc);
1805222Sksewell@umich.edu    // calculate and set loops_per_jiffy
1815222Sksewell@umich.edu    ((LinuxMipsSystem *)tc->getSystemPtr())->setDelayLoop(tc);
1825222Sksewell@umich.edu}
1835222Sksewell@umich.edu
1845222Sksewell@umich.eduvoid
1855222Sksewell@umich.eduLinuxMipsSystem::PrintThreadInfo::process(ThreadContext *tc)
1865222Sksewell@umich.edu{
1875222Sksewell@umich.edu    Linux::ThreadInfo ti(tc);
1885222Sksewell@umich.edu
1895222Sksewell@umich.edu    DPRINTF(Thread, "Currently Executing Thread %s, pid %d, started at: %d\n",
1905222Sksewell@umich.edu            ti.curTaskName(), ti.curTaskPID(), ti.curTaskStart());
1915222Sksewell@umich.edu}
1925222Sksewell@umich.edu
1935222Sksewell@umich.eduLinuxMipsSystem *
1945222Sksewell@umich.eduLinuxMipsSystemParams::create()
1955222Sksewell@umich.edu{
1965222Sksewell@umich.edu    return new LinuxMipsSystem(this);
1975222Sksewell@umich.edu}
198