Commit e4cf1adc806f24d26756fa828e0d7b515a06752d

Authored by bellard
1 parent 72cc6cfe

added sum command


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1434 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 18 additions and 0 deletions
monitor.c
@@ -562,6 +562,22 @@ static void do_print(int count, int format, int size, unsigned int valh, unsigne @@ -562,6 +562,22 @@ static void do_print(int count, int format, int size, unsigned int valh, unsigne
562 term_printf("\n"); 562 term_printf("\n");
563 } 563 }
564 564
  565 +static void do_sum(uint32_t start, uint32_t size)
  566 +{
  567 + uint32_t addr;
  568 + uint8_t buf[1];
  569 + uint16_t sum;
  570 +
  571 + sum = 0;
  572 + for(addr = start; addr < (start + size); addr++) {
  573 + cpu_physical_memory_rw(addr, buf, 1, 0);
  574 + /* BSD sum algorithm ('sum' Unix command) */
  575 + sum = (sum >> 1) | (sum << 15);
  576 + sum += buf[0];
  577 + }
  578 + term_printf("%05d\n", sum);
  579 +}
  580 +
565 typedef struct { 581 typedef struct {
566 int keycode; 582 int keycode;
567 const char *name; 583 const char *name;
@@ -906,6 +922,8 @@ static term_cmd_t term_cmds[] = { @@ -906,6 +922,8 @@ static term_cmd_t term_cmds[] = {
906 "keys", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1')" }, 922 "keys", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1')" },
907 { "system_reset", "", do_system_reset, 923 { "system_reset", "", do_system_reset,
908 "", "reset the system" }, 924 "", "reset the system" },
  925 + { "sum", "ii", do_sum,
  926 + "addr size", "compute the checksum of a memory region" },
909 { NULL, NULL, }, 927 { NULL, NULL, },
910 }; 928 };
911 929