00001 /* 00002 Copyright (C) 2000-2003, Intel Corporation 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, 00006 are permitted provided that the following conditions are met: 00007 00008 Redistributions of source code must retain the above copyright notice, this list 00009 of conditions and the following disclaimer. 00010 00011 Redistributions in binary form must reproduce the above copyright notice, this list 00012 of conditions and the following disclaimer in the documentation and/or other materials 00013 provided with the distribution. 00014 00015 Neither the name of the owner nor the names of its contributors may be used to endorse or 00016 promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR 00021 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00022 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 00023 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00024 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 */ 00027 00028 //-*-c++-*- 00029 //============================================================================= 00030 // 00031 // Module : ekapi_opcode_access.cxx 00032 // $Date : $ 00033 // $Author: marcel $ 00034 // $Source: /proj/osprey/CVS/open64/osprey1.0/common/ipfec_targ_info/access/ekapi_opcode_access.cxx,v $ 00035 // 00036 // Description: 00037 // ============ 00038 // access opcode from knob file, and encapsulate KAPI 00039 // first layer opcode of access layer. 00040 //============================================================================= 00041 00042 #include <string.h> 00043 #include <stdio.h> 00044 #include <assert.h> 00045 #include <stdlib.h> 00046 00047 #include "ekapi_ia64.h" 00048 #include "ekapi_util.h" 00049 00050 // Function: EKAPI_OpCount 00051 // pknobs: A pointer to the variable initialized by KAPI_initialize(). 00052 // Return the count of all the opcodes 00053 int EKAPI_OpCount(void *pknobs) 00054 { 00055 return KAPI_count4attribute( pknobs , "opcode" ); 00056 }; 00057 00058 // Function: EKAPI_Op2Fu 00059 // pknobs: A pointer to the variable initialized by KAPI_initialize(). 00060 // index: Index of the op. 00061 // Return a function class of an op 00062 char *EKAPI_Op2Fu( void *pknobs, int index) 00063 { 00064 char *str_knob, *str_fu,*fu_name; 00065 int ID; 00066 char *name; 00067 00068 str_knob = KAPI_attribute4index( pknobs, "opcode", index); 00069 FmtAssert(str_knob, ("opcode attribute should not be NULL")); 00070 00071 //get the third field from whole attribute string str_knob. 00072 ID = atoi(strtok( str_knob, "," )); 00073 Is_True(ID==index, ("Opcode %d not equal to index %d!\n", ID, index)); 00074 strtok( NULL, "," ); 00075 00076 str_fu = StrTrim(strtok( NULL, "," )); 00077 fu_name = StrTrim(strtok(str_fu, ":")); 00078 00079 // fu_name[1] = StrTrim(strtok(NULL, ":")); 00080 00081 name = strdup(fu_name); 00082 00083 free(str_knob); 00084 00085 return name; 00086 } 00087 00088 00089 // Function: EKAPI_OpName4id 00090 // pknobs: A pointer to the variable initialized by KAPI_initialize(). 00091 // index: Index of the op. 00092 // Return an op's name according to the code 00093 char * EKAPI_OpName4id(void *pknobs, int index) 00094 { 00095 char *str_knob, *str_name, *name; 00096 int ID; 00097 00098 str_knob = KAPI_attribute4index( pknobs, "opcode", index); 00099 00100 //get the second field from whole attribute string str_knob. 00101 ID = atoi(strtok( str_knob, "," )); 00102 Is_True(ID==index, ("Opcode %d not equal to index %d!\n", ID, index)); 00103 00104 str_name = StrTrim(strtok( NULL, "," )); 00105 name = strdup(str_name); 00106 00107 free(str_knob); 00108 return name; 00109 } 00110 // Function EKAPI_Op2FuIndex 00111 // pknobs: A pointer to the variable initialized by KAPI_initialize(). 00112 // index: index of an op 00113 // Return an op's function class identical 00114 int EKAPI_Op2FuIndex(void *pknobs, int index) 00115 { 00116 char *buf; 00117 int fu; 00118 00119 buf = EKAPI_Op2Fu(pknobs, index); 00120 if ( (strcmp(buf, "fuUNKNOWN") == 0) || 00121 (strcmp(buf, "fuDUMMY") ==0) ) 00122 { 00123 fu = -2; 00124 } 00125 else 00126 { 00127 //If not hold this function class ,it will return -1 00128 fu = KAPI_fuName2fuIndex( pknobs, buf ); 00129 } 00130 00131 // free(buf); 00132 return fu; 00133 } 00134
1.5.6