system.cc revision 1082
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 if (kernelSymtab->findAddress("do_entInt", addr)) 149 intStartEvent->schedule(addr + sizeof(MachInst) * 2); 150 151 intEndEvent = new InterruptEndEvent(&pcEventQueue, "intStartEvent"); 152 if (palSymtab->findAddress("Call_Pal_Rti", addr)) 153 intEndEvent->schedule(addr + sizeof(MachInst)); 154 else 155 panic("could not find symbol\n"); 156} 157 158LinuxSystem::~LinuxSystem() 159{ 160#ifdef DEBUG 161 delete kernelPanicEvent; 162#endif 163 delete skipIdeDelay50msEvent; 164 delete skipDelayLoopEvent; 165 delete skipCacheProbeEvent; 166 delete debugPrintkEvent; 167 delete idleStartEvent; 168 delete printThreadEvent; 169 delete intStartEvent; 170} 171 172 173void 174LinuxSystem::setDelayLoop(ExecContext *xc) 175{ 176 Addr addr = 0; 177 if (kernelSymtab->findAddress("loops_per_jiffy", addr)) { 178 Addr paddr = vtophys(physmem, addr); 179 180 uint8_t *loops_per_jiffy = 181 physmem->dma_addr(paddr, sizeof(uint32_t)); 182 183 Tick cpuFreq = xc->cpu->getFreq(); 184 Tick intrFreq = platform->interrupt_frequency; 185 *(uint32_t *)loops_per_jiffy = 186 (uint32_t)((cpuFreq / intrFreq) * 0.9988); 187 } 188} 189 190BEGIN_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem) 191 192 SimObjectParam<MemoryController *> mem_ctl; 193 SimObjectParam<PhysicalMemory *> physmem; 194 195 Param<string> kernel_code; 196 Param<string> console_code; 197 Param<string> pal_code; 198 199 Param<string> boot_osflags; 200 Param<string> readfile; 201 Param<unsigned int> init_param; 202 203 Param<uint64_t> system_type; 204 Param<uint64_t> system_rev; 205 206 Param<bool> bin; 207 VectorParam<string> binned_fns; 208 Param<bool> bin_int; 209 210END_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem) 211 212BEGIN_INIT_SIM_OBJECT_PARAMS(LinuxSystem) 213 214 INIT_PARAM(mem_ctl, "memory controller"), 215 INIT_PARAM(physmem, "phsyical memory"), 216 INIT_PARAM(kernel_code, "file that contains the kernel code"), 217 INIT_PARAM(console_code, "file that contains the console code"), 218 INIT_PARAM(pal_code, "file that contains palcode"), 219 INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot", 220 "a"), 221 INIT_PARAM_DFLT(readfile, "file to read startup script from", ""), 222 INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0), 223 INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34), 224 INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10), 225 INIT_PARAM_DFLT(bin, "is this system to be binned", false), 226 INIT_PARAM(binned_fns, "functions to be broken down and binned"), 227 INIT_PARAM_DFLT(bin_int, "is interrupt code binned seperately?", false) 228 229END_INIT_SIM_OBJECT_PARAMS(LinuxSystem) 230 231CREATE_SIM_OBJECT(LinuxSystem) 232{ 233 System::Params *p = new System::Params; 234 p->name = getInstanceName(); 235 p->memctrl = mem_ctl; 236 p->physmem = physmem; 237 p->kernel_path = kernel_code; 238 p->console_path = console_code; 239 p->palcode = pal_code; 240 p->boot_osflags = boot_osflags; 241 p->init_param = init_param; 242 p->readfile = readfile; 243 p->system_type = system_type; 244 p->system_rev = system_rev; 245 p->bin = bin; 246 p->binned_fns = binned_fns; 247 p->bin_int = bin_int; 248 return new LinuxSystem(p); 249} 250 251REGISTER_SIM_OBJECT("LinuxSystem", LinuxSystem) 252 253