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