system.cc revision 1310
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#ifdef DEBUG 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#endif 112 113 /** 114 * Any time ide_delay_50ms, calibarte_delay or 115 * determine_cpu_caches is called just skip the 116 * function. Currently determine_cpu_caches only is used put 117 * information in proc, however if that changes in the future we 118 * will have to fill in the cache size variables appropriately. 119 */ 120 skipIdeDelay50msEvent = new SkipFuncEvent(&pcEventQueue, "ide_delay_50ms"); 121 if (kernelSymtab->findAddress("ide_delay_50ms", addr)) 122 skipIdeDelay50msEvent->schedule(addr+sizeof(MachInst)); 123 124 skipDelayLoopEvent = new LinuxSkipDelayLoopEvent(&pcEventQueue, 125 "calibrate_delay"); 126 if (kernelSymtab->findAddress("calibrate_delay", addr)) 127 skipDelayLoopEvent->schedule(addr+sizeof(MachInst)); 128 129 skipCacheProbeEvent = new SkipFuncEvent(&pcEventQueue, 130 "determine_cpu_caches"); 131 if (kernelSymtab->findAddress("determine_cpu_caches", addr)) 132 skipCacheProbeEvent->schedule(addr+sizeof(MachInst)); 133 134 debugPrintkEvent = new DebugPrintkEvent(&pcEventQueue, "dprintk"); 135 if (kernelSymtab->findAddress("dprintk", addr)) 136 debugPrintkEvent->schedule(addr+8); 137 138 idleStartEvent = new IdleStartEvent(&pcEventQueue, "cpu_idle", this); 139 if (kernelSymtab->findAddress("cpu_idle", addr)) 140 idleStartEvent->schedule(addr); 141 142 printThreadEvent = new PrintThreadInfo(&pcEventQueue, "threadinfo"); 143 if (kernelSymtab->findAddress("alpha_switch_to", addr) && DTRACE(Thread)) 144 printThreadEvent->schedule(addr + sizeof(MachInst) * 6); 145 146 intStartEvent = new InterruptStartEvent(&pcEventQueue, "intStartEvent"); 147 148 if (params->bin_int) { 149 if (palSymtab->findAddress("sys_int_21", addr)) 150 intStartEvent->schedule(addr + sizeof(MachInst) * 2); 151 else 152 panic("could not find symbol: sys_int_21\n"); 153 154 intEndEvent = new InterruptEndEvent(&pcEventQueue, "intEndEvent"); 155 if (palSymtab->findAddress("rti_to_kern", addr)) 156 intEndEvent->schedule(addr) ; 157 else 158 panic("could not find symbol: rti_to_kern\n"); 159 160 intEndEvent2 = new InterruptEndEvent(&pcEventQueue, "intEndEvent2"); 161 if (palSymtab->findAddress("rti_to_user", addr)) 162 intEndEvent2->schedule(addr); 163 else 164 panic("could not find symbol: rti_to_user\n"); 165 166 167 intEndEvent3 = new InterruptEndEvent(&pcEventQueue, "intEndEvent3"); 168 if (kernelSymtab->findAddress("do_softirq", addr)) 169 intEndEvent3->schedule(addr + sizeof(MachInst) * 2); 170 else 171 panic("could not find symbol: do_softirq\n"); 172 } 173} 174 175LinuxSystem::~LinuxSystem() 176{ 177#ifdef DEBUG 178 delete kernelPanicEvent; 179#endif 180 delete skipIdeDelay50msEvent; 181 delete skipDelayLoopEvent; 182 delete skipCacheProbeEvent; 183 delete debugPrintkEvent; 184 delete idleStartEvent; 185 delete printThreadEvent; 186 delete intStartEvent; 187 delete intEndEvent; 188 delete intEndEvent2; 189} 190 191 192void 193LinuxSystem::setDelayLoop(ExecContext *xc) 194{ 195 Addr addr = 0; 196 if (kernelSymtab->findAddress("loops_per_jiffy", addr)) { 197 Addr paddr = vtophys(physmem, addr); 198 199 uint8_t *loops_per_jiffy = 200 physmem->dma_addr(paddr, sizeof(uint32_t)); 201 202 Tick cpuFreq = xc->cpu->getFreq(); 203 Tick intrFreq = platform->interrupt_frequency; 204 *(uint32_t *)loops_per_jiffy = 205 (uint32_t)((cpuFreq / intrFreq) * 0.9988); 206 } 207} 208 209BEGIN_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem) 210 211 SimObjectParam<MemoryController *> memctrl; 212 SimObjectParam<PhysicalMemory *> physmem; 213 214 Param<string> kernel; 215 Param<string> console; 216 Param<string> pal; 217 218 Param<string> boot_osflags; 219 Param<string> readfile; 220 Param<unsigned int> init_param; 221 222 Param<uint64_t> system_type; 223 Param<uint64_t> system_rev; 224 225 Param<bool> bin; 226 VectorParam<string> binned_fns; 227 Param<bool> bin_int; 228 229END_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem) 230 231BEGIN_INIT_SIM_OBJECT_PARAMS(LinuxSystem) 232 233 INIT_PARAM(memctrl, "memory controller"), 234 INIT_PARAM(physmem, "phsyical memory"), 235 INIT_PARAM(kernel, "file that contains the kernel code"), 236 INIT_PARAM(console, "file that contains the console code"), 237 INIT_PARAM(pal, "file that contains palcode"), 238 INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot", 239 "a"), 240 INIT_PARAM_DFLT(readfile, "file to read startup script from", ""), 241 INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0), 242 INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34), 243 INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10), 244 INIT_PARAM_DFLT(bin, "is this system to be binned", false), 245 INIT_PARAM(binned_fns, "functions to be broken down and binned"), 246 INIT_PARAM_DFLT(bin_int, "is interrupt code binned seperately?", true) 247 248END_INIT_SIM_OBJECT_PARAMS(LinuxSystem) 249 250CREATE_SIM_OBJECT(LinuxSystem) 251{ 252 System::Params *p = new System::Params; 253 p->name = getInstanceName(); 254 p->memctrl = memctrl; 255 p->physmem = physmem; 256 p->kernel_path = kernel; 257 p->console_path = console; 258 p->palcode = pal; 259 p->boot_osflags = boot_osflags; 260 p->init_param = init_param; 261 p->readfile = readfile; 262 p->system_type = system_type; 263 p->system_rev = system_rev; 264 p->bin = bin; 265 p->binned_fns = binned_fns; 266 p->bin_int = bin_int; 267 return new LinuxSystem(p); 268} 269 270REGISTER_SIM_OBJECT("LinuxSystem", LinuxSystem) 271 272