Multitasking

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.
piranha

Multitasking

Post by piranha »

Does anyone have a link for a tutorial or simple example of multitasking?

It would be really helpful!

Thx!
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Multitasking

Post by Pype.Clicker »

http://www.mega-tokyo.com/osfaq/Context%20Switching

(sometimes i wonder what's the use of "read before you post" mention in the QuickLinkz thread title)
User avatar
ces_mohab
Member
Member
Posts: 77
Joined: Wed Oct 18, 2006 3:08 am

Re:Multitasking

Post by ces_mohab »

I think the following link is useful. just copy and past code as it with small modifications then understand each line finally write your own. http://www.osdever.net/tutorials/multitasking.php?the_id=84
::)
To write an OS you need 2 minds one for coding and other for debugging.
piranha

Re:Multitasking

Post by piranha »

thanks

"(sometimes i wonder what's the use of "read before you post" mention in the QuickLinkz thread title)": sorry.

" just copy and past code as it with small modifications ": What are the modifications, please?
User avatar
ces_mohab
Member
Member
Posts: 77
Joined: Wed Oct 18, 2006 3:08 am

Re:Multitasking

Post by ces_mohab »

I mean by small modifications , make code fit to your source code. I don't know how you handle interupts and IRQs. :-*
To write an OS you need 2 minds one for coding and other for debugging.
piranha

Re:Multitasking

Post by piranha »

Ok...But when I make the modifications, and compile, I get these:

sched.c:65: error: 'kstacks' undeclared (first use in this function)
sched.c:65: error: (Each undeclared identifier is reported only once
sched.c:65: error: for each function it appears in.)
sched.c:65: error: 'd'undeclared (first use in this function)
sched.c:65: error: 'KSTACKTOP' undeclared (first use in this function)
sched.c:66: warning: value computed is not used
sched.c:84: error: 'processes' undeclared (first use in this function)
sched.c:84: error: 'f' undeclared (first use in this function)
sched.c:87: error: 'stacks' undeclared (first use in this function)
sched.c:87: error: 'USTACKTOP' undeclared (first use in this function)
sched.c:58: warning: unused parameter ';priority'
sched.c: In function 'sctimer_handler':
sched.c:96: error: 'task_to_bill' undeclared (first use in this function)
sched.c:101: warning: implicit declaration of function 'schedule'
sched.c: At top level:
sched.c:108: warning: conflicting types for 'schedule';
sched.c:101: warning: previous implicit declaration of 'schedule' was here
sched.c: In function 'schedule':
sched.c:109: error: 'ELEMENT' undeclared (first use in this function)
sched.c:109: error: ‘proz’ undeclared (first use in this function)
sched.c:110: warning: implicit declaration of function ‘queue_empty’
sched.c:110: error: ‘roundrobin_prozesse’ undeclared (first use in this function)
sched.c:114: warning: implicit declaration of function ‘remove_first_element_from_queue’
sched.c:116: warning: implicit declaration of function ‘add_element_to_queue_rear’
sched.c:120: warning: implicit declaration of function ‘choose_prozess’
sched.c: In function ‘task_anlegen’:
sched.c:88: warning: control reaches end of non-void function

Do I need to write my own functions for these?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Multitasking

Post by Pype.Clicker »

well, that suggests me that you're missing a .h file. Clearly, there are a couple of "global variables" such as the array of kernel stacks or the pointer to the current task that you do not define.

You're also missing some constants such as the initial value for top-of-stack in the user-space stacks or kernel-space stacks...
User avatar
ces_mohab
Member
Member
Posts: 77
Joined: Wed Oct 18, 2006 3:08 am

Re:Multitasking

Post by ces_mohab »

When I looked at my code I found it 's very different from this tutorial but I can help you.
Declare the following variables

Code: Select all

#define MAX_PROCESS 100
struct process* current_process ;
struct process process_tab[MAX_PROCESS] ;

#define KSTACKTOP 1024
#define USTACKTOP 1024

unsigned char kstacks[MAX_PROCESS][KSTACKTOP] ;
unsigned char stacks[MAX_PROCESS][USTACKTOP] ;

Use a simple scheduling function as follows:

Code: Select all

