13.3.5. Context switching

Angel maintains context blocks for each task under its control through the life of the task, and saves the value of all current processor registers when a task switch occurs. It uses two groups of register context save areas:

The global register blocks: angel_GlobalRegBlock

The Angel global register blocks are used by all the exception handlers and the special functions Angel_Yield() and Angel_Wait(). Register blocks are defined as an array of seven elements. Table 13.2 shows the global register blocks.

Table 13.2. Global register blocks

Register blockDescription
RB_InterruptedThis is used by the FIQ and IRQ exception handlers.

This is used by Angel_SerialiseTask().

RB_SWIThis is saved on entry to a complex SWI and restored on return to the application.
RB_UndefThis is saved on entry to the undefined instruction handler.
RB_AbortThis is saved on entry to the abort handler.

This is used by the Angel_Yield() and Angel_Wait() functions.


This is used only in a debug build of Angel. It saves the context in which a fatal error occurred.

In the case of RB_SWI and RB_Interrupted, the register blocks contain the previous task register context so that the interrupt can be handled. If the handler function calls Angel_SerialiseTask(), the global register context is saved into the current task TQI.

In the case of RB_Yield, the register block is used to store temporarily the context of the calling task, prior to entering the serializer. The serializer saves the contents of RB_Yield to the TQI entry for the current task, if required.

The Angel task queue: angel_TQ_Pool

The serializer maintains a task queue by linking together the elements of the angel_TQ_Pool array. The task queue must contain an idle task entry. Each element of the array is a Task Queue Item (TQI). A TQI contains task information such as:

  • the register context for the task

  • the current priority of the task

  • the type of the task (for example, TP_Application)

  • the task state (for example, TS_Blocked)

  • the initial stack value for the task

  • a pointer to the next lower-priority task.

The elements in the angel_TQ_Pool array are managed by routines within the serializer and must not be modified externally.

Angel calls Angel_NewTask() to create new tasks. This function initializes a free TQI with the values required to run the task. When the task is selected for execution, Angel_SelectNextTask() loads the register context into the CPU. The context is restored to the same TQI when:

  • Angel_SerialiseTask() is called as the result of exception processing or a call to Angel_Yield()

  • Angel_Wait() determines that the task must be blocked.

When the debugger requests information about the state of the application registers, the Angel debug agent retrieves the register values from the TQI for the application. The application TQI is updated from the appropriate global register block when exceptions cause Angel code to be run.

Overview of Angel stacks for each mode

The serialization mechanism described in Angel task management ensures that only one task ever executes in Supervisor mode. Therefore, all Angel Supervisor mode tasks share a single stack, on the basis that:

  • it is always empty when a task starts

  • when the task returns, all information that was on the stack is lost.

The application uses its own stack, and executes in either User or Supervisor mode. Callbacks due to application requests to read or write from devices under control of the Device Driver Architecture execute in User mode, and use the application stack.

The following Angel stacks are simple stacks exclusively used by one thread of control. This is ensured by disabling interrupts in the corresponding processor modes:

  • IRQ stack

  • FIQ stack

  • UND stack

  • ABT stack.

The User mode stack is also split into two cases, because the Application stack and Angel stack are kept entirely separate. The Angel User mode stack is split into array elements that are allocated to new tasks, as required. The application stack must be defined by the application.

Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0040D