1 #ifndef __FLT_H__ 2 #define __FLT_H__ 3 4 #if !defined(USE_INT32_FOR_PTRS) 5 #include "versions.h" 6 #endif 7 8 typedef unsigned short uint16_t; 9 typedef short int16_t; 10 typedef unsigned int uint32_t; 11 typedef int int32_t; 12 13 //================= Module information structure ===================== 14 15 #define MODULEINFO_V1_MAGICNUM 0x023703e5 16 17 // CHDK versions 18 #define ANY_CHDK_BRANCH 0 19 #define REQUIRE_CHDK_MAIN 1 20 #define REQUIRE_CHDK_DE 2 21 #define REQUIRE_CHDK_SDM 3 22 #define REQUIRE_CHDK_PRIVATEBUILD 4 23 24 // PlatformID check (can be used to make a module specific to a camera model) 25 #define ANY_PLATFORM_ALLOWED 0 26 27 // Architecture of build (GCC ABI, thumb/thumb2, etc) 28 #define GCC_ELF_THUMB 1 29 #define GCC_EABI_THUMB 2 30 #define GCC_ELF_THUMB2 0x11 // Cortex R, unlikely variant 31 #define GCC_EABI_THUMB2 0x12 // Cortex R 32 #define GCC_ELF_THUMB2A 0x21 // Cortex A, unlikely variant 33 #define GCC_EABI_THUMB2A 0x22 // Cortex A 34 35 // Base module interface - once loaded into memory and any relocations done these 36 // functions provide the minimum interface to run the module code. 37 // Extend this interface for modules that need additional functions (e.g. libdng_sym in dng.h) 38 typedef struct 39 { 40 int (*loader)(); // loader function. Optional 41 // Should only perform initialisation that can be done when module is first loaded. 42 // Returns 0 for success, non-zero (error code) on failure 43 int (*unloader)(); // unloader function. Optional 44 // Does any necessary clean up just prior to module being removed 45 // Returns 0 for success, non-zero (error code) on failure [return value not currently used] 46 int (*can_unload)(); // ask module if it is safe to unload. Optional 47 // Called each keyboard task tick to see if it is safe to unload the module 48 int (*exit_alt)(); // alert module that CHDK is leaving <ALT> mode. Optional 49 // If the module should be unloaded when <ALT> mode exits then this function 50 // should tell the module to return 'true' on the next call to can_unload 51 // This function should not do any cleanup or shutdown of the module 52 int (*run)(); // run module (for simple modules like games). Optional 53 // If not supplied then an extended interface is required to call module code 54 } base_interface_t; 55 56 // Module types 57 #define MTYPE_UNKNOWN 0 // Undefined 58 #define MTYPE_EXTENSION 1 // System extension (e.g. dng, edge overlay, etc) 59 #define MTYPE_GAME 2 // Games (added to Games menu) 60 #define MTYPE_TOOL 3 // Custom tool (added to Tools menu) 61 #define MTYPE_SCRIPT_LANG 4 // Script language 62 #define MTYPE_MASK 0xFF // Mask for type values above 63 #define MTYPE_SUBMENU_TOOL 0x100 // Flag to indicate tool module is a submenu 64 65 // Module information structure 66 // Contains everything used to communicate with and run code in the module 67 typedef struct 68 { 69 uint32_t magicnum; // MODULEINFO_V1_MAGICNUM - sanity check when loading 70 uint32_t sizeof_struct; // sizeof this struct - sanity check when loading 71 _version_t module_version; // version of module - compared to version in module_handler_t 72 uint32_t chdk_required_branch; // CHDK version checks 73 uint32_t chdk_required_ver; 74 uint32_t chdk_required_architecture; 75 uint32_t chdk_required_platfid; 76 77 int32_t moduleName; // pointer to string with module name or -LANG_ID 78 int32_t moduleType; // module type flags (see MTYPE_ definitions) 79 80 #if defined(USE_INT32_FOR_PTRS) // For elfflt.c on 64 bit Linux 81 uint32_t lib; 82 #else 83 base_interface_t* lib; // Pointer to interface library 84 #endif 85 86 // Version checks (set to {0,0} to skip check) 87 _version_t conf_ver; // CONF version (Conf structure in conf.h) 88 _version_t cam_screen_ver; // CAM SCREEN version (camera_screen in camera_info.h) 89 _version_t cam_sensor_ver; // CAM SENSOR version (camera_sensor in camera_info.h) 90 _version_t cam_info_ver; // CAM INFO version (camera_info in camera_info.h) 91 92 char symbol; // Optional symbol to use in Games / Tools menu for module 93 } ModuleInfo; 94 95 //================= FLAT Header structure ============== 96 97 /* 98 Structure of CFLAT v10 file: 99 - flt_hdr [see flat_hdr structure] 100 - .text [start from flt_hdr.entry] 101 - .rodata + .data [start from flt_hdr.data_start] 102 - reloc_list [start from flt_hdr.reloc_start] 103 * this is just array of offsets in flat 104 - import_list [start from flt_hdr.import_start] 105 * this is array of import_record_t 106 107 Notes: 108 .bss no longer stored in file, segment generated at runtime, 109 - starts immediately after .data segment (@flt_hdr.reloc_start) 110 - size specified in flt_hdr.bss_size 111 */ 112 113 #define FLAT_VERSION 10 114 #define FLAT_MAGIC_NUMBER 0x414c4643 //"CFLA" 115 116 // Module file header 117 // This is located at the start of the module file and is used to load the module 118 // into memory and perform any necessary relocations. 119 // Once loaded the _module_info pointer handles everything else. 120 typedef struct 121 { 122 uint32_t magic; // "CFLA" (must match FLAT_MAGIC_NUMBER) 123 uint32_t rev; // version (must match FLAT_VERSION) 124 uint32_t entry; // Offset of start .text segment 125 uint32_t data_start; // Offset of .data segment from beginning of file 126 uint32_t bss_size; // Size of .bss segment (for run time allocation) [bss start == reloc_start] 127 128 // Relocation info 129 uint32_t reloc_start; // Offset of relocation records from beginning of file (also start of bss segment) 130 uint32_t import_start; // Offset of import section 131 uint32_t import_size; // size of import section 132 133 // Offset / Pointer to ModuleInfo structure 134 union 135 { 136 uint32_t _module_info_offset; // Offset ModuleInfo from beginning of file 137 #if defined(USE_INT32_FOR_PTRS) // For elfflt.c on 64 bit Linux 138 uint32_t _module_info; // Ptr to ModuleInfo after relocation 139 #else 140 ModuleInfo* _module_info; // Ptr to ModuleInfo after relocation 141 #endif 142 }; 143 } flat_hdr; 144 145 #endif /* __FLT_H__ */