Skip to content

Commit c7eee53

Browse files
author
Hugo
committed
fin de sys_exit avec sys_exit non-explicite. Toujours un gros doute sur le code de retour.. Je ne vois pas où on le récupère coté noyau. Variable globale ?
1 parent f8d8677 commit c7eee53

File tree

4 files changed

+48
-17
lines changed

4 files changed

+48
-17
lines changed

Aurel-Hugo/kmain.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "sched.h"
44
#define NB_PROCESS 5
55

6-
void user_process()
6+
void user_process(void)
77
{
88
int v=0;
99
for(;;)
@@ -13,10 +13,10 @@ void user_process()
1313
}
1414
}
1515

16-
void user_process_stopping()
16+
void user_process_stopping(void)
1717
{
1818
int v=0;
19-
while(v<1)
19+
while(v<2)
2020
{
2121
v++;
2222
sys_yield();

Aurel-Hugo/src/sched.c

+33-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "sched.h"
22
#include "kheap.h"
3+
#include "hw.h"
34

45
struct pcb_s* current_process;
56
struct pcb_s kmain_process;
@@ -33,13 +34,15 @@ sys_yield(void)
3334
__asm("mov lr, %0" : : "r"(current_process->lr_user));
3435
}
3536

36-
void
37+
int
3738
sys_exit(int status)
3839
{
40+
current_process->code_retour = status;
3941
__asm("mov r0, #7");
4042
__asm("swi #0");
4143
__asm("mov sp, %0" : : "r"(current_process->sp));
4244
__asm("mov lr, %0" : : "r"(current_process->lr_user));
45+
return status;
4346
}
4447

4548
/* DO_SYS_ACTION */
@@ -79,7 +82,7 @@ do_sys_yield(void)
7982
// puis on charge les registres du nouveau processus
8083
sp_sauv[i] = current_process->registres[i];
8184
}
82-
// on enregistre le CPSR de l'ancien processus
85+
// on enregistre le CPSR et lr_svc de l'ancien processus
8386
__asm("mrs %0, SPSR" : "=r"(old_process->cpsr));
8487
// puis on restaure le CPSR du nouveau processus
8588
__asm("msr SPSR, %0" : : "r"(current_process->cpsr));
@@ -118,28 +121,50 @@ sched_init(void)
118121
current_process->next = current_process;
119122
current_process->previous = current_process;
120123
current_process->etat = RUNNING;
124+
current_process->code_retour = -1;
121125
}
122126

123127
void
124128
create_process(func_t* entry)
125129
{
126130
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);
129131
struct pcb_s* pcb_res_next = current_process->next;
130132

131133
current_process->next = pcb_res;
132134
pcb_res->previous = current_process;
133135

134136
pcb_res->next = pcb_res_next;
135137
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;
136146
}
137147

138148
void
139-
elect()
149+
elect(void)
140150
{
141151
// si le processus courant tournait, alors on l'arrete
142152
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+
}

Aurel-Hugo/src/sched.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,35 @@ typedef int (func_t) (void) ;
77
typedef enum {READY, RUNNING, TERMINATED} status;
88
struct pcb_s
99
{
10-
uint32_t registres[13];
10+
uint32_t registres[13];
11+
// lr_user = start_current_process OU = pc où on a fait le yield()
1112
func_t* lr_user;
1213
func_t* lr_svc;
14+
// fonction_process = la fonction à executer par le processus (cf start_current_process)
15+
func_t* fonction_process;
1316
uint32_t* sp;
14-
uint32_t* cpsr;
17+
uint32_t cpsr;
1518
struct pcb_s* next;
1619
struct pcb_s* previous;
1720
status etat;
21+
int code_retour;
1822
};
1923

2024
// lance dest en tant que prochain processus à executer
2125
void sys_yieldto(struct pcb_s* dest);
2226
// laisse l'ordonnanceur choisir le prochain processus à executer
2327
void sys_yield();
2428
// Termine le processus courant avec le code de retour status.
25-
void sys_exit(int status);
29+
int sys_exit(int status);
2630

2731
void do_sys_yieldto(void);
2832
void do_sys_yield(void);
2933
void do_sys_exit();
3034

3135
void sched_init(void);
3236
void create_process(func_t* entry);
33-
void elect();
37+
void elect(void);
38+
//demarre le processus courant, puis appelle sys_exit()
39+
void start_current_process(void);
3440

3541
#endif

Aurel-Hugo/src/syscall.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ swi_handler(void)
8989
case 3: do_sys_settime(); break;
9090
case 4: do_sys_gettime(); break;
9191
case 5: do_sys_yieldto(); break;
92-
case 6: do_sys_yield(); break;
93-
case 7: do_sys_exit(); break;
92+
case 6: do_sys_yield(); break;
93+
case 7: do_sys_exit(); break;
9494
default: PANIC();
9595
}
9696
__asm("ldmfd sp!, {r0-r12, pc}^");

0 commit comments

Comments
 (0)