CHDK_DE Vorschauversion  Trunk Rev. 6014
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
module_load.h-Dateireferenz
#include "module_def.h"
+ Include-Abhängigkeitsdiagramm für module_load.h:
+ Dieser Graph zeigt, welche Datei direkt oder indirekt diese Datei enthält:

gehe zum Quellcode dieser Datei

Datenstrukturen

struct  module_handler_t
 
struct  module_entry
 

Makrodefinitionen

#define MAX_NUM_LOADED_MODULES   10
 

Funktionen

flat_hdrmodule_preload (const char *path, const char *name, _version_t ver)
 
int module_load (module_handler_t *hMod)
 
void module_unload (const char *name)
 
void get_module_info (const char *name, ModuleInfo *mi, char *modName, int modNameLen)
 
int module_run (char *name)
 
module_entrymodule_get_adr (unsigned int idx)
 
void module_exit_alt ()
 
void module_tick_unloader ()
 
void module_log_clear ()
 

Makro-Dokumentation

#define MAX_NUM_LOADED_MODULES   10

Definiert in Zeile 8 der Datei module_load.h.

Dokumentation der Funktionen

void get_module_info ( const char *  name,
ModuleInfo mi,
char *  modName,
int  modNameLen 
)

Definiert in Zeile 838 der Datei module_load.c.

839 {
840  memset(mi, 0, sizeof(ModuleInfo));
841  if (modName)
842  modName[0] = 0; // Only used if module name stored in file (not a LANG string)
843 
844  // Get full path to module file, and hash of path
845  char path[60];
846  get_module_path(path, name);
847 
848  // open file
849  int fd = open(path, O_RDONLY, 0777);
850  if (fd < 0)
851  return;
852 
853  // Read module header only to get size info
854  flat_hdr flat;
855  read(fd, (char*)&flat, sizeof(flat_hdr));
856 
857  // Check version and magic number - make sure it is a CHDK module file
858  if ((flat.rev == FLAT_VERSION) && (flat.magic == FLAT_MAGIC_NUMBER))
859  {
861  read(fd, mi, sizeof(ModuleInfo));
862 
863  if ((mi->moduleName >= 0) && modName)
864  {
865  // Load module name string
866  lseek(fd, mi->moduleName, SEEK_SET);
867  read(fd, modName, modNameLen-1);
868  modName[modNameLen-1] = 0;
869  }
870  }
871 
872  close(fd);
873 }
void module_exit_alt ( )

Definiert in Zeile 792 der Datei module_load.c.

793 {
794  int idx;
795 
796  for (idx=MAX_NUM_LOADED_MODULES-1; idx>=0; idx--)
797  {
798  if (modules[idx].hdr && modules[idx].hdr->_module_info->lib->exit_alt)
799  {
800  // Tell module we are leaving <ALT>
801  modules[idx].hdr->_module_info->lib->exit_alt();
802  }
803  }
804 }
module_entry* module_get_adr ( unsigned int  idx)

Definiert in Zeile 828 der Datei module_load.c.

829 {
830  if (idx < MAX_NUM_LOADED_MODULES)
831  if (modules[idx].hdr)
832  return &modules[idx];
833  return 0;
834 }
int module_load ( module_handler_t hMod)

Definiert in Zeile 660 der Datei module_load.c.

661 {
662  // Attempt to load module
663  _module_load(hMod);
664 
665  // If load succeeded return success
666  if (*hMod->lib && (*hMod->lib != hMod->default_lib))
667  {
668  return 1;
669  }
670 
671  // If load failed reset library to unloaded default (should not be needed!)
672  if (*hMod->lib == 0)
673  *hMod->lib = hMod->default_lib;
674 
675  // Failure
676  return 0;
677 }
void module_log_clear ( )

Definiert in Zeile 343 der Datei module_load.c.

344 {
345  remove("A/MODULES.LOG");
346 }
flat_hdr* module_preload ( const char *  path,
const char *  name,
_version_t  ver 
)

Definiert in Zeile 518 der Datei module_load.c.

519 {
520  // Allocate buffer and open file
521  int module_fd = b_open(path);
522  if (module_fd <= 0)
523  {
524  moduleload_error(name, "open error");
525  return 0;
526  }
527 
528  // Read module header only to get size info
529  flat_hdr flat;
530  b_read(module_fd, (char*)&flat, sizeof(flat)); // TODO - compare loaded with requested size
531 
532  // Error message
533  char *msg = 0;
534 
535  // Pointer to memory allocated to load module
536  flat_hdr* flat_buf = 0;
537 
538  // Check version and magic number - make sure it is a CHDK module file
539  if ((flat.rev == FLAT_VERSION) && (flat.magic == FLAT_MAGIC_NUMBER))
540  {
541  // Allocate module memory, and load module code
542  msg = load_module_file(module_fd, name, flat.reloc_start, flat.bss_size, &flat_buf);
543  if (msg == 0)
544  {
545  // Module info checks
546  ModuleInfo *mod_info = flat_buf->_module_info = (ModuleInfo*)((unsigned int)flat_buf+flat_buf->_module_info_offset);
547 
548  // Validate version requirements
549  msg = validate(mod_info, ver);
550  if (msg == 0)
551  {
552  // Make relocations
553  msg = link_module(module_fd, flat_buf);
554  }
555  }
556  }
557  else
558  msg = "bad magicnum";
559 
560  // Close file
561  b_close(module_fd);
562 
563  // If any error found, free module memory and display error
564  if (msg)
565  {
566  if (flat_buf)
567  free(flat_buf);
568  moduleload_error(name, msg);
569  return 0;
570  }
571 
572  // TODO these could be changed to operate on affected address ranges only
573  // after relocating but before attempting to execute loaded code
574  // clean data cache to ensure code is in main memory
576  // then flush instruction cache to ensure no addresses containing new code are cached
578 
579  // Return module memory address
580  return flat_buf;
581 }
int module_run ( char *  name)

Definiert in Zeile 755 der Datei module_load.c.

756 {
757  int i;
758  for (i=0; i<MAX_SIMPLE_MODULE; i++)
759  {
760  // Check if module loaded (otherwise name not valid)
761  if (*h_run[i].lib != h_run[i].default_lib)
762  {
763  if (namecmp(name, h_run[i].name))
764  {
765  // Already loaded
766  return (*h_run[i].lib)->run();
767  }
768  }
769  }
770  for (i=0; i<MAX_SIMPLE_MODULE; i++)
771  {
772  // Look for empty slot
773  if (*h_run[i].lib == h_run[i].default_lib)
774  {
775  // Found space - run module
776  strcpy(h_run[i].name, name);
777  return (*h_run[i].lib)->run();
778  }
779  }
780 
781  // Error - no space
783 
784  return -1;
785 }
void module_tick_unloader ( )

Definiert in Zeile 809 der Datei module_load.c.

810 {
811  int idx;
812 
813  for (idx=MAX_NUM_LOADED_MODULES-1; idx>=0; idx--)
814  {
815  if (modules[idx].hdr && modules[idx].hdr->_module_info->lib->can_unload)
816  {
817  // Ask module if it is safe to unload
818  if (modules[idx].hdr->_module_info->lib->can_unload())
819  module_unload_idx(idx);
820  }
821  }
822 }
void module_unload ( const char *  name)

Definiert in Zeile 410 der Datei module_load.c.

411 {
412  // Get full path to module file, and hash of path
413  char path[60];
414  unsigned int hash = get_module_path(path, name);
415 
416  // Find loaded module, and unload it
418 }