source: soft/giet_vm/giet_kernel/ctx_handler.h @ 310

Last change on this file since 310 was 310, checked in by alain, 10 years ago

Reducing the number of log messages.

  • Property svn:executable set to *
File size: 5.3 KB
Line 
1/////////////////////////////////////////////////////////////////////////////////////////
2// File     : ctx_handler.h
3// Date     : 01/04/2012
4// Authors  : alain greiner & joel porquet
5// Copyright (c) UPMC-LIP6
6/////////////////////////////////////////////////////////////////////////////////////////
7// The ctx_handler.h and ctx_handler.c files are part of the GIET-VM nano-kernel.
8// This code is used to support context switch when several tasks are executing
9// in time multiplexing on a single processor.
10// The tasks are statically allocated to a processor in the boot phase, and
11// there is one private scheduler per processor. Each sheduler occupies 4K bytes,
12// and contains up to 14 task contexts (task_id is from 0 to 13).
13// The task context [13] is reserved for the "idle" task that does nothing, and
14// is launched by the scheduler when there is no other runable task.
15/////////////////////////////////////////////////////////////////////////////////////////
16// A task context is an array of 64 words = 256 bytes.
17// It contains copies of processor registers (when the task is preempted):
18// - GPR[i], generally stored in slot (i). $0, $26 & $27 are not saved.
19// - HI & LO registers
20// - CP0 registers: EPC, SR, CR, BVAR
21// - CP2 registers : PTPR
22// It contains some general informations associated to the task:
23// - TTY    : TTY channel global index
24// - NIC    : NIC channel global index
25// - CMA    : CMA channel global index
26// - HBA    : HBA channel global index
27// - DMA    : DMA channel local index
28// - TIM    : TIM channel local index
29// - PTAB   : page table virtual base address
30// - LTID   : Task local index (in scheduler)
31// - VSID   : Virtual space index
32// - RUN    : Task state (0 => sleeping / 1 => runnable )
33// - TRDID  : Thread ID index (in vspace)
34//
35// ctx[0] <- ***   |ctx[8] <- $8    |ctx[16]<- $16   |ctx[24]<- $24
36// ctx[1] <- $1    |ctx[9] <- $9    |ctx[17]<- $17   |ctx[25]<- $25
37// ctx[2] <- $2    |ctx[10]<- $10   |ctx[18]<- $18   |ctx[26]<- LO
38// ctx[3] <- $3    |ctx[11]<- $11   |ctx[19]<- $19   |ctx[27]<- HI
39// ctx[4] <- $4    |ctx[12]<- $12   |ctx[20]<- $20   |ctx[28]<- $28
40// ctx[5] <- $5    |ctx[13]<- $13   |ctx[21]<- $21   |ctx[29]<- SP
41// ctx[6] <- $6    |ctx[14]<- $14   |ctx[22]<- $22   |ctx[30]<- $30
42// ctx[7] <- $7    |ctx[15]<- $15   |ctx[23]<- $23   |ctx[31]<- RA
43//
44// ctx[32]<- EPC   |ctx[40]<- TTY   |ctx[48]<- TRDID |
45// ctx[33]<- CR    |ctx[41]<- DMA
46// ctx[34]<- SR    |ctx[42]<- NIC
47// ctx[35]<- BVAR  |ctx[43]<- TIM
48// ctx[36]<- PTAB  |ctx[44]<- HBA
49// ctx[37]<- LTID  |ctx[45]<- CMA
50// ctx[38]<- VSID  |ctx[46]<- GTID
51// ctx[39]<- PTPR  |ctx[47]<- RUN
52/////////////////////////////////////////////////////////////////////////////////////////
53
54#ifndef _CTX_HANDLER_H
55#define _CTX_HANDLER_H
56
57#include <giet_config.h>
58
59/////////////////////////////////////////////////////////////////////////////////
60//    Definition of the scheduler structure
61/////////////////////////////////////////////////////////////////////////////////
62
63typedef struct static_scheduler_s
64{
65    unsigned int context[14][64];      // at most 14 task (including idle_task)
66    unsigned int tasks;                // actual number of tasks
67    unsigned int current;              // current task index
68    unsigned int hwi_vector[32];       // hardware interrupt vector
69    unsigned int pti_vector[32];       // timer    interrupt vector
70    unsigned int wti_vector[32];       // software interrupt vector
71    unsigned int reserved[30];         // padding to 4 Kbytes
72} static_scheduler_t;
73
74
75/////////////////////////////////////////////////////////////////////////////////
76//  "idle" task index definition
77/////////////////////////////////////////////////////////////////////////////////
78
79#define IDLE_TASK_INDEX        13
80
81/////////////////////////////////////////////////////////////////////////////////
82//    Definition of the task context slots indexes
83/////////////////////////////////////////////////////////////////////////////////
84
85#define CTX_SP_ID        29  // Stack Pointer
86#define CTX_RA_ID        31  // Return Address
87
88#define CTX_EPC_ID       32  // Exception Program Counter (CP0)
89#define CTX_CR_ID        33  // Cause Register (CP0)
90#define CTX_SR_ID        34  // Status Register (CP0)
91#define CTX_BVAR_ID      35      // Bad Virtual Address Register (CP0)
92#define CTX_PTAB_ID      36  // Page Table Virtual address
93#define CTX_LTID_ID      37  // Local  Task Index (in scheduler)
94#define CTX_VSID_ID      38  // Vspace Index     
95#define CTX_PTPR_ID      39  // Page Table Pointer Register (PADDR>>13)
96
97#define CTX_TTY_ID       40  // global TTY channel   
98#define CTX_DMA_ID       41  // local DMA channel
99#define CTX_NIC_ID       42  // global NIC channel
100#define CTX_TIM_ID       43  // local TIMER channel
101#define CTX_HBA_ID       44  // global HBA channel
102#define CTX_CMA_ID       45  // global CMA channel
103#define CTX_GTID_ID      46  // Global Task Index
104#define CTX_RUN_ID       47  // Boolean: task runable
105
106#define CTX_TRDID_ID     48  // Thread Index in vspace
107
108//////////////////////////////////////////////////////////////////////////////////
109//     Prototype of the context switch function
110//////////////////////////////////////////////////////////////////////////////////
111
112extern void _ctx_switch();
113extern void _ctx_eret();
114extern void _idle_task();
115
116extern static_scheduler_t _scheduler[];
117
118#endif
Note: See TracBrowser for help on using the repository browser.