Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

switching between ARM/THUMB state

Tags:

arm

Why should an ARM controller return to ARM state from THUMB state, when an exception occurs?

like image 896
user188424 Avatar asked Jan 23 '23 03:01

user188424


2 Answers

One explanation might be that ARM mode is the CPU's "native" operating mode, and that it's possible to do more operations in that mode than in the limited Thumb mode. The Thumb mode, as far as I've understood, is optimized for code size, which might mean it lacks certain instructions that perhaps are necessary in exception processing.

This page mentions that exception processing is always done in ARM mode. It doesn't provide any reasons why, so maybe it's just The Way It Is, by design. It does talk about ways to exit from exception processing back to the proper (ARM or Thumb) mode though, so as long as you're not writing the exception handler yourself, you might be able to ignore this issue. That, of course, assumes that your system is set up with a "default" exception handler that does retain the execution mode.

On the other hand, this page says this, about the interrupt vectors of the Cortex-M3 ARM implementation:

The LSB of each exception vector indicates whether the exception is to be executed in the Thumb state.

So it doesn't seem to be universally true, perhaps you can make your particular exception run in Thumb mode.

like image 195
unwind Avatar answered Feb 12 '23 21:02

unwind


Perhaps it is because that the interrupt vector table is really an ARM instruction and to process it requires being in ARM mode. This reduces the programmers job as you dont have to write two handlers one for arm mode and one for thumb mode. How would you even know there is one entry point for an exception and you can only have one instruction type to handle it. You can certainly switch to thumb mode once entered no different than switching to thumb mode after a reset exception.

The cortex-m3 has re-defined the interrupt vector table to be more traditional (an address instead of an instruction). By necessity I would assume, the cortex-m3 is a thumb(2) only processor so either they re-define the vector table to hold thumb instructions or they re-define the table with addresses, or they have just enough of an arm core to process the load or jump that you normally see in a vector table entry.

Basically you would either need two entries per exception, one for the arm based handler and one for the thumb based handler or you require the user to write their handler with an entry point that is one mode specifically.

Even with the one mode entry point into a handler, you still have to be aware of the mode the processor was in when the exception occurred to know what address to return to and how to inspect the instruction in question that caused the exception.

like image 33
old_timer Avatar answered Feb 12 '23 23:02

old_timer