2 # Copyright (c) 2011-2013, ARM Limited. All rights reserved.
4 # SPDX-License-Identifier: BSD-2-Clause-Patent
7 from arm_ds
.debugger_v1
import DebugException
12 import firmware_volume
15 CONST_DEBUG_INFO_TABLE_GUID
= ( 0x49152E77L
, 0x47641ADAL
, 0xFE7AA2B7L
, 0x8B5ED9FEL
)
19 def __init__(self
, ec
, debug_info_table_header_offset
):
21 self
.base
= debug_info_table_header_offset
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)
29 debug_info_table_base
= self
.ec
.getMemoryService().readMemory32(self
.base
+ 0x8)
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))
38 debug_info
= self
.ec
.getMemoryService().readMemory32(debug_info_table_base
+ (i
* 4))
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)
48 image_base
= self
.ec
.getMemoryService().readMemory64(loaded_image_protocol
+ 0x40)
49 image_size
= self
.ec
.getMemoryService().readMemory32(loaded_image_protocol
+ 0x48)
51 # Get the base address of the structure EFI_LOADED_IMAGE_PROTOCOL
52 loaded_image_protocol
= self
.ec
.getMemoryService().readMemory32(debug_info
+ 0x4)
54 image_base
= self
.ec
.getMemoryService().readMemory32(loaded_image_protocol
+ 0x20)
55 image_size
= self
.ec
.getMemoryService().readMemory32(loaded_image_protocol
+ 0x28)
57 self
.DebugInfos
.append((image_base
,image_size
))
60 def load_symbols_at(self
, addr
, verbose
= False):
61 if self
.DebugInfos
== []:
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])
70 section
= firmware_volume
.EfiSectionPE32(self
.ec
, debug_info
[0])
73 edk2_debugger
.load_symbol_from_file(self
.ec
, section
.get_debug_filepath(), section
.get_debug_elfbase(), verbose
)
74 except Exception, (ErrorClass
, ErrorMessage
):
76 print "Error while loading a symbol file (%s: %s)" % (ErrorClass
, ErrorMessage
)
82 raise Exception('DebugInfoTable','No symbol found at 0x%x' % addr
)
84 def load_all_symbols(self
, verbose
= False):
85 if self
.DebugInfos
== []:
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])
92 section
= firmware_volume
.EfiSectionPE32(self
.ec
, debug_info
[0])
95 edk2_debugger
.load_symbol_from_file(self
.ec
, section
.get_debug_filepath(), section
.get_debug_elfbase(), verbose
)
96 except Exception, (ErrorClass
, ErrorMessage
):
98 print "Error while loading a symbol file (%s: %s)" % (ErrorClass
, ErrorMessage
)
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
)
107 section
= firmware_volume
.EfiSectionPE32(self
.ec
, base_pe32
)
108 print section
.get_debug_filepath()
111 CONST_ST_SIGNATURE
= ('I','B','I',' ','S','Y','S','T')
113 def __init__(self
, ec
, membase
, memsize
):
114 self
.membase
= membase
115 self
.memsize
= memsize
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
127 # Start at top and look on 4MB boundaries for system table ptr structure
128 while offset
> self
.membase
:
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
:
135 if edk2_debugger
.is_aarch64(self
.ec
):
136 self
.system_table_base
= self
.ec
.getMemoryService().readMemory64(offset
+ 0x8)
138 self
.system_table_base
= self
.ec
.getMemoryService().readMemory32(offset
+ 0x8)
140 offset
= offset
- 0x400000
143 raise Exception('SystemTable','System Table not found in System Memory [0x%x;0x%X]' % (membase
,membase
+memsize
))
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)
150 # Get location of the Configuration Table entries
151 conf_table_offset
= self
.ec
.getMemoryService().readMemory64(self
.system_table_base
+ 0x70)
153 # Number of configuration Table entry
154 conf_table_entry_count
= self
.ec
.getMemoryService().readMemory32(self
.system_table_base
+ 0x40)
156 # Get location of the Configuration Table entries
157 conf_table_offset
= self
.ec
.getMemoryService().readMemory32(self
.system_table_base
+ 0x44)
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)
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)
169 return self
.ec
.getMemoryService().readMemory32(offset
+ 0x10)
171 raise Exception('SystemTable','Configuration Table not found')