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