6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 12:03 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed May 14, 2014 4:43 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
(First, some context. Then some notes about the reset logic in the NMOS 6502)

In a thread elsewhere about 6502 behaviour, MichaelM exhibited a datasheet showing the differences between the NMOS part and a particular CMOS part, the California Micro Devices G65SC02:
MichaelM wrote:
Jac:

Garth pointed me to this datasheet. In Table V there's a good discussion of the behavioral differences between the NMOS and CMOS 6502s.


That prompted me to make an observation about the reset behaviour:

jac_goudsmit wrote:
BigEd wrote:
Interesting that this device pushes three bytes to the stack at reset. On the one hand, it allows a reset to work as an interrupt (it knows what what happening and can even return) but on the other hand it's making a change. Previously I've opined that it's better not to write. But on reflection, when the stack is always in page one, it's unlikely that anything of interest would be overwritten.


(Going off-topic, that's okay)

The WDC 65C02 also appears to handle a reset as a half-ass interrupt: during three of the six reset cycles, it appears to read from three decrementing(!) addresses in the stack area.

I suspect that handling all three signals (~IRQ, ~NMI and ~RESET) the same way (pushing the flags and PC onto the stack) made sense in the electronics design, but the team at MOS decided to add an extra gate or diode or PLA entry to change the three stack pushes during reset from writes into reads so that no memory would be affected by the reset. And apparently the company that made this 6502 clone decided to leave that gate out.

Indeed, nothing of interest is likely to be overwritten unless you're in a very restricted system (e.g. a system with just a 6532 or 6530 where the zero page and stack are likely mirrored). And one could argue that when the system is reset, it shouldn't assume anything about the state of the RAM, so who cares if it writes something to the stack. But I reckon Chuck and Bill and the guys figured that one extra gate to prevent writes wouldn't change the size of the chip too much, and would save a lot of headaches in cases that they couldn't possibly foresee.

I wonder how hard it would be to find where the stack pushes during reset are changed into reads in Visual6502.org.

===Jac


jbevren wrote:
The 6502 has apparently always handled /RESET as an interrupt with the exception of stack writes not following through. This and some other very low level items were covered by Michael Steil in 27c3. You can see his presentation on youtube (search: [27C3] (en) Reverse Engineering the MOS 6502 CPU, make sure you include (en)). If anyone's remotely interested in how interrupts are processed, or especially why a NMOS 6502 jams up when it executes a $02 (or most $x2) opcodes, watch Stiel's presentation.

Regarding design choices on working with /RESET, that would make some sense as it could save on logic cost.


That YouTube video is probably this one.

I had a look using visual6502 and also the giant schematic (pdf) by Balazs Beregnyei.

It turns out that there's an extra transistor to suppress the writes during reset. The crucial signal is called C1x5 in the schematic, and C1x5Reset in the visual6502. It's produced near lower right of the schematic, or here on the chip:
Attachment:
File comment: This corner of the 6502 - bottom right in Balazs' schematic - derives the internal signals Reset0 and C1x5
reset-and-C1x5.png
reset-and-C1x5.png [ 25.75 KiB | Viewed 1974 times ]


Here's the C1x5 signal in action, the logic is a bit lower left of dead centre of the schematic:
Attachment:
File comment: The RnW logic takes in the C1x5 signal
C1x5disablesRnW.png
C1x5disablesRnW.png [ 25.56 KiB | Viewed 1974 times ]


Here's a 6502 simulation showing the latching of the reset value, which is held until the end of the BRK sequence, and which suppresses the three writes to the stack.
Attachment:
6502-reset-no-writes.png
6502-reset-no-writes.png [ 106.39 KiB | Viewed 1971 times ]


Here's the crucial pull-down transistor t3455 on the chip.

Cheers
Ed


Top
 Profile  
Reply with quote  
PostPosted: Thu May 15, 2014 6:38 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
Thanks, Ed, for the new topic and the detailed post! :)

BigEd wrote:
Interesting that this device pushes three bytes to the stack at reset. On the one hand, it allows a reset to work as an interrupt (it knows what what happening and can even return) but on the other hand it's making a change. Previously I've opined that it's better not to write. But on reflection, when the stack is always in page one, it's unlikely that anything of interest would be overwritten.
Ed, from the sound of things you ultimately decided in favor of "live" writes to stack -- that their value as a feature outweighs the drawbacks. And the idea of three interrupts instead of two is appealing. So what's not to like?

jac_goudsmit wrote:
But I reckon Chuck and Bill and the guys figured that [preventing writes] would save a lot of headaches in cases that they couldn't possibly foresee.
I think Jac touched on the real issue -- headaches, I mean. But perhaps not unforseen headaches. They may well have been scared off just by the prospect of confusing prospective buyers, as perhaps not everyone will accept or feel comfortable with the idea.

I guess if I were in their shoes back then I would've made the same choice. But my preference today, for a 65xx chip I'll be playing with myself, is to let the stack writes proceed so the third interrupt is available if needed.

cheers
Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Thu May 15, 2014 7:46 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
I think the crucial question of safety at reset - the possibility of using reset to initiate a useful post-mortem debug, if not to try to use reset as an extra level of interrupt - depends on the stack not being able to trash anything important. In the early 6502 machines, with only 128 bytes of RAM, stack and zero page overlap completely, and it might not be possible to spare 3 bytes, or to risk an erroneous stack pointer pointing into data memory or even I/O devices. In ordinary 6502 machines, we're probably fine - just sometimes a program or OS will use the lower part of page 1 for something. In post-6502 expanded machines, the stack pointer is more free to point anywhere, and the danger comes back.

But even with that said, we need to balance the benefit of an uncorrupted machine in post-mortem with the ignorance of the value of the PC at the time of the reset... so I still might go with Jeff and the CMD (or WDC??) design team, and allow reset to save state. (Which is a reversal of an earlier position)

Do we know whether or not today's 65C02 from WDC write bytes during reset?

Cheers
Ed


Top
 Profile  
Reply with quote  
PostPosted: Sat May 17, 2014 2:03 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
BigEd wrote:
Do we know whether or not today's 65C02 from WDC write bytes during reset?
The writes to stack are suppressed during reset, according to Table 5-7 of WDC's Sept 2010 edition of the W65C816S datasheet. There's a specific footnote to that effect, so it seems unlikely to be merely one of WDC's all-too-common datasheet typos.

BigEd wrote:
we need to balance the benefit of an uncorrupted machine in post-mortem with the ignorance of the value of the PC at the time of the reset...
One thing clear about the post-mortem is that it would be nice to preserve the pre-reset values of both the PC and whatever's in the 3 bytes @ the stack pointer -- but there isn't any way to have our cake and eat it too.

In favor of the CPU itself not suppressing the writes to stack during reset is the fact that a user could suppress those writes externally if desired. But if the CPU suppresses them, they can't easily be restored with external hardware, and the user loses the opportunity to choose.

-- Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Sat May 17, 2014 4:23 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
I suppose one could add a short tracing FIFO to a design, and at least capture the last PC values before or during Reset.
The address bus will also give away the value of the stack pointer as the 3 dummy pushes happen... but once in the reset routine, any state preservation would overwrite the next few stack slots - unless there was also hardware to suppress those stack writes and place them in an i/o device.
Perhaps simplest would be an alternate page 1 which is automatically banked in at reset... or in the case of an FPGA design, anything you like!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 30 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: