system.cc revision 2158
1451SN/A/* 21762SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 3451SN/A * All rights reserved. 4451SN/A * 5451SN/A * Redistribution and use in source and binary forms, with or without 6451SN/A * modification, are permitted provided that the following conditions are 7451SN/A * met: redistributions of source code must retain the above copyright 8451SN/A * notice, this list of conditions and the following disclaimer; 9451SN/A * redistributions in binary form must reproduce the above copyright 10451SN/A * notice, this list of conditions and the following disclaimer in the 11451SN/A * documentation and/or other materials provided with the distribution; 12451SN/A * neither the name of the copyright holders nor the names of its 13451SN/A * contributors may be used to endorse or promote products derived from 14451SN/A * this software without specific prior written permission. 15451SN/A * 16451SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17451SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18451SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19451SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20451SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21451SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22451SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23451SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24451SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25451SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26451SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu */ 282665Ssaidi@eecs.umich.edu 292665Ssaidi@eecs.umich.edu/** 302665Ssaidi@eecs.umich.edu * @file 312665Ssaidi@eecs.umich.edu * This code loads the linux kernel, console, pal and patches certain 32451SN/A * functions. The symbol tables are loaded so that traces can show 33451SN/A * the executing function and we can skip functions. Various delay 34885SN/A * loops are skipped and their final values manually computed to speed 35885SN/A * up boot time. 361040SN/A */ 371040SN/A 381040SN/A#include "arch/alpha/system.hh" 391040SN/A#include "base/loader/symtab.hh" 401040SN/A#include "cpu/exec_context.hh" 41885SN/A#include "cpu/base.hh" 42885SN/A#include "kern/linux/linux_system.hh" 432212SN/A#include "kern/linux/linux_threadinfo.hh" 4411793Sbrandon.potter@amd.com#include "kern/linux/printk.hh" 458229Snate@binkert.org#include "mem/functional/memory_control.hh" 462158SN/A#include "mem/functional/physical.hh" 479329Sdam.sunwoo@arm.com#include "sim/builder.hh" 488229Snate@binkert.org#include "sim/byteswap.hh" 491180SN/A#include "dev/platform.hh" 508229Snate@binkert.org#include "targetarch/arguments.hh" 512680Sktlim@umich.edu#include "targetarch/vtophys.hh" 528232Snate@binkert.org 538229Snate@binkert.orgusing namespace std; 541885SN/Ausing namespace TheISA; 552521SN/A 562521SN/ALinuxSystem::LinuxSystem(Params *p) 574826Ssaidi@eecs.umich.edu : AlphaSystem(p) 582036SN/A{ 59451SN/A Addr addr = 0; 60451SN/A Addr paddr = 0; 612212SN/A 622212SN/A /** 63451SN/A * The symbol swapper_pg_dir marks the beginning of the kernel and 642212SN/A * the location of bootloader passed arguments 652158SN/A */ 66451SN/A if (!kernelSymtab->findAddress("swapper_pg_dir", KernelStart)) { 678706Sandreas.hansson@arm.com panic("Could not determine start location of kernel"); 688706Sandreas.hansson@arm.com } 698706Sandreas.hansson@arm.com 708706Sandreas.hansson@arm.com /** 718706Sandreas.hansson@arm.com * Since we aren't using a bootloader, we have to copy the 728706Sandreas.hansson@arm.com * kernel arguments directly into the kernel's memory. 738706Sandreas.hansson@arm.com */ 748706Sandreas.hansson@arm.com paddr = vtophys(physmem, CommandLine()); 758706Sandreas.hansson@arm.com char *commandline = (char *)physmem->dma_addr(paddr, sizeof(uint64_t)); 768706Sandreas.hansson@arm.com if (commandline) 778706Sandreas.hansson@arm.com strncpy(commandline, params()->boot_osflags.c_str(), CommandLineSize); 78451SN/A 791855SN/A /** 801855SN/A * find the address of the est_cycle_freq variable and insert it 811855SN/A * so we don't through the lengthly process of trying to 821855SN/A * calculated it by using the PIT, RTC, etc. 831855SN/A */ 841855SN/A if (kernelSymtab->findAddress("est_cycle_freq", addr)) { 851855SN/A paddr = vtophys(physmem, addr); 861855SN/A uint8_t *est_cycle_frequency = 871855SN/A physmem->dma_addr(paddr, sizeof(uint64_t)); 881855SN/A 891855SN/A if (est_cycle_frequency) 901855SN/A *(uint64_t *)est_cycle_frequency = 911855SN/A Clock::Frequency / p->boot_cpu_frequency; 928852Sandreas.hansson@arm.com } 9314010Sgabeblack@google.com 9414010Sgabeblack@google.com 95836SN/A /** 96885SN/A * EV5 only supports 127 ASNs so we are going to tell the kernel that the 971070SN/A * paritiuclar EV6 we have only supports 127 asns. 981070SN/A * @todo At some point we should change ev5.hh and the palcode to support 991070SN/A * 255 ASNs. 100885SN/A */ 1012521SN/A if (kernelSymtab->findAddress("dp264_mv", addr)) { 1028852Sandreas.hansson@arm.com paddr = vtophys(physmem, addr); 1038852Sandreas.hansson@arm.com char *dp264_mv = (char *)physmem->dma_addr(paddr, sizeof(uint64_t)); 104451SN/A 105836SN/A if (dp264_mv) { 106885SN/A *(uint32_t*)(dp264_mv+0x18) = LittleEndianGuest::htog((uint32_t)127); 107943SN/A } else 108943SN/A panic("could not translate dp264_mv addr\n"); 109943SN/A 110943SN/A } else 111943SN/A panic("could not find dp264_mv\n"); 1122521SN/A 1138852Sandreas.hansson@arm.com#ifndef NDEBUG 1142521SN/A kernelPanicEvent = addKernelFuncEvent<BreakPCEvent>("panic"); 1151070SN/A if (!kernelPanicEvent) 116943SN/A panic("could not find kernel symbol \'panic\'"); 1178885SAli.Saidi@ARM.com 1188885SAli.Saidi@ARM.com#if 0 1198885SAli.Saidi@ARM.com kernelDieEvent = addKernelFuncEvent<BreakPCEvent>("die_if_kernel"); 1208885SAli.Saidi@ARM.com if (!kernelDieEvent) 1218885SAli.Saidi@ARM.com panic("could not find kernel symbol \'die_if_kernel\'"); 1228885SAli.Saidi@ARM.com#endif 1231492SN/A 1249645SAndreas.Sandberg@ARM.com#endif 1251885SN/A 126860SN/A /** 127451SN/A * Any time ide_delay_50ms, calibarte_delay or 128885SN/A * determine_cpu_caches is called just skip the 1291895SN/A * function. Currently determine_cpu_caches only is used put 1301070SN/A * information in proc, however if that changes in the future we 1311070SN/A * will have to fill in the cache size variables appropriately. 1321070SN/A */ 1331070SN/A 134885SN/A skipIdeDelay50msEvent = 135848SN/A addKernelFuncEvent<SkipFuncEvent>("ide_delay_50ms"); 1361885SN/A skipDelayLoopEvent = 1371885SN/A addKernelFuncEvent<SkipDelayLoopEvent>("calibrate_delay"); 1381885SN/A skipCacheProbeEvent = 1391885SN/A addKernelFuncEvent<SkipFuncEvent>("determine_cpu_caches"); 1401885SN/A debugPrintkEvent = addKernelFuncEvent<DebugPrintkEvent>("dprintk"); 1411885SN/A idleStartEvent = addKernelFuncEvent<IdleStartEvent>("cpu_idle"); 1421885SN/A 1431885SN/A if (kernelSymtab->findAddress("alpha_switch_to", addr) && DTRACE(Thread)) { 1441885SN/A printThreadEvent = new PrintThreadInfo(&pcEventQueue, "threadinfo", 1454741Sstever@eecs.umich.edu addr + sizeof(MachInst) * 6); 1464741Sstever@eecs.umich.edu } else { 1474741Sstever@eecs.umich.edu printThreadEvent = NULL; 1484741Sstever@eecs.umich.edu } 1494741Sstever@eecs.umich.edu 1508885SAli.Saidi@ARM.com if (params()->bin_int) { 1514741Sstever@eecs.umich.edu intStartEvent = addPalFuncEvent<InterruptStartEvent>("sys_int_21"); 1521885SN/A if (!intStartEvent) 1531885SN/A panic("could not find symbol: sys_int_21\n"); 1541885SN/A 1551885SN/A intEndEvent = addPalFuncEvent<InterruptEndEvent>("rti_to_kern"); 1561657SN/A if (!intEndEvent) 157451SN/A panic("could not find symbol: rti_to_kern\n"); 158451SN/A 1592212SN/A intEndEvent2 = addPalFuncEvent<InterruptEndEvent>("rti_to_user"); 160451SN/A if (!intEndEvent2) 1611492SN/A panic("could not find symbol: rti_to_user\n"); 162451SN/A 1631070SN/A intEndEvent3 = addKernelFuncEvent<InterruptEndEvent>("do_softirq"); 164869SN/A if (!intEndEvent3) 165869SN/A panic("could not find symbol: do_softirq\n"); 166869SN/A } 1671070SN/A} 1681070SN/A 1691082SN/ALinuxSystem::~LinuxSystem() 170451SN/A{ 171451SN/A#ifndef NDEBUG 172803SN/A delete kernelPanicEvent; 1732680Sktlim@umich.edu#endif 174803SN/A delete skipIdeDelay50msEvent; 175803SN/A delete skipDelayLoopEvent; 176803SN/A delete skipCacheProbeEvent; 1772680Sktlim@umich.edu delete debugPrintkEvent; 1788741Sgblack@eecs.umich.edu delete idleStartEvent; 1798852Sandreas.hansson@arm.com delete printThreadEvent; 18013893Sgabeblack@google.com delete intStartEvent; 18113893Sgabeblack@google.com delete intEndEvent; 182803SN/A delete intEndEvent2; 183803SN/A} 184803SN/A 1851885SN/A 1862680Sktlim@umich.eduvoid 1871885SN/ALinuxSystem::setDelayLoop(ExecContext *xc) 1882680Sktlim@umich.edu{ 1891885SN/A Addr addr = 0; 1902680Sktlim@umich.edu if (kernelSymtab->findAddress("loops_per_jiffy", addr)) { 1911885SN/A Addr paddr = vtophys(physmem, addr); 1921885SN/A 1931885SN/A uint8_t *loops_per_jiffy = 1942680Sktlim@umich.edu physmem->dma_addr(paddr, sizeof(uint32_t)); 1951885SN/A 1962680Sktlim@umich.edu Tick cpuFreq = xc->cpu->frequency(); 1971885SN/A Tick intrFreq = platform->intrFrequency(); 1981885SN/A *(uint32_t *)loops_per_jiffy = 1991885SN/A (uint32_t)((cpuFreq / intrFreq) * 0.9988); 2001885SN/A } 2011885SN/A} 2024762Snate@binkert.org 2034762Snate@binkert.orgvoid 204451SN/ALinuxSystem::SkipDelayLoopEvent::process(ExecContext *xc) 2054762Snate@binkert.org{ 206451SN/A 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