system.cc revision 5714
12689Sktlim@umich.edu/* 29814Sandreas.hansson@arm.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 38666SPrakash.Ramrakhyani@arm.com * Copyright (c) 2007 MIPS Technologies, Inc. 48666SPrakash.Ramrakhyani@arm.com * All rights reserved. 58666SPrakash.Ramrakhyani@arm.com * 68666SPrakash.Ramrakhyani@arm.com * Redistribution and use in source and binary forms, with or without 78666SPrakash.Ramrakhyani@arm.com * modification, are permitted provided that the following conditions are 88666SPrakash.Ramrakhyani@arm.com * met: redistributions of source code must retain the above copyright 98666SPrakash.Ramrakhyani@arm.com * notice, this list of conditions and the following disclaimer; 108666SPrakash.Ramrakhyani@arm.com * redistributions in binary form must reproduce the above copyright 118666SPrakash.Ramrakhyani@arm.com * notice, this list of conditions and the following disclaimer in the 128666SPrakash.Ramrakhyani@arm.com * documentation and/or other materials provided with the distribution; 138666SPrakash.Ramrakhyani@arm.com * neither the name of the copyright holders nor the names of its 142689Sktlim@umich.edu * contributors may be used to endorse or promote products derived from 157897Shestness@cs.utexas.edu * this software without specific prior written permission. 162689Sktlim@umich.edu * 172689Sktlim@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182689Sktlim@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192689Sktlim@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202689Sktlim@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212689Sktlim@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222689Sktlim@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232689Sktlim@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242689Sktlim@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252689Sktlim@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262689Sktlim@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272689Sktlim@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282689Sktlim@umich.edu * 292689Sktlim@umich.edu * Authors: Ali Saidi 302689Sktlim@umich.edu * Nathan Binkert 312689Sktlim@umich.edu * Jaidev Patwardhan 322689Sktlim@umich.edu */ 332689Sktlim@umich.edu 342689Sktlim@umich.edu#include "arch/mips/system.hh" 352689Sktlim@umich.edu#include "arch/vtophys.hh" 362689Sktlim@umich.edu#include "base/remote_gdb.hh" 372689Sktlim@umich.edu#include "base/loader/object_file.hh" 382689Sktlim@umich.edu#include "base/loader/hex_file.hh" 392689Sktlim@umich.edu#include "base/loader/symtab.hh" 402689Sktlim@umich.edu#include "base/trace.hh" 412689Sktlim@umich.edu#include "mem/physical.hh" 422689Sktlim@umich.edu#include "params/MipsSystem.hh" 432689Sktlim@umich.edu#include "sim/byteswap.hh" 442689Sktlim@umich.edu 457897Shestness@cs.utexas.edu 462689Sktlim@umich.eduusing namespace LittleEndianGuest; 472689Sktlim@umich.edu 482521SN/AMipsSystem::MipsSystem(Params *p) 493960Sgblack@eecs.umich.edu : System(p) 504194Ssaidi@eecs.umich.edu{ 511070SN/A 521070SN/A#if FULL_SYSTEM 539142Ssteve.reinhardt@amd.com if (p->bare_iron == true) { 542521SN/A hexFile = new HexFile(params()->hex_file_name); 556658Snate@binkert.org if(!hexFile->loadSections(&functionalPort,MipsISA::LoadAddrMask)) 568229Snate@binkert.org panic("Could not load hex file\n"); 578232Snate@binkert.org } 588666SPrakash.Ramrakhyani@arm.com 598769Sgblack@eecs.umich.edu Addr addr = 0; 609293Sandreas.hansson@arm.com /* Comment out old Alpha Based Code 612522SN/A 628769Sgblack@eecs.umich.edu Don't need the console before we start looking at booting linux */ 632037SN/A 648229Snate@binkert.org 658769Sgblack@eecs.umich.edu consoleSymtab = new SymbolTable; 6656SN/A 676658Snate@binkert.org 682SN/A /** 692107SN/A * Load the console code into memory 702SN/A */ 712SN/A // Load Console Code 722SN/A console = createObjectFile(params()->console); 732SN/A 742SN/A warn("console code is located at: %s\n", params()->console); 751070SN/A 768703Sandreas.hansson@arm.com if (console == NULL) 778703Sandreas.hansson@arm.com fatal("Could not load console file %s", params()->console); 788826Snilay@cs.wisc.edu //Load program sections into memory 792521SN/A console->loadSections(&functionalPort, MipsISA::LoadAddrMask); 809814Sandreas.hansson@arm.com 817580SAli.Saidi@arm.com //load symbols 827770SAli.Saidi@ARM.com if (!console->loadGlobalSymbols(consoleSymtab)) 839293Sandreas.hansson@arm.com panic("could not load console symbols\n"); 847914SBrad.Beckmann@amd.com 859814Sandreas.hansson@arm.com if (!console->loadGlobalSymbols(debugSymbolTable)) 867914SBrad.Beckmann@amd.com panic("could not load console symbols\n"); 877914SBrad.Beckmann@amd.com 888666SPrakash.Ramrakhyani@arm.com 897914SBrad.Beckmann@amd.com#ifndef NDEBUG 908666SPrakash.Ramrakhyani@arm.com consolePanicEvent = addConsoleFuncEvent<BreakPCEvent>("panic"); 917897Shestness@cs.utexas.edu#endif 922SN/A 931070SN/A /** 941070SN/A * Copy the osflags (kernel arguments) into the consoles 951070SN/A * memory. (Presently Linux does not use the console service 968769Sgblack@eecs.umich.edu * routine to get these command line arguments, but Tru64 and 978769Sgblack@eecs.umich.edu * others do.) 988769Sgblack@eecs.umich.edu */ 998769Sgblack@eecs.umich.edu if (consoleSymtab->findAddress("env_booted_osflags", addr)) { 1008666SPrakash.Ramrakhyani@arm.com warn("writing addr starting from %#x", addr); 1018832SAli.Saidi@ARM.com cout << "-" << endl; 1029814Sandreas.hansson@arm.com virtPort.writeBlob(addr, (uint8_t*)params()->boot_osflags.c_str(), 1039814Sandreas.hansson@arm.com strlen(params()->boot_osflags.c_str())); 1049814Sandreas.hansson@arm.com } 1059814Sandreas.hansson@arm.com 1069814Sandreas.hansson@arm.com /** 1078832SAli.Saidi@ARM.com * Set the hardware reset parameter block system type and revision 1088832SAli.Saidi@ARM.com * information to Tsunami. 1098832SAli.Saidi@ARM.com */ 1108832SAli.Saidi@ARM.com if (consoleSymtab->findAddress("m5_rpb", addr)) { 1118832SAli.Saidi@ARM.com uint64_t data; 1128832SAli.Saidi@ARM.com data = htog(params()->system_type); 1138832SAli.Saidi@ARM.com virtPort.write(addr+0x50, data); 1148832SAli.Saidi@ARM.com data = htog(params()->system_rev); 1158832SAli.Saidi@ARM.com virtPort.write(addr+0x58, data); 1168885SAli.Saidi@ARM.com } else 1178885SAli.Saidi@ARM.com panic("could not find hwrpb\n"); 1188885SAli.Saidi@ARM.com#endif 1199147Snilay@cs.wisc.edu} 1209147Snilay@cs.wisc.edu 1219147Snilay@cs.wisc.eduMipsSystem::~MipsSystem() 1228885SAli.Saidi@ARM.com{ 1238885SAli.Saidi@ARM.com} 1248885SAli.Saidi@ARM.com#if FULL_SYSTEM 1258885SAli.Saidi@ARM.com/** 1268885SAli.Saidi@ARM.com * This function fixes up addresses that are used to match PCs for 1278885SAli.Saidi@ARM.com * hooking simulator events on to target function executions. 1288885SAli.Saidi@ARM.com * 1298885SAli.Saidi@ARM.com * Mips binaries may have multiple global offset table (GOT) 1308885SAli.Saidi@ARM.com * sections. A function that uses the GOT starts with a 1318885SAli.Saidi@ARM.com * two-instruction prolog which sets the global pointer (gp == r29) to 1328885SAli.Saidi@ARM.com * the appropriate GOT section. The proper gp value is calculated 1338885SAli.Saidi@ARM.com * based on the function address, which must be passed by the caller 1348885SAli.Saidi@ARM.com * in the procedure value register (pv aka t12 == r27). This sequence 1358885SAli.Saidi@ARM.com * looks like the following: 1368885SAli.Saidi@ARM.com * 1378885SAli.Saidi@ARM.com * opcode Ra Rb offset 1388885SAli.Saidi@ARM.com * ldah gp,X(pv) 09 29 27 X 1398885SAli.Saidi@ARM.com * lda gp,Y(gp) 08 29 29 Y 1408885SAli.Saidi@ARM.com * 1418885SAli.Saidi@ARM.com * for some constant offsets X and Y. The catch is that the linker 1428885SAli.Saidi@ARM.com * (or maybe even the compiler, I'm not sure) may recognize that the 1438885SAli.Saidi@ARM.com * caller and callee are using the same GOT section, making this 1448885SAli.Saidi@ARM.com * prolog redundant, and modify the call target to skip these 1458885SAli.Saidi@ARM.com * instructions. If we check for execution of the first instruction 1468885SAli.Saidi@ARM.com * of a function (the one the symbol points to) to detect when to skip 1478885SAli.Saidi@ARM.com * it, we'll miss all these modified calls. It might work to 1488885SAli.Saidi@ARM.com * unconditionally check for the third instruction, but not all 1498885SAli.Saidi@ARM.com * functions have this prolog, and there's some chance that those 1508885SAli.Saidi@ARM.com * first two instructions could have undesired consequences. So we do 1518885SAli.Saidi@ARM.com * the Right Thing and pattern-match the first two instructions of the 1528885SAli.Saidi@ARM.com * function to decide where to patch. 1538885SAli.Saidi@ARM.com * 1548885SAli.Saidi@ARM.com * Eventually this code should be moved into an ISA-specific file. 1558885SAli.Saidi@ARM.com */ 1569053Sdam.sunwoo@arm.com 1579053Sdam.sunwoo@arm.comAddr 1589053Sdam.sunwoo@arm.comMipsSystem::fixFuncEventAddr(Addr addr) 1592SN/A{ 1602SN/A /* 1612SN/A // mask for just the opcode, Ra, and Rb fields (not the offset) 1622SN/A const uint32_t inst_mask = 0xffff0000; 1631070SN/A // ldah gp,X(pv): opcode 9, Ra = 29, Rb = 27 1641070SN/A const uint32_t gp_ldah_pattern = (9 << 26) | (29 << 21) | (27 << 16); 1658666SPrakash.Ramrakhyani@arm.com // lda gp,Y(gp): opcode 8, Ra = 29, rb = 29 1668666SPrakash.Ramrakhyani@arm.com const uint32_t gp_lda_pattern = (8 << 26) | (29 << 21) | (29 << 16); 1678666SPrakash.Ramrakhyani@arm.com 1682SN/A uint32_t i1 = virtPort.read<uint32_t>(addr); 1692SN/A uint32_t i2 = virtPort.read<uint32_t>(addr + sizeof(MipsISA::MachInst)); 1708706Sandreas.hansson@arm.com 1718706Sandreas.hansson@arm.com if ((i1 & inst_mask) == gp_ldah_pattern && 1728706Sandreas.hansson@arm.com (i2 & inst_mask) == gp_lda_pattern) { 1738706Sandreas.hansson@arm.com Addr new_addr = addr + 2* sizeof(MipsISA::MachInst); 1748706Sandreas.hansson@arm.com DPRINTF(Loader, "fixFuncEventAddr: %p -> %p", addr, new_addr); 1758706Sandreas.hansson@arm.com return new_addr; 1768706Sandreas.hansson@arm.com } else { 1778706Sandreas.hansson@arm.com return addr; 1789294Sandreas.hansson@arm.com }*/ 1799294Sandreas.hansson@arm.com return addr; 1808703Sandreas.hansson@arm.com} 1818703Sandreas.hansson@arm.com 1828922Swilliam.wang@arm.com 1838703Sandreas.hansson@arm.comvoid 1848703Sandreas.hansson@arm.comMipsSystem::setMipsAccess(Addr access) 1852901Ssaidi@eecs.umich.edu{ 1864762Snate@binkert.org Addr addr = 0; 1872901Ssaidi@eecs.umich.edu if (consoleSymtab->findAddress("m5MipsAccess", addr)) { 1889342SAndreas.Sandberg@arm.com // virtPort.write(addr, htog(AlphaISA::Phys2K0Seg(access))); 1892901Ssaidi@eecs.umich.edu } else 1902901Ssaidi@eecs.umich.edu panic("could not find m5MipsAccess\n"); 1912901Ssaidi@eecs.umich.edu } 1923960Sgblack@eecs.umich.edu 1933960Sgblack@eecs.umich.edu#endif 1944095Sbinkertn@umich.edu 1954095Sbinkertn@umich.edubool 1964095Sbinkertn@umich.eduMipsSystem::breakpoint() 1973960Sgblack@eecs.umich.edu{ 1983960Sgblack@eecs.umich.edu return 0; 1997445Ssteve.reinhardt@amd.com // return remoteGDB[0]->trap(MIPS_KENTRY_INT); 2007445Ssteve.reinhardt@amd.com} 2017445Ssteve.reinhardt@amd.com 2027445Ssteve.reinhardt@amd.comvoid 2037445Ssteve.reinhardt@amd.comMipsSystem::serialize(std::ostream &os) 2047445Ssteve.reinhardt@amd.com{ 2057445Ssteve.reinhardt@amd.com System::serialize(os); 206180SN/A // consoleSymtab->serialize("console_symtab", os); 2075718Shsul@eecs.umich.edu} 2082SN/A 2095712Shsul@eecs.umich.edu 2105718Shsul@eecs.umich.eduvoid 2115718Shsul@eecs.umich.eduMipsSystem::unserialize(Checkpoint *cp, const std::string §ion) 2125718Shsul@eecs.umich.edu{ 2135718Shsul@eecs.umich.edu System::unserialize(cp,section); 2145718Shsul@eecs.umich.edu // consoleSymtab->unserialize("console_symtab", cp, section); 2155718Shsul@eecs.umich.edu} 2165718Shsul@eecs.umich.edu 2175718Shsul@eecs.umich.eduMipsSystem * 2185718Shsul@eecs.umich.eduMipsSystemParams::create() 2195718Shsul@eecs.umich.edu{ 2205718Shsul@eecs.umich.edu return new MipsSystem(this); 2215718Shsul@eecs.umich.edu} 2221806SN/A 2231806SN/A