utility.cc revision 14020:c9bf7a011602
112855Sgabeblack@google.com/* 212855Sgabeblack@google.com * Copyright (c) 2003-2005 The Regents of The University of Michigan 312855Sgabeblack@google.com * All rights reserved. 412855Sgabeblack@google.com * 512855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612855Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112855Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412855Sgabeblack@google.com * this software without specific prior written permission. 1512855Sgabeblack@google.com * 1612855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712855Sgabeblack@google.com * 2812855Sgabeblack@google.com * Authors: Gabe Black 2912855Sgabeblack@google.com * Ali Saidi 3012855Sgabeblack@google.com */ 3112855Sgabeblack@google.com 3212855Sgabeblack@google.com#include "arch/sparc/utility.hh" 3312855Sgabeblack@google.com 3412855Sgabeblack@google.com#include "arch/sparc/faults.hh" 3512855Sgabeblack@google.com#include "arch/sparc/vtophys.hh" 3612855Sgabeblack@google.com#include "mem/fs_translating_port_proxy.hh" 3712855Sgabeblack@google.com 3812855Sgabeblack@google.comnamespace SparcISA { 3912855Sgabeblack@google.com 4012855Sgabeblack@google.com 4112855Sgabeblack@google.com// The caller uses %o0-%05 for the first 6 arguments even if their floating 4212855Sgabeblack@google.com// point. Double precision floating point values take two registers/args. 4312855Sgabeblack@google.com// Quads, structs, and unions are passed as pointers. All arguments beyond 4412855Sgabeblack@google.com// the sixth are passed on the stack past the 16 word window save area, 4512855Sgabeblack@google.com// space for the struct/union return pointer, and space reserved for the 4612855Sgabeblack@google.com// first 6 arguments which the caller may use but doesn't have to. 4712855Sgabeblack@google.comuint64_t 4812855Sgabeblack@google.comgetArgument(ThreadContext *tc, int &number, uint16_t size, bool fp) 4912855Sgabeblack@google.com{ 5012855Sgabeblack@google.com if (!FullSystem) { 5112855Sgabeblack@google.com panic("getArgument() only implemented for full system\n"); 5212855Sgabeblack@google.com M5_DUMMY_RETURN 5312855Sgabeblack@google.com } 5412855Sgabeblack@google.com 5512855Sgabeblack@google.com const int NumArgumentRegs = 6; 5612855Sgabeblack@google.com if (number < NumArgumentRegs) { 5712855Sgabeblack@google.com return tc->readIntReg(8 + number); 5812855Sgabeblack@google.com } else { 5912855Sgabeblack@google.com Addr sp = tc->readIntReg(StackPointerReg); 6012855Sgabeblack@google.com PortProxy &vp = tc->getVirtProxy(); 6112855Sgabeblack@google.com uint64_t arg = vp.read<uint64_t>(sp + 92 + 6212855Sgabeblack@google.com (number-NumArgumentRegs) * sizeof(uint64_t)); 6312855Sgabeblack@google.com return arg; 6412855Sgabeblack@google.com } 6512855Sgabeblack@google.com} 6612855Sgabeblack@google.com 6712855Sgabeblack@google.comvoid 6812855Sgabeblack@google.comcopyMiscRegs(ThreadContext *src, ThreadContext *dest) 6912855Sgabeblack@google.com{ 7012855Sgabeblack@google.com 7112855Sgabeblack@google.com uint8_t tl = src->readMiscRegNoEffect(MISCREG_TL); 7212855Sgabeblack@google.com 7312855Sgabeblack@google.com // Read all the trap level dependent registers and save them off 7412855Sgabeblack@google.com for (int i = 1; i <= MaxTL; i++) { 7512855Sgabeblack@google.com src->setMiscRegNoEffect(MISCREG_TL, i); 7612855Sgabeblack@google.com dest->setMiscRegNoEffect(MISCREG_TL, i); 7712855Sgabeblack@google.com 7812855Sgabeblack@google.com dest->setMiscRegNoEffect(MISCREG_TT, 7912855Sgabeblack@google.com src->readMiscRegNoEffect(MISCREG_TT)); 8012855Sgabeblack@google.com dest->setMiscRegNoEffect(MISCREG_TPC, 8112855Sgabeblack@google.com src->readMiscRegNoEffect(MISCREG_TPC)); 8212855Sgabeblack@google.com dest->setMiscRegNoEffect(MISCREG_TNPC, 8312855Sgabeblack@google.com src->readMiscRegNoEffect(MISCREG_TNPC)); 8412855Sgabeblack@google.com dest->setMiscRegNoEffect(MISCREG_TSTATE, 8512855Sgabeblack@google.com src->readMiscRegNoEffect(MISCREG_TSTATE)); 86 } 87 88 // Save off the traplevel 89 dest->setMiscRegNoEffect(MISCREG_TL, tl); 90 src->setMiscRegNoEffect(MISCREG_TL, tl); 91 92 93 // ASRs 94// dest->setMiscRegNoEffect(MISCREG_Y, 95// src->readMiscRegNoEffect(MISCREG_Y)); 96// dest->setMiscRegNoEffect(MISCREG_CCR, 97// src->readMiscRegNoEffect(MISCREG_CCR)); 98 dest->setMiscReg(MISCREG_ASI, 99 src->readMiscRegNoEffect(MISCREG_ASI)); 100 dest->setMiscRegNoEffect(MISCREG_TICK, 101 src->readMiscRegNoEffect(MISCREG_TICK)); 102 dest->setMiscRegNoEffect(MISCREG_FPRS, 103 src->readMiscRegNoEffect(MISCREG_FPRS)); 104 dest->setMiscRegNoEffect(MISCREG_SOFTINT, 105 src->readMiscRegNoEffect(MISCREG_SOFTINT)); 106 dest->setMiscRegNoEffect(MISCREG_TICK_CMPR, 107 src->readMiscRegNoEffect(MISCREG_TICK_CMPR)); 108 dest->setMiscRegNoEffect(MISCREG_STICK, 109 src->readMiscRegNoEffect(MISCREG_STICK)); 110 dest->setMiscRegNoEffect(MISCREG_STICK_CMPR, 111 src->readMiscRegNoEffect(MISCREG_STICK_CMPR)); 112 113 // Priv Registers 114 dest->setMiscRegNoEffect(MISCREG_TICK, 115 src->readMiscRegNoEffect(MISCREG_TICK)); 116 dest->setMiscRegNoEffect(MISCREG_TBA, 117 src->readMiscRegNoEffect(MISCREG_TBA)); 118 dest->setMiscRegNoEffect(MISCREG_PSTATE, 119 src->readMiscRegNoEffect(MISCREG_PSTATE)); 120 dest->setMiscRegNoEffect(MISCREG_PIL, 121 src->readMiscRegNoEffect(MISCREG_PIL)); 122 dest->setMiscReg(MISCREG_CWP, 123 src->readMiscRegNoEffect(MISCREG_CWP)); 124// dest->setMiscRegNoEffect(MISCREG_CANSAVE, 125// src->readMiscRegNoEffect(MISCREG_CANSAVE)); 126// dest->setMiscRegNoEffect(MISCREG_CANRESTORE, 127// src->readMiscRegNoEffect(MISCREG_CANRESTORE)); 128// dest->setMiscRegNoEffect(MISCREG_OTHERWIN, 129// src->readMiscRegNoEffect(MISCREG_OTHERWIN)); 130// dest->setMiscRegNoEffect(MISCREG_CLEANWIN, 131// src->readMiscRegNoEffect(MISCREG_CLEANWIN)); 132// dest->setMiscRegNoEffect(MISCREG_WSTATE, 133// src->readMiscRegNoEffect(MISCREG_WSTATE)); 134 dest->setMiscReg(MISCREG_GL, src->readMiscRegNoEffect(MISCREG_GL)); 135 136 // Hyperprivilged registers 137 dest->setMiscRegNoEffect(MISCREG_HPSTATE, 138 src->readMiscRegNoEffect(MISCREG_HPSTATE)); 139 dest->setMiscRegNoEffect(MISCREG_HINTP, 140 src->readMiscRegNoEffect(MISCREG_HINTP)); 141 dest->setMiscRegNoEffect(MISCREG_HTBA, 142 src->readMiscRegNoEffect(MISCREG_HTBA)); 143 dest->setMiscRegNoEffect(MISCREG_STRAND_STS_REG, 144 src->readMiscRegNoEffect(MISCREG_STRAND_STS_REG)); 145 dest->setMiscRegNoEffect(MISCREG_HSTICK_CMPR, 146 src->readMiscRegNoEffect(MISCREG_HSTICK_CMPR)); 147 148 // FSR 149 dest->setMiscRegNoEffect(MISCREG_FSR, 150 src->readMiscRegNoEffect(MISCREG_FSR)); 151 152 // Strand Status Register 153 dest->setMiscRegNoEffect(MISCREG_STRAND_STS_REG, 154 src->readMiscRegNoEffect(MISCREG_STRAND_STS_REG)); 155 156 // MMU Registers 157 dest->setMiscRegNoEffect(MISCREG_MMU_P_CONTEXT, 158 src->readMiscRegNoEffect(MISCREG_MMU_P_CONTEXT)); 159 dest->setMiscRegNoEffect(MISCREG_MMU_S_CONTEXT, 160 src->readMiscRegNoEffect(MISCREG_MMU_S_CONTEXT)); 161 dest->setMiscRegNoEffect(MISCREG_MMU_PART_ID, 162 src->readMiscRegNoEffect(MISCREG_MMU_PART_ID)); 163 dest->setMiscRegNoEffect(MISCREG_MMU_LSU_CTRL, 164 src->readMiscRegNoEffect(MISCREG_MMU_LSU_CTRL)); 165 166 // Scratchpad Registers 167 dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R0, 168 src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R0)); 169 dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R1, 170 src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R1)); 171 dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R2, 172 src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R2)); 173 dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R3, 174 src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R3)); 175 dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R4, 176 src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R4)); 177 dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R5, 178 src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R5)); 179 dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R6, 180 src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R6)); 181 dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R7, 182 src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R7)); 183 184 // Queue Registers 185 dest->setMiscRegNoEffect(MISCREG_QUEUE_CPU_MONDO_HEAD, 186 src->readMiscRegNoEffect(MISCREG_QUEUE_CPU_MONDO_HEAD)); 187 dest->setMiscRegNoEffect(MISCREG_QUEUE_CPU_MONDO_TAIL, 188 src->readMiscRegNoEffect(MISCREG_QUEUE_CPU_MONDO_TAIL)); 189 dest->setMiscRegNoEffect(MISCREG_QUEUE_DEV_MONDO_HEAD, 190 src->readMiscRegNoEffect(MISCREG_QUEUE_DEV_MONDO_HEAD)); 191 dest->setMiscRegNoEffect(MISCREG_QUEUE_DEV_MONDO_TAIL, 192 src->readMiscRegNoEffect(MISCREG_QUEUE_DEV_MONDO_TAIL)); 193 dest->setMiscRegNoEffect(MISCREG_QUEUE_RES_ERROR_HEAD, 194 src->readMiscRegNoEffect(MISCREG_QUEUE_RES_ERROR_HEAD)); 195 dest->setMiscRegNoEffect(MISCREG_QUEUE_RES_ERROR_TAIL, 196 src->readMiscRegNoEffect(MISCREG_QUEUE_RES_ERROR_TAIL)); 197 dest->setMiscRegNoEffect(MISCREG_QUEUE_NRES_ERROR_HEAD, 198 src->readMiscRegNoEffect(MISCREG_QUEUE_NRES_ERROR_HEAD)); 199 dest->setMiscRegNoEffect(MISCREG_QUEUE_NRES_ERROR_TAIL, 200 src->readMiscRegNoEffect(MISCREG_QUEUE_NRES_ERROR_TAIL)); 201} 202 203void 204copyRegs(ThreadContext *src, ThreadContext *dest) 205{ 206 // First loop through the integer registers. 207 int old_gl = src->readMiscRegNoEffect(MISCREG_GL); 208 int old_cwp = src->readMiscRegNoEffect(MISCREG_CWP); 209 // Globals 210 for (int x = 0; x < MaxGL; ++x) { 211 src->setMiscReg(MISCREG_GL, x); 212 dest->setMiscReg(MISCREG_GL, x); 213 // Skip %g0 which is always zero. 214 for (int y = 1; y < 8; y++) 215 dest->setIntReg(y, src->readIntReg(y)); 216 } 217 // Locals and ins. Outs are all also ins. 218 for (int x = 0; x < NWindows; ++x) { 219 src->setMiscReg(MISCREG_CWP, x); 220 dest->setMiscReg(MISCREG_CWP, x); 221 for (int y = 16; y < 32; y++) 222 dest->setIntReg(y, src->readIntReg(y)); 223 } 224 // Microcode reg and pseudo int regs (misc regs in the integer regfile). 225 for (int y = NumIntArchRegs; y < NumIntArchRegs + NumMicroIntRegs; ++y) 226 dest->setIntReg(y, src->readIntReg(y)); 227 228 // Restore src's GL, CWP 229 src->setMiscReg(MISCREG_GL, old_gl); 230 src->setMiscReg(MISCREG_CWP, old_cwp); 231 232 233 // Then loop through the floating point registers. 234 for (int i = 0; i < SparcISA::NumFloatArchRegs; ++i) { 235 dest->setFloatReg(i, src->readFloatReg(i)); 236 } 237 238 // Would need to add condition-code regs if implemented 239 assert(NumCCRegs == 0); 240 241 // Copy misc. registers 242 copyMiscRegs(src, dest); 243 244 // Lastly copy PC/NPC 245 dest->pcState(src->pcState()); 246} 247 248void 249skipFunction(ThreadContext *tc) 250{ 251 PCState newPC = tc->pcState(); 252 newPC.set(tc->readIntReg(ReturnAddressReg)); 253 tc->pcState(newPC); 254} 255 256 257void 258initCPU(ThreadContext *tc, int cpuId) 259{ 260 static Fault por = std::make_shared<PowerOnReset>(); 261 if (cpuId == 0) 262 por->invoke(tc); 263} 264 265} // namespace SPARC_ISA 266