Ich hab hier irgendeinen Bug im Multitasking, und zwar wird beim return von task_scheduler() irgendwo hingesprungen, wo gar nicht gesprungen werden soll. Wers hinkriegt, darf den taskhandler behalten/benutzen
task.asm (handler)
task.c (die logik und alles)
task.asm (handler)
Code: [Auswählen]
[global _timer_int]
[extern _task_scheduler]
_timer_int:
cli
pusha ;Save registers
push ds
push es
push fs
push gs
call _task_scheduler ;Call C Scheduler
mov esp, eax ;Put return value(eax) into esp
;Send EOI to PIC
mov al, 0x20
out 0x20, al
pop gs
pop fs
pop es
pop ds
popa
sti
iret
task.c (die logik und alles)
Code: [Auswählen]
/*-------------------------------------------------------------------------------------------
Delta Nanocore
This file is part of the implementation of Delta Nanocore.
You may use this code to understand how things work, but
you may NOT copy/use this code for your own purposes.
If you want to, you need permission by the Author of this code (Clemens Brust).
You may distribute the binaries for free. If you want to sell them, ask the Author
for permission.
Copyright (C) 2005 by Clemens-Alexander Brust
-------------------------------------------------------------------------------------------*/
struct task
{
unsigned long t_esp;
unsigned long t_id;
unsigned long t_cr3;
char* t_descriptor;
};
struct task_node
{
struct task t_task;
struct task_node* prev;
struct task_node* next;
};
struct task_node* task_current;
unsigned long task_enable=0;
unsigned long esptarget;
unsigned long cr3target;
// Prototypes:
struct task_node* task_init();
unsigned long task_add(unsigned long t_eip, unsigned long t_esp, unsigned long t_id, unsigned long t_cr3, char* descriptor);
struct task_node* task_last();
struct task_node* task_first();
void task_unlink(struct task_node* tnode);
void task_attach(struct task_node* tnode);
void task_next();
unsigned long task_scheduler();
void task_store_data();
//Implementations
struct task_node* task_init()
{
task_current=kmalloc(sizeof(struct task_node));
if(task_current==0)
return 0;
task_current->prev=0;
task_current->next=0;
task_current->t_task.t_id=0;
task_current->t_task.t_esp=read_esp();
task_current->t_task.t_cr3=read_cr3();
task_current->t_task.t_descriptor="Nanocore";
task_enable=1;
return task_current;
}
unsigned long task_add(unsigned long t_eip, unsigned long t_esp, unsigned long t_id, unsigned long t_cr3, char* descriptor)
{
struct task_node* tnode=0;
tnode=kmalloc(sizeof(struct task_node));
if(tnode==0)
{
return 0;
}
tnode->t_task.t_esp=t_esp;
*(unsigned long*)t_esp=t_eip;
asm("cli");
unsigned long tmp_esp=read_esp();
write_esp(t_esp-4);
asm("pushal");
asm("push %ds");
asm("push %es");
asm("push %fs");
asm("push %gs");
write_esp(tmp_esp);
tnode->t_task.t_id=t_id;
tnode->t_task.t_cr3=t_cr3;
tnode->t_task.t_descriptor=descriptor;
tnode->prev=task_current;
task_attach(tnode);
asm("sti");
return;
}
struct task_node* task_last()
{
struct task_node* p=task_current;
while(p->next)
{
p=p->next;
}
return p;
}
struct task_node* task_first()
{
struct task_node* p=task_current;
while(p->prev)
{
p=p->prev;
}
return p;
}
void task_unlink(struct task_node* tnode)
{
if(tnode)
{
if(tnode->next)
tnode->next->prev=tnode->prev;
if(tnode->prev)
tnode->prev->next=tnode->next;
}
return;
}
void task_attach(struct task_node* tnode)
{
task_last()->next=tnode;
return;
}
void task_next()
{
if(task_current->next)
{
task_current=task_current->next;
}
else
{
task_current=task_first();
}
return;
}
unsigned long task_scheduler()
{
printm("task_scheduler","test");
if(task_enable)
{
task_store_data(); // Save
task_next(); // All the logic is in there
printm("using task",task_current->t_task.t_descriptor);
char esp_d[8];
itoa(esp_d,'x',task_current->t_task.t_esp);
printm("esp",esp_d);
return task_current->t_task.t_esp; //<<<<<------ ERROR!
}
printm("task_scheduler","done");
return read_esp();
}
void task_store_data()
{
task_current->t_task.t_esp=read_esp();
task_current->t_task.t_cr3=read_cr3();
return;
}

Übersicht
Wiki
Hilfe
Suche
Einloggen
Registrieren
Drucken


Gespeichert

