system.cc revision 2234
18968Snilay@cs.wisc.edu/* 28968Snilay@cs.wisc.edu * Copyright (c) 2004-2005 The Regents of The University of Michigan 38968Snilay@cs.wisc.edu * All rights reserved. 48968Snilay@cs.wisc.edu * 58968Snilay@cs.wisc.edu * Redistribution and use in source and binary forms, with or without 68968Snilay@cs.wisc.edu * modification, are permitted provided that the following conditions are 78968Snilay@cs.wisc.edu * met: redistributions of source code must retain the above copyright 88968Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer; 98968Snilay@cs.wisc.edu * redistributions in binary form must reproduce the above copyright 108968Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer in the 118968Snilay@cs.wisc.edu * documentation and/or other materials provided with the distribution; 128968Snilay@cs.wisc.edu * neither the name of the copyright holders nor the names of its 138968Snilay@cs.wisc.edu * contributors may be used to endorse or promote products derived from 148968Snilay@cs.wisc.edu * this software without specific prior written permission. 158968Snilay@cs.wisc.edu * 168968Snilay@cs.wisc.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 178968Snilay@cs.wisc.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 188968Snilay@cs.wisc.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 198968Snilay@cs.wisc.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 208968Snilay@cs.wisc.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 218968Snilay@cs.wisc.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 228968Snilay@cs.wisc.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 238968Snilay@cs.wisc.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 248968Snilay@cs.wisc.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 258968Snilay@cs.wisc.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 268968Snilay@cs.wisc.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 278968Snilay@cs.wisc.edu */ 288968Snilay@cs.wisc.edu 298968Snilay@cs.wisc.edu/** 308968Snilay@cs.wisc.edu * @file 318968Snilay@cs.wisc.edu * This code loads the linux kernel, console, pal and patches certain 328968Snilay@cs.wisc.edu * functions. The symbol tables are loaded so that traces can show 338968Snilay@cs.wisc.edu * the executing function and we can skip functions. Various delay 348968Snilay@cs.wisc.edu * loops are skipped and their final values manually computed to speed 358968Snilay@cs.wisc.edu * up boot time. 369123Sandreas.hansson@arm.com */ 378968Snilay@cs.wisc.edu 388968Snilay@cs.wisc.edu#include "arch/arguments.hh" 398968Snilay@cs.wisc.edu#include "arch/vtophys.hh" 408968Snilay@cs.wisc.edu#include "arch/alpha/linux/system.hh" 418968Snilay@cs.wisc.edu#include "arch/alpha/linux/threadinfo.hh" 428968Snilay@cs.wisc.edu#include "arch/alpha/system.hh" 438968Snilay@cs.wisc.edu#include "base/loader/symtab.hh" 448968Snilay@cs.wisc.edu#include "cpu/exec_context.hh" 458968Snilay@cs.wisc.edu#include "cpu/base.hh" 468968Snilay@cs.wisc.edu#include "dev/platform.hh" 478968Snilay@cs.wisc.edu#include "kern/linux/printk.hh" 488968Snilay@cs.wisc.edu#include "kern/linux/events.hh" 498968Snilay@cs.wisc.edu#include "mem/functional/memory_control.hh" 508968Snilay@cs.wisc.edu#include "mem/functional/physical.hh" 518968Snilay@cs.wisc.edu#include "sim/builder.hh" 528968Snilay@cs.wisc.edu#include "sim/byteswap.hh" 538968Snilay@cs.wisc.edu 548968Snilay@cs.wisc.eduusing namespace std; 558968Snilay@cs.wisc.eduusing namespace AlphaISA; 568968Snilay@cs.wisc.eduusing namespace Linux; 578968Snilay@cs.wisc.edu 589826Sandreas.hansson@arm.comLinuxAlphaSystem::LinuxAlphaSystem(Params *p) 599802Snilay@cs.wisc.edu : AlphaSystem(p) 609827Sakash.bagdia@arm.com{ 619827Sakash.bagdia@arm.com Addr addr = 0; 629793Sakash.bagdia@arm.com Addr paddr = 0; 638968Snilay@cs.wisc.edu 649827Sakash.bagdia@arm.com /** 659827Sakash.bagdia@arm.com * The symbol swapper_pg_dir marks the beginning of the kernel and 669827Sakash.bagdia@arm.com * the location of bootloader passed arguments 679827Sakash.bagdia@arm.com */ 689802Snilay@cs.wisc.edu if (!kernelSymtab->findAddress("swapper_pg_dir", KernelStart)) { 699802Snilay@cs.wisc.edu panic("Could not determine start location of kernel"); 709793Sakash.bagdia@arm.com } 7110118Snilay@cs.wisc.edu 728968Snilay@cs.wisc.edu /** 739793Sakash.bagdia@arm.com * Since we aren't using a bootloader, we have to copy the 749827Sakash.bagdia@arm.com * kernel arguments directly into the kernel's memory. 759827Sakash.bagdia@arm.com */ 769793Sakash.bagdia@arm.com paddr = vtophys(physmem, CommandLine()); 778968Snilay@cs.wisc.edu char *commandline = (char *)physmem->dma_addr(paddr, sizeof(uint64_t)); 788968Snilay@cs.wisc.edu if (commandline) 798968Snilay@cs.wisc.edu strncpy(commandline, params()->boot_osflags.c_str(), CommandLineSize); 808968Snilay@cs.wisc.edu 818968Snilay@cs.wisc.edu /** 828968Snilay@cs.wisc.edu * find the address of the est_cycle_freq variable and insert it 838968Snilay@cs.wisc.edu * so we don't through the lengthly process of trying to 848968Snilay@cs.wisc.edu * calculated it by using the PIT, RTC, etc. 8510090Snilay@cs.wisc.edu */ 8610090Snilay@cs.wisc.edu if (kernelSymtab->findAddress("est_cycle_freq", addr)) { 8710090Snilay@cs.wisc.edu paddr = vtophys(physmem, addr); 888968Snilay@cs.wisc.edu uint8_t *est_cycle_frequency = 899577Snilay@cs.wisc.edu physmem->dma_addr(paddr, sizeof(uint64_t)); 909577Snilay@cs.wisc.edu 919577Snilay@cs.wisc.edu if (est_cycle_frequency) 929835Sandreas.hansson@arm.com *(uint64_t *)est_cycle_frequency = 939826Sandreas.hansson@arm.com Clock::Frequency / p->boot_cpu_frequency; 949826Sandreas.hansson@arm.com } 9510118Snilay@cs.wisc.edu 969826Sandreas.hansson@arm.com 978968Snilay@cs.wisc.edu /** 988968Snilay@cs.wisc.edu * EV5 only supports 127 ASNs so we are going to tell the kernel that the 99 * paritiuclar EV6 we have only supports 127 asns. 100 * @todo At some point we should change ev5.hh and the palcode to support 101 * 255 ASNs. 102 */ 103 if (kernelSymtab->findAddress("dp264_mv", addr)) { 104 paddr = vtophys(physmem, addr); 105 char *dp264_mv = (char *)physmem->dma_addr(paddr, sizeof(uint64_t)); 106 107 if (dp264_mv) { 108 *(uint32_t*)(dp264_mv+0x18) = LittleEndianGuest::htog((uint32_t)127); 109 } else 110 panic("could not translate dp264_mv addr\n"); 111 112 } else 113 panic("could not find dp264_mv\n"); 114 115#ifndef NDEBUG 116 kernelPanicEvent = addKernelFuncEvent<BreakPCEvent>("panic"); 117 if (!kernelPanicEvent) 118 panic("could not find kernel symbol \'panic\'"); 119 120#if 0 121 kernelDieEvent = addKernelFuncEvent<BreakPCEvent>("die_if_kernel"); 122 if (!kernelDieEvent) 123 panic("could not find kernel symbol \'die_if_kernel\'"); 124#endif 125 126#endif 127 128 /** 129 * Any time ide_delay_50ms, calibarte_delay or 130 * determine_cpu_caches is called just skip the 131 * function. Currently determine_cpu_caches only is used put 132 * information in proc, however if that changes in the future we 133 * will have to fill in the cache size variables appropriately. 134 */ 135 136 skipIdeDelay50msEvent = 137 addKernelFuncEvent<SkipFuncEvent>("ide_delay_50ms"); 138 skipDelayLoopEvent = 139 addKernelFuncEvent<SkipDelayLoopEvent>("calibrate_delay"); 140 skipCacheProbeEvent = 141 addKernelFuncEvent<SkipFuncEvent>("determine_cpu_caches"); 142 debugPrintkEvent = addKernelFuncEvent<DebugPrintkEvent>("dprintk"); 143 idleStartEvent = addKernelFuncEvent<IdleStartEvent>("cpu_idle"); 144 145 if (kernelSymtab->findAddress("alpha_switch_to", addr) && DTRACE(Thread)) { 146 printThreadEvent = new PrintThreadInfo(&pcEventQueue, "threadinfo", 147 addr + sizeof(MachInst) * 6); 148 } else { 149 printThreadEvent = NULL; 150 } 151 152 if (params()->bin_int) { 153 intStartEvent = addPalFuncEvent<InterruptStartEvent>("sys_int_21"); 154 if (!intStartEvent) 155 panic("could not find symbol: sys_int_21\n"); 156 157 intEndEvent = addPalFuncEvent<InterruptEndEvent>("rti_to_kern"); 158 if (!intEndEvent) 159 panic("could not find symbol: rti_to_kern\n"); 160 161 intEndEvent2 = addPalFuncEvent<InterruptEndEvent>("rti_to_user"); 162 if (!intEndEvent2) 163 panic("could not find symbol: rti_to_user\n"); 164 165 intEndEvent3 = addKernelFuncEvent<InterruptEndEvent>("do_softirq"); 166 if (!intEndEvent3) 167 panic("could not find symbol: do_softirq\n"); 168 } 169} 170 171LinuxAlphaSystem::~LinuxAlphaSystem() 172{ 173#ifndef NDEBUG 174 delete kernelPanicEvent; 175#endif 176 delete skipIdeDelay50msEvent; 177 delete skipDelayLoopEvent; 178 delete skipCacheProbeEvent; 179 delete debugPrintkEvent; 180 delete idleStartEvent; 181 delete printThreadEvent; 182 delete intStartEvent; 183 delete intEndEvent; 184 delete intEndEvent2; 185} 186 187 188void 189LinuxAlphaSystem::setDelayLoop(ExecContext *xc) 190{ 191 Addr addr = 0; 192 if (kernelSymtab->findAddress("loops_per_jiffy", addr)) { 193 Addr paddr = vtophys(physmem, addr); 194 195 uint8_t *loops_per_jiffy = 196 physmem->dma_addr(paddr, sizeof(uint32_t)); 197 198 Tick cpuFreq = xc->getCpuPtr()->frequency(); 199 Tick intrFreq = platform->intrFrequency(); 200 *(uint32_t *)loops_per_jiffy = 201 (uint32_t)((cpuFreq / intrFreq) * 0.9988); 202 } 203} 204 205 206void 207LinuxAlphaSystem::SkipDelayLoopEvent::process(ExecContext *xc) 208{ 209 SkipFuncEvent::process(xc); 210 // calculate and set loops_per_jiffy 211 ((LinuxAlphaSystem *)xc->getSystemPtr())->setDelayLoop(xc); 212} 213 214void 215LinuxAlphaSystem::PrintThreadInfo::process(ExecContext *xc) 216{ 217 Linux::ThreadInfo ti(xc); 218 219 DPRINTF(Thread, "Currently Executing Thread %s, pid %d, started at: %d\n", 220 ti.curTaskName(), ti.curTaskPID(), ti.curTaskStart()); 221} 222 223 224BEGIN_DECLARE_SIM_OBJECT_PARAMS(LinuxAlphaSystem) 225 226 Param<Tick> boot_cpu_frequency; 227 SimObjectParam<MemoryController *> memctrl; 228 SimObjectParam<PhysicalMemory *> physmem; 229 230 Param<string> kernel; 231 Param<string> console; 232 Param<string> pal; 233 234 Param<string> boot_osflags; 235 Param<string> readfile; 236 Param<unsigned int> init_param; 237 238 Param<uint64_t> system_type; 239 Param<uint64_t> system_rev; 240 241 Param<bool> bin; 242 VectorParam<string> binned_fns; 243 Param<bool> bin_int; 244 245END_DECLARE_SIM_OBJECT_PARAMS(LinuxAlphaSystem) 246 247BEGIN_INIT_SIM_OBJECT_PARAMS(LinuxAlphaSystem) 248 249 INIT_PARAM(boot_cpu_frequency, "Frequency of the boot CPU"), 250 INIT_PARAM(memctrl, "memory controller"), 251 INIT_PARAM(physmem, "phsyical memory"), 252 INIT_PARAM(kernel, "file that contains the kernel code"), 253 INIT_PARAM(console, "file that contains the console code"), 254 INIT_PARAM(pal, "file that contains palcode"), 255 INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot", 256 "a"), 257 INIT_PARAM_DFLT(readfile, "file to read startup script from", ""), 258 INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0), 259 INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34), 260 INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10), 261 INIT_PARAM_DFLT(bin, "is this system to be binned", false), 262 INIT_PARAM(binned_fns, "functions to be broken down and binned"), 263 INIT_PARAM_DFLT(bin_int, "is interrupt code binned seperately?", true) 264 265END_INIT_SIM_OBJECT_PARAMS(LinuxAlphaSystem) 266 267CREATE_SIM_OBJECT(LinuxAlphaSystem) 268{ 269 AlphaSystem::Params *p = new AlphaSystem::Params; 270 p->name = getInstanceName(); 271 p->boot_cpu_frequency = boot_cpu_frequency; 272 p->memctrl = memctrl; 273 p->physmem = physmem; 274 p->kernel_path = kernel; 275 p->console_path = console; 276 p->palcode = pal; 277 p->boot_osflags = boot_osflags; 278 p->init_param = init_param; 279 p->readfile = readfile; 280 p->system_type = system_type; 281 p->system_rev = system_rev; 282 p->bin = bin; 283 p->binned_fns = binned_fns; 284 p->bin_int = bin_int; 285 return new LinuxAlphaSystem(p); 286} 287 288REGISTER_SIM_OBJECT("LinuxAlphaSystem", LinuxAlphaSystem) 289 290