Context (Overview)


Introduction

The context indicates the internal state of the system at a given time, or the data (structure) stored in that internal state. The context is normally mainly a collection of register values, but it can also contain other information. NitroSDK has a thread system that comprises an assembly of operations to save, switch and reset the context. Below is an explanation of the context information that NitroSDK will save.

There are functions to initialize the context (OS_InitContext()), save the existing context (OS_SaveContext()), load the context (OS_LoadContext()), and a function for debugging (OS_DumpContext()). But because the thread system handles these functions, the user seldom calls them directly.


Context Information

The context structure OSContext is defined as in the example below:

typedef struct OSContext
{
    u32         cpsr ;
    u32         r[13] ;
    u32         sp ;
    u32         lr ;
    u32         pc_plus4 ;

#ifdef  SDK_CONTEXT_HAS_SP_SVC
    u32         sp_svc;
#endif
#ifdef  SDK_ARM9
    CPContext   cp_context ;
#endif
} OSContext;

 

cpsr The Current Program Status Register
An ARM register value that stores the states of flags and interrupts.
r[13] The region for storing general-use registers R0 to R12
sp The region for storing the stack pointer (R13)
lr The region for storing the link register (R14)
pc_plus4 The region for storing the value of the program counter (PC)
To execute from the next command when the context is reset, the PC value is incremented by 4 and stored here.
sp_svc Takes the value of the stack pointer in SVC (supervisor call) mode
You can choose whether or not to include this information in the context by defining it at compilation time.
cp_context The status of the arithmetic coprocessor
Includes the states of the divider and the square root'er. The arithmetic unit is designed to move to the appropriate state even when the context is switched. Since the ARM7 has neither a divider nor a square root'er, this member of the context structure only exists for the ARM9. It is defined as follows:
typedef struct CPContext
{
    u64     div_numer ;
    u64     div_denom ;
    u64     sqrt ;    
    u16     div_mode ;
    u16     sqrt_mode;
} CPContext ;

See Also

List of OS Functions (Context)

Revision History

11/05/2004 Initial version