Page 1 of 1

V86

Posted: Tue Apr 27, 2004 11:00 pm
by Mius
How can i use a v86 monitor with software taskswitching?

RE:V86

Posted: Tue Apr 27, 2004 11:00 pm
by TheUbu
Mius,

You can not do it with software taskswitching you will need to user TSS atleast just for your v86 monitor... The intel programmers ref for ia32 vol3 goes over this in quite detail.



-Christopher

RE:V86

Posted: Tue Apr 27, 2004 11:00 pm
by CodeSlasher
TheUbu I think you are wrong.
The manual says it is possible to switch to V86 mode only by an interrupt return with a stack that has the proper layout and VM bit set in the EFLAG on the Stack.(and some other methods, I dont have the manual here)
so if you are using software task switching, the stack that you want to use for the V86 task has to have its VM bit set in the EFLAG dword on the stack.
Besides, even if you use software task switching,you still need at least 1 TSS so that the CPU can get the stack pointer to use for Ring 0 and 3.
so with 1 TSS, you have to patch the tss fields for a task to be switched to before the switch.

RE:V86

Posted: Tue Apr 27, 2004 11:00 pm
by TheUbu
CodeSlasher,

You know you're right I didn't think about going into v86 mode that way. As far as the TSS I don't know if the original post was using anything other then ring 0.


-Christopher

RE:V86

Posted: Wed Apr 28, 2004 11:00 pm
by Mius
How can i use only 1 tss for all my tasks? if i modify his values, it don't change.

RE:V86

Posted: Wed Apr 28, 2004 11:00 pm
by TheUbu
Mius,

Of course the TSS is cached however remember to reset the busy bit.



-Christopher

RE:V86

Posted: Wed Apr 28, 2004 11:00 pm
by Mius
it doesn't work.
can you please write all the steps needed to do this type of switching?
the hardware taskswitching doesn't work too :-(((
only the software one works properly.

RE:V86

Posted: Thu Apr 29, 2004 11:00 pm
by CodeSlasher
You need to also RELOAD THE TSR before you do the stack switch
Here is my C code to do that

void patch_tss()
{
        sys_tss.ss0 = running_task->stack0_sel;
        sys_tss.esp0 =(unsigned long)running_task->stack0_ptr;
        sys_tss.ss = running_task->stack3_sel;
        sys_tss.esp = (unsigned long)running_task->stack3_ptr;
        sys_tss.eflags = running_task->eflags;

        update_gdt_entry(KERNEL_TSS_SEL,KERNEL_TSS|TSS_NOT_BUSY);

        load_task_reg(KERNEL_TSS_SEL);
        return;
}
after this function returns, I then switch tasking using the software stack method

RE:V86

Posted: Thu Apr 29, 2004 11:00 pm
by TheUbu
Mius:

For each task have a TSS structure the format of the structure you can pull out of the Intel docs...

Set up your first TSS when your scheduler comes around just have it update the TSS entry in your GDT and do a far jmp to it here is a quick sample code that would be in your scheduler..

  GDT[4].descriptor.baseLow  = (memAddr & 0xFFFF);
  GDT[4].descriptor.baseMed  = ((memAddr >> 16) & 0xFF);
  GDT[4].descriptor.baseHigh = (memAddr >> 24);
  GDT[4].descriptor.access   = '\x89';
    asm("ljmp $0x20,$0\n");

In your kernel initialization code you would hat ltr 0x20


-Christopher