From ac537030a36a94d8527e840cf2d83fb902e33e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Sun, 9 Dec 2018 11:11:39 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20gestion=20des=20t=C3=A2ches,=20compilat?= =?UTF-8?q?ion=20ok,=20mise=20en=20place=20d'un=20test=20par=20le=20pseudo?= =?UTF-8?q?-interpr=C3=A9teur,=20commande=20:=20testtask?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/memory.h | 3 +-- include/process.h | 8 ++++++-- include/shell.h | 1 + lib/process.c | 39 +++++++++++++++++++++++---------------- lib/shell.c | 15 ++++++++++++++- 5 files changed, 45 insertions(+), 21 deletions(-) diff --git a/include/memory.h b/include/memory.h index b7c374a..66124f0 100755 --- a/include/memory.h +++ b/include/memory.h @@ -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 { diff --git a/include/process.h b/include/process.h index 4a0f197..3bc13a0 100755 --- a/include/process.h +++ b/include/process.h @@ -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)); diff --git a/include/shell.h b/include/shell.h index bf7031c..12c9cb4 100644 --- a/include/shell.h +++ b/include/shell.h @@ -31,3 +31,4 @@ int detectpci(); int showmem(); int testmem(); int testcall(); +int testtask(); diff --git a/lib/process.c b/lib/process.c index 4898160..1b3b3c4 100644 --- a/lib/process.c +++ b/lib/process.c @@ -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; diff --git a/lib/shell.c b/lib/shell.c index 75fed7d..7f0f6e5 100644 --- a/lib/shell.c +++ b/lib/shell.c @@ -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();