1 /*===================================================================================================== 2 chdk_dasm.h 3 4 This sofware is provided "as is" with no warantee or representation of any "fitness for use"/ 5 6 This software contains code included under the license included below. The code was changed to 7 - provide formatting compatible with gcc as used for CHDK development 8 - provide a multi-pass approach was added to allow the generation and handling of labels. 9 - expanded command line options 10 - correction to dissassembly bugs and added support for the STRD instruction. 11 12 None of these modifications are the work of the original author. 13 14 And if you are wondering, the original dissassembler code appears to have been optimized to 15 run on an ARM process, which explains all the goofy use of left and right shifts. Those compile 16 nicely to a single instrucion on the ARM processor. 17 18 =====================================================================================================*/ 19 20 /* disarm -- a simple disassembler for ARM instructions 21 * (c) 2000 Gareth McCaughan 22 * 23 * This file may be distributed and used freely provided: 24 * 1. You do not distribute any version that lacks this 25 * copyright notice (exactly as it appears here, extending 26 * from the start to the end of the C-language comment 27 * containing these words)); and, 28 * 2. If you distribute any modified version, its source 29 * contains a clear description of the ways in which 30 * it differs from the original version, and a clear 31 * indication that the changes are not mine. 32 * There is no restriction on your permission to use and 33 * distribute object code or executable code derived from 34 * this. 35 * 36 * The original version of this file (or perhaps a later 37 * version by the original author) may or may not be 38 * available at http://web.ukonline.co.uk/g.mccaughan/g/software.html . 39 * 40 * Share and enjoy! -- g 41 */ 42 43 typedef unsigned int t_address; 44 typedef unsigned int t_value; 45 46 #define declstruct(name) typedef struct name s##name, * p##name 47 #define defstruct(name) struct name 48 #define defequiv(new,old) typedef struct old s##new, * p##new 49 50 declstruct(DisOptions); 51 52 #define disopt_SWInames 0x001 /* use names, not &nnnn */ 53 #define disopt_CommaSpace 0x002 /* put spaces after commas */ 54 #define disopt_FIXS 0x004 /* bogus FIX syntax for ObjAsm */ 55 #define disopt_print_address_mode 0x008 /* output in plain mode - no address comments */ 56 #define disopt_indent_mneumonics_mode 0x010 /* indent mneumonics additionally */ 57 #define disopt_patch_comment 0x020 // add comment to patched instruction 58 #define disopt_exclude_dcd 0x040 // Don't write 'DCD' disassembly 59 #define disopt_nullsub_call 0x080 // Call to nullsub detected 60 #define disopt_patch_branch 0x100 // patch address in next instruction 61 #define disopt_patch_value 0x200 // patch value in next instruction 62 #define disopt_remember_branches 0x400 // enable/disable storing branch addresses 63 #define disopt_comment_lines 0x800 // enable/disable commenting out of instructions 64 #define disopt_line_numbers 0x1000 // print line number of firmware code 65 66 defstruct(DisOptions) { 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 }; 74 75 extern t_address addr, last_used_addr; 76 extern sDisOptions options; 77 extern struct llist *branch_list; 78 extern char *patch_func_name; 79 extern t_address patch_new_val; 80 extern t_address patch_old_val; 81 extern int patch_ref_address[20]; 82 extern char patch_ref_name[20][256]; 83 extern int save_patch_ref; 84 extern char *patch_comment; 85 86 struct lnode * l_search(struct llist *ls, t_address address); 87 void l_remove(struct llist *ls, t_address addr); 88 t_address find_end(firmware *fw, t_address start); 89 void disassemble1(firmware *fw, t_address start, t_value length); 90 void disassemble(firmware *fw, FILE *outfile, t_address start, t_value length);