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