system.cc revision 4762
111723Sar4jc@virginia.edu/* 211723Sar4jc@virginia.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan 311723Sar4jc@virginia.edu * All rights reserved. 411723Sar4jc@virginia.edu * 511723Sar4jc@virginia.edu * Redistribution and use in source and binary forms, with or without 611723Sar4jc@virginia.edu * modification, are permitted provided that the following conditions are 711723Sar4jc@virginia.edu * met: redistributions of source code must retain the above copyright 811723Sar4jc@virginia.edu * notice, this list of conditions and the following disclaimer; 911723Sar4jc@virginia.edu * redistributions in binary form must reproduce the above copyright 1011723Sar4jc@virginia.edu * notice, this list of conditions and the following disclaimer in the 1111723Sar4jc@virginia.edu * documentation and/or other materials provided with the distribution; 1211723Sar4jc@virginia.edu * neither the name of the copyright holders nor the names of its 1311723Sar4jc@virginia.edu * contributors may be used to endorse or promote products derived from 1411723Sar4jc@virginia.edu * this software without specific prior written permission. 1511723Sar4jc@virginia.edu * 1611723Sar4jc@virginia.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1711723Sar4jc@virginia.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1811723Sar4jc@virginia.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1911723Sar4jc@virginia.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2011723Sar4jc@virginia.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2111723Sar4jc@virginia.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2211723Sar4jc@virginia.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2311723Sar4jc@virginia.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2411723Sar4jc@virginia.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2511723Sar4jc@virginia.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2611723Sar4jc@virginia.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2711723Sar4jc@virginia.edu * 2811723Sar4jc@virginia.edu * Authors: Ali Saidi 2911723Sar4jc@virginia.edu * Nathan Binkert 3011723Sar4jc@virginia.edu */ 3111723Sar4jc@virginia.edu 3211723Sar4jc@virginia.edu#include <sys/signal.h> 3311723Sar4jc@virginia.edu 3411723Sar4jc@virginia.edu#include "arch/alpha/ev5.hh" 3511723Sar4jc@virginia.edu#include "arch/alpha/system.hh" 3611723Sar4jc@virginia.edu#include "arch/alpha/remote_gdb.hh" 3711723Sar4jc@virginia.edu#include "arch/vtophys.hh" 3811723Sar4jc@virginia.edu#include "base/loader/object_file.hh" 3911723Sar4jc@virginia.edu#include "base/loader/symtab.hh" 4011723Sar4jc@virginia.edu#include "base/trace.hh" 4111723Sar4jc@virginia.edu#include "mem/physical.hh" 4211723Sar4jc@virginia.edu#include "params/AlphaSystem.hh" 4311723Sar4jc@virginia.edu#include "sim/byteswap.hh" 4411723Sar4jc@virginia.edu 4511723Sar4jc@virginia.edu 4611723Sar4jc@virginia.eduusing namespace LittleEndianGuest; 4711723Sar4jc@virginia.edu 4811723Sar4jc@virginia.eduAlphaSystem::AlphaSystem(Params *p) 4911723Sar4jc@virginia.edu : System(p) 5011723Sar4jc@virginia.edu{ 5111723Sar4jc@virginia.edu consoleSymtab = new SymbolTable; 5211723Sar4jc@virginia.edu palSymtab = new SymbolTable; 5311723Sar4jc@virginia.edu 5411723Sar4jc@virginia.edu 5511723Sar4jc@virginia.edu /** 5611723Sar4jc@virginia.edu * Load the pal, and console code into memory 5711723Sar4jc@virginia.edu */ 5811723Sar4jc@virginia.edu // Load Console Code 5911723Sar4jc@virginia.edu console = createObjectFile(params()->console); 6011723Sar4jc@virginia.edu if (console == NULL) 6111723Sar4jc@virginia.edu fatal("Could not load console file %s", params()->console); 6211723Sar4jc@virginia.edu 6311723Sar4jc@virginia.edu // Load pal file 6411723Sar4jc@virginia.edu pal = createObjectFile(params()->pal); 6511723Sar4jc@virginia.edu if (pal == NULL) 66 fatal("Could not load PALcode file %s", params()->pal); 67 68 69 // Load program sections into memory 70 pal->loadSections(&functionalPort, AlphaISA::LoadAddrMask); 71 console->loadSections(&functionalPort, AlphaISA::LoadAddrMask); 72 73 // load symbols 74 if (!console->loadGlobalSymbols(consoleSymtab)) 75 panic("could not load console symbols\n"); 76 77 if (!pal->loadGlobalSymbols(palSymtab)) 78 panic("could not load pal symbols\n"); 79 80 if (!pal->loadLocalSymbols(palSymtab)) 81 panic("could not load pal symbols\n"); 82 83 if (!console->loadGlobalSymbols(debugSymbolTable)) 84 panic("could not load console symbols\n"); 85 86 if (!pal->loadGlobalSymbols(debugSymbolTable)) 87 panic("could not load pal symbols\n"); 88 89 if (!pal->loadLocalSymbols(debugSymbolTable)) 90 panic("could not load pal symbols\n"); 91 92 Addr addr = 0; 93#ifndef NDEBUG 94 consolePanicEvent = addConsoleFuncEvent<BreakPCEvent>("panic"); 95#endif 96 97 /** 98 * Copy the osflags (kernel arguments) into the consoles 99 * memory. (Presently Linux does not use the console service 100 * routine to get these command line arguments, but Tru64 and 101 * others do.) 102 */ 103 if (consoleSymtab->findAddress("env_booted_osflags", addr)) { 104 virtPort.writeBlob(addr, (uint8_t*)params()->boot_osflags.c_str(), 105 strlen(params()->boot_osflags.c_str())); 106 } 107 108 /** 109 * Set the hardware reset parameter block system type and revision 110 * information to Tsunami. 111 */ 112 if (consoleSymtab->findAddress("m5_rpb", addr)) { 113 uint64_t data; 114 data = htog(params()->system_type); 115 virtPort.write(addr+0x50, data); 116 data = htog(params()->system_rev); 117 virtPort.write(addr+0x58, data); 118 } else 119 panic("could not find hwrpb\n"); 120 121} 122 123AlphaSystem::~AlphaSystem() 124{ 125 delete consoleSymtab; 126 delete console; 127 delete pal; 128#ifdef DEBUG 129 delete consolePanicEvent; 130#endif 131} 132 133/** 134 * This function fixes up addresses that are used to match PCs for 135 * hooking simulator events on to target function executions. 136 * 137 * Alpha binaries may have multiple global offset table (GOT) 138 * sections. A function that uses the GOT starts with a 139 * two-instruction prolog which sets the global pointer (gp == r29) to 140 * the appropriate GOT section. The proper gp value is calculated 141 * based on the function address, which must be passed by the caller 142 * in the procedure value register (pv aka t12 == r27). This sequence 143 * looks like the following: 144 * 145 * opcode Ra Rb offset 146 * ldah gp,X(pv) 09 29 27 X 147 * lda gp,Y(gp) 08 29 29 Y 148 * 149 * for some constant offsets X and Y. The catch is that the linker 150 * (or maybe even the compiler, I'm not sure) may recognize that the 151 * caller and callee are using the same GOT section, making this 152 * prolog redundant, and modify the call target to skip these 153 * instructions. If we check for execution of the first instruction 154 * of a function (the one the symbol points to) to detect when to skip 155 * it, we'll miss all these modified calls. It might work to 156 * unconditionally check for the third instruction, but not all 157 * functions have this prolog, and there's some chance that those 158 * first two instructions could have undesired consequences. So we do 159 * the Right Thing and pattern-match the first two instructions of the 160 * function to decide where to patch. 161 * 162 * Eventually this code should be moved into an ISA-specific file. 163 */ 164Addr 165AlphaSystem::fixFuncEventAddr(Addr addr) 166{ 167 // mask for just the opcode, Ra, and Rb fields (not the offset) 168 const uint32_t inst_mask = 0xffff0000; 169 // ldah gp,X(pv): opcode 9, Ra = 29, Rb = 27 170 const uint32_t gp_ldah_pattern = (9 << 26) | (29 << 21) | (27 << 16); 171 // lda gp,Y(gp): opcode 8, Ra = 29, rb = 29 172 const uint32_t gp_lda_pattern = (8 << 26) | (29 << 21) | (29 << 16); 173 174 uint32_t i1 = virtPort.read<uint32_t>(addr); 175 uint32_t i2 = virtPort.read<uint32_t>(addr + sizeof(AlphaISA::MachInst)); 176 177 if ((i1 & inst_mask) == gp_ldah_pattern && 178 (i2 & inst_mask) == gp_lda_pattern) { 179 Addr new_addr = addr + 2* sizeof(AlphaISA::MachInst); 180 DPRINTF(Loader, "fixFuncEventAddr: %p -> %p", addr, new_addr); 181 return new_addr; 182 } else { 183 return addr; 184 } 185} 186 187 188void 189AlphaSystem::setAlphaAccess(Addr access) 190{ 191 Addr addr = 0; 192 if (consoleSymtab->findAddress("m5AlphaAccess", addr)) { 193 virtPort.write(addr, htog(EV5::Phys2K0Seg(access))); 194 } else 195 panic("could not find m5AlphaAccess\n"); 196} 197 198void 199AlphaSystem::serialize(std::ostream &os) 200{ 201 System::serialize(os); 202 consoleSymtab->serialize("console_symtab", os); 203 palSymtab->serialize("pal_symtab", os); 204} 205 206 207void 208AlphaSystem::unserialize(Checkpoint *cp, const std::string §ion) 209{ 210 System::unserialize(cp,section); 211 consoleSymtab->unserialize("console_symtab", cp, section); 212 palSymtab->unserialize("pal_symtab", cp, section); 213} 214 215AlphaSystem * 216AlphaSystemParams::create() 217{ 218 return new AlphaSystem(this); 219} 220