root/modules/cpuinfo.c

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

DEFINITIONS

This source file includes following definitions.
  1. regperm_str
  2. cpuinfo_write_file
  3. basic_module_init
  4. cpuinfo_finish

   1 #include "stdlib.h"
   2 #include "gui_mbox.h"
   3 #include "gui.h"
   4 #include "gui_lang.h"
   5 #include "lang.h"
   6 
   7 struct cpuinfo_bitfield_desc_s {
   8     unsigned bits;
   9     const char *name;
  10     const char *(*desc_fn)(unsigned val);
  11 };
  12 
  13 struct cpuinfo_word_desc_s {
  14     const char *name;
  15     const struct cpuinfo_bitfield_desc_s *fields;
  16 };
  17 
  18 const struct cpuinfo_bitfield_desc_s cpuinf_id[] = {
  19     {4,"Revision"},
  20     {12,"Part"},
  21     {4,"ARM Arch"},
  22     {4,"Variant"},
  23     {8,"Implementor"},
  24     {}
  25 };
  26 
  27 static const char *reg_sizes[] = {
  28     "4K", "8K", "16K", "32K", "64K", "128K", "256K", "512K", 
  29     "1M", "2M", "4M", "8M", "16M", "32M", "64M", "128M", "256M", "512M",
  30     "1G", "2G", "4G",
  31 };
  32 
  33 static const char *regperm_str(unsigned val) {
  34     switch(val) {
  35         case 0: return "P:-- U:--";
  36         case 1: return "P:RW U:--";
  37         case 2: return "P:RW U:R-";
  38         case 3: return "P:RW U:RW";
  39         case 5: return "P:R- U:--";
  40         case 6: return "P:R- U:R-";
  41         default:
  42             return "P:?? U:??";
  43     }
  44 }
  45 
  46 #ifdef THUMB_FW
  47     #include "cpuinfo_v7.c"
  48     // note, this is how many we know, nothing to do with how many cpuinfo_get_info knows
  49     #define NUM_CPUINFO_WORDS (((sizeof(cpuinfo_desc_pmsa)>sizeof(cpuinfo_desc_vmsa))? \
  50                               sizeof(cpuinfo_desc_pmsa):sizeof(cpuinfo_desc_vmsa))/ \
  51                               sizeof(cpuinfo_desc_pmsa[0]) - 1)
  52 #else
  53     #include "cpuinfo_v5.c"
  54     // note, this is how many we know, nothing to do with how many cpuinfo_get_info knows
  55     #define NUM_CPUINFO_WORDS ((sizeof(cpuinfo_desc)/sizeof(cpuinfo_desc[0])) - 1)
  56 #endif
  57 
  58 void cpuinfo_finish(unsigned dummy);
  59 
  60 void cpuinfo_write_file(void) {
  61     unsigned cpuinfo[NUM_CPUINFO_WORDS];
  62     int i,j;
  63     unsigned fieldval,wordval;
  64     unsigned mask,bits;
  65     FILE *finfo;
  66     char buf[100];
  67     char *p;
  68 #ifdef THUMB_FW
  69     struct cpuinfo_word_desc_s *cpuinfo_desc;
  70     if (cpu_is_vmsa()) {
  71         FILE *f=fopen("A/MMU_MAP.CSV", "wb");
  72         memmapping_vmsa(f);
  73         cpuinfo_get_info_vmsa(cpuinfo);
  74         cpuinfo_desc = (struct cpuinfo_word_desc_s*) cpuinfo_desc_vmsa;
  75     }
  76     else {
  77         cpuinfo_get_info_pmsa(cpuinfo);
  78         cpuinfo_desc = (struct cpuinfo_word_desc_s*) cpuinfo_desc_pmsa;
  79     }
  80 #else
  81     cpuinfo_get_info(cpuinfo);
  82 #endif
  83     finfo=fopen("A/CPUINFO.TXT", "wb");
  84     for(i = 0; cpuinfo_desc[i].name; i++) {
  85         wordval = cpuinfo[i];
  86         sprintf(buf,"%-10s 0x%08X\n",cpuinfo_desc[i].name,wordval);
  87         fwrite(buf,1,strlen(buf),finfo);
  88         for(j=0; cpuinfo_desc[i].fields[j].name; j++) {
  89             p=buf;
  90             bits = cpuinfo_desc[i].fields[j].bits;
  91             mask = ~(0xFFFFFFFF << bits);
  92             fieldval = wordval & mask;
  93             p+=sprintf(p,"  %-20s 0x%X %d",cpuinfo_desc[i].fields[j].name,fieldval,fieldval);
  94             if(cpuinfo_desc[i].fields[j].desc_fn) {
  95                 p+=sprintf(p," [%s]",cpuinfo_desc[i].fields[j].desc_fn(fieldval));
  96             }
  97             strcat(p,"\n");
  98             fwrite(buf,1,strlen(buf),finfo);
  99             wordval >>= bits;
 100         }
 101     }
 102     fclose(finfo);
 103     sprintf(buf, lang_str(LANG_CPUINFO_WROTE), "A/CPUINFO.TXT");
 104     gui_mbox_init(LANG_MENU_DEBUG_CPU_INFO,(int)buf,MBOX_FUNC_RESTORE|MBOX_TEXT_CENTER, cpuinfo_finish);
 105 }
 106 
 107 int basic_module_init() {
 108     cpuinfo_write_file();
 109     return 1;
 110 }
 111 // =========  MODULE INIT =================
 112 #include "simple_module.c"
 113 void cpuinfo_finish(unsigned dummy) {
 114     running=0;
 115 }
 116 
 117 ModuleInfo _module_info =
 118 {
 119     MODULEINFO_V1_MAGICNUM,
 120     sizeof(ModuleInfo),
 121     SIMPLE_MODULE_VERSION,                      // Module version
 122 
 123     ANY_CHDK_BRANCH, 0, OPT_ARCHITECTURE,                       // Requirements of CHDK version
 124     ANY_PLATFORM_ALLOWED,               // Specify platform dependency
 125 
 126     -LANG_MENU_DEBUG_CPU_INFO,  // Module name
 127     MTYPE_TOOL,             //Read CPU and cache information from CP15
 128 
 129     &_librun.base,
 130 
 131     ANY_VERSION,                // CONF version
 132     ANY_VERSION,                // CAM SCREEN version
 133     ANY_VERSION,                // CAM SENSOR version
 134     ANY_VERSION,                // CAM INFO version
 135 };
 136 
 137 /*************** END OF AUXILARY PART *******************/
 138 

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