@@ -85,6 +85,7 @@ def step(self):
8585 self .ql .hw .step ()
8686
8787 def stop (self ):
88+ self .ql .emu_stop ()
8889 self .runable = False
8990
9091 def run (self , count = - 1 , end = None ):
@@ -112,13 +113,34 @@ def init_context(self):
112113 self .ql .reg .write ('pc' , self .ql .mem .read_ptr (0x4 ))
113114
114115 def soft_interrupt_handler (self , ql , intno ):
115- if intno == EXCP .SWI :
116- ql .hw .nvic .set_pending (IRQ .SVCALL )
117-
118- elif intno == EXCP .EXCEPTION_EXIT :
119- ql .emu_stop ()
120-
121- else :
116+ forward_mapper = {
117+ EXCP .UDEF : IRQ .HARD_FAULT , # undefined instruction
118+ EXCP .SWI : IRQ .SVCALL , # software interrupt
119+ EXCP .PREFETCH_ABORT : IRQ .HARD_FAULT ,
120+ EXCP .DATA_ABORT : IRQ .HARD_FAULT ,
121+ EXCP .EXCEPTION_EXIT : IRQ .NOTHING ,
122+ # EXCP.KERNEL_TRAP : IRQ.NOTHING,
123+ # EXCP.HVC : IRQ.NOTHING,
124+ # EXCP.HYP_TRAP : IRQ.NOTHING,
125+ # EXCP.SMC : IRQ.NOTHING,
126+ # EXCP.VIRQ : IRQ.NOTHING,
127+ # EXCP.VFIQ : IRQ.NOTHING,
128+ # EXCP.SEMIHOST : IRQ.NOTHING,
129+ EXCP .NOCP : IRQ .USAGE_FAULT , # v7M NOCP UsageFault
130+ EXCP .INVSTATE : IRQ .USAGE_FAULT , # v7M INVSTATE UsageFault
131+ EXCP .STKOF : IRQ .USAGE_FAULT , # v8M STKOF UsageFault
132+ # EXCP.LAZYFP : IRQ.NOTHING,
133+ # EXCP.LSERR : IRQ.NOTHING,
134+ EXCP .UNALIGNED : IRQ .USAGE_FAULT , # v7M UNALIGNED UsageFault
135+ }
136+
137+ ql .emu_stop ()
138+
139+ try :
140+ handle = forward_mapper .get (intno )
141+ if handle != IRQ .NOTHING :
142+ ql .hw .nvic .set_pending (handle )
143+ except IndexError :
122144 raise QlErrorNotImplemented (f'Unhandled interrupt number ({ intno } )' )
123145
124146 def hard_interrupt_handler (self , ql , intno ):
0 commit comments