Skip to content

Commit e5efd04

Browse files
committed
CHAPITRE 6.4 SOLIDITE DU MIDI 12h00
1 parent 86cd532 commit e5efd04

File tree

12 files changed

+1579
-1505
lines changed

12 files changed

+1579
-1505
lines changed

Loic-Jo/sysif/build/kernel.elf

492 Bytes
Binary file not shown.

Loic-Jo/sysif/build/kernel.list

+1,316-1,229
Large diffs are not rendered by default.

Loic-Jo/sysif/build/kmain.md5

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
505603315a32dfd59d2f63b102ce6cd4 /home/jtaws/Documents/GitHub/SEA/Loic-Jo/sysif/test/kmain-yieldto.c
1+
54302c1afb0b870b2246aeb11b46e653 /home/jtaws/Documents/GitHub/SEA/Loic-Jo/sysif/test/kmain-yield.c

Loic-Jo/sysif/build/kmain.o

-664 Bytes
Binary file not shown.

Loic-Jo/sysif/build/mapfile.map

+164-168
Large diffs are not rendered by default.

Loic-Jo/sysif/build/sched.o

1.08 KB
Binary file not shown.

Loic-Jo/sysif/build/syscall.o

100 Bytes
Binary file not shown.

Loic-Jo/sysif/kmain.c

+14-93
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,15 @@
22
#include "util.h"
33
#include "sched.h"
44

5-
//struct pcb_s pcb1, pcb2;
6-
7-
struct pcb_s *p1, *p2;
8-
9-
void
10-
dummy()
11-
{
12-
return;
13-
}
14-
15-
int
16-
div(int dividend, int divisor)
17-
{
18-
int result = 0;
19-
int remainder = dividend;
20-
21-
while(remainder >= divisor) {
22-
result++;
23-
remainder -= divisor;
24-
}
25-
26-
return result;
27-
}
28-
29-
int
30-
compute_volume(int rad)
31-
{
32-
int rad3 = rad * rad * rad;
33-
34-
return div(4*355*rad3, 3*113);
35-
}
36-
37-
void
38-
user_process_1()
39-
{
40-
int v1=5;
41-
while(1){
42-
v1++;
43-
sys_yieldto(p2);
44-
}
45-
}
46-
5+
#define NB_PROCESS 5
476

487
void
49-
user_process_2()
8+
user_process()
509
{
51-
int v2=-12;
10+
int v=0;
5211
while(1){
53-
v2-=2;
54-
sys_yieldto(p1);
12+
v++;
13+
sys_yield();
5514
}
5615
}
5716

@@ -60,54 +19,16 @@ void
6019
kmain(void){
6120
sched_init();
6221

63-
p1 = create_process((func_t*) &user_process_1);
64-
p2 = create_process((func_t*) &user_process_2);
65-
66-
//~ p1 = &pcb1;
67-
//~ p2 = &pcb2;
68-
69-
//initialize p1 and p2
70-
71-
//CODE
72-
//~ pcb1.lr_user = (uint32_t) &user_process_1;
73-
//~ pcb2.lr_user = (uint32_t) &user_process_2;
22+
int i;
23+
for(i=0;i<NB_PROCESS;i++)
24+
{
25+
create_process((func_t*) &user_process);
26+
}
7427

7528
__asm("cps 0x10"); // switch CPU to USER mode
7629

77-
sys_yieldto(p1);
78-
79-
// unreachable
80-
PANIC();
81-
}
82-
83-
84-
/*
85-
int
86-
kmain(void)
87-
{
88-
//__asm("cps 0x10");
89-
// SWI
90-
//sys_reboot();
91-
92-
//while(1) {
93-
// sys_nop();
94-
//}
95-
//sys_reboot();
96-
uint64_t date_ms = 0x12345678cacacaca;
97-
sys_settime(date_ms);
98-
99-
// User
100-
//__asm("cps #19");
101-
//__asm("mov r14, r11");
102-
//__asm("mov cpsr, r12");
103-
// System
104-
//__asm("cps #31");
105-
int radius = 5;
106-
int volume;
107-
108-
dummy();
109-
volume = compute_volume(radius);
110-
111-
return volume;
30+
while(1)
31+
{
32+
sys_yield();
33+
}
11234
}
113-
*/

Loic-Jo/sysif/src/sched.c

+70-4
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,82 @@ uint32_t sp_user;
1010
void sched_init()
1111
{
1212
current_process = &kmain_process;
13+
current_process->next_pcb = current_process;
1314
kheap_init();
1415
}
1516

