Domain/ARM
[ARM] Exception generating codes...
yhcting
2006. 5. 13. 14:00
[[ blog 이사 과정에서 정확한 posting날짜가 분실됨. 년도와 분기 정도는 맞지 않을까? ]]
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.