system.cc revision 2
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 2003 The Regents of The University of Michigan 36145Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66145Snate@binkert.org * modification, are permitted provided that the following conditions are 76145Snate@binkert.org * met: redistributions of source code must retain the above copyright 86145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116145Snate@binkert.org * documentation and/or other materials provided with the distribution; 126145Snate@binkert.org * neither the name of the copyright holders nor the names of its 136145Snate@binkert.org * contributors may be used to endorse or promote products derived from 146145Snate@binkert.org * this software without specific prior written permission. 156145Snate@binkert.org * 166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145Snate@binkert.org */ 286145Snate@binkert.org 297832Snate@binkert.org#include "kernel_loader.hh" 307547SBrad.Beckmann@amd.com#include "exec_context.hh" 317547SBrad.Beckmann@amd.com#include "object_file.hh" 328645Snilay@cs.wisc.edu#include "memory_control.hh" 337454Snate@binkert.org#include "physical_memory.hh" 347054Snate@binkert.org#include "symtab.hh" 3510301Snilay@cs.wisc.edu#include "remote_gdb.hh" 368258SBrad.Beckmann@amd.com#include "vtophys.hh" 376154Snate@binkert.org#include "system.hh" 387054Snate@binkert.org#include "trace.hh" 397547SBrad.Beckmann@amd.com 406154Snate@binkert.orgusing namespace std; 416154Snate@binkert.org 426145Snate@binkert.orgvector<System *> System::systemList; 437055Snate@binkert.org 447454Snate@binkert.orgint System::numSystemsRunning = 0; 457055Snate@binkert.org 466876Ssteve.reinhardt@amd.comSystem::System(const std::string _name, 476876Ssteve.reinhardt@amd.com MemoryController *_memCtrl, 486285Snate@binkert.org PhysicalMemory *_physmem, 498259SBrad.Beckmann@amd.com const std::string &kernel_path, 508259SBrad.Beckmann@amd.com const std::string &console_path, 518259SBrad.Beckmann@amd.com const std::string &palcode, 528259SBrad.Beckmann@amd.com const std::string &boot_osflags) 537054Snate@binkert.org : SimObject(_name), 547054Snate@binkert.org kernel_panic_event(&pcEventQueue, "kernel panic"), 557054Snate@binkert.org console_panic_event(&pcEventQueue, "console panic"), 567454Snate@binkert.org badaddr_event(&pcEventQueue, "badaddr"), 576285Snate@binkert.org skip_power_state(&pcEventQueue, "tl_v48_capture_power_state"), 589274Snilay@cs.wisc.edu skip_scavenge_boot(&pcEventQueue, "pmap_scavenge_boot"), 599593Snilay@cs.wisc.edu printf_event(&pcEventQueue, "printf"), 609593Snilay@cs.wisc.edu debug_printf_event(&pcEventQueue, "debug_printf", false), 619274Snilay@cs.wisc.edu debug_printfr_event(&pcEventQueue, "debug_printfr", true), 629858Snilay@cs.wisc.edu dump_mbuf_event(&pcEventQueue, "dump_mbuf"), 639274Snilay@cs.wisc.edu memCtrl(_memCtrl), 649274Snilay@cs.wisc.edu physmem(_physmem), 656881SBrad.Beckmann@amd.com remoteGDB(NULL), 666285Snate@binkert.org gdbListen(NULL) 677054Snate@binkert.org{ 687054Snate@binkert.org kernelSymtab = new SymbolTable; 696881SBrad.Beckmann@amd.com consoleSymtab = new SymbolTable; 707054Snate@binkert.org 716881SBrad.Beckmann@amd.com EcoffObject kernel(kernel_path); 727054Snate@binkert.org EcoffObject console(console_path); 737054Snate@binkert.org 747054Snate@binkert.org if (!kernel.loadGlobals(kernelSymtab)) 759799Snilay@cs.wisc.edu panic("could not load kernel symbols\n"); 766285Snate@binkert.org 776145Snate@binkert.org if (!console.loadGlobals(consoleSymtab)) 786145Snate@binkert.org panic("could not load console symbols\n"); 796145Snate@binkert.org 809858Snilay@cs.wisc.edu // Load pal file 817454Snate@binkert.org loadPal(palcode, physmem, PAL_BASE); 826145Snate@binkert.org 836145Snate@binkert.org // copy of initial reg file contents 846145Snate@binkert.org initRegs = new RegFile; 857054Snate@binkert.org memset(initRegs, 0, sizeof(RegFile)); 868257SBrad.Beckmann@amd.com 878257SBrad.Beckmann@amd.com // Load console file 889799Snilay@cs.wisc.edu loadKernel(console_path, physmem); 896145Snate@binkert.org 907054Snate@binkert.org // Load kernel file 919858Snilay@cs.wisc.edu loadKernel(kernel_path, physmem, initRegs, 929858Snilay@cs.wisc.edu &kernelStart, &kernelEnd, &kernelEntry); 937054Snate@binkert.org 948258SBrad.Beckmann@amd.com DPRINTF(Loader, "Kernel loaded...\n"); 958258SBrad.Beckmann@amd.com 9610311Snilay@cs.wisc.edu#ifdef FULL_SYSTEM 9710311Snilay@cs.wisc.edu Addr addr = 0; 9810311Snilay@cs.wisc.edu 998257SBrad.Beckmann@amd.com for(int i = 0; i < 12/*MAX_CPUS*/; i++) 1009858Snilay@cs.wisc.edu xc_array[i] = (ExecContext *) 0; 1016145Snate@binkert.org 1026145Snate@binkert.org num_cpus = 0; 1036145Snate@binkert.org 1047054Snate@binkert.org if (kernelSymtab->findAddress("enable_async_printf", addr)) { 1058257SBrad.Beckmann@amd.com Addr paddr = vtophys(physmem, addr); 1068257SBrad.Beckmann@amd.com uint8_t *enable_async_printf = 1079799Snilay@cs.wisc.edu physmem->dma_addr(paddr, sizeof(uint32_t)); 1086145Snate@binkert.org 1097054Snate@binkert.org if (enable_async_printf) 1109858Snilay@cs.wisc.edu *(uint32_t *)enable_async_printf = 0; 1116145Snate@binkert.org } 1126145Snate@binkert.org 1136145Snate@binkert.org if (consoleSymtab->findAddress("env_booted_osflags", addr)) { 1147054Snate@binkert.org Addr paddr = vtophys(physmem, addr); 1158257SBrad.Beckmann@amd.com char *osflags = (char *)physmem->dma_addr(paddr, sizeof(uint32_t)); 1168257SBrad.Beckmann@amd.com 1179799Snilay@cs.wisc.edu if (osflags) 1186145Snate@binkert.org strcpy(osflags, boot_osflags.c_str()); 1196145Snate@binkert.org } 12010370Snilay@cs.wisc.edu 12110370Snilay@cs.wisc.edu if (kernelSymtab->findAddress("panic", addr)) 1226145Snate@binkert.org kernel_panic_event.schedule(addr); 1237054Snate@binkert.org else 1247054Snate@binkert.org panic("could not find kernel symbol \'panic\'"); 1257054Snate@binkert.org 12610311Snilay@cs.wisc.edu if (consoleSymtab->findAddress("panic", addr)) 1277054Snate@binkert.org console_panic_event.schedule(addr); 1287454Snate@binkert.org 1297054Snate@binkert.org if (kernelSymtab->findAddress("badaddr", addr)) 13010311Snilay@cs.wisc.edu badaddr_event.schedule(addr); 13110311Snilay@cs.wisc.edu else 1327054Snate@binkert.org panic("could not find kernel symbol \'badaddr\'"); 1337454Snate@binkert.org 1347054Snate@binkert.org if (kernelSymtab->findAddress("tl_v48_capture_power_state", addr)) 13510311Snilay@cs.wisc.edu skip_power_state.schedule(addr); 1367054Snate@binkert.org 1378258SBrad.Beckmann@amd.com if (kernelSymtab->findAddress("pmap_scavenge_boot", addr)) 1388258SBrad.Beckmann@amd.com skip_scavenge_boot.schedule(addr); 1399858Snilay@cs.wisc.edu 1409858Snilay@cs.wisc.edu#if TRACING_ON 14110311Snilay@cs.wisc.edu if (kernelSymtab->findAddress("printf", addr)) 14210311Snilay@cs.wisc.edu printf_event.schedule(addr); 1437054Snate@binkert.org 1447054Snate@binkert.org if (kernelSymtab->findAddress("m5printf", addr)) 1457054Snate@binkert.org debug_printf_event.schedule(addr); 1467054Snate@binkert.org 1477054Snate@binkert.org if (kernelSymtab->findAddress("m5printfr", addr)) 1487832Snate@binkert.org debug_printfr_event.schedule(addr); 1497832Snate@binkert.org 1507054Snate@binkert.org if (kernelSymtab->findAddress("m5_dump_mbuf", addr)) 1517054Snate@binkert.org dump_mbuf_event.schedule(addr); 1527054Snate@binkert.org#endif 1537054Snate@binkert.org 1547054Snate@binkert.org#endif 1557054Snate@binkert.org 1567054Snate@binkert.org // add self to global system list 15710311Snilay@cs.wisc.edu systemList.push_back(this); 15810311Snilay@cs.wisc.edu 15910311Snilay@cs.wisc.edu numSystemsRunning++; 1607054Snate@binkert.org} 1617054Snate@binkert.org 16210370Snilay@cs.wisc.edu 16310370Snilay@cs.wisc.eduSystem::~System() 16410370Snilay@cs.wisc.edu{ 16510311Snilay@cs.wisc.edu delete kernelSymtab; 1667054Snate@binkert.org delete consoleSymtab; 1677054Snate@binkert.org delete initRegs; 16810311Snilay@cs.wisc.edu} 16910311Snilay@cs.wisc.edu 17010311Snilay@cs.wisc.edu 1717054Snate@binkert.orgvoid 1727054Snate@binkert.orgSystem::initBootContext(ExecContext *xc) 17310370Snilay@cs.wisc.edu{ 17410370Snilay@cs.wisc.edu xc->regs = *initRegs; 17510370Snilay@cs.wisc.edu 17610311Snilay@cs.wisc.edu remoteGDB = new RemoteGDB(this, xc); 1777054Snate@binkert.org gdbListen = new GDBListener(remoteGDB, 7000); 1787054Snate@binkert.org gdbListen->listen(); 1797054Snate@binkert.org 1809863Snilay@cs.wisc.edu // Reset the system 1817054Snate@binkert.org // 1829863Snilay@cs.wisc.edu TheISA::init(physmem, &xc->regs); 1839863Snilay@cs.wisc.edu} 1849863Snilay@cs.wisc.edu 1859863Snilay@cs.wisc.edu 1869863Snilay@cs.wisc.eduvoid 1879863Snilay@cs.wisc.eduSystem::registerExecContext(ExecContext *xc) 1889863Snilay@cs.wisc.edu{ 1899863Snilay@cs.wisc.edu if (num_cpus == 12/*MAX_CPUS*/) 1909863Snilay@cs.wisc.edu panic("Too many CPU's\n"); 1919863Snilay@cs.wisc.edu xc_array[xc->cpu_id] = xc; 1927547SBrad.Beckmann@amd.com num_cpus++; 1939863Snilay@cs.wisc.edu} 1949863Snilay@cs.wisc.edu 1959863Snilay@cs.wisc.edu 1969863Snilay@cs.wisc.eduvoid 1977547SBrad.Beckmann@amd.comSystem::printSystems() 1989863Snilay@cs.wisc.edu{ 1999863Snilay@cs.wisc.edu vector<System *>::iterator i = systemList.begin(); 2009863Snilay@cs.wisc.edu vector<System *>::iterator end = systemList.end(); 2019863Snilay@cs.wisc.edu for (; i != end; ++i) { 2027054Snate@binkert.org System *sys = *i; 2037054Snate@binkert.org cerr << "System " << sys->name() << ": " << hex << sys << endl; 2047054Snate@binkert.org } 2057054Snate@binkert.org} 2069863Snilay@cs.wisc.edu 2077054Snate@binkert.org 2089858Snilay@cs.wisc.eduextern "C" 2099863Snilay@cs.wisc.eduvoid 2107054Snate@binkert.orgprintSystems() 2117054Snate@binkert.org{ 2127054Snate@binkert.org System::printSystems(); 2137054Snate@binkert.org} 2147054Snate@binkert.org 2156145Snate@binkert.org 2167054Snate@binkert.orgBEGIN_DECLARE_SIM_OBJECT_PARAMS(System) 2176145Snate@binkert.org 2186876Ssteve.reinhardt@amd.com SimObjectParam<MemoryController *> mem_ctl; 2196876Ssteve.reinhardt@amd.com SimObjectParam<PhysicalMemory *> physmem; 2206876Ssteve.reinhardt@amd.com 2216876Ssteve.reinhardt@amd.com Param<string> kernel_code; 2226876Ssteve.reinhardt@amd.com Param<string> console_code; 2236876Ssteve.reinhardt@amd.com Param<string> pal_code; 2249302Snilay@cs.wisc.edu Param<string> boot_osflags; 2259302Snilay@cs.wisc.edu 2269302Snilay@cs.wisc.eduEND_DECLARE_SIM_OBJECT_PARAMS(System) 2279302Snilay@cs.wisc.edu 2289302Snilay@cs.wisc.eduBEGIN_INIT_SIM_OBJECT_PARAMS(System) 2299302Snilay@cs.wisc.edu 2309302Snilay@cs.wisc.edu INIT_PARAM(mem_ctl, "memory controller"), 2319302Snilay@cs.wisc.edu INIT_PARAM(physmem, "phsyical memory"), 2329302Snilay@cs.wisc.edu INIT_PARAM(kernel_code, "file that contains the kernel code"), 2339858Snilay@cs.wisc.edu INIT_PARAM(console_code, "file that contains the console code"), 2349858Snilay@cs.wisc.edu INIT_PARAM(pal_code, "file that contains palcode"), 2359302Snilay@cs.wisc.edu INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot", 2369302Snilay@cs.wisc.edu "a") 2379302Snilay@cs.wisc.edu 2389302Snilay@cs.wisc.eduEND_INIT_SIM_OBJECT_PARAMS(System) 2399302Snilay@cs.wisc.edu 2409302Snilay@cs.wisc.edu 2419302Snilay@cs.wisc.eduCREATE_SIM_OBJECT(System) 2429302Snilay@cs.wisc.edu{ 2439302Snilay@cs.wisc.edu System *sys = new System(getInstanceName(), mem_ctl, physmem, 2449302Snilay@cs.wisc.edu kernel_code, console_code, pal_code, 2459302Snilay@cs.wisc.edu boot_osflags); 2469302Snilay@cs.wisc.edu 2479302Snilay@cs.wisc.edu return sys; 2489302Snilay@cs.wisc.edu} 2499302Snilay@cs.wisc.edu 2509302Snilay@cs.wisc.eduREGISTER_SIM_OBJECT("System", System) 2519302Snilay@cs.wisc.edu