@@ -107,7 +107,7 @@ def __init__(self, iface, proxy, utils):
107107 self .wdt_cpu = None
108108 self .smp = True
109109 self .hook_exceptions = False
110- self .started_cpus = set ()
110+ self .started_cpus = {}
111111 self .started = False
112112 self .ctx = None
113113 self .hvcall_handlers = {}
@@ -658,7 +658,6 @@ def handle_msr(self, ctx, iss=None):
658658 MDSCR_EL1 ,
659659 }
660660 ro = {
661- CYC_OVRD_EL1 ,
662661 ACC_CFG_EL1 ,
663662 ACC_OVRD_EL1 ,
664663 }
@@ -673,7 +672,15 @@ def handle_msr(self, ctx, iss=None):
673672 shadow .add (DBGWVRn_EL1 (i ))
674673
675674 value = 0
676- if enc in shadow :
675+ if enc == CYC_OVRD_EL1 and iss .DIR == MSR_DIR .WRITE :
676+ if iss .Rt != 31 :
677+ value = ctx .regs [iss .Rt ]
678+ self .log (f"Skip: msr { name } , x{ iss .Rt } = { value :x} " )
679+ if value & 1 :
680+ self .log ("Guest is shutting down CPU" )
681+ self .p .hv_exit_cpu ()
682+ del self .started_cpus [self .ctx .cpu_id ]
683+ elif enc in shadow :
677684 if iss .DIR == MSR_DIR .READ :
678685 value = self .sysreg [self .ctx .cpu_id ].setdefault (enc , 0 )
679686 self .log (f"Shadow: mrs x{ iss .Rt } , { name } = { value :x} " )
@@ -1503,6 +1510,34 @@ def hook_pmgr_dev(dev):
15031510 self .map_hook (addr , 4 , read = lambda base , off , width : pg_overrides [base + off ])
15041511 self .add_tracer (irange (addr , 4 ), "PMGR HACK" , TraceMode .RESERVED )
15051512
1513+ cpu_hack = [
1514+ # 0x210e20020,
1515+ # 0x211e20020,
1516+ # 0x212e20020,
1517+ ]
1518+
1519+ def wh (base , off , data , width ):
1520+ if isinstance (data , list ):
1521+ data = data [0 ]
1522+ self .log (f"CPU W { base :x} +{ off :x} :{ width } = 0x{ data :x} : Dangerous write" )
1523+
1524+ for addr in cpu_hack :
1525+ self .map_hook (addr , 8 , write = wh )
1526+ self .add_tracer (irange (addr , 8 ), "CPU HACK" , TraceMode .RESERVED )
1527+
1528+ def cpu_state_rh (base , off , width ):
1529+ data = ret = self .p .read64 (base + off )
1530+ die = base // 0x20_0000_0000
1531+ cluster = (base >> 24 ) & 0xf
1532+ cpu = (base >> 20 ) & 0xf
1533+ for i , j in self .started_cpus .items ():
1534+ if j == (die , cluster , cpu ):
1535+ break
1536+ else :
1537+ ret &= ~ 0xff
1538+ self .log (f"CPU STATE R { base :x} +{ off :x} :{ width } = 0x{ data :x} -> 0x{ ret :x} " )
1539+ return ret
1540+
15061541 def cpustart_wh (base , off , data , width ):
15071542 self .log (f"CPUSTART W { base :x} +{ off :x} :{ width } = 0x{ data :x} " )
15081543 if off >= 8 :
@@ -1512,6 +1547,9 @@ def cpustart_wh(base, off, data, width):
15121547 for i in range (32 ):
15131548 if data & (1 << i ):
15141549 self .start_secondary (die , cluster , i )
1550+ cpu_state = 0x210050100 | (die << 27 ) | (cluster << 24 ) | (i << 20 )
1551+ self .map_hook (cpu_state , 8 , read = cpu_state_rh )
1552+ self .add_tracer (irange (addr , 8 ), "CPU STATE HACK" , TraceMode .RESERVED )
15151553
15161554 die_count = self .adt ["/arm-io" ].die_count if hasattr (self .adt ["/arm-io" ], "die-count" ) else 1
15171555
@@ -1546,7 +1584,7 @@ def start_secondary(self, die, cluster, cpu):
15461584 self .log (f" CPU #{ index } : RVBAR = { entry :#x} " )
15471585
15481586 self .sysreg [index ] = {}
1549- self .started_cpus . add ( index )
1587+ self .started_cpus [ index ] = ( die , cluster , cpu )
15501588 self .p .hv_start_secondary (index , entry )
15511589
15521590 def setup_adt (self ):
@@ -1867,7 +1905,7 @@ def start(self):
18671905 # Does not return
18681906
18691907 self .started = True
1870- self .started_cpus . add ( 0 )
1908+ self .started_cpus [ 0 ] = ( 0 , 0 , 0 )
18711909 self .p .hv_start (self .entry , self .guest_base + self .bootargs_off )
18721910
18731911from .. import trace
0 commit comments