예제 #1
0
int disasm_dotnet(struct _memory *memory, uint32_t address, char *instruction, int *cycles_min, int *cycles_max)
{
  uint8_t opcode;
  int n;

  instruction[0] = 0;

  *cycles_min = 0;
  *cycles_max = 0;

  opcode = memory_read_m(memory, address);

  if (opcode == 0xfe)
  {
    opcode = memory_read_m(memory, address + 1);

    n = 0;
    while(table_dotnet_fe[n].instr != NULL)
    {
      if (opcode != table_dotnet_fe[n].opcode)
      {
        n++;
        continue;
      }

      switch(table_dotnet_fe[n].type)
      {
        case DOTNET_OP_NONE:
          sprintf(instruction, "%s", table_dotnet_fe[n].instr);
          return 2;
        default:
          return 2;
      }
    }
  }

  n = 0;
  while(table_dotnet[n].instr != NULL)
  {
    if (opcode != table_dotnet[n].opcode)
    {
      n++;
      continue;
    }

    switch(table_dotnet[n].type)
    {
      case DOTNET_OP_NONE:
        sprintf(instruction, "%s", table_dotnet[n].instr);
        return 1;
      default:
        return 1;
    }
  }

  return 1;
}
예제 #2
0
파일: 6800.c 프로젝트: mikeakohn/naken_asm
void list_output_6800(struct _asm_context *asm_context, uint32_t start, uint32_t end)
{
  int cycles_min,cycles_max;
  char instruction[128];
  char bytes[10];
  int count;
  int n;

  fprintf(asm_context->list, "\n");

  while(start < end)
  {
    count = disasm_6800(&asm_context->memory, start, instruction, &cycles_min, &cycles_max);

    bytes[0] = 0;
    for (n = 0; n < count; n++)
    {
      char temp[4];
      sprintf(temp, "%02x ", memory_read_m(&asm_context->memory, start + n));
      strcat(bytes, temp);
    }

    fprintf(asm_context->list, "0x%04x: %-9s %-40s cycles: ", start, bytes, instruction);

    if (cycles_min == cycles_max)
    { fprintf(asm_context->list, "%d\n", cycles_min); }
      else
    { fprintf(asm_context->list, "%d-%d\n", cycles_min, cycles_max); }

    start += count;
  }
}
예제 #3
0
void list_output_805x(struct _asm_context *asm_context, int address)
{
int cycles_min=-1,cycles_max=-1,count;
char instruction[128];
char temp[32];
char temp2[4];
int n;

  fprintf(asm_context->list, "\n");
  count=disasm_805x(&asm_context->memory, address, instruction, &cycles_min, &cycles_max);

  temp[0]=0;
  for (n=0; n<count; n++)
  {
    sprintf(temp2, "%02x ", memory_read_m(&asm_context->memory, address+n));
    strcat(temp, temp2);
  }

  fprintf(asm_context->list, "0x%04x: %-10s %-40s cycles: ", address, temp, instruction);

/*
  if (cycles_min==cycles_max)
  { fprintf(asm_context->list, "%d\n", cycles_min); }
    else
  { fprintf(asm_context->list, "%d-%d\n", cycles_min, cycles_max); }
*/
}
예제 #4
0
void test_float(const char *source, float *answer, int length, int endian)
{
  struct _asm_context asm_context = { 0 };
  int oops = 0;
  int i;

  printf("Testing: %s (%s) ... ", source, endian == LITTLE ? "little":"big");

  tokens_open_buffer(&asm_context, source);
  tokens_reset(&asm_context);

  if (endian == BIG)
  {
    asm_context.memory.endian = 1;
  }

  assemble(&asm_context);

  uint32_t f = 0;

  for (i = 0; i < length * 4; i++)
  {
    if ((i % 4) == 0) { f = 0; }

    // printf("%d) %02x\n", i, memory_read_m(&asm_context.memory, i));
    if (endian == LITTLE)
    {
      f = (f >> 8) | (memory_read_m(&asm_context.memory, i) << 24);
    }
      else
    {
예제 #5
0
void list_output_powerpc(struct _asm_context *asm_context, int address)
{
int cycles_min,cycles_max;
char instruction[128];
char bytes[10];
int count;
int n;
//unsigned int opcode=memory_read_m(&asm_context->memory, address);

  fprintf(asm_context->list, "\n");
  count=disasm_powerpc(&asm_context->memory, address, instruction, &cycles_min, &cycles_max);

  bytes[0] = 0;
  for (n = 0; n < count; n++)
  {
    char temp[4];
    sprintf(temp, "%02x ", memory_read_m(&asm_context->memory, address+n));
    strcat(bytes, temp);
  }

  fprintf(asm_context->list, "0x%04x: %-9s %-40s cycles: ", address, bytes, instruction);

  if (cycles_min == cycles_max)
  { fprintf(asm_context->list, "%d\n", cycles_min); }
    else
  { fprintf(asm_context->list, "%d-%d\n", cycles_min, cycles_max); }
}
예제 #6
0
void disasm_range_dotnet(struct _memory *memory, uint32_t flags, uint32_t start, uint32_t end)
{
  char instruction[128];
  int cycles_min = 0, cycles_max = 0;
  int opcode, count;
  char hex[80];
  char temp[16];
  int n;

  printf("\n");

  printf("%-7s %-5s %-40s Cycles\n", "Addr", "Opcode", "Instruction");
  printf("------- ------ ----------------------------------       ------\n");

  while(start <= end)
  {
    count = disasm_dotnet(memory, start, instruction, &cycles_min, &cycles_max);

     hex[0] = 0;

     for (n = 0; n < count; n++)
     {
       opcode = memory_read_m(memory, start + n);

       sprintf(temp, "%02x ", opcode);
       strcat(hex, temp);
     }

    printf("0x%04x: %-20s %-40s\n", start, hex, instruction);

    start += count;
  }
}
예제 #7
0
void disasm_range_805x(struct _memory *memory, int start, int end)
{
char instruction[128];
char temp[32];
char temp2[4];
int cycles_min=0,cycles_max=0;
int count;
int n;

  printf("\n");

  printf("%-7s %-5s %-40s Cycles\n", "Addr", "Opcode", "Instruction");
  printf("------- ------ ----------------------------------       ------\n");

  while(start<=end)
  {
    //num=READ_RAM(start)|(READ_RAM(start+1)<<8);

    count=disasm_805x(memory, start, instruction, &cycles_min, &cycles_max);

    temp[0]=0;
    for (n=0; n<count; n++)
    {
      //sprintf(temp2, "%02x ", READ_RAM(start+n));
      sprintf(temp2, "%02x ", memory_read_m(memory, start+n));
      strcat(temp, temp2);
    }

    if (cycles_min<1)
    {
      printf("0x%04x: %-10s %-40s ?\n", start, temp, instruction);
    }
      else
    if (cycles_min==cycles_max)
    {
      printf("0x%04x: %-10s %-40s %d\n", start, temp, instruction, cycles_min);
    }
      else
    {
      printf("0x%04x: %-10s %-40s %d-%d\n", start, temp, instruction, cycles_min, cycles_max);
    }

#if 0
    count-=4;
    while (count>0)
    {
      start=start+4;
      num=READ_RAM(start)|(READ_RAM(start+1)<<8);
      printf("0x%04x: 0x%04x\n", start, num);
      count-=4;
    }
#endif

    start=start+count;
  }
}
예제 #8
0
void test_int(const char *source, uint8_t *answer, int length, int endian)
{
  struct _asm_context asm_context = { 0 };
  int oops = 0;
  int i;

  printf("Testing: %s (%s) ... ", source, endian == LITTLE ? "little":"big");

  tokens_open_buffer(&asm_context, source);
  tokens_reset(&asm_context);

  if (endian == BIG)
  {
    asm_context.memory.endian = 1;
  }

  assemble(&asm_context);

  for (i = 0; i < length; i++)
  {
    if (memory_read_m(&asm_context.memory, i) != answer[i])
    {
      oops++;
    }
  }

  if (oops != 0)
  {
    printf("FAIL\n");
    errors++;
  }
    else
  {
    printf("PASS\n");
  }

  tokens_close(&asm_context);
  assembler_free(&asm_context);
}
예제 #9
0
void list_output_dotnet(struct _asm_context *asm_context, uint32_t start, uint32_t end)
{
  int cycles_min, cycles_max;
  char instruction[128];
  int opcode, count;
  char hex[80];
  char temp[16];
  int n;

  count = disasm_dotnet(&asm_context->memory, start, instruction, &cycles_min, &cycles_max);

  hex[0] = 0;

  for (n = 0; n < count; n++)
  {
    opcode = memory_read_m(&asm_context->memory, start + n);

    sprintf(temp, "%02x ", opcode);
    strcat(hex, temp);
  }

  fprintf(asm_context->list, "0x%04x: %-20s %-40s\n", start, hex, instruction);
}
예제 #10
0
  assemble(&asm_context);

  uint32_t f = 0;

  for (i = 0; i < length * 4; i++)
  {
    if ((i % 4) == 0) { f = 0; }

    // printf("%d) %02x\n", i, memory_read_m(&asm_context.memory, i));
    if (endian == LITTLE)
    {
      f = (f >> 8) | (memory_read_m(&asm_context.memory, i) << 24);
    }
      else
    {
      f = (f << 8) | memory_read_m(&asm_context.memory, i);
    }

    if ((i % 4) == 3)
    {
#if 0
      float a = f & 0x7fffff;
      uint8_t e = ((f >> 23) & 0xff);
      if ((f & 0x80000000) != 0) { a = -a; }
#endif
      union
      {
        float f;
        uint32_t i;
      } data;
예제 #11
0
파일: 6800.c 프로젝트: mikeakohn/naken_asm
int parse_instruction_6800(struct _asm_context *asm_context, char *instr)
{
  char token[TOKENLEN];
  int token_type;
  char instr_case[TOKENLEN];
  int operand_type;
  int operand_value;
  int address_size = 0;
  int opcode = -1;
  int n;

  lower_copy(instr_case, instr);

  do
  {
    token_type = tokens_get(asm_context, token, TOKENLEN);

    if (token_type == TOKEN_EOL || token_type == TOKEN_EOF)
    {
      operand_type = OPERAND_NONE;
      break;
    }

    if (token_type == TOKEN_POUND)
    {
      operand_type = OPERAND_NUMBER;
      if (eval_expression(asm_context, &operand_value) != 0)
      {
        if (asm_context->pass == 2)
        {
          print_error_illegal_expression(instr, asm_context);
          return -1;
        }

        eat_operand(asm_context);
        operand_value = 0xffff;
      }
    }
      else
    {
      operand_type = OPERAND_ADDRESS;
      tokens_push(asm_context, token, token_type);
      if (eval_expression(asm_context, &operand_value) != 0)
      {
        if (asm_context->pass == 2)
        {
          print_error_illegal_expression(instr, asm_context);
          return -1;
        }

        eat_operand(asm_context);
        operand_value = 0xffff;
      }

      token_type = tokens_get(asm_context, token, TOKENLEN);
      if (token_type == TOKEN_EOL || token_type == TOKEN_EOF) { break; }
      if (IS_NOT_TOKEN(token, ','))
      {
        print_error_unexp(token, asm_context);
        return -1;
      }

      if (expect_token_s(asm_context, "x") != 0) { return -1; }
      operand_type = OPERAND_ADDRESS_COMMA_X;
    }
  } while(0);

  for (n = 0; n < 256; n++)
  {
    if (table_6800[n].instr == NULL) { continue; }

    if (strcmp(instr_case, table_6800[n].instr) == 0)
    {
      if (table_6800[n].operand_type == M6800_OP_NONE &&
          operand_type == OPERAND_NONE)
      {
        add_bin8(asm_context, n, IS_OPCODE);
        return 1;
      }
        else
      if (table_6800[n].operand_type == M6800_OP_REL_OFFSET &&
          operand_type == OPERAND_ADDRESS)
      {
        int offset = operand_value - (asm_context->address + 2);
        if (asm_context->pass != 1)
        {
          if (offset < -128 || offset > 127)
          {
            print_error_range("Offset", -128, 127, asm_context);
            return -1;
          }
        }
        add_bin8(asm_context, n, IS_OPCODE);
        add_bin8(asm_context, offset & 0xff, IS_OPCODE);

        return 1;
      }
        else
      if (table_6800[n].operand_type == M6800_OP_IMM16 &&
          operand_type == OPERAND_NUMBER)
      {
        add_bin8(asm_context, n, IS_OPCODE);
        add_bin8(asm_context, operand_value >> 8, IS_OPCODE);
        add_bin8(asm_context, operand_value & 0xff, IS_OPCODE);
        return 3;
      }
        else
      if (table_6800[n].operand_type == M6800_OP_IMM8 &&
          operand_type == OPERAND_NUMBER)
      {
        if (asm_context->pass != 1)
        {
          if (operand_value < -128 || operand_value > 255)
          {
            print_error_range("Offset", -128, 255, asm_context);
            return -1;
          }
        }
        add_bin8(asm_context, n, IS_OPCODE);
        add_bin8(asm_context, operand_value & 0xff, IS_OPCODE);
        return 2;
      }
        else
      if (table_6800[n].operand_type == M6800_OP_NN_X &&
          operand_type == OPERAND_ADDRESS_COMMA_X)
      {
        int offset = operand_value-(asm_context->address + 2);
        if (asm_context->pass != 1)
        {
          if (offset < -128 || offset > 127)
          {
            print_error_range("Offset", -128, 127, asm_context);
            return -1;
          }
        }
        add_bin8(asm_context, n, IS_OPCODE);
        add_bin8(asm_context, offset & 0xff, IS_OPCODE);
        return 2;
      }
        else
      if (table_6800[n].operand_type == M6800_OP_DIR_PAGE_8 &&
          operand_type == OPERAND_ADDRESS)
      {
        if (asm_context->pass == 1)
        {
          if (address_size == 0 && (operand_value >= 0 && operand_value <= 255))
          {
            address_size = 1;
            opcode = n;
          }
        }

        if (memory_read_m(&asm_context->memory, asm_context->address) == 1)
        {
          add_bin8(asm_context, n, IS_OPCODE);
          add_bin8(asm_context, operand_value, IS_OPCODE);
          return 2;
        }
      }
        else
      if (table_6800[n].operand_type == M6800_OP_ABSOLUTE_16 &&
          operand_type == OPERAND_ADDRESS)
      {
        if (asm_context->pass == 1)
        {
          if (address_size == 0)
          {
            address_size = 2;
            opcode=n;
          }
        }

        if (memory_read_m(&asm_context->memory, asm_context->address)==2)
        {
          add_bin8(asm_context, n, IS_OPCODE);
          add_bin8(asm_context, operand_value >> 8, IS_OPCODE);
          add_bin8(asm_context, operand_value & 0xff, IS_OPCODE);
          return 2;
        }
      }