1 /*---------------------------------------------------------------------------* 2 Project: TwlSDK - bin2obj 3 File: bin2obj.h 4 5 Copyright 2005-2008 Nintendo. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Date:: 2008-09-18#$ 14 $Rev: 8573 $ 15 $Author: okubata_ryoma $ 16 *---------------------------------------------------------------------------*/ 17 #ifndef BIN2OBJ_H__ 18 #define BIN2OBJ_H__ 19 20 #include <stdio.h> 21 #include <malloc.h> // calloc() 22 #include <stdlib.h> // free(), exit() 23 #include <sys/stat.h> // stat() 24 #include <string.h> // strlen/strdup/strcpy/memcpy 25 #include <getopt.h> // getopt_long_only 26 #include <ctype.h> // isalnum(), isdight() 27 #include <assert.h> // assert() 28 #include "types.h" 29 #include "object.h" 30 31 typedef struct 32 { 33 char *app_name; 34 char *binary_filename; 35 char *object_filename; 36 char *section_rodata; 37 char *section_rwdata; 38 char *symbol_begin; 39 char *symbol_end; 40 u32 align; 41 BOOL writable; 42 u8 endian; // ELFDATA2LSB/ELFDATA2MSB 43 u16 machine; // EM_PPC=20 EM_ARM=40 44 } 45 Bin2ObjArgs; 46 47 #define DEFAULT_ALIGN 4 48 #define DEFALUT_WRITABLE TRUE 49 #define DEFAULT_SYMBOL_BEGIN "%b_begin" 50 #define DEFAULT_SYMBOL_END "%b_end" 51 52 #define DEFAULT_SECTION_RWDATA ".data" 53 #define DEFAULT_SECTION_RODATA ".rodata" 54 55 // for Compatiblity with CodeWarrior BinToElf 56 #define COMPATIBLE_SYMBOL_BEGIN "_binary_%t" 57 #define COMPATIBLE_SYMBOL_END "_binary_%t_end" 58 59 BOOL bin2obj(const Bin2ObjArgs * args); 60 61 char *create_symbol_string(const char *filename, const char *symbol_format); 62 int replace_word(char **str, int pos, int len, const char *substr); 63 char *StrDup(const char *str); 64 char *StrCatDup(const char *str1, const char *str2); 65 char *StrNDup(const char *str, int len); 66 void *Calloc(int size); 67 void UnpackFileName(const char *path, char **dir, char **base, char **ext); 68 69 void cook_args(Bin2ObjArgs * t, int argc, char *argv[]); 70 void free_args(Bin2ObjArgs * t); 71 72 void object_init(Object * obj, u16, u8); 73 void map_section(Object * obj); 74 void conv_to_big_endian(const Object * obj, Object * cooked_obj); 75 u32 roundup(u32, u32); 76 BOOL output_object(const Object * obj, const char *filename); 77 BOOL add_datasec(Object * obj, 78 const char *section_rodata, const char *section_rwdata, 79 const char *symbol_format_begin, const char *symbol_format_end, 80 const char *filename, BOOL writable, u32 align); 81 u32 add_section_name(Object * obj, const char *name); 82 u32 add_section(Object * obj, const char *name, u32 type, u32 flags, u32 size, u32 align); 83 u32 add_symbol_name(Object * obj, const char *name); 84 u32 add_symbol(Object * obj, const char *symbol, u32 value, u32 size, u32 section); 85 86 #endif //BIN2OBJ_H__ 87