Date : Sat, 17 Jun 1989 06:13:38 GMT
From : tiamat!quintro!bpdsun1!dwg@uunet.uu.net (David W. Glessner)
Subject: Z80 initialization and NMI usage ?
I'm having some trouble with NMI (non-maskable interrupt) occuring during
the initialization code on a Z80 embedded system.
The Z80's NMI input is connected to an early warning powerfail output
on the power supply.
The problem code is:
0000 DI
0001 JR init
..
0066 RETN ; ignore NMI
0068 init: LD HL,(stack)
006B LD SP,HL
..
An NMI intermittently occurs before the stack pointer has been initialized.
The PC seems to be stacked to locations FFFE and FFFD. When the RETN
instruction executes, an invalid return address (e.g. 4545) is popped
because no memory exists for addresses FFFD and FFFE. This is causing
"very bad" things to happen :-(
SP obviously needs to be set up before NMIs can occur.
I think the following version fixes the problem:
0000 DI
0001 LD SP,(stack)
0005 JR init
Zilog's "Z80 Product Specification" indicates that interrupts are not
sampled at the end of EI or DI.
Does this apply to INT and NMI or just INT?
After CPU reset, normal interrupts (i.e. INT) are disabled, so the
initial DI isn't strictly necessary. I would like any RST 0 instructions
(e.g. SW somehow sees a C7 opcode) to DI as soon as possible.
Please Email responses and I'll post a summary.
Thanks,
David W. Glessner Harris Corp - Broadcast Div - Quincy, IL
<whatever>NET: quintro!bpdsun1!dwg@lll-winken[.llnl.gov]
tiamat!quintro!bpdsun1!dwg@uunet
End of INFO-CPM Digest V89 Issue #140
*************************************