2 // Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 // SPDX-License-Identifier: BSD-2-Clause-Patent
7 define /R int compare_guid(guid1, guid2)
11 return strncmp(guid1, guid2, 16);
15 define /R unsigned char * find_system_table(mem_start, mem_size)
16 unsigned char *mem_start;
17 unsigned long mem_size;
19 unsigned char *mem_ptr;
21 mem_ptr = mem_start + mem_size;
25 mem_ptr -= 0x400000; // 4 MB
27 if (strncmp(mem_ptr, "IBI SYST", 8) == 0)
29 return *(unsigned long *)(mem_ptr + 8); // EfiSystemTableBase
32 } while (mem_ptr > mem_start);
38 define /R unsigned char * find_debug_info_table_header(system_table)
39 unsigned char *system_table;
41 unsigned long configuration_table_entries;
42 unsigned char *configuration_table;
44 unsigned char debug_table_guid[16];
46 // Fill in the debug table's guid
47 debug_table_guid[ 0] = 0x77;
48 debug_table_guid[ 1] = 0x2E;
49 debug_table_guid[ 2] = 0x15;
50 debug_table_guid[ 3] = 0x49;
51 debug_table_guid[ 4] = 0xDA;
52 debug_table_guid[ 5] = 0x1A;
53 debug_table_guid[ 6] = 0x64;
54 debug_table_guid[ 7] = 0x47;
55 debug_table_guid[ 8] = 0xB7;
56 debug_table_guid[ 9] = 0xA2;
57 debug_table_guid[10] = 0x7A;
58 debug_table_guid[11] = 0xFE;
59 debug_table_guid[12] = 0xFE;
60 debug_table_guid[13] = 0xD9;
61 debug_table_guid[14] = 0x5E;
62 debug_table_guid[15] = 0x8B;
64 configuration_table_entries = *(unsigned long *)(system_table + 64);
65 configuration_table = *(unsigned long *)(system_table + 68);
67 for (index = 0; index < configuration_table_entries; index++)
69 if (compare_guid(configuration_table, debug_table_guid) == 0)
71 return *(unsigned long *)(configuration_table + 16);
74 configuration_table += 20;
81 define /R int valid_pe_header(header)
82 unsigned char *header;
84 if ((header[0x00] == 'M') &&
85 (header[0x01] == 'Z') &&
86 (header[0x80] == 'P') &&
87 (header[0x81] == 'E'))
96 define /R unsigned long pe_headersize(header)
97 unsigned char *header;
101 size = header + 0x00AC;
107 define /R unsigned char *pe_filename(header)
108 unsigned char *header;
110 unsigned long *debugOffset;
111 unsigned char *stringOffset;
113 if (valid_pe_header(header))
115 debugOffset = header + 0x0128;
116 stringOffset = header + *debugOffset + 0x002C;
125 define /R int char_is_valid(c)
128 if (c >= 32 && c < 127)
135 define /R write_symbols_file(filename, mem_start, mem_size)
136 unsigned char *filename;
137 unsigned char *mem_start;
138 unsigned long mem_size;
140 unsigned char *system_table;
141 unsigned char *debug_info_table_header;
142 unsigned char *debug_info_table;
143 unsigned long debug_info_table_size;
145 unsigned char *debug_image_info;
146 unsigned char *loaded_image_protocol;
147 unsigned char *image_base;
148 unsigned char *debug_filename;
149 unsigned long header_size;
152 system_table = find_system_table(mem_start, mem_size);
153 if (system_table == 0)
158 status = fopen(88, filename, "w");
160 debug_info_table_header = find_debug_info_table_header(system_table);
162 debug_info_table = *(unsigned long *)(debug_info_table_header + 8);
163 debug_info_table_size = *(unsigned long *)(debug_info_table_header + 4);
165 for (index = 0; index < (debug_info_table_size * 4); index += 4)
167 debug_image_info = *(unsigned long *)(debug_info_table + index);
169 if (debug_image_info == 0)
174 loaded_image_protocol = *(unsigned long *)(debug_image_info + 4);
176 image_base = *(unsigned long *)(loaded_image_protocol + 32);
178 debug_filename = pe_filename(image_base);
179 header_size = pe_headersize(image_base);
181 $fprintf 88, "%s 0x%08x\n", debug_filename, image_base + header_size$;