From ee6ea2f21e2516047db66004fda060a23b152103 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Wed, 6 Apr 2011 17:30:31 +0200 Subject: Support memset operation --- cli.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'cli.c') diff --git a/cli.c b/cli.c index 16151fc..4fe56c9 100644 --- a/cli.c +++ b/cli.c @@ -121,6 +121,11 @@ void Usage(int argc, char *argv[], const char *format, ...) { " -s - Number of words (default: 1)\n" " -a - Bits per word (default: 32)\n" " -e - Endianess Little/Big (default: host)\n" +"\n" +" Data:\n" +" Data can be specified as sequence of hexdecimal number or\n" +" a single value prefixed with '*'. In this case it will be\n" +" replicated the specified amount of times\n" "\n\n", argv[0]); @@ -565,6 +570,8 @@ int main(int argc, char **argv) { const char *addr = NULL; const char *reg = NULL; const char *bank = NULL; + char **data = NULL; + uintptr_t start = -1; size_t size = 1; access_t access = 4; @@ -665,7 +672,16 @@ int main(int argc, char **argv) { switch (mode) { case MODE_WRITE: if (!addr) Usage(argc, argv, "The address is not specified"); - if ((argc - optind) != size) Usage(argc, argv, "The %i data values is specified, but %i required", argc - optind, size); + if (((argc - optind) == 1)&&(*argv[optind] == '*')) { + int vallen = strlen(argv[optind]); + data = (char**)malloc(size * (vallen + sizeof(char*))); + if (!data) Error("Error allocating memory for data array"); + for (i = 0; i < size; i++) { + data[i] = ((char*)data) + size * sizeof(char*) + i * vallen; + strcpy(data[i], argv[optind] + 1); + } + } else if ((argc - optind) == size) data = argv + optind; + else Usage(argc, argv, "The %i data values is specified, but %i required", argc - optind, size); break; case MODE_READ: if (!addr) { @@ -735,13 +751,15 @@ int main(int argc, char **argv) { else ReadRegisterRange(handle, model, bank, start, size); break; case MODE_WRITE: - WriteData(handle, bar, start, size, access, endianess, argv + optind); + WriteData(handle, bar, start, size, access, endianess, data); break; case MODE_WRITE_REGISTER: - if (reg) WriteRegister(handle, model, bank, reg, argv + optind); - else WriteRegisterRange(handle, model, bank, start, size, argv + optind); + if (reg) WriteRegister(handle, model, bank, reg, data); + else WriteRegisterRange(handle, model, bank, start, size, data); break; } pcilib_close(handle); + + if (data != argv + optind) free(data); } -- cgit v1.2.3