Skip to content

Commit 96749b0

Browse files
authored
Merge branch 'qilingframework:dev' into dev
2 parents dd20546 + 2e782b1 commit 96749b0

28 files changed

+1988
-34
lines changed

qiling/hw/char/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
44
#
55

6-
from .stm32f4xx_usart import STM32F4xxUsart
6+
from .stm32f4xx_usart import STM32F4xxUsart
7+
from .gd32vf1xx_usart import GD32VF1xxUsart

qiling/hw/char/gd32vf1xx_usart.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import ctypes
2+
3+
from qiling.hw.connectivity import QlConnectivityPeripheral
4+
5+
6+
class GD32VF1xxUsart(QlConnectivityPeripheral):
7+
class Type(ctypes.Structure):
8+
""" Universal synchronous asynchronous receiver
9+
transmitter
10+
"""
11+
12+
_fields_ = [
13+
("STAT", ctypes.c_uint32), # Address offset: 0x00, Status register
14+
("DATA", ctypes.c_uint32), # Address offset: 0x04, Data register
15+
("BAUD", ctypes.c_uint32), # Address offset: 0x08, Baud rate register
16+
("CTL0", ctypes.c_uint32), # Address offset: 0x0C, Control register 0
17+
("CTL1", ctypes.c_uint32), # Address offset: 0x10, Control register 1
18+
("CTL2", ctypes.c_uint32), # Address offset: 0x14, Control register 2
19+
("GP" , ctypes.c_uint32), # Address offset: 0x18, Guard time and prescaler register
20+
]
21+
22+
def __init__(self, ql, label):
23+
super().__init__(ql, label)
24+
25+
self.usart = self.struct(
26+
STAT = 0x000000c0,
27+
DATA = 0x00000000,
28+
BAUD = 0x00000000,
29+
CTL0 = 0x00000000,
30+
CTL1 = 0x00000000,
31+
CTL2 = 0x00000000,
32+
GP = 0x00000000,
33+
)
34+
35+
@QlConnectivityPeripheral.device_handler
36+
def step(self):
37+
pass
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
from enum import IntEnum
2+
3+
4+
class INTF(IntEnum):
5+
GIF0 = 0x1 << 0 # Global interrupt flag of channel 0
6+
FTFIF0 = 0x1 << 1 # Full Transfer finish flag of channe 0
7+
HTFIF0 = 0x1 << 2 # Half transfer finish flag of channel 0
8+
ERRIF0 = 0x1 << 3 # Error flag of channel 0
9+
GIF1 = 0x1 << 4 # Global interrupt flag of channel 1
10+
FTFIF1 = 0x1 << 5 # Full Transfer finish flag of channe 1
11+
HTFIF1 = 0x1 << 6 # Half transfer finish flag of channel 1
12+
ERRIF1 = 0x1 << 7 # Error flag of channel 1
13+
GIF2 = 0x1 << 8 # Global interrupt flag of channel 2
14+
FTFIF2 = 0x1 << 9 # Full Transfer finish flag of channe 2
15+
HTFIF2 = 0x1 << 10 # Half transfer finish flag of channel 2
16+
ERRIF2 = 0x1 << 11 # Error flag of channel 2
17+
GIF3 = 0x1 << 12 # Global interrupt flag of channel 3
18+
FTFIF3 = 0x1 << 13 # Full Transfer finish flag of channe 3
19+
HTFIF3 = 0x1 << 14 # Half transfer finish flag of channel 3
20+
ERRIF3 = 0x1 << 15 # Error flag of channel 3
21+
GIF4 = 0x1 << 16 # Global interrupt flag of channel 4
22+
FTFIF4 = 0x1 << 17 # Full Transfer finish flag of channe 4
23+
HTFIF4 = 0x1 << 18 # Half transfer finish flag of channel 4
24+
ERRIF4 = 0x1 << 19 # Error flag of channel 4
25+
GIF5 = 0x1 << 20 # Global interrupt flag of channel 5
26+
FTFIF5 = 0x1 << 21 # Full Transfer finish flag of channe 5
27+
HTFIF5 = 0x1 << 22 # Half transfer finish flag of channel 5
28+
ERRIF5 = 0x1 << 23 # Error flag of channel 5
29+
GIF6 = 0x1 << 24 # Global interrupt flag of channel 6
30+
FTFIF6 = 0x1 << 25 # Full Transfer finish flag of channe 6
31+
HTFIF6 = 0x1 << 26 # Half transfer finish flag of channel 6
32+
ERRIF6 = 0x1 << 27 # Error flag of channel 6
33+
34+
class INTC(IntEnum):
35+
GIFC0 = 0x1 << 0 # Clear global interrupt flag of channel 0
36+
FTFIFC0 = 0x1 << 1 # Clear bit for full transfer finish flag of channel 0
37+
HTFIFC0 = 0x1 << 2 # Clear bit for half transfer finish flag of channel 0
38+
ERRIFC0 = 0x1 << 3 # Clear bit for error flag of channel 0
39+
GIFC1 = 0x1 << 4 # Clear global interrupt flag of channel 1
40+
FTFIFC1 = 0x1 << 5 # Clear bit for full transfer finish flag of channel 1
41+
HTFIFC1 = 0x1 << 6 # Clear bit for half transfer finish flag of channel 1
42+
ERRIFC1 = 0x1 << 7 # Clear bit for error flag of channel 1
43+
GIFC2 = 0x1 << 8 # Clear global interrupt flag of channel 2
44+
FTFIFC2 = 0x1 << 9 # Clear bit for full transfer finish flag of channel 2
45+
HTFIFC2 = 0x1 << 10 # Clear bit for half transfer finish flag of channel 2
46+
ERRIFC2 = 0x1 << 11 # Clear bit for error flag of channel 2
47+
GIFC3 = 0x1 << 12 # Clear global interrupt flag of channel 3
48+
FTFIFC3 = 0x1 << 13 # Clear bit for full transfer finish flag of channel 3
49+
HTFIFC3 = 0x1 << 14 # Clear bit for half transfer finish flag of channel 3
50+
ERRIFC3 = 0x1 << 15 # Clear bit for error flag of channel 3
51+
GIFC4 = 0x1 << 16 # Clear global interrupt flag of channel 4
52+
FTFIFC4 = 0x1 << 17 # Clear bit for full transfer finish flag of channel 4
53+
HTFIFC4 = 0x1 << 18 # Clear bit for half transfer finish flag of channel 4
54+
ERRIFC4 = 0x1 << 19 # Clear bit for error flag of channel 4
55+
GIFC5 = 0x1 << 20 # Clear global interrupt flag of channel 5
56+
FTFIFC5 = 0x1 << 21 # Clear bit for full transfer finish flag of channel 5
57+
HTFIFC5 = 0x1 << 22 # Clear bit for half transfer finish flag of channel 5
58+
ERRIFC5 = 0x1 << 23 # Clear bit for error flag of channel 5
59+
GIFC6 = 0x1 << 24 # Clear global interrupt flag of channel 6
60+
FTFIFC6 = 0x1 << 25 # Clear bit for full transfer finish flag of channel 6
61+
HTFIFC6 = 0x1 << 26 # Clear bit for half transfer finish flag of channel 6
62+
ERRIFC6 = 0x1 << 27 # Clear bit for error flag of channel 6
63+
64+
class CH0CTL(IntEnum):
65+
CHEN = 0x1 << 0 # Channel enable
66+
FTFIE = 0x1 << 1 # Enable bit for channel full transfer finish interrupt
67+
HTFIE = 0x1 << 2 # Enable bit for channel half transfer finish interrupt
68+
ERRIE = 0x1 << 3 # Enable bit for channel error interrupt
69+
DIR = 0x1 << 4 # Transfer direction
70+
CMEN = 0x1 << 5 # Circular mode enable
71+
PNAGA = 0x1 << 6 # Next address generation algorithm of peripheral
72+
MNAGA = 0x1 << 7 # Next address generation algorithm of memory
73+
PWIDTH = 0x3 << 8 # Transfer data size of peripheral
74+
MWIDTH = 0x3 << 10 # Transfer data size of memory
75+
PRIO = 0x3 << 12 # Priority level
76+
M2M = 0x1 << 14 # Memory to Memory Mode
77+
78+
class CH0CNT(IntEnum):
79+
CNT = 0xffff << 0 # Transfer counter
80+
81+
class CH0PADDR(IntEnum):
82+
PADDR = 0xffffffff << 0 # Peripheral base address
83+
84+
class CH0MADDR(IntEnum):
85+
MADDR = 0xffffffff << 0 # Memory base address
86+
87+
class CH1CTL(IntEnum):
88+
CHEN = 0x1 << 0 # Channel enable
89+
FTFIE = 0x1 << 1 # Enable bit for channel full transfer finish interrupt
90+
HTFIE = 0x1 << 2 # Enable bit for channel half transfer finish interrupt
91+
ERRIE = 0x1 << 3 # Enable bit for channel error interrupt
92+
DIR = 0x1 << 4 # Transfer direction
93+
CMEN = 0x1 << 5 # Circular mode enable
94+
PNAGA = 0x1 << 6 # Next address generation algorithm of peripheral
95+
MNAGA = 0x1 << 7 # Next address generation algorithm of memory
96+
PWIDTH = 0x3 << 8 # Transfer data size of peripheral
97+
MWIDTH = 0x3 << 10 # Transfer data size of memory
98+
PRIO = 0x3 << 12 # Priority level
99+
M2M = 0x1 << 14 # Memory to Memory Mode
100+
101+
class CH1CNT(IntEnum):
102+
CNT = 0xffff << 0 # Transfer counter
103+
104+
class CH1PADDR(IntEnum):
105+
PADDR = 0xffffffff << 0 # Peripheral base address
106+
107+
class CH1MADDR(IntEnum):
108+
MADDR = 0xffffffff << 0 # Memory base address
109+
110+
class CH2CTL(IntEnum):
111+
CHEN = 0x1 << 0 # Channel enable
112+
FTFIE = 0x1 << 1 # Enable bit for channel full transfer finish interrupt
113+
HTFIE = 0x1 << 2 # Enable bit for channel half transfer finish interrupt
114+
ERRIE = 0x1 << 3 # Enable bit for channel error interrupt
115+
DIR = 0x1 << 4 # Transfer direction
116+
CMEN = 0x1 << 5 # Circular mode enable
117+
PNAGA = 0x1 << 6 # Next address generation algorithm of peripheral
118+
MNAGA = 0x1 << 7 # Next address generation algorithm of memory
119+
PWIDTH = 0x3 << 8 # Transfer data size of peripheral
120+
MWIDTH = 0x3 << 10 # Transfer data size of memory
121+
PRIO = 0x3 << 12 # Priority level
122+
M2M = 0x1 << 14 # Memory to Memory Mode
123+
124+
class CH2CNT(IntEnum):
125+
CNT = 0xffff << 0 # Transfer counter
126+
127+
class CH2PADDR(IntEnum):
128+
PADDR = 0xffffffff << 0 # Peripheral base address
129+
130+
class CH2MADDR(IntEnum):
131+
MADDR = 0xffffffff << 0 # Memory base address
132+
133+
class CH3CTL(IntEnum):
134+
CHEN = 0x1 << 0 # Channel enable
135+
FTFIE = 0x1 << 1 # Enable bit for channel full transfer finish interrupt
136+
HTFIE = 0x1 << 2 # Enable bit for channel half transfer finish interrupt
137+
ERRIE = 0x1 << 3 # Enable bit for channel error interrupt
138+
DIR = 0x1 << 4 # Transfer direction
139+
CMEN = 0x1 << 5 # Circular mode enable
140+
PNAGA = 0x1 << 6 # Next address generation algorithm of peripheral
141+
MNAGA = 0x1 << 7 # Next address generation algorithm of memory
142+
PWIDTH = 0x3 << 8 # Transfer data size of peripheral
143+
MWIDTH = 0x3 << 10 # Transfer data size of memory
144+
PRIO = 0x3 << 12 # Priority level
145+
M2M = 0x1 << 14 # Memory to Memory Mode
146+
147+
class CH3CNT(IntEnum):
148+
CNT = 0xffff << 0 # Transfer counter
149+
150+
class CH3PADDR(IntEnum):
151+
PADDR = 0xffffffff << 0 # Peripheral base address
152+
153+
class CH3MADDR(IntEnum):
154+
MADDR = 0xffffffff << 0 # Memory base address
155+
156+
class CH4CTL(IntEnum):
157+
CHEN = 0x1 << 0 # Channel enable
158+
FTFIE = 0x1 << 1 # Enable bit for channel full transfer finish interrupt
159+
HTFIE = 0x1 << 2 # Enable bit for channel half transfer finish interrupt
160+
ERRIE = 0x1 << 3 # Enable bit for channel error interrupt
161+
DIR = 0x1 << 4 # Transfer direction
162+
CMEN = 0x1 << 5 # Circular mode enable
163+
PNAGA = 0x1 << 6 # Next address generation algorithm of peripheral
164+
MNAGA = 0x1 << 7 # Next address generation algorithm of memory
165+
PWIDTH = 0x3 << 8 # Transfer data size of peripheral
166+
MWIDTH = 0x3 << 10 # Transfer data size of memory
167+
PRIO = 0x3 << 12 # Priority level
168+
M2M = 0x1 << 14 # Memory to Memory Mode
169+
170+
class CH4CNT(IntEnum):
171+
CNT = 0xffff << 0 # Transfer counter
172+
173+
class CH4PADDR(IntEnum):
174+
PADDR = 0xffffffff << 0 # Peripheral base address
175+
176+
class CH4MADDR(IntEnum):
177+
MADDR = 0xffffffff << 0 # Memory base address
178+
179+
class CH5CTL(IntEnum):
180+
CHEN = 0x1 << 0 # Channel enable
181+
FTFIE = 0x1 << 1 # Enable bit for channel full transfer finish interrupt
182+
HTFIE = 0x1 << 2 # Enable bit for channel half transfer finish interrupt
183+
ERRIE = 0x1 << 3 # Enable bit for channel error interrupt
184+
DIR = 0x1 << 4 # Transfer direction
185+
CMEN = 0x1 << 5 # Circular mode enable
186+
PNAGA = 0x1 << 6 # Next address generation algorithm of peripheral
187+
MNAGA = 0x1 << 7 # Next address generation algorithm of memory
188+
PWIDTH = 0x3 << 8 # Transfer data size of peripheral
189+
MWIDTH = 0x3 << 10 # Transfer data size of memory
190+
PRIO = 0x3 << 12 # Priority level
191+
M2M = 0x1 << 14 # Memory to Memory Mode
192+
193+
class CH5CNT(IntEnum):
194+
CNT = 0xffff << 0 # Transfer counter
195+
196+
class CH5PADDR(IntEnum):
197+
PADDR = 0xffffffff << 0 # Peripheral base address
198+
199+
class CH5MADDR(IntEnum):
200+
MADDR = 0xffffffff << 0 # Memory base address
201+
202+
class CH6CTL(IntEnum):
203+
CHEN = 0x1 << 0 # Channel enable
204+
FTFIE = 0x1 << 1 # Enable bit for channel full transfer finish interrupt
205+
HTFIE = 0x1 << 2 # Enable bit for channel half transfer finish interrupt
206+
ERRIE = 0x1 << 3 # Enable bit for channel error interrupt
207+
DIR = 0x1 << 4 # Transfer direction
208+
CMEN = 0x1 << 5 # Circular mode enable
209+
PNAGA = 0x1 << 6 # Next address generation algorithm of peripheral
210+
MNAGA = 0x1 << 7 # Next address generation algorithm of memory
211+
PWIDTH = 0x3 << 8 # Transfer data size of peripheral
212+
MWIDTH = 0x3 << 10 # Transfer data size of memory
213+
PRIO = 0x3 << 12 # Priority level
214+
M2M = 0x1 << 14 # Memory to Memory Mode
215+
216+
class CH6CNT(IntEnum):
217+
CNT = 0xffff << 0 # Transfer counter
218+
219+
class CH6PADDR(IntEnum):
220+
PADDR = 0xffffffff << 0 # Peripheral base address
221+
222+
class CH6MADDR(IntEnum):
223+
MADDR = 0xffffffff << 0 # Memory base address
224+
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
from enum import IntEnum
2+
3+
4+
class CTL0(IntEnum):
5+
SRESET = 0x1 << 15 # Software reset
6+
SALT = 0x1 << 13 # SMBus alert
7+
PECTRANS = 0x1 << 12 # PEC Transfer
8+
POAP = 0x1 << 11 # Position of ACK and PEC when receiving
9+
ACKEN = 0x1 << 10 # Whether or not to send an ACK
10+
STOP = 0x1 << 9 # Generate a STOP condition on I2C bus
11+
START = 0x1 << 8 # Generate a START condition on I2C bus
12+
SS = 0x1 << 7 # Whether to stretch SCL low when data is not ready in slave mode
13+
GCEN = 0x1 << 6 # Whether or not to response to a General Call (0x00)
14+
PECEN = 0x1 << 5 # PEC Calculation Switch
15+
ARPEN = 0x1 << 4 # ARP protocol in SMBus switch
16+
SMBSEL = 0x1 << 3 # SMBusType Selection
17+
SMBEN = 0x1 << 1 # SMBus/I2C mode switch
18+
I2CEN = 0x1 << 0 # I2C peripheral enable
19+
20+
class CTL1(IntEnum):
21+
DMALST = 0x1 << 12 # Flag indicating DMA last transfer
22+
DMAON = 0x1 << 11 # DMA mode switch
23+
BUFIE = 0x1 << 10 # Buffer interrupt enable
24+
EVIE = 0x1 << 9 # Event interrupt enable
25+
ERRIE = 0x1 << 8 # Error interrupt enable
26+
I2CCLK = 0x3f << 0 # I2C Peripheral clock frequency
27+
28+
class SADDR0(IntEnum):
29+
ADDFORMAT = 0x1 << 15 # Address mode for the I2C slave
30+
ADDRESS9_8 = 0x3 << 8 # Highest two bits of a 10-bit address
31+
ADDRESS7_1 = 0x7f << 1 # 7-bit address or bits 7:1 of a 10-bit address
32+
ADDRESS0 = 0x1 << 0 # Bit 0 of a 10-bit address
33+
34+
class SADDR1(IntEnum):
35+
ADDRESS2 = 0x7f << 1 # Second I2C address for the slave in Dual-Address mode
36+
DUADEN = 0x1 << 0 # Dual-Address mode switch
37+
38+
class DATA(IntEnum):
39+
TRB = 0xff << 0 # Transmission or reception data buffer register
40+
41+
class STAT0(IntEnum):
42+
SMBALT = 0x1 << 15 # SMBus Alert status
43+
SMBTO = 0x1 << 14 # Timeout signal in SMBus mode
44+
PECERR = 0x1 << 12 # PEC error when receiving data
45+
OUERR = 0x1 << 11 # Over-run or under-run situation occurs in slave mode
46+
AERR = 0x1 << 10 # Acknowledge error
47+
LOSTARB = 0x1 << 9 # Arbitration Lost in master mode
48+
BERR = 0x1 << 8 # A bus error occurs indication a unexpected START or STOP condition on I2C bus
49+
TBE = 0x1 << 7 # I2C_DATA is Empty during transmitting
50+
RBNE = 0x1 << 6 # I2C_DATA is not Empty during receiving
51+
STPDET = 0x1 << 4 # STOP condition detected in slave mode
52+
ADD10SEND = 0x1 << 3 # Header of 10-bit address is sent in master mode
53+
BTC = 0x1 << 2 # Byte transmission completed
54+
ADDSEND = 0x1 << 1 # Address is sent in master mode or received and matches in slave mode
55+
SBSEND = 0x1 << 0 # START condition sent out in master mode
56+
57+
class STAT1(IntEnum):
58+
PECV = 0xff << 8 # Packet Error Checking Value that calculated by hardware when PEC is enabled
59+
DUMODF = 0x1 << 7 # Dual Flag in slave mode
60+
HSTSMB = 0x1 << 6 # SMBus Host Header detected in slave mode
61+
DEFSMB = 0x1 << 5 # Default address of SMBusDevice
62+
RXGC = 0x1 << 4 # General call address (00h) received
63+
TR = 0x1 << 2 # Whether the I2C is a transmitter or a receiver
64+
I2CBSY = 0x1 << 1 # Busy flag
65+
MASTER = 0x1 << 0 # A flag indicating whether I2C block is in master or slave mode
66+
67+
class CKCFG(IntEnum):
68+
FAST = 0x1 << 15 # I2C speed selection in master mode
69+
DTCY = 0x1 << 14 # Duty cycle in fast mode
70+
CLKC = 0xfff << 0 # I2C Clock control in master mode
71+
72+
class RT(IntEnum):
73+
RISETIME = 0x3f << 0 # Maximum rise time in master mode
74+

0 commit comments

Comments
 (0)