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