root/modules/flt.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


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

/* [<][>][^][v][top][bottom][index][help] */