pseudo_inst.cc revision 954
1/* 2 * Copyright (c) 2003-2004 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 29#include <fcntl.h> 30#include <cstdio> 31#include <string> 32 33#include "arch/alpha/pseudo_inst.hh" 34#include "arch/alpha/vtophys.hh" 35#include "cpu/base_cpu.hh" 36#include "cpu/exec_context.hh" 37#include "sim/param.hh" 38#include "sim/serialize.hh" 39#include "sim/sim_exit.hh" 40#include "sim/stat_control.hh" 41#include "sim/stats.hh" 42#include "sim/system.hh" 43 44using namespace std; 45using namespace Stats; 46 47namespace AlphaPseudo 48{ 49 bool doStatisticsInsts; 50 bool doCheckpointInsts; 51 bool doQuiesce; 52 53 void 54 arm(ExecContext *xc) 55 { 56 xc->kernelStats.arm(); 57 } 58 59 void 60 quiesce(ExecContext *xc) 61 { 62 if (!doQuiesce) 63 return; 64 65 xc->suspend(); 66 xc->kernelStats.quiesce(); 67 } 68 69 void 70 ivlb(ExecContext *xc) 71 { 72 xc->kernelStats.ivlb(); 73 } 74 75 void 76 ivle(ExecContext *xc) 77 { 78 } 79 80 void 81 m5exit_old(ExecContext *xc) 82 { 83 SimExit(curTick, "m5_exit_old instruction encountered"); 84 } 85 86 void 87 m5exit(ExecContext *xc) 88 { 89 Tick delay = xc->regs.intRegFile[16]; 90 Tick when = curTick + NS2Ticks(delay); 91 SimExit(when, "m5_exit instruction encountered"); 92 } 93 94 void 95 resetstats(ExecContext *xc) 96 { 97 if (!doStatisticsInsts) 98 return; 99 100 Tick delay = xc->regs.intRegFile[16]; 101 Tick period = xc->regs.intRegFile[17]; 102 103 Tick when = curTick + NS2Ticks(delay); 104 Tick repeat = NS2Ticks(period); 105 106 using namespace Stats; 107 SetupEvent(Reset, when, repeat); 108 } 109 110 void 111 dumpstats(ExecContext *xc) 112 { 113 if (!doStatisticsInsts) 114 return; 115 116 Tick delay = xc->regs.intRegFile[16]; 117 Tick period = xc->regs.intRegFile[17]; 118 119 Tick when = curTick + NS2Ticks(delay); 120 Tick repeat = NS2Ticks(period); 121 122 using namespace Stats; 123 SetupEvent(Dump, when, repeat); 124 } 125 126 void 127 dumpresetstats(ExecContext *xc) 128 { 129 if (!doStatisticsInsts) 130 return; 131 132 Tick delay = xc->regs.intRegFile[16]; 133 Tick period = xc->regs.intRegFile[17]; 134 135 Tick when = curTick + NS2Ticks(delay); 136 Tick repeat = NS2Ticks(period); 137 138 using namespace Stats; 139 SetupEvent(Dump|Reset, when, repeat); 140 } 141 142 void 143 m5checkpoint(ExecContext *xc) 144 { 145 if (!doCheckpointInsts) 146 return; 147 148 Tick delay = xc->regs.intRegFile[16]; 149 Tick period = xc->regs.intRegFile[17]; 150 151 Tick when = curTick + NS2Ticks(delay); 152 Tick repeat = NS2Ticks(period); 153 154 Checkpoint::setup(when, repeat); 155 } 156 157 void 158 readfile(ExecContext *xc) 159 { 160 const string &file = xc->cpu->system->readfile; 161 if (file.empty()) { 162 xc->regs.intRegFile[0] = ULL(0); 163 return; 164 } 165 166 Addr vaddr = xc->regs.intRegFile[16]; 167 uint64_t len = xc->regs.intRegFile[17]; 168 uint64_t offset = xc->regs.intRegFile[18]; 169 uint64_t result = 0; 170 171 int fd = ::open(file.c_str(), O_RDONLY, 0); 172 if (fd < 0) 173 panic("could not open file %s\n", file); 174 175 char *buf = new char[len]; 176 char *p = buf; 177 while (len > 0) { 178 int bytes = ::pread(fd, p, len, offset); 179 if (bytes <= 0) 180 break; 181 182 p += bytes; 183 offset += bytes; 184 result += bytes; 185 len -= bytes; 186 } 187 188 close(fd); 189 CopyIn(xc, vaddr, buf, result); 190 delete [] buf; 191 xc->regs.intRegFile[0] = result; 192 } 193 194 class Context : public ParamContext 195 { 196 public: 197 Context(const string §ion) : ParamContext(section) {} 198 void checkParams(); 199 }; 200 201 Context context("PseudoInsts"); 202 203 Param<bool> __quiesce(&context, "quiesce", 204 "enable quiesce instructions", 205 true); 206 Param<bool> __statistics(&context, "statistics", 207 "enable statistics pseudo instructions", 208 true); 209 Param<bool> __checkpoint(&context, "checkpoint", 210 "enable checkpoint pseudo instructions", 211 true); 212 213 void 214 Context::checkParams() 215 { 216 doQuiesce = __quiesce; 217 doStatisticsInsts = __statistics; 218 doCheckpointInsts = __checkpoint; 219 } 220} 221