fix: préparation au basculement de tâche par la pile fonction task_switch, correction à apporter dans la gestion de la mémoire
This commit is contained in:
parent
a31cf264c3
commit
44d5634532
|
@ -21,6 +21,10 @@
|
|||
|
||||
#define pushf() asm("pushf"::)
|
||||
|
||||
#define pop(mem) asm("popl %0":"=m" (mem))
|
||||
|
||||
#define push(mem) asm("pushl %0"::"m" (mem))
|
||||
|
||||
#define popf() asm("popf"::)
|
||||
|
||||
#define iret() asm("iret"::)
|
||||
|
|
|
@ -85,3 +85,4 @@ bool isdesvalid(u16 sel);
|
|||
u8 getdesbit3(u16 sel);
|
||||
u32 getdesdpl(u16 sel);
|
||||
u16 getdesalign(u16 sel);
|
||||
void setTSS(u32 ss,u32 sp);
|
||||
|
|
|
@ -220,6 +220,6 @@ struct idtr {
|
|||
void enableirq(u8 irq);
|
||||
void disableirq(u8 irq);
|
||||
void cpuerror(const u8 * src, const regs *stack);
|
||||
|
||||
void createdump(regs *dump);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -145,5 +145,6 @@ u32 task_usePID (u32 pid);
|
|||
u32 task_create();
|
||||
u32 elf_test(u8 *src);
|
||||
u32 elf_load(u8 *src, u32 pid);
|
||||
void task_switch(u32 pid, bool fromkernelmode);
|
||||
process *getcurrentprocess();
|
||||
void task_run(u32 pid);
|
||||
|
|
|
@ -46,6 +46,15 @@ void initgdt(u32 offset)
|
|||
initselectors(offset);
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Change le TSS courant */
|
||||
|
||||
void setTSS(u32 ss,u32 sp)
|
||||
{
|
||||
tss0.esp0 = sp;
|
||||
tss0.ss0 = ss;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Initialise le registre de tâche (TSR) */
|
||||
|
||||
|
|
|
@ -125,7 +125,6 @@ void setidt(u32 offset, u16 select, u16 type, u16 index)
|
|||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/* Met une entrée dans l'IDT */
|
||||
|
||||
void putidt(u32 offset, u16 select, u16 type, u16 index)
|
||||
|
@ -135,6 +134,43 @@ void putidt(u32 offset, u16 select, u16 type, u16 index)
|
|||
idt[index] = temp;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* Créé un dump de la mémoire en empilant les registres */
|
||||
|
||||
void createdump(regs *dump)
|
||||
{
|
||||
push(dump->eax);
|
||||
push(dump->ecx);
|
||||
push(dump->edx);
|
||||
push(dump->ebx);
|
||||
push(dump->esp);
|
||||
push(dump->ebp);
|
||||
push(dump->esi);
|
||||
push(dump->edi);
|
||||
push(dump->eflags);
|
||||
push(dump->cs);
|
||||
push(dump->eip);
|
||||
push(dump->ds);
|
||||
push(dump->es);
|
||||
push(dump->fs);
|
||||
push(dump->gs);
|
||||
push(dump->ss);
|
||||
push(dump->cr0);
|
||||
push(dump->cr2);
|
||||
push(dump->cr3);
|
||||
push(dump->cr4);
|
||||
push(dump->dr0);
|
||||
push(dump->dr1);
|
||||
push(dump->dr2);
|
||||
push(dump->dr3);
|
||||
push(dump->dr6);
|
||||
push(dump->dr7);
|
||||
u32 eferlow=dump->efer & 0xFFFF;
|
||||
u32 eferhigh=dump->efer >> 32;
|
||||
push(eferlow);
|
||||
push(eferhigh);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* Affiche une erreur CPU et fige l'ordinateur */
|
||||
|
||||
|
|
|
@ -149,12 +149,33 @@ u32 task_usePID (u32 pid)
|
|||
lastpid=pid;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Bascule vers une tâche */
|
||||
|
||||
void task_switch(u32 pid, bool fromkernelmode)
|
||||
{
|
||||
u32 ss,esp,eflags;
|
||||
current = &processes[pid];
|
||||
setTSS(current->kstack.ss0,current->kstack.esp0);
|
||||
eflags = (current->dump.eflags | 0x200) & 0xFFFFBFFF;
|
||||
if (fromkernelmode) {
|
||||
ss = current->dump.ss;
|
||||
esp = current->dump.esp;
|
||||
} else {
|
||||
ss = current->kstack.ss0;
|
||||
esp = current->kstack.esp0;
|
||||
}
|
||||
createdump(¤t->dump);
|
||||
restdebugcpu();
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Execute une tâche */
|
||||
|
||||
void task_run(u32 pid)
|
||||
{
|
||||
processes[pid].status = STATUS_RUN;
|
||||
task_switch(pid, true);
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
|
|
Loading…
Reference in New Issue