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