software based task switching help needed

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
durrow

software based task switching help needed

Post by durrow »

folks,

i've lurked for a few days looking for the right answer. i've search tutorials up and down and have read both Operating Systems design and implementation and protected mode software architecture. for the most part all my questions have been answered by these resources except for two. the only reason they aren't answer is because i'm confused and sometimes it just takes the right example to get my lightbulb lit.

question 1: software based task switching

on taskCreate i am doing the following:

Code: Select all

     setjmp(task[i].stack);
     address = (unsigned long)(stack[i] + USER_STACK_SPACE);
     task[i].active = TRUE;
     task[i].stack[0].esp = address;
     task[i].stack[0].eip = fptr;
     task[i].stack[0].eflags = 0x200;
     task[i].priority = priority;
on schedule i am doing the following:

Code: Select all

      /* save off the old task */
      setjmp(task[activeTask].stack);
      
      /* set the current next task to current */
      activeTask = valueHolder;
     
      /* set the new stack */
      longjmp(task[valueHolder].stack, 1);
      
      /* jump back kiss myself */
      asm("ret");
this seems to work okay for the most part. it task switches from the idle task to task 1, but when it tries to go back i run into a page fault, followed by a general protection fault.

any ideas? if you need more code or context please ask

my setjmp and longjmp are taken from OSD.

question 2: vm86

i am using grub for my bootloader so i'm already in protected mode. i am trying to understand [baby steps - i read about this ALOT] how to to vm86 mode. i understand the concept and i understand parts but don't know where to exactly start, and i mean START.

thank you in advance for any help.

dennis
durrow

Re:software based task switching help needed

Post by durrow »

i'll add to my first question:

Code: Select all

taskCreate called (0,255)   <--- task id, priority
doing setjmp for [0]
taskCreate called (1,10)
doing setjmp for [1]
scheduler found task [1] at priority [10]
switching to task [1] - priority [10]
"task 1" <---- output of task 1 running
switching to task [0] - no priority of interest found uses next task
doing setjmp for [1]
doing longjmp for [0]
interrupt exception page fault handler
general protection fault - unrecoverable

above is the debug output (without the code i know it's tough). hopefully the output will give you insight into the flow of what's happening.

Pype:> Please use [ code ] and [ /code ] - Click (modify) to check how i made your code readable
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:software based task switching help needed

Post by Pype.Clicker »

i think the best you can do is get the crash context for your page fault (eip, cr2, generic register values) and
1. find out where the problem occurs
2. if code pointer is valid, find out - giving the value of CR2 and of the generic register - which register combination lead to page fault and thus which variable in your C code was wrong.
Post Reply