
14-01-2009, 16:27
|
|
|
|
חבר מתאריך: 19.10.07
הודעות: 65
|
|
|
ריבוי תהליכים בקרנל
כרגע אני עובד על Multitasking בקרנל שלי (יש בו כבר GDT, IDT, Paging, Memory manager וכל מיני) ומשום מה אני מקבל page fault על 0xFFFFB00A אחרי שאני מחזיר את הESP החדש של ה"thread" (אם אני לא מחזיר את אותו esp, ואני מחזיר את הesp האחרון, הכל רץ אחלה, אבל זו לא המטרה כמובן)
הקוד:
קוד:
#include "task.h"
#include "mm.h"
#include "screen.h"
#include "hardware.h"
typedef struct
{
unsigned int pid;
unsigned int stack;
unsigned int state : 1;
void (*thread)(void);
} task_t;
task_t tasks[2];
int pid;
void initialize_multitasking(void)
{
create_task(0, idle);
create_task(1, idle2);
unsigned int divisor = 1193180 / 50;
outport(0x43, 0x36);
outport(0x40, divisor & 0xFF);
outport(0x40, (divisor >> 8) & 0xFF);
outport(0x21, 0x00); // enable interrupts from IRQ 0-7 (PIT will now start working)
}
void idle(void)
{
puts("Idling...");
while(1) ;
}
void idle2(void)
{
puts("IDLE?...");
while(1) ;
}
void create_task(int id, void (*thread)())
{
asm volatile("cli");
unsigned int *stack;
stack = (unsigned int *)((unsigned int)malloc(0x1000) + 0x1000);
*--stack = 0;
*--stack = 0;
*--stack = 0x202;
*--stack = 0x08;
*--stack = (unsigned int)thread;
unsigned int i = 0;
for(;i<8;i++) // pusha
*--stack = 0;
for(i=0;i<4;i++) // ds, fs, es, gs
*--stack = 0x10;
tasks[id].stack = (unsigned int)stack;
tasks[id].state = 1;
tasks[id].thread = thread;
pid = id;
}
unsigned int schedule_tasks(unsigned int context)
{
tasks[pid].stack = context;
switch(pid)
{
case 0:
pid = 1;
break;
case 1:
pid = 0;
break;
}
return tasks[pid].stack; // CAUSES A PAGE FAULT!!!!!!
putdec(tasks[pid].stack); // this is cool and is the right address
// this works perfectly return context;
}
האסמבלי:
קוד:
extern schedule_tasks
global IRQ0
IRQ0:
pusha
push ds
push es
push fs
push gs
mov ax, 0x10
mov ds, ax
mov fs, ax
mov es, ax
mov gs, ax
push esp
call schedule_tasks
mov esp, eax
pop gs
pop fs
pop es
pop ds
popa
iret
כתבתי הערות איפה שצריך. תודה.
|