05.02.2013 Views

ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The System Level Programmers’ Model<br />

B1.6.12 Supervisor Call (SVC) exception<br />

The Supervisor Call instruction SVC enters Supervisor mode <strong>and</strong> requests a supervisor function. Typically,<br />

the SVC instruction is used to request an operating system function. For more information, see SVC<br />

(previously SWI) on page A8-430.<br />

Note<br />

In previous versions of the <strong>ARM</strong> architecture, the SVC instruction was called SWI, Software Interrupt.<br />

The following pseudocode describes how this exception is taken:<br />

// TakeSVCException()<br />

// ==================<br />

TakeSVCException()<br />

// Determine return information. SPSR is to be the current CPSR, after changing the IT[]<br />

// bits to give them the correct values for the following instruction, <strong>and</strong> LR is to be<br />

// the current PC minus 2 for Thumb or 4 for <strong>ARM</strong>, to change the PC offsets of 4 or 8<br />

// respectively from the address of the current instruction into the required address of<br />

// the next instruction (the SVC instruction having size 2 or 4 bytes respectively).<br />

ITAdvance();<br />

new_lr_value = if CPSR.T == ‘1’ then PC-2 else PC-4;<br />

new_spsr_value = CPSR;<br />

// Enter Supervisor (‘10011’) mode, <strong>and</strong> ensure Secure state if initially in Monitor<br />

// (‘10110’) mode. This affects the banked versions of various registers accessed later<br />

// in the code.<br />

if CPSR.M == ‘10110’ then SCR.NS = ‘0’;<br />

CPSR.M = ‘10011’;<br />

// Write return information to registers, <strong>and</strong> make further CPSR changes: IRQs disabled,<br />

// IT state reset, instruction set <strong>and</strong> endianness to SCTLR-configured values.<br />

SPSR[] = new_spsr_value;<br />

R[14] = new_lr_value;<br />

CPSR.I = ‘1’;<br />

CPSR.IT = ‘00000000’;<br />

CPSR.J = ‘0’; CPSR.T = SCTLR.TE; // TE=0: <strong>ARM</strong>, TE=1: Thumb<br />

CPSR.E = SCTLR.EE; // EE=0: little-endian, EE=1: big-endian<br />

// Branch to SVC vector.<br />

BranchTo(ExcVectorBase() + 8);<br />

The preferred exception return from an SVC exception is a return to the next instruction after the SVC<br />

instruction. Use the LR <strong>and</strong> SPSR values generated by the exception entry to produce this return by using<br />

an exception return instruction without a subtraction.<br />

For more information, see Exception return on page B1-38.<br />

B1-52 Copyright © 1996-1998, 2000, 2004-2008 <strong>ARM</strong> Limited. All rights reserved. <strong>ARM</strong> DDI 0406B

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!