[ARM] Exceptions…

Here are unexpected exceptions that can be occurred in SW(ARM).

  * Data Abort
  * Prefetch
  * Undefined Instruction
  * Divide by zero.

And here is sample code to raise these exceptions.

#pragma O0   /* disable all optimization */

typedef void (*_FuncT)(void);
void _test_data_abort(void)
{
    int   c;
    int*  p = (int*)0xdeaddead;
    c = *p;
}

void _test_prefetch_abort(void)
{
    _FuncT  f;
    f = (_FuncT)0xdeaddead;
    (*f)();
}

static const int _undef_inst = 0xff0000ff;
void _test_undefined_instruction()
{
    _FuncT f;
    f = (_FuncT)(&_undef_inst);
    (*f)();
}

(divide by zero) is omitted

In ‘_test_undefined_instruction()’ , variable ‘_undef_inst’ is located at 4byte-aligned-position. So, program mode becomes ARM mode when “f=(_FuncT)(&_undef_inst);” is executed – BX to 4byte-aligned-address (address & 0x1 == 0x00).

“MSB <–FFxxxxxx–> LSB” area is ‘undefined instruction’ area in ARM instruction. So, we can make endian-independent-‘undefined instruction’ by setting ‘_undef_inst’ as 0xff0000ff.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s