= GIET-VM / Context Switch Handler = [[PageOutline]] The [source:soft/giet_vm/giet_kernel/ctx_handler.c ctx_handler.c] and [source:soft/giet_vm/giet_kernel/ctx_handler.h ctx_handler.h] files define the data structure and functions used to handle context switching. They are prefixed by "_" to remind that they can only be executed by a processor in kernel mode. A task context is an array of 64 words = 256 bytes. It contains copies of processor registers (when the task is preempted): * GPR[i] : generally stored in slot (i). $0, $26 & $27 are not saved. * HI & LO registers : used by multiply/divide instructions. * CP0 registers : EPC, SR, CR, BVAR * CP2 registers : PTPR It contains some general informations associated to the task: * TTY : TTY channel global index * NIC : NIC channel global index * CMA : CMA channel global index * HBA : HBA channel global index * DMA : DMA channel local index * TIM : TIM channel local index * PTAB : page table virtual base address * LTID : Task local index (in scheduler) * VSID : Virtual space index * RUN : Task state (0 => sleeping / 1 => runnable ) * TRDID : Thread ID index (in vspace) || [0] *** || [8] $8 || [16] $16 || [24] $24 || [32] EPC || [40] TTY || [48] TRDID || || [1] $1 || [9] $9 || [17] $17 || [25] $25 || [33] CR || [41] DMA || [49] *** || || [2] $2 || [10] $10 || [18] $18 || [26] LO || [34] SR || [42] NIC || [50] *** || || [3] $3 || [11] $11 || [19] $19 || [27] HI || [35] BVAR || [43] TIM || [51] *** || || [4] $4 || [12] $12 || [20] $20 || [28] $28 || [36] PTAB || [44] HBA || [52] *** || || [5] $5 || [13] $13 || [21] $21 || [29] SP || [37] LTID || [45] CMA || [53] *** || || [6] $6 || [14] $14 || [22] $22 || [30] $30 || [38] VSID || [46] GTID || [54] *** || || [7] $7 || [15] $15 || [23] $23 || [31] RA | [39] PTPR || [47] RUN || [55] *** || === unsigned int _get_current_task_id( void ) === This function returns the local task index for the task currently running on the processor. === unsigned int _get_task_slot( unsigned int gpid, unsigned int ltid, unsigned int slot ) This function returns the content of a context ''slot'' for a task identified by the the ''gpid'' argument (global processor index), and the ''ltid'' argument (local task index on the processor). === void _set_task_slot( unsigned int gpid, unsigned int ltid, unsigned int slot, unsigned int value ) This function writes ''value'' in the the context ''slot'' of the task identified by the the ''gpid'' argument (global processor index), and the ''ltid'' argument (local task index on the processor). === unsigned int _get_context_slot( unsigned int slot ) This function returns the content of a context ''slot'' for the calling task. === void _set_task_slot( unsigned int slot, unsigned int value ) This function writes ''value'' in the the context ''slot'' of the running task.