Skip to content

Commit 69d7296

Browse files
committed
v2.9.8
* update to PySide6 (Qt6) * add ole2 format * update structs subpackage to allow chosen pointer sizes * partial update of avr architecture
1 parent 3f062db commit 69d7296

30 files changed

+572
-118
lines changed

README.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ The default Qt stylesheet is inspired by the excellent QDarkStyleSheet_ and
8484
uses most of its icons through the *QResource* API made available
8585
from the generated *rc_icons.py* module::
8686

87-
<pyenv>/lib/python3.<x>/site-packages/PySide2/rcc -g python icons.qrc > rc_icons.py
87+
<pyenv>/lib/python3.<x>/site-packages/PySide6/rcc -g python icons.qrc > rc_icons.py
8888

8989

9090
Licence
@@ -96,6 +96,13 @@ Please see `LICENSE`_.
9696
Changelog
9797
=========
9898

99+
- `v2.9.8`_
100+
101+
* update to PySide6 (Qt6)
102+
* add ole2 format
103+
* update structs subpackage to allow chosen pointer sizes
104+
* partial update of avr architecture
105+
99106
- `v2.9.7`_
100107

101108
* drop python <3.8 support

amoco/arch/avr/asm.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def _pop_(fmap, _l):
2121

2222
def __pc(f):
2323
def pcnpc(i, fmap):
24-
fmap[pc] = fmap[pc] + i.length
24+
fmap[pc] = fmap[pc] + i.length//2
2525
if len(fmap.conds) > 0:
2626
cond = fmap.conds.pop()
2727
m = mapper()
@@ -97,14 +97,17 @@ def i_BREAK(i, fmap):
9797
fmap[pc] = ext("BREAK", size=pc.size).call(fmap)
9898

9999

100+
@__pc
100101
def i_IN(i, fmap):
101102
r, port = i.operands
102-
fmap[pc] = ext("IN", size=pc.size).call(fmap)
103-
103+
port = port.value
104+
fmap[r] = fmap(mmregs.get(port,top(r.size)))
104105

106+
@__pc
105107
def i_OUT(i, fmap):
106108
port, r = i.operands
107-
fmap[pc] = ext("OUT", size=pc.size).call(fmap)
109+
port = port.value
110+
fmap[mmregs[port]] = fmap(r)
108111

109112

110113
# arithmetic & logic instructions:
@@ -513,26 +516,26 @@ def i_LPM(i, fmap):
513516
@__pc
514517
def i_BRBC(i, fmap):
515518
b, offset = i.operands
516-
fmap[pc] = fmap(tst(b == bit0, pc + (2 * offset), pc))
519+
fmap[pc] = fmap(tst(b == bit0, pc + (offset), pc))
517520

518521

519522
@__pc
520523
def i_BRBS(i, fmap):
521524
b, offset = i.operands
522-
fmap[pc] = fmap(tst(b == bit1, pc + (2 * offset), pc))
525+
fmap[pc] = fmap(tst(b == bit1, pc + (offset), pc))
523526

524527

525528
@__pc
526529
def i_CALL(i, fmap):
527530
adr = i.operands[0]
528531
_push_(fmap, fmap(pc))
529-
fmap[pc] = fmap(2 * adr)
532+
fmap[pc] = fmap(adr)
530533

531534

532535
@__pc
533536
def i_JMP(i, fmap):
534537
adr = i.operands[0]
535-
fmap[pc] = fmap(2 * adr)
538+
fmap[pc] = fmap(adr)
536539

537540

538541
@__pc
@@ -550,13 +553,13 @@ def i_RETI(i, fmap):
550553
def i_RCALL(i, fmap):
551554
offset = i.operands[0]
552555
_push_(fmap, fmap(pc))
553-
fmap[pc] = fmap(pc + (2 * offset))
556+
fmap[pc] = fmap(pc + (offset))
554557

555558

556559
@__pc
557560
def i_RJMP(i, fmap):
558561
offset = i.operands[0]
559-
fmap[pc] = fmap(pc + (2 * offset))
562+
fmap[pc] = fmap(pc + (offset))
560563

561564

562565
@__pc

amoco/arch/avr/env.py

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
R[26] = slc(X, 0, 8, "XL")
1818
R[27] = slc(X, 8, 8, "XH")
1919
Y = reg("Y", 16)
20-
R[28] = slc(X, 0, 8, "YL")
21-
R[29] = slc(X, 8, 8, "YH")
20+
R[28] = slc(Y, 0, 8, "YL")
21+
R[29] = slc(Y, 8, 8, "YH")
2222
Z = reg("Z", 16)
23-
R[30] = slc(X, 0, 8, "ZL")
24-
R[31] = slc(X, 8, 8, "ZH")
23+
R[30] = slc(Z, 0, 8, "ZL")
24+
R[31] = slc(Z, 8, 8, "ZH")
2525

