Switching task

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
Fukuda

Switching task

Post by Fukuda »

Here is my taskmanager initialization code:

Code: Select all

void InitTaskManager(void)
{
    lldt(0);

    AddTask(Idle, "Idle task");        //->Sel = 0x18

    ltr(0x18);
    IsScheduleActive = FALSE;
    __asm__ __volatile__ ("ljmp $0x18,$0x0");
}
(to simplify code I just wrote the selector number)
and here is what bochs says:

Code: Select all

[CPU  ] jump_protected: JUMP to busy 386 TSS unsupported.
I just want to jump to my idle task... What am I doing so wrong??
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Switching task

Post by Candy »

Code: Select all

    ltr(0x18);

    __asm__ __volatile__ ("ljmp $0x18,$0x0");

Code: Select all

[CPU  ] jump_protected: JUMP to busy 386 TSS unsupported.
I just want to jump to my idle task... What am I doing so wrong??
Well, if you want to jump to your new task, you need to give the new task a TSS. You did.

You also need a TSS for the CURRENT task. You don't have one (you load only the current tasks TSS with ltr). So, when the CPU wants to switch from your current task to your new task, it found out that your new task was already running (you selected it as store for the current data too, so it was active). Solution: make 2 TSSes and load one for the current data, one for the new thread.

PS, why do you want to kickstart the idle thread?
Fukuda

Re:Switching task

Post by Fukuda »

I load current task with ltr but dont make a far jump to it. Neednt I make a far jump?
PS, why do you want to kickstart the idle thread?
This is just a try..
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:Switching task

Post by Pype.Clicker »

you may never call/jump to the current TSS. period.

If you want to try to switch to another TSS, you need to have set up a current TSS first. If you're not interrested in conserving the current CPU state in any TSS, just load TR register with a selector to a "trash" TSS that you never jump to, but often jump from (that's a trick i learned from TRAN =).

If you just want to tell the CPU which is the "current" TSS, just use the LTR instruction, but do not jump.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Switching task

Post by Candy »

Fukuda wrote: I load current task with ltr but dont make a far jump to it. Neednt I make a far jump?
Well, on a jump to a TSS the current state is stored in the current TSS, and the new state is loaded from the new TSS.

So, you need a TSS to store the current state to, and a TSS to load the new state from. You cannot make them the same, so you have to have some place to dump the current context, even if you never use it again.
Fukuda

Re:Switching task

Post by Fukuda »

I load ltr with 0x20 and jump to 0x18.

Code: Select all

    lldt(0);

    AddTask(Idle, "Idle task");
    AddTask(taskA, "task A");
    AddTask(taskB, "task B");

    ltr(0x18);
    IsScheduleActive = FALSE;
    __asm__ __volatile__ ("ljmp $0x20,$0x0");
This time bochs gave no error but jmping is not successfull. Because it resets and restarts again continuously. (No scheduler activated yet) What may be wrong?
Post Reply