feat: gestion des tâches, compilation ok, mise en place d'un test par le pseudo-interpréteur, commande : testtask

This commit is contained in:
Nicolas Hordé 2018-12-09 11:11:39 +01:00
parent 11071e5bbd
commit ac537030a3
5 changed files with 45 additions and 21 deletions

View File

@ -54,11 +54,10 @@
#define RPL_RING2 0b01 /* Anneau 2 */
#define RPL_RING3 0b11 /* Anneau 3 */
#define MALLOC_MINIMUM 16
#define setcr3(addr) \
asm volatile ("mov %0, %%eax; mov %%eax, %%cr3"::"m"(processes[pid].pd->addr->paddr));
asm volatile ("mov %[memaddr], %%eax; mov %%eax, %%cr3"::[memaddr] "m" (addr) );
/* Malloc, pour l'attribution de mémoire en heap */
typedef struct tmalloc {

View File

@ -127,10 +127,14 @@ typedef struct process {
u32 pid;
regs dump;
stackdef kstack;
pd ppd;
pd *pdd;
u32 result;
u8 status;
process *parent;
u8 *exec_low;
u8 *exec_high;
u8 *bss_low;
u8 *bss_high;
struct process *parent;
page_t page_head;
u32 entry;
} process __attribute__ ((packed));

View File

@ -31,3 +31,4 @@ int detectpci();
int showmem();
int testmem();
int testcall();
int testtask();

View File

@ -11,7 +11,14 @@ process *processes;
process *current;
u32 lastpid;
u8 elf_errors[][]={"Aucune signature ELF","Fichier au format ELF mais non 32 bits","ELF non MSB","ELF mauvaise version","ELF pour OS ne correspondant pas","Mauvais type de machine"};
u8 elf_errors1[]="Aucune signature ELF";
u8 elf_errors2[]="Fichier au format ELF mais non 32 bits";
u8 elf_errors3[]="ELF non MSB";
u8 elf_errors4[]="ELF mauvaise version";
u8 elf_errors5[]="ELF pour OS ne correspondant pas";
u8 elf_errors6[]="Mauvais type de machine";
u8 *elf_errors[6]={&elf_errors1,&elf_errors2,&elf_errors3,&elf_errors4,&elf_errors5,&elf_errors6};
/*******************************************************************************/
/* Vérifie la signature ELF
@ -52,44 +59,44 @@ u32 elf_test(u8 *src)
u32 elf_load(u8 *src, u32 pid)
{
u8 *p;
u8 *ptr;
u8 code;
u32 v_begin, v_end;
elf32 *header;
elf32p *program;
u32 i, pe;
u32 i;
header = (elf32 *) src;
program = (elf32p) (src + header->e_phoff);
program = (elf32p *) (src + header->e_phoff);
code=elf_test(src);
if (code!=0) {
printf("Mauvais format ELF : N°%s !\r\n",elf_errors[code-1]);
return NULL;
}
for (pe = 0; pe < header->e_phnum; pe++, program++) {
for (i = 0; i < header->e_phnum; i++, program++) {
if (program->p_type == PT_LOAD) {
v_begin = program->p_vaddr;
v_end = program->p_vaddr + program->p_memsz;
if (v_begin < USER_CODE) {
printk ("Ne peut charger l'executable en desssous de l'adresse %X\r\n", USER_CODE);
printf ("Ne peut charger l'executable en desssous de l'adresse %X\r\n", USER_CODE);
return 0;
}
if (v_end > USER_STACK) {
printk ("Ne peut charger l'executable au desssus de l'adresse %X\r\n", USER_STACK);
printf ("Ne peut charger l'executable au desssus de l'adresse %X\r\n", USER_STACK);
return 0;
}
if (program->p_flags == PF_X + PF_R) {
proc->b_exec = (u8*) v_begin;
proc->e_exec = (u8*) v_end;
processes[pid].exec_low = (u8*) v_begin;
processes[pid].exec_high = (u8*) v_end;
}
if (program->p_flags == PF_W + PF_R) {
proc->b_bss = (u8*) v_begin;
proc->e_bss = (u8*) v_end;
processes[pid].bss_low = (u8*) v_begin;
processes[pid].bss_high = (u8*) v_end;
}
memcpy((u8 *) v_begin, (u8 *) (file + program->p_offset), program->p_filesz);
memcpy((u8 *) v_begin, (u8 *) (src + program->p_offset), program->p_filesz,0);
if (program->p_memsz > program->p_filesz)
for (i = program->p_filesz, p = (u8 *) program->p_vaddr; i < program->p_memsz; i++)
p[i] = 0;
for (i = program->p_filesz, ptr = (u8 *) program->p_vaddr; i < program->p_memsz; i++)
ptr[i] = 0;
}
}
return header->e_entry;
@ -124,6 +131,7 @@ u32 task_getfreePID ()
if (parsed>MAXNUMPROCESS) {
printf("PANIC: plus d'emplacement disponible pour un novueau processus\n");
return NULL;
}
return i;
}
@ -149,13 +157,12 @@ u32 task_create(u8 *code)
TAILQ_INIT(&processes[pid].page_head);
current = &processes[pid];
setcr3(processes[pid].pdd->addr->paddr);
elf_load(u8 *src, pid);
kstack = virtual_page_getfree();
processes[pid].dump.ss = SEL_USER_STACK || RPL_RING3;
processes[pid].dump.esp = USER_STACK;
processes[pid].dump.eflags = 0x0;
processes[pid].dump.cs = SEL_USER_CODE || RPL_RING3;
processes[pid].dump.eip = elf_load(u8 *src, u32 pid)
processes[pid].dump.eip = elf_load(code,pid);
processes[pid].dump.ds = SEL_USER_DATA || RPL_RING3;
processes[pid].dump.es = SEL_USER_DATA || RPL_RING3;
processes[pid].dump.fs = SEL_USER_DATA || RPL_RING3;

View File

@ -41,9 +41,10 @@ static command commands[] = {
{"font" , "", &sfont},
{"test3d" , "", &test3d},
{"detectpci" , "", &detectpci},
{"showmem" , "", &showmem},
{"wmem" , "", &showmem},
{"testmem" , "", &testmem},
{"testcall" , "", &testcall},
{"testtask" , "", &testtask},
};
/*******************************************************************************/
@ -83,8 +84,17 @@ int test(void)
return;
}
/*******************************************************************************/
/* Test l'usage de création de tâche */
int testtask()
{
print("*** Creation d'une tache");
}
/*******************************************************************************/
/* Test l'usage de syscall */
int testcall()
{
print("*** avant appel");
@ -94,6 +104,7 @@ int testcall()
/*******************************************************************************/
/* Test la memoire */
int testmem()
{
u8* test;
@ -109,6 +120,7 @@ int testmem()
/*******************************************************************************/
/* Affiche des informations sur la mémoire */
int showmem()
{
u32 libre=getmemoryfree();
@ -122,6 +134,7 @@ int showmem()
/*******************************************************************************/
/* Affiche les périphériques PCI */
int detectpci()
{
scanPCI();