Misplaced Pages

Interrupts in 65xx processors

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.

The 65xx family of microprocessors , consisting of the MOS Technology 6502 and its derivatives, the WDC 65C02 , WDC 65C802 and WDC 65C816 , and CSG 65CE02 , all handle interrupts in a similar fashion. There are three hardware interrupt signals common to all 65xx processors and one software interrupt , the BRK instruction. The WDC 65C816 adds a fourth hardware interrupt— ABORT , useful for implementing virtual memory architectures—and the COP software interrupt instruction (also present in the 65C802), intended for use in a system with a coprocessor of some type (e.g., a floating-point processor ).

#493506

64-459: The hardware interrupt signals are all active low , and are as follows: The detection of a RESET signal causes the processor to enter a system initialization period of six clock cycles, after which it sets the interrupt request disable flag in the status register and loads the program counter with the values stored at the processor initialization vector ( $ 00FFFC – $ 00FFFD ) before commencing execution. If operating in native mode,

128-453: A BRK . This requirement is eliminated when operating the 65C802/65C816 in native mode, due to the separate vectors for the two interrupt types. The 65C816's ABORTB interrupt input is intended to provide the means to redirect program execution when a hardware exception is detected, such as a page fault or a memory access violation . Hence the processor's response when the ABORTB input

192-636: A multi-level cell stores data using multiple voltages. Storing n bits in one cell requires the device to reliably distinguish 2 distinct voltage levels. Digital line codes may use more than two states to encode and transmit data more efficiently. Examples include alternate mark inversion and 4B3T from telecommunications, and pulse-amplitude modulation variants used by Ethernet over twisted pair . For instance, 100BASE-TX uses MLT-3 encoding with three differential voltage levels (−1V, 0V, +1V) while 1000BASE-T encodes data using five differential voltage levels (−1V, −0.5V, 0V, +0.5V, +1V). Once received,

256-410: A "C" in the part number. Throughout the 1980s, both NMOS and CMOS parts were widely used with CMOS becoming more widespread as the decade went along. NMOS was preferred for components that performed active processing such as CPUs or graphics processors due to its higher speed and cheaper manufacturing cost as these were expensive compared to a passive component such as a memory chip, and some chips such as

320-455: A hardware interrupt line and execution of BRK was not accounted for in the design—the BRK instruction will be ignored in such a case. Also, the status of the decimal mode flag in the processor status register is unchanged following an interrupt of any kind. This behavior can potentially result in a difficult to locate bug in the interrupt handler if decimal mode happens to be enabled at

384-402: A line receiver converts from interface levels to internal voltage levels. For example, TTL levels are different from those of CMOS . Generally, a TTL output does not rise high enough to be reliably recognized as a logic 1 by a CMOS input, especially if it is only connected to a high-input-impedance CMOS input that does not source significant current. This problem was solved by the invention of

