preemptie multitasking task switch

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
yolda
Posts: 13
Joined: Wed May 27, 2009 12:56 pm

preemptie multitasking task switch

Post by yolda »

Hi all, ive been having a problem with my multitasking system at the time of using the stack and making the context switch. I am using the same GDT for all processes to keep it simple, very basic memory, etc. Thast why i dont backup CS DS ES GS etc.

For some reason its not working, i get all the way to iret, but its not calling my procedure that i wanna schedule.

here i initialize the stack and put "garbage" so that when the stack is used for the first time it has useful data

Code: Select all

void run()
{
                   //set a new stack, why cant i use 0x00100000?
                    procesos[indicePCB].ebpBackup =  0x000E0000;//malloc1MB();

                   //should they both be the same value?
                    procesos[indicePCB].espBackup = procesos[indicePCB].ebpBackup;



 
                   //i do a backup of the current stack
                    __asm__  ("mov eax, ebp" : "=a" (tempSS) :);
                    __asm__  ("mov eax, esp" : "=a" (tempSP) :);

                    //set the stack to run
                    __asm__  ( "mov ebp, eax" : : "a"(procesos[indicePCB].ebpBackup));
                    __asm__  ( "mov esp, eax" : : "a"(procesos[indicePCB].espBackup));
                    
                    //push proc to call when program ends
                    __asm__  ( "push eax" : : "a"(&punteroEndProgram));  //
                   //program to call
                    __asm__  ( "push eax" : : "a"(&vectorProgramas[indice]));
                   //save registries with gargabe to pop out the 1st time, same with flags
                    __asm__  ( "pusha" );   //registros
                    __asm__  ( "pushf" );   //banderas

                   //put the call irq0 cont after an interrupt
                    __asm__  ( "push eax" : : "a"(&irq0Cont));  //

                   //update esp
                    __asm__  ("mov eax, esp" : "=a" (procesos[indicePCB].espBackup) :);


                    //print(" PRUEBA ");

                    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!




                    //restore old stack
                    __asm__  ( "mov ebp, eax" : : "a"(tempSS) );
                    __asm__  ( "mov esp, eax" : : "a"(tempSP) );
}
this is the interruption routine called by IRQ0 PIT

Code: Select all


_irq0:

     pushad
     pushfd
     cli
	
     call _schedule

_irq0Cont:


     popfd

     popad

     sti
     iretd

Here i schedule the current process

Code: Select all

void schedule ()
{
    print("\n IRQ_0 INI ");
    if (procesoActual == ultimoProceso)
    {
        procesoActual = primerProceso;
    }

    else
    {
        procesoActual++;
        if (procesoActual >= 5)
        {
            procesoActual = 0;
        }
    }
   //allow interrupts later on from PIT
    out(0x20, 0x20);

//load EBP and ESP
    __asm__  ( "mov ebp, eax" : : "a"(procesos[colaEnteros[procesoActual]].ebpBackup));
    __asm__  ( "mov esp, eax" : : "a"(procesos[colaEnteros[procesoActual]].espBackup));

//NECESARY?
    __asm__("push ebp");
    __asm__("mov ebp, esp");

    print("\n IRQ_0 END ");


}
Post Reply