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