]>
Commit | Line | Data |
---|---|---|
1e57a462 | 1 | #\r |
72efe027 | 2 | # Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r |
1e57a462 | 3 | #\r |
f4dfad05 | 4 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r |
1e57a462 | 5 | #\r |
6 | \r | |
7 | from arm_ds.debugger_v1 import DebugException\r | |
8 | \r | |
9 | import struct\r | |
10 | \r | |
11 | import edk2_debugger\r | |
12 | import firmware_volume\r | |
13 | \r | |
14 | class DebugInfoTable:\r | |
15 | CONST_DEBUG_INFO_TABLE_GUID = ( 0x49152E77L, 0x47641ADAL, 0xFE7AA2B7L, 0x8B5ED9FEL)\r | |
3402aac7 | 16 | \r |
1e57a462 | 17 | DebugInfos = []\r |
3402aac7 | 18 | \r |
1e57a462 | 19 | def __init__(self, ec, debug_info_table_header_offset):\r |
20 | self.ec = ec\r | |
21 | self.base = debug_info_table_header_offset\r | |
3402aac7 | 22 | \r |
1e57a462 | 23 | def get_debug_info(self):\r |
e3d495e1 | 24 | # Get the information from EFI_DEBUG_IMAGE_INFO_TABLE_HEADER\r |
1e57a462 | 25 | count = self.ec.getMemoryService().readMemory32(self.base + 0x4)\r |
ace89877 OM |
26 | if edk2_debugger.is_aarch64(self.ec):\r |
27 | debug_info_table_base = self.ec.getMemoryService().readMemory64(self.base + 0x8)\r | |
28 | else:\r | |
29 | debug_info_table_base = self.ec.getMemoryService().readMemory32(self.base + 0x8)\r | |
3402aac7 | 30 | \r |
1e57a462 | 31 | self.DebugInfos = []\r |
3402aac7 | 32 | \r |
1e57a462 | 33 | for i in range(0, count):\r |
34 | # Get the address of the structure EFI_DEBUG_IMAGE_INFO\r | |
e3d495e1 | 35 | if edk2_debugger.is_aarch64(self.ec):\r |
ace89877 | 36 | debug_info = self.ec.getMemoryService().readMemory64(debug_info_table_base + (i * 8))\r |
e3d495e1 HL |
37 | else:\r |
38 | debug_info = self.ec.getMemoryService().readMemory32(debug_info_table_base + (i * 4))\r | |
39 | \r | |
1e57a462 | 40 | if debug_info:\r |
41 | debug_info_type = self.ec.getMemoryService().readMemory32(debug_info)\r | |
42 | # Normal Debug Info Type\r | |
43 | if debug_info_type == 1:\r | |
e3d495e1 HL |
44 | if edk2_debugger.is_aarch64(self.ec):\r |
45 | # Get the base address of the structure EFI_LOADED_IMAGE_PROTOCOL\r | |
ace89877 | 46 | loaded_image_protocol = self.ec.getMemoryService().readMemory64(debug_info + 0x8)\r |
e3d495e1 | 47 | \r |
ace89877 | 48 | image_base = self.ec.getMemoryService().readMemory64(loaded_image_protocol + 0x40)\r |
e3d495e1 HL |
49 | image_size = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x48)\r |
50 | else:\r | |
51 | # Get the base address of the structure EFI_LOADED_IMAGE_PROTOCOL\r | |
52 | loaded_image_protocol = self.ec.getMemoryService().readMemory32(debug_info + 0x4)\r | |
53 | \r | |
54 | image_base = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x20)\r | |
55 | image_size = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x28)\r | |
3402aac7 | 56 | \r |
1e57a462 | 57 | self.DebugInfos.append((image_base,image_size))\r |
3402aac7 | 58 | \r |
1e57a462 | 59 | # Return (base, size)\r |
72efe027 | 60 | def load_symbols_at(self, addr, verbose = False):\r |
1e57a462 | 61 | if self.DebugInfos == []:\r |
62 | self.get_debug_info()\r | |
3402aac7 | 63 | \r |
1e57a462 | 64 | found = False\r |
65 | for debug_info in self.DebugInfos:\r | |
66 | if (addr >= debug_info[0]) and (addr < debug_info[0] + debug_info[1]):\r | |
e3d495e1 HL |
67 | if edk2_debugger.is_aarch64(self.ec):\r |
68 | section = firmware_volume.EfiSectionPE64(self.ec, debug_info[0])\r | |
69 | else:\r | |
70 | section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0])\r | |
3402aac7 | 71 | \r |
72efe027 | 72 | try:\r |
73 | edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase(), verbose)\r | |
74 | except Exception, (ErrorClass, ErrorMessage):\r | |
75 | if verbose:\r | |
76 | print "Error while loading a symbol file (%s: %s)" % (ErrorClass, ErrorMessage)\r | |
1e57a462 | 77 | \r |
78 | found = True\r | |
79 | return debug_info\r | |
80 | \r | |
81 | if found == False:\r | |
82 | raise Exception('DebugInfoTable','No symbol found at 0x%x' % addr)\r | |
83 | \r | |
72efe027 | 84 | def load_all_symbols(self, verbose = False):\r |
1e57a462 | 85 | if self.DebugInfos == []:\r |
86 | self.get_debug_info()\r | |
3402aac7 | 87 | \r |
1e57a462 | 88 | for debug_info in self.DebugInfos:\r |
e3d495e1 HL |
89 | if edk2_debugger.is_aarch64(self.ec):\r |
90 | section = firmware_volume.EfiSectionPE64(self.ec, debug_info[0])\r | |
91 | else:\r | |
e6f3ed43 | 92 | section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0])\r |
3402aac7 | 93 | \r |
72efe027 | 94 | try:\r |
95 | edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase(), verbose)\r | |
96 | except Exception, (ErrorClass, ErrorMessage):\r | |
97 | if verbose:\r | |
98 | print "Error while loading a symbol file (%s: %s)" % (ErrorClass, ErrorMessage)\r | |
1e57a462 | 99 | \r |
100 | def dump(self):\r | |
101 | self.get_debug_info()\r | |
102 | for debug_info in self.DebugInfos:\r | |
103 | base_pe32 = debug_info[0]\r | |
e3d495e1 HL |
104 | if edk2_debugger.is_aarch64(self.ec):\r |
105 | section = firmware_volume.EfiSectionPE64(self.ec, base_pe32)\r | |
106 | else:\r | |
107 | section = firmware_volume.EfiSectionPE32(self.ec, base_pe32)\r | |
1e57a462 | 108 | print section.get_debug_filepath()\r |
3402aac7 | 109 | \r |
1e57a462 | 110 | class SystemTable:\r |
111 | CONST_ST_SIGNATURE = ('I','B','I',' ','S','Y','S','T')\r | |
3402aac7 | 112 | \r |
1e57a462 | 113 | def __init__(self, ec, membase, memsize):\r |
114 | self.membase = membase\r | |
115 | self.memsize = memsize\r | |
116 | self.ec = ec\r | |
3402aac7 | 117 | \r |
1e57a462 | 118 | found = False\r |
3402aac7 | 119 | \r |
1e57a462 | 120 | # Start from the top of the memory\r |
121 | offset = self.membase + self.memsize\r | |
122 | # Align to highest 4MB boundary\r | |
123 | offset = offset & ~0x3FFFFF\r | |
124 | # We should not have a System Table at the top of the System Memory\r | |
125 | offset = offset - 0x400000\r | |
3402aac7 | 126 | \r |
1e57a462 | 127 | # Start at top and look on 4MB boundaries for system table ptr structure\r |
128 | while offset > self.membase:\r | |
129 | try:\r | |
130 | signature = struct.unpack("cccccccc", self.ec.getMemoryService().read(str(offset), 8, 32))\r | |
131 | except DebugException:\r | |
132 | raise Exception('SystemTable','Fail to access System Memory. Ensure all the memory in the region [0x%x;0x%X] is accessible.' % (membase,membase+memsize))\r | |
133 | if signature == SystemTable.CONST_ST_SIGNATURE:\r | |
134 | found = True\r | |
ace89877 OM |
135 | if edk2_debugger.is_aarch64(self.ec):\r |
136 | self.system_table_base = self.ec.getMemoryService().readMemory64(offset + 0x8)\r | |
137 | else:\r | |
138 | self.system_table_base = self.ec.getMemoryService().readMemory32(offset + 0x8)\r | |
1e57a462 | 139 | break\r |
140 | offset = offset - 0x400000\r | |
3402aac7 | 141 | \r |
1e57a462 | 142 | if not found:\r |
143 | raise Exception('SystemTable','System Table not found in System Memory [0x%x;0x%X]' % (membase,membase+memsize))\r | |
3402aac7 | 144 | \r |
1e57a462 | 145 | def get_configuration_table(self, conf_table_guid):\r |
e3d495e1 HL |
146 | if edk2_debugger.is_aarch64(self.ec):\r |
147 | # Number of configuration Table entry\r | |
e6f3ed43 | 148 | conf_table_entry_count = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x68)\r |
e3d495e1 HL |
149 | \r |
150 | # Get location of the Configuration Table entries\r | |
ace89877 | 151 | conf_table_offset = self.ec.getMemoryService().readMemory64(self.system_table_base + 0x70)\r |
e3d495e1 HL |
152 | else:\r |
153 | # Number of configuration Table entry\r | |
e6f3ed43 | 154 | conf_table_entry_count = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x40)\r |
e3d495e1 HL |
155 | \r |
156 | # Get location of the Configuration Table entries\r | |
157 | conf_table_offset = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x44)\r | |
3402aac7 | 158 | \r |
1e57a462 | 159 | for i in range(0, conf_table_entry_count):\r |
e3d495e1 HL |
160 | if edk2_debugger.is_aarch64(self.ec):\r |
161 | offset = conf_table_offset + (i * 0x18)\r | |
162 | else:\r | |
163 | offset = conf_table_offset + (i * 0x14)\r | |
1e57a462 | 164 | guid = struct.unpack("<IIII", self.ec.getMemoryService().read(str(offset), 16, 32))\r |
165 | if guid == conf_table_guid:\r | |
ace89877 OM |
166 | if edk2_debugger.is_aarch64(self.ec):\r |
167 | return self.ec.getMemoryService().readMemory64(offset + 0x10)\r | |
168 | else:\r | |
169 | return self.ec.getMemoryService().readMemory32(offset + 0x10)\r | |
3402aac7 | 170 | \r |
1e57a462 | 171 | raise Exception('SystemTable','Configuration Table not found')\r |