Beispiel #1
0
int shell_addbp(char **args)
{
    if (!args[1]) return MISSING_ARGS;

    add_bp(get_value_from_string(args[1]));
    return OK;
}
Beispiel #2
0
void debug_interf(void)
{
    char in_buf[256];
    char val[32];
    char cmd;
    int in_a, in_b, in_c;
    int i, j;
    while (1) {
        printf("> ");
        fflush(stdout);
        //    in_buf[0]=0;
        // memset(in_buf,0,255);
        //scanf("%s %s",in_buf);
        fgets(in_buf, 255, stdin);
        switch (in_buf[0]) {
        case 'q':
        case 'c':
            dbg_step = 0;
            return;
            break;
        case 's':
            dbg_step = 1;
            return;
        case 'b':
            sscanf(in_buf, "%c %x", &cmd, &in_a);
            add_bp(in_a);
            break;
        case 'B':
            sscanf(in_buf, "%c %x", &cmd, &in_a);
            del_bp(in_a);
            break;
        case 'd':
            sscanf(in_buf, "%c %s", &cmd, val);
            /*
               printf("in : %s\n",in_buf);
               printf("val: %s\n",val);
             */
            in_a = strtol(val, NULL, 0);
            //      printf("ina: %x\n",in_a);
            cpu_68k_disassemble(in_a, 10);
            break;
        case 'p':
            cpu_68k_dumpreg();
            break;
        }
        printf("\n");
    }
}
static void dbg_get(char* s, int size) {
    //char buf[size];
    char *args,*argsend;
    int pc;

    fgets(s, size, stdin);

    args = s + 1;
    while((*args) && ((*args) < 32)) args++;

    switch (s[0]) {
    case '?':
	printf("B [address]           Add a breakpoint at [address]\n"
	       "N [address]           Del breakpoint at [address]\n"
	       "R                     Run until breakpoint\n");
	return;
    case 'B':
	if (args) {
	    pc=strtoul(args,&argsend,0);
	    if (args != argsend)
		add_bp(pc);
	    else
		printf("Invalid input\n");
	}
	s[0]=0;
	break;
    case 'N':
	if (args) {
	    pc=strtoul(args,&argsend,0);
	    if (args != argsend)
		del_bp(pc);
	    else
		printf("Invalid input\n");
	}
	s[0]=0;
	break;
    case 'R':
	while(check_bp(cpu_68k_getpc())!=SDL_TRUE && dbg_step==0) {
	     cpu_68k_dpg_step();
	}
	if (dbg_step) dbg_step=0;
	s[0]=0;
	break;
    }
    
}
Beispiel #4
0
create() {
   ::create();
   set_bp_flags( BT_INSECT );
   add_bp( BP_HEAD, "head", 2, 2 );
   add_bp( BP_CHEST, "chest", 3, 1 );
   add_bp( BP_BACK, "back", 4, 0 );
   add_bp( BP_LLEG, "left front leg", 1, -1 );
   add_bp( BP_RLEG, "right front leg", 1, -1 );
   add_bp( BP_LLEG2, "left middle leg", 1, -1 );
   add_bp( BP_RLEG2, "right middle leg", 1, -1 );
   add_bp( BP_LLEG3, "left rear leg", 1, -1 );
   add_bp( BP_RLEG3, "right rear leg", 1, -1 );
   set_size( 10 );
   set_food_cost( 1 );
   set_water_cost( 1 );
   set_hp_per_con( 10 );
   set_min_hp( 5 );
   set_mana_per_emp( 1 );
   set_mana_per_int( 0 );
   set_min_mana( 0 );
   set_end_per_con( 4 );
   set_end_per_will( 2 );
   set_min_end( 10 );
}
Beispiel #5
0
create() {
   ::create();
   set_bp_flags( BT_QUADRUPED | BP_TAIL );
   add_bp( BP_HEAD, "head", 2, 2 );
   add_bp(  BP_NECK, "neck", 1, 2 );
   add_bp(  BP_CHEST, "chest", 3, 1 );
   add_bp(  BP_GROIN, "loins", 0, 1 );
   add_bp(  BP_BACK, "back", 4, 0 );
   add_bp(  BP_TAIL, "tail", 3, -2 );
   add_bp(  BP_LLEG, "front left leg", 2, -1 );
   add_bp(  BP_RLEG, "front right leg", 2, -1 );
   add_bp(  BP_LFOOT, "front left hoof", 1, -2 );
   add_bp(  BP_RFOOT, "front right hoof", 1, -2 );
   add_bp(  BP_LLEG2, "rear left leg", 1, -1 );
   add_bp(  BP_RLEG2, "rear right leg", 1, -1 );
   add_bp(  BP_LFOOT2, "rear left hoof", 0, -2 );
   add_bp(  BP_RFOOT2, "rear right hoof", 0, -2 );
   set_size( 30 );
   set_food_cost( 4 );
   set_water_cost( 4 );
   set_hp_per_con( 8 );
   set_min_hp( 35 );
   set_mana_per_emp( 1 );
   set_mana_per_int( 0 );
   set_min_mana( 0 );
   set_end_per_con( 4 );
   set_end_per_will( 2 );
   set_min_end( 10 );
}
Beispiel #6
0
int
main(void)
{
  // INITIALIZING
  struct queue cmd_queue;
  q_init (&cmd_queue);

  uint8_t *mem = calloc (__MEMORY_SIZE, sizeof(uint8_t));
  char *input = malloc (sizeof(char)*__INPUT_SIZE);
  char *cmd = malloc (sizeof(char)*__CMD_SIZE);
  char *filename = malloc (sizeof(char)*__FILENAME_SIZE);
  if (mem == NULL || input == NULL || filename == NULL
      || cmd == NULL)
    {
      puts("MEMORY INSUFFICIENT");
      goto memory_clear;
    }

  if (!init_oplist (__OPCODE_FILENAME))
    {
      puts("OPCODE LIST INITIALIZATION FAILED.");
      goto memory_clear;
    }

  // COMMAND PROCESSING
  while (true)
    {
      int i;
      struct q_elem *qe;
      uint8_t value;
      uint32_t start, end;
      DIR *dirp = NULL;
      struct dirent *dir = NULL;
      char check[2];
      bool is_valid_cmd = false;
      char *tok = NULL;

      printf("%s", __SHELL_FORM);
      if (!get_chars(input, __INPUT_SIZE))
        goto memory_clear;

      // Processing input string
      snprintf((char *) __CMD_FORMAT, __CMD_FORMAT_SIZE,
                   "%%%ds", __CMD_SIZE - 1);
      if (sscanf(input, (const char *) __CMD_FORMAT, cmd)!=1)
        cmd[0] = '\0';
      
      // Switching with commands
      switch(get_cmd_index(cmd))
        {
        case CMD_HELP:
          if(sscanf(input, "%*s %1s", check) == 1)
            {
              puts("WRONG INSTRUCTION");
              break;
            }
          puts(__HELP_FORM);
          is_valid_cmd = true;
          break;
        
        case CMD_DIR:
          if(sscanf(input, "%*s %1s", check) == 1)
            {
              puts("WRONG INSTRUCTION");
              break;
            }
          // open directory and read through all elem.
          i = 1;
          dirp = opendir(".");
          dir = readdir(dirp);
          for(; dir!=NULL; dir = readdir(dirp))
            {
              struct stat st;
              if(stat((const char*) dir->d_name, &st)!=0)
                {
                  puts("FILE NOT FOUND");
                  goto memory_clear;
                }
              // FIX: ignore . and ..
              if(_SAME_STR(dir->d_name, ".")
                 || _SAME_STR(dir->d_name, ".."))
                continue;
              printf("%20s", dir->d_name);
              if(S_ISDIR(st.st_mode)) // is Directory?
                putchar('/');
              else if( (st.st_mode & S_IXUSR) // is exe?
                 || (st.st_mode & S_IXGRP)
                 || (st.st_mode & S_IXOTH) )
                putchar('*');
              putchar('\t');
             
              // print newline after 3 elements
              if((i++)%3==0)
                putchar('\n');
            }
          if((i-1)%3!=0)
            putchar('\n');
          
          is_valid_cmd = true;
          break;
        
        case CMD_QUIT:
          if(sscanf(input, "%*s %1s", check) == 1)
            {
              puts("WRONG INSTRUCTION");
              break;
            }
          
          is_valid_cmd = true;
          goto memory_clear;
        
        case CMD_HISTORY:
          if(sscanf(input, "%*s %1s", check) == 1)
            {
              puts("WRONG INSTRUCTION");
              break;
            }
          qe = q_begin (&cmd_queue);
          i = 1;
          // print every formatted history
          for (; qe!=q_end(&cmd_queue); qe=q_next(qe))
            printf("%-4d %s\n", i++,
                   q_entry(qe, struct cmd_elem, elem)->cmd);
          printf("%-4d %s\n", i, input);
          
          is_valid_cmd = true;
          break;
        
        case CMD_DUMP:
          switch(sscanf(input, "%s %x , %x", cmd, &start, &end))
            {
            case 1:
              if(sscanf(input, "%*s %1s", check) == 1)
                {
                  puts("WRONG INSTRUCTION");
                  break;
                }
              start = get_location (0, false);
              end = start + 0x10 * 10 - 1;
              // if end is too large, point to end and go 0
              if ( end >= __MEMORY_SIZE )
                end = __MEMORY_SIZE - 1;
              hexdump (mem, start, end);
              if ( end == __MEMORY_SIZE - 1)
                get_location (0, true);
              else
                get_location (end + 1, true);
              
              is_valid_cmd = true;
              break;
            
            case 2:
              if(sscanf(input, "%*s %*x %1s", check) == 1)
                {
                  puts("WRONG INSTRUCTION");
                  break;
                }
              if (start >= __MEMORY_SIZE)
                {
                  puts("OUT OF MEMORY BOUNDS.");
                  break;
                }
              end = start + 0x10 * 10 - 1;
              // if end is too large, point to end and go 0
              if ( end >= __MEMORY_SIZE )
                end = __MEMORY_SIZE - 1;
              hexdump (mem, start, end);
              if ( end == __MEMORY_SIZE - 1)
                get_location (0, true);
              else
                get_location (end + 1, true);
              
              is_valid_cmd = true;
              break;
            
            case 3:
              if(sscanf(input, "%*s %*x , %*x %1s", check) == 1)
                {
                  puts("WRONG INSTRUCTION");
                  break;
                }
              if (!(start<=end && end<__MEMORY_SIZE))
                {
                  puts("OUT OF MEMORY BOUNDS.");
                  break;
                }
              hexdump (mem, start, end);
              // if end is too large, point to end and go 0
              if ( end == __MEMORY_SIZE - 1)
                get_location (0, true);
              else
                get_location (end + 1, true);
              
              is_valid_cmd = true;
              break;

            default:
              puts("WRONG INSTRUCTION");
              break;
            }
          break;
        
        case CMD_EDIT:
          switch(sscanf(input, "%s %x , %hhx",
                        cmd, &start, &value))
            {
            case 3:
              if(sscanf(input, "%*s %*x , %*x %1s", check) == 1)
                {
                  puts("WRONG INSTRUCTION");
                  break;
                }
              hexfill (mem, __MEMORY_SIZE, start, start, value);
              
              is_valid_cmd = true;
              break;
            
            default:
              puts("WRONG INSTRUCTION");
              break;
            }
          break;
        
        case CMD_FILL:
          switch(sscanf(input, "%s %x , %x , %hhx",
                        cmd, &start, &end, &value))
            {
            case 4:
              if(sscanf(input,
                        "%*s %*x , %*x , %*x %1s", check) == 1)
                {
                  puts("WRONG INSTRUCTION");
                  break;
                }
              hexfill (mem, __MEMORY_SIZE, start, end, value);
              
              is_valid_cmd = true;
              break;
            
            default:
              puts("WRONG INSTRUCTION");
              break;
            }
          break;

        case CMD_RESET:
          if(sscanf(input, "%*s %1s", check) == 1)
            {
              puts("WRONG INSTRUCTION");
              break;
            }
          // equivalent to fill 0, __MEMORY_SIZE-1
          hexfill (mem, __MEMORY_SIZE, 0, __MEMORY_SIZE - 1, 0);
              
          is_valid_cmd = true;
          break;

        case CMD_OPCODE:
          switch(sscanf(input, "%*s %s", cmd))
            {
            case 1:
              if(sscanf(input, "%*s %*s %1s", check) == 1)
                {
                  puts("WRONG INSTRUCTION");
                  break;
                }
              i = find_oplist (cmd);
              if (i != -1)
                printf("opcode is %02X\n", i);
              else
                {
                  printf("%s: NO SUCH OPCODE\n", cmd);
                  is_valid_cmd = false;
                }
              break;

            default:
              puts("WRONG INSTRUCTION");
              break;
            }
          break;

        case CMD_OPCODELIST:
          if(sscanf(input, "%*s %1s", check) == 1)
            {
              puts("WRONG INSTRUCTION");
              break;
            }
          print_oplist ();
          is_valid_cmd = true;
          break;

        case CMD_ASSEMBLE:
          // Processing input string
          snprintf((char *) __CMD_FORMAT,
                   __CMD_FORMAT_SIZE,
                   "%%%ds %%%ds %%1s",
                   __CMD_SIZE - 1,
                   __FILENAME_SIZE - 1);
          if (sscanf(input,
                     (const char *) __CMD_FORMAT,
                     cmd, filename, check)!=2)
            {
              puts("WRONG INSTRUCTION");
              break;
            }
          if (!is_file((const char*)filename))
            {
              puts("FILE NOT FOUND");
              break;
            }

          is_valid_cmd = assemble_file (filename);

          break;

        case CMD_TYPE:
          // Processing input string
          snprintf((char *) __CMD_FORMAT,
                   __CMD_FORMAT_SIZE,
                   "%%%ds %%%ds %%1s",
                   __CMD_SIZE - 1,
                   __FILENAME_SIZE - 1);
          if (sscanf(input,
                     (const char *) __CMD_FORMAT,
                     cmd, filename, check)!=2)
            {
              puts("WRONG INSTRUCTION");
              break;
            }
          if (!is_file((const char*)filename))
            {
              puts("FILE NOT FOUND");
              break;
            }
          else
            {
              print_file((const char*)filename);
              is_valid_cmd = true;
            }

          break;

        case CMD_SYMBOL:
          if(sscanf(input, "%*s %1s", check) == 1)
            {
              puts("WRONG INSTRUCTION");
              break;
            }

          print_symbol_table ();
          is_valid_cmd = true;

          break;

        case CMD_PROGADDR:
          if(sscanf(input, "%*s %*x %1s", check) == 1
             || sscanf(input, "%*s %x", &i) != 1)
            {
              puts("WRONG INSTRUCTION");
              break;
            }
          if (i < 0 || i >= __MEMORY_SIZE - 1)
            {
              puts("INVALID PROGRAM ADDRESS");
              break;
            }

          set_progaddr ((uint32_t) i);
          is_valid_cmd = true;

          break;

        case CMD_LOADER:
          init_loader ();
          tok = strtok (input, " ");
          while ( (tok = strtok (NULL, " ")) != NULL)
            {
              if (!is_file (tok))
                {
                  printf ("[%s]: INVALID FILE\n", tok);
                  free_loader ();
                  break;
                }
              if (!add_obj_loader (tok))
                {
                  printf ("[%s]: LOADER FAILED\n", tok);
                  free_loader ();
                  break;
                }
            }

          // if normally added
          if (tok == NULL)
            {
              // address __MEMORY_SIZE is reserved for boot
              if (get_proglen()+get_progaddr()>=__MEMORY_SIZE-1)
                {
                  puts ("PROGRAM IS TOO BIG: LOADER FAILED");
                  free_loader ();
                  break;
                }
              if (!run_loader (mem))
                {
                  puts ("LOADER FAILED");
                  free_loader ();
                  break;
                }
              print_load_map ();
            }
          free_loader ();
          is_valid_cmd = true;

          break;

        case CMD_RUN:
          if(sscanf(input, "%*s %1s", check) == 1)
            {
              puts("WRONG INSTRUCTION");
              break;
            }
          if (!init_run ())
            {
              puts ("RUN FAILED");
              free_run ();
              break;
            }
          run (mem);
          free_run ();
          is_valid_cmd = true;

          break;

        case CMD_BP:
          if(sscanf(input, "%*s %1s", check) != 1)
            {
              print_bp ();
              is_valid_cmd = true;
              break;
            }
          if(sscanf(input, "%*s %6s %1s", cmd, check) == 2
             || sscanf(input, "%*s %6s", cmd) != 1)
            {
              puts("WRONG INSTRUCTION");
              break;
            }
          if (_SAME_STR(cmd, "clear"))
            {
              puts ("\t[ok] clear all breakpoints");
              free_bp ();
              is_valid_cmd = true;
              break;
            }

          if(sscanf(input, "%*s %*x %1s", check) == 1
             || sscanf(input, "%*s %x", &start) != 1)
            {
              puts("WRONG INSTRUCTION");
              break;
            }
          if (start >= __MEMORY_SIZE - 1)
            {
              puts ("INVALID BREAKPOINT ADDRESS");
              break;
            }
          if (add_bp (start))
            printf ("\t[ok] create breakpoint %x\n", start);
          is_valid_cmd = true;

          break;

        default:
          if(sscanf(input, "%1s", check) == 1)
            {
              puts("WRONG INSTRUCTION");
              break;
            }
        }

      if (is_valid_cmd)
        {
          // Saving commands
          struct cmd_elem *e = malloc(sizeof(struct cmd_elem));
          if (e == NULL)
            {
              puts("MEMORY INSUFFICIENT.");
              goto memory_clear;
            }
          e->cmd = malloc(sizeof(char)*(strlen(input)+1));
          if (e->cmd == NULL)
            {
              puts("MEMORY INSUFFICIENT.");
              goto memory_clear;
            }
          strcpy(e->cmd, input);
          q_insert (&cmd_queue, &(e->elem));
        } 
    }


memory_clear:
  if (mem != NULL)
    free (mem);
  if (input != NULL)
    free (input);
  if (cmd != NULL)
    free (cmd);
  while (!q_empty(&cmd_queue))
    {
      struct q_elem *e = q_delete(&cmd_queue);
      struct cmd_elem *ce = q_entry(e, struct cmd_elem, elem);
      if (ce->cmd != NULL)
        free(ce->cmd);
      free(ce);
    }
  free_oplist ();
  free_loader ();
  free_bp ();
  free_run ();

  return 0;
}