m5.c revision 4090:08bd6439b907
1/* 2 * Copyright (c) 2003-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: Nathan Binkert 29 */ 30 31#include <inttypes.h> 32#include <stdio.h> 33#include <stdlib.h> 34#include <string.h> 35#include <unistd.h> 36 37#include "m5op.h" 38 39char *progname; 40 41void 42usage() 43{ 44 printf("usage: m5 initparam\n" 45 " m5 sw99param\n" 46 " m5 exit [delay]\n" 47 " m5 resetstats [delay [period]]\n" 48 " m5 dumpstats [delay [period]]\n" 49 " m5 dumpresetstats [delay [period]]\n" 50 " m5 checkpoint [delay [period]]\n" 51 " m5 readfile\n" 52 "\n" 53 "All times in nanoseconds!\n"); 54 exit(1); 55} 56 57#define COMPARE(X) (strcmp(X, command) == 0) 58 59int 60main(int argc, char *argv[]) 61{ 62 char *command; 63 uint64_t param; 64 uint64_t arg1 = 0; 65 uint64_t arg2 = 0; 66 67 progname = argv[0]; 68 if (argc < 2) 69 usage(); 70 71 command = argv[1]; 72 73 if (COMPARE("initparam")) { 74 if (argc != 2) 75 usage(); 76 77 printf("%ld", m5_initparam()); 78 return 0; 79 } 80 81 if (COMPARE("sw99param")) { 82 if (argc != 2) 83 usage(); 84 85 param = m5_initparam(); 86 // run-time, rampup-time, rampdown-time, warmup-time, connections 87 printf("%d %d %d %d %d", (param >> 48) & 0xfff, 88 (param >> 36) & 0xfff, (param >> 24) & 0xfff, 89 (param >> 12) & 0xfff, (param >> 0) & 0xfff); 90 91 return 0; 92 } 93 94 if (COMPARE("exit")) { 95 switch (argc) { 96 case 3: 97 arg1 = strtoul(argv[2], NULL, 0); 98 case 2: 99 m5_exit(arg1); 100 return 0; 101 102 default: 103 usage(); 104 } 105 } 106 107 if (COMPARE("resetstats")) { 108 switch (argc) { 109 case 4: 110 arg2 = strtoul(argv[3], NULL, 0); 111 case 3: 112 arg1 = strtoul(argv[2], NULL, 0); 113 case 2: 114 m5_reset_stats(arg1, arg2); 115 return 0; 116 117 default: 118 usage(); 119 } 120 } 121 122 if (COMPARE("dumpstats")) { 123 switch (argc) { 124 case 4: 125 arg2 = strtoul(argv[3], NULL, 0); 126 case 3: 127 arg1 = strtoul(argv[2], NULL, 0); 128 case 2: 129 m5_dump_stats(arg1, arg2); 130 return 0; 131 132 default: 133 usage(); 134 } 135 } 136 137 if (COMPARE("dumpresetstats")) { 138 switch (argc) { 139 case 4: 140 arg2 = strtoul(argv[3], NULL, 0); 141 case 3: 142 arg1 = strtoul(argv[2], NULL, 0); 143 case 2: 144 m5_dumpreset_stats(arg1, arg2); 145 return 0; 146 147 default: 148 usage(); 149 } 150 } 151 152 if (COMPARE("readfile")) { 153 char buf[256*1024]; 154 int offset = 0; 155 int len; 156 157 if (argc != 2) 158 usage(); 159 160 while ((len = m5_readfile(buf, sizeof(buf), offset)) > 0) { 161 write(STDOUT_FILENO, buf, len); 162 offset += len; 163 } 164 165 return 0; 166 } 167 168 if (COMPARE("checkpoint")) { 169 switch (argc) { 170 case 4: 171 arg2 = strtoul(argv[3], NULL, 0); 172 case 3: 173 arg1 = strtoul(argv[2], NULL, 0); 174 case 2: 175 m5_checkpoint(arg1, arg2); 176 return 0; 177 178 default: 179 usage(); 180 } 181 182 return 0; 183 } 184 185 if (COMPARE("loadsymbol")) { 186 m5_loadsymbol(arg1); 187 return 0; 188 } 189 if (COMPARE("readfile")) { 190 char buf[256*1024]; 191 int offset = 0; 192 int len; 193 194 if (argc != 2) 195 usage(); 196 197 while ((len = m5_readfile(buf, sizeof(buf), offset)) > 0) { 198 write(STDOUT_FILENO, buf, len); 199 offset += len; 200 } 201 202 return 0; 203 } 204 205 usage(); 206} 207