2626
with is_reg_flags:
2727
SREG = reg("SREG", 8)
@@ -39,6 +39,8 @@
3939

4040
with is_reg_stack:
4141
sp = reg("SP", 16)
42+
spl = slc(sp,0,8,"SPL")
43+
sph = slc(sp,8,8,"SPH")
4244

4345
RAMPX = reg("RAMPX", 8)
4446
RAMPY = reg("RAMPY", 8)
@@ -47,3 +49,62 @@
4749
EIND = reg("EIND", 8)
4850

4951
registers = R + [sp, pc, SREG]
52+
53+
mmregs = {
54+
0x1e: reg("GPIOR0",8), # General Purpose I/O Register 0
55+
0x1f: reg("EECR",8), # EEPROM control register:[EERE, EEPE, EEMPE, EERIE, EEPM0, EEPM1, -, -]
56+
0x20: reg("EEDR",8), # data readout from the EEPROM @ EEAR
57+
0x21: reg("EEARL",8), # EEPROM address (Low)
58+
0x22: reg("EEARH",8), # EEPROM address (High)
59+
0x2a: reg("GPIOR1",8), # General Purpose I/O Register 1
60+
0x2b: reg("GPIOR2",8), # General Purpose I/O Register 2
61+
0x2c: reg("SPCR",8),
62+
0x2d: reg("SPSR",8),
63+
0x2e: reg("SPDR",8),
64+
0x33: reg("SMCR",8), # Spleep Mode Control Register
65+
0x35: reg("MCUSR",8), # MCU Control Register
66+
0x3d: spl,
67+
0x3e: sph,
68+
0x3f: SREG,
69+
0x61: reg("CLKPR",8), # Clock Prescale
70+
0x64: reg("PRR",8), # Power Reduction
71+
0x66: reg("OSCCAL",8), # Oscillator Calibration
72+
0xc6: reg("UDR0",8),
73+
}
74+
75+
EECR = mmregs[0x1f]
76+
EERE = slc(EECR,0, 1, "EERE") # EEPROM Read Enable
77+
EEPE = slc(EECR,1, 1, "EEPE") # EEPROM Write Enable
78+
EEMPE = slc(EECR,2, 1, "EEMPE") # EEPROM Master Write Enable
79+
EERIE = slc(EECR,3, 1, "EERIE") # enable EEPROM ready interrupt
80+
EEPM0 = slc(EECR,4, 1, "EEPM0") # EEPROM programming mode: 00=EraseWrite 01:EraseOnly
81+
EEPM1 = slc(EECR,5, 1, "EEPM1") # 10=WriteOnly 11:Reserved
82+
83+
vectors = [
84+
ext("RESET",8),
85+
ext("INT0",8),
86+
ext("INT1",8),
87+
ext("PCINT0",8),
88+
ext("PCINT1",8),
89+
ext("PCINT2",8),
90+
ext("WDT",8),
91+
ext("TIMER2_COMPA",8),
92+
ext("TIMER2_COMPB",8),
93+
ext("TIMER2_OVF",8),
94+
ext("TIMER1_CAPT",8),
95+
ext("TIMER1_COMPA",8),
96+
ext("TIMER1_COMPB",8),
97+
ext("TIMER1_OVF",8),
98+
ext("TIMER0_COMPA",8),
99+
ext("TIMER0_COMPB",8),
100+
ext("TIMER0_OVF",8),
101+
ext("SPI_STC",8),
102+
ext("USART_RX",8),
103+
ext("USART_UDRE",8),
104+
ext("USART_TX",8),
105+
ext("ADC",8),
106+
ext("EE_READY",8),
107+
ext("ANALOG_COMP",8),
108+
ext("TWI",8),
109+
ext("SPM_READY",8),
110+
]

amoco/arch/avr/formats.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ def subf(i, L=args):
3131

3232
return subf
3333

34+
def opport(pos):
35+
def port(i, pos=pos):
36+
o = i.operands[pos]
37+
assert o._is_cst
38+
r = mmregs[o.value]
39+
return [(Token.Register,"{0}".format(r))]
40+
return port
3441

3542
def opreg(pos):
3643
def subr(i, pos=pos):
@@ -79,7 +86,7 @@ def subpc(i, pos=pos):
7986
npc = pc
8087
npc += i.length
8188
offset = i.operands[pos]
82-
tgt = npc + 2 * offset
89+
tgt = npc + offset
8390
return [(Token.Address, "*" + str(tgt))]
8491

