1
1
#include "sched.h"
2
2
#include "kheap.h"
3
+ #include "hw.h"
3
4
4
5
struct pcb_s * current_process ;
5
6
struct pcb_s kmain_process ;
@@ -33,13 +34,15 @@ sys_yield(void)
33
34
__asm("mov lr, %0" : : "r" (current_process -> lr_user ));
34
35
}
35
36
36
- void
37
+ int
37
38
sys_exit (int status )
38
39
{
40
+ current_process -> code_retour = status ;
39
41
__asm("mov r0, #7" );
40
42
__asm("swi #0" );
41
43
__asm("mov sp, %0" : : "r" (current_process -> sp ));
42
44
__asm("mov lr, %0" : : "r" (current_process -> lr_user ));
45
+ return status ;
43
46
}
44
47
45
48
/* DO_SYS_ACTION */
@@ -79,7 +82,7 @@ do_sys_yield(void)
79
82
// puis on charge les registres du nouveau processus
80
83
sp_sauv [i ] = current_process -> registres [i ];
81
84
}
82
- // on enregistre le CPSR de l'ancien processus
85
+ // on enregistre le CPSR et lr_svc de l'ancien processus
83
86
__asm("mrs %0, SPSR" : "=r" (old_process -> cpsr ));
84
87
// puis on restaure le CPSR du nouveau processus
85
88
__asm("msr SPSR, %0" : : "r" (current_process -> cpsr ));
@@ -118,28 +121,50 @@ sched_init(void)
118
121
current_process -> next = current_process ;
119
122
current_process -> previous = current_process ;
120
123
current_process -> etat = RUNNING ;
124
+ current_process -> code_retour = -1 ;
121
125
}
122
126
123
127
void
124
128
create_process (func_t * entry )
125
129
{
126
130
struct pcb_s * pcb_res = (struct pcb_s * ) kAlloc (sizeof (struct pcb_s ));
127
- pcb_res -> lr_user = entry ;
128
- pcb_res -> sp = (uint32_t * ) (kAlloc (SIZE_OF_PROCESS_STACK_OCTETS ) + sizeof (uint8_t )* SIZE_OF_PROCESS_STACK_OCTETS );
129
131
struct pcb_s * pcb_res_next = current_process -> next ;
130
132
131
133
current_process -> next = pcb_res ;
132
134
pcb_res -> previous = current_process ;
133
135
134
136
pcb_res -> next = pcb_res_next ;
135
137
pcb_res_next -> previous = pcb_res ;
138
+
139
+ // pcb_res->lr_user = entry;
140
+ pcb_res -> lr_user = (func_t * )(& start_current_process );
141
+ pcb_res -> fonction_process = entry ;
142
+ pcb_res -> sp = (uint32_t * ) (kAlloc (SIZE_OF_PROCESS_STACK_OCTETS ) + sizeof (uint8_t )* SIZE_OF_PROCESS_STACK_OCTETS );
143
+ pcb_res -> code_retour = -1 ;
144
+ pcb_res -> etat = READY ;
145
+ pcb_res -> cpsr = 0b101010000 ;
136
146
}
137
147
138
148
void
139
- elect ()
149
+ elect (void )
140
150
{
141
151
// si le processus courant tournait, alors on l'arrete
142
152
current_process -> etat = (current_process -> etat == RUNNING ) ? READY : current_process -> etat ;
143
- current_process = current_process -> next ;
144
- current_process -> etat = RUNNING ;
145
- }
153
+ if (current_process == current_process -> next )
154
+ {
155
+ // il n'y a plus de processus à executer : on termine le kernel
156
+ terminate_kernel ();
157
+ }
158
+ else
159
+ {
160
+ current_process = current_process -> next ;
161
+ current_process -> etat = RUNNING ;
162
+ }
163
+ }
164
+
165
+ void
166
+ start_current_process (void )
167
+ {
168
+ current_process -> fonction_process ();
169
+ sys_exit (0 );
170
+ }
0 commit comments