system.cc revision 5254
15222Sksewell@umich.edu/* 25254Sksewell@umich.edu * Copyright (c) 2007 MIPS Technologies, Inc. 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 315254Sksewell@umich.edu * Steve Reinhardt 325222Sksewell@umich.edu */ 335222Sksewell@umich.edu 345222Sksewell@umich.edu/** 355222Sksewell@umich.edu * @file 365222Sksewell@umich.edu * This code loads the linux kernel, console, pal and patches certain 375222Sksewell@umich.edu * functions. The symbol tables are loaded so that traces can show 385222Sksewell@umich.edu * the executing function and we can skip functions. Various delay 395222Sksewell@umich.edu * loops are skipped and their final values manually computed to speed 405222Sksewell@umich.edu * up boot time. 415222Sksewell@umich.edu */ 425222Sksewell@umich.edu 435222Sksewell@umich.edu#include "arch/vtophys.hh" 445222Sksewell@umich.edu#include "arch/mips/idle_event.hh" 455222Sksewell@umich.edu#include "arch/mips/linux/system.hh" 465222Sksewell@umich.edu#include "arch/mips/linux/threadinfo.hh" 475222Sksewell@umich.edu#include "arch/mips/system.hh" 485222Sksewell@umich.edu#include "base/loader/symtab.hh" 495222Sksewell@umich.edu#include "cpu/thread_context.hh" 505222Sksewell@umich.edu#include "cpu/base.hh" 515222Sksewell@umich.edu#include "dev/platform.hh" 525222Sksewell@umich.edu#include "kern/linux/printk.hh" 535222Sksewell@umich.edu#include "kern/linux/events.hh" 545222Sksewell@umich.edu#include "mem/physical.hh" 555222Sksewell@umich.edu#include "mem/port.hh" 565222Sksewell@umich.edu#include "sim/arguments.hh" 575222Sksewell@umich.edu#include "sim/byteswap.hh" 585222Sksewell@umich.edu 595222Sksewell@umich.eduusing namespace std; 605222Sksewell@umich.eduusing namespace MipsISA; 615222Sksewell@umich.eduusing namespace Linux; 625222Sksewell@umich.edu 635222Sksewell@umich.eduLinuxMipsSystem::LinuxMipsSystem(Params *p) 645222Sksewell@umich.edu : MipsSystem(p) 655222Sksewell@umich.edu{ 665222Sksewell@umich.edu Addr addr = 0; 675222Sksewell@umich.edu 685222Sksewell@umich.edu /** 695222Sksewell@umich.edu * The symbol swapper_pg_dir marks the beginning of the kernel and 705222Sksewell@umich.edu * the location of bootloader passed arguments 715222Sksewell@umich.edu */ 725222Sksewell@umich.edu if (!kernelSymtab->findAddress("swapper_pg_dir", KernelStart)) { 735222Sksewell@umich.edu panic("Could not determine start location of kernel"); 745222Sksewell@umich.edu } 755222Sksewell@umich.edu 765222Sksewell@umich.edu /** 775222Sksewell@umich.edu * Since we aren't using a bootloader, we have to copy the 785222Sksewell@umich.edu * kernel arguments directly into the kernel's memory. 795222Sksewell@umich.edu */ 805222Sksewell@umich.edu virtPort.writeBlob(CommandLine(), (uint8_t*)params()->boot_osflags.c_str(), 815222Sksewell@umich.edu params()->boot_osflags.length()+1); 825222Sksewell@umich.edu 835222Sksewell@umich.edu /** 845222Sksewell@umich.edu * find the address of the est_cycle_freq variable and insert it 855222Sksewell@umich.edu * so we don't through the lengthly process of trying to 865222Sksewell@umich.edu * calculated it by using the PIT, RTC, etc. 875222Sksewell@umich.edu */ 885222Sksewell@umich.edu if (kernelSymtab->findAddress("est_cycle_freq", addr)) 895222Sksewell@umich.edu virtPort.write(addr, (uint64_t)(Clock::Frequency / 905222Sksewell@umich.edu p->boot_cpu_frequency)); 915222Sksewell@umich.edu 925222Sksewell@umich.edu 935222Sksewell@umich.edu /** 945222Sksewell@umich.edu * EV5 only supports 127 ASNs so we are going to tell the kernel that the 955222Sksewell@umich.edu * paritiuclar EV6 we have only supports 127 asns. 965222Sksewell@umich.edu * @todo At some point we should change ev5.hh and the palcode to support 975222Sksewell@umich.edu * 255 ASNs. 985222Sksewell@umich.edu */ 995222Sksewell@umich.edu if (kernelSymtab->findAddress("dp264_mv", addr)) 1005222Sksewell@umich.edu virtPort.write(addr + 0x18, LittleEndianGuest::htog((uint32_t)127)); 1015222Sksewell@umich.edu else 1025222Sksewell@umich.edu panic("could not find dp264_mv\n"); 1035222Sksewell@umich.edu 1045222Sksewell@umich.edu#ifndef NDEBUG 1055222Sksewell@umich.edu kernelPanicEvent = addKernelFuncEvent<BreakPCEvent>("panic"); 1065222Sksewell@umich.edu if (!kernelPanicEvent) 1075222Sksewell@umich.edu panic("could not find kernel symbol \'panic\'"); 1085222Sksewell@umich.edu 1095222Sksewell@umich.edu#if 0 1105222Sksewell@umich.edu kernelDieEvent = addKernelFuncEvent<BreakPCEvent>("die_if_kernel"); 1115222Sksewell@umich.edu if (!kernelDieEvent) 1125222Sksewell@umich.edu panic("could not find kernel symbol \'die_if_kernel\'"); 1135222Sksewell@umich.edu#endif 1145222Sksewell@umich.edu 1155222Sksewell@umich.edu#endif 1165222Sksewell@umich.edu 1175222Sksewell@umich.edu /** 1185222Sksewell@umich.edu * Any time ide_delay_50ms, calibarte_delay or 1195222Sksewell@umich.edu * determine_cpu_caches is called just skip the 1205222Sksewell@umich.edu * function. Currently determine_cpu_caches only is used put 1215222Sksewell@umich.edu * information in proc, however if that changes in the future we 1225222Sksewell@umich.edu * will have to fill in the cache size variables appropriately. 1235222Sksewell@umich.edu */ 1245222Sksewell@umich.edu 1255222Sksewell@umich.edu skipIdeDelay50msEvent = 1265222Sksewell@umich.edu addKernelFuncEvent<SkipFuncEvent>("ide_delay_50ms"); 1275222Sksewell@umich.edu skipDelayLoopEvent = 1285222Sksewell@umich.edu addKernelFuncEvent<SkipDelayLoopEvent>("calibrate_delay"); 1295222Sksewell@umich.edu skipCacheProbeEvent = 1305222Sksewell@umich.edu addKernelFuncEvent<SkipFuncEvent>("determine_cpu_caches"); 1315222Sksewell@umich.edu debugPrintkEvent = addKernelFuncEvent<DebugPrintkEvent>("dprintk"); 1325222Sksewell@umich.edu idleStartEvent = addKernelFuncEvent<IdleStartEvent>("cpu_idle"); 1335222Sksewell@umich.edu 1345222Sksewell@umich.edu // Disable for now as it runs into panic() calls in VPTr methods 1355222Sksewell@umich.edu // (see sim/vptr.hh). Once those bugs are fixed, we can 1365222Sksewell@umich.edu // re-enable, but we should find a better way to turn it on than 1375222Sksewell@umich.edu // using DTRACE(Thread), since looking at a trace flag at tick 0 1385222Sksewell@umich.edu // leads to non-intuitive behavior with --trace-start. 1395222Sksewell@umich.edu if (false && kernelSymtab->findAddress("mips_switch_to", addr)) { 1405222Sksewell@umich.edu printThreadEvent = new PrintThreadInfo(&pcEventQueue, "threadinfo", 1415222Sksewell@umich.edu addr + sizeof(MachInst) * 6); 1425222Sksewell@umich.edu } else { 1435222Sksewell@umich.edu printThreadEvent = NULL; 1445222Sksewell@umich.edu } 1455222Sksewell@umich.edu} 1465222Sksewell@umich.edu 1475222Sksewell@umich.eduLinuxMipsSystem::~LinuxMipsSystem() 1485222Sksewell@umich.edu{ 1495222Sksewell@umich.edu#ifndef NDEBUG 1505222Sksewell@umich.edu delete kernelPanicEvent; 1515222Sksewell@umich.edu#endif 1525222Sksewell@umich.edu delete skipIdeDelay50msEvent; 1535222Sksewell@umich.edu delete skipDelayLoopEvent; 1545222Sksewell@umich.edu delete skipCacheProbeEvent; 1555222Sksewell@umich.edu delete debugPrintkEvent; 1565222Sksewell@umich.edu delete idleStartEvent; 1575222Sksewell@umich.edu delete printThreadEvent; 1585222Sksewell@umich.edu} 1595222Sksewell@umich.edu 1605222Sksewell@umich.edu 1615222Sksewell@umich.eduvoid 1625222Sksewell@umich.eduLinuxMipsSystem::setDelayLoop(ThreadContext *tc) 1635222Sksewell@umich.edu{ 1645222Sksewell@umich.edu Addr addr = 0; 1655222Sksewell@umich.edu if (kernelSymtab->findAddress("loops_per_jiffy", addr)) { 1665222Sksewell@umich.edu Tick cpuFreq = tc->getCpuPtr()->frequency(); 1675222Sksewell@umich.edu Tick intrFreq = platform->intrFrequency(); 1685222Sksewell@umich.edu VirtualPort *vp; 1695222Sksewell@umich.edu 1705222Sksewell@umich.edu vp = tc->getVirtPort(); 1715222Sksewell@umich.edu vp->writeHtoG(addr, (uint32_t)((cpuFreq / intrFreq) * 0.9988)); 1725222Sksewell@umich.edu tc->delVirtPort(vp); 1735222Sksewell@umich.edu } 1745222Sksewell@umich.edu} 1755222Sksewell@umich.edu 1765222Sksewell@umich.edu 1775222Sksewell@umich.eduvoid 1785222Sksewell@umich.eduLinuxMipsSystem::SkipDelayLoopEvent::process(ThreadContext *tc) 1795222Sksewell@umich.edu{ 1805222Sksewell@umich.edu SkipFuncEvent::process(tc); 1815222Sksewell@umich.edu // calculate and set loops_per_jiffy 1825222Sksewell@umich.edu ((LinuxMipsSystem *)tc->getSystemPtr())->setDelayLoop(tc); 1835222Sksewell@umich.edu} 1845222Sksewell@umich.edu 1855222Sksewell@umich.eduvoid 1865222Sksewell@umich.eduLinuxMipsSystem::PrintThreadInfo::process(ThreadContext *tc) 1875222Sksewell@umich.edu{ 1885222Sksewell@umich.edu Linux::ThreadInfo ti(tc); 1895222Sksewell@umich.edu 1905222Sksewell@umich.edu DPRINTF(Thread, "Currently Executing Thread %s, pid %d, started at: %d\n", 1915222Sksewell@umich.edu ti.curTaskName(), ti.curTaskPID(), ti.curTaskStart()); 1925222Sksewell@umich.edu} 1935222Sksewell@umich.edu 1945222Sksewell@umich.eduLinuxMipsSystem * 1955222Sksewell@umich.eduLinuxMipsSystemParams::create() 1965222Sksewell@umich.edu{ 1975222Sksewell@umich.edu return new LinuxMipsSystem(this); 1985222Sksewell@umich.edu} 199