]> git.proxmox.com Git - mirror_edk2.git/blame - BeagleBoardPkg/Debugger_scripts/rvi_symbols_macros.inc
BeagleBoardPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BeagleBoardPkg / Debugger_scripts / rvi_symbols_macros.inc
CommitLineData
2ef2b01e 1//\r
1ebd6c11 2// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
3402aac7 3//\r
a1594be9 4// SPDX-License-Identifier: BSD-2-Clause-Patent\r
2ef2b01e
A
5//\r
6\r
7define /R int compare_guid(guid1, guid2)\r
8 unsigned char *guid1;\r
9 unsigned char *guid2;\r
10{\r
11 return strncmp(guid1, guid2, 16);\r
12}\r
13.\r
14\r
15define /R unsigned char * find_system_table(mem_start, mem_size)\r
16 unsigned char *mem_start;\r
17 unsigned long mem_size;\r
18{\r
19 unsigned char *mem_ptr;\r
3402aac7 20\r
2ef2b01e 21 mem_ptr = mem_start + mem_size;\r
3402aac7 22\r
2ef2b01e
A
23 do\r
24 {\r
25 mem_ptr -= 0x400000; // 4 MB\r
3402aac7 26\r
2ef2b01e
A
27 if (strncmp(mem_ptr, "IBI SYST", 8) == 0)\r
28 {\r
29 return *(unsigned long *)(mem_ptr + 8); // EfiSystemTableBase\r
3402aac7
RC
30 }\r
31\r
2ef2b01e 32 } while (mem_ptr > mem_start);\r
3402aac7 33\r
2ef2b01e
A
34 return 0;\r
35}\r
36.\r
37\r
38define /R unsigned char * find_debug_info_table_header(system_table)\r
39 unsigned char *system_table;\r
40{\r
41 unsigned long configuration_table_entries;\r
42 unsigned char *configuration_table;\r
43 unsigned long index;\r
44 unsigned char debug_table_guid[16];\r
3402aac7 45\r
2ef2b01e
A
46 // Fill in the debug table's guid\r
47 debug_table_guid[ 0] = 0x77;\r
48 debug_table_guid[ 1] = 0x2E;\r
49 debug_table_guid[ 2] = 0x15;\r
50 debug_table_guid[ 3] = 0x49;\r
51 debug_table_guid[ 4] = 0xDA;\r
52 debug_table_guid[ 5] = 0x1A;\r
53 debug_table_guid[ 6] = 0x64;\r
54 debug_table_guid[ 7] = 0x47;\r
55 debug_table_guid[ 8] = 0xB7;\r
56 debug_table_guid[ 9] = 0xA2;\r
57 debug_table_guid[10] = 0x7A;\r
58 debug_table_guid[11] = 0xFE;\r
59 debug_table_guid[12] = 0xFE;\r
60 debug_table_guid[13] = 0xD9;\r
61 debug_table_guid[14] = 0x5E;\r
62 debug_table_guid[15] = 0x8B;\r
3402aac7 63\r
2ef2b01e
A
64 configuration_table_entries = *(unsigned long *)(system_table + 64);\r
65 configuration_table = *(unsigned long *)(system_table + 68);\r
3402aac7 66\r
2ef2b01e
A
67 for (index = 0; index < configuration_table_entries; index++)\r
68 {\r
69 if (compare_guid(configuration_table, debug_table_guid) == 0)\r
70 {\r
71 return *(unsigned long *)(configuration_table + 16);\r
72 }\r
3402aac7 73\r
2ef2b01e
A
74 configuration_table += 20;\r
75 }\r
3402aac7 76\r
2ef2b01e
A
77 return 0;\r
78}\r
79.\r
80\r
81define /R int valid_pe_header(header)\r
82 unsigned char *header;\r
83{\r
84 if ((header[0x00] == 'M') &&\r
85 (header[0x01] == 'Z') &&\r
86 (header[0x80] == 'P') &&\r
87 (header[0x81] == 'E'))\r
88 {\r
89 return 1;\r
90 }\r
3402aac7 91\r
2ef2b01e
A
92 return 0;\r
93}\r
94.\r
95\r
96define /R unsigned long pe_headersize(header)\r
97 unsigned char *header;\r
98{\r
99 unsigned long *size;\r
3402aac7 100\r
2ef2b01e 101 size = header + 0x00AC;\r
3402aac7 102\r
2ef2b01e
A
103 return *size;\r
104}\r
105.\r
106\r
107define /R unsigned char *pe_filename(header)\r
108 unsigned char *header;\r
109{\r
110 unsigned long *debugOffset;\r
111 unsigned char *stringOffset;\r
3402aac7 112\r
2ef2b01e
A
113 if (valid_pe_header(header))\r
114 {\r
115 debugOffset = header + 0x0128;\r
116 stringOffset = header + *debugOffset + 0x002C;\r
3402aac7 117\r
2ef2b01e
A
118 return stringOffset;\r
119 }\r
3402aac7 120\r
2ef2b01e
A
121 return 0;\r
122}\r
123.\r
124\r
125define /R int char_is_valid(c)\r
126 unsigned char c;\r
127{\r
128 if (c >= 32 && c < 127)\r
129 return 1;\r
130\r
131 return 0;\r
132}\r
133.\r
134\r
135define /R write_symbols_file(filename, mem_start, mem_size)\r
136 unsigned char *filename;\r
137 unsigned char *mem_start;\r
3402aac7 138 unsigned long mem_size;\r
2ef2b01e
A
139{\r
140 unsigned char *system_table;\r
141 unsigned char *debug_info_table_header;\r
142 unsigned char *debug_info_table;\r
143 unsigned long debug_info_table_size;\r
144 unsigned long index;\r
145 unsigned char *debug_image_info;\r
146 unsigned char *loaded_image_protocol;\r
147 unsigned char *image_base;\r
148 unsigned char *debug_filename;\r
149 unsigned long header_size;\r
150 int status;\r
3402aac7 151\r
2ef2b01e
A
152 system_table = find_system_table(mem_start, mem_size);\r
153 if (system_table == 0)\r
154 {\r
155 return;\r
156 }\r
3402aac7 157\r
2ef2b01e 158 status = fopen(88, filename, "w");\r
3402aac7 159\r
2ef2b01e 160 debug_info_table_header = find_debug_info_table_header(system_table);\r
3402aac7 161\r
2ef2b01e
A
162 debug_info_table = *(unsigned long *)(debug_info_table_header + 8);\r
163 debug_info_table_size = *(unsigned long *)(debug_info_table_header + 4);\r
3402aac7 164\r
2ef2b01e
A
165 for (index = 0; index < (debug_info_table_size * 4); index += 4)\r
166 {\r
3402aac7
RC
167 debug_image_info = *(unsigned long *)(debug_info_table + index);\r
168\r
2ef2b01e
A
169 if (debug_image_info == 0)\r
170 {\r
171 break;\r
172 }\r
3402aac7 173\r
2ef2b01e 174 loaded_image_protocol = *(unsigned long *)(debug_image_info + 4);\r
3402aac7 175\r
2ef2b01e 176 image_base = *(unsigned long *)(loaded_image_protocol + 32);\r
3402aac7 177\r
2ef2b01e
A
178 debug_filename = pe_filename(image_base);\r
179 header_size = pe_headersize(image_base);\r
3402aac7 180\r
2ef2b01e
A
181 $fprintf 88, "%s 0x%08x\n", debug_filename, image_base + header_size$;\r
182 }\r
3402aac7
RC
183\r
184\r
2ef2b01e
A
185 fclose(88);\r
186}\r
187.\r
188\r