André's 8-bit Pages  Projects  Code  Resources  Tools  Forum
(by Google)

65002 Register Set

This page describes the register set of the 65002.

The register set is very similar to the 6502, with only a few extensions... As there are different options for register widths, "W" describes the width option, i.e. either 16, 32 or 64 bit.

In addition to the core registers there are registers for the memory management.

RegisterName650265kComment
PCProgram Counter16 bitW bit
AAccumulator8 bitW bitOperations can be done in 8, 16, 32, 64 bit (up to W)
XX register8 bitW bitOperations can be done in 8, 16, 32, 64 bit (up to W)
YY register8 bitW bitOperations can be done in 8, 16, 32, 64 bit (up to W)
EEffective Address Register-W bitStores effective address for opcodes
BBase Offset Register-W bitAddress offset for addressing modes
S(U)User mode Stack pointer-W bit
S(H)Hypervisor mode Stack pointer8 bit, with high byte set to 1W bit
SRStatus Register8 bit, with bit 5 set to 18 bitSame as 6502, bit5 set to 0, high 8 bit see below
ESRExtended Status Register-8 bitSee below

The A, X and Y registers are similar to the 6502 registers, only that they are at least 16  bit wide.

The status register is divided into two bytes, the status and the extended status. The first mirrors the original 6502 status byte:

bit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0
1286432168421
NV0BDIZC

Explanation of the status bits:

BitNameExplanation
NNegativeSet when operation results in a negative value (bit 7 set)
VOverflowSet when arithmetic operation or compare results in an overflow value
BBreakSet when a BRK opcode has been executed, is only written to the stack
DDecimalDecimal flag
IInterruptSet to disable interrupts (deprecated)
ZZeroSet when operation results in a zero value
CCarryCarry for arithmetic operations and compares

The second byte is an extended status byte. It is written on the stack frame on TRAP (user and hypervisor mode) and interrupts in hypervisor mode. It can also be written with a word-wide PHP and restored with a word-wide PLP. However, only the G and OE flags are written and restored, the others are written and read as zero on PHP.w/PLP

bit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0
1286432168421
GOE00H0SF1SF0

Note that the value read from the stack on RTI and RTU opcodes is fully executed only when read from the supervisor stack. If the hypervisor mode bit H is set when reading from user stack, a privilege violation abort (PRIVRTI) is executed. If H is not set, the stack frame size bits SF are evaluated and the return address is read from the stack with a size according to SF.

BitNameExplanationState on Reset
HHypervisor modeSet when the processor is in hypervisor mode1
SF1/SF0Stack Frame SizeDetermines the stack frame size for a TRAP or an interrupt (01=2 byte, 10=4 byte, 11=8 byte return address. 00 is the native size of the processor) 01
GSigned greater or equalSet when the processor does an SBC or CMP, and detects that the result of the comparison is greater or equal. This should always be (N xor V) after SBC, but CMP does not set V, so there it is different, and enables signed compares.0
OEOddOdd/Even flag. Set at the same time the Z-flag is set, directly from bit 0 of the value.0
Interrupt Management Registers
RegisterName650265kComment
IMRInterrupt Level Mask Register-8 bitInterrupt Mask - define which interrupt levels are accepted
EIMEffective Interrupt Level Mask Register-8 bitTemporary Interrupt Mask. set from the ISR when an interrupt routine is initiated. Reset to IMR on RTI.
ISRInterrupt Level Status Register-8 bitInterrupt line status - number of highest active interrupt line
IVInterrupt base register-W bitBase address for interrupt vectors
TVTrap vector base register-W bitBase address for trap vectors
AVAbort vector base register-W bitBase address for abort vectors
TMVTrap maximum allowed vector number-W bitset the maximum allowed trap vector number + 1 (i.e. zero means none allowed)

The interrupt registers allow to query the current interrupt state and to control interrupt execution. They are not stored on the stack frame.

Registerbit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0
Value1286432168421
IMR00000IMR2IMR1IMR0
EIM00000EIM2EIM1EIM0
ISR00000ISR2ISR1ISR0

Description of the interrupt registers:

BitNameExplanationDefault
IMR2/IMR1/IMR0Interrupt Priority MaskDefines a number from 0 to 3. Each interrupt that has a vector number above the value set here is disabled. Lower or equal interrupt numbers are enabled. I.e. value 0 disables all interrupts but NMI. Value 3 enables all interrupts. 00 (all interrupts but NMI disabled)
ISR2/ISR1/ISR0Interrupt Status RegisterDefines a number from 0 to 3 that determines the current interrupt level, i.e. the highest priority of all current - maskable - active interrupts, even if the interrupt itself is masked. 00 means no interrupt. For example 01 means interrupt 1 is active, but none other, while 10 means interrupt 2 is active, no matter if interrupt 1 is active or not.
EIM2/EIM1/EIM0Temporary Interrupt Priority MaskThis value is set from the interrupt mask register on RTI and CLEIM (both only on hypervisor mode), and set to the interrupt level when the interrupt occurs. An interrupt routine is initiated when EIM has a lower value than ISR - e.g. after an RTI or CLEIM when a lower priority interrupt is pending.

