I have implemented irqs ans my sheduler class.
my clock launch a method that look for the next thread to launch.
when this method found one, it save the state of the current thread ( in a struct that is a private object in my thread class). and load the other thread.
It works fine with 2 threads but this case crash :
the 1st thread is the main program, the second one is this function :
Code: Select all
void fonc(){
int cpt = 0;
*((unsigned char*)0xB8001) = 0xF;
for(; ; )
{
cpt += 1;
cpt%=10;
*((unsigned char*)0xB8000) = tab2[cpt];
}
}
this is my structure and my save and reload methods
Code: Select all
void Thread::reload()
{
asm("mov %0, %%gs" :: "r" (context.gs));
asm("mov %0, %%fs" :: "r" (context.fs));
asm("mov %0, %%es" :: "r" (context.es));
asm("mov %0, %%ds" :: "r" (context.ds));
asm("mov %0, %%eax" :: "r" (context.eax));
asm("mov %0, %%ebx" :: "r" (context.ebx));
asm("mov %0, %%ecx" :: "r" (context.ecx));
asm("mov %0, %%edx" :: "r" (context.edx));
asm("mov %0, %%esi" :: "r" (context.esi));
asm("mov %0, %%edi" :: "r" (context.edi));
asm("mov %0, %%esp" :: "r" (context.esp));
asm("mov %0, %%ebp" :: "r" (context.ebp));
asm("mov %0, %%ss" :: "r" (context.ss));
}
void Thread::save(){
asm("mov %%gs, %0" : "=r" (context.gs));
asm("mov %%fs, %0" : "=r" (context.fs));
asm("mov %%es, %0" : "=r" (context.es));
asm("mov %%ds, %0" : "=r" (context.ds));
asm("mov %%eax, %0" : "=r" (context.eax));
asm("mov %%ebx, %0" : "=r" (context.ebx));
asm("mov %%ecx, %0" : "=r" (context.ecx));
asm("mov %%edx, %0" : "=r" (context.edx));
asm("mov %%esi, %0" : "=r" (context.esi));
asm("mov %%edi, %0" : "=r" (context.edi));
asm("mov %%esp, %0" : "=r" (context.esp));
asm("mov %%ebp, %0" : "=r" (context.ebp));
asm("mov %%ss, %0" : "=r" (context.ss));
}
typedef struct
{
unsigned long gs;
unsigned long fs;
unsigned long es;
unsigned long ds;
unsigned long eax;
unsigned long ebx;
unsigned long ecx;
unsigned long edx;
unsigned long esp;
unsigned long ebp;
unsigned long esi;
unsigned long edi;
unsigned long eip;
unsigned long ss;
unsigned long cs;
unsigned long eflag;
} jmp_buf;
class Thread{
private:
jmp_buf context;
...
[Edited by Brendan - Added code tags due to popular demand!]