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