Please note that in the following a higher value means a lower register value and vice versa.

The three interrupt registers work as follows. The supervisor-writable IMR defines which interrupts initiate an interrupt routine. For example if the value is set to 2, interrupts with priority values 0 (NMI), 1 and 2 are enabled. Interrupt with priority 3 and more are disabled.

The ISR presents the "highest" interrupt priority (lowest value(!)) that is currently active. For example if interrupt lines 2, 5, and 7 are active, the ISR presents "2" as current status.

When the ISR has a priority that is higher or equal than the IMR value, an interrupt routine is initiated. To stop the processor from continously starting the interrupt routine, when an interrupt routine is initiated, the EIM is used. It is the effective interrupt mask and normally set to the IMR value. When an interrupt routine is initiated, the EIM is set to the ISR value. Then, as long as the ISR value is equal or larger than EIM, no further (stacked) interrupt routine is initiated. Only when a new interrupt with a higher priority (lower value) appears, the ISR value gets lower than EIM and a stacked interrupt routine is initiated.

EIM is reset to the highest value on RTI or CLEIM when executed in supervisor mode.

The vector base registers allow define the addresses where interrupt, trap and abort vectors are fetched from.

RegisterDescription
IVAddress of interrupt vectors table; lowest 8 bit are reserved and must be 0
TVAddress of trap vectors table; lowest 8 bit are reserved and must be 0
AVAddress of abort vectors table; lowest 8 bit are reserved and must be 0

For details see the Interrupts page.

Mode Control Registers
RegisterName650265kComment
UMMUser Mode Match register-8 bitMatch register for user mode
HMMHypervisor Mode Match register-8 bitMatch register for hypervisor mode
UMCUser Mode Configuration Register-8 bitConfiguring user mode options
UIMUser Mode Interrupt Mask Register-8 bitInterrupt mask effective when SEI is set in user mode.

The match codes - UMM and HMM - are used to identify matching memory management configurations (see below).

The User Mode Configuration register UMC defines a set of control bits for the user mode:

bit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0
1286432168421
---RSS--UMW1UMW0

User Mode Configuration Bits:

BitNameExplanationState on Reset
RSSRestricted Stack Sizewhen set, the user mode stack is restricted to the page $01xxCleared
UMW1/UMW0User Mode Widthdefines the "natural" address width for the user mode. 00=full width, 01=word, 10=long, 11=quad.00 (natural width)

The User Mode Interrupt Mask register UIM defines which interrupts are masked when the interrupt status flag is set in user mode.

Registerbit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0
Value1286432168421
UIM00000UIM2UIM1UIM0

User Mode Interrupt Mask bits:

BitNameExplanationState on Reset
UIM2/UIM1/UIM0User mode interrupt mask registerWhen the interrupt status bit is set in user mode (e.g. with SEI), interrupts can be masked with this setting.Reset to the lowest priority interrupt ("110" - so that this is blocked).

The container management has a number of register sets. Each set contains three full size (W bits) registers:

Container-RegisterDefinitionComment
Addr/matchcode mask0-7: matchcode mask
8-W: address mask
Addr/matchcode compare value0-7: matchcode compare value
8-W: address compare value
Addr offset/container control0-7: Container control
8-W: address offset value

There can be any number of register sets. The number can be read from a configuration register. If there are register sets, there must be at least four sets.

To identify which register set is active, the current match code is ANDed with the matchcode mask, then compared with the matchcode compare value. If the values match, the register set is active.

When a register set is active, the address mask is ANDed with the CPU address, and compared with the address compare value. If the values match, then the CPU address is ANDed with the inverse of the address mask, and ORed with the address offset.

For more details see the Memory Management page.

 

Disclaimer

All Copyrights are acknowledged. The information here is provided under the terms as described in the license section.

Last updated 2012-04-29. Last modified: 2013-11-17
follow

Follow my 8-bit tweets on Mastodon (In new window) or Bluesky

discuss

Discuss my site on this 6502.org forum thread

(Forum registration required to post)

hot!

Dive into the retro feeling and build yourself a Micro-PET or a Multi-board Commodore 4032 replica

Need more speed? Speed up your 6502 computer with this 10 MHz 6502 CPU accelerator board

Interested in electronics design? Look at the design lesson I got from Bil Herd, the hardware designer of the C128

Want 64bit? - pimp the 6502 with the 65k processor design!