Skip to content

Commit a7ad66f

Browse files
Merge pull request #977 from cla7aye15I4nd/dev
Avoid scanning the entire syscall table
2 parents 5da9098 + fc947cd commit a7ad66f

File tree

8 files changed

+1992
-664
lines changed

8 files changed

+1992
-664
lines changed

examples/mcu/LCD1602A.txt

Lines changed: 0 additions & 145 deletions
This file was deleted.

qiling/arch/arm_const.py

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,7 @@
2323
"sp": UC_ARM_REG_SP,
2424
"lr": UC_ARM_REG_LR,
2525
"pc": UC_ARM_REG_PC,
26-
# cortex-M Special Register
27-
"msp": UC_ARM_REG_MSP,
28-
"psp": UC_ARM_REG_PSP,
29-
"xpsr": UC_ARM_REG_XPSR,
30-
"xpsr_nzcvqg": UC_ARM_REG_XPSR_NZCVQG,
31-
"apsr": UC_ARM_REG_APSR,
32-
"ipsr": UC_ARM_REG_IPSR,
33-
"epsr": UC_ARM_REG_EPSR,
34-
"primask": UC_ARM_REG_PRIMASK,
35-
"faultmask": UC_ARM_REG_FAULTMASK,
36-
"basepri": UC_ARM_REG_BASEPRI,
37-
"control": UC_ARM_REG_CONTROL,
26+
3827
# CPSR needs to be at offset 25 for GDB, see https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/arch/arm.h;h=fa589fd0582c0add627a068e6f4947a909c45e86;hb=HEAD#l34
3928
# The fp registers inbetween have become obsolete
4029
"f0": UC_ARM_REG_INVALID,
@@ -51,28 +40,3 @@
5140
"c13_c0_3": UC_ARM_REG_C13_C0_3,
5241
"fpexc": UC_ARM_REG_FPEXC,
5342
}
54-
55-
class IRQ(IntEnum):
56-
NMI = -14
57-
HARD_FAULT = -13
58-
MEMORY_MANAGEMENT_FAULT = -12
59-
BUS_FAULT = -11
60-
USAGE_FAULT = -10
61-
SVCALL = -5
62-
PENDSV = -2
63-
SYSTICK = -1
64-
65-
class CONTROL(IntEnum):
66-
FPCA = 0b100
67-
SPSEL = 0b010
68-
PRIV = 0b001
69-
70-
class EXC_RETURN(IntEnum):
71-
MASK = 0xfffffff0
72-
RETURN_SP = 0b0100
73-
RETURN_MODE = 0b1000
74-
75-
class EXCP(IntEnum):
76-
SWI = 2 # software interrupt
77-
EXCEPTION_EXIT = 8 # Return from v7M exception
78-

qiling/arch/cortex_m.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from qiling.exception import QlErrorNotImplemented
1414

1515
from .arm import QlArchARM
16-
from .arm_const import IRQ, EXC_RETURN, CONTROL, EXCP
16+
from .cortex_m_const import IRQ, EXC_RETURN, CONTROL, EXCP, reg_map
1717

1818
class QlInterruptContext(ContextDecorator):
1919
def __init__(self, ql):
@@ -61,6 +61,13 @@ class QlArchCORTEX_M(QlArchARM):
6161
def __init__(self, ql):
6262
super().__init__(ql)
6363

64+
reg_maps = (
65+
reg_map,
66+
)
67+
68+
for reg_maper in reg_maps:
69+
self.ql.reg.expand_mapping(reg_maper)
70+
6471
def intr_cb(ql, intno):
6572
if intno == EXCP.SWI:
6673
ql.hw.nvic.set_pending(IRQ.SVCALL)

qiling/arch/cortex_m_const.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
4+
#
5+
6+
from unicorn.arm_const import *
7+
from enum import IntEnum
8+
9+
reg_map = {
10+
"r0": UC_ARM_REG_R0,
11+
"r1": UC_ARM_REG_R1,
12+
"r2": UC_ARM_REG_R2,
13+
"r3": UC_ARM_REG_R3,
14+
"r4": UC_ARM_REG_R4,
15+
"r5": UC_ARM_REG_R5,
16+
"r6": UC_ARM_REG_R6,
17+
"r7": UC_ARM_REG_R7,
18+
"r8": UC_ARM_REG_R8,
19+
"r9": UC_ARM_REG_R9,
20+
"r10": UC_ARM_REG_R10,
21+
"r11": UC_ARM_REG_R11,
22+
"r12": UC_ARM_REG_R12,
23+
"sp": UC_ARM_REG_SP,
24+
"lr": UC_ARM_REG_LR,
25+
"pc": UC_ARM_REG_PC,
26+
27+
# cortex-M Special Register
28+
"msp": UC_ARM_REG_MSP,
29+
"psp": UC_ARM_REG_PSP,
30+
"xpsr": UC_ARM_REG_XPSR,
31+
"apsr": UC_ARM_REG_APSR,
32+
"ipsr": UC_ARM_REG_IPSR,
33+
"epsr": UC_ARM_REG_EPSR,
34+
"primask": UC_ARM_REG_PRIMASK,
35+
"faultmask": UC_ARM_REG_FAULTMASK,
36+
"basepri": UC_ARM_REG_BASEPRI,
37+
"control": UC_ARM_REG_CONTROL,
38+
39+
"xpsr_nzcvqg": UC_ARM_REG_XPSR_NZCVQG,
40+
}
41+
42+
class IRQ(IntEnum):
43+
NMI = -14
44+
HARD_FAULT = -13
45+
MEMORY_MANAGEMENT_FAULT = -12
46+
BUS_FAULT = -11
47+
USAGE_FAULT = -10
48+
SVCALL = -5
49+
PENDSV = -2
50+
SYSTICK = -1
51+
52+
class CONTROL(IntEnum):
53+
FPCA = 0b100
54+
SPSEL = 0b010
55+
PRIV = 0b001
56+
57+
class EXC_RETURN(IntEnum):
58+
MASK = 0xfffffff0
59+
RETURN_SP = 0b0100
60+
RETURN_MODE = 0b1000
61+
62+
class EXCP(IntEnum):
63+
SWI = 2 # software interrupt
64+
EXCEPTION_EXIT = 8 # Return from v7M exception
65+

qiling/hw/intc/cm4_nvic.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import ctypes
77

88
from qiling.hw.peripheral import QlPeripheral
9-
from qiling.arch.arm_const import IRQ
109

1110

1211
class CortexM4Nvic(QlPeripheral):

qiling/hw/misc/cm4_scb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import ctypes
88

99
from qiling.hw.peripheral import QlPeripheral
10-
from qiling.arch.arm_const import IRQ
10+
from qiling.arch.cortex_m_const import IRQ
1111

1212
class CortexM4Scb(QlPeripheral):
1313
class Type(ctypes.Structure):

qiling/hw/timer/cm4_systick.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55

66
import ctypes
7-
from qiling.arch.arm_const import IRQ
7+
from qiling.arch.cortex_m_const import IRQ
88
from qiling.hw.peripheral import QlPeripheral
99
from qiling.hw.const.cm4_systick import SYSTICK_CTRL
1010

0 commit comments

Comments
 (0)