29.10.2014 Views

ARM Compiler toolchain v4.1 for µVision Using the Compiler

ARM Compiler toolchain v4.1 for µVision Using the Compiler

ARM Compiler toolchain v4.1 for µVision Using the Compiler

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

<strong>Compiler</strong> Coding Practices<br />

5.55 Examining parameters when integer division-by-zero errors occur in C code<br />

If you want to examine parameters and save <strong>the</strong>m <strong>for</strong> postmortem debugging, you can trap<br />

__aeabi_idiv0. You can intervene in all calls to __aeabi_idiv0 by using <strong>the</strong> $Super$$ and $Sub$$<br />

mechanism.<br />

To examine parameters when integer division-by-zero occurs:<br />

1. Prefix __aeabi_idiv0() with $Super$$ to identify <strong>the</strong> original unpatched function<br />

__aeabi_idiv0().<br />

2. Use __aeabi_idiv0() prefixed with $Super$$ to call <strong>the</strong> original function directly.<br />

3. Prefix __aeabi_idiv0() with $Sub$$ to identify <strong>the</strong> new function to be called in place of<br />

<strong>the</strong> original version of __aeabi_idiv0().<br />

4. Use __aeabi_idiv0() prefixed with $Sub$$ to add processing be<strong>for</strong>e or after <strong>the</strong> original<br />

function __aeabi_idiv0().<br />

5.55.1 Example<br />

Example 5-5 illustrates <strong>the</strong> use of <strong>the</strong> $Super$$ and $Sub$$ mechanism to intercept __aeabi_div0.<br />

Example 5-5 Intercepting __aeabi_div0 using $Super$$ and $Sub$$<br />

extern void $Super$$__aeabi_idiv0(void);<br />

/* this function is called instead of <strong>the</strong> original __aeabi_idiv0() */<br />

void $Sub$$__aeabi_idiv0()<br />

{<br />

// insert code to process a divide by zero<br />

...<br />

// call <strong>the</strong> original __aeabi_idiv0 function<br />

$Super$$__aeabi_idiv0();<br />

}<br />

5.55.2 See also<br />

Concepts<br />

• Integer division-by-zero errors in C code on page 5-67.<br />

<strong>Using</strong> <strong>the</strong> Linker:<br />

• <strong>Using</strong> $Super$$ and $Sub$$ to patch symbol definitions on page 7-28.<br />

O<strong>the</strong>r in<strong>for</strong>mation<br />

• Run-time ABI <strong>for</strong> <strong>the</strong> <strong>ARM</strong> Architecture,<br />

http://infocenter.arm.com/help/topic/com.arm.doc.ihi0043-/index.html.<br />

<strong>ARM</strong> DUI 0375C Copyright © 2007-2008, 2011 <strong>ARM</strong>. All rights reserved. 5-71<br />

ID061811<br />

Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!