void schedule( void )
{   
   if( current_process->process_number == 0 ){
      current_process = &process_tab[1] ;
   else if(current_process->process_number == 1 ){
      current_process = &process_tab[2] ;
   else if(current_process->process_number == 2 )
      current_process = &process_tab[3] ;
   else
      current_process = &process_tab[0] ;
}
use task_anlegen as follows:

Code: Select all

void init_task( int task , unsigned epoint )
{
    uint_t *stacksetup; 
    stacksetup=&kstacks[task][KSTACKTOP]; //esp0
    stacksetup-- ;         //SS
    *stacksetup--=0x0202;  //flags
    *stacksetup--=0x08;    // CS
    *stacksetup--=epoint;  // Instruction pointer
   *stacksetup--= 0;      //error code
   *stacksetup--=0x20;    // interupt no.
 
   *stacksetup--=0;    //ebp
    *stacksetup--=0;    //esp
    *stacksetup--=0;    //edi
    *stacksetup--=0;    //esi
    *stacksetup--=0;    //edx
    *stacksetup--=0;    //ecx
    *stacksetup--=0;    //ebx
    *stacksetup--=0;    //eax
    
   *stacksetup--=0x20; //ds
    *stacksetup--=0x20; //es
    *stacksetup--=0x20; //fs
    *stacksetup=  0x20; //gs

   //filling in the struct.
    process_tab[task].process_esp=(uint_t)stacksetup;
    process_tab[task].process_ss=0x10;
    process_tab[task].process_kstack=(uint_t)&kstacks[task][KSTACKTOP];
    process_tab[task].process_ustack=(uint_t)&stacks[task][USTACKTOP];

   process_tab[task].process_number = task ;

}
Finally use init_process_tab before enabling interupts:

Code: Select all


void t1(void) ;
void t2(void) ;
void t3(void) ;

void init_process_tab(void)
{
   init_task( 1 , t1 ); 
   init_task( 2 , t2 ) ;
   init_task( 3 , t3 ) ;
   current_process = &process_tab[0] ;
}
Where t1 and t2 and t3 are 3 tasks doing any thing, I suggest each one prints a character. You notice there are 4 tasks where is the forth which is task 0?? It?s the kernel itself you may force the kernel to infinite loop just after enabling interrupts. As you noticed we didn't initialize it because it's saved when the first interrupt occurs.

I am not sure if this code will work.
[move]Good luck ::)[/move]
To write an OS you need 2 minds one for coding and other for debugging.
piranha

Re:Multitasking

Post by piranha »

Is this preemptive or Cooperative?
piranha

Re:Multitasking

Post by piranha »

ok, but when I compile i get:

schedul.c:3: error: array type has incomplete element type
schedul.c: In function ‘schedule’:
schedul.c:16: error: dereferencing pointer to incomplete type
schedul.c:17: error: dereferencing pointer to incomplete type

(the file name is schedul.c. But you might have figured that out)
piranha

Re:Multitasking

Post by piranha »

actually, nvm.

i got it to compile, but it doesnt work.
the main function does this:
gdt_install();
idt_install();
isrs_install();
irq_install();
keyboard_install();
init_process_tab();
timer_install();
sti();
   for(;;);

and the timer interrupt calls schedule every 10 ticks.

the t1, t2, t3 functions put "Hello, my name is t[1,2,3]"

but when the OS runs, nothing happens
help?!?!
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Re:Multitasking

Post by Kevin McGuire »

Try making the schedule function print something to the screen. ???
piranha

Re:Multitasking

Post by piranha »

Ok, the scheduler does get called. I verified that
Now what?
help!
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Re:Multitasking

Post by Kevin McGuire »

Having completed your new PC, take some time to go back over your work in the previous steps, and check that all your connections are correctly aligned and secure, and that your CPU, RAM and cards are all secure in their fixings. A thorough check here can save a lot of frustration later on.

Proceed now by connecting the remaining devices, such that you can power up and test the new machine. Position the PC case such that you have clear access the sockets/connectors at the back.
15-way VGA connector
DVI connector
Monitor signal cable

Take the Monitor display cable, and connect it to the suitable connector on the Video Card backplate. Use the cable screws if necessary to fully secure the cable. Do not worry about other connectors on the Video card at this stage.

Once this is completed the scheduler will magicly start working all on its own.

Or, Try these links.

http://www.mega-tokyo.com/osfaq/
http://www.osdever.net/
http://www.mega-tokyo.com/osfaq/Help%21 ... crashed%21
User avatar
ces_mohab
Member
Member
Posts: 77
Joined: Wed Oct 18, 2006 3:08 am

Re:Multitasking

Post by ces_mohab »

Just try to print data in stack just before iret in your IRQ handler

You know the 5 poped variables before iret
esp
SS
eflags
CS
eip

and check their values
To write an OS you need 2 minds one for coding and other for debugging.
Post Reply