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