]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Scripts/Ds5/system_table.py
ARM Packages: Fixed line endings
[mirror_edk2.git] / ArmPlatformPkg / Scripts / Ds5 / system_table.py
1 #
2 # Copyright (c) 2011-2012, 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 count = self.ec.getMemoryService().readMemory32(self.base + 0x4)
31 debug_info_table_base = self.ec.getMemoryService().readMemory32(self.base + 0x8)
32
33 self.DebugInfos = []
34
35 for i in range(0, count):
36 # Get the address of the structure EFI_DEBUG_IMAGE_INFO
37 debug_info = self.ec.getMemoryService().readMemory32(debug_info_table_base + (i * 4))
38 if debug_info:
39 debug_info_type = self.ec.getMemoryService().readMemory32(debug_info)
40 # Normal Debug Info Type
41 if debug_info_type == 1:
42 # Get the base address of the structure EFI_LOADED_IMAGE_PROTOCOL
43 loaded_image_protocol = self.ec.getMemoryService().readMemory32(debug_info + 0x4)
44
45 image_base = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x20)
46 image_size = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x28)
47
48 self.DebugInfos.append((image_base,image_size))
49
50 # Return (base, size)
51 def load_symbols_at(self, addr):
52 if self.DebugInfos == []:
53 self.get_debug_info()
54
55 found = False
56 for debug_info in self.DebugInfos:
57 if (addr >= debug_info[0]) and (addr < debug_info[0] + debug_info[1]):
58 section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0])
59
60 edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase())
61
62 found = True
63 return debug_info
64
65 if found == False:
66 raise Exception('DebugInfoTable','No symbol found at 0x%x' % addr)
67
68 def load_all_symbols(self):
69 if self.DebugInfos == []:
70 self.get_debug_info()
71
72 for debug_info in self.DebugInfos:
73 section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0])
74
75 edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase())
76
77 def dump(self):
78 self.get_debug_info()
79 for debug_info in self.DebugInfos:
80 base_pe32 = debug_info[0]
81 section = firmware_volume.EfiSectionPE32(self.ec, base_pe32)
82 print section.get_debug_filepath()
83
84 class SystemTable:
85 CONST_ST_SIGNATURE = ('I','B','I',' ','S','Y','S','T')
86
87 def __init__(self, ec, membase, memsize):
88 self.membase = membase
89 self.memsize = memsize
90 self.ec = ec
91
92 found = False
93
94 # Start from the top of the memory
95 offset = self.membase + self.memsize
96 # Align to highest 4MB boundary
97 offset = offset & ~0x3FFFFF
98 # We should not have a System Table at the top of the System Memory
99 offset = offset - 0x400000
100
101 # Start at top and look on 4MB boundaries for system table ptr structure
102 while offset > self.membase:
103 try:
104 signature = struct.unpack("cccccccc", self.ec.getMemoryService().read(str(offset), 8, 32))
105 except DebugException:
106 raise Exception('SystemTable','Fail to access System Memory. Ensure all the memory in the region [0x%x;0x%X] is accessible.' % (membase,membase+memsize))
107 if signature == SystemTable.CONST_ST_SIGNATURE:
108 found = True
109 self.system_table_base = self.ec.getMemoryService().readMemory32(offset + 0x8)
110 break
111 offset = offset - 0x400000
112
113 if not found:
114 raise Exception('SystemTable','System Table not found in System Memory [0x%x;0x%X]' % (membase,membase+memsize))
115
116 def get_configuration_table(self, conf_table_guid):
117 # Number of configuration Table entry
118 conf_table_entry_count = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x40)
119
120 # Get location of the Configuration Table entries
121 conf_table_offset = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x44)
122
123 for i in range(0, conf_table_entry_count):
124 offset = conf_table_offset + (i * 0x14)
125 guid = struct.unpack("<IIII", self.ec.getMemoryService().read(str(offset), 16, 32))
126 if guid == conf_table_guid:
127 return self.ec.getMemoryService().readMemory32(offset + 0x10)
128
129 raise Exception('SystemTable','Configuration Table not found')