8592
return subpc
@@ -88,11 +95,23 @@ def subpc(i, pos=pos):
8895
def opadr(pos):
8996
def subabs(i, pos=pos):
9097
tgt = i.operands[pos]
91-
tgt = 2 * tgt
9298
return [(Token.Address, "*" + str(tgt))]
9399

94100
return subabs
95101

102+
def format_io(i):
103+
L = []
104+
for o in i.operands:
105+
if o._is_reg:
106+
tt = Token.Register
107+
r = o
108+
elif o._is_cst:
109+
tt = Token.Memory
110+
r = mmregs.get(o.value,top(8))
111+
L.append((tt,"{0}".format(r)))
112+
L.append((Token.Literal,', '))
113+
L.pop()
114+
return L
96115

97116
def format_mem(i):
98117
s = i.misc["mem"]
@@ -153,6 +172,7 @@ def format_brc(i):
153172
"avr_br": [mnemo, pcrel(0)],
154173
"avr_noops": [mnemo],
155174
"avr_call": [mnemo, opadr(0)],
175+
"avr_io": [mnemo, format_io],
156176
}
157177

158178
AVR_full = Formatter(AVR_full_formats)

amoco/arch/tricore/asm.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,8 @@ def i_CALL(ins,fmap):
836836
_ea = composer([cst(0,6),FCXO,cst(0,6),FCXS])
837837
new_fcx = fmap(mem(_ea,32))
838838
disp=0
839-
for r in (PCXI,PSW,A[10],A[11],D[8],D[9],D[10],D[11],A[12],A[13],A[14],
840-
A[15],D[12],D[13],D[14],D[15]):
841-
fmap[mem(_ea,32,disp=disp)] = r
839+
for r in env.Upper_Context:
840+
fmap[mem(_ea,32,disp=disp)] = fmap(r)
842841
disp += 4
843842
fmap[PCPN] = fmap(CCPN)
844843
fmap[PIE] = fmap(IE)
@@ -857,8 +856,7 @@ def i_RET(ins,fmap):
857856
new_pcxi = fmap(mem(_ea,32))
858857
new_psw = fmap(mem(_ea,32,disp=4))
859858
disp=8
860-
for r in (A[10],A[11],D[8],D[9],D[10],D[11],A[12],A[13],A[14],
861-
A[15],D[12],D[13],D[14],D[15]):
859+
for r in env.Upper_Context[2:]:
862860
fmap[r] = fmap(mem(_ea,32,disp=disp))
863861
disp += 4
864862
fmap[mem(_ea,32)] = fmap(FCX)
@@ -874,8 +872,7 @@ def i_RFE(ins,fmap):
874872
new_pcxi = fmap(mem(_ea,32))
875873
new_psw = fmap(mem(_ea,32,disp=4))
876874
disp=8
877-
for r in (A[10],A[11],D[8],D[9],D[10],D[11],A[12],A[13],A[14],
878-
A[15],D[12],D[13],D[14],D[15]):
875+
for r in env.Upper_Context[2:]:
879876
fmap[r] = fmap(mem(_ea,32,disp=disp))
880877
disp += 4
881878
fmap[mem(_ea,32)] = fmap(FCX)
@@ -891,8 +888,7 @@ def i_CALLI(ins,fmap):
891888
_ea = composer([cst(0,6),FCXO,cst(0,6),FCXS])
892889
new_fcx = fmap(mem(_ea,32))
893890
disp=0
894-
for r in (PCXI,PSW,A[10],A[11],D[8],D[9],D[10],D[11],A[12],A[13],A[14],
895-
A[15],D[12],D[13],D[14],D[15]):
891+
for r in env.Upper_Context:
896892
fmap[mem(_ea,32,disp=disp)] = r
897893
disp += 4
898894
fmap[PCPN] = fmap(CCPN)
@@ -1003,9 +999,8 @@ def i_BISR(ins,fmap):
1003999
_ea = composer([cst(0,6),FCXO,cst(0,6),FCXS])
10041000
new_fcx = fmap(mem(_ea,32))
10051001
disp=0
1006-
for r in (PCXI,ra,A[2],A[3],D[0],D[1],D[2],D[3],A[4],A[5],A[6],
1007-
A[7],D[4],D[5],D[6],D[7]):
1008-
fmap[mem(_ea,32,disp=disp)] = r
1002+
for r in env.Lower_Context:
1003+
fmap[mem(_ea,32,disp=disp)] = fmap(r)
10091004
disp += 4
10101005
fmap[PCPN] = fmap(CCPN)
10111006
fmap[PIE] = fmap(IE)

amoco/arch/tricore/env.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@
4646
# -----------------
4747

