diff options
Diffstat (limited to 'main/common/reg_cache.c')
-rw-r--r-- | main/common/reg_cache.c | 205 |
1 files changed, 104 insertions, 101 deletions
diff --git a/main/common/reg_cache.c b/main/common/reg_cache.c index 1c6c794..ec2a3f7 100644 --- a/main/common/reg_cache.c +++ b/main/common/reg_cache.c @@ -1,7 +1,7 @@ /************************************************************************** * * Copyright (c) 2013 Alcatel-Lucent - * + * * Alcatel Lucent licenses this file to You under the Apache License, * Version 2.0 (the "License"); you may not use this file except in * compliance with the License. A copy of the License is contained the @@ -20,10 +20,10 @@ * * reg_cache.c: * - * Allow the user to display CPU registers that are locally cached - * when an exception is hit. These registers are not the currently - * active registers in the CPU context; rather, a copy of the context at - * the time of the most recent breakpoint or exception. + * Allow the user to display CPU registers that are locally cached + * when an exception is hit. These registers are not the currently + * active registers in the CPU context; rather, a copy of the context at + * the time of the most recent breakpoint or exception. * * Original author: Ed Sutter (ed.sutter@alcatel-lucent.com) * @@ -43,25 +43,25 @@ * An example table is as follows (taken from FADS-MPC860 target)... * * static char *regnames[] = { - * "R0", "R1", "R2", "R3", - * "R4", "R5", "R6", "R7", - * "R8", "R9", "R10", "R11", - * "R12", "R13", "R14", "R15", - * "R16", "R17", "R18", "R19", - * "R20", "R21", "R22", "R23", - * "R24", "R25", "R26", "R27", - * "R28", "R29", "R30", "R31", - * "MSR", "CR", "LR", "XER", - * "DAR", "DSISR", "SRR0", "SRR1", - * "CTR", "DEC", "TBL", "TBU", - * "SPRG0", "SPRG1", "SPRG2", "SPRG3", + * "R0", "R1", "R2", "R3", + * "R4", "R5", "R6", "R7", + * "R8", "R9", "R10", "R11", + * "R12", "R13", "R14", "R15", + * "R16", "R17", "R18", "R19", + * "R20", "R21", "R22", "R23", + * "R24", "R25", "R26", "R27", + * "R28", "R29", "R30", "R31", + * "MSR", "CR", "LR", "XER", + * "DAR", "DSISR", "SRR0", "SRR1", + * "CTR", "DEC", "TBL", "TBU", + * "SPRG0", "SPRG1", "SPRG2", "SPRG3", * }; * - * The real definition of this array would be in the file regnames.c in + * The real definition of this array would be in the file regnames.c in * the target-specific directory. */ -#define REGTOT (sizeof regnames/sizeof(char *)) +#define REGTOT (sizeof regnames/sizeof(char *)) /* regtbl[]: * This array is used to store the actual register values. Storage @@ -73,7 +73,7 @@ ulong regtbl[REGTOT]; void flushRegtbl(void) { - flushDcache((char *)regtbl,sizeof(regtbl)); + flushDcache((char *)regtbl,sizeof(regtbl)); } /* regidx(): @@ -84,16 +84,16 @@ flushRegtbl(void) static int regidx(char *name) { - int i; - - strtoupper(name); - for(i=0;i<REGTOT;i++) { - if (!strcmp(name,regnames[i])) { - return(i); - } - } - printf("Bad reg: '%s'\n",name); - return(-1); + int i; + + strtoupper(name); + for(i=0; i<REGTOT; i++) { + if(!strcmp(name,regnames[i])) { + return(i); + } + } + printf("Bad reg: '%s'\n",name); + return(-1); } /* putreg(): @@ -103,13 +103,14 @@ regidx(char *name) int putreg(char *name,ulong value) { - int idx; + int idx; + + if((idx = regidx(name)) == -1) { + return(-1); + } - if ((idx = regidx(name)) == -1) - return(-1); - - regtbl[idx] = value; - return(0); + regtbl[idx] = value; + return(0); } /* getreg(): @@ -118,13 +119,14 @@ putreg(char *name,ulong value) int getreg(char *name,ulong *value) { - int idx; + int idx; - if ((idx = regidx(name)) == -1) - return(-1); - - *value = regtbl[idx]; - return(0); + if((idx = regidx(name)) == -1) { + return(-1); + } + + *value = regtbl[idx]; + return(0); } /* showregs(): @@ -135,13 +137,14 @@ getreg(char *name,ulong *value) void showregs(void) { - int i, j; - - for(i=0;i<REGTOT;) { - for(j=0;((j<4) && (i<REGTOT));j++,i++) - printf("%6s=0x%08lx ",regnames[i],regtbl[i]); - printf("\n"); - } + int i, j; + + for(i=0; i<REGTOT;) { + for(j=0; ((j<4) && (i<REGTOT)); j++,i++) { + printf("%6s=0x%08lx ",regnames[i],regtbl[i]); + } + printf("\n"); + } } /* reginit(): @@ -150,69 +153,69 @@ showregs(void) void reginit(void) { - int i; + int i; - for(i=0;i<REGTOT;i++) - regtbl[i] = 0; + for(i=0; i<REGTOT; i++) { + regtbl[i] = 0; + } } #if INCLUDE_STRACE char *RegHelp[] = { - "Display/modify content of monitor's register cache", - "-[v:] [regname] [value]", + "Display/modify content of monitor's register cache", + "-[v:] [regname] [value]", #if INCLUDE_VERBOSEHELP - "Options:", - " -v {var} quietly load 'var' with register content", + "Options:", + " -v {var} quietly load 'var' with register content", #endif - 0, + 0, }; int Reg(int argc,char *argv[]) { - ulong reg; - int opt, i, forscript; - char *varname, buf[32]; - - forscript = 0; - varname = (char *)0; - while((opt=getopt(argc,argv,"sv:")) != -1) { - switch(opt) { - case 's': - forscript = 1; - break; - case 'v': - varname = optarg; - break; - default: - return(CMD_PARAM_ERROR); - } - } - - if (argc == optind) { - if (forscript) { - for(i=0;i<REGTOT;i++) - printf("reg %s 0x%lx\n",regnames[i],regtbl[i]); - } - else - showregs(); - return(CMD_SUCCESS); - } - else if (argc == optind + 1) { - if (getreg(argv[optind],®) != -1) { - sprintf(buf,"0x%lx",reg); - if (varname) - setenv(varname,buf); - else - printf("%s = %s\n",argv[optind],buf); - } - } - else if (argc == optind + 2) { - putreg(argv[1],strtol(argv[optind+1],(char **)0,0)); - } - else { - return(CMD_PARAM_ERROR); - } - return(CMD_SUCCESS); + ulong reg; + int opt, i, forscript; + char *varname, buf[32]; + + forscript = 0; + varname = (char *)0; + while((opt=getopt(argc,argv,"sv:")) != -1) { + switch(opt) { + case 's': + forscript = 1; + break; + case 'v': + varname = optarg; + break; + default: + return(CMD_PARAM_ERROR); + } + } + + if(argc == optind) { + if(forscript) { + for(i=0; i<REGTOT; i++) { + printf("reg %s 0x%lx\n",regnames[i],regtbl[i]); + } + } else { + showregs(); + } + return(CMD_SUCCESS); + } else if(argc == optind + 1) { + if(getreg(argv[optind],®) != -1) { + sprintf(buf,"0x%lx",reg); + if(varname) { + setenv(varname,buf); + } else { + printf("%s = %s\n",argv[optind],buf); + } + } + } else if(argc == optind + 2) { + putreg(argv[1],strtol(argv[optind+1],(char **)0,0)); + } else { + return(CMD_PARAM_ERROR); + } + return(CMD_SUCCESS); } #endif |