16-
struct pcb_s* create_process(func_t* entry)
17+
void create_process(func_t* entry)
1718
{
19+
// Allocation de la place pour la pcb
1820
struct pcb_s * pcb = (struct pcb_s *) kAlloc(sizeof(struct pcb_s));
21+
22+
// Mise en place du lr_svc, lr_user, et du cpsr
1923
pcb->lr_svc = (uint32_t) entry;
2024
pcb->lr_user = (uint32_t) entry;
2125
__asm("mrs %0, cpsr" : "=r"(pcb->cpsr));
2226

27+
// Allocation de la stack, et on fait pointer sp tout en haut de ce qu'on vient allouer vu que SP décroit
2328
uint32_t * sp_zone = (uint32_t *) kAlloc(10000);
2429
pcb->sp = (uint32_t) sp_zone + 10000;
2530

26-
return pcb;
31+
// On chaîne de manière circulaire current_process
32+
struct pcb_s * temp_pcb = current_process->next_pcb;
33+
current_process->next_pcb = pcb;
34+
pcb->next_pcb = temp_pcb;
35+
36+
return;
37+
}
38+
39+
void elect()
40+
{
41+
current_process = current_process->next_pcb;
42+
}
43+
44+
void sys_yield()
45+
{
46+
__asm("mov r0, #6");
47+
__asm("SWI #0");
48+
}
49+
50+
void do_sys_yield(uint32_t * sp_param_base)
51+
{
52+
// save lr_user and sp_user
53+
__asm("cps #31"); // Mode système
54+
__asm("mov %0, lr" : "=r"(current_process->lr_user));
55+
__asm("mov %0, sp" : "=r"(current_process->sp));
56+
__asm("cps #19"); // Retour au mode SVC
57+
58+
// Sauvegarde de spsr dans current_process
59+
__asm("mrs %0, spsr" : "=r"(current_process->cpsr));
60+
61+
// save context into the current_process struct
62+
int i;
63+
for (i = 0; i < 13 ; i++) {
64+
current_process->regs[i] = *(sp_param_base + i);
65+
}
66+
// Sauvegarde du LR_SVC
67+
current_process->lr_svc = *(sp_param_base + 13);
68+
69+
70+
//changement de proccess
71+
elect();
72+
73+
74+
// retrieve lr_user and sp_user
75+
__asm("cps #31"); // Mode système
76+
__asm("mov lr, %0" : : "r"(current_process->lr_user));
77+
__asm("mov sp, %0" : : "r"(current_process->sp));
78+
__asm("cps #19"); // Retour au mode SVC
79+
80+
// On met le cpsr du current process dans spsr
81+
__asm("msr spsr, %0" : : "r"(current_process->cpsr));
82+
83+
// retreive data from current_process struct into context
84+
for (i = 0; i < 13 ; i++) {
85+
*(sp_param_base + i) = current_process->regs[i];
86+
}
87+
// Restitution du LR_SVC
88+
*(sp_param_base + 13) = current_process->lr_svc;
2789
}
2890

2991
void sys_yieldto(struct pcb_s * dest)
@@ -54,18 +116,22 @@ void do_sys_yieldto(uint32_t * sp_param_base)
54116
*(sp_param_base + i) = dest->regs[i];
55117
}
56118

119+
// Sauvegarde du LR_SVC
57120
current_process->lr_svc = *(sp_param_base + 13);
58121
*(sp_param_base + 13) = dest->lr_svc;
59122

60-
__asm("mrs %0, spsr" : "=r"(current_process->cpsr)); // /** Bijour, ci moi la banane qui code :) **/
123+
// Sauvegarde de spsr dans current_process
124+
__asm("mrs %0, spsr" : "=r"(current_process->cpsr));
61125

126+
//changement de proccess
62127
current_process = dest;
63128

64129
__asm("cps #31"); // Mode système
65130
__asm("mov lr, %0" : : "r"(current_process->lr_user));
66131
__asm("mov sp, %0" : : "r"(current_process->sp));
67132
__asm("cps #19"); // Retour au mode SVC
68-
__asm("msr spsr, %0" : : "r"(current_process->cpsr));
69133

134+
// On met le cpsr du current process dans spsr
135+
__asm("msr spsr, %0" : : "r"(current_process->cpsr));
70136
}
71137

Loic-Jo/sysif/src/sched.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,21 @@ struct pcb_s {
1212
uint32_t lr_svc;
1313
uint32_t lr_user;
1414
uint32_t cpsr;
15+
struct pcb_s * next_pcb;
1516
};
1617

1718
typedef int (func_t) (void);
1819

19-
struct pcb_s* create_process(func_t* entry);
20+
void create_process(func_t* entry);
2021

2122
void sched_init();
2223

24+
void elect();
25+
26+
void sys_yield();
27+
28+
void do_sys_yield();
29+
2330
void sys_yieldto(struct pcb_s* dest);
2431

2532
void do_sys_yieldto(uint32_t * sp_param_base);

Loic-Jo/sysif/src/syscall.c

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ void __attribute__((naked)) swi_handler() {
3030
case 5:
3131
do_sys_yieldto(sp_param_base);
3232
break;
33+
case 6:
34+
do_sys_yield(sp_param_base);
35+
break;
3336
default :
3437
PANIC();
3538
}

Loic-Jo/sysif/tools/init.gdb

+3-9
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,9 @@ b *kernel_panic
1515
b swi_handler
1616

1717
b *kmain
18-
b *do_sys_yieldto
19-
b *user_process_1
20-
b *user_process_2
21-
b *sys_yieldto
22-
b syscall.c:39
23-
b sched.c:33
24-
b sched.c:41
25-
b kmain.c:44
26-
b kmain.c:55
18+
b *do_sys_yield
19+
b *user_process
20+
b *sys_yield
2721

2822
source utils.gdb
2923

0 commit comments

Comments
 (0)