CHDK_DE Vorschauversion  Trunk Rev. 5547
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
chdk_dasm.h-Dateireferenz
+ Dieser Graph zeigt, welche Datei direkt oder indirekt diese Datei enthält:

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define declstruct(name)   typedef struct name s##name, * p##name
 
#define defstruct(name)   struct name
 
#define defequiv(new, old)   typedef struct old s##new, * p##new
 
#define disopt_SWInames   0x001 /* use names, not &nnnn */
 
#define disopt_CommaSpace   0x002 /* put spaces after commas */
 
#define disopt_FIXS   0x004 /* bogus FIX syntax for ObjAsm */
 
#define disopt_print_address_mode   0x008 /* output in plain mode - no address comments */
 
#define disopt_indent_mneumonics_mode   0x010 /* indent mneumonics additionally */
 
#define disopt_patch_comment   0x020
 
#define disopt_exclude_dcd   0x040
 
#define disopt_nullsub_call   0x080
 
#define disopt_patch_branch   0x100
 
#define disopt_patch_value   0x200
 
#define disopt_remember_branches   0x400
 
#define disopt_comment_lines   0x800
 
#define disopt_line_numbers   0x1000
 

Typdefinitionen

typedef unsigned int t_address
 
typedef unsigned int t_value
 

Funktionen

 declstruct (DisOptions)
 
 defstruct (DisOptions)
 
struct lnodel_search (struct llist *ls, t_address address)
 
void l_remove (struct llist *ls, t_address addr)
 
t_address find_end (firmware *fw, t_address start)
 
void disassemble1 (firmware *fw, t_address start, t_value length)
 
void disassemble (firmware *fw, FILE *outfile, t_address start, t_value length)
 

Variablen

t_address addr
 
t_address last_used_addr
 
sDisOptions options
 
struct llistbranch_list
 
char * patch_func_name
 
t_address patch_new_val
 
t_address patch_old_val
 
int patch_ref_address [20]
 
char patch_ref_name [20][256]
 
int save_patch_ref
 
char * patch_comment
 

Makro-Dokumentation

#define declstruct (   name)    typedef struct name s##name, * p##name

Definiert in Zeile 46 der Datei chdk_dasm.h.

#define defequiv (   new,
  old 
)    typedef struct old s##new, * p##new

Definiert in Zeile 48 der Datei chdk_dasm.h.

#define defstruct (   name)    struct name

Definiert in Zeile 47 der Datei chdk_dasm.h.

#define disopt_CommaSpace   0x002 /* put spaces after commas */

Definiert in Zeile 53 der Datei chdk_dasm.h.

#define disopt_comment_lines   0x800

Definiert in Zeile 63 der Datei chdk_dasm.h.

#define disopt_exclude_dcd   0x040

Definiert in Zeile 58 der Datei chdk_dasm.h.

#define disopt_FIXS   0x004 /* bogus FIX syntax for ObjAsm */

Definiert in Zeile 54 der Datei chdk_dasm.h.

#define disopt_indent_mneumonics_mode   0x010 /* indent mneumonics additionally */

Definiert in Zeile 56 der Datei chdk_dasm.h.

#define disopt_line_numbers   0x1000

Definiert in Zeile 64 der Datei chdk_dasm.h.

#define disopt_nullsub_call   0x080

Definiert in Zeile 59 der Datei chdk_dasm.h.

#define disopt_patch_branch   0x100

Definiert in Zeile 60 der Datei chdk_dasm.h.

#define disopt_patch_comment   0x020

Definiert in Zeile 57 der Datei chdk_dasm.h.

#define disopt_patch_value   0x200

Definiert in Zeile 61 der Datei chdk_dasm.h.

#define disopt_print_address_mode   0x008 /* output in plain mode - no address comments */

Definiert in Zeile 55 der Datei chdk_dasm.h.

#define disopt_remember_branches   0x400

Definiert in Zeile 62 der Datei chdk_dasm.h.

#define disopt_SWInames   0x001 /* use names, not &nnnn */

Definiert in Zeile 52 der Datei chdk_dasm.h.

Dokumentation der benutzerdefinierten Typen

typedef unsigned int t_address

Definiert in Zeile 43 der Datei chdk_dasm.h.

typedef unsigned int t_value

Definiert in Zeile 44 der Datei chdk_dasm.h.

Dokumentation der Funktionen

declstruct ( DisOptions  )
defstruct ( DisOptions  )

Definiert in Zeile 66 der Datei chdk_dasm.h.

