@@ -6,6 +6,10 @@ struct pcb_s kmain_process;
6
6
7
7
extern unsigned int * sp_sauv ;
8
8
9
+ #define SIZE_OF_PROCESS_STACK_OCTETS 10000
10
+
11
+ /* SYS_ACTION */
12
+
9
13
void
10
14
sys_yieldto (struct pcb_s * dest )
11
15
{
@@ -26,9 +30,20 @@ sys_yield(void)
26
30
__asm("mov %0, sp" : "=r" (current_process -> sp ));
27
31
__asm("swi #0" );
28
32
__asm("mov sp, %0" : : "r" (current_process -> sp ));
29
- __asm("mov lr, %0" : : "r" (current_process -> lr_user )); // current_process est maintenant "dest"
33
+ __asm("mov lr, %0" : : "r" (current_process -> lr_user ));
34
+ }
35
+
36
+ void
37
+ sys_exit (int status )
38
+ {
39
+ __asm("mov r0, #7" );
40
+ __asm("swi #0" );
41
+ __asm("mov sp, %0" : : "r" (current_process -> sp ));
42
+ __asm("mov lr, %0" : : "r" (current_process -> lr_user ));
30
43
}
31
44
45
+ /* DO_SYS_ACTION */
46
+
32
47
void
33
48
do_sys_yieldto (void )
34
49
{
@@ -59,7 +74,7 @@ do_sys_yield(void)
59
74
int i ;
60
75
for (i = 0 ; i < 13 ; i ++ )
61
76
{
62
- // on enregistre les registres courant
77
+ // on enregistre les registres courants
63
78
old_process -> registres [i ] = sp_sauv [i ];
64
79
// puis on charge les registres du nouveau processus
65
80
sp_sauv [i ] = current_process -> registres [i ];
@@ -70,27 +85,61 @@ do_sys_yield(void)
70
85
__asm("msr SPSR, %0" : : "r" (current_process -> cpsr ));
71
86
}
72
87
88
+
89
+ void
90
+ do_sys_exit ()
91
+ {
92
+ current_process -> etat = TERMINATED ;
93
+ current_process -> previous -> next = current_process -> next ;
94
+ current_process -> next -> previous = current_process -> previous ;
95
+ struct pcb_s * to_delete = current_process ;
96
+ elect ();
97
+ kFree ((void * )to_delete -> sp , SIZE_OF_PROCESS_STACK_OCTETS );
98
+ kFree ((void * )to_delete , sizeof (struct pcb_s ));
99
+ // ici tout est propre mais il faut encore que l'on change de contexte
100
+ // on passe donc au processus suivant
101
+ int i ;
102
+ for (i = 0 ; i < 13 ; i ++ )
103
+ {
104
+ // puis on charge les registres du nouveau processus
105
+ sp_sauv [i ] = current_process -> registres [i ];
106
+ }
107
+ // puis on restaure le CPSR du nouveau processus
108
+ __asm("msr SPSR, %0" : : "r" (current_process -> cpsr ));
109
+ }
110
+
111
+ /* Autre */
112
+
73
113
void
74
114
sched_init (void )
75
115
{
76
116
kheap_init ();
77
117
current_process = & kmain_process ;
78
118
current_process -> next = current_process ;
119
+ current_process -> previous = current_process ;
120
+ current_process -> etat = RUNNING ;
79
121
}
80
122
81
123
void
82
124
create_process (func_t * entry )
83
125
{
84
126
struct pcb_s * pcb_res = (struct pcb_s * ) kAlloc (sizeof (struct pcb_s ));
85
127
pcb_res -> lr_user = entry ;
86
- pcb_res -> sp = (uint32_t * ) (kAlloc ( 10000 ) + sizeof (uint8_t )* 10000 );
128
+ pcb_res -> sp = (uint32_t * ) (kAlloc (SIZE_OF_PROCESS_STACK_OCTETS ) + sizeof (uint8_t )* SIZE_OF_PROCESS_STACK_OCTETS );
87
129
struct pcb_s * pcb_res_next = current_process -> next ;
130
+
88
131
current_process -> next = pcb_res ;
132
+ pcb_res -> previous = current_process ;
133
+
89
134
pcb_res -> next = pcb_res_next ;
135
+ pcb_res_next -> previous = pcb_res ;
90
136
}
91
137
92
138
void
93
139
elect ()
94
140
{
141
+ // si le processus courant tournait, alors on l'arrete
142
+ current_process -> etat = (current_process -> etat == RUNNING ) ? READY : current_process -> etat ;
95
143
current_process = current_process -> next ;
144
+ current_process -> etat = RUNNING ;
96
145
}
0 commit comments