Some tips for Context switching

You may continue to use the `setjmp+longjmp' mechanism. Neha has figured out that OsKit's setjmp.h structure is borrowed from FreeBSD. You can check out FreeBSD's setjmp.h (should be available easily on the net) to figure out where in the jmpbuf structure are the SP and PC.

If you use this method of context switching you should become familiar with the OsKit's implementation of setjmp, longjmp,... For setjmp, you may look at these files in the OsKit root directory. Similarly for longjmp. Note that you will be quizzed on this during the demonstration.

Alternatively, you may use OsKit's trap_state for context switching. Here is an assortment of code supplied by Soumyadeb which may help you in context switching for A4.

Beware that you will be quizzed thoroughly during your demonstration if you use this mechanism.

First assume that you have registered the following interrupt handlers:

//Setting IRQ Handler
//Setting Trap Handlers

Assume that your typical pcb structure is as given in pcb.h. Then you can put your context switch codes save_pcb.c and load_thread.c in your handlers which should be defined as:

struct pcb_struct *current_pcb;
unsigned int *esp_pointer;

//Timer Interrupt Handler
int timer_interrupt_handler(struct trap_state *tsptr)
//Your stuff ...followed by saving context
              esp_pointer+=1;//Getting the esp of interrupted process
              save_pcb(current_pcb,tsptr,curr_time);//Save the context
              current_pcb->esp=esp_pointer;//Saving the esp
              append_to_queue(current_thread_id);//Append the current thread
//Your stuff ...followed by loading context
          current_pcb=next_thread();//Returns pointer to the pcb;
          tsptr->eip=&load_thread;//Load the next thread


//System Call Interrupt Handler
int system_call_interrupt_handler(struct trap_state *tsptr)
//Your stuff. Similar to above but you'll have to pull out
// args from arg0=*(esp_pointer+1) ... etc and also put
// return values.

Check out here for the trap_state structure.

Hope this helps you submit soon. All good things must come to an end!

Subhashis Banerjee / Dept. Computer Science and Engineering / IIT Delhi / Hauz Khas/ New Delhi 110016 /