]> git.proxmox.com Git - mirror_edk2.git/blob - BeagleBoardPkg/Debugger_scripts/rvi_symbols_macros.inc
ArmPkg/CompilerIntrinsicsLib: Add uread, uwrite GCC assembly sources
[mirror_edk2.git] / BeagleBoardPkg / Debugger_scripts / rvi_symbols_macros.inc
1 //
2 // Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
3 //
4 // SPDX-License-Identifier: BSD-2-Clause-Patent
5 //
6
7 define /R int compare_guid(guid1, guid2)
8 unsigned char *guid1;
9 unsigned char *guid2;
10 {
11 return strncmp(guid1, guid2, 16);
12 }
13 .
14
15 define /R unsigned char * find_system_table(mem_start, mem_size)
16 unsigned char *mem_start;
17 unsigned long mem_size;
18 {
19 unsigned char *mem_ptr;
20
21 mem_ptr = mem_start + mem_size;
22
23 do
24 {
25 mem_ptr -= 0x400000; // 4 MB
26
27 if (strncmp(mem_ptr, "IBI SYST", 8) == 0)
28 {
29 return *(unsigned long *)(mem_ptr + 8); // EfiSystemTableBase
30 }
31
32 } while (mem_ptr > mem_start);
33
34 return 0;
35 }
36 .
37
38 define /R unsigned char * find_debug_info_table_header(system_table)
39 unsigned char *system_table;
40 {
41 unsigned long configuration_table_entries;
42 unsigned char *configuration_table;
43 unsigned long index;
44 unsigned char debug_table_guid[16];
45
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;
63
64 configuration_table_entries = *(unsigned long *)(system_table + 64);
65 configuration_table = *(unsigned long *)(system_table + 68);
66
67 for (index = 0; index < configuration_table_entries; index++)
68 {
69 if (compare_guid(configuration_table, debug_table_guid) == 0)
70 {
71 return *(unsigned long *)(configuration_table + 16);
72 }
73
74 configuration_table += 20;
75 }
76
77 return 0;
78 }
79 .
80
81 define /R int valid_pe_header(header)
82 unsigned char *header;
83 {
84 if ((header[0x00] == 'M') &&
85 (header[0x01] == 'Z') &&
86 (header[0x80] == 'P') &&
87 (header[0x81] == 'E'))
88 {
89 return 1;
90 }
91
92 return 0;
93 }
94 .
95
96 define /R unsigned long pe_headersize(header)
97 unsigned char *header;
98 {
99 unsigned long *size;
100
101 size = header + 0x00AC;
102
103 return *size;
104 }
105 .
106
107 define /R unsigned char *pe_filename(header)
108 unsigned char *header;
109 {
110 unsigned long *debugOffset;
111 unsigned char *stringOffset;
112
113 if (valid_pe_header(header))
114 {
115 debugOffset = header + 0x0128;
116 stringOffset = header + *debugOffset + 0x002C;
117
118 return stringOffset;
119 }
120
121 return 0;
122 }
123 .
124
125 define /R int char_is_valid(c)
126 unsigned char c;
127 {
128 if (c >= 32 && c < 127)
129 return 1;
130
131 return 0;
132 }
133 .
134
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;
139 {
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;
144 unsigned long index;
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;
150 int status;
151
152 system_table = find_system_table(mem_start, mem_size);
153 if (system_table == 0)
154 {
155 return;
156 }
157
158 status = fopen(88, filename, "w");
159
160 debug_info_table_header = find_debug_info_table_header(system_table);
161
162 debug_info_table = *(unsigned long *)(debug_info_table_header + 8);
163 debug_info_table_size = *(unsigned long *)(debug_info_table_header + 4);
164
165 for (index = 0; index < (debug_info_table_size * 4); index += 4)
166 {
167 debug_image_info = *(unsigned long *)(debug_info_table + index);
168
169 if (debug_image_info == 0)
170 {
171 break;
172 }
173
174 loaded_image_protocol = *(unsigned long *)(debug_image_info + 4);
175
176 image_base = *(unsigned long *)(loaded_image_protocol + 32);
177
178 debug_filename = pe_filename(image_base);
179 header_size = pe_headersize(image_base);
180
181 $fprintf 88, "%s 0x%08x\n", debug_filename, image_base + header_size$;
182 }
183
184
185 fclose(88);
186 }
187 .
188