Hello again, i have problem with user space tasks.
If i create only one task with user mode segments it's works fine, but if i set the user mode registers to other tasks, the switch works fine too, but aften saving the last task state, the registers address point always to the last task.
What i do wrong?
Here my task creation function:
Code: Select all
struct process *process_create(void (*entryPoint)(),bool isUser,char *name) {
struct process *p = process_allocateProcess();
if (p->used) {
printf("%s: %d\n",__func__,p->pid);
stackFrame *frame = (pmml_alloc(true))-sizeof(stackFrame);
frame->flags = 0x202;
frame->cs = (isUser ? 0x1b : 0x8);
frame->eip = (uint32_t)entryPoint;
frame->ebp = 0;
frame->esp = 0;
frame->edi = 0;
frame->esi = 0;
frame->edx = 0;
frame->ecx = 0;
frame->ebx = 0;
frame->eax = 0;
frame->ds = (isUser ? 0x23 : 0x10);
frame->es = frame->ds;
frame->fs = frame->ds;
frame->gs = frame->ds;
frame->ss = frame->ds;
frame->usersp = (isUser ? ((int)pmml_alloc(true)+1024) : 0);
p->esp = frame;
p->name = name;
processList[p->pid].esp = frame;
printf("Process %d, user stack: %x\n",p->pid,frame->usersp);
}
return p; // not implemented
}
Here my schedule function:
Code: Select all
stackFrame *process_schedule(stackFrame *stack) {
// don't save context on first switch
if (!scs.fswitch) {
processList[scs.threadndx].esp = stack;
}
if (!scs.fswitch) {
for (scs.threadndx = (scs.threadndx+1) & 0xf; !processList[scs.threadndx].used; scs.threadndx = (scs.threadndx +1) & 0xf);
}
scs.fswitch = false;
stackFrame *fr = processList[scs.threadndx].esp;
return fr;
}
scs struct:
Code: Select all
typedef struct _state {
bool fswitch; // first switchk
uint32_t threadndx; // index of thread
} state;
state scs;
And finally the irq handler:
Code: Select all
scheduler_irq:
pusha
push ds
push es
push fs
push gs
mov ax,0x10
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
push esp
call process_schedule
cmp eax,0
jz _scheduler_error
mov esp,eax
pop gs
pop fs
pop es
pop ds
_scheduler_exit:
mov al,0x20
out 0x20,al
popa
iret
_scheduler_error:
push _schedulerError
push _schedulerName
push _schedulerFile
call panic
section .data
_schedulerError db "Returned stack null",0
_schedulerName db "scheduler_irq",0
_schedulerFile db "interruptsasm.asm",0