MIPS Verified
™Document Number: MD00656 Revision 01.00
October, 2007
MIPS Technologies, Inc.
1225 Charleston Road Mountain View, CA 94043-1353
Copyright © 2007 MIPS Technologies Inc. All rights reserved.
Brief Introduction to MIPS32® M4K® Core Shadow Registers for Microcontroller
Applications
Brief Introduction to MIPS32® M4K® Core Shadow Registers for Microcontroller Applications, Revision 01.00 3 Copyright © 2007 MIPS Technologies Inc. All rights reserved.
1 Introduction
The RISC architecture brings many advantages to the microcontroller space including the fact that compared to CISC architectures it is much friendlier to compilers and very economical in silicon area. For silicon designers and their tar- get customers, this translates to high performance at low cost.
There are, however, some additional considerations for the end user when using RISC-based processors, especially at the lower frequencies found in the general purpose microcontroller space.
One of these issues is related to the context save and restore sequence during an interrupt or exception handling rou- tine. The context save and restore sequence in a RISC-based machine can potentially be very cycle-intensive, given that at least 16 if not 32 general purpose registers (GPRs) must be pushed to or popped from a stack or static storage space somewhere in RAM. In some cases, it is only after a significant amount of clock cycles that the core is ready to address the actual interrupt request.
Designers can take shortcuts by not saving all of the registers—either by writing the entire application in assembly language or instructing the compiler to use only certain registers during code translation. Either way, this adds addi- tional constraints to the software design since the software developer must be aware of these requirements at all times.
The MIPS32® M4K® RISC core is no different than other RISC cores in this respect in that it has 32 GPRs and an application binary interface (ABI) that uses the full range of the 32 GPRs as defined by the MIPS32 Release 2 archi- tecture.
However, the M4K core provides a more elegant solution in the form of GPR shadow register support, greatly reduc- ing the interrupt response overhead and ultimately matching the highly responsive and deterministic structure of CISC-based microcontrollers. It offers the best of both worlds.
2 M4K Core Shadow Register Sets: Basic Introduction
A new feature in the MIPS32 Release 2 architecture greatly streamlines the ability to handle interrupts and excep- tions. Processors implemented using the MIPS32 Release 2 architecture, including the M4K core, allow for up to eight copies of the GPRs to be present within the core itself. This feature is a build-time option that creates an advanced interrupt control structure not usually found in the microcontroller space.
Now chip designers can decide to balance speed against total core area, creating one, two, four or eight copies of the GPRs. By definition, shadow set 0 is the default GPR set, such that up to seven additional shadow sets are available exclusively for interrupt service tasks.
The additional GPRs are completely isolated from each other and normal memory space, except in the cases men- tioned below. Each GPR set can be associated with one or multiple interrupt vectors, depending on the application.
When processing an interrupt or exception, the M4K core will determine which shadow set is to be used based on the values the designer sets in specific control registers. It then establishes the specified shadow register set as the active set of GPRs, allowing the interrupt vector to continue execution. This process completely eliminates the need for any context save or restore cycle, since the specified interrupt service routine is the sole owner of the shadow register that is currently active.
3 M4K Core Shadow Register Sets: Basic Operation
Not only does this mean that no time is wasted before the interrupt or exception code can begin actual implementa- tion, but it also means that the content of the registers has been preserved since the last exception or interrupt event was active. This saves time on retrieving specific values from the SRAM space.
Following is the basic procedure for initialization of an interrupt controller scheme on the M4K core. It retains the standard steps of any general interrupt system initialization procedure, with the addition of one important new step:
1. Standard: Set base vector table address
2. Standard: Fill interrupt table with active vector addresses
3. Standard: Fill non-active vector table addresses with stub addresses 4. M4K Specific: Assign vector specific IDs to associated GPR register set
5. Standard: Clear all active and pending interrupt sources 6. Standard: Enable all active interrupt sources
7. Standard: Enable global interrupts
3 M4K Core Shadow Register Sets: Basic Operation
A detailed description of the entire implementation of shadow register sets is beyond the scope of this document; such a description can be found in the paper, “MIPS32® M4K® Processor Core Implementor’s Guide,” available through MIPS Technologies. The basic operation is summarized as follows.
Figure 1 illustrates the basic concepts involved with an M4K core built with a total of four register sets. It must be noted that these four register sets are completely contained within the processor core and require no external RAM to implement. Also indicated in the diagram are two key control registers, SRSCTL and SRSMAP, used in the configu- ration and implementation of the shadow GPR logic.
Brief Introduction to MIPS32® M4K® Core Shadow Registers for Microcontroller Applications, Revision 01.00 5 Copyright © 2007 MIPS Technologies Inc. All rights reserved.
Figure 1 MIPS32® Vectored Interrupt / Shadow Register Structure
Figure 1 indicates the state of the core just before execution of the interrupt service routine is about to begin:
• A hardware interrupt of a specific source has been acknowledged by the external interrupt controller.
• The external interrupt controller has passed this vector ID onto the M4K core. For this example, we will assume the vector ID is 1.
• The core uses this vector ID to determine the target GPR set to use. The M4K core does this by the configu- ration set in the SRSMAP, which contains shadow GPR IDs for Vector ID 0 through Vector ID 7.
The M4K core then uses this information to perform the following:
• The current GPR ID is copied into the SRSCTL_PSS field of the SRSCTL control register. This is the Previ- ous Shadow Set ID to be recovered later when the interrupt or exception request is completed.
• The GPR set ID pulled from the SRSMAP control register is copied into the SRSCTL_CSS field of the STSCTL control register. This now specifies the Current Shadow Set.
• Execution of the interrupt or exception service routine proceeds to completion and an ERET instruction is executed.
• The M4K core then copies the values from the SRSCTL_PSS bit field into the SRSCTL_CSS bit field and execution resumes from the point at which the interrupt or exception was issued.
There is a clear advantage of this process over the standard-context save and restore procedure: the M4K core wastes no time in setting up a GPR environment that allows it to begin processing the interrupt service request or exception request almost immediately. Using the shadow GPR function of the M4K core, the interrupt latency is reduced to only 22 cycles, or a total of 550 ns.
Hardware Interrupts
External
SRSMAP
SRSCTL MIPS32®
M4K® Core
R31
R0
Bank 0
Vector ID
SRSCTL_PSS
Interrupts
R31
R0
Bank 1
R31
R0
Bank 2
R31
R0
Bank 3 SRSCTL_CSS
4 M4K Core Shadow Register Sets: Finer Grain Control
4 M4K Core Shadow Register Sets: Finer Grain Control
During normal execution of user-space code on the M4K core, each copy of the GPR set remains invisible to the pro- cessor core unless its specific ID is active. However there are some special processor instructions that allow the M4K core, when executing in kernel mode, to access any given register set. RDPGPR and WRPGPR instructions allow a privileged execution thread to access any and all GPR shadow sets at will. This may be required when a specific GPR set is dual-purposed between two discrete but similar interrupt vectors. Knowing how the compiler ABI places the active data into the GPR sets would allow a user to pick and choose specific GPR values for safekeeping, depending on the specific interrupt vector that is executing. An example of where this would be useful is in the case of two Ethernet devices that share the same register structure, but are processing different TCP/IP streams.
5 M4K Core Shadow Register Sets: Benefits in the Microcontroller Space
Use of the shadow set feature of the M4K core allows system designers to maximize the interrupt response time to external events, even when dropping the processor core speed to save power.
The compromises of the software design now shift from dealing with the inherent waste of clock cycles needed to preserve the current state of the system to deciding which interrupt sources deserve their own shadow register sets and which ones can share a dedicated GPR set between them. This is a much easier challenge.
The shadow GPR system is straightforward in initialization and operation with most of the heavy work happening transparently to the executing code. This allows software designers to concentrate on the efficiency of the actual interrupt service routine rather than on system housekeeping. By taking advantage of shadow GPRs, the M4K core can greatly reduce the interrupt response overhead and offer a highly responsive, deterministic solution for 32-bit microcontrollers.
Brief Introduction to MIPS32® M4K® Core Shadow Registers for Microcontroller Applications, Revision: 01.00 Copyright © 2007 MIPS Technologies Inc. All rights reserved.
Template: nW1.03, Built with tags: 2B
Copyright © 2007 MIPS Technologies, Inc. All rights reserved.
Unpublished rights (if any) reserved under the copyright laws of the United States of America and other countries.
This document contains information that is proprietary to MIPS Technologies, Inc. ("MIPS Technologies"). Any copying, reproducing, modifying or use of this information (in whole or in part) that is not expressly permitted in writing by MIPS Technologies or an authorized third party is strictly prohibited. At a minimum, this information is protected under unfair competition and copyright laws. Violations thereof may result in criminal penalties and fines.
Any document provided in source format (i.e., in a modifiable form such as in FrameMaker or Microsoft Word format) is subject to use and distribution restrictions that are independent of and supplemental to any and all confidentiality restrictions. UNDER NO CIRCUMSTANCES MAY A DOCUMENT PROVIDED IN SOURCE FORMAT BE DISTRIBUTED TO A THIRD PARTY IN SOURCE FORMAT WITHOUT THE EXPRESS WRITTEN PERMISSION OF MIPS TECHNOLOGIES, INC.
MIPS Technologies reserves the right to change the information contained in this document to improve function, design or otherwise. MIPS Technologies does not assume any liability arising out of the application or use of this information, or of any error or omission in such information. Any warranties, whether express, statutory, implied or otherwise, including but not limited to the implied warranties of merchantability or fitness for a particular purpose, are excluded.
Except as expressly provided in any written license agreement from MIPS Technologies or an authorized third party, the furnishing of this document does not give recipient any license to any intellectual property rights, including any patent rights, that cover the information in this document.
The information contained in this document shall not be exported, reexported, transferred, or released, directly or indirectly, in violation of the law of any country or international law, regulation, treaty, Executive Order, statute, amendments or supplements thereto. Should a conflict arise regarding the export, reexport, transfer, or release of the information contained in this document, the laws of the United States of America shall be the governing law.
The information contained in this document constitutes one or more of the following: commercial computer software, commercial computer software documentation or other commercial items. If the user of this information, or any related documentation of any kind, including related technical data or manuals, is an agency, department, or other entity of the United States government ("Government"), the use, duplication, reproduction, release, modification, disclosure, or transfer of this information, or any related documentation of any kind, is restricted in accordance with Federal Acquisition Regulation 12.212 for civilian agencies and Defense Federal Acquisition Regulation Supplement 227.7202 for military agencies. The use of this information by the Government is further restricted in accordance with the terms of the license agreement(s) and/or applicable contract terms and conditions covering this information from MIPS Technologies or an authorized third party.
MIPS, MIPS I, MIPS II, MIPS III, MIPS IV, MIPS V, MIPS-3D, MIPS16, MIPS16e, MIPS32, MIPS64, MIPS-Based, MIPSsim, MIPSpro, MIPS Technologies logo, MIPS-VERIFIED, MIPS-VERIFIED logo, 4K, 4Kc, 4Km, 4Kp, 4KE, 4KEc, 4KEm, 4KEp, 4KS, 4KSc, 4KSd, M4K, 5K, 5Kc, 5Kf, 24K, 24Kc, 24Kf, 24KE, 24KEc, 24KEf, 34K, 34Kc, 34Kf, 74K, 74Kf, 74Kc, 1004K, 1004Kc, 1004Kf, R3000, R4000, R5000, ASMACRO, Atlas, "At the core of the user experience.", BusBridge, Bus Navigator, CLAM, CorExtend, CoreFPGA, CoreLV, EC, FPGA View, FS2, FS2 FIRST SILICON SOLUTIONS logo, FS2 NAVIGATOR, HyperDebug, HyperJTAG, JALGO, Logic Navigator, Malta, MDMX, MED, MGB, OCI, PDtrace, the Pipeline, Pro Series, SEAD, SEAD-2, SmartMIPS, SOC-it, System Navigator, and YAMON are trademarks or registered trademarks of MIPS Technologies, Inc. in the United States and other countries.
All other trademarks referred to herein are the property of their respective owners.