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 3211793Sbrandon.potter@amd.com#include "arch/alpha/system.hh" 3311793Sbrandon.potter@amd.com 343567Sgblack@eecs.umich.edu#include <sys/signal.h> 353567Sgblack@eecs.umich.edu 362432SN/A#include "arch/alpha/ev5.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" 418232Snate@binkert.org#include "debug/Loader.hh" 428706Sandreas.hansson@arm.com#include "mem/fs_translating_port_proxy.hh" 434762Snate@binkert.org#include "params/AlphaSystem.hh" 442158SN/A#include "sim/byteswap.hh" 452158SN/A 465568Snate@binkert.orgusing namespace AlphaISA; 472158SN/A 482158SN/AAlphaSystem::AlphaSystem(Params *p) 499847Sandreas.hansson@arm.com : System(p), intrFreq(0), virtProxy(getSystemPort(), p->cache_line_size) 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 // load symbols 692158SN/A if (!console->loadGlobalSymbols(consoleSymtab)) 702158SN/A panic("could not load console symbols\n"); 712158SN/A 722158SN/A if (!pal->loadGlobalSymbols(palSymtab)) 732158SN/A panic("could not load pal symbols\n"); 742158SN/A 752158SN/A if (!pal->loadLocalSymbols(palSymtab)) 762158SN/A panic("could not load pal symbols\n"); 772158SN/A 782158SN/A if (!console->loadGlobalSymbols(debugSymbolTable)) 792158SN/A panic("could not load console symbols\n"); 802158SN/A 812158SN/A if (!pal->loadGlobalSymbols(debugSymbolTable)) 822158SN/A panic("could not load pal symbols\n"); 832158SN/A 842158SN/A if (!pal->loadLocalSymbols(debugSymbolTable)) 852158SN/A panic("could not load pal symbols\n"); 862158SN/A 878885SAli.Saidi@ARM.com 888885SAli.Saidi@ARM.com} 898885SAli.Saidi@ARM.com 908885SAli.Saidi@ARM.comAlphaSystem::~AlphaSystem() 918885SAli.Saidi@ARM.com{ 928885SAli.Saidi@ARM.com delete consoleSymtab; 938885SAli.Saidi@ARM.com delete console; 948885SAli.Saidi@ARM.com delete pal; 958885SAli.Saidi@ARM.com#ifdef DEBUG 968885SAli.Saidi@ARM.com delete consolePanicEvent; 978885SAli.Saidi@ARM.com#endif 988885SAli.Saidi@ARM.com} 998885SAli.Saidi@ARM.com 1008885SAli.Saidi@ARM.comvoid 1018885SAli.Saidi@ARM.comAlphaSystem::initState() 1028885SAli.Saidi@ARM.com{ 1032158SN/A Addr addr = 0; 1048885SAli.Saidi@ARM.com 1058885SAli.Saidi@ARM.com // Moved from the constructor to here since it relies on the 1068885SAli.Saidi@ARM.com // address map being resolved in the interconnect 1078885SAli.Saidi@ARM.com 1088885SAli.Saidi@ARM.com // Call the initialisation of the super class 1098885SAli.Saidi@ARM.com System::initState(); 1108885SAli.Saidi@ARM.com 1118885SAli.Saidi@ARM.com // Load program sections into memory 1128885SAli.Saidi@ARM.com pal->loadSections(physProxy, loadAddrMask); 1138885SAli.Saidi@ARM.com console->loadSections(physProxy, loadAddrMask); 1142158SN/A 1152158SN/A /** 1162158SN/A * Copy the osflags (kernel arguments) into the consoles 1172158SN/A * memory. (Presently Linux does not use the console service 1182158SN/A * routine to get these command line arguments, but Tru64 and 1192158SN/A * others do.) 1202158SN/A */ 1212158SN/A if (consoleSymtab->findAddress("env_booted_osflags", addr)) { 12214010Sgabeblack@google.com virtProxy.writeBlob(addr, params()->boot_osflags.c_str(), 1238852Sandreas.hansson@arm.com strlen(params()->boot_osflags.c_str())); 1242158SN/A } 1252158SN/A 1262158SN/A /** 1272158SN/A * Set the hardware reset parameter block system type and revision 1282158SN/A * information to Tsunami. 1292158SN/A */ 1302158SN/A if (consoleSymtab->findAddress("m5_rpb", addr)) { 1312521SN/A uint64_t data; 1322521SN/A data = htog(params()->system_type); 1338852Sandreas.hansson@arm.com virtProxy.write(addr+0x50, data); 1342521SN/A data = htog(params()->system_rev); 1358852Sandreas.hansson@arm.com virtProxy.write(addr+0x58, data); 1362158SN/A } else 1372158SN/A panic("could not find hwrpb\n"); 1389153Snilay@cs.wisc.edu} 1398885SAli.Saidi@ARM.com 1409153Snilay@cs.wisc.eduvoid 1419153Snilay@cs.wisc.eduAlphaSystem::startup() 1429153Snilay@cs.wisc.edu{ 1438885SAli.Saidi@ARM.com // Setup all the function events now that we have a system and a symbol 1448885SAli.Saidi@ARM.com // table 1458885SAli.Saidi@ARM.com setupFuncEvents(); 1468885SAli.Saidi@ARM.com} 1478885SAli.Saidi@ARM.com 1488885SAli.Saidi@ARM.comvoid 1498885SAli.Saidi@ARM.comAlphaSystem::setupFuncEvents() 1508885SAli.Saidi@ARM.com{ 1518885SAli.Saidi@ARM.com#ifndef NDEBUG 1528885SAli.Saidi@ARM.com consolePanicEvent = addConsoleFuncEvent<BreakPCEvent>("panic"); 1538885SAli.Saidi@ARM.com#endif 1542158SN/A} 1552158SN/A 1562158SN/A/** 1572158SN/A * This function fixes up addresses that are used to match PCs for 1582158SN/A * hooking simulator events on to target function executions. 1592158SN/A * 1602158SN/A * Alpha binaries may have multiple global offset table (GOT) 1612158SN/A * sections. A function that uses the GOT starts with a 1622158SN/A * two-instruction prolog which sets the global pointer (gp == r29) to 1632158SN/A * the appropriate GOT section. The proper gp value is calculated 1642158SN/A * based on the function address, which must be passed by the caller 1652158SN/A * in the procedure value register (pv aka t12 == r27). This sequence 1662158SN/A * looks like the following: 1672158SN/A * 1685543Ssaidi@eecs.umich.edu * opcode Ra Rb offset 1695543Ssaidi@eecs.umich.edu * ldah gp,X(pv) 09 29 27 X 1705543Ssaidi@eecs.umich.edu * lda gp,Y(gp) 08 29 29 Y 1712158SN/A * 1722158SN/A * for some constant offsets X and Y. The catch is that the linker 1732158SN/A * (or maybe even the compiler, I'm not sure) may recognize that the 1742158SN/A * caller and callee are using the same GOT section, making this 1752158SN/A * prolog redundant, and modify the call target to skip these 1762158SN/A * instructions. If we check for execution of the first instruction 1772158SN/A * of a function (the one the symbol points to) to detect when to skip 1782158SN/A * it, we'll miss all these modified calls. It might work to 1792158SN/A * unconditionally check for the third instruction, but not all 1802158SN/A * functions have this prolog, and there's some chance that those 1812158SN/A * first two instructions could have undesired consequences. So we do 1822158SN/A * the Right Thing and pattern-match the first two instructions of the 1832158SN/A * function to decide where to patch. 1842158SN/A * 1852158SN/A * Eventually this code should be moved into an ISA-specific file. 1862158SN/A */ 1872158SN/AAddr 1882158SN/AAlphaSystem::fixFuncEventAddr(Addr addr) 1892158SN/A{ 1902158SN/A // mask for just the opcode, Ra, and Rb fields (not the offset) 1912158SN/A const uint32_t inst_mask = 0xffff0000; 1922158SN/A // ldah gp,X(pv): opcode 9, Ra = 29, Rb = 27 1932158SN/A const uint32_t gp_ldah_pattern = (9 << 26) | (29 << 21) | (27 << 16); 1942158SN/A // lda gp,Y(gp): opcode 8, Ra = 29, rb = 29 1952158SN/A const uint32_t gp_lda_pattern = (8 << 26) | (29 << 21) | (29 << 16); 1962158SN/A 1978852Sandreas.hansson@arm.com uint32_t i1 = virtProxy.read<uint32_t>(addr); 1988852Sandreas.hansson@arm.com uint32_t i2 = virtProxy.read<uint32_t>(addr + sizeof(MachInst)); 1992158SN/A 2002158SN/A if ((i1 & inst_mask) == gp_ldah_pattern && 2012158SN/A (i2 & inst_mask) == gp_lda_pattern) { 2025569Snate@binkert.org Addr new_addr = addr + 2 * sizeof(MachInst); 2032158SN/A DPRINTF(Loader, "fixFuncEventAddr: %p -> %p", addr, new_addr); 2042158SN/A return new_addr; 2052158SN/A } else { 2062158SN/A return addr; 2072158SN/A } 2082158SN/A} 2092158SN/A 2102158SN/Avoid 2112158SN/AAlphaSystem::setAlphaAccess(Addr access) 2122158SN/A{ 2132158SN/A Addr addr = 0; 2142158SN/A if (consoleSymtab->findAddress("m5AlphaAccess", addr)) { 2158852Sandreas.hansson@arm.com virtProxy.write(addr, htog(Phys2K0Seg(access))); 2165569Snate@binkert.org } else { 2172158SN/A panic("could not find m5AlphaAccess\n"); 2185569Snate@binkert.org } 2192158SN/A} 2202158SN/A 2212158SN/Avoid 22210905Sandreas.sandberg@arm.comAlphaSystem::serializeSymtab(CheckpointOut &cp) const 2232158SN/A{ 22410905Sandreas.sandberg@arm.com consoleSymtab->serialize("console_symtab", cp); 22510905Sandreas.sandberg@arm.com palSymtab->serialize("pal_symtab", cp); 2262158SN/A} 2272158SN/A 2282158SN/Avoid 22910905Sandreas.sandberg@arm.comAlphaSystem::unserializeSymtab(CheckpointIn &cp) 2302158SN/A{ 23110905Sandreas.sandberg@arm.com consoleSymtab->unserialize("console_symtab", cp); 23210905Sandreas.sandberg@arm.com palSymtab->unserialize("pal_symtab", cp); 2332158SN/A} 2342158SN/A 2354762Snate@binkert.orgAlphaSystem * 2364762Snate@binkert.orgAlphaSystemParams::create() 2372158SN/A{ 2384762Snate@binkert.org return new AlphaSystem(this); 2392158SN/A} 240