66  {
67  t_value flags;
68  char * * regnames; /* pointer to 16 |char *|s: register names */
69  t_address ROM_start;
70  t_address ROM_end;
71  t_address start_address;
72  t_address end_address;
73 };
void disassemble ( firmware fw,
FILE outfile,
t_address  start,
t_value  length 
)

Definiert in Zeile 1328 der Datei chdk_dasm.c.

1329 {
1330  t_value w;
1331 
1332  int dcd_mode_on = 0;
1333 
1334  // Only need 1 pass here - assumes disassemble1 called previously
1335  addr = start ;
1336  t_value word_count = 0 ;
1337 
1338  while (word_count < length )
1339  {
1340  w = fwval(fw,adr2idx(fw,addr));
1341 
1342  pInstruction instr = instr_disassemble(fw, w, addr, &options);
1343 
1344  if (l_search(branch_list, addr))
1345  {
1346  fprintf(outfile,"\n\"loc_%08X:\\n\"\n", addr);
1347  dcd_mode_on = 0;
1348  }
1349  struct lnode* lptr = l_search(dcd_list,addr);
1350  if ( lptr || dcd_mode_on )
1351  {
1352  if ((options.flags & disopt_exclude_dcd) == 0)
1353  fprintf(outfile,"\"dword_%8.8X DCD 0x%X \\n\"\n", addr , w);
1354  dcd_mode_on = 1;
1355  /*
1356  t_value aword ;
1357  int i ;
1358  unsigned char ch ;
1359  aword = lptr->data ;
1360  for ( i=0 ; i< 4 ; i++ )
1361  {
1362  ch = aword & 0xFF ;
1363  if ( (ch>=0x20) && ( ch < 0x80) ) fprintf(outfile," %c" , ch );
1364  else fprintf(outfile,"_" );
1365  aword = aword >> 8 ;
1366  }
1367  fprintf(outfile, "\n" ) ;
1368  */
1369  }
1370  else
1371  {
1372  if (instr->undefined || instr->badbits || instr->oddbits) {
1373  fprintf(outfile,"Error: ");
1374  if (instr->undefined) fprintf(outfile,"[---undefined instr---] 0x%8.8X ", w);
1375  if (instr->badbits) fprintf(outfile, "[---illegal bits---] 0x%8.8X ", w);
1376  if (instr->oddbits) fprintf(outfile, "[---unexpected bits---] 0x%8.8X ", w);
1377  if ( !((instr->undefined) || (instr->badbits) || (instr->oddbits)) )
1378  fprintf(outfile, "[---unknown error---] 0x%8.8X ", w);
1379  if ( options.flags & disopt_print_address_mode)
1380  {
1381  fprintf(outfile,"// rom:%.8x 0x%8.8X \n", addr, w);
1382  }
1383  else fprintf(outfile,"\n");
1384  }
1385  else
1386  {
1387  strcat( instr->text, " \\n\"") ;
1388  if (options.flags & disopt_line_numbers) fprintf(outfile,"/*%3d*/",(addr - options.start_address) / 4 + 1);
1389  char *indent = "\" ";
1391  indent = "//\" ";
1393  fprintf(outfile," ");
1394  if (options.flags & disopt_print_address_mode)
1395  {
1396  fprintf(outfile,"%s%-40s // rom:%.8x 0x%8.8X", indent, instr->text, addr, w);
1397  }
1398  else fprintf(outfile,"%s%s", indent, instr->text);
1399 
1400  if ((options.flags & disopt_patch_branch) || (options.flags & disopt_patch_value))
1401  {
1402  if (patch_old_func_name)
1403  fprintf(outfile," // --> Patched. Old value = _%s.", patch_old_func_name);
1404  else
1405  fprintf(outfile," // --> Patched. Old value = 0x%X.", patch_old_val);
1406  if ((options.flags & disopt_patch_comment) && patch_comment)
1407  {
1408  fprintf(outfile, " %s", patch_comment);
1409  patch_comment = 0;
1410  }
1411  }
1412  else if ((options.flags & disopt_patch_comment) && patch_comment)
1413  {
1414  fprintf(outfile, " // %s", patch_comment);
1415  patch_comment = 0;
1416  }
1417  else if (options.flags & disopt_nullsub_call)
1418  {
1419  fprintf(outfile," // --> Nullsub call removed.");
1420  }
1421  fprintf(outfile,"\n");
1422  }
1423  }
1424 
1425  word_count++ ;
1426  addr += 4;
1427  }
1428 }
void disassemble1 ( firmware fw,
t_address  start,
t_value  length 
)

