Application Note 235: Migrating From MIPS To ARM
Application Note 235: Migrating From MIPS To ARM
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 1
ARM DAI 0235C
Introduction
Release information
Change history
Proprietary notice
Words and logos marked with ® or © are registered trademarks or trademarks owned by
ARM Limited, except as otherwise stated below in this proprietary notice. Other brands
and names mentioned herein may be the trademarks of their respective owners.
Neither the whole nor any part of the information contained in, or the product described in,
this document may be adapted or reproduced in any material form except with the prior
written permission of the copyright holder.
The product described in this document is subject to continuous developments and
improvements. All particulars of the product and its use contained in this document are
given by ARM in good faith. However, all warranties implied or expressed, including but
not limited to implied warranties of merchantability, or fitness for purpose, are excluded.
This document is intended only to assist the reader in the use of the product. ARM Limited
shall not be liable for any loss or damage arising from the use of any information in this
document, or any error or omission in such information, or any incorrect use of the
product.
Confidentiality status
If you have any comments on this Application Note, please send email to
errata@arm.com giving:
the document title
the document number
the page number(s) to which your comments refer
an explanation of your comments.
General suggestions for additions and improvements are also welcome.
http://www.arm.com
2 Copyright © 2010 ARM Limited. All rights reserved. Application Note 235
ARM DAI 0235C
Introduction
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 3
ARM DAI 0235C
Introduction
Table of Contents
1 Introduction ................................................................................................................5
1.1 The ARM architecture .........................................................................................5
1.2 ARM development tools ......................................................................................5
1.3 References and Further Reading........................................................................5
2 ARM architecture features.........................................................................................6
2.1 ARM architecture versions ..................................................................................6
2.2 Programmer’s model...........................................................................................6
2.3 Debug..................................................................................................................8
3 MIPS and ARM compared..........................................................................................9
3.1 Programmer’s model...........................................................................................9
3.2 System control and configuration registers .......................................................15
3.3 Exceptions and interrupts..................................................................................15
3.4 Memory .............................................................................................................17
3.5 Debug................................................................................................................19
3.6 Power management ..........................................................................................20
3.7 Security features ...............................................................................................21
4 Migrating a software application ............................................................................22
4.1 General considerations .....................................................................................22
4.2 Tools configuration............................................................................................24
4.3 Startup...............................................................................................................24
4.4 Handling interrupts and exceptions ...................................................................25
4.5 Timing and delays .............................................................................................30
4.6 Power Management ..........................................................................................30
4.7 C Programming .................................................................................................31
4 Copyright © 2010 ARM Limited. All rights reserved. Application Note 235
ARM DAI 0235C
Introduction
1 Introduction
The purpose of this document is to highlight areas of interest for those involved in
migrating software applications from MIPS to ARM platforms. No attempt is made to
promote one architecture over the other, merely to explain clearly the issues involved in a
decision to migrate an existing software application from one to the other.
Familiarity with the MIPS architecture is assumed and corresponding ARM features are
explained.
The ARM architecture is supported by a wide range of technology, tools and infrastructure
available from a large number of partners in the ARM Connected Community. Pointers to
these resources are given where appropriate, although ARM’s own supporting technology
is highlighted.
There is much related documentation available from ARM (see references below) which
should be consulted where further detail is required.
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 5
ARM DAI 0235C
ARM architecture features
1. Register set
The ARM register set consists of 37 general-purpose registers, 16 of which are usable at
any one time. The subset which is usable is determined by the current operation mode
(see below).
In addition to the general purpose registers, the CPSR (Current Program Status Register)
hold current status, operating mode, instruction set state, ALU status flags etc.
2. Operating modes
The ARM core supports seven operating modes. All of these, with the exception of User
mode, are privileged. Five modes (Supervisor, Undefined, Abort, FIQ and IRQ) are
associated with handling particular types of exception events. Applications generally run
either in User mode (unprivileged) or System mode (privileged) with the operating system,
if one is used, running in Supervisor mode.
3. Instruction sets
Current ARM cores may support several instruction sets:
The native ARM instruction set, in which all instructions are 32-bit.
6 Copyright © 2010 ARM Limited. All rights reserved. Application Note 235
ARM DAI 0235C
ARM architecture features
The Thumb instruction set (introduced in ARMv4T), in which all instructions are
16-bit. This provides greatly improved code density.
Java bytecode – cores which include the Jazelle-DBX extension are capable of
executing Java bytecode directly in hardware.
The ARM and Thumb instruction sets have both been extended several times since
their introduction. In particular, the Thumb-2 extension introduces 32-bit instructions
into the 16-bit Thumb instruction set providing greatly increased performance without
compromising the code density benefits of thumb.
Of the ARM cores available on the market today, all support the ARM and Thumb
instruction sets as a minimum, with the exception of ARMv7-M devices which support
only the Thumb-2 instruction set.
5. Memory architecture
ARM cores have a 32-bit address bus providing a flat 4GB linear address space. Memory
is addressed in bytes and may be accessed as 8-byte doublewords, 4-byte words, 2-byte
halfwords or single bytes. Configuration options in the core determine the endianness and
alignment behavior of the memory interface.
More advanced ARM cores implement caches, Tightly Coupled Memory (TCM) regions,
virtual memory and memory protection features.
2. Jazelle
ARM provides two optional methods for acceleration of Java and other dynamically
compiler languages.
Jazelle-DBX (Direct Bytecode eXecution) which supports execution of a subset of Java
bytecodes in hardware.
Jazelle-RCT (Runtime Compilation Target) which provides some extended instructions
to improve performance of Just-In-Time compilation techniques for
languages like Java, Perl etc.
3. Memory protection
Many ARM cores incorporate a Memory Protection Unit (MPU) which allows memory to be
partitioned into a number of regions. Each region cab be assigned access permissions
which are policed automatically by the MPU at run-time.
4. Virtual memory
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 7
ARM DAI 0235C
ARM architecture features
6. Multicore support
ARM11MPCore and Cortex-A9 MPCore are multi-core versions of the ARM11 and
Cortex-A9 respectively. They are designed to be used in clusters of up to four cores which
are connected via logic which controls interrupt distribution and manages cache
coherency.
2.3 Debug
ARM provides debug using the industry-standard JTAG port. As standard, this uses a 5-
wire connection. A 2-wire version is also available for use in applications where pin-count
is at a premium.
ARM’s CoreSight on-chip debug infrastructure allows chip designers to specify and build
complex multi-core debug systems which allow synchronous trace and debug of multiple
cores within a single device.
8 Copyright © 2010 ARM Limited. All rights reserved. Application Note 235
ARM DAI 0235C
MIPS and ARM compared
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 9
ARM DAI 0235C
MIPS and ARM compared
switches or interrupts. The need to use larger fields in instructions to specify register
operands also somewhat reduces the flexibility of MIPS instructions. ARM instructions, for
instance, often support more flexible addressing modes as there are bits available to
encode more options.
Although the ARM register set is smaller, techniques like register renaming (in which
architectural registers are dynamically mapped in the pipeline to a much larger set of
physical registers) greatly increase the scope for code optimizations in ARM systems.
The MIPs architecture supports the implementation of multiple “shadow” banks of
registers. This allows more efficient context-switching operations but the fact that this
feature is not commonly or consistently implemented on MIPS-based devices makes it of
limited use. Consequently, few compilers or operating systems make use of it.
In addition to the general purpose register set, MIPS provides two separate registers (Hi
and Lo) to hold the results of a multiply operation. Special instructions are used to read
these registers and copy the contents to general purpose registers. These registers must
also be saved in the event of exceptions or task switches, increasing the cost of having
them. In contrast, the ARM multiplication instructions use general purpose registers for
input and output, removing the need to save and restore extra registers.
Both architectures support coprocessors with separate banks of dedicated registers. ARM
supports up to 15 coprocessors (with 11 available for user-definition), while MIPS
supports up to 4.
In general, only the ALU flags (NZCVQ) are modifiable when executing in user mode.
Other fields, with the exception of T and J bits, may be modified directly when in privileged
modes. T and J bits are only changed indirectly by execution of instructions like BX and
BXJ.
A
P
The v7-M CPSR can be referred to using the following names, which indicate various
combinations of sub-fields.
APSR – Application Program Status Register (ALU flags only)
IPSR – Interrupt Program Status Register (ISE number)
EPSR – Execution Program Status Register (IT, ICI and T fields)
The name xPSR refers to a composite of all three and is the one automatically saved on
the stack on entry to an exception.
Only APSR is accessible to Thread mode programs. IPSR is only accessible in privileged
Handler mode. EPSR is not generally user-accessible at all.
The corresponding features in a MIPS processor are held, mostly, in the Status Register
which is part of CP0 (CP0, Register 12).
10 Copyright © 2010 ARM Limited. All rights reserved. Application Note 235
ARM DAI 0235C
MIPS and ARM compared
The following table lists the bits in the MIPS status register and their ARM equivalents.
Fields or bits not listed are reserved.
CPSR E
BEV 22 Exception CP15 Control V
vector Register
location
TS 21 TLB N/A
shutdown
SR 20 Soft Reset N/A
indicator
NMI 19 NMI indicator N/A
IM 15-8 Interrupt CPSR I, F
Mask
UM 4 User mode CPSR Mode bits
ERL 2 Error Level N/A
EXL 1 Exception N/A
Level
IE 0 Interrupt CPSR I, F
Enable
Note that the ALU status flags are not visible in the MIPS status register. They cannot be
directly modified and can only be tested indirectly via conditional branch instructions. In
the ARM CPSR, the flags are fully visible and can be read and modified at any time.
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 11
ARM DAI 0235C
MIPS and ARM compared
in scope to the instructions added in v5TE of the ARM architecture. However, the fact that
these extensions are optional means that many applications and tools do not make use of
them. In contrast, the ARM instruction set is much more standardized and all tools support
the extensions added at each increment.
Both architectures support floating point operations via an external coprocessor. In the
case of MIPS, this is always CP1, in ARM CP10 is used for single-precision and CP11 for
double-precision.
The MIPS CorExtend feature allows for user-defined extensions to the core instruction
set. However, due to the lack of standardization, this feature is little used. ARM prefers not
provide this kind of ability for licensees, believing that a standardized instruction set
makes for wider tools and operating system support.
ARM and MIPS instruction sets are, as you would expect from two RISC cores, fairly
similar in many respects. These example pairs of instructions look very similar and
perform essentially the same operations.
MIPS ARM
addu $1, $2, $3 ADD r1, r2, r3
lw $3, 20($4) LDR r3, [r4, #20]
jal function BL function
12 Copyright © 2010 ARM Limited. All rights reserved. Application Note 235
ARM DAI 0235C
MIPS and ARM compared
Generally, there is little need for an application to explicitly change mode. The appropriate
mode is entered when an exception is handled by the core. In particular, a program
executing in User mode gains access to privileged OS features by executing an SVC
instruction which causes an automatic switch into Supervisor mode. The transition back to
User mode happens automatically on return from the SVC exception handler.
Generally, following reset (in Supervisor mode), the startup code completes all system
initialization in privileged mode and then optionally switches into User mode (or System
mode if the user application is to run with privilege) before calling the main application
entry point.
Obviously, the mode bits can only be modified when running in a privileged mode.
3.1.5 Stack
By convention, both architectures generally implement a full-descending stack. MIPS uses
$29 for the stack pointer, ARM uses r13. A stack push or pop operation on a MIPS
machine involves two distinct operations: a load (or store) following by an add (or subtract)
to adjust the stack pointer. ARM’s auto-update addressing modes make this unnecessary
as the load (or store) and stack pointer adjustment can be achieved in a single instruction.
The ARM architecture also includes instructions for loading (LDM) and storing (STM)
multiple registers in a single operation. These make pushing and popping a number of
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 13
ARM DAI 0235C
MIPS and ARM compared
registers (e.g. on context switch or function entry/exit) much more efficient when working
with ARM.
Note that the ARM assembler uses PUSH and POP mnemonics to correspond to the
instruction shown above.
Because of the fundamental inefficiency of MIPS stack operations, MIPS functions
generally create a large stack frame in one operation at the head of the function. This is
then used by the function for temporary storage before being deleted on return.
14 Copyright © 2010 ARM Limited. All rights reserved. Application Note 235
ARM DAI 0235C
MIPS and ARM compared
ARM cores have a number of such registers – which one to use depends on the
exception type e.g. the CP15 Fault Status Register is used to determine the cause
of an abort.
Both cores have a dedicated return instruction which restores status and returns
to the interrupted code.
Note though that ARM cores prior to architecture v6 do not support the RFE
instruction and a set of special data processing instructions are used instead.
Both architectures support an external vectored interrupt controller which supplies
individual handler addresses for all external interrupt sources.
ARM maps several events to the abort exception which are treated separately by
MIPS cores. These include TLB miss, MMU address error, external bus error,
watchpoint trigger, cache error etc. MIPS cores have no mechanism to generate
an abort as a result of a buffered write to memory (this is because MIPS requires
all memory aborts to be precise).
Similarly, several different events in MIPS cores are mapped to the ARM undef
exception. These include RI (unrecognized instruction), CpU (coprocessor not
enabled), FLE (floating point exception). Both architectures routinely use these
events as an entry point to soft coprocessor emulation.
The MIPS Syscall exception corresponds to the ARM SVC instruction although
the register conventions and instruction format are slightly different.
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 15
ARM DAI 0235C
MIPS and ARM compared
interrupt handler to carry out any necessary disabling of lower-priority interrupts for
instance.
ARM is similar in this assumption. In general, though, most ARM implementations
incorporate an external interrupt controller which is programmed to carry out this process
automatically, freeing up software to handle the interrupts themselves.
16 Copyright © 2010 ARM Limited. All rights reserved. Application Note 235
ARM DAI 0235C
MIPS and ARM compared
3.4 Memory
This tends to force a similar memory map across most applications implemented for MIPS
architectures. Assuming that an OS is being used and that user mode is being used to
enforce some degree of protection:
Kuseg - user processes and data
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 17
ARM DAI 0235C
MIPS and ARM compared
Kseg0 - OS kernel
Kseg1 - reset/initialization code, memory-mapped peripherals
Kseg2 - OS kernel for OS’s which use an MMU
Kseg1 is the only region of memory which is guaranteed to behave usably immediately
following reset since it is unmapped and uncached. For this reason, the reset vector
address lies within it. Following initialization (at least of the caches), many systems will
switch to executing in the Kseg0 region.
18 Copyright © 2010 ARM Limited. All rights reserved. Application Note 235
ARM DAI 0235C
MIPS and ARM compared
Both architectures have strict rules governing alignment of data in memory. Essentially,
data items must be aligned on natural boundaries. The MIPS assembler supports
synthetic macros to implement unaligned accesses; the ARM assembler has no
equivalent.
However, in ARM cores from architecture ARMv6 onwards, these alignment requirements
have been considerably relaxed. In these cores, there is hardware support for access to
unaligned data. Note that ARMv6 cores start up in a mode which is backwards compatible
with earlier behavior and the new features must be explicitly enabled if required.
3.4.5 Caches
Both architectures support similar cache configurations: Harvard L1 caches, backed by
optional unified L2 cache.
MIPS caches have either 4 or 8-word lines, can be 1, 2 or 4-way set associative and are
usually write-back. Cacheability of memory regions is part of the fixed address map
described above e.g. Kseg0 is cached, Kseg1 is uncached etc. MIPs allows very little user
configurability of cacheability beyond this.
MIPs caches are random on reset and need to be manually invalidated before they can be
enabled. This varies amongst ARM cores with earlier caches tending to be automatically
invalidated and later ones requiring manual invalidation following reset. This process is
generally more difficult on MIPS cores since the cache maintenance operations work only
with single cache lines. Many ARM cores provide “global” cache operations which can be
used, for instance, to invalidate the entire cache in a single instruction.
In both architectures, the caches are usually virtually-indexed and physically-tagged (on
most ARMv7-A cores, caches are physically-indexed and physically-tagged).
In general, MIPS operations correspond to ARM as shown in the table.
MIPS ARM
Hit Writeback Invalidate Clean and Invalidate
Hit Invalidate Invalidate
Hit Writeback Clean
Fill Preload
3.5 Debug
Both architectures provide for debug over the standard JTAG connections. The underlying
implementation, however, is a little different.
MIPS CPUs enter “debug” mode following a debug event (e.g. a breakpoint or single step
instruction). The core is still running in this state and a resident debug monitor provides
debug functionality to an external host.
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 19
ARM DAI 0235C
MIPS and ARM compared
ARM CPUs support a debug “state” in which the core is halted and isolated from the rest
of the system. The core can then be controlled from the external system via some on-chip
logic (EmbeddedICE). ARM terms this “halt mode” debugging – ARM chips also support
an alternative, “monitor” mode debugging, in which debug commands are handled by a
small resident monitor. This allows software to be debugged without halting the system.
Both systems support program and data tracing with trace data stored either in on-chip
RAM or in an external trace buffer.
To assist with performance benchmarking, both cores incorporate a range of configurable
counters which can be used to capture data in a non-intrusive manner.
20 Copyright © 2010 ARM Limited. All rights reserved. Application Note 235
ARM DAI 0235C
MIPS and ARM compared
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 21
ARM DAI 0235C
Migrating a software application
1. Code
Operating system code in a MIPS system will usually be placed in kseg0, with user code
in kuseg.
The ARM memory map allows code to be placed anywhere where there is suitable
memory. Both types of system will benefit, in terms of performance, if code is relocated to
RAM during startup. The scatter loading feature of the ARM development tools makes this
relocation essentially automatic and it is specified completely at build time.
22 Copyright © 2010 ARM Limited. All rights reserved. Application Note 235
ARM DAI 0235C
Migrating a software application
2. Data
In a MIPS system, data is located primarily depending on whether it is to be cached or not.
Cached data should be located in kseg0, uncached in kseg1.
In an ARM system, data memory can be placed anywhere, allowing data to be placed
according to space or performance requirements. The scatter-loading scheme used by
the ARM development tools makes it easy to make the correspondence between initial
values (held in ROM) and initialized data segments (established and initialized in RAM at
startup).
3. Peripherals
Peripherals in a MIPS system are generally allocated to the uncached and unmapped
kseg1 region.
In an ARM system, they can be allocated anywhere outside of any TCM regions. If an
MMU or MPU is being used, peripheral regions should be configured as uncached and
unbuffered. The scatter control file also allows you very easily to specify that these areas
are not initialized automatically during startup (using the UNINIT directive).
Some versions of the gcc compiler for MIPS define long double as a 128-bit type when
using a MIPS64 device. The MIPS SDE toolkit does not support this.
Code built for MIPS64 devices can also use 64-bit pointers if the 64-bit ABI is selected.
The major difference here when porting code is the sign of the 8-bit char type. When
porting to ARM, the problem can be ignored if necessary by switching the default using
the –unsigned_chars compiler switch.
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 23
ARM DAI 0235C
Migrating a software application
MIPS has several conventions: N32 (for 32-bit processors) and N64 (for 64-bit) are the
most common. Other (O32 for example) are generally obsolete.
The two standards are fairly similar. Each allocates a number of registers for passing the
first few parameters, with the remainder being placed on the stack. Note though that the
way in which MIPS procedures handle the stack is significantly different to ARM. This is
primarily due to the lack of “push” and “pop” type instructions in the MIPS architecture.
MIPS applications, especially those built for Linux, make extensive use of a structure
called the “Global Offset Table” in order to implement position-independent code and
data. All external references are routed to this global table of pointers which has an entry
for each external symbol. ARM has no need of this and makes use of “literal pools” to
achieve the same result.
4.3 Startup
The startup sequence for a MIPS application might look something like the following.
1. Start executing from 0xBFC0:0000 (physical 0x1FC0:0000)
SR(EXL)=1 (CPU in kernel mode, interrupts disabled)
SR(BEV)=1 (exceptions vector through uncached entry points)
2. Branch to main entry point
3. Initialize stack pointer
4. Invalidate caches
5. Invalidate TLB
6. Jump to execute in kseg0 (cached)
7. Set SR(BEV)=0 (switch exceptions to cached entry point)
8. Jump to main application entry point
24 Copyright © 2010 ARM Limited. All rights reserved. Application Note 235
ARM DAI 0235C
Migrating a software application
5. Initialize TCMs
6. Invalidate caches
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 25
ARM DAI 0235C
Migrating a software application
Non-nested IRQ handler (v6 and later) Nested IRQ handler (v6 and later)
IRQ_Handler IRQ_Handler
PUSH {r0-r3, r12, lr} SUB lr, lr, #4
BL identify_and_clear_source SRSFD sp!, #0x1f
BL C_irq_handler
POP {r0-r3, r12, lr} CPS #0x1f
SUBS pc, lr, #4
PUSH {r0-r3, r12}
BL identify_and_clear_source
CPSIE i
BL C_irq_handler
CPSID i
The nested IRQ handler re-enables IRQ interrupts (using the CPSIE instruction).
However, before doing this, to prevent corruption of the return address, it must change to
System mode (the first CPS instruction). All registers (including the return address and
SPSR) are saved on the System mode stack (this is shared with User mode).
The ARM ABI requires that the stack pointer is doubleword-aligned at public boundaries
so exception handlers must check and, if necessary, correct the alignment of the stack
prior to making any external function calls.
26 Copyright © 2010 ARM Limited. All rights reserved. Application Note 235
ARM DAI 0235C
Migrating a software application
The code for handling nested interrupts on cores prior to architecture v6 is slightly
different as these cores do not support some of the instructions used in the code shown
above (CPS, SRS and RFE).
Non-nested IRQ handler (v5 and earlier) Nested IRQ handler (v5 and earlier)
IRQ_Handler IRQ_Handler
PUSH {r0-r3, r12, lr} SUB lr, lr, #4
BL identify_and_clear_source STR lr, [sp, #-4]!
BL C_irq_handler MRS r14, SPSR
POP {r0-r3, r12, lr} STMFD sp!, {r0-r4, r12, r14}
SUBS pc, lr, #4
BL identify_and_clear_source
BL C_irq_handler
Note that this code changes state and enables/disables IRQ by reading and modifying the
CPSR directly (this is done via the CPS instruction in later processors).
When porting to an ARMv7-M architecture target, this process is much simpler as the IRQ
and FIQ handlers can be coded entirely in C as AAPCS-compliant functions. The context
save and restore operations are carried out automatically by the hardware. The
architectural vectored interrupt controller also takes care of prioritisation and dispatch.
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 27
ARM DAI 0235C
Migrating a software application
most other causes (with the exception of cache errors and TLB refills) through one further
entry. The vector table is usually constructed by explicitly locating exception handler
routines (often just stubs which call longer handler functions) at the addresses in the
vector table.
Address Exception
0xBFC0.0000 - Reset and NMI
0xBFC0.0200 - TLB refill
0xBFC0.0300 - Cache error
0xBFC0.0380 - All others (including interrupts when
Cause(IV) is clear)
0xBFC0.0400 - Interrupts (when Cause(IV) is set)
0xBFC0.0480 - Debug exceptions
The ARM vector table consists of a single word-sized entry for each of the eight possible
exceptions.
Address Exception
0x0000.0000 Reset
0x0000.0004 Undefined Instruction
0x0000.0008 Software Interrupt (SVC)
0x0000.000C Prefetch Abort
0x0000.0010 Data Abort
0x0000.0014 (Reserved)
0x0000.0018 IRQ
0x0000.001C FIQ
Each entry in the vector table typically consists of a branch instruction pointing to the start
of the relevant exception handler. For a “small” application (i.e. one in which the exception
handlers are within direct branch range of the vector table), branch instructions can be
used.
28 Copyright © 2010 ARM Limited. All rights reserved. Application Note 235
ARM DAI 0235C
Migrating a software application
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 29
ARM DAI 0235C
Migrating a software application
handler for the active interrupt automatically by the interrupt controller and branches
directly to that routine. This routine must still be written following the IRQ handler
conventions regarding context saving, register usage, re-entrancy and return instruction.
Later MIPS processors support a vectored exception mechanism in which the vector
address is broken out either into eight addresses, one for each of six hardware interrupt
sources and two for each of two software interrupts (this is Vectored Interrupt Mode) or
into up to 64 separate addresses (this is External Interrupt Controller Mode).
Vectored Interrupt Mode, if available (indicated by Config3(VInt) being set to 1), is enabled
by setting the IntCtl(VS) bit.
If an external interrupt controller is available, Config3(VEIC) will be set to 1.
Again, the situation on ARMv7-M devices is much simpler, with a single vector table
(which contains addresses) being declared.
30 Copyright © 2010 ARM Limited. All rights reserved. Application Note 235
ARM DAI 0235C
Migrating a software application
for a more detailed description of the power management facilities provided by a typical
ARM core.
When using an operating system or real-time scheduler, it is likely that the power
management features will have been built into the kernel. In this case, it is simply a case
of ensuring that your user processes make it clear to the scheduler when they are idle.
How you do this will be system-dependent.
When writing a bare metal application, you will have to insert appropriate instructions into
your code to allow the hardware to sleep when possible. For instance, busy-wait loops
should have WFI/WFE instructions inserted. However, it is more power-efficient to avoid
polling in general and implement an interrupt-driven system with power management
instructions in the main loop.
4.7 C Programming
In general, the similarities between the two architectures will mean that C code which has
been optimized for MIPS platforms should perform well when re-compiled for ARM.
Clearly any inline assembler or architecturally-specific intrinsic functions will need to be
removed, replaced or rewritten. Similarly, any cache or TLB maintenance code will need
to be rewritten. Recall that TLB management in the two architectures is significantly
different: in MIPS systems, address translation depends on run-time support code; in
ARM systems, the page tables are initialized at startup and the MMU then reads these at
run-time automatically.
Both architectures have similarly strict rules on data alignment. However, ARM cores
supporting architecture v6 and later are capable of supporting unaligned accesses in
hardware. In Cortex-A cores, this feature is permanently enabled; on earlier cores which
support backwards compatibility the feature defaults to disabled and can be enabled, if
required, by setting the U bit in CP15 register c1.
Be careful though with any data which has been declared using the packed attribute. The
declaration may need to be corrected to use the __packed keyword when using the ARM
tools.
In ARM applications, any problems with branch range are fixed up by the linker during the
build process. Consequently, there is no need to declare functions as “far” or “longcall”.
ARM as no need for any equivalent to the “GP-relative” addressing schemes common in
MIPS programs. There is therefore no need to specify an equivalent of the –Gnum
command line option nor to explicitly declare data in the .small or .comm sections.
Application Note 235 Copyright © 2010 ARM Limited. All rights reserved. 31
ARM DAI 0235C