system.cc revision 5543
12158SN/A/* 22158SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 32158SN/A * All rights reserved. 42158SN/A * 52158SN/A * Redistribution and use in source and binary forms, with or without 62158SN/A * modification, are permitted provided that the following conditions are 72158SN/A * met: redistributions of source code must retain the above copyright 82158SN/A * notice, this list of conditions and the following disclaimer; 92158SN/A * redistributions in binary form must reproduce the above copyright 102158SN/A * notice, this list of conditions and the following disclaimer in the 112158SN/A * documentation and/or other materials provided with the distribution; 122158SN/A * neither the name of the copyright holders nor the names of its 132158SN/A * contributors may be used to endorse or promote products derived from 142158SN/A * this software without specific prior written permission. 152158SN/A * 162158SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172158SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182158SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192158SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202158SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212158SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222158SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232158SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242158SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252158SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262158SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Ali Saidi 292760Sbinkertn@umich.edu * Nathan Binkert 302158SN/A */ 312158SN/A 323567Sgblack@eecs.umich.edu#include <sys/signal.h> 333567Sgblack@eecs.umich.edu 342432SN/A#include "arch/alpha/ev5.hh" 352158SN/A#include "arch/alpha/system.hh" 363536Sgblack@eecs.umich.edu#include "arch/alpha/remote_gdb.hh" 372215SN/A#include "arch/vtophys.hh" 382158SN/A#include "base/loader/object_file.hh" 392158SN/A#include "base/loader/symtab.hh" 402158SN/A#include "base/trace.hh" 412521SN/A#include "mem/physical.hh" 424762Snate@binkert.org#include "params/AlphaSystem.hh" 432158SN/A#include "sim/byteswap.hh" 442158SN/A 452158SN/A 462158SN/Ausing namespace LittleEndianGuest; 472158SN/A 482158SN/AAlphaSystem::AlphaSystem(Params *p) 492158SN/A : System(p) 502158SN/A{ 512158SN/A consoleSymtab = new SymbolTable; 522158SN/A palSymtab = new SymbolTable; 532158SN/A 542158SN/A 552158SN/A /** 562158SN/A * Load the pal, and console code into memory 572158SN/A */ 582158SN/A // Load Console Code 594762Snate@binkert.org console = createObjectFile(params()->console); 602158SN/A if (console == NULL) 614762Snate@binkert.org fatal("Could not load console file %s", params()->console); 622158SN/A 632158SN/A // Load pal file 644762Snate@binkert.org pal = createObjectFile(params()->pal); 652158SN/A if (pal == NULL) 664762Snate@binkert.org fatal("Could not load PALcode file %s", params()->pal); 672158SN/A 682158SN/A 692158SN/A // Load program sections into memory 702521SN/A pal->loadSections(&functionalPort, AlphaISA::LoadAddrMask); 712521SN/A console->loadSections(&functionalPort, AlphaISA::LoadAddrMask); 722158SN/A 732158SN/A // load symbols 742158SN/A if (!console->loadGlobalSymbols(consoleSymtab)) 752158SN/A panic("could not load console symbols\n"); 762158SN/A 772158SN/A if (!pal->loadGlobalSymbols(palSymtab)) 782158SN/A panic("could not load pal symbols\n"); 792158SN/A 802158SN/A if (!pal->loadLocalSymbols(palSymtab)) 812158SN/A panic("could not load pal symbols\n"); 822158SN/A 832158SN/A if (!console->loadGlobalSymbols(debugSymbolTable)) 842158SN/A panic("could not load console symbols\n"); 852158SN/A 862158SN/A if (!pal->loadGlobalSymbols(debugSymbolTable)) 872158SN/A panic("could not load pal symbols\n"); 882158SN/A 892158SN/A if (!pal->loadLocalSymbols(debugSymbolTable)) 902158SN/A panic("could not load pal symbols\n"); 912158SN/A 922158SN/A Addr addr = 0; 932158SN/A#ifndef NDEBUG 942158SN/A consolePanicEvent = addConsoleFuncEvent<BreakPCEvent>("panic"); 952158SN/A#endif 962158SN/A 972158SN/A /** 982158SN/A * Copy the osflags (kernel arguments) into the consoles 992158SN/A * memory. (Presently Linux does not use the console service 1002158SN/A * routine to get these command line arguments, but Tru64 and 1012158SN/A * others do.) 1022158SN/A */ 1032158SN/A if (consoleSymtab->findAddress("env_booted_osflags", addr)) { 1042521SN/A virtPort.writeBlob(addr, (uint8_t*)params()->boot_osflags.c_str(), 1052521SN/A strlen(params()->boot_osflags.c_str())); 1062158SN/A } 1072158SN/A 1082158SN/A /** 1092158SN/A * Set the hardware reset parameter block system type and revision 1102158SN/A * information to Tsunami. 1112158SN/A */ 1122158SN/A if (consoleSymtab->findAddress("m5_rpb", addr)) { 1132521SN/A uint64_t data; 1142521SN/A data = htog(params()->system_type); 1152549SN/A virtPort.write(addr+0x50, data); 1162521SN/A data = htog(params()->system_rev); 1172549SN/A virtPort.write(addr+0x58, data); 1182158SN/A } else 1192158SN/A panic("could not find hwrpb\n"); 1202158SN/A 1212158SN/A} 1222158SN/A 1232158SN/AAlphaSystem::~AlphaSystem() 1242158SN/A{ 1252158SN/A delete consoleSymtab; 1262158SN/A delete console; 1272158SN/A delete pal; 1282158SN/A#ifdef DEBUG 1292158SN/A delete consolePanicEvent; 1302158SN/A#endif 1312158SN/A} 1322158SN/A 1332158SN/A/** 1342158SN/A * This function fixes up addresses that are used to match PCs for 1352158SN/A * hooking simulator events on to target function executions. 1362158SN/A * 1372158SN/A * Alpha binaries may have multiple global offset table (GOT) 1382158SN/A * sections. A function that uses the GOT starts with a 1392158SN/A * two-instruction prolog which sets the global pointer (gp == r29) to 1402158SN/A * the appropriate GOT section. The proper gp value is calculated 1412158SN/A * based on the function address, which must be passed by the caller 1422158SN/A * in the procedure value register (pv aka t12 == r27). This sequence 1432158SN/A * looks like the following: 1442158SN/A * 1455543Ssaidi@eecs.umich.edu * opcode Ra Rb offset 1465543Ssaidi@eecs.umich.edu * ldah gp,X(pv) 09 29 27 X 1475543Ssaidi@eecs.umich.edu * lda gp,Y(gp) 08 29 29 Y 1482158SN/A * 1492158SN/A * for some constant offsets X and Y. The catch is that the linker 1502158SN/A * (or maybe even the compiler, I'm not sure) may recognize that the 1512158SN/A * caller and callee are using the same GOT section, making this 1522158SN/A * prolog redundant, and modify the call target to skip these 1532158SN/A * instructions. If we check for execution of the first instruction 1542158SN/A * of a function (the one the symbol points to) to detect when to skip 1552158SN/A * it, we'll miss all these modified calls. It might work to 1562158SN/A * unconditionally check for the third instruction, but not all 1572158SN/A * functions have this prolog, and there's some chance that those 1582158SN/A * first two instructions could have undesired consequences. So we do 1592158SN/A * the Right Thing and pattern-match the first two instructions of the 1602158SN/A * function to decide where to patch. 1612158SN/A * 1622158SN/A * Eventually this code should be moved into an ISA-specific file. 1632158SN/A */ 1642158SN/AAddr 1652158SN/AAlphaSystem::fixFuncEventAddr(Addr addr) 1662158SN/A{ 1672158SN/A // mask for just the opcode, Ra, and Rb fields (not the offset) 1682158SN/A const uint32_t inst_mask = 0xffff0000; 1692158SN/A // ldah gp,X(pv): opcode 9, Ra = 29, Rb = 27 1702158SN/A const uint32_t gp_ldah_pattern = (9 << 26) | (29 << 21) | (27 << 16); 1712158SN/A // lda gp,Y(gp): opcode 8, Ra = 29, rb = 29 1722158SN/A const uint32_t gp_lda_pattern = (8 << 26) | (29 << 21) | (29 << 16); 1732158SN/A 1742521SN/A uint32_t i1 = virtPort.read<uint32_t>(addr); 1752521SN/A uint32_t i2 = virtPort.read<uint32_t>(addr + sizeof(AlphaISA::MachInst)); 1762158SN/A 1772158SN/A if ((i1 & inst_mask) == gp_ldah_pattern && 1782158SN/A (i2 & inst_mask) == gp_lda_pattern) { 1792521SN/A Addr new_addr = addr + 2* sizeof(AlphaISA::MachInst); 1802158SN/A DPRINTF(Loader, "fixFuncEventAddr: %p -> %p", addr, new_addr); 1812158SN/A return new_addr; 1822158SN/A } else { 1832158SN/A return addr; 1842158SN/A } 1852158SN/A} 1862158SN/A 1872158SN/A 1882158SN/Avoid 1892158SN/AAlphaSystem::setAlphaAccess(Addr access) 1902158SN/A{ 1912158SN/A Addr addr = 0; 1922158SN/A if (consoleSymtab->findAddress("m5AlphaAccess", addr)) { 1932521SN/A virtPort.write(addr, htog(EV5::Phys2K0Seg(access))); 1942158SN/A } else 1952158SN/A panic("could not find m5AlphaAccess\n"); 1962158SN/A} 1972158SN/A 1982158SN/Avoid 1992158SN/AAlphaSystem::serialize(std::ostream &os) 2002158SN/A{ 2012158SN/A System::serialize(os); 2022158SN/A consoleSymtab->serialize("console_symtab", os); 2032158SN/A palSymtab->serialize("pal_symtab", os); 2042158SN/A} 2052158SN/A 2062158SN/A 2072158SN/Avoid 2082158SN/AAlphaSystem::unserialize(Checkpoint *cp, const std::string §ion) 2092158SN/A{ 2102158SN/A System::unserialize(cp,section); 2112158SN/A consoleSymtab->unserialize("console_symtab", cp, section); 2122158SN/A palSymtab->unserialize("pal_symtab", cp, section); 2132158SN/A} 2142158SN/A 2154762Snate@binkert.orgAlphaSystem * 2164762Snate@binkert.orgAlphaSystemParams::create() 2172158SN/A{ 2184762Snate@binkert.org return new AlphaSystem(this); 2192158SN/A} 220