]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmEbPkg/Debugger_scripts/rvi_symbols_macros.inc
A better template, with some build scripts, for ArmEbPkg. New libraries are just...
[mirror_edk2.git] / ArmEbPkg / Debugger_scripts / rvi_symbols_macros.inc
diff --git a/ArmEbPkg/Debugger_scripts/rvi_symbols_macros.inc b/ArmEbPkg/Debugger_scripts/rvi_symbols_macros.inc
new file mode 100755 (executable)
index 0000000..97d465e
--- /dev/null
@@ -0,0 +1,194 @@
+//\r
+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+//  \r
+//  This program and the accompanying materials\r
+//  are licensed and made available under the terms and conditions of the BSD License\r
+//  which accompanies this distribution.  The full text of the license may be found at\r
+//  http://opensource.org/licenses/bsd-license.php\r
+//\r
+//  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+//  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+\r
+define /R int compare_guid(guid1, guid2)\r
+    unsigned char *guid1;\r
+    unsigned char *guid2;\r
+{\r
+    return strncmp(guid1, guid2, 16);\r
+}\r
+.\r
+\r
+define /R unsigned char * find_system_table(mem_start, mem_size)\r
+    unsigned char *mem_start;\r
+    unsigned long mem_size;\r
+{\r
+    unsigned char *mem_ptr;\r
+     \r
+    mem_ptr = mem_start + mem_size;\r
+    \r
+    do\r
+    {\r
+        mem_ptr -= 0x400000; // 4 MB\r
+        \r
+        if (strncmp(mem_ptr, "IBI SYST", 8) == 0)\r
+        {\r
+            return *(unsigned long *)(mem_ptr + 8); // EfiSystemTableBase\r
+        }        \r
+        \r
+    } while (mem_ptr > mem_start);\r
+    \r
+    return 0;\r
+}\r
+.\r
+\r
+define /R unsigned char * find_debug_info_table_header(system_table)\r
+    unsigned char *system_table;\r
+{\r
+    unsigned long configuration_table_entries;\r
+    unsigned char *configuration_table;\r
+    unsigned long index;\r
+    unsigned char debug_table_guid[16];\r
+    \r
+    // Fill in the debug table's guid\r
+    debug_table_guid[ 0] = 0x77;\r
+    debug_table_guid[ 1] = 0x2E;\r
+    debug_table_guid[ 2] = 0x15;\r
+    debug_table_guid[ 3] = 0x49;\r
+    debug_table_guid[ 4] = 0xDA;\r
+    debug_table_guid[ 5] = 0x1A;\r
+    debug_table_guid[ 6] = 0x64;\r
+    debug_table_guid[ 7] = 0x47;\r
+    debug_table_guid[ 8] = 0xB7;\r
+    debug_table_guid[ 9] = 0xA2;\r
+    debug_table_guid[10] = 0x7A;\r
+    debug_table_guid[11] = 0xFE;\r
+    debug_table_guid[12] = 0xFE;\r
+    debug_table_guid[13] = 0xD9;\r
+    debug_table_guid[14] = 0x5E;\r
+    debug_table_guid[15] = 0x8B;\r
+    \r
+    configuration_table_entries = *(unsigned long *)(system_table + 64);\r
+    configuration_table         = *(unsigned long *)(system_table + 68);\r
+    \r
+    for (index = 0; index < configuration_table_entries; index++)\r
+    {\r
+        if (compare_guid(configuration_table, debug_table_guid) == 0)\r
+        {\r
+            return *(unsigned long *)(configuration_table + 16);\r
+        }\r
+        \r
+        configuration_table += 20;\r
+    }\r
+    \r
+    return 0;\r
+}\r
+.\r
+\r
+define /R int valid_pe_header(header)\r
+        unsigned char *header;\r
+{\r
+    if ((header[0x00] == 'M') &&\r
+        (header[0x01] == 'Z') &&\r
+        (header[0x80] == 'P') &&\r
+        (header[0x81] == 'E'))\r
+    {\r
+        return 1;\r
+    }\r
+    \r
+    return 0;\r
+}\r
+.\r
+\r
+define /R unsigned long pe_headersize(header)\r
+        unsigned char *header;\r
+{\r
+    unsigned long *size;\r
+    \r
+    size = header + 0x00AC;\r
+    \r
+    return *size;\r
+}\r
+.\r
+\r
+define /R unsigned char *pe_filename(header)\r
+        unsigned char *header;\r
+{\r
+    unsigned long *debugOffset;\r
+    unsigned char *stringOffset;\r
+   \r
+    if (valid_pe_header(header))\r
+    {\r
+        debugOffset  = header + 0x0128;\r
+        stringOffset = header + *debugOffset + 0x002C;\r
+       \r
+        return stringOffset;\r
+    }\r
+   \r
+    return 0;\r
+}\r
+.\r
+\r
+define /R int char_is_valid(c)\r
+        unsigned char c;\r
+{\r
+    if (c >= 32 && c < 127)\r
+       return 1;\r
+\r
+    return 0;\r
+}\r
+.\r
+\r
+define /R write_symbols_file(filename, mem_start, mem_size)\r
+    unsigned char *filename;\r
+    unsigned char *mem_start;\r
+    unsigned long mem_size;    \r
+{\r
+    unsigned char *system_table;\r
+    unsigned char *debug_info_table_header;\r
+    unsigned char *debug_info_table;\r
+    unsigned long debug_info_table_size;\r
+    unsigned long index;\r
+    unsigned char *debug_image_info;\r
+    unsigned char *loaded_image_protocol;\r
+    unsigned char *image_base;\r
+    unsigned char *debug_filename;\r
+    unsigned long header_size;\r
+    int           status;\r
+    \r
+    system_table = find_system_table(mem_start, mem_size);\r
+    if (system_table == 0)\r
+    {\r
+        return;\r
+    }\r
+    \r
+    status = fopen(88, filename, "w");\r
+    \r
+    debug_info_table_header = find_debug_info_table_header(system_table);\r
+    \r
+    debug_info_table      = *(unsigned long *)(debug_info_table_header + 8);\r
+    debug_info_table_size = *(unsigned long *)(debug_info_table_header + 4);\r
+    \r
+    for (index = 0; index < (debug_info_table_size * 4); index += 4)\r
+    {\r
+        debug_image_info = *(unsigned long *)(debug_info_table + index); \r
+        \r
+        if (debug_image_info == 0)\r
+        {\r
+            break;\r
+        }\r
+        \r
+        loaded_image_protocol = *(unsigned long *)(debug_image_info + 4);\r
+        \r
+        image_base = *(unsigned long *)(loaded_image_protocol + 32);\r
+        \r
+        debug_filename = pe_filename(image_base);\r
+        header_size    = pe_headersize(image_base);\r
+    \r
+        $fprintf 88, "%s 0x%08x\n", debug_filename, image_base + header_size$;\r
+    }\r
+    \r
+    \r
+    fclose(88);\r
+}\r
+.\r
+\r