system.cc revision 1040
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/aout_object.hh" 39#include "base/loader/elf_object.hh" 40#include "base/loader/object_file.hh" 41#include "base/loader/symtab.hh" 42#include "base/remote_gdb.hh" 43#include "base/trace.hh" 44#include "cpu/exec_context.hh" 45#include "cpu/base_cpu.hh" 46#include "kern/linux/linux_events.hh" 47#include "kern/linux/linux_system.hh" 48#include "kern/system_events.hh" 49#include "mem/functional_mem/memory_control.hh" 50#include "mem/functional_mem/physical_memory.hh" 51#include "sim/builder.hh" 52#include "dev/platform.hh" 53#include "targetarch/isa_traits.hh" 54#include "targetarch/vtophys.hh" 55#include "sim/debug.hh" 56 57extern SymbolTable *debugSymbolTable; 58 59using namespace std; 60 61LinuxSystem::LinuxSystem(const string _name, const uint64_t _init_param, 62 MemoryController *_memCtrl, PhysicalMemory *_physmem, 63 const string &kernel_path, const string &console_path, 64 const string &palcode, const string &boot_osflags, 65 const bool _bin, const vector<string> &_binned_fns) 66 : System(_name, _init_param, _memCtrl, _physmem, _bin, _binned_fns), 67 bin(_bin), binned_fns(_binned_fns) 68{ 69 kernelSymtab = new SymbolTable; 70 consoleSymtab = new SymbolTable; 71 72 /** 73 * Load the kernel, pal, and console code into memory 74 */ 75 // Load kernel code 76 ObjectFile *kernel = createObjectFile(kernel_path); 77 if (kernel == NULL) 78 fatal("Could not load kernel file %s", kernel_path); 79 80 // Load Console Code 81 ObjectFile *console = createObjectFile(console_path); 82 if (console == NULL) 83 fatal("Could not load console file %s", console_path); 84 85 // Load pal file 86 ObjectFile *pal = createObjectFile(palcode); 87 if (pal == NULL) 88 fatal("Could not load PALcode file %s", palcode); 89 pal->loadSections(physmem, true); 90 91 // Load console file 92 console->loadSections(physmem, true); 93 94 // Load kernel file 95 kernel->loadSections(physmem, true); 96 kernelStart = kernel->textBase(); 97 kernelEnd = kernel->bssBase() + kernel->bssSize(); 98 kernelEntry = kernel->entryPoint(); 99 100 // load symbols 101 if (!kernel->loadGlobalSymbols(kernelSymtab)) 102 panic("could not load kernel symbols\n"); 103 debugSymbolTable = kernelSymtab; 104 105 if (!kernel->loadLocalSymbols(kernelSymtab)) 106 panic("could not load kernel local symbols\n"); 107 108 if (!console->loadGlobalSymbols(consoleSymtab)) 109 panic("could not load console symbols\n"); 110 111 DPRINTF(Loader, "Kernel start = %#x\n" 112 "Kernel end = %#x\n" 113 "Kernel entry = %#x\n", 114 kernelStart, kernelEnd, kernelEntry); 115 116 DPRINTF(Loader, "Kernel loaded...\n"); 117 118 119#ifdef DEBUG 120 kernelPanicEvent = new BreakPCEvent(&pcEventQueue, "kernel panic"); 121 consolePanicEvent = new BreakPCEvent(&pcEventQueue, "console panic"); 122#endif 123 124 skipIdeDelay50msEvent = new SkipFuncEvent(&pcEventQueue, 125 "ide_delay_50ms"); 126 127 skipDelayLoopEvent = new LinuxSkipDelayLoopEvent(&pcEventQueue, 128 "calibrate_delay"); 129 130 skipCacheProbeEvent = new SkipFuncEvent(&pcEventQueue, 131 "determine_cpu_caches"); 132 133 debugPrintkEvent = new DebugPrintkEvent(&pcEventQueue, "dprintk"); 134 135 Addr addr = 0; 136 137 /** 138 * find the address of the est_cycle_freq variable and insert it so we don't 139 * through the lengthly process of trying to calculated it by using the PIT, 140 * RTC, etc. 141 */ 142 if (kernelSymtab->findAddress("est_cycle_freq", addr)) { 143 Addr paddr = vtophys(physmem, addr); 144 uint8_t *est_cycle_frequency = 145 physmem->dma_addr(paddr, sizeof(uint64_t)); 146 147 if (est_cycle_frequency) 148 *(uint64_t *)est_cycle_frequency = htoa(ticksPerSecond); 149 } 150 151 152 /** 153 * Copy the osflags (kernel arguments) into the consoles memory. Presently 154 * Linux does use the console service routine to get these command line 155 * arguments, but we might as well make them available just in case. 156 */ 157 if (consoleSymtab->findAddress("env_booted_osflags", addr)) { 158 Addr paddr = vtophys(physmem, addr); 159 char *osflags = (char *)physmem->dma_addr(paddr, sizeof(uint32_t)); 160 161 if (osflags) 162 strcpy(osflags, boot_osflags.c_str()); 163 } 164 165 /** 166 * Since we aren't using a bootloader, we have to copy the kernel arguments 167 * directly into the kernels memory. 168 */ 169 { 170 Addr paddr = vtophys(physmem, PARAM_ADDR); 171 char *commandline = (char*)physmem->dma_addr(paddr, sizeof(uint64_t)); 172 if (commandline) 173 strcpy(commandline, boot_osflags.c_str()); 174 } 175 176 177 /** 178 * Set the hardware reset parameter block system type and revision 179 * information to Tsunami. 180 */ 181 if (consoleSymtab->findAddress("xxm_rpb", addr)) { 182 Addr paddr = vtophys(physmem, addr); 183 char *hwprb = (char *)physmem->dma_addr(paddr, sizeof(uint64_t)); 184 185 if (hwprb) { 186 // Tsunami 187 *(uint64_t*)(hwprb + 0x50) = htoa(ULL(34)); 188 189 // Plain DP264 190 *(uint64_t*)(hwprb + 0x58) = htoa(ULL(1) << 10); 191 } 192 else 193 panic("could not translate hwprb addr to set system type/variation\n"); 194 195 } else 196 panic("could not find hwprb to set system type/variation\n"); 197 198 /** 199 * EV5 only supports 127 ASNs so we are going to tell the kernel that the 200 * paritiuclar EV6 we have only supports 127 asns. 201 * @todo At some point we should change ev5.hh and the palcode to support 202 * 255 ASNs. 203 */ 204 if (kernelSymtab->findAddress("dp264_mv", addr)) { 205 Addr paddr = vtophys(physmem, addr); 206 char *dp264_mv = (char *)physmem->dma_addr(paddr, sizeof(uint64_t)); 207 208 if (dp264_mv) { 209 *(uint32_t*)(dp264_mv+0x18) = htoa((uint32_t)127); 210 } else 211 panic("could not translate dp264_mv addr to set the MAX_ASN to 127\n"); 212 213 } else 214 panic("could not find dp264_mv to set the MAX_ASN to 127\n"); 215 216 217 218#ifdef DEBUG 219 if (kernelSymtab->findAddress("panic", addr)) 220 kernelPanicEvent->schedule(addr); 221 else 222 panic("could not find kernel symbol \'panic\'"); 223 224 if (consoleSymtab->findAddress("panic", addr)) 225 consolePanicEvent->schedule(addr); 226#endif 227 228 /** 229 * Any time ide_delay_50ms, calibarte_delay or determine_cpu_caches is called 230 * just skip the function. Currently determine_cpu_caches only is used put 231 * information in proc, however if that changes in the future we will have to 232 * fill in the cache size variables appropriately. 233 */ 234 if (kernelSymtab->findAddress("ide_delay_50ms", addr)) 235 skipIdeDelay50msEvent->schedule(addr+sizeof(MachInst)); 236 237 if (kernelSymtab->findAddress("calibrate_delay", addr)) 238 skipDelayLoopEvent->schedule(addr+sizeof(MachInst)); 239 240 if (kernelSymtab->findAddress("determine_cpu_caches", addr)) 241 skipCacheProbeEvent->schedule(addr+sizeof(MachInst)); 242 243 if (kernelSymtab->findAddress("dprintk", addr)) 244 debugPrintkEvent->schedule(addr+sizeof(MachInst)*2); 245} 246 247LinuxSystem::~LinuxSystem() 248{ 249 delete kernel; 250 delete console; 251 252 delete kernelSymtab; 253 delete consoleSymtab; 254 255 delete kernelPanicEvent; 256 delete consolePanicEvent; 257 delete skipIdeDelay50msEvent; 258 delete skipDelayLoopEvent; 259 delete skipCacheProbeEvent; 260} 261 262 263void 264LinuxSystem::setDelayLoop(ExecContext *xc) 265{ 266 Addr addr = 0; 267 if (kernelSymtab->findAddress("loops_per_jiffy", addr)) { 268 Addr paddr = vtophys(physmem, addr); 269 270 uint8_t *loops_per_jiffy = 271 physmem->dma_addr(paddr, sizeof(uint32_t)); 272 273 Tick cpuFreq = xc->cpu->getFreq(); 274 Tick intrFreq = platform->interrupt_frequency; 275 *(uint32_t *)loops_per_jiffy = 276 (uint32_t)((cpuFreq / intrFreq) * 0.9988); 277 } 278} 279 280int 281LinuxSystem::registerExecContext(ExecContext *xc) 282{ 283 int xcIndex = System::registerExecContext(xc); 284 285 if (xcIndex == 0) { 286 // activate with zero delay so that we start ticking right 287 // away on cycle 0 288 xc->activate(0); 289 } 290 291 RemoteGDB *rgdb = new RemoteGDB(this, xc); 292 GDBListener *gdbl = new GDBListener(rgdb, 7000 + xcIndex); 293 gdbl->listen(); 294 /** 295 * Uncommenting this line waits for a remote debugger to connect 296 * to the simulator before continuing. 297 */ 298 //gdbl->accept(); 299 300 if (remoteGDB.size() <= xcIndex) { 301 remoteGDB.resize(xcIndex+1); 302 } 303 304 remoteGDB[xcIndex] = rgdb; 305 306 return xcIndex; 307} 308 309 310void 311LinuxSystem::replaceExecContext(ExecContext *xc, int xcIndex) 312{ 313 System::replaceExecContext(xcIndex, xc); 314 remoteGDB[xcIndex]->replaceExecContext(xc); 315} 316 317bool 318LinuxSystem::breakpoint() 319{ 320 return remoteGDB[0]->trap(ALPHA_KENTRY_IF); 321} 322 323BEGIN_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem) 324 325 Param<bool> bin; 326 SimObjectParam<MemoryController *> mem_ctl; 327 SimObjectParam<PhysicalMemory *> physmem; 328 Param<uint64_t> init_param; 329 330 Param<string> kernel_code; 331 Param<string> console_code; 332 Param<string> pal_code; 333 Param<string> boot_osflags; 334 VectorParam<string> binned_fns; 335 336 Param<string> readfile; 337 338END_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem) 339 340BEGIN_INIT_SIM_OBJECT_PARAMS(LinuxSystem) 341 342 343 INIT_PARAM_DFLT(bin, "is this system to be binned", false), 344 INIT_PARAM(mem_ctl, "memory controller"), 345 INIT_PARAM(physmem, "phsyical memory"), 346 INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0), 347 INIT_PARAM(kernel_code, "file that contains the code"), 348 INIT_PARAM(console_code, "file that contains the console code"), 349 INIT_PARAM(pal_code, "file that contains palcode"), 350 INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot", 351 "a"), 352 INIT_PARAM(binned_fns, "functions to be broken down and binned"), 353 INIT_PARAM_DFLT(readfile, "file to read startup script from", "") 354 355 356END_INIT_SIM_OBJECT_PARAMS(LinuxSystem) 357 358CREATE_SIM_OBJECT(LinuxSystem) 359{ 360 LinuxSystem *sys = new LinuxSystem(getInstanceName(), init_param, mem_ctl, 361 physmem, kernel_code, console_code, 362 pal_code, boot_osflags, bin, binned_fns); 363 364 sys->readfile = readfile; 365 return sys; 366} 367 368REGISTER_SIM_OBJECT("LinuxSystem", LinuxSystem) 369