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