/* dbXX - mm.c modify memory command */ #include "defs.h" static void mmmode( char *address, int size ) { unsigned int value; char *cp; /* enter modify mode */ while(1){ smallprintf("\n%X ",address); switch( size ){ /* make sure value is consistent */ case 1: value = (unsigned int) * ( (unsigned char *) address); puthex( (unsigned char) value & 0xff ); break; case 2: value = (unsigned int) *( (unsigned short *)address); smallprintf("%x", value & 0xffff) ; break; case 4: value = (unsigned int) * ( (unsigned int *) address); smallprintf("%X",value ) ; break; } smallprintf(" :"); // make it "hot" getstring( inbuf , SZOFINBUF ,1 ); cp = skipblanc( inbuf ); if( *cp == '.' ) return; if( *cp == '-' ) { address = address - size ; } else if( *cp == '+' ) { address = address + size ; } else if( *cp == '\n' || *cp == '\0' ) { /* reenter loop */ } else{ /* expect a new value */ value = decval( cp, 1 ); // complain if illegal switch( size ) { case 1: *((unsigned char *)address) = (unsigned char) value; break; case 2: *((unsigned short *)address) = (unsigned short) value; break; case 4: *((unsigned int *)address) = (unsigned int) value; break; } } } } void mm ( int argc, char ** argv) { int size; int address; int value; // Expect command line syntax depending on arguments... if( argc == 4 ) { // mm -b|w|l ADDRESS VALUE // modify memory and return size = getsize ( argv[1] ,1 ); address = decval( argv[2], 1 ); value = decval( argv[3], size ); switch( size ) { case 1: *((unsigned char *)address) = (unsigned char) value; break; case 2: *((unsigned short *)address) = (unsigned short) value; break; case 4: *((unsigned int *)address) = (unsigned int) value; break; } //poke( (unsigned char *) address, size, value ); return; } if( argc == 3 ) { // mm -b|w|l ADDRESS if( argv[1][0] == '-' ) { size = getsize ( argv[1] ,1 ); address = decval( argv[2], 1 ); mmmode( (char *) address, size ); }else{ // mm ADDRESS VALUE size = 2; /* default */ address = decval( argv[1], 1 ); value = decval( argv[2], 1 ); switch( size ) { case 1: *((unsigned char *)address) = (unsigned char) value; break; case 2: *((unsigned short *)address) = (unsigned short) value; break; case 4: *((unsigned int *)address) = (unsigned int) value; break; } // poke( (unsigned char *) address, DEFSIZ, value ); return; } return; } if( argc == 2 ) { // mm ADDRESS address = decval( argv[1], 1 ); mmmode( (char *) address, 4 ); return; } help_mm(); }