Rizin
unix-like reverse engineering framework and cli tools
M68KInstructionTblGen.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  opcode_struct
 

Macros

#define DECL_SPEC
 

Functions

static int valid_ea (unsigned int opcode, unsigned int mask)
 
static int DECL_SPEC compare_nof_true_bits (const void *aptr, const void *bptr)
 
static void build_opcode_table (void)
 
int main ()
 

Variables

static opcode_struct g_opcode_info []
 

Macro Definition Documentation

◆ DECL_SPEC

#define DECL_SPEC

Definition at line 387 of file M68KInstructionTblGen.c.

Function Documentation

◆ build_opcode_table()

static void build_opcode_table ( void  )
static

Definition at line 411 of file M68KInstructionTblGen.c.

412 {
413  unsigned int i;
414  unsigned int opcode;
415  opcode_struct* ostruct;
416  unsigned int opcode_info_length = 0;
417  const unsigned int total_count = 0x10000;
418 
419  for(ostruct = g_opcode_info;ostruct->name != 0;ostruct++)
420  opcode_info_length++;
421 
422  qsort((void *)g_opcode_info, opcode_info_length, sizeof(g_opcode_info[0]), compare_nof_true_bits);
423 
424  printf("/* This table is auto-generated. DO NOT MANUALLY EDIT! Look in M68KInstructionTblGen.c for more info */\n");
425  printf("static instruction_struct g_instruction_table[] = {\n");
426 
427  for(i=0;i<0x10000;i++) {
428  const char *name = "d68000_invalid";
429  uint16_t word2_mask = 0;
430  uint16_t word2_match = 0;
431  opcode = i;
432  /* search through opcode info for a match */
433  for(ostruct = g_opcode_info;ostruct->name != 0;ostruct++) {
434  /* match opcode mask and allowed ea modes */
435  if ((opcode & ostruct->mask) == ostruct->match) {
436  /* Handle destination ea for move instructions */
437  if ((!strcmp(ostruct->name, "d68000_move_8") ||
438  !strcmp(ostruct->name, "d68000_move_16") ||
439  !strcmp(ostruct->name, "d68000_move_32")) &&
440  !valid_ea(((opcode>>9)&7) | ((opcode>>3)&0x38), 0xbf8))
441  continue;
442  if (valid_ea(opcode, ostruct->ea_mask)) {
443  name = ostruct->name;
444  word2_mask = ostruct->mask2;
445  word2_match = ostruct->match2;
446  break;
447  }
448  }
449  }
450 
451  // Handle so the last entry won't have a , at the end
452  if (i != total_count - 1) {
453  printf("\t{ %s, 0x%x, 0x%x },\n", name, word2_mask, word2_match);
454  } else {
455  printf("\t{ %s, 0x%x, 0x%x }\n", name, word2_mask, word2_match);
456  }
457  }
458 
459  printf("};\n\n");
460 }
static opcode_struct g_opcode_info[]
static int valid_ea(unsigned int opcode, unsigned int mask)
static int DECL_SPEC compare_nof_true_bits(const void *aptr, const void *bptr)
lzma_index ** i
Definition: index.h:629
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
void qsort(void *a, size_t n, size_t es, int(*cmp)(const void *, const void *))
Definition: qsort.h:130
unsigned short uint16_t
Definition: sftypes.h:30
Definition: z80asm.h:102

References compare_nof_true_bits(), opcode_struct::ea_mask, g_opcode_info, i, opcode_struct::mask, opcode_struct::mask2, opcode_struct::match, opcode_struct::match2, opcode_struct::name, printf(), qsort(), and valid_ea().

Referenced by main().

◆ compare_nof_true_bits()

static int DECL_SPEC compare_nof_true_bits ( const void *  aptr,
const void *  bptr 
)
static

Definition at line 392 of file M68KInstructionTblGen.c.

393 {
394  unsigned int a = ((const opcode_struct*)aptr)->mask;
395  unsigned int b = ((const opcode_struct*)bptr)->mask;
396 
397  a = ((a & 0xAAAA) >> 1) + (a & 0x5555);
398  a = ((a & 0xCCCC) >> 2) + (a & 0x3333);
399  a = ((a & 0xF0F0) >> 4) + (a & 0x0F0F);
400  a = ((a & 0xFF00) >> 8) + (a & 0x00FF);
401 
402  b = ((b & 0xAAAA) >> 1) + (b & 0x5555);
403  b = ((b & 0xCCCC) >> 2) + (b & 0x3333);
404  b = ((b & 0xF0F0) >> 4) + (b & 0x0F0F);
405  b = ((b & 0xFF00) >> 8) + (b & 0x00FF);
406 
407  return b - a; /* reversed to get greatest to least sorting */
408 }
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41

References a, and b.

Referenced by build_opcode_table().

◆ main()

int main ( void  )

Definition at line 462 of file M68KInstructionTblGen.c.

462  {
464  return 0;
465 }
static void build_opcode_table(void)

References build_opcode_table().

◆ valid_ea()

static int valid_ea ( unsigned int  opcode,
unsigned int  mask 
)
static

Definition at line 341 of file M68KInstructionTblGen.c.

342 {
343  if (mask == 0)
344  return 1;
345 
346  switch(opcode & 0x3f) {
347  case 0x00: case 0x01: case 0x02: case 0x03:
348  case 0x04: case 0x05: case 0x06: case 0x07:
349  return (mask & 0x800) != 0;
350  case 0x08: case 0x09: case 0x0a: case 0x0b:
351  case 0x0c: case 0x0d: case 0x0e: case 0x0f:
352  return (mask & 0x400) != 0;
353  case 0x10: case 0x11: case 0x12: case 0x13:
354  case 0x14: case 0x15: case 0x16: case 0x17:
355  return (mask & 0x200) != 0;
356  case 0x18: case 0x19: case 0x1a: case 0x1b:
357  case 0x1c: case 0x1d: case 0x1e: case 0x1f:
358  return (mask & 0x100) != 0;
359  case 0x20: case 0x21: case 0x22: case 0x23:
360  case 0x24: case 0x25: case 0x26: case 0x27:
361  return (mask & 0x080) != 0;
362  case 0x28: case 0x29: case 0x2a: case 0x2b:
363  case 0x2c: case 0x2d: case 0x2e: case 0x2f:
364  return (mask & 0x040) != 0;
365  case 0x30: case 0x31: case 0x32: case 0x33:
366  case 0x34: case 0x35: case 0x36: case 0x37:
367  return (mask & 0x020) != 0;
368  case 0x38:
369  return (mask & 0x010) != 0;
370  case 0x39:
371  return (mask & 0x008) != 0;
372  case 0x3a:
373  return (mask & 0x002) != 0;
374  case 0x3b:
375  return (mask & 0x001) != 0;
376  case 0x3c:
377  return (mask & 0x004) != 0;
378  }
379  return 0;
380 
381 }
#define mask()

References mask.

Referenced by build_opcode_table().

Variable Documentation

◆ g_opcode_info

opcode_struct g_opcode_info[]
static

Definition at line 37 of file M68KInstructionTblGen.c.

Referenced by build_opcode_table().