4848
ISP = reg("ISP",32) # interrupt stack pointer
49+
SYSCON = reg("SYSCON",32) # system control register
4950

5051
ICR = reg("ICR",32) # interrupt control register
51-
PIPN = slc(ICR,16,8,"ICR.PIPN")
52-
IE = slc(ICR,15,1,"IE")
53-
CCPN = slc(ICR,0,8,"CCPN")
52+
PIPN = slc(ICR,16,8,"ICR.PIPN") # pending interrupt priority number
53+
IE = slc(ICR,15,1,"IE") # global interrupt Enable Bit
54+
CCPN = slc(ICR,0,8,"CCPN") # Current CPU Priority Number
5455

5556
BIV = reg("BIV",32) # base of interrupt vector table register
5657
BTV = reg("BTV",32) # base of trap vector table register
@@ -90,6 +91,12 @@
9091
def get_current_CSA():
9192
return composer([cst(0,6),PCXO,cst(0,6),PCXS])
9293

94+
Lower_Context = (PCXI, ra, A[2], A[3], D[0], D[1], D[2], D[3],
95+
A[4], A[5], A[6], A[7], D[4], D[5], D[6], D[7])
96+
97+
Upper_Context = (PCXI,PSW,A[10],A[11],D[8],D[9],D[10],D[11],A[12],A[13],A[14],
98+
A[15],D[12],D[13],D[14],D[15])
99+
93100
is_reg_pc(pc)
94101
is_reg_flags(PSW)
95102
is_reg_stack(sp)
@@ -99,6 +106,30 @@ def get_current_CSA():
99106
CSFR = {
100107
0xfe00: PCXI,
101108
0xfe04: PSW,
109+
0xfe14: SYSCON,
110+
0xfe20: BIV,
111+
0xfe24: BTV,
112+
0xfe28: ISP,
113+
0xfe2c: ICR,
102114
}
103115

116+
addr = 0xff00
117+
for d in D:
118+
CSFR[addr] = d
119+
addr+=4
120+
121+
addr = 0xff80
122+
for a in A:
123+
CSFR[addr] = d
124+
addr+=4
125+
126+
Traps = [ ("VAF", "VAP"), # Class 0: MMU
127+
("PRIV", "MPR", "MPW", "MPX", "MPP", "MPN", "GRWP"), # Class 1: Internal Protection Traps
128+
("IOPC", "UOPC", "OPD", "ALN", "MEM"), # Class 2: Instruction Errors
129+
("FCD", "CDO", "CDU", "FCU", "CSU", "CTYP", "NEST"), # Class 3: Context Management
130+
("PSE", "DSE", "DAE", "PIE", "DIE", "TAE"), # Class 4: System Bus & Periph.
131+
("OVF", "SOVF"), # Class 5: Assertion Traps
132+
("SYS",), # Class 6: System Call,
133+
("NMI",)] # Class 7: Non-Maskable Interrupt
134+
104135
internals = {"trap": None}

amoco/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ def __str__(self):
307307

308308
conf = Config()
309309

310+
if ll:=os.getenv("AMOCO_LOG_LEVEL"):
311+
conf.Log.level = ll
312+
310313
from amoco.logger import Log as _LogClass #lgtm [py/unsafe-cyclic-import]
311314

312315
logger = _LogClass(__name__)

amoco/sa/ghidra.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import ghidra_bridge
22

3-
b = ghidra_bridge.GhidraBridge(namespace=__module__.__dict__)
3+
b = ghidra_bridge.GhidraBridge(namespace=locals())
44

55
def select_range(begin,end):
6-
setCurrentSelection = ghidra.program.model.address.setCurrentSelection
76
AddressSet = ghidra.program.model.address.AddressSet
87
setCurrentSelection(AddressSet(toAddr(begin),toAddr(end)))
98

@@ -41,6 +40,19 @@ def create_labels(labels):
4140
a = toAddr(a)
4241
sym.createLabel(a, r, USER_DEFINED)
4342

43+
def getFunctions_XRefd_at_Location(address):
44+
if isinstance(address,int):
45+
address = toAddr(address)
46+
loc = ghidra.program.util.ProgramLocation(currentProgram,address)
47+
F = []
48+
for r in ghidra.app.util.XReferenceUtils.getAllXrefs(loc):
49+
f = getFunctionContaining(r.getFromAddress())
50+
if f is None:
51+
print("no function containing reference %s"%r)
52+
continue
53+
F.append(f)
54+
return set(F)
55+
4456
def get_decompiled(func_name):
4557
func = getGlobalFunctions(func_name)[0]
4658
options = ghidra.app.decompiler.DecompileOptions()

0 commit comments

Comments
 (0)