]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Scripts/Ds5/system_table.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ArmPlatformPkg / Scripts / Ds5 / system_table.py
1 #
2 # Copyright (c) 2011-2013, ARM Limited. All rights reserved.
3 #
4 # SPDX-License-Identifier: BSD-2-Clause-Patent
5 #
6
7 from arm_ds.debugger_v1 import DebugException
8
9 import struct
10
11 import edk2_debugger
12 import firmware_volume
13
14 class DebugInfoTable:
15 CONST_DEBUG_INFO_TABLE_GUID = ( 0x49152E77L, 0x47641ADAL, 0xFE7AA2B7L, 0x8B5ED9FEL)
16
17 DebugInfos = []
18
19 def __init__(self, ec, debug_info_table_header_offset):
20 self.ec = ec
21 self.base = debug_info_table_header_offset
22
23 def get_debug_info(self):
24 # Get the information from EFI_DEBUG_IMAGE_INFO_TABLE_HEADER
25 count = self.ec.getMemoryService().readMemory32(self.base + 0x4)
26 if edk2_debugger.is_aarch64(self.ec):
27 debug_info_table_base = self.ec.getMemoryService().readMemory64(self.base + 0x8)
28 else:
29 debug_info_table_base = self.ec.getMemoryService().readMemory32(self.base + 0x8)
30
31 self.DebugInfos = []
32
33 for i in range(0, count):
34 # Get the address of the structure EFI_DEBUG_IMAGE_INFO
35 if edk2_debugger.is_aarch64(self.ec):
36 debug_info = self.ec.getMemoryService().readMemory64(debug_info_table_base + (i * 8))
37 else:
38 debug_info = self.ec.getMemoryService().readMemory32(debug_info_table_base + (i * 4))
39
40 if debug_info:
41 debug_info_type = self.ec.getMemoryService().readMemory32(debug_info)
42 # Normal Debug Info Type
43 if debug_info_type == 1:
44 if edk2_debugger.is_aarch64(self.ec):
45 # Get the base address of the structure EFI_LOADED_IMAGE_PROTOCOL
46 loaded_image_protocol = self.ec.getMemoryService().readMemory64(debug_info + 0x8)
47
48 image_base = self.ec.getMemoryService().readMemory64(loaded_image_protocol + 0x40)
49 image_size = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x48)
50 else:
51 # Get the base address of the structure EFI_LOADED_IMAGE_PROTOCOL
52 loaded_image_protocol = self.ec.getMemoryService().readMemory32(debug_info + 0x4)
53
54 image_base = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x20)
55 image_size = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x28)
56
57 self.DebugInfos.append((image_base,image_size))
58
59 # Return (base, size)
60 def load_symbols_at(self, addr, verbose = False):
61 if self.DebugInfos == []:
62 self.get_debug_info()
63
64 found = False
65 for debug_info in self.DebugInfos:
66 if (addr >= debug_info[0]) and (addr < debug_info[0] + debug_info[1]):
67 if edk2_debugger.is_aarch64(self.ec):
68 section = firmware_volume.EfiSectionPE64(self.ec, debug_info[0])
69 else:
70 section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0])
71
72 try:
73 edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase(), verbose)
74 except Exception, (ErrorClass, ErrorMessage):
75 if verbose:
76 print "Error while loading a symbol file (%s: %s)" % (ErrorClass, ErrorMessage)
77
78 found = True
79 return debug_info
80
81 if found == False:
82 raise Exception('DebugInfoTable','No symbol found at 0x%x' % addr)
83
84 def load_all_symbols(self, verbose = False):
85 if self.DebugInfos == []:
86 self.get_debug_info()
87
88 for debug_info in self.DebugInfos:
89 if edk2_debugger.is_aarch64(self.ec):
90 section = firmware_volume.EfiSectionPE64(self.ec, debug_info[0])
91 else:
92 section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0])
93
94 try:
95 edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase(), verbose)
96 except Exception, (ErrorClass, ErrorMessage):
97 if verbose:
98 print "Error while loading a symbol file (%s: %s)" % (ErrorClass, ErrorMessage)
99
100 def dump(self):
101 self.get_debug_info()
102 for debug_info in self.DebugInfos:
103 base_pe32 = debug_info[0]
104 if edk2_debugger.is_aarch64(self.ec):
105 section = firmware_volume.EfiSectionPE64(self.ec, base_pe32)
106 else:
107 section = firmware_volume.EfiSectionPE32(self.ec, base_pe32)
108 print section.get_debug_filepath()
109
110 class SystemTable:
111 CONST_ST_SIGNATURE = ('I','B','I',' ','S','Y','S','T')
112
113 def __init__(self, ec, membase, memsize):
114 self.membase = membase
115 self.memsize = memsize
116 self.ec = ec
117
118 found = False
119
120 # Start from the top of the memory
121 offset = self.membase + self.memsize
122 # Align to highest 4MB boundary
123 offset = offset & ~0x3FFFFF
124 # We should not have a System Table at the top of the System Memory
125 offset = offset - 0x400000
126
127 # Start at top and look on 4MB boundaries for system table ptr structure
128 while offset > self.membase:
129 try:
130 signature = struct.unpack("cccccccc", self.ec.getMemoryService().read(str(offset), 8, 32))
131 except DebugException:
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))
133 if signature == SystemTable.CONST_ST_SIGNATURE:
134 found = True
135 if edk2_debugger.is_aarch64(self.ec):
136 self.system_table_base = self.ec.getMemoryService().readMemory64(offset + 0x8)
137 else:
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().readMemory64(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 if edk2_debugger.is_aarch64(self.ec):
167 return self.ec.getMemoryService().readMemory64(offset + 0x10)
168 else:
169 return self.ec.getMemoryService().readMemory32(offset + 0x10)
170
171 raise Exception('SystemTable','Configuration Table not found')