Advertisement
xerpi

MPCore Private Memory Region reader

Jan 25th, 2015
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.66 KB | None | 0 0
  1. /*
  2.  * MPCore Private Memory Region "reader" by xerpi
  3.  * You have to provide a MPCore Private Memory Region dump
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdint.h>
  8.  
  9. #define NELEMS(x)  (sizeof(x) / sizeof(x[0]))
  10. #define MPCORE_PMR_SIZE (0x2000)
  11.  
  12. struct mpcore_pmr_register {
  13.     uint32_t offset;
  14.     const char *const name;
  15. };
  16.  
  17. struct mpcore_pmr_peripheral {
  18.     uint32_t offset;
  19.     const char *const name;
  20.     struct mpcore_pmr_register registers[];
  21. };
  22.  
  23. const struct mpcore_pmr_peripheral scu_peripheral = {
  24.     0x0000,
  25.     "SCU",
  26.     {
  27.         {0x00, "Control Register"},
  28.         {0x04, "Configuration Register"},
  29.         {0x08, "SCU CPU Status"},
  30.         {0x0C, "Invalidate all"},
  31.         {0x10, "Performance Monitor"},
  32.         {0x14, "Monitor Counter Events 0"},
  33.         {0x18, "Monitor Counter Events 1"},
  34.         {0x1C, "Monitor Counter 0"},
  35.         {0x20, "Monitor Counter 1"},
  36.         {0x24, "Monitor Counter 2"},
  37.         {0x28, "Monitor Counter 3"},
  38.         {0x2C, "Monitor Counter 4"},
  39.         {0x30, "Monitor Counter 5"},
  40.         {0x34, "Monitor Counter 6"},
  41.         {0x38, "Monitor Counter 7"},
  42.         {0, NULL}
  43.     }
  44. };
  45.  
  46. const struct mpcore_pmr_peripheral CPU_interrupt_interfaces_peripheral = {
  47.     0x0100,
  48.     "CPU interrupt interfaces (identified by CPU transaction ID)",
  49.     {
  50.         {0x00, "Control Register"},
  51.         {0x04, "Priority Mask Register"},
  52.         {0x08, "Binary Point Register"},
  53.         {0x0C, "Interrupt Acknowledge Register"},
  54.         {0x10, "End of Interrupt Register"},
  55.         {0x14, "Running Priority Register"},
  56.         {0x18, "Highest Pending Interrupt Register"},
  57.         {0, NULL}
  58.     }
  59. };
  60.  
  61. const struct mpcore_pmr_peripheral CPU0_interrupt_interface_peripheral = {
  62.     0x0200,
  63.     "CPU 0 interrupt interface (aliased for debug purposes)",
  64.     {
  65.         {0x00, "Control Register"},
  66.         {0x04, "Priority Mask Register"},
  67.         {0x08, "Binary Point Register"},
  68.         {0x0C, "Interrupt Acknowledge Register"},
  69.         {0x10, "End of Interrupt Register"},
  70.         {0x14, "Running Priority Register"},
  71.         {0x18, "Highest Pending Interrupt Register"},
  72.         {0, NULL}
  73.     }
  74. };
  75.  
  76. const struct mpcore_pmr_peripheral CPU1_interrupt_interface_peripheral = {
  77.     0x0300,
  78.     "CPU 1 interrupt interface (aliased for debug purposes)",
  79.     {
  80.         {0x00, "Control Register"},
  81.         {0x04, "Priority Mask Register"},
  82.         {0x08, "Binary Point Register"},
  83.         {0x0C, "Interrupt Acknowledge Register"},
  84.         {0x10, "End of Interrupt Register"},
  85.         {0x14, "Running Priority Register"},
  86.         {0x18, "Highest Pending Interrupt Register"},
  87.         {0, NULL}
  88.     }
  89. };
  90.  
  91. const struct mpcore_pmr_peripheral CPU2_interrupt_interface_peripheral = {
  92.     0x0400,
  93.     "CPU 2 interrupt interface (aliased for debug purposes)",
  94.     {
  95.         {0x00, "Control Register"},
  96.         {0x04, "Priority Mask Register"},
  97.         {0x08, "Binary Point Register"},
  98.         {0x0C, "Interrupt Acknowledge Register"},
  99.         {0x10, "End of Interrupt Register"},
  100.         {0x14, "Running Priority Register"},
  101.         {0x18, "Highest Pending Interrupt Register"},
  102.         {0, NULL}
  103.     }
  104. };
  105.  
  106. const struct mpcore_pmr_peripheral CPU3_interrupt_interface_peripheral = {
  107.     0x0500,
  108.     "CPU 3 interrupt interface (aliased for debug purposes)",
  109.     {
  110.         {0x00, "Control Register"},
  111.         {0x04, "Priority Mask Register"},
  112.         {0x08, "Binary Point Register"},
  113.         {0x0C, "Interrupt Acknowledge Register"},
  114.         {0x10, "End of Interrupt Register"},
  115.         {0x14, "Running Priority Register"},
  116.         {0x18, "Highest Pending Interrupt Register"},
  117.         {0, NULL}
  118.     }
  119. };
  120.  
  121. const struct mpcore_pmr_peripheral CPU_timer_and_watchdog_peripheral = {
  122.     0x0600,
  123.     "CPU timer and watchdog (identified by CPU transaction ID)",
  124.     {
  125.         {0x00, "Timer Load Register"},
  126.         {0x04, "Timer Counter Register"},
  127.         {0x08, "Timer Control Register"},
  128.         {0x0C, "Timer Interrupt Status Register"},
  129.         {0x20, "Watchdog Load Register"},
  130.         {0x24, "Watchdog Counter Register"},
  131.         {0x28, "Watchdog Control Register"},
  132.         {0x2C, "Watchdog Interrupt Status Register"},
  133.         {0x30, "Watchdog Reset Sent Register"},
  134.         {0x34, "Watchdog Disable Register"},
  135.         {0, NULL}
  136.     }
  137. };
  138.  
  139. const struct mpcore_pmr_peripheral CPU0_timer_and_watchdog_peripheral = {
  140.     0x0700,
  141.     "CPU0 timer and watchdog",
  142.     {
  143.         {0x00, "Timer Load Register"},
  144.         {0x04, "Timer Counter Register"},
  145.         {0x08, "Timer Control Register"},
  146.         {0x0C, "Timer Interrupt Status Register"},
  147.         {0x20, "Watchdog Load Register"},
  148.         {0x24, "Watchdog Counter Register"},
  149.         {0x28, "Watchdog Control Register"},
  150.         {0x2C, "Watchdog Interrupt Status Register"},
  151.         {0x30, "Watchdog Reset Sent Register"},
  152.         {0x34, "Watchdog Disable Register"},
  153.         {0, NULL}
  154.     }
  155. };
  156.  
  157. const struct mpcore_pmr_peripheral CPU1_timer_and_watchdog_peripheral = {
  158.     0x0800,
  159.     "CPU1 timer and watchdog",
  160.     {
  161.         {0x00, "Timer Load Register"},
  162.         {0x04, "Timer Counter Register"},
  163.         {0x08, "Timer Control Register"},
  164.         {0x0C, "Timer Interrupt Status Register"},
  165.         {0x20, "Watchdog Load Register"},
  166.         {0x24, "Watchdog Counter Register"},
  167.         {0x28, "Watchdog Control Register"},
  168.         {0x2C, "Watchdog Interrupt Status Register"},
  169.         {0x30, "Watchdog Reset Sent Register"},
  170.         {0x34, "Watchdog Disable Register"},
  171.         {0, NULL}
  172.     }
  173. };
  174.  
  175. const struct mpcore_pmr_peripheral CPU2_timer_and_watchdog_peripheral = {
  176.     0x0900,
  177.     "CPU2 timer and watchdog",
  178.     {
  179.         {0x00, "Timer Load Register"},
  180.         {0x04, "Timer Counter Register"},
  181.         {0x08, "Timer Control Register"},
  182.         {0x0C, "Timer Interrupt Status Register"},
  183.         {0x20, "Watchdog Load Register"},
  184.         {0x24, "Watchdog Counter Register"},
  185.         {0x28, "Watchdog Control Register"},
  186.         {0x2C, "Watchdog Interrupt Status Register"},
  187.         {0x30, "Watchdog Reset Sent Register"},
  188.         {0x34, "Watchdog Disable Register"},
  189.         {0, NULL}
  190.     }
  191. };
  192.  
  193. const struct mpcore_pmr_peripheral CPU3_timer_and_watchdog_peripheral = {
  194.     0x0A00,
  195.     "CPU3 timer and watchdog",
  196.     {
  197.         {0x00, "Timer Load Register"},
  198.         {0x04, "Timer Counter Register"},
  199.         {0x08, "Timer Control Register"},
  200.         {0x0C, "Timer Interrupt Status Register"},
  201.         {0x20, "Watchdog Load Register"},
  202.         {0x24, "Watchdog Counter Register"},
  203.         {0x28, "Watchdog Control Register"},
  204.         {0x2C, "Watchdog Interrupt Status Register"},
  205.         {0x30, "Watchdog Reset Sent Register"},
  206.         {0x34, "Watchdog Disable Register"},
  207.         {0, NULL}
  208.     }
  209. };
  210.  
  211. const struct mpcore_pmr_peripheral global_interrupt_distributor_peripheral = {
  212.     0x1000,
  213.     "Global Interrupt distributor",
  214.     {
  215.         {0x00, "Interrupt Distributor Control Register"},
  216.         {0x04, "Interrupt Controller Type Register"},
  217.         {0x100, "Interrupt Enable set Registers ID0-ID31"},
  218.         {0x180, "Interrupt Enable clear Registers ID0-ID31"},
  219.         {0x200, "Interrupt Pending set Registers"},
  220.         {0x280, "Interrupt Pending clear Registers"},
  221.         {0x300, "Interrupt Active Bit Registers"},
  222.         {0x400, "Interrupt Priority Registers"},
  223.         {0x800, "Interrupt CPU targets Registers"},
  224.         {0xC00, "Interrupt Configuration Registers, ID0-ID15"},
  225.         {0xC04, "Interrupt Configuration Registers, ID29-ID31"},
  226.         {0xD00, "Interrupt Line Level Registers ID0-ID31"},
  227.         {0xF00, "Software Interrupt Register"},
  228.         {0xFE0, "Peripheral Identification Register 0"},
  229.         {0xFE4, "Peripheral Identification Register 1"},
  230.         {0xFE8, "Peripheral Identification Register 2"},
  231.         {0xFEC, "Peripheral Identification Register 3"},
  232.         {0xFF0, "PrimeCell Identification Register 0"},
  233.         {0xFF4, "PrimeCell Identification Register 1"},
  234.         {0xFF8, "PrimeCell Identification Register 2"},
  235.         {0xFFC, "PrimeCell Identification Register 3"},
  236.         {0, NULL}
  237.     }
  238. };
  239.  
  240. const struct mpcore_pmr_peripheral *const peripheral_array[] = {
  241.     &scu_peripheral,
  242.     &CPU_interrupt_interfaces_peripheral,
  243.     &CPU0_interrupt_interface_peripheral,
  244.     &CPU1_interrupt_interface_peripheral,
  245.     &CPU2_interrupt_interface_peripheral,
  246.     &CPU3_interrupt_interface_peripheral,
  247.     &CPU_timer_and_watchdog_peripheral,
  248.     &CPU0_timer_and_watchdog_peripheral,
  249.     &CPU1_timer_and_watchdog_peripheral,
  250.     &CPU2_timer_and_watchdog_peripheral,
  251.     &CPU3_timer_and_watchdog_peripheral,
  252.     &global_interrupt_distributor_peripheral
  253. };
  254.  
  255. int main(int argc, char *argv[])
  256. {
  257.     if (argc < 2) {
  258.         printf("Usage: mpcore-pmr-reader file.bin\n");
  259.         return -1;
  260.     }
  261.    
  262.     FILE *fp = fopen(argv[1], "rb");
  263.     if (fp == NULL) {
  264.         printf("Error opening \"%s\"\n", argv[1]);
  265.         return -1;
  266.     }
  267.    
  268.     unsigned char buffer[MPCORE_PMR_SIZE];
  269.    
  270.     size_t n = fread(buffer, 1, MPCORE_PMR_SIZE, fp);
  271.    
  272.     if (n != MPCORE_PMR_SIZE) {
  273.         printf("Error reading from \"%s\"\n", argv[1]);
  274.         fclose(fp);
  275.         return -1;
  276.     }
  277.     fclose(fp);
  278.    
  279.     int i;
  280.     for (i = 0; i < NELEMS(peripheral_array); i++) {
  281.        
  282.         printf("%s - base offset: 0x%04X\n",
  283.             peripheral_array[i]->name,
  284.             peripheral_array[i]->offset);
  285.            
  286.         int j = 0;
  287.         while ((peripheral_array[i]->registers[j].offset != 0) ||
  288.                (peripheral_array[i]->registers[j].name != NULL)) {
  289.                    
  290.             printf("\t0x%08X - %s\n",
  291.                 *(uint32_t *)(
  292.                     (uintptr_t)buffer +
  293.                     peripheral_array[i]->offset +
  294.                     peripheral_array[i]->registers[j].offset),
  295.                 peripheral_array[i]->registers[j].name
  296.                 ); 
  297.  
  298.             j++;
  299.         }
  300.     }
  301.    
  302.     return 0;
  303. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement