system.cc revision 2190
1/* 2 * Copyright (c) 2004-2005 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/loader/symtab.hh" 39#include "cpu/exec_context.hh" 40#include "cpu/base.hh" 41#include "kern/linux/linux_system.hh" 42#include "kern/linux/linux_threadinfo.hh" 43#include "kern/linux/printk.hh" 44#include "mem/functional/memory_control.hh" 45#include "mem/functional/physical.hh" 46#include "sim/builder.hh" 47#include "sim/byteswap.hh" 48#include "dev/platform.hh" 49#include "targetarch/arguments.hh" 50#include "targetarch/vtophys.hh" 51 52using namespace std; 53using namespace TheISA; 54 55LinuxSystem::LinuxSystem(Params *p) 56 : System(p) 57{ 58 Addr addr = 0; 59 Addr paddr = 0; 60 61 /** 62 * The symbol swapper_pg_dir marks the beginning of the kernel and 63 * the location of bootloader passed arguments 64 */ 65 if (!kernelSymtab->findAddress("swapper_pg_dir", KernelStart)) { 66 panic("Could not determine start location of kernel"); 67 } 68 69 /** 70 * Since we aren't using a bootloader, we have to copy the 71 * kernel arguments directly into the kernel's memory. 72 */ 73 paddr = vtophys(physmem, CommandLine()); 74 char *commandline = (char *)physmem->dma_addr(paddr, sizeof(uint64_t)); 75 if (commandline) 76 strncpy(commandline, params->boot_osflags.c_str(), CommandLineSize); 77 78 /** 79 * find the address of the est_cycle_freq variable and insert it 80 * so we don't through the lengthly process of trying to 81 * calculated it by using the PIT, RTC, etc. 82 */ 83 if (kernelSymtab->findAddress("est_cycle_freq", addr)) { 84 paddr = vtophys(physmem, addr); 85 uint8_t *est_cycle_frequency = 86 physmem->dma_addr(paddr, sizeof(uint64_t)); 87 88 if (est_cycle_frequency) 89 *(uint64_t *)est_cycle_frequency = 90 Clock::Frequency / p->boot_cpu_frequency; 91 } 92 93 94 /** 95 * EV5 only supports 127 ASNs so we are going to tell the kernel that the 96 * paritiuclar EV6 we have only supports 127 asns. 97 * @todo At some point we should change ev5.hh and the palcode to support 98 * 255 ASNs. 99 */ 100 if (kernelSymtab->findAddress("dp264_mv", addr)) { 101 paddr = vtophys(physmem, addr); 102 char *dp264_mv = (char *)physmem->dma_addr(paddr, sizeof(uint64_t)); 103 104 if (dp264_mv) { 105 *(uint32_t*)(dp264_mv+0x18) = LittleEndianGuest::htog((uint32_t)127); 106 } else 107 panic("could not translate dp264_mv addr\n"); 108 109 } else 110 panic("could not find dp264_mv\n"); 111 112#ifndef NDEBUG 113 kernelPanicEvent = addKernelFuncEvent<BreakPCEvent>("panic"); 114 if (!kernelPanicEvent) 115 panic("could not find kernel symbol \'panic\'"); 116 117#if 0 118 kernelDieEvent = addKernelFuncEvent<BreakPCEvent>("die_if_kernel"); 119 if (!kernelDieEvent) 120 panic("could not find kernel symbol \'die_if_kernel\'"); 121#endif 122 123#endif 124 125 /** 126 * Any time ide_delay_50ms, calibarte_delay or 127 * determine_cpu_caches is called just skip the 128 * function. Currently determine_cpu_caches only is used put 129 * information in proc, however if that changes in the future we 130 * will have to fill in the cache size variables appropriately. 131 */ 132 133 skipIdeDelay50msEvent = 134 addKernelFuncEvent<SkipFuncEvent>("ide_delay_50ms"); 135 skipDelayLoopEvent = 136 addKernelFuncEvent<SkipDelayLoopEvent>("calibrate_delay"); 137 skipCacheProbeEvent = 138 addKernelFuncEvent<SkipFuncEvent>("determine_cpu_caches"); 139 debugPrintkEvent = addKernelFuncEvent<DebugPrintkEvent>("dprintk"); 140 idleStartEvent = addKernelFuncEvent<IdleStartEvent>("cpu_idle"); 141 142 if (kernelSymtab->findAddress("alpha_switch_to", addr) && DTRACE(Thread)) { 143 printThreadEvent = new PrintThreadInfo(&pcEventQueue, "threadinfo", 144 addr + sizeof(MachInst) * 6); 145 } else { 146 printThreadEvent = NULL; 147 } 148 149 if (params->bin_int) { 150 intStartEvent = addPalFuncEvent<InterruptStartEvent>("sys_int_21"); 151 if (!intStartEvent) 152 panic("could not find symbol: sys_int_21\n"); 153 154 intEndEvent = addPalFuncEvent<InterruptEndEvent>("rti_to_kern"); 155 if (!intEndEvent) 156 panic("could not find symbol: rti_to_kern\n"); 157 158 intEndEvent2 = addPalFuncEvent<InterruptEndEvent>("rti_to_user"); 159 if (!intEndEvent2) 160 panic("could not find symbol: rti_to_user\n"); 161 162 intEndEvent3 = addKernelFuncEvent<InterruptEndEvent>("do_softirq"); 163 if (!intEndEvent3) 164 panic("could not find symbol: do_softirq\n"); 165 } 166} 167 168LinuxSystem::~LinuxSystem() 169{ 170#ifndef NDEBUG 171 delete kernelPanicEvent; 172#endif 173 delete skipIdeDelay50msEvent; 174 delete skipDelayLoopEvent; 175 delete skipCacheProbeEvent; 176 delete debugPrintkEvent; 177 delete idleStartEvent; 178 delete printThreadEvent; 179 delete intStartEvent; 180 delete intEndEvent; 181 delete intEndEvent2; 182} 183 184 185void 186LinuxSystem::setDelayLoop(ExecContext *xc) 187{ 188 Addr addr = 0; 189 if (kernelSymtab->findAddress("loops_per_jiffy", addr)) { 190 Addr paddr = vtophys(physmem, addr); 191 192 uint8_t *loops_per_jiffy = 193 physmem->dma_addr(paddr, sizeof(uint32_t)); 194 195 Tick cpuFreq = xc->getCpuPtr()->frequency(); 196 Tick intrFreq = platform->intrFrequency(); 197 *(uint32_t *)loops_per_jiffy = 198 (uint32_t)((cpuFreq / intrFreq) * 0.9988); 199 } 200} 201 202void 203LinuxSystem::SkipDelayLoopEvent::process(ExecContext *xc) 204{ 205 SkipFuncEvent::process(xc); 206 // calculate and set loops_per_jiffy 207 ((LinuxSystem *)xc->getSystemPtr())->setDelayLoop(xc); 208} 209 210void 211LinuxSystem::DebugPrintkEvent::process(ExecContext *xc) 212{ 213 if (DTRACE(DebugPrintf)) { 214 if (!raw) { 215 StringWrap name(xc->getSystemPtr()->name() + ".dprintk"); 216 DPRINTFN(""); 217 } 218 219 AlphaArguments args(xc); 220 Printk(args); 221 SkipFuncEvent::process(xc); 222 } 223} 224 225void 226LinuxSystem::PrintThreadInfo::process(ExecContext *xc) 227{ 228 Linux::ThreadInfo ti(xc); 229 230 DPRINTF(Thread, "Currently Executing Thread %s, pid %d, started at: %d\n", 231 ti.curTaskName(), ti.curTaskPID(), ti.curTaskStart()); 232} 233 234 235BEGIN_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem) 236 237 Param<Tick> boot_cpu_frequency; 238 SimObjectParam<MemoryController *> memctrl; 239 SimObjectParam<PhysicalMemory *> physmem; 240 241 Param<string> kernel; 242 Param<string> console; 243 Param<string> pal; 244 245 Param<string> boot_osflags; 246 Param<string> readfile; 247 Param<unsigned int> init_param; 248 249 Param<uint64_t> system_type; 250 Param<uint64_t> system_rev; 251 252 Param<bool> bin; 253 VectorParam<string> binned_fns; 254 Param<bool> bin_int; 255 256END_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem) 257 258BEGIN_INIT_SIM_OBJECT_PARAMS(LinuxSystem) 259 260 INIT_PARAM(boot_cpu_frequency, "Frequency of the boot CPU"), 261 INIT_PARAM(memctrl, "memory controller"), 262 INIT_PARAM(physmem, "phsyical memory"), 263 INIT_PARAM(kernel, "file that contains the kernel code"), 264 INIT_PARAM(console, "file that contains the console code"), 265 INIT_PARAM(pal, "file that contains palcode"), 266 INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot", 267 "a"), 268 INIT_PARAM_DFLT(readfile, "file to read startup script from", ""), 269 INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0), 270 INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34), 271 INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10), 272 INIT_PARAM_DFLT(bin, "is this system to be binned", false), 273 INIT_PARAM(binned_fns, "functions to be broken down and binned"), 274 INIT_PARAM_DFLT(bin_int, "is interrupt code binned seperately?", true) 275 276END_INIT_SIM_OBJECT_PARAMS(LinuxSystem) 277 278CREATE_SIM_OBJECT(LinuxSystem) 279{ 280 System::Params *p = new System::Params; 281 p->name = getInstanceName(); 282 p->boot_cpu_frequency = boot_cpu_frequency; 283 p->memctrl = memctrl; 284 p->physmem = physmem; 285 p->kernel_path = kernel; 286 p->console_path = console; 287 p->palcode = pal; 288 p->boot_osflags = boot_osflags; 289 p->init_param = init_param; 290 p->readfile = readfile; 291 p->system_type = system_type; 292 p->system_rev = system_rev; 293 p->bin = bin; 294 p->binned_fns = binned_fns; 295 p->bin_int = bin_int; 296 return new LinuxSystem(p); 297} 298 299REGISTER_SIM_OBJECT("LinuxSystem", LinuxSystem) 300 301