system.cc revision 5569:baeee670d4ce
14826Ssaidi@eecs.umich.edu/* 24826Ssaidi@eecs.umich.edu * Copyright (c) 2004-2005 The Regents of The University of Michigan 34826Ssaidi@eecs.umich.edu * All rights reserved. 44826Ssaidi@eecs.umich.edu * 54826Ssaidi@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 64826Ssaidi@eecs.umich.edu * modification, are permitted provided that the following conditions are 74826Ssaidi@eecs.umich.edu * met: redistributions of source code must retain the above copyright 84826Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 94826Ssaidi@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 104826Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 114826Ssaidi@eecs.umich.edu * documentation and/or other materials provided with the distribution; 124826Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its 134826Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from 144826Ssaidi@eecs.umich.edu * this software without specific prior written permission. 154826Ssaidi@eecs.umich.edu * 164826Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 174826Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 184826Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 194826Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 204826Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 214826Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224826Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234826Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244826Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254826Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264826Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274826Ssaidi@eecs.umich.edu * 284826Ssaidi@eecs.umich.edu * Authors: Ali Saidi 294826Ssaidi@eecs.umich.edu * Lisa Hsu 304826Ssaidi@eecs.umich.edu * Nathan Binkert 314826Ssaidi@eecs.umich.edu * Steve Reinhardt 324826Ssaidi@eecs.umich.edu */ 334826Ssaidi@eecs.umich.edu 344826Ssaidi@eecs.umich.edu/** 354826Ssaidi@eecs.umich.edu * @file 364826Ssaidi@eecs.umich.edu * This code loads the linux kernel, console, pal and patches certain 374826Ssaidi@eecs.umich.edu * functions. The symbol tables are loaded so that traces can show 384826Ssaidi@eecs.umich.edu * the executing function and we can skip functions. Various delay 395569Snate@binkert.org * loops are skipped and their final values manually computed to speed 404826Ssaidi@eecs.umich.edu * up boot time. 415569Snate@binkert.org */ 425569Snate@binkert.org 434826Ssaidi@eecs.umich.edu#include "arch/vtophys.hh" 444826Ssaidi@eecs.umich.edu#include "arch/alpha/idle_event.hh" 455958Sgblack@eecs.umich.edu#include "arch/alpha/linux/system.hh" 464826Ssaidi@eecs.umich.edu#include "arch/alpha/linux/threadinfo.hh" 474826Ssaidi@eecs.umich.edu#include "arch/alpha/system.hh" 485958Sgblack@eecs.umich.edu#include "base/loader/symtab.hh" 494826Ssaidi@eecs.umich.edu#include "cpu/thread_context.hh" 505958Sgblack@eecs.umich.edu#include "cpu/base.hh" 514826Ssaidi@eecs.umich.edu#include "dev/platform.hh" 524826Ssaidi@eecs.umich.edu#include "kern/linux/printk.hh" 535498Ssaidi@eecs.umich.edu#include "kern/linux/events.hh" 544826Ssaidi@eecs.umich.edu#include "mem/physical.hh" 554826Ssaidi@eecs.umich.edu#include "mem/port.hh" 564826Ssaidi@eecs.umich.edu#include "sim/arguments.hh" 574826Ssaidi@eecs.umich.edu#include "sim/byteswap.hh" 584826Ssaidi@eecs.umich.edu 594826Ssaidi@eecs.umich.eduusing namespace std; 605569Snate@binkert.orgusing namespace AlphaISA; 614826Ssaidi@eecs.umich.eduusing namespace Linux; 624826Ssaidi@eecs.umich.edu 634826Ssaidi@eecs.umich.eduLinuxAlphaSystem::LinuxAlphaSystem(Params *p) 646329Sgblack@eecs.umich.edu : AlphaSystem(p) 656329Sgblack@eecs.umich.edu{ 666329Sgblack@eecs.umich.edu Addr addr = 0; 676329Sgblack@eecs.umich.edu 686329Sgblack@eecs.umich.edu /** 696329Sgblack@eecs.umich.edu * The symbol swapper_pg_dir marks the beginning of the kernel and 706329Sgblack@eecs.umich.edu * the location of bootloader passed arguments 716329Sgblack@eecs.umich.edu */ 726329Sgblack@eecs.umich.edu if (!kernelSymtab->findAddress("swapper_pg_dir", KernelStart)) { 736329Sgblack@eecs.umich.edu panic("Could not determine start location of kernel"); 746329Sgblack@eecs.umich.edu } 756329Sgblack@eecs.umich.edu 766329Sgblack@eecs.umich.edu /** 776329Sgblack@eecs.umich.edu * Since we aren't using a bootloader, we have to copy the 786329Sgblack@eecs.umich.edu * kernel arguments directly into the kernel's memory. 796329Sgblack@eecs.umich.edu */ 806329Sgblack@eecs.umich.edu virtPort.writeBlob(CommandLine(), (uint8_t*)params()->boot_osflags.c_str(), 816329Sgblack@eecs.umich.edu params()->boot_osflags.length()+1); 826329Sgblack@eecs.umich.edu 836329Sgblack@eecs.umich.edu /** 846329Sgblack@eecs.umich.edu * find the address of the est_cycle_freq variable and insert it 856329Sgblack@eecs.umich.edu * so we don't through the lengthly process of trying to 866329Sgblack@eecs.umich.edu * calculated it by using the PIT, RTC, etc. 876329Sgblack@eecs.umich.edu */ 886329Sgblack@eecs.umich.edu if (kernelSymtab->findAddress("est_cycle_freq", addr)) 896329Sgblack@eecs.umich.edu virtPort.write(addr, (uint64_t)(Clock::Frequency / 906329Sgblack@eecs.umich.edu p->boot_cpu_frequency)); 916329Sgblack@eecs.umich.edu 926329Sgblack@eecs.umich.edu 936329Sgblack@eecs.umich.edu /** 946329Sgblack@eecs.umich.edu * EV5 only supports 127 ASNs so we are going to tell the kernel that the 956329Sgblack@eecs.umich.edu * paritiuclar EV6 we have only supports 127 asns. 966329Sgblack@eecs.umich.edu * @todo At some point we should change ev5.hh and the palcode to support 976329Sgblack@eecs.umich.edu * 255 ASNs. 984826Ssaidi@eecs.umich.edu */ 994826Ssaidi@eecs.umich.edu if (kernelSymtab->findAddress("dp264_mv", addr)) 100 virtPort.write(addr + 0x18, LittleEndianGuest::htog((uint32_t)127)); 101 else 102 panic("could not find dp264_mv\n"); 103 104#ifndef NDEBUG 105 kernelPanicEvent = addKernelFuncEvent<BreakPCEvent>("panic"); 106 if (!kernelPanicEvent) 107 panic("could not find kernel symbol \'panic\'"); 108 109#if 0 110 kernelDieEvent = addKernelFuncEvent<BreakPCEvent>("die_if_kernel"); 111 if (!kernelDieEvent) 112 panic("could not find kernel symbol \'die_if_kernel\'"); 113#endif 114 115#endif 116 117 /** 118 * Any time ide_delay_50ms, calibarte_delay or 119 * determine_cpu_caches is called just skip the 120 * function. Currently determine_cpu_caches only is used put 121 * information in proc, however if that changes in the future we 122 * will have to fill in the cache size variables appropriately. 123 */ 124 125 skipIdeDelay50msEvent = 126 addKernelFuncEvent<SkipFuncEvent>("ide_delay_50ms"); 127 skipDelayLoopEvent = 128 addKernelFuncEvent<SkipDelayLoopEvent>("calibrate_delay"); 129 skipCacheProbeEvent = 130 addKernelFuncEvent<SkipFuncEvent>("determine_cpu_caches"); 131 debugPrintkEvent = addKernelFuncEvent<DebugPrintkEvent>("dprintk"); 132 idleStartEvent = addKernelFuncEvent<IdleStartEvent>("cpu_idle"); 133 134 // Disable for now as it runs into panic() calls in VPTr methods 135 // (see sim/vptr.hh). Once those bugs are fixed, we can 136 // re-enable, but we should find a better way to turn it on than 137 // using DTRACE(Thread), since looking at a trace flag at tick 0 138 // leads to non-intuitive behavior with --trace-start. 139 if (false && kernelSymtab->findAddress("alpha_switch_to", addr)) { 140 printThreadEvent = new PrintThreadInfo(&pcEventQueue, "threadinfo", 141 addr + sizeof(MachInst) * 6); 142 } else { 143 printThreadEvent = NULL; 144 } 145} 146 147LinuxAlphaSystem::~LinuxAlphaSystem() 148{ 149#ifndef NDEBUG 150 delete kernelPanicEvent; 151#endif 152 delete skipIdeDelay50msEvent; 153 delete skipDelayLoopEvent; 154 delete skipCacheProbeEvent; 155 delete debugPrintkEvent; 156 delete idleStartEvent; 157 delete printThreadEvent; 158} 159 160void 161LinuxAlphaSystem::setDelayLoop(ThreadContext *tc) 162{ 163 Addr addr = 0; 164 if (kernelSymtab->findAddress("loops_per_jiffy", addr)) { 165 Tick cpuFreq = tc->getCpuPtr()->frequency(); 166 Tick intrFreq = platform->intrFrequency(); 167 VirtualPort *vp; 168 169 vp = tc->getVirtPort(); 170 vp->writeHtoG(addr, (uint32_t)((cpuFreq / intrFreq) * 0.9988)); 171 } 172} 173 174void 175LinuxAlphaSystem::SkipDelayLoopEvent::process(ThreadContext *tc) 176{ 177 SkipFuncEvent::process(tc); 178 // calculate and set loops_per_jiffy 179 ((LinuxAlphaSystem *)tc->getSystemPtr())->setDelayLoop(tc); 180} 181 182void 183LinuxAlphaSystem::PrintThreadInfo::process(ThreadContext *tc) 184{ 185 Linux::ThreadInfo ti(tc); 186 187 DPRINTF(Thread, "Currently Executing Thread %s, pid %d, started at: %d\n", 188 ti.curTaskName(), ti.curTaskPID(), ti.curTaskStart()); 189} 190 191LinuxAlphaSystem * 192LinuxAlphaSystemParams::create() 193{ 194 return new LinuxAlphaSystem(this); 195} 196