]>
Commit | Line | Data |
---|---|---|
1e57a462 | 1 | #\r |
72efe027 | 2 | # Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r |
1e57a462 | 3 | # \r |
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 | |
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 | |
22 | \r | |
23 | DebugInfos = []\r | |
24 | \r | |
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 | |
28 | \r | |
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 |
32 | debug_info_table_base = self.ec.getMemoryService().readMemory32(self.base + 0x8)\r | |
33 | \r | |
34 | self.DebugInfos = []\r | |
35 | \r | |
36 | for i in range(0, count):\r | |
37 | # Get the address of the structure EFI_DEBUG_IMAGE_INFO\r | |
e3d495e1 HL |
38 | if edk2_debugger.is_aarch64(self.ec):\r |
39 | debug_info = self.ec.getMemoryService().readMemory32(debug_info_table_base + (i * 8))\r | |
40 | else:\r | |
41 | debug_info = self.ec.getMemoryService().readMemory32(debug_info_table_base + (i * 4))\r | |
42 | \r | |
1e57a462 | 43 | if debug_info:\r |
44 | debug_info_type = self.ec.getMemoryService().readMemory32(debug_info)\r | |
45 | # Normal Debug Info Type\r | |
46 | if debug_info_type == 1:\r | |
e3d495e1 HL |
47 | if edk2_debugger.is_aarch64(self.ec):\r |
48 | # Get the base address of the structure EFI_LOADED_IMAGE_PROTOCOL\r | |
49 | loaded_image_protocol = self.ec.getMemoryService().readMemory32(debug_info + 0x8)\r | |
50 | \r | |
51 | image_base = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x40)\r | |
52 | image_size = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x48)\r | |
53 | else:\r | |
54 | # Get the base address of the structure EFI_LOADED_IMAGE_PROTOCOL\r | |
55 | loaded_image_protocol = self.ec.getMemoryService().readMemory32(debug_info + 0x4)\r | |
56 | \r | |
57 | image_base = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x20)\r | |
58 | image_size = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x28)\r | |
1e57a462 | 59 | \r |
60 | self.DebugInfos.append((image_base,image_size))\r | |
61 | \r | |
62 | # Return (base, size)\r | |
72efe027 | 63 | def load_symbols_at(self, addr, verbose = False):\r |
1e57a462 | 64 | if self.DebugInfos == []:\r |
65 | self.get_debug_info()\r | |
66 | \r | |
67 | found = False\r | |
68 | for debug_info in self.DebugInfos:\r | |
69 | if (addr >= debug_info[0]) and (addr < debug_info[0] + debug_info[1]):\r | |
e3d495e1 HL |
70 | if edk2_debugger.is_aarch64(self.ec):\r |
71 | section = firmware_volume.EfiSectionPE64(self.ec, debug_info[0])\r | |
72 | else:\r | |
73 | section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0])\r | |
1e57a462 | 74 | \r |
72efe027 | 75 | try:\r |
76 | edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase(), verbose)\r | |
77 | except Exception, (ErrorClass, ErrorMessage):\r | |
78 | if verbose:\r | |
79 | print "Error while loading a symbol file (%s: %s)" % (ErrorClass, ErrorMessage)\r | |
1e57a462 | 80 | \r |
81 | found = True\r | |
82 | return debug_info\r | |
83 | \r | |
84 | if found == False:\r | |
85 | raise Exception('DebugInfoTable','No symbol found at 0x%x' % addr)\r | |
86 | \r | |
72efe027 | 87 | def load_all_symbols(self, verbose = False):\r |
1e57a462 | 88 | if self.DebugInfos == []:\r |
89 | self.get_debug_info()\r | |
90 | \r | |
91 | for debug_info in self.DebugInfos:\r | |
e3d495e1 HL |
92 | if edk2_debugger.is_aarch64(self.ec):\r |
93 | section = firmware_volume.EfiSectionPE64(self.ec, debug_info[0])\r | |
94 | else:\r | |
95 | section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0]) | |
96 | \r | |
72efe027 | 97 | try:\r |
98 | edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase(), verbose)\r | |
99 | except Exception, (ErrorClass, ErrorMessage):\r | |
100 | if verbose:\r | |
101 | print "Error while loading a symbol file (%s: %s)" % (ErrorClass, ErrorMessage)\r | |
1e57a462 | 102 | \r |
103 | def dump(self):\r | |
104 | self.get_debug_info()\r | |
105 | for debug_info in self.DebugInfos:\r | |
106 | base_pe32 = debug_info[0]\r | |
e3d495e1 HL |
107 | if edk2_debugger.is_aarch64(self.ec):\r |
108 | section = firmware_volume.EfiSectionPE64(self.ec, base_pe32)\r | |
109 | else:\r | |
110 | section = firmware_volume.EfiSectionPE32(self.ec, base_pe32)\r | |
1e57a462 | 111 | print section.get_debug_filepath()\r |
112 | \r | |
113 | class SystemTable:\r | |
114 | CONST_ST_SIGNATURE = ('I','B','I',' ','S','Y','S','T')\r | |
115 | \r | |
116 | def __init__(self, ec, membase, memsize):\r | |
117 | self.membase = membase\r | |
118 | self.memsize = memsize\r | |
119 | self.ec = ec\r | |
120 | \r | |
121 | found = False\r | |
122 | \r | |
123 | # Start from the top of the memory\r | |
124 | offset = self.membase + self.memsize\r | |
125 | # Align to highest 4MB boundary\r | |
126 | offset = offset & ~0x3FFFFF\r | |
127 | # We should not have a System Table at the top of the System Memory\r | |
128 | offset = offset - 0x400000\r | |
129 | \r | |
130 | # Start at top and look on 4MB boundaries for system table ptr structure\r | |
131 | while offset > self.membase:\r | |
132 | try:\r | |
133 | signature = struct.unpack("cccccccc", self.ec.getMemoryService().read(str(offset), 8, 32))\r | |
134 | except DebugException:\r | |
135 | 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 | |
136 | if signature == SystemTable.CONST_ST_SIGNATURE:\r | |
137 | found = True\r | |
138 | self.system_table_base = self.ec.getMemoryService().readMemory32(offset + 0x8)\r | |
139 | break\r | |
140 | offset = offset - 0x400000\r | |
141 | \r | |
142 | if not found:\r | |
143 | raise Exception('SystemTable','System Table not found in System Memory [0x%x;0x%X]' % (membase,membase+memsize))\r | |
144 | \r | |
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 | |
148 | conf_table_entry_count = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x68) | |
149 | \r | |
150 | # Get location of the Configuration Table entries\r | |
151 | conf_table_offset = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x70)\r | |
152 | else:\r | |
153 | # Number of configuration Table entry\r | |
154 | conf_table_entry_count = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x40) | |
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 | |
1e57a462 | 158 | \r |
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 | |
166 | return self.ec.getMemoryService().readMemory32(offset + 0x10)\r | |
167 | \r | |
168 | raise Exception('SystemTable','Configuration Table not found')\r |