448-611: A logic design is simplified by inverting the choice of active level (see De Morgan's laws ). The name of an active-low signal is historically written with a bar above it to distinguish it from an active-high signal. For example, the name Q , read Q bar or Q not , represents an active-low signal. The conventions commonly used are: Many control signals in electronics are active-low signals (usually reset lines, chip-select lines and so on). Logic families such as TTL can sink more current than they can source, so fanout and noise immunity increase. It also allows for wired-OR logic if

512-419: A logic-level transition. However, few logic circuits can detect such a condition, and most devices will interpret the signal simply as high or low in an undefined or device-specific manner. Some logic devices incorporate Schmitt trigger inputs, whose behavior is much better defined in the threshold region and have increased resilience to small variations in the input voltage. The problem of the circuit designer

576-404: A resistor, so the whole circuit can be made with n-channel MOSFETs only. NMOS circuits are slow to transition from low to high. When transitioning from high to low, the transistors provide low resistance, and the capacitive charge at the output drains away very quickly (similar to discharging a capacitor through a very low resistor). But the resistance between the output and the positive supply rail

640-477: A single interrupt input. When STP is executed, the MPU halts its internal clock in the high phase, retaining all data in its registers, and enters a low power state. The MPU is brought out of this state by pulling its reset input pin ( RESB , which is classified as an interrupt input) low. Execution will then resume at the address stored at locations $ 00FFFC-$ 00FFFD , the hardware reset vector. As with WAI , STP

704-467: A system's firmware . A typical technique often used during firmware development was to arrange for the BRK vector to point to an unprogrammed "patch area" in the PROM. In the event a bug was discovered, patching would be accomplished by "blowing" all of the fuses at the address where the faulty instruction was located, thus changing the instruction's opcode to $ 00 . Upon executing the resulting BRK ,

SECTION 10

#1733085205494

768-443: A technology first developed by Federico Faggin at Fairchild Semiconductor . These silicon gates are still used in most types of MOSFET based integrated circuits , although metal gates ( Al or Cu ) started to reappear in the early 2000s for certain types of high speed circuits, such as high performance microprocessors. The MOSFETs are n-type enhancement mode transistors, arranged in a so-called "pull-down network" (PDN) between

832-429: A very low resistance between the output and the negative supply, forcing the output to be low (logic 0, = False). When both A and B are high, both transistors are conductive, creating an even lower resistance path to ground. The only case where the output is high is when both transistors are off, which occurs only when both A and B are low, thus satisfying the truth table of a NOR gate: A MOSFET can be made to operate as

896-470: Is zero (or false ), the PDN will be active, meaning that at least one transistor is allowing a current path between the negative supply and the output. This causes a voltage drop over the load, and thus a low voltage at the output, representing the zero. As an example, here is a NOR gate implemented in schematic NMOS. If either input A or input B is high (logic 1, = True), the respective MOS transistor acts as

960-597: Is as a debugging aid in conjunction with a machine language monitor . By overwriting an opcode with BRK ( $ 00 ) and directing the BRK hardware vector to the entry point of the monitor, one can cause a program to halt at any desired point, allowing the monitor to take control. At that time, one may examine memory, view the processor's register values, patch code, etc. Debugging, as advocated by Kuckes and Thompson, can be facilitated by liberally sprinkling one's code with NOP instructions (opcode $ EA ) that can be replaced by BRK instructions without altering

1024-486: Is asserted (negated) is different from when IRQB and/or NMIB are asserted. Also, achieving correct operation in response to ABORTB requires that the interrupt occur at the proper time during the machine cycle , whereas no such requirement exists for IRQB or NMIB . When ABORTB is asserted during a valid memory cycle, that is, when the processor has asserted the VDA and/or VPA status outputs,

1088-450: Is being operated in emulation or native mode at the time of the interrupt. If the latter, it may also be necessary to preserve the data bank ( DB ) and direct (zero) page ( DP ) registers to guarantee transparency. Also, a 65C816 native mode operating system may well use a different stack location than the application software, which means the ISR would have to preserve and subsequently restore

1152-544: Is created by applying voltage to the third terminal, called the gate . Like other MOSFETs, nMOS transistors have four modes of operation: cut-off (or subthreshold), triode, saturation (sometimes called active), and velocity saturation. NMOS AND-by-default logic can produce unusual glitches or buggy behavior in NMOS components, such as the 6502 "illegal opcodes" which are absent in CMOS 6502s. In some cases such as Commodore's VIC-II chip,

1216-484: Is desired as the system is waiting, and/or a quick response is required. A typical example of code that would make use of WAI is as follows: In the above code fragment, the MPU will halt upon execution of WAI and go into a very low power consumption state. Despite interrupt requests (IRQ) having been disabled prior to the WAI instruction, the MPU will respond to any hardware interrupt while waiting. Upon receipt of an IRQ,

1280-451: Is executed, the interrupted program will continue at the address immediately following the signature. If BRK is used as a debugging device, the program counter may have to be adjusted to point to the signature in order for execution to resume where expected. Alternatively, a NOP may be inserted as a signature "placeholder," in which case no program counter adjustment will be required. The fact that BRK and COP double-increment

1344-467: Is intended for use in low-power embedded applications where long periods of time may elapse between events that require MPU attention and no other processing is required. STP would not be used in normal programming, as it would result in total cessation of processing. Logic level#Active state In digital circuits , a logic level is one of a finite number of states that a digital signal can inhabit. Logic levels are usually represented by

SECTION 20

#1733085205494

1408-480: Is separately discussed below. Note that the processor does not push the accumulator and index registers on to the stack—code in the interrupt handler must perform that task, as well as restore the registers at the termination of interrupt processing, as necessary. Also note that the vector for IRQ is the same as that for BRK in all eight bit 65xx processors, as well as in the 65C802/65C816 when operating in emulation mode. When operating in native mode,

1472-401: Is that a direct current must flow through a logic gate even when the output is in a steady state (low in the case of NMOS). This means static power dissipation , i.e. power drain even when the circuit is not switching, leading to high power consumption. Another disadvantage of NMOS circuits is their thermal output. Due to the need to keep constant voltage running through the circuit to hold

1536-528: Is the stack that existed at the time of the interrupt will be inaccessible unless it was also in page 1 RAM and no larger than 256 bytes. In general, mode switching while servicing an interrupt is not a recommended procedure, but may be necessary in specific operating environments. As previously noted, BRK and COP are software interrupts and, as such, may be used in a variety of ways to implement system functions. A historical use of BRK has been to assist in patching PROMs when bugs were discovered in

1600-687: Is to avoid circumstances that produce intermediate levels, so that the circuit behaves predictably. Nearly all digital circuits use a consistent logic level for all internal signals. That level, however, varies from one system to another. Interconnecting any two logic families often required special techniques such as additional pull-up resistors or purpose-built interface circuits known as level shifters. A level shifter connects one digital circuit that uses one logic level to another digital circuit that uses another logic level. Often two level shifters are used, one at each system: A line driver converts from internal logic levels to standard interface line levels;

1664-449: The VDA or VPA signals. Also, ABORTB must remain asserted until the fall of the phase-two clock and then be immediately released. If these timing constraints are not observed, the abort interrupt handler itself may be aborted, causing registers and/or memory to be changed in a possibly-undefined manner. In the NMOS 6502 and derivatives (e.g., 6510), the simultaneous assertion of

1728-479: The DB and DP registers. In the case of the index registers, they may be pushed without regard to their sizes, as changing sizes automatically sets the most significant byte (MSB) in these registers to zero and no data will be lost when the pushed value is restored, provided the index registers are the same size they were when pushed. The accumulator, however, is really two registers: designated .A and .B . Pushing

1792-547: The Motorola 68030 were hybrids with both NMOS and CMOS sections. CMOS has been near-universal in integrated circuits since the 1990s. Additionally, just like in diode–transistor logic , transistor–transistor logic , emitter-coupled logic etc., the asymmetric input logic levels make NMOS and PMOS circuits more susceptible to noise than CMOS. These disadvantages are why CMOS logic has supplanted most of these types in most high-speed digital circuits such as microprocessors despite

1856-486: The stack pointer ( SP ). Further complicating matters with the 65C816/65C802 is that the sizes of the accumulator and index registers may be either 8 or 16 bits when operating in native mode, requiring that their sizes be preserved for later restoration. The methods by which the MPU state is preserved and restored within an ISR will vary with the different versions of the 65xx family. For NMOS processors (e.g., 6502, 6510, 8502, etc.), there can be only one method by which

1920-643: The voltage difference between the signal and ground , although other standards exist. The range of voltage levels that represent each state depends on the logic family being used. A logic-level shifter can be used to allow compatibility between different circuits. In binary logic the two levels are logical high and logical low , which generally correspond to binary numbers 1 and 0 respectively or truth values true and false respectively. Signals with one of these two levels can be used in Boolean algebra for digital circuit design or analysis. The use of either

1984-519: The 65C802/65C816 provide separate vectors for IRQ and BRK . When set, the interrupt request disable flag (the I bit in the status register) will disable detection of the IRQ signal, but will have no effect on any other interrupts (however, see below section on the WAI instruction implemented in WDC CMOS processors). Additionally, with the 65(c)02 or the 65C816/65C802 operating in emulation mode,

Interrupts in 65xx processors - Misplaced Pages Continue

2048-409: The 65C816/65C802 are switched back to emulation mode and stay there until returned to native mode under software control. The detection of an NMI or IRQ signal, as well as the execution of a BRK instruction, will cause the same overall sequence of events, which are, in order: The behavior of the 65C816 when ABORT is asserted differs in some respects from the above description and

2112-432: The 74HCT family of devices that uses CMOS technology but TTL input logic levels. These devices only work with a 5 V power supply. Though rare, ternary computers evaluate base 3 three-valued or ternary logic using 3 voltage levels. In three-state logic , an output device can be in one of three possible states: 0, 1, or Z, with the last meaning high impedance . This is not a voltage or logic level, but means that

2176-494: The ISR can use them as needed. When the ISR has concluded its work, it would restore the registers and then resume the interrupted foreground task. Again, the following NMOS code is typical: A consequence of the RTI instruction is the MPU will return to decimal mode if that was its state at the time of the interrupt. The 65C02 , and the 65C816/65C802 when operating in emulation mode, require less code, as they are able to push and pull

2240-522: The ISR must preserve the microprocessor (MPU) state and not disturb anything in memory that it is not supposed to disturb. Additionally, the ISR should be fully reentrant , meaning that if two interrupts arrive in close succession, the ISR will be able to resume processing the first interrupt after the second one has been serviced. Reentrancy is typically achieved by using only the MPU hardware stack for storage (though there are other possible methods). Preserving

2304-404: The MPU state means that the ISR must assure that whatever values were in the MPU registers at the time of the interrupt are there when the ISR terminates. A part of the preservation process is automatically handled by the MPU when it acknowledges the interrupt, as it will push the program counter (and program bank in the 65C816/65C802) and status register to the stack prior to executing the ISR. At

2368-445: The MPU will "awaken" in one clock cycle and resume execution at the instruction immediately following WAI . Hence interrupt latency will be very short (70 nanoseconds at 14 megahertz), resulting in the most rapid response possible to an external event. Similar in some ways to WAI is the STP ( ST o P , opcode $ DB ) instruction, which completely shuts down the MPU while waiting for

2432-441: The MPU would be redirected to the patch area, into which suitable patch code would be written. Often, the patch area code started by "sniffing the stack" to determine the address at which the bug was encountered, potentially allowing for the presence of more than one patch in the PROM. The use of BRK for PROM patching diminished once EPROMs and EEPROMs became commonly available. Another use of BRK in software development

2496-501: The above pushes have occurred—it should be apparent why this is so. The following code, added to the above sequence, would handle this requirement: At the completion of the ISR, the above processes would be reversed as follows: Note that upon executing RTI , the 65C816/65C802 will automatically restore the register sizes to what they were when the interrupt occurred, since pulling the previously–saved status register sets or clears both register size bits to what they were at

2560-422: The accumulator and index registers are preserved, as only the accumulator can be pushed to and pulled from the stack. Therefore, the following ISR entry code is typical: The CLD instruction is necessary because, as previously noted, NMOS versions of the 6502 do not clear the D (decimal mode) flag in the status register when an interrupt occurs. Once the accumulator and index registers have been preserved,

2624-415: The accumulator when it is set to 8 bits will not preserve .B , which could result in a loss of transparency should the ISR change .B in any way. Therefore, the accumulator must always be set to 16 bits before being pushed or pulled if the ISR will be using .B . It is also more efficient to set the index registers to 16 bits before pushing them. Otherwise, the ISR has to then push an extra copy of

Interrupts in 65xx processors - Misplaced Pages Continue

2688-437: The actual behaviour of the program being debugged. A characteristic of the BRK and COP instructions is that the processor treats either of them as a two byte instruction: the opcode itself and the following byte, which is referred to as the "signature." Upon execution of BRK or COP , the processor will add two to the program counter prior to pushing it to the stack. Hence when RTI ( R e T urn from I nterrupt)

2752-547: The bugs present in the chip's logic were extensively exploited by programmers for graphics effects. For many years, NMOS circuits were much faster than comparable PMOS and CMOS circuits, which had to use much slower p-channel transistors. It was also easier to manufacture NMOS than CMOS, as the latter has to implement p-channel transistors in special n-wells on the p-substrate, not prone to damage from bus conflicts, and not as vulnerable to electrostatic discharge damage. The major drawback with NMOS (and most other logic families )

2816-412: The completion of the ISR, when the RTI instruction is executed, the MPU will reverse the process. No member of the 65xx family pushes any other registers to the stack. In most ISRs, the accumulator and/or index registers must be preserved to assure transparency and later restored as the final steps prior to executing RTI . In the case of the 65C816/65C802, consideration must be given to whether it

2880-416: The copy of the status register that is pushed on to the stack will have the B flag set if a BRK ( software interrupt ) was the cause of the interrupt, or cleared if an IRQ was the cause. Hence the interrupt service routine must retrieve a copy of the saved status register from where it was pushed onto the stack and check the status of the B flag in order to distinguish between an IRQ and

2944-399: The fact that CMOS was originally very slow compared to logic gates built with bipolar transistors . MOS stands for metal-oxide-semiconductor , reflecting the way MOS-transistors were originally constructed, predominantly before the 1970s, with gates of metal, typically aluminium. Since around 1970, however, most MOS circuits have used self-aligned gates made of polycrystalline silicon ,

3008-409: The following sequence of events will occur: As the address pushed to the stack is that of the aborted instruction rather than the contents of the program counter, executing an RTI ( R e T urn from I nterrupt) following an ABORT interrupt will cause the processor to return to the aborted instruction, rather than the next instruction, as would be the case with the other interrupts. In order for

3072-407: The higher or the lower voltage level to represent either logic state is arbitrary. The two options are active high ( positive logic ) and active low ( negative logic ). Active-high and active-low states can be mixed at will: for example, a read only memory integrated circuit may have a chip-select signal that is active-low, but the data and address bits are conventionally active-high. Occasionally

3136-404: The index registers without using the accumulator as an intermediary. They also automatically clear decimal mode before executing the ISR. The following is typical: Upon finishing up, the ISR would reverse the process: As previously stated, there is a little more complexity with the 65C816/65C802 when operating in native mode due to the variable register sizes and the necessity of accounting for

3200-494: The line coding is converted back to binary. NMOS logic NMOS or nMOS logic (from N-type metal–oxide–semiconductor) uses n-type (-) MOSFETs (metal–oxide–semiconductor field-effect transistors ) to implement logic gates and other digital circuits . NMOS transistors operate by creating an inversion layer in a p-type transistor body. This inversion layer, called the n-channel, can conduct electrons between n-type source and drain terminals. The n-channel

3264-442: The logic gate output and negative supply voltage (typically the ground). A pull up (i.e. a "load" that can be thought of as a resistor, see below) is placed between the positive supply voltage and each logic gate output. Any logic gate , including the logical inverter , can then be implemented by designing a network of parallel and/or series circuits, such that if the desired output for a certain combination of boolean input values

SECTION 50

#1733085205494

3328-686: The logic gates are open-collector / open-drain with a pull-up resistor. Examples of this are the I²C bus, CAN bus, and PCI bus. Some signals have a meaning in both states and notation may indicate such. For example, it is common to have a read/write line designated R/ W , indicating that the signal is high in case of a read and low in case of a write. The two logical states are usually represented by two different voltages, but two different currents are used in some logic signaling, like digital current loop interface and current-mode logic . High and low thresholds are specified for each logic family. When below

3392-422: The low threshold, the signal is low . When above the high threshold, the signal is high . Intermediate levels are undefined, resulting in highly implementation-specific circuit behavior. It is usual to allow some tolerance in the voltage levels used; for example, 0 to 2 volts might represent logic 0, and 3 to 5 volts logic 1. A voltage of 2 to 3 volts would be invalid and occur only in a fault condition or during

3456-503: The operating system re-enable them. WAI ( WA it for I nterrupt, opcode $ CB ) is an instruction available on the WDC version of the 65C02 and the 65C816/65C802 microprocessors (MPU) that halts the MPU and places it into a semi-catatonic state until a hardware interrupt of any kind occurs. The primary use for WAI is in low-power embedded systems where the MPU has nothing to do until an expected event occurs and minimal power consumption

3520-555: The output is not controlling the state of the connected circuit. Four valued logic adds a fourth state, X ( don't care ), meaning the value of the signal is unimportant and undefined. It means that an input is undefined, or an output signal may be chosen for implementation convenience (see Karnaugh map § Don't cares ). IEEE 1164 defines 9 logic states for use in electronic design automation . The standard includes strong and weakly driven signals, high impedance and unknown and uninitialized states. In solid-state storage devices,

3584-404: The processor to correctly respond to an abort, system logic must assert (negate) the ABORTB input as soon as a valid address has been placed on the bus and it has been determined that the address constitutes a page fault, memory access violation or other anomaly (e.g., attempted execution of a privileged instruction). Hence the logic must not assert ABORTB until the processor has asserted

3648-450: The processor to the same address, simple code may be used to preserve the registers on the stack prior to turning control over to the requested service. However, this programming model will result in somewhat slower execution as compared to calling a service as a subroutine , primarily a result of the stack activity that occurs with any interrupt. Also, interrupt requests will have been disabled by executing BRK or COP , requiring that

3712-435: The program counter before pushing it to the stack facilitates the technique of treating them as supervisor call instructions , as found on some mainframe computers . The usual procedure is to treat the signature as an operating system service index. The operating system BRK or COP handler would retrieve the value of the program counter pushed to the stack, decrement it and read from the resulting memory location to get

3776-431: The range $ 00 - $ 7F . The use of BRK and/or COP to request an operating system service means user applications do not have to know the entry address of each operating system function, only the correct signature byte to invoke the desired operation. Hence relocation of the operating system in memory will not break compatibility with existing user applications. Also, as executing BRK or COP always vectors

3840-445: The signature. After converting the signature to a zero-based index, a simple lookup table can be consulted to load the program counter with the address of the proper service routine. Upon completion of the service routine, the RTI instruction would be used to return control to the program that made the operating system call. Note that the signature for BRK may be any value, whereas the signature for COP should be limited to

3904-437: The status register so it can restore the register sizes prior to pulling them from the stack. For most ISRs, the following entry code will achieve the goal of transparency: In the above code fragment, the symbol % is MOS Technology and WDC standard assembly language syntax for a bitwise operand . If the ISR has its own assigned stack location, preservation of the stack pointer ( SP ) must occur in memory after

SECTION 60

#1733085205494

3968-471: The time of an interrupt. These anomalies were corrected in all CMOS versions of the processor. A well-designed and succinct interrupt handler or interrupt service routine (ISR) will not only expeditiously service any event that causes an interrupt, it will do so without interfering in any way with the interrupted foreground task—the ISR must be "transparent" to the interrupted task (although exceptions may apply in specialized cases). This means that

4032-420: The time of the interrupt. While it is possible to switch the 65C816/65C802 from native mode to emulation mode within an ISR, such is fraught with peril. In addition to forcing the accumulator and index registers to 8 bits (causing a loss of the most significant byte in the index registers), entering emulation mode will truncate the stack pointer to 8 bits and relocate the stack itself to page 1 RAM . The result

4096-430: The transistors' states, NMOS circuits can generate a considerable amount of heat in operation which can reduce the device's reliability. This was especially problematic with the early large gate process nodes in the 1970s. CMOS circuits for contrast generate almost no heat unless the transistor count approaches 1 million. CMOS components were relatively uncommon in the 1970s-early 1980s and would typically be indicated with

#493506