Guest User

Untitled

a guest
Oct 22nd, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include <assert.h>
  6.  
  7. static void parse_vs_draw(uint32_t *value1, uint32_t *value2)
  8. {
  9.    printf("\tDRAW: num_1: %d (0x%x), index_draw: %s, num_2: %d (0x%x)\n",
  10.           *value1 >> 24, *value1 >> 24,
  11.           (*value2 & 0x00000001) ? "enabled" : "disabled",
  12.           (*value2 & 0xfffffffe) << 8, (*value2 & 0xfffffffe) << 8);
  13. }
  14.  
  15. static void parse_vs_shader_info(uint32_t *value1, uint32_t *value2)
  16. {
  17.    printf("\tSHADER_INFO: prefetch: %s, size: %d (0x%x)\n",
  18.           (*value1 & 0x00100000) ? "enabled" : "disabled",
  19.           (((*value1 & 0x000fffff) >> 10) + 1) << 4,
  20.           (((*value1 & 0x000fffff) >> 10) + 1) << 4);
  21. }
  22.  
  23. static void parse_vs_unknown1(uint32_t *value1, uint32_t *value2)
  24. {
  25.    printf("\tUNKNOWN_1\n");
  26. }
  27.  
  28. static void parse_vs_varying_attribute_count(uint32_t *value1, uint32_t *value2)
  29. {
  30.    printf("\tVARYING_ATTRIBUTE_COUNT: nr_vary: %d (0x%x), nr_attr: %d (0x%x)\n",
  31.           ((*value1 & 0x00ffffff) >> 8) + 1, ((*value1 & 0x00ffffff) >> 8) + 1,
  32.           (*value1 >> 24) + 1, (*value1 >> 24) + 1);
  33. }
  34.  
  35. static void parse_vs_attributes_address(uint32_t *value1, uint32_t *value2)
  36. {
  37.    printf("\tATTRIBUTES_ADDRESS: address: 0x%08x, size: %d (0x%x)\n",
  38.           *value1, (*value2 & 0x0fffffff) >> 17, (*value2 & 0x0fffffff) >> 17);
  39. }
  40.  
  41. static void parse_vs_varyings_address(uint32_t *value1, uint32_t *value2)
  42. {
  43.    printf("\tVARYINGS_ADDRESS: address: 0x%08x, size: %d (0x%x)\n",
  44.           *value1, (*value2 & 0x0fffffff) >> 17, (*value2 & 0x0fffffff) >> 17);
  45. }
  46.  
  47. static void parse_vs_uniforms_address(uint32_t *value1, uint32_t *value2)
  48. {
  49.    printf("\tUNIFORMS_ADDRESS: address: 0x%08x, size: %d (0x%x)\n",
  50.           *value1, (*value2 & 0x0fffffff) >> 12, (*value2 & 0x0fffffff) >> 12);
  51. }
  52.  
  53. static void parse_vs_shader_address(uint32_t *value1, uint32_t *value2)
  54. {
  55.    printf("\tSHADER_ADDRESS: address: 0x%08x, size: %d (0x%x)\n",
  56.           *value1, (*value2 & 0x0fffffff) >> 12, (*value2 & 0x0fffffff) >> 12);
  57. }
  58.  
  59. static void parse_vs_semaphore(uint32_t *value1, uint32_t *value2)
  60. {
  61.    if (*value1 == 0x00028000)
  62.       printf("\tSEMAPHORE_BEGIN_1\n");
  63.    else if (*value1 == 0x00000001)
  64.       printf("\tSEMAPHORE_BEGIN_2\n");
  65.    else if (*value1 == 0x00000000)
  66.       printf("\tSEMAPHORE_END: index_draw disabled\n");
  67.    else if (*value1 == 0x00018000)
  68.       printf("\tSEMAPHORE_END: index_draw disabled\n");
  69.    else
  70.       printf("\tSEMAPHORE - cmd unknown!\n");
  71. }
  72.  
  73. static void parse_vs_unknown2(uint32_t *value1, uint32_t *value2)
  74. {
  75.    printf("\tUNKNOWN_2\n");
  76. }
  77.  
  78. void parse_vs(uint32_t desc[], int size_i)
  79. {
  80.    uint32_t *value1;
  81.    uint32_t *value2;
  82.  
  83.    printf("============ VS CMD STREAM BEGIN =============\n");
  84.    for (int i = 0; i < (size_i / 4) - 1; i = i + 2) {
  85.       value1 = &desc[i];
  86.       value2 = &desc[i + 1];
  87.  
  88.       printf("/* 0x%08x */\t0x%08x 0x%08x", i * 4, *value1, *value2);
  89.  
  90.       if ((*value2 & 0xffff0000) == 0x00000000)
  91.          parse_vs_draw(value1, value2);
  92.       else if ((*value2 & 0xff0000ff) == 0x10000040)
  93.          parse_vs_shader_info(value1, value2);
  94.       else if ((*value2 & 0xff0000ff) == 0x10000041)
  95.          parse_vs_unknown1(value1, value2);
  96.       else if ((*value2 & 0xff0000ff) == 0x10000042)
  97.          parse_vs_varying_attribute_count(value1, value2);
  98.       else if ((*value2 & 0xff0000ff) == 0x20000000)
  99.          parse_vs_attributes_address(value1, value2);
  100.       else if ((*value2 & 0xff0000ff) == 0x20000008)
  101.          parse_vs_varyings_address(value1, value2);
  102.       else if ((*value2 & 0xff000000) == 0x30000000)
  103.          parse_vs_uniforms_address(value1, value2);
  104.       else if ((*value2 & 0xff000000) == 0x40000000)
  105.          parse_vs_shader_address(value1, value2);
  106.       else if ((*value2  & 0xff000000)== 0x50000000)
  107.          parse_vs_semaphore(value1, value2);
  108.       else if ((*value2 & 0xff000000) == 0x60000000)
  109.          parse_vs_unknown2(value1, value2);
  110.       else
  111.          printf("\t--- unknown cmd ---\n");
  112.    }
  113.    printf("============ VS CMD STREAM END ===============\n");
  114. }
  115.  
  116. int main(void)
  117. {
  118.    /* Mali blob */
  119.    uint32_t desc_i[] = {
  120.       0x00028000, 0x50000000, 0x00000001, 0x50000000, /* 0x00000000 */
  121.       0x10014480, 0x30040000, 0x10000100, 0x40050000, /* 0x00000010 */
  122.       0x00001000, 0x10000040, 0x00000100, 0x10000042, /* 0x00000020 */
  123.       0x00000003, 0x10000041, 0x100144c0, 0x20020000, /* 0x00000030 */
  124.       0x100144d0, 0x20040008, 0x01000000, 0x00000000, /* 0x00000040 */
  125.       0x00000000, 0x60000000, 0x00000000, 0x50000000, /* 0x00000050 */
  126.    };
  127.  
  128.    parse_vs(desc_i, sizeof(desc_i));
  129.  
  130.    return 0;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment