# 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
> A region that stores the register where the status of flags and interrupt states.

> 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 Can be included or excluded according to the definitions during compilation. The value for the stack pointer for SVC (supervisor call) mode is entered here.

> cp_context The status of the arithmetic coprocessor Includes the states of the divider and the square rooter. The arithmetic unit is designed to move to the appropriate state even if the context is switched. Since the ARM7 has neither a divider nor a square rooter, 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

12/13/2004 Corrected typos
11/05/2004 Initial version

CONFIDENTIAL