feat: fonction task_switch & task_run passe en mode utilisateur RING0 mais plantage lors de l'execution

This commit is contained in:
Nicolas Hordé 2018-12-12 00:15:36 +01:00
parent dd70f75ab8
commit 69fa9567a1
4 changed files with 17 additions and 41 deletions

View File

@ -56,11 +56,11 @@
})
#define createdump(dump) ({ \
push(dump.ss);\
push(dump.esp);\
push(dump.eflags);\
push(dump.cs);\
push(dump.eip);\
push(dump.esp);\
push(dump.ss);\
push(dump.ds);\
push(dump.es);\
push(dump.fs);\
@ -90,11 +90,11 @@
#define dumpcpu() ({ \
asm("\
pushl %%ss\n \
pushl %%esp\n \
pushf \n \
pushl %%cs\n \
pushl $0x0\n \
pushl %%esp\n \
pushl %%ss\n \
pushl %%ds\n \
pushl %%es\n \
pushl %%fs\n \
@ -132,7 +132,7 @@
pushl %%eax":::);\
})
#define restcpu(usermode) ({\
#define restcpu() ({\
asm("\
popl %%eax \n \
popl %%edx \n \
@ -166,11 +166,9 @@
popl %%fs\n \
popl %%es\n \
popl %%ds\n \"::);\
if (usermode==true)\
asm("add $0x8,%%esp"::);\
})
#define restdebugcpu(usermode) ({\
#define restdebugcpu() ({\
asm("\
popl %%eax \n \
popl %%edx \n \
@ -198,8 +196,6 @@
popl %%fs\n \
popl %%es\n \
popl %%ds":::);\
if (usermode==true)\
asm("add $0x8,%%esp"::);\
})
/*
@ -237,11 +233,11 @@ typedef struct regs {
u32 fs;
u32 es;
u32 ds;
u32 ss;
u32 esp;
u32 eip;
u32 cs;
u32 eflags;
u32 esp;
u32 ss;
} regs __attribute__ ((packed));
/* exception pile */
typedef struct exception_stack {

View File

@ -214,14 +214,7 @@ void exception1()
initselectors(retry_address);
}
changevc(0);
if (dump->cs==SEL_KERNEL_CODE)
{
restdebugcpu(true);
}
else
{
restdebugcpu(false);
}
restdebugcpu();
iret();
}
@ -435,14 +428,7 @@ void exception14()
printf("Page fault - %s at adress %Y cs:eip - %Y:%Y\r\n",ex14_errors[current->error_code & 0xF],dump->cr2,dump->cs,dump->eip);
cpuerror("#SS Page fault",dump);
}
if (dump->cs==SEL_KERNEL_CODE)
{
restdebugcpu(true);
}
else
{
restdebugcpu(false);
}
restdebugcpu();
iret();
}

View File

@ -154,18 +154,12 @@ u32 task_usePID (u32 pid)
void task_switch(u32 pid, bool fromkernelmode)
{
process *previous=current;
current = &processes[pid];
setTSS(current->kstack.ss0,current->kstack.esp0);
current->dump.eflags = (current->dump.eflags | 0x200) & 0xFFFFBFFF;
createdump(current->dump);
if (fromkernelmode)
{
restdebugcpu(true);
}
else
{
restdebugcpu(false);
}
restdebugcpu();
iret();
}
@ -175,7 +169,7 @@ void task_switch(u32 pid, bool fromkernelmode)
void task_run(u32 pid)
{
processes[pid].status = STATUS_RUN;
task_switch(pid, true);
task_switch(pid, false);
}
/*******************************************************************************/
@ -194,7 +188,7 @@ u32 task_create(u8 *code)
setcr3(processes[pid].pdd->addr->paddr);
kstack = virtual_page_getfree();
processes[pid].dump.ss = SEL_USER_STACK | RPL_RING3;
processes[pid].dump.esp = USER_STACK;
processes[pid].dump.esp = USER_STACK-16;
processes[pid].dump.eflags = 0x0;
processes[pid].dump.cs = SEL_USER_CODE | RPL_RING3;
processes[pid].dump.eip = elf_load(code,pid);

View File

@ -42,7 +42,7 @@ void sysenter_handler(void)
break;
}
restdebugcpu(true);
restdebugcpu();
sysexit();
}