Definiert in Zeile 1283 der Datei chdk_dasm.c.

1284 {
1285  t_value w;
1286 
1287  free(dcd_list);
1288  dcd_list = new_list();
1289  free(branch_list);
1290  branch_list = new_list();
1291 
1292  // Do three passes; but don't generate any code
1293  int pass;
1294  for ( pass = 1 ; pass <=3 ; pass++ )
1295  {
1296  if ( pass == 2 )
1297  {
1298  struct lnode* lptr = dcd_list->head;
1299  while ( lptr != NULL )
1300  {
1301  addr = (t_address) lptr->address ;
1302  w = fwval(fw,adr2idx(fw,addr));
1303  lptr->data = w ;
1304  lptr = lptr->next ;
1305  }
1306  }
1307  else // pass 1 & 3
1308  {
1309  addr = start ;
1310  t_value word_count = 0 ;
1311 
1312  while (word_count < length )
1313  {
1314  w = fwval(fw,adr2idx(fw,addr));
1315  instr_disassemble(fw, w, addr, &options);
1316 
1317  struct lnode* lptr = l_search(dcd_list,addr);
1318  if (!lptr)
1319  last_used_addr = addr;
1320 
1321  word_count++ ;
1322  addr += 4;
1323  }
1324  }
1325  }
1326 }
t_address find_end ( firmware fw,
t_address  start 
)

Definiert in Zeile 1430 der Datei chdk_dasm.c.

1431 {
1432  int i;
1433  start = adr2idx(fw,start);
1434  for (i=0; i<500; i++, start++)
1435  if ((fwval(fw,start+1) & 0xFFFF4000) == 0xE92D4000) // STMFD SP!, {...,LR}
1436  {
1437  int j;
1438  for (j=0; j<50; j++, start--)
1439  {
1440  if ((fwval(fw,start) & 0xFF000000) == 0xEA000000) // B
1441  {
1442  return idx2adr(fw,start);
1443  }
1444  if ((fwval(fw,start) & 0xFFFF8000) == 0xE8BD8000) // LDMFD SP!, {...,PC}
1445  {
1446  return idx2adr(fw,start);
1447  }
1448  if ((fwval(fw,start) & 0xFFFFFFF0) == 0xE12FFF10) // BX
1449  {
1450  return idx2adr(fw,start);
1451  }
1452  if ((fwval(fw,start) & 0xFFFFF000) == 0xE49DF000) // LDR PC,[SP,...
1453  {
1454  return idx2adr(fw,start);
1455  }
1456  }
1457  return 0;
1458  }
1459  return 0;
1460 }
void l_remove ( struct llist ls,
t_address  addr 
)

Definiert in Zeile 118 der Datei capdis.c.

119 {
120  if (ls)
121  {
122  struct lnode *p, *l;
123  l = 0;
124  p = ls->head;
125  while (p)
126  {
127  if (p->address == addr)
128  {
129  if (l)
130  l->next = p->next;
131  else
132  ls->head = p->next;
133  (ls->size)--;
134  return;
135  }
136  l = p;
137  p = p->next;
138  }
139  }
140 }
struct lnode* l_search ( struct llist ls,
t_address  address 
)

Definiert in Zeile 87 der Datei capdis.c.

87  {
88  struct lnode *node;
89 
90  node = ls->head;
91  while ( node != NULL && node->address != address ) {
92  node = node->next ;
93  }
94  if (node == NULL) {
95  return 0; /* 'item' not found */
96  }
97 
98  return node;
99 }

Variablen-Dokumentation

t_address addr

Definiert in Zeile 1281 der Datei chdk_dasm.c.

struct llist* branch_list

Definiert in Zeile 262 der Datei chdk_dasm.c.

t_address last_used_addr

Definiert in Zeile 1281 der Datei chdk_dasm.c.

sDisOptions options

Definiert in Zeile 96 der Datei chdk_dasm.c.

char* patch_comment

Definiert in Zeile 90 der Datei chdk_dasm.c.

char* patch_func_name

Definiert in Zeile 81 der Datei chdk_dasm.c.

t_address patch_new_val

Definiert in Zeile 84 der Datei chdk_dasm.c.

t_address patch_old_val

Definiert in Zeile 85 der Datei chdk_dasm.c.

int patch_ref_address[20]

Definiert in Zeile 87 der Datei chdk_dasm.c.

char patch_ref_name[20][256]

Definiert in Zeile 88 der Datei chdk_dasm.c.

int save_patch_ref

Definiert in Zeile 89 der Datei chdk_dasm.c.