# OS_InitContext

## C Specification

      #include <nitro/os.h>

      void OS_InitContext( OSContext* context,
                           u32         newpc,
                           u32         newsp );

## Arguments

`context` | Context
`newpc` | Start address
`newsp` | Stack

## Return Values

None.

## Description

This function initializes context.

The context structure `OSContext` has the following members:

`u32 cpsr` | CPSR (Current Program Status Register)
`u32 r[13]` | Registers R0 - R12
`u32 sp` | Stack pointer (R13 register)
`u32 lr` | Link register (R14 register)
`u32 pc_plus4` | Program counter + 4 (R15 register+4)
`u32 sp_svc` | Used to save to stack in Supervisor mode (see note 1)
`CPContext cp_context` | Context for the divider / square root calculator (see note 2)

Note 1: May not exist according to compile options. Note 2: Exists only in ARM9.

With `OS_InitContext()`, the stack for SVC is secured downward from newsp. (Depending on the compile option, this process may not occur.))`cpsr` is set appropriately by checking the processor mode (distinguishing ARM and THUMB) from the CPSR register. `r[0] – r[12]` (registers R0 - R12) and `lr` (register R14) are zero-cleared. `pc_plus4` takes a value 4 more than the specified value of `newpc`.

`cp_context` exists only in ARM9, and is a context for divider / square root calculator. CPContext structure contains the following members.

`u64 div_numer` | Parameter of the divider (divisor)
`u64 div_denom` | Parameter for the divider (dividend)
`u64 sqrt` | Parameter for the square root calculator
`u16 div_mode` | Divider mode
`u16 sqrt_mode` | Square root calculator mode

`OS_InitContext()` does not change the content of `cp_context`.

## See Also

`OS_SaveContext, OS_LoadContext, OS_DumpContext
`

## Revision History

06/30/2004 Described `cp_context` .
12/01/2003 Initial version.

CONFIDENTIAL