system.cc revision 2158
1/* 2 * Copyright (c) 2004-2005 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 "arch/alpha/system.hh" 39#include "base/loader/symtab.hh" 40#include "cpu/exec_context.hh" 41#include "cpu/base.hh" 42#include "kern/linux/linux_system.hh" 43#include "kern/linux/linux_threadinfo.hh" 44#include "kern/linux/printk.hh" 45#include "mem/functional/memory_control.hh" 46#include "mem/functional/physical.hh" 47#include "sim/builder.hh" 48#include "sim/byteswap.hh" 49#include "dev/platform.hh" 50#include "targetarch/arguments.hh" 51#include "targetarch/vtophys.hh" 52 53using namespace std; 54using namespace TheISA; 55 56LinuxSystem::LinuxSystem(Params *p) 57 : AlphaSystem(p) 58{ 59 Addr addr = 0; 60 Addr paddr = 0; 61 62 /** 63 * The symbol swapper_pg_dir marks the beginning of the kernel and 64 * the location of bootloader passed arguments 65 */ 66 if (!kernelSymtab->findAddress("swapper_pg_dir", KernelStart)) { 67 panic("Could not determine start location of kernel"); 68 } 69 70 /** 71 * Since we aren't using a bootloader, we have to copy the 72 * kernel arguments directly into the kernel's memory. 73 */ 74 paddr = vtophys(physmem, CommandLine()); 75 char *commandline = (char *)physmem->dma_addr(paddr, sizeof(uint64_t)); 76 if (commandline) 77 strncpy(commandline, params()->boot_osflags.c_str(), CommandLineSize); 78 79 /** 80 * find the address of the est_cycle_freq variable and insert it 81 * so we don't through the lengthly process of trying to 82 * calculated it by using the PIT, RTC, etc. 83 */ 84 if (kernelSymtab->findAddress("est_cycle_freq", addr)) { 85 paddr = vtophys(physmem, addr); 86 uint8_t *est_cycle_frequency = 87 physmem->dma_addr(paddr, sizeof(uint64_t)); 88 89 if (est_cycle_frequency) 90 *(uint64_t *)est_cycle_frequency = 91 Clock::Frequency / p->boot_cpu_frequency; 92 } 93 94 95 /** 96 * EV5 only supports 127 ASNs so we are going to tell the kernel that the 97 * paritiuclar EV6 we have only supports 127 asns. 98 * @todo At some point we should change ev5.hh and the palcode to support 99 * 255 ASNs. 100 */ 101 if (kernelSymtab->findAddress("dp264_mv", addr)) { 102 paddr = vtophys(physmem, addr); 103 char *dp264_mv = (char *)physmem->dma_addr(paddr, sizeof(uint64_t)); 104 105 if (dp264_mv) { 106 *(uint32_t*)(dp264_mv+0x18) = LittleEndianGuest::htog((uint32_t)127); 107 } else 108 panic("could not translate dp264_mv addr\n"); 109 110 } else 111 panic("could not find dp264_mv\n"); 112 113#ifndef NDEBUG 114 kernelPanicEvent = addKernelFuncEvent<BreakPCEvent>("panic"); 115 if (!kernelPanicEvent) 116 panic("could not find kernel symbol \'panic\'"); 117 118#if 0 119 kernelDieEvent = addKernelFuncEvent<BreakPCEvent>("die_if_kernel"); 120 if (!kernelDieEvent) 121 panic("could not find kernel symbol \'die_if_kernel\'"); 122#endif 123 124#endif 125 126 /** 127 * Any time ide_delay_50ms, calibarte_delay or 128 * determine_cpu_caches is called just skip the 129 * function. Currently determine_cpu_caches only is used put 130 * information in proc, however if that changes in the future we 131 * will have to fill in the cache size variables appropriately. 132 */ 133 134 skipIdeDelay50msEvent = 135 addKernelFuncEvent<SkipFuncEvent>("ide_delay_50ms"); 136 skipDelayLoopEvent = 137 addKernelFuncEvent<SkipDelayLoopEvent>("calibrate_delay"); 138 skipCacheProbeEvent = 139 addKernelFuncEvent<SkipFuncEvent>("determine_cpu_caches"); 140 debugPrintkEvent = addKernelFuncEvent<DebugPrintkEvent>("dprintk"); 141 idleStartEvent = addKernelFuncEvent<IdleStartEvent>("cpu_idle"); 142 143 if (kernelSymtab->findAddress("alpha_switch_to", addr) && DTRACE(Thread)) { 144 printThreadEvent = new PrintThreadInfo(&pcEventQueue, "threadinfo", 145 addr + sizeof(MachInst) * 6); 146 } else { 147 printThreadEvent = NULL; 148 } 149 150 if (params()->bin_int) { 151 intStartEvent = addPalFuncEvent<InterruptStartEvent>("sys_int_21"); 152 if (!intStartEvent) 153 panic("could not find symbol: sys_int_21\n"); 154 155 intEndEvent = addPalFuncEvent<InterruptEndEvent>("rti_to_kern"); 156 if (!intEndEvent) 157 panic("could not find symbol: rti_to_kern\n"); 158 159 intEndEvent2 = addPalFuncEvent<InterruptEndEvent>("rti_to_user"); 160 if (!intEndEvent2) 161 panic("could not find symbol: rti_to_user\n"); 162 163 intEndEvent3 = addKernelFuncEvent<InterruptEndEvent>("do_softirq"); 164 if (!intEndEvent3) 165 panic("could not find symbol: do_softirq\n"); 166 } 167} 168 169LinuxSystem::~LinuxSystem() 170{ 171#ifndef NDEBUG 172 delete kernelPanicEvent; 173#endif 174 delete skipIdeDelay50msEvent; 175 delete skipDelayLoopEvent; 176 delete skipCacheProbeEvent; 177 delete debugPrintkEvent; 178 delete idleStartEvent; 179 delete printThreadEvent; 180 delete intStartEvent; 181 delete intEndEvent; 182 delete intEndEvent2; 183} 184 185 186void 187LinuxSystem::setDelayLoop(ExecContext *xc) 188{ 189 Addr addr = 0; 190 if (kernelSymtab->findAddress("loops_per_jiffy", addr)) { 191 Addr paddr = vtophys(physmem, addr); 192 193 uint8_t *loops_per_jiffy = 194 physmem->dma_addr(paddr, sizeof(uint32_t)); 195 196 Tick cpuFreq = xc->cpu->frequency(); 197 Tick intrFreq = platform->intrFrequency(); 198 *(uint32_t *)loops_per_jiffy = 199 (uint32_t)((cpuFreq / intrFreq) * 0.9988); 200 } 201} 202 203void 204LinuxSystem::SkipDelayLoopEvent::process(ExecContext *xc) 205{ 206 SkipFuncEvent::process(xc); 207 // calculate and set loops_per_jiffy 208 ((LinuxSystem *)xc->system)->setDelayLoop(xc); 209} 210 211void 212LinuxSystem::DebugPrintkEvent::process(ExecContext *xc) 213{ 214 if (DTRACE(DebugPrintf)) { 215 if (!raw) { 216 StringWrap name(xc->system->name() + ".dprintk"); 217 DPRINTFN(""); 218 } 219 220 AlphaArguments args(xc); 221 Printk(args); 222 SkipFuncEvent::process(xc); 223 } 224} 225 226void 227LinuxSystem::PrintThreadInfo::process(ExecContext *xc) 228{ 229 Linux::ThreadInfo ti(xc); 230 231 DPRINTF(Thread, "Currently Executing Thread %s, pid %d, started at: %d\n", 232 ti.curTaskName(), ti.curTaskPID(), ti.curTaskStart()); 233} 234 235 236BEGIN_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem) 237 238 Param<Tick> boot_cpu_frequency; 239 SimObjectParam<MemoryController *> memctrl; 240 SimObjectParam<PhysicalMemory *> physmem; 241 242 Param<string> kernel; 243 Param<string> console; 244 Param<string> pal; 245 246 Param<string> boot_osflags; 247 Param<string> readfile; 248 Param<unsigned int> init_param; 249 250 Param<uint64_t> system_type; 251 Param<uint64_t> system_rev; 252 253 Param<bool> bin; 254 VectorParam<string> binned_fns; 255 Param<bool> bin_int; 256 257END_DECLARE_SIM_OBJECT_PARAMS(LinuxSystem) 258 259BEGIN_INIT_SIM_OBJECT_PARAMS(LinuxSystem) 260 261 INIT_PARAM(boot_cpu_frequency, "Frequency of the boot CPU"), 262 INIT_PARAM(memctrl, "memory controller"), 263 INIT_PARAM(physmem, "phsyical memory"), 264 INIT_PARAM(kernel, "file that contains the kernel code"), 265 INIT_PARAM(console, "file that contains the console code"), 266 INIT_PARAM(pal, "file that contains palcode"), 267 INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot", 268 "a"), 269 INIT_PARAM_DFLT(readfile, "file to read startup script from", ""), 270 INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0), 271 INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34), 272 INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10), 273 INIT_PARAM_DFLT(bin, "is this system to be binned", false), 274 INIT_PARAM(binned_fns, "functions to be broken down and binned"), 275 INIT_PARAM_DFLT(bin_int, "is interrupt code binned seperately?", true) 276 277END_INIT_SIM_OBJECT_PARAMS(LinuxSystem) 278 279CREATE_SIM_OBJECT(LinuxSystem) 280{ 281 AlphaSystem::Params *p = new AlphaSystem::Params; 282 p->name = getInstanceName(); 283 p->boot_cpu_frequency = boot_cpu_frequency; 284 p->memctrl = memctrl; 285 p->physmem = physmem; 286 p->kernel_path = kernel; 287 p->console_path = console; 288 p->palcode = pal; 289 p->boot_osflags = boot_osflags; 290 p->init_param = init_param; 291 p->readfile = readfile; 292 p->system_type = system_type; 293 p->system_rev = system_rev; 294 p->bin = bin; 295 p->binned_fns = binned_fns; 296 p->bin_int = bin_int; 297 return new LinuxSystem(p); 298} 299 300REGISTER_SIM_OBJECT("LinuxSystem", LinuxSystem) 301 302