2 # Copyright (c) 2011-2012, ARM Limited. All rights reserved.
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
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.
13 from arm_ds
.debugger_v1
import DebugException
15 import firmware_volume
19 CONST_DEBUG_INFO_TABLE_GUID
= ( 0x49152E77L
, 0x47641ADAL
, 0xFE7AA2B7L
, 0x8B5ED9FEL
)
23 def __init__(self
, ec
, debug_info_table_header_offset
):
25 self
.base
= debug_info_table_header_offset
27 def get_debug_info(self
):
28 count
= self
.ec
.getMemoryService().readMemory32(self
.base
+ 0x4)
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 debug_info
= self
.ec
.getMemoryService().readMemory32(debug_info_table_base
+ (i
* 4))
37 debug_info_type
= self
.ec
.getMemoryService().readMemory32(debug_info
)
38 # Normal Debug Info Type
39 if debug_info_type
== 1:
40 # Get the base address of the structure EFI_LOADED_IMAGE_PROTOCOL
41 loaded_image_protocol
= self
.ec
.getMemoryService().readMemory32(debug_info
+ 0x4)
43 image_base
= self
.ec
.getMemoryService().readMemory32(loaded_image_protocol
+ 0x20)
44 image_size
= self
.ec
.getMemoryService().readMemory32(loaded_image_protocol
+ 0x28)
46 self
.DebugInfos
.append((image_base
,image_size
))
49 def load_symbols_at(self
, addr
):
50 if self
.DebugInfos
== []:
54 for debug_info
in self
.DebugInfos
:
55 if (addr
>= debug_info
[0]) and (addr
< debug_info
[0] + debug_info
[1]):
56 section
= firmware_volume
.EfiSectionPE32(self
.ec
, debug_info
[0])
58 edk2_debugger
.load_symbol_from_file(self
.ec
, section
.get_debug_filepath(), section
.get_debug_elfbase())
64 raise Exception('DebugInfoTable','No symbol found at 0x%x' % addr
)
66 def load_all_symbols(self
):
67 if self
.DebugInfos
== []:
70 for debug_info
in self
.DebugInfos
:
71 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())
77 for debug_info
in self
.DebugInfos
:
78 base_pe32
= debug_info
[0]
79 section
= firmware_volume
.EfiSectionPE32(self
.ec
, base_pe32
)
80 print section
.get_debug_filepath()
83 CONST_ST_SIGNATURE
= ('I','B','I',' ','S','Y','S','T')
85 def __init__(self
, ec
, membase
, memsize
):
86 self
.membase
= membase
87 self
.memsize
= memsize
92 # Start from the top of the memory
93 offset
= self
.membase
+ self
.memsize
94 # Align to highest 4MB boundary
95 offset
= offset
& ~
0x3FFFFF
96 # We should not have a System Table at the top of the System Memory
97 offset
= offset
- 0x400000
99 # Start at top and look on 4MB boundaries for system table ptr structure
100 while offset
> self
.membase
:
102 signature
= struct
.unpack("cccccccc", self
.ec
.getMemoryService().read(str(offset
), 8, 32))
103 except DebugException
:
104 raise Exception('SystemTable','Fail to access System Memory. Ensure all the memory in the region [0x%x;0x%X] is accessible.' % (membase
,membase
+memsize
))
105 if signature
== SystemTable
.CONST_ST_SIGNATURE
:
107 self
.system_table_base
= self
.ec
.getMemoryService().readMemory32(offset
+ 0x8)
109 offset
= offset
- 0x400000
112 raise Exception('SystemTable','System Table not found in System Memory [0x%x;0x%X]' % (membase
,membase
+memsize
))
114 def get_configuration_table(self
, conf_table_guid
):
115 # Number of configuration Table entry
116 conf_table_entry_count
= self
.ec
.getMemoryService().readMemory32(self
.system_table_base
+ 0x40)
118 # Get location of the Configuration Table entries
119 conf_table_offset
= self
.ec
.getMemoryService().readMemory32(self
.system_table_base
+ 0x44)
121 for i
in range(0, conf_table_entry_count
):
122 offset
= conf_table_offset
+ (i
* 0x14)
123 guid
= struct
.unpack("<IIII", self
.ec
.getMemoryService().read(str(offset
), 16, 32))
124 if guid
== conf_table_guid
:
125 return self
.ec
.getMemoryService().readMemory32(offset
+ 0x10)
127 raise Exception('SystemTable','Configuration Table not found')