system.cc revision 1070
1/* 2 * Copyright (c) 2004 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29/** 30 * @file 31 * This code loads the linux kernel, console, pal and patches certain 32 * functions. The symbol tables are loaded so that traces can show 33 * the executing function and we can skip functions. Various delay 34 * loops are skipped and their final values manually computed to speed 35 * up boot time. 36 */ 37 38#include "base/trace.hh" 39#include "cpu/exec_context.hh" 40#include "cpu/base_cpu.hh" 41#include "kern/linux/linux_events.hh" 42#include "kern/linux/linux_system.hh" 43#include "kern/system_events.hh" 44#include "mem/functional_mem/memory_control.hh" 45#include "mem/functional_mem/physical_memory.hh" 46#include "sim/builder.hh" 47#include "dev/platform.hh" 48#include "targetarch/isa_traits.hh" 49#include "targetarch/vtophys.hh" 50#include "sim/debug.hh" 51 52extern SymbolTable *debugSymbolTable; 53 54using namespace std; 55 56LinuxSystem::LinuxSystem(Params *p) 57 : System(p) 58{ 59 Addr addr = 0; 60 61 /** 62 * find the address of the est_cycle_freq variable and insert it 63 * so we don't through the lengthly process of trying to 64 * calculated it by using the PIT, RTC, etc. 65 */ 66 if (kernelSymtab->findAddress("est_cycle_freq", addr)) { 67 Addr paddr = vtophys(physmem, addr); 68 uint8_t *est_cycle_frequency = 69 physmem->dma_addr(paddr, sizeof(uint64_t)); 70 71 if (est_cycle_frequency) 72 *(uint64_t *)est_cycle_frequency = htoa(ticksPerSecond); 73 } 74 75 76 /** 77 * Since we aren't using a bootloader, we have to copy the kernel arguments 78 * directly into the kernels memory. 79 */ 80 { 81 Addr paddr = vtophys(physmem, PARAM_ADDR); 82 char *commandline = (char*)physmem->dma_addr(paddr, sizeof(uint64_t)); 83 if (commandline) 84 strcpy(commandline, params->boot_osflags.c_str()); 85 } 86 87 88 /** 89 * EV5 only supports 127 ASNs so we are going to tell the kernel that the 90 * paritiuclar EV6 we have only supports 127 asns. 91 * @todo At some point we should change ev5.hh and the palcode to support 92 * 255 ASNs. 93 */ 94 if (kernelSymtab->findAddress("dp264_mv", addr)) { 95 Addr paddr = vtophys(physmem, addr); 96 char *dp264_mv = (char *)physmem->dma_addr(paddr, sizeof(uint64_t)); 97 98 if (dp264_mv) { 99 *(uint32_t*)(dp264_mv+0x18) = htoa((uint32_t)127); 100 } else 101 panic("could not translate dp264_mv addr\n"); 102 103 } else 104 panic("could not find dp264_mv\n"); 105 106#ifdef DEBUG 107 kernelPanicEvent = new BreakPCEvent(&pcEventQueue, "kernel panic"); 108 if (kernelSymtab->findAddress("panic", addr)) 109 kernelPanicEvent->schedule(addr); 110 else 111 panic("could not find kernel symbol \'panic\'"); 112#endif 113 114 /** 115 * Any time ide_delay_50ms, calibarte_delay or 116 * determine_cpu_caches is called just skip the 117 * function. Currently determine_cpu_caches only is used put 118 * information in proc, however if that changes in the future we 119 * will have to fill in the cache size variables appropriately. 120 */ 121 skipIdeDelay50msEvent = new SkipFuncEvent(&pcEventQueue, "ide_delay_50ms"); 122 if (kernelSymtab->findAddress("ide_delay_50ms", addr)) 123 skipIdeDelay50msEvent->schedule(addr+sizeof(MachInst)); 124 125 skipDelayLoopEvent = new LinuxSkipDelayLoopEvent(&pcEventQueue, 126 "calibrate_delay"); 127 if (kernelSymtab->findAddress("calibrate_delay", addr)) 128 skipDelayLoopEvent->schedule(addr+sizeof(MachInst)); 129 130 skipCacheProbeEvent = new SkipFuncEvent(&pcEventQueue, 131 "determine_cpu_caches"); 132 if (kernelSymtab->findAddress("determine_cpu_caches", addr)) 133 skipCacheProbeEvent->schedule(addr+sizeof(MachInst)); 134 135 debugPrintkEvent = new DebugPrintkEvent(&pcEventQueue, "dprintk"); 136 if (kernelSymtab->findAddress("dprintk", addr)) 137 debugPrintkEvent->schedule(addr+8); 138 139 idleStartEvent = new IdleStartEvent(&pcEventQueue, "cpu_idle", this); 140 if (kernelSymtab->findAddress("cpu_idle", addr)) 141 idleStartEvent->schedule(addr); 142 143 printThreadEvent = new PrintThreadInfo(&pcEventQueue, "threadinfo"); 144 if (kernelSymtab->findAddress("alpha_switch_to", addr) && DTRACE(Thread)) 145 printThreadEvent->schedule(addr + sizeof(MachInst) * 6); 146} 147 148LinuxSystem::~LinuxSystem() 149{ 150#ifdef DEBUG 151 delete kernelPanicEvent; 152#endif 153 delete skipIdeDelay50msEvent; 154 delete skipDelayLoopEvent; 155 delete skipCacheProbeEvent; 156 delete debugPrintkEvent; 157 delete idleStartEvent; 158} 159 160 161void 162LinuxSystem::setDelayLoop(ExecContext *xc) 163{ 164 Addr addr = 0; 165 if (kernelSymtab->findAddress("loops_per_jiffy", addr)) { 166 Addr paddr = vtophys(physmem, addr); 167 168 uint8_t *loops_per_jiffy = 169 physmem->dma_addr(paddr, sizeof(uint32_t)); 170 171 Tick cpuFreq = xc->cpu->getFreq(); 172 Tick intrFreq = platform->interrupt_frequency; 173 *(uint32_t *)loops_per_jiffy = 174 (uint32_t)((cpuFreq / intrFreq) * 0.9988); 175 } 176} 177 178BEGIN_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem) 179 180 SimObjectParam<MemoryController *> mem_ctl; 181 SimObjectParam<PhysicalMemory *> physmem; 182 183 Param<string> kernel_code; 184 Param<string> console_code; 185 Param<string> pal_code; 186 187 Param<string> boot_osflags; 188 Param<string> readfile; 189 Param<unsigned int> init_param; 190 191 Param<uint64_t> system_type; 192 Param<uint64_t> system_rev; 193 194 Param<bool> bin; 195 VectorParam<string> binned_fns; 196 197END_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem) 198 199BEGIN_INIT_SIM_OBJECT_PARAMS(LinuxSystem) 200 201 INIT_PARAM(mem_ctl, "memory controller"), 202 INIT_PARAM(physmem, "phsyical memory"), 203 INIT_PARAM(kernel_code, "file that contains the kernel code"), 204 INIT_PARAM(console_code, "file that contains the console code"), 205 INIT_PARAM(pal_code, "file that contains palcode"), 206 INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot", 207 "a"), 208 INIT_PARAM_DFLT(readfile, "file to read startup script from", ""), 209 INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0), 210 INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34), 211 INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10), 212 INIT_PARAM_DFLT(bin, "is this system to be binned", false), 213 INIT_PARAM(binned_fns, "functions to be broken down and binned") 214 215END_INIT_SIM_OBJECT_PARAMS(LinuxSystem) 216 217CREATE_SIM_OBJECT(LinuxSystem) 218{ 219 System::Params *p = new System::Params; 220 p->name = getInstanceName(); 221 p->memctrl = mem_ctl; 222 p->physmem = physmem; 223 p->kernel_path = kernel_code; 224 p->console_path = console_code; 225 p->palcode = pal_code; 226 p->boot_osflags = boot_osflags; 227 p->init_param = init_param; 228 p->readfile = readfile; 229 p->system_type = system_type; 230 p->system_rev = system_rev; 231 p->bin = bin; 232 p->binned_fns = binned_fns; 233 234 return new LinuxSystem(p); 235} 236 237REGISTER_SIM_OBJECT("LinuxSystem", LinuxSystem) 238 239