Skip to content

Commit 6184baf

Browse files
committed
Add docstring in qlhwmanager
1 parent 06a5063 commit 6184baf

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

qiling/hw/hw.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,25 @@
55

66
import ctypes
77

8+
from qiling.core import Qiling
9+
from qiling.hw.peripheral import QlPeripheral
810
from qiling.utils import ql_get_module_function
911
from qiling.exception import QlErrorModuleFunctionNotFound
1012

1113

1214
class QlHwManager:
13-
def __init__(self, ql):
15+
def __init__(self, ql: Qiling):
1416
self.ql = ql
1517

1618
self.entity = {}
1719
self.region = {}
1820

19-
def create(self, label, cls=None, base=None):
20-
"""You can access the `label` by `ql.hw.label` or `ql.hw['label']`"""
21+
def create(self, label: str, cls: "QlPeripheral"=None, base: int=None) -> "QlPeripheral":
22+
""" Create the peripheral accroding the label and profiles.
2123
24+
cls: Structure of the peripheral. Use defualt ql structure if not provide.
25+
base: Base address. Use defualt address if not provide.
26+
"""
2227
profile_cls, profile_base, kwargs = self.load_profile(label.upper())
2328

2429
cls = profile_cls if cls is None else cls
@@ -34,13 +39,21 @@ def create(self, label, cls=None, base=None):
3439
except QlErrorModuleFunctionNotFound:
3540
self.ql.log.warning(f'The {cls}({label}) has not been implemented')
3641

37-
def delete(self, label):
42+
def delete(self, label: str):
43+
""" Remove the peripheral
44+
"""
3845
if label in self.entity:
3946
self.entity.pop(label)
4047
self.region.pop(label)
4148
delattr(self, label)
4249

43-
def load_profile(self, label):
50+
def load_profile(self, label: str):
51+
""" Get peripheral information (structure, base address, initialization list)from profile.
52+
53+
Args:
54+
label (str): Peripheral Label
55+
56+
"""
4457
section = self.ql.profile[label]
4558

4659
cls = section['class']
@@ -50,16 +63,18 @@ def load_profile(self, label):
5063

5164
return cls, base, kwargs
5265

53-
def find(self, addr, size):
54-
def check_bound(lbound, rbound):
55-
return lbound <= addr and addr + size <= rbound
66+
def find(self, address: int):
67+
""" Find the peripheral at `address`
68+
"""
5669

5770
for label in self.entity.keys():
5871
for lbound, rbound in self.region[label]:
59-
if check_bound(lbound, rbound):
72+
if lbound <= address <= rbound:
6073
return self.entity[label]
6174

6275
def step(self):
76+
""" Update all peripheral's state
77+
"""
6378
for _, entity in self.entity.items():
6479
entity.step()
6580

@@ -100,7 +115,7 @@ def setup_mmio(self, begin, size, info=""):
100115

101116
def mmio_read_cb(ql, offset, size):
102117
address = begin + offset
103-
hardware = self.find(address, size)
118+
hardware = self.find(address)
104119

105120
if hardware:
106121
return hardware.read(address - hardware.base, size)
@@ -113,7 +128,7 @@ def mmio_read_cb(ql, offset, size):
113128

114129
def mmio_write_cb(ql, offset, size, value):
115130
address = begin + offset
116-
hardware = self.find(address, size)
131+
hardware = self.find(address)
117132

118133
if hardware:
119134
hardware.write(address - hardware.base, size, value)

0 commit comments

Comments
 (0)