My Project
Chargement...
Recherche...
Aucune correspondance
appelsysteme.c
Aller à la documentation de ce fichier.
1
7#include <manux/appelsysteme.h>
8
9#include <manux/errno.h>
10#include <manux/printk.h>
11#include <manux/debug.h>
12#include <manux/scheduler.h> // sys_basculerTache
13#include <manux/memoire.h> // AS_obtenirPages, à virer aprés dispatch
14#include <manux/console.h> // Console
15#ifdef MANUX_TACHES
16# include <manux/tache.h> // sysFork
17#endif
18#ifdef MANUX_TUBES
19# include <manux/tubes.h> // sys_tube
20#endif
21#if defined(MANUX_TACHES) && !defined(MANUX_REENTRANT)
22# include <manux/exclusion-mutuelle.h> // Mutex
23#endif
24
25#include <manux/horloge.h>
26
28
32static
33int sys_dumbAS(ParametreAS as)
34{
35 (void) as;
36 printk("I am so useless, ...\n");
37
39
40 printk("It took me some time, ...\n");
41
42 return 4832;
43}
44
45#ifdef MANUX_AS_TEST_SYNCHRO
53static int testSynchroCompteur = 0;
54#define MANUX_AS_TEST_SYNCHRO_DELAI 500
55
56int sys_testSynchroAS(ParametreAS as, int inc, int action)
57{
58 int x;
59
60 x = testSynchroCompteur;
61
62 switch (action) {
63 case 1 :
65 break;
66 case 2:
67 attenteMilliSecondes(MANUX_AS_TEST_SYNCHRO_DELAI);
68 break;
69 default :
70 }
71
72 x += inc;
73 testSynchroCompteur = x;
74
75 return testSynchroCompteur;
76}
77#endif // MANUX_AS_TEST_SYNCHRO
78
82static
83int sys_erreurAS(ParametreAS as)
84{
85 paniqueNoyau("Appel systeme %d non implante !\n", as.eax);
86
87 return 0;
88}
89
90int definirAppelSysteme(int num, void * appel)
91{
92 // C'est plus prudent
94
95 // Attention, il faut tenir compte de la valeur de retour !!
96 // Pour le moment, je ne suis pas très clair là dessus (voir par
97 // exemple la fonction suivante) donc on maintient l'assert
98 // précédente.
99 if ((num < 0) || (num >= NB_MAX_APPELS_SYSTEME)) {
100 return EINVAL;
101 } else {
102 printk_debug(DBG_KERNEL_AS, "Appel sys %d loaded\n", num);
103 vecteurAppelsSysteme[num] = appel;
104 return ESUCCES;
105 }
106}
107
109{
110 printk_debug(DBG_KERNEL_AS, "vecteur des AS = 0x%x\n", vecteurAppelsSysteme);
111
112 for (int a = 0; a < NB_MAX_APPELS_SYSTEME; a++) {
113 definirAppelSysteme(a, sys_erreurAS);
114 }
115
116 definirAppelSysteme(NBAS_DUMB, sys_dumbAS);
117
118#ifdef MANUX_AS_TEST_SYNCHRO
119 definirAppelSysteme(NBAS_TEST_SYNC, sys_testSynchroAS);
120#endif
121
122 /* Envoyer une chaîne de caractères sur la console */
123 definirAppelSysteme(NBAS_ECRIRE_CONS, sys_ecrireConsole);
124
125#ifdef MANUX_TACHES
126 // Création d'une nouvelle tâche
128
129 // Invocation explicite de l'ordonnanceur
131#endif
132
133#ifdef MANUX_TUBES
134 // Création d'un tube de communiations entre tâches
135 definirAppelSysteme(NBAS_TUBE, sys_tube);
136#endif
137
139
140 /* Les suivants sont à revoir */
141 //definirAppelSysteme(NBAS_CONSOLE, AS_console);
142 //definirAppelSysteme(NBAS_OBTENIR_PAGES, AS_obtenirPages);
143 //definirAppelSysteme(NBAS_FORK, sysFork);
144
145#if defined(MANUX_TACHES) && !defined(MANUX_REENTRANT)
146 tacheDansLeNoyau= 0;
147 exclusionMutuelleInitialiser(&verrouGeneralDuNoyau);
148#endif
149}
150
155{
156 printk_debug(DBG_KERNEL_AS, "Appel sys %d IN\n", num);
157
158#if defined(MANUX_TACHES) && !defined(MANUX_REENTRANT)
163# ifdef MANUX_TUBE_REENTRANT
164 if (num != NBAS_TUBE) {
165# endif
166 exclusionMutuelleEntrer(&verrouGeneralDuNoyau);
167 assert(tacheDansLeNoyau == 0);
168 tacheDansLeNoyau = tacheEnCours->numero;
169# ifdef MANUX_TUBE_REENTRANT
170 }
171# endif
172#endif
173
174#ifdef MANUX_AS_AUDIT
175 tacheEnCours->nbAppelsSystemeIn[num]++;
176#endif
177}
178
183{
184
185 printk_debug(DBG_KERNEL_AS, "Appel sys %d OUT\n", num);
186
187#if defined(MANUX_TACHES) && !defined(MANUX_REENTRANT)
192# ifdef MANUX_TUBE_REENTRANT
193 if (num != NBAS_TUBE) {
194# endif
195 tacheDansLeNoyau = 0;
196 exclusionMutuelleSortir(&verrouGeneralDuNoyau);
197# ifdef MANUX_TUBE_REENTRANT
198 }
199# endif
200#endif
201
202#ifdef MANUX_AS_AUDIT
203 tacheEnCours->nbAppelsSystemeOut[num]++;
204#endif
205}
206
207
void * vecteurAppelsSysteme[NB_MAX_APPELS_SYSTEME]
void entrerAppelSysteme(uint32_t num)
Prélude à un appel système.
int definirAppelSysteme(int num, void *appel)
void sortirAppelSysteme(uint32_t num)
Fin d'un appel système.
void initialiserAppelsSysteme(void)
Définition des exlusions mutuelles.
void exclusionMutuelleEntrer(ExclusionMutuelle *em)
Entrée en exclusion mutuelle.
void exclusionMutuelleInitialiser(ExclusionMutuelle *em)
Initialisation d'une exclusion mutuelle.
void exclusionMutuelleSortir(ExclusionMutuelle *em)
NO_OPTIMIZE void attenteMilliSecondes(int n)
Attente active de n millisecondes.
Definition horloge.c:115
#define NB_MAX_APPELS_SYSTEME
#define NBAS_CREER_TACHE
#define NBAS_DUMB
#define NBAS_BASCULER_TACHE
#define NBAS_ECRIRE_CONS
#define NBAS_IDENTIFIANT_TACHE
Définition des fonctions de base d'accés à la console.
#define EINVAL
Definition errno.h:14
#define ESUCCES
Definition errno.h:10
typedef void(Handler(void))
Définition des fonctions de base d'entrée-sortie du noyau.
void printk(char *format,...)
Fonction principale d'affichage dans le noyau.
Definition printk.c:166
unsigned long uint32_t
Definition types.h:20
uint16_t a
Exemple de fonction de mise-à-jour d'un paramètre dans un registre.
#define assert(cond)
Definition debug.h:126
#define paniqueNoyau(fmt, args...)
Definition debug.h:107
#define printk_debug(lvl, fmt, args...)
Definition debug.h:86
#define DBG_KERNEL_AS
Definition debug.h:28
int sys_identifiantTache(void)
TacheID sys_creerTache(ParametreAS as, CorpsTache corpsTache, booleen shareConsole)
Tache * tacheEnCours
: L'identification de la tâche en cours
Definition scheduler.c:91
void ordonnanceur(void)
Basculer vers la prochaine tache à exécuter.
Definition scheduler.c:98
int sys_basculerTache(ParametreAS as)
uint32_t eax
TacheID numero
Definition tache.h:88