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