feat: ajout de process.h/c pour la gestion de la création de tâche/processus, non compilable
This commit is contained in:
parent
8d3da6480a
commit
11071e5bbd
|
@ -3,6 +3,9 @@
|
|||
/* */
|
||||
#include "types.h"
|
||||
|
||||
#ifndef _ASM
|
||||
#define _ASM
|
||||
|
||||
/******************************************************************************/
|
||||
#define halt() asm("hlt"::)
|
||||
|
||||
|
@ -121,3 +124,4 @@
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
#endif
|
||||
|
|
|
@ -42,4 +42,4 @@ bool apic2;
|
|||
bool cansetflag (u32 flag);
|
||||
void cpuid(u32 op, u32 *eax, u32 *ebx,u32 *ecx, u32 *edx);
|
||||
u8 getcpuinfos(cpuinfo *inf);
|
||||
void show_cpu(save_stack *stack);
|
||||
void show_cpu(regs *stack);
|
||||
|
|
|
@ -155,7 +155,7 @@
|
|||
|
||||
|
||||
/* save pile */
|
||||
typedef struct save_stack {
|
||||
typedef struct regs {
|
||||
u64 efer;
|
||||
u32 dr7;
|
||||
u32 dr6;
|
||||
|
@ -183,7 +183,7 @@ typedef struct save_stack {
|
|||
u32 edx;
|
||||
u32 ecx;
|
||||
u32 eax;
|
||||
} save_stack __attribute__ ((packed));
|
||||
} regs __attribute__ ((packed));
|
||||
/* exception pile */
|
||||
typedef struct exception_stack {
|
||||
u32 error_code;
|
||||
|
@ -219,7 +219,7 @@ struct idtr {
|
|||
void initpic(void);
|
||||
void enableirq(u8 irq);
|
||||
void disableirq(u8 irq);
|
||||
void cpuerror(const u8 * src, const save_stack *stack);
|
||||
void cpuerror(const u8 * src, const regs *stack);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
#include "types.h"
|
||||
#include "queue.h"
|
||||
|
||||
#ifndef _MEMORY
|
||||
#define _MEMORY
|
||||
|
||||
#define TOPAGE(addr) (addr) >> 12
|
||||
#define TOPD(addr) ((addr) & 0xFFC00000) >> 22
|
||||
#define TOPT(addr) ((addr) & 0x003FF000) >> 12
|
||||
|
@ -45,8 +48,18 @@
|
|||
#define PAGE_DIRTY 0b001000000 /* page écrite */
|
||||
#define PAGE_GLOBAL 0b100000000 /* évite que le TLB mette à jour l'adresse dans le cache si CR4 est remis à zéro (NECESSITE CR4) */
|
||||
|
||||
/* Selecteur RPL */
|
||||
#define RPL_RING0 0b00 /* Anneau 0 */
|
||||
#define RPL_RING1 0b01 /* Anneau 1 */
|
||||
#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));
|
||||
|
||||
/* Malloc, pour l'attribution de mémoire en heap */
|
||||
typedef struct tmalloc {
|
||||
u32 size:31;
|
||||
|
@ -111,3 +124,5 @@ u32 getmallocused(void);
|
|||
u32 getmallocfree(void);
|
||||
u32 getmallocnonallocated(void);
|
||||
u32 virtual_getpagesfree();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
/*******************************************************************************/
|
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
||||
/* */
|
||||
|
||||
#include "types.h"
|
||||
#include "interrupts.h"
|
||||
#include "memory.h"
|
||||
|
||||
#define MAXPIDVALUE 0xFFFF
|
||||
#define MAXNUMPROCESS 256
|
||||
|
||||
#define STATUS_FREE 0x0
|
||||
#define STATUS_ZOMBIE 0xFF
|
||||
#define STATUS_READY 0xF0
|
||||
#define STATUS_RUN 0x1
|
||||
#define STATUS_SLEEP 0x2
|
||||
|
||||
/* ELF type */
|
||||
#define ET_NONE 0 //No file type
|
||||
#define ET_REL 1 //Relocatable file
|
||||
#define ET_EXEC 2 //Executable file
|
||||
#define ET_DYN 3 //Shared object file
|
||||
#define ET_CORE 4 //Core file
|
||||
#define ET_LOOS 0xfe00 //Operating system-specific
|
||||
#define ET_HIOS 0xfeff //Operating system-specific
|
||||
#define ET_LOPROC 0xff00 //Processor-specific
|
||||
#define ET_HIPROC 0xffff //Processor-specific
|
||||
|
||||
/* ELF identification */
|
||||
#define EI_MAG0 0 //File identification
|
||||
#define EI_MAG1 1 //File identification
|
||||
#define EI_MAG2 2 //File identification
|
||||
#define EI_MAG3 3 //File identification
|
||||
#define EI_CLASS 4 //File class
|
||||
#define EI_DATA 5 //Data encoding
|
||||
#define EI_VERSION 6 //File version
|
||||
#define EI_OSABI 7 //Operating system/ABI identification
|
||||
#define EI_ABIVERSION 8 //ABI version
|
||||
#define EI_PAD 9 //Start of padding bytes
|
||||
#define EI_NIDENT 16 //Size of e_ident[]
|
||||
|
||||
/* ELF version */
|
||||
#define EV_NONE 0 //Invalid version
|
||||
#define EV_CURRENT 1 //Current version
|
||||
|
||||
/* ELF machine type */
|
||||
|
||||
#define EM_NONE 0 //No machine
|
||||
#define EM_386 3 //Intel 80386
|
||||
#define EM_IA_64 50 //Intel IA-64 processor architecture
|
||||
#define EM_X86_64 62 //AMD x86-64 architecture
|
||||
|
||||
/* EI signature */
|
||||
#define ELFMAG0 0x7f
|
||||
#define ELFMAG1 'E'
|
||||
#define ELFMAG2 'L'
|
||||
#define ELFMAG3 'F'
|
||||
|
||||
/* EI file class */
|
||||
#define ELFCLASSNONE 0 /* invalid class */
|
||||
#define ELFCLASS32 1 /* 32-bit objects */
|
||||
#define ELFCLASS64 2 /* 64-bit objects */
|
||||
|
||||
/* EI data structure */
|
||||
#define ELFDATANONE 0 /* invalide data encoding */
|
||||
#define ELFDATA2LSB 1 /* least significant byte first (0x01020304 is 0x04 0x03 0x02 0x01) */
|
||||
#define ELFDATA2MSB 2 /* most significant byte first (0x01020304 is 0x01 0x02 0x03 0x04) */
|
||||
|
||||
/* p type */
|
||||
#define PT_NULL 0
|
||||
#define PT_LOAD 1
|
||||
#define PT_DYNAMIC 2
|
||||
#define PT_INTERP 3
|
||||
#define PT_NOTE 4
|
||||
#define PT_SHLIB 5
|
||||
#define PT_PHDR 6
|
||||
#define PT_LOPROC 0x70000000
|
||||
#define PT_HIPROC 0x7fffffff
|
||||
|
||||
/* p flags */
|
||||
#define PF_X 0x1
|
||||
#define PF_W 0x2
|
||||
#define PF_R 0x4
|
||||
|
||||
/* OS identification */
|
||||
#define ELFOSABI_NONE 0 //No extensions or unspecified
|
||||
#define ELFOSABI_LINUX 3 //Linux
|
||||
#define ELFOSABI_COS2000 15 //COS2000
|
||||
|
||||
/* ELF header */
|
||||
typedef struct elf32 {
|
||||
u8 e_ident[EI_NIDENT];
|
||||
u16 e_type;
|
||||
u16 e_machine;
|
||||
u32 e_version;
|
||||
u8* e_entry;
|
||||
u32 e_phoff;
|
||||
u32 e_shoff;
|
||||
u32 e_flags;
|
||||
u16 e_ehsize;
|
||||
u16 e_phentsize;
|
||||
u16 e_phnum;
|
||||
u16 e_shentsize;
|
||||
u16 e_shnum;
|
||||
u16 e_shstrndx;
|
||||
} elf32;
|
||||
|
||||
typedef struct elf32p{
|
||||
u32 p_type;
|
||||
u32 p_offset;
|
||||
u8* p_vaddr;
|
||||
u8* p_paddr;
|
||||
u32 p_filesz;
|
||||
u32 p_memsz;
|
||||
u32 p_flags;
|
||||
u32 p_align;
|
||||
} elf32p;
|
||||
|
||||
|
||||
typedef struct stackdef {
|
||||
u32 esp0;
|
||||
u16 ss0;
|
||||
} stackdef __attribute__ ((packed));
|
||||
|
||||
|
||||
typedef struct process {
|
||||
u32 pid;
|
||||
regs dump;
|
||||
stackdef kstack;
|
||||
pd ppd;
|
||||
u32 result;
|
||||
u8 status;
|
||||
process *parent;
|
||||
page_t page_head;
|
||||
u32 entry;
|
||||
} process __attribute__ ((packed));
|
||||
|
||||
void task_init();
|
||||
u32 task_getfreePID ();
|
||||
u32 task_usePID (u32 pid);
|
||||
u32 task_create();
|
|
@ -11,13 +11,13 @@ int (*function)()
|
|||
int rebootnow();
|
||||
int test2d();
|
||||
int test3d();
|
||||
int readidt();
|
||||
int readgdt();
|
||||
int showidt();
|
||||
int showgdt();
|
||||
int detectcpu();
|
||||
int mode();
|
||||
int clear();
|
||||
int regs();
|
||||
int info();
|
||||
int showregs();
|
||||
int showinfo();
|
||||
int err();
|
||||
int view();
|
||||
int test(void);
|
||||
|
@ -28,6 +28,6 @@ int sfont(u8* commandline);
|
|||
int help();
|
||||
int logo();
|
||||
int detectpci();
|
||||
int mem();
|
||||
int showmem();
|
||||
int testmem();
|
||||
int testsyscall();
|
||||
int testcall();
|
||||
|
|
|
@ -129,7 +129,7 @@ u8 getcpuinfos(cpuinfo * proc)
|
|||
/******************************************************************************/
|
||||
/* Affiche les registres CPU */
|
||||
|
||||
void show_lightcpu(save_stack *stack)
|
||||
void show_lightcpu(regs *stack)
|
||||
{
|
||||
u32 i;
|
||||
printf("\33[0mEAX=%Y EBX=%Y ECX=%Y EDX=%Y\r\n", stack->eax, stack->ebx, stack->ecx, stack->edx);
|
||||
|
@ -194,7 +194,7 @@ void show_lightcpu(save_stack *stack)
|
|||
/******************************************************************************/
|
||||
/* Affiche les registres CPU */
|
||||
|
||||
void show_cpu(save_stack *stack)
|
||||
void show_cpu(regs *stack)
|
||||
{
|
||||
printf("EAX=%Y EBX=%Y ECX=%Y EDX=%Y\r\n", stack->eax, stack->ebx, stack->ecx, stack->edx);
|
||||
printf("ESI=%Y EDI=%Y ESP=%Y EBP=%Y\r\n", stack->esi, stack->edi, stack->esp, stack->ebp);
|
||||
|
|
|
@ -23,10 +23,8 @@ void initgdt(u32 offset)
|
|||
makegdtdes(0x0, 0x00000, 0x00, 0x00, &gdt[0]); /* descripteur nul */
|
||||
makegdtdes(0x0, 0xFFFFF, SEG_PRESENT | SEG_NORMAL | SEG_CODE | SEG_RING0 | SEG_READ | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[1]); /* code -> SEL_KERNEL_CODE */
|
||||
makegdtdes(0x0, 0x00000, SEG_PRESENT | SEG_NORMAL | SEG_DATA | SEG_RING0 | SEG_EXPAND_DOWN | SEG_READ_WRITE | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[2]); /* pile -> SEL_KERNEL_STACK */
|
||||
makegdtdes(0x0, 0xFFFFF, SEG_PRESENT | SEG_NORMAL | SEG_CODE | SEG_RING0 | SEG_READ | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[3]); /* code -> SEL_KERNEL_CODE */
|
||||
makegdtdes(0x0, 0x00000, SEG_PRESENT | SEG_NORMAL | SEG_DATA | SEG_RING0 | SEG_EXPAND_DOWN | SEG_READ_WRITE | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[4]); /* pile -> SEL_KERNEL_STACK */
|
||||
makegdtdes(0x0, 0xFFFFF, SEG_PRESENT | SEG_NORMAL | SEG_CODE | SEG_RING3 | SEG_CONFORMING | SEG_READ | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[7]); /* code -> SEL_USER_CODE */
|
||||
makegdtdes(0x0, 0x00000, SEG_PRESENT | SEG_NORMAL | SEG_DATA | SEG_RING3 | SEG_EXPAND_DOWN | SEG_READ_WRITE | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[8]); /* pile -> SEL_USER_STACK */
|
||||
makegdtdes(0x0, 0xFFFFF, SEG_PRESENT | SEG_NORMAL | SEG_CODE | SEG_RING3 | SEG_CONFORMING | SEG_READ | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[3]); /* code -> SEL_USER_CODE */
|
||||
makegdtdes(0x0, 0x00000, SEG_PRESENT | SEG_NORMAL | SEG_DATA | SEG_RING3 | SEG_EXPAND_DOWN | SEG_READ_WRITE | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[4]); /* pile -> SEL_USER_STACK */
|
||||
makegdtdes(0x0, 0xFFFFF, SEG_PRESENT | SEG_NORMAL | SEG_DATA | SEG_RING0 | SEG_READ_WRITE | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[5]); /* data -> SEL_KERNEL_DATA */
|
||||
makegdtdes(0x0, 0xFFFFF, SEG_PRESENT | SEG_NORMAL | SEG_DATA | SEG_RING3 | SEG_READ_WRITE | SEG_ACCESSED, GRANULARITY_4K | OPSIZE_32B | SYS_AVAILABLE, &gdt[6]); /* data -> SEL_USER_DATA */
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ void putidt(u32 offset, u16 select, u16 type, u16 index)
|
|||
/******************************************************************************/
|
||||
/* Affiche une erreur CPU et fige l'ordinateur */
|
||||
|
||||
void cpuerror(const u8 * src, const save_stack *stack)
|
||||
void cpuerror(const u8 * src, const regs *stack)
|
||||
{
|
||||
printf("\033[31m*** ERREUR CPU : %s *** \r\n", src);
|
||||
if (stack!=NULL) show_cpu(stack);
|
||||
|
@ -168,7 +168,7 @@ void interruption()
|
|||
|
||||
void exception0()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -184,7 +184,7 @@ void exception0()
|
|||
void exception1()
|
||||
{
|
||||
cli();
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -223,7 +223,7 @@ void exception1()
|
|||
|
||||
void exception2()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -238,7 +238,7 @@ void exception2()
|
|||
|
||||
void exception3()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -253,7 +253,7 @@ void exception3()
|
|||
|
||||
void exception4()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -268,7 +268,7 @@ void exception4()
|
|||
|
||||
void exception5()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -283,7 +283,7 @@ void exception5()
|
|||
|
||||
void exception6()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -298,7 +298,7 @@ void exception6()
|
|||
|
||||
void exception7()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -313,7 +313,7 @@ void exception7()
|
|||
|
||||
void exception8()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -328,7 +328,7 @@ void exception8()
|
|||
|
||||
void exception9()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -343,7 +343,7 @@ void exception9()
|
|||
|
||||
void exception10()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -358,7 +358,7 @@ void exception10()
|
|||
|
||||
void exception11()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -373,7 +373,7 @@ void exception11()
|
|||
|
||||
void exception12()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -388,7 +388,7 @@ void exception12()
|
|||
|
||||
void exception13()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -403,7 +403,7 @@ void exception13()
|
|||
|
||||
void exception14()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -448,7 +448,7 @@ void exception14()
|
|||
|
||||
void exception15()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -463,7 +463,7 @@ void exception15()
|
|||
|
||||
void exception16()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -478,7 +478,7 @@ void exception16()
|
|||
|
||||
void exception17()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
@ -493,7 +493,7 @@ void exception17()
|
|||
|
||||
void exception18()
|
||||
{
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
exception_stack_noerror *current;
|
||||
u32 *oldesp;
|
||||
getEBP(oldesp);
|
||||
|
|
|
@ -218,7 +218,7 @@ unsigned convert(u32 keypressed)
|
|||
}
|
||||
|
||||
else if (key == SCAN_F9) {
|
||||
save_stack dump;
|
||||
regs dump;
|
||||
show_cpu(&dump);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,178 @@
|
|||
/*******************************************************************************/
|
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
||||
/* */
|
||||
|
||||
#include "types.h"
|
||||
#include "process.h"
|
||||
#include "memory.h"
|
||||
#include "gdt.h"
|
||||
|
||||
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"};
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Vérifie la signature ELF
|
||||
0 - RAS
|
||||
1 - Pas la signature ELF
|
||||
2 - pas ELF32
|
||||
3 - pas bon organisation LSB/MSB
|
||||
4 - pas bonne version ELF
|
||||
5 - pas bon OS
|
||||
6 - pas bon type machine */
|
||||
|
||||
u32 elf_test(u8 *src)
|
||||
{
|
||||
elf32 *header=(elf32 *) src;
|
||||
if (header->e_ident[EI_MAG0] == ELFMAG0 && header->e_ident[EI_MAG1] == ELFMAG1
|
||||
&& header->e_ident[EI_MAG2] == ELFMAG2 && header->e_ident[EI_MAG3] == ELFMAG3)
|
||||
{
|
||||
if (header->e_ident[EI_CLASS]!=ELFCLASS32)
|
||||
return 1;
|
||||
if (header->e_ident[EI_DATA]!=ELFDATA2LSB)
|
||||
return 2;
|
||||
if (header->e_ident[EI_DATA]!=ELFDATA2LSB)
|
||||
return 3;
|
||||
if (header->e_ident[EI_VERSION]!=EV_CURRENT || header->e_version!=EV_CURRENT)
|
||||
return 4;
|
||||
if (header->e_ident[EI_OSABI]!=ELFOSABI_COS2000)
|
||||
return 5;
|
||||
if (header->e_machine==EM_386)
|
||||
return 6;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Charge le fichier ELF en mémoire et mets à jour les informations sur le processus */
|
||||
|
||||
u32 elf_load(u8 *src, u32 pid)
|
||||
{
|
||||
u8 *p;
|
||||
u8 code;
|
||||
u32 v_begin, v_end;
|
||||
elf32 *header;
|
||||
elf32p *program;
|
||||
u32 i, pe;
|
||||
|
||||
header = (elf32 *) src;
|
||||
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++) {
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
if (v_end > USER_STACK) {
|
||||
printk ("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;
|
||||
}
|
||||
if (program->p_flags == PF_W + PF_R) {
|
||||
proc->b_bss = (u8*) v_begin;
|
||||
proc->e_bss = (u8*) v_end;
|
||||
}
|
||||
memcpy((u8 *) v_begin, (u8 *) (file + program->p_offset), program->p_filesz);
|
||||
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;
|
||||
}
|
||||
}
|
||||
return header->e_entry;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Initialise la liste des processus */
|
||||
|
||||
void task_init() {
|
||||
u32 i=0;
|
||||
processes=(process*)vmalloc(sizeof(process)*MAXNUMPROCESS);
|
||||
while (i++ < MAXNUMPROCESS) {
|
||||
processes[i].pid=NULL;
|
||||
processes[i].status=STATUS_FREE;
|
||||
}
|
||||
current=NULL;
|
||||
lastpid=NULL;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Récupère un emplacement dans la liste des processus */
|
||||
|
||||
u32 task_getfreePID ()
|
||||
{
|
||||
u32 i = lastpid;
|
||||
u32 parsed = 0;
|
||||
while (processes[++i].status != STATUS_FREE && ++parsed < MAXNUMPROCESS)
|
||||
{
|
||||
if (i>=MAXNUMPROCESS)
|
||||
i=0;
|
||||
}
|
||||
if (parsed>MAXNUMPROCESS) {
|
||||
printf("PANIC: plus d'emplacement disponible pour un novueau processus\n");
|
||||
return NULL;
|
||||
return i;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Determine le dernier PID occupé */
|
||||
|
||||
u32 task_usePID (u32 pid)
|
||||
{
|
||||
lastpid=pid;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Initialise une tâche */
|
||||
|
||||
u32 task_create(u8 *code)
|
||||
{
|
||||
process *previous=current;
|
||||
u32 pid=task_getfreePID();
|
||||
task_usePID(pid);
|
||||
page *kstack;
|
||||
processes[pid].pid = pid;
|
||||
processes[pid].pdd = virtual_pd_create();
|
||||
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.ds = SEL_USER_DATA || RPL_RING3;
|
||||
processes[pid].dump.es = SEL_USER_DATA || RPL_RING3;
|
||||
processes[pid].dump.fs = SEL_USER_DATA || RPL_RING3;
|
||||
processes[pid].dump.gs = SEL_USER_DATA || RPL_RING3;
|
||||
processes[pid].dump.cr3 = (u32) processes[pid].pdd->addr->paddr;
|
||||
processes[pid].kstack.ss0 = SEL_KERNEL_STACK;
|
||||
processes[pid].kstack.esp0 = (u32) kstack->vaddr + PAGESIZE - 16;
|
||||
processes[pid].dump.eax = 0;
|
||||
processes[pid].dump.ecx = 0;
|
||||
processes[pid].dump.edx = 0;
|
||||
processes[pid].dump.ebx = 0;
|
||||
processes[pid].dump.ebp = 0;
|
||||
processes[pid].dump.esi = 0;
|
||||
processes[pid].dump.edi = 0;
|
||||
processes[pid].result = 0;
|
||||
processes[pid].status = STATUS_READY;
|
||||
current = previous;
|
||||
setcr3(current->dump.cr3);
|
||||
return pid;
|
||||
}
|
33
lib/shell.c
33
lib/shell.c
|
@ -26,10 +26,10 @@ static command commands[] = {
|
|||
{"mode" , "", &mode},
|
||||
{"detectcpu" , "", &detectcpu},
|
||||
{"test2d" , "", &test2d},
|
||||
{"regs" , "", ®s},
|
||||
{"gdt" , "", &readgdt},
|
||||
{"idt" , "", &readidt},
|
||||
{"info" , "", &info},
|
||||
{"regs" , "", &showregs},
|
||||
{"gdt" , "", &showgdt},
|
||||
{"idt" , "", &showidt},
|
||||
{"info" , "", &showinfo},
|
||||
{"err" , "", &err},
|
||||
{"test" , "", &test},
|
||||
{"view" , "", &view},
|
||||
|
@ -41,9 +41,9 @@ static command commands[] = {
|
|||
{"font" , "", &sfont},
|
||||
{"test3d" , "", &test3d},
|
||||
{"detectpci" , "", &detectpci},
|
||||
{"mem" , "", &mem},
|
||||
{"showmem" , "", &showmem},
|
||||
{"testmem" , "", &testmem},
|
||||
{"testsyscall" , "", &testsyscall},
|
||||
{"testcall" , "", &testcall},
|
||||
};
|
||||
|
||||
/*******************************************************************************/
|
||||
|
@ -85,7 +85,7 @@ int test(void)
|
|||
|
||||
/*******************************************************************************/
|
||||
/* Test l'usage de syscall */
|
||||
int testsyscall()
|
||||
int testcall()
|
||||
{
|
||||
print("*** avant appel");
|
||||
syscall2(0x0, 0x1980, 0x2505);
|
||||
|
@ -98,19 +98,18 @@ int testmem()
|
|||
{
|
||||
u8* test;
|
||||
print("**** AVANT ALLOCATION\r\n");
|
||||
mem();
|
||||
showmem();
|
||||
test=vmalloc(150*1024*1024); /* 10 pages */
|
||||
print("**** APRES ALLOCATION\r\n");
|
||||
mem();
|
||||
showmem();
|
||||
vfree(test);
|
||||
print("**** APRES LIBERATION\r\n");
|
||||
mem();
|
||||
|
||||
showmem();
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Affiche des informations sur la mémoire */
|
||||
int mem()
|
||||
int showmem()
|
||||
{
|
||||
u32 libre=getmemoryfree();
|
||||
u32 total=physical_getmemorysize();
|
||||
|
@ -416,7 +415,7 @@ int err(u8* commandline)
|
|||
|
||||
/*******************************************************************************/
|
||||
/* Information sur le démarrage */
|
||||
int info()
|
||||
int showinfo()
|
||||
{
|
||||
getgrubinfo_all();
|
||||
return 0;
|
||||
|
@ -425,9 +424,9 @@ int info()
|
|||
/*******************************************************************************/
|
||||
/* Affiche les registres */
|
||||
|
||||
int regs()
|
||||
int showregs()
|
||||
{
|
||||
save_stack dump;
|
||||
regs dump;
|
||||
show_cpu(&dump);
|
||||
return 0;
|
||||
}
|
||||
|
@ -600,7 +599,7 @@ int test2d()
|
|||
/*******************************************************************************/
|
||||
/* Lit l'IDT et l'affiche */
|
||||
|
||||
int readidt()
|
||||
int showidt()
|
||||
{
|
||||
u32 index, i = 0;
|
||||
idtdes *desc;
|
||||
|
@ -648,7 +647,7 @@ int readidt()
|
|||
/*******************************************************************************/
|
||||
/* Lit les descripteurs GDT et les affiche */
|
||||
|
||||
int readgdt()
|
||||
int showgdt()
|
||||
{
|
||||
u32 index;
|
||||
struct gdtr gdtreg;
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
void sysenter_handler(void)
|
||||
{
|
||||
cli();
|
||||
save_stack *dump;
|
||||
regs *dump;
|
||||
dumpcpu();
|
||||
getESP(dump);
|
||||
sti();
|
||||
|
|
Loading…
Reference in New Issue