From: Stefan E. <se...@us...> - 2001-10-04 14:46:11
|
Update of /cvsroot/blob/blob/src In directory usw-pr-cvs1:/tmp/cvs-serv27518 Modified Files: debug.c Log Message: - moved peek and pore from chkmem.c over here - added memcpy command - added bitchg command Index: debug.c =================================================================== RCS file: /cvsroot/blob/blob/src/debug.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- debug.c 2001/10/04 12:38:59 1.1 +++ debug.c 2001/10/04 14:46:08 1.2 @@ -0,0 +1,285 @@ +/* + * debug.c: Debugging command functions + * + * Copyright (C) 2001 Stefan Eletzhofer <ste...@ww...> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ident "$Id$" + +/********************************************************************** + * Includes + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "errno.h" +#include "error.h" +#include "types.h" +#include "util.h" +#include "serial.h" +#include "command.h" + +/********************************************************************** + * defines + */ + +/* this will send a cold shiver through erik's spine ... */ +#define ERR( x ) { ret = x; goto DONE; } + +/* more readable IMHO */ +#define MEM( x ) (*((u32 *)x)) + +/********************************************************************** + * program globals + */ + +/********************************************************************** + * module globals + */ + +/********************************************************************** + * prototypes + */ + +void perror( int errno, char *func ) +{ + printerrprefix(); + + if ( errno < 0 ) + errno = -errno; + + if ( func != NULL) { + SerialOutputString(func); + SerialOutputString(": "); + } + SerialOutputString(strerror(errno)); + + SerialOutputByte('\n'); +} + +/********************************************************************** + * exported functions + */ + +/********************************************************************** + * static functions + */ + +/********************************************************************* + * CmdMemcpy + * + * AUTOR: SELETZ + * REVISED: + * + * Command wrapper for memcpy utility function. + * + */ +static int CmdMemcpy( int argc, char *argv[] ) +{ + int ret = 0; + u32 src = 0L; + u32 dest = 0L; + u32 len = 0L; + + if ( argc < 4 ) ERR( -EINVAL ); + + ret = strtoval( argv[1], &src ); + if ( ret < 0 ) ERR( -EINVAL ); + + ret = strtoval( argv[2], &dest ); + if ( ret < 0 ) ERR( -EINVAL ); + + ret = strtoval( argv[3], &len ); + if ( ret < 0 ) ERR( -EINVAL ); + + /* counted in words */ + if ( len & 0x00000003 ) { + len = ( len >> 2 ) + 1; + } else { + len = len >> 2; + } + + SerialOutputString("\n### Now copying 0x"); + SerialOutputHex(len); + SerialOutputString(" words from 0x"); + SerialOutputHex((int)src); + SerialOutputString(" to 0x"); + SerialOutputHex((int)dest); + SerialOutputByte('\n'); + + MyMemCpy( (u32 *)dest, (const u32 *)src, len); + + SerialOutputString(" done\n"); + + ret = 0; +DONE: + if ( ret != 0 ) { + perror( ret, __FUNCTION__ ); + } + return ret; +} + +static char memcpyhelp[] = "memcpy [source] [dest] [len]\n" +"copy memory blocks\n"; +__commandlist(CmdMemcpy, "memcpy", memcpyhelp); + +/********************************************************************* + * Poke + * + * AUTOR: Stefan Eletzhofer + * REVISED: + * + * Poke values to memory + * + */ +int Poke( int argc, char *argv[] ) +{ + int ret = 0; + u32 address; + u32 value; + + if ( argc < 3 ) ERR( -EINVAL ); + + ret = strtoval(argv[1], &address); + if ( ret < 0 ) ERR( -EINVAL ); + + ret = strtoval(argv[2], &value); + if ( ret < 0 ) ERR( -EINVAL ); + +#if CHKMEM_DEBUG + SerialOutputString("adr=0x"); + SerialOutputHex(address); + SerialOutputString(" val=0x"); + SerialOutputHex(value); + SerialOutputString("\n"); +#endif + + MEM( address ) = value; + + ret = 0; +DONE: + if ( ret != 0 ) { + perror( ret, __FUNCTION__ ); + } + return ret; +} +static char pokehelp[] = "poke address value\n"; +__commandlist(Poke, "poke", pokehelp ); + +/********************************************************************* + * Peek + * + * AUTOR: Stefan Eletzhofer + * REVISED: + * + * Poke values to memory + * + */ +int Peek( int argc, char *argv[] ) +{ + int ret = 0; + u32 address; + u32 value; + + if ( argc < 2 ) ERR( -EINVAL ); + + ret = strtoval(argv[1], &address); + if ( ret < 0 ) ERR( -EINVAL ); + +#if CHKMEM_DEBUG + SerialOutputString("adr=0x"); + SerialOutputHex(address); + SerialOutputString("\n"); +#endif + + value = MEM( address ); + + SerialOutputHex(value); + SerialOutputString("\n"); + + ret = 0; +DONE: + if ( ret != 0 ) { + perror( ret, __FUNCTION__ ); + } + return ret; +} +static char peekhelp[] = "peek address\n"; +__commandlist(Peek, "peek", peekhelp ); + + +/********************************************************************* + * BitChange + * + * AUTOR: SELETZ + * REVISED: + * + * Modifies bits of an given memory location + * + */ +int BitChange( int argc, char *argv[] ) +{ + int ret = 0; + u32 adr = 0L; + u32 value = 0L; + + if ( argc < 4 ) ERR( -EINVAL ); + + ret = strtoval( argv[1], &adr ); + if ( ret < 0 ) ERR( -EINVAL ); + + ret = strtoval( argv[2], &value ); + if ( ret < 0 ) ERR( -EINVAL ); + + SerialOutputHex( MEM( adr ) ); + + switch ( argv[3][0] & (~0x20) ) { + case 'A': + MEM( adr ) &= value; + break; + case 'S': + case 'O': + MEM( adr ) |= value; + break; + case 'X': + MEM( adr ) ^= value; + break; + case 'C': + MEM( adr ) &= ~value; + break; + default: + ERR( -EINVAL ); + break; + } + + SerialOutputString( "->" ); + SerialOutputHex( MEM( adr ) ); + SerialOutputString( "\n" ); + + ret = 0; +DONE: + if ( ret != 0 ) { + perror( ret, __FUNCTION__ ); + } + return ret; +} +static char bitchghelp[] = "bitchg address value {and|or|xor|set|clear}\n"; +__commandlist(BitChange, "bitchg", bitchghelp ); + |