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.
prepare a dummy TSS, will be used only once.
ltr ax with the selector of that TSS
prepare a new TSS, will be used to host a hardware task
far jump to this selector (offset ignored)
reuse first TSS or scrap it
After this, you are running in the context of the second TSS. There is no need to modify TR hereafter. If you want to switch to a new hawrdware task, simply far jump to the selector of its TSS. Also there is no need to save/restore the stack before or after the task switch. When control gets back to the instruction after the far jump, every register is restored by the processor. Just like if the far jump never happened. This is in contrast with software multitasking (stack-based multitasking), where you use one TSS (that rules all ) and have to save/restore the stack and (at least nonvolatile) registers manually.
InsightSoft wrote:
After this, you are running in the context of the second TSS. There is no need to modify TR hereafter. If you want to switch to a new hawrdware task, simply far jump to the selector of its TSS. Also there is no need to save/restore the stack before or after the task switch. When control gets back to the instruction after the far jump, every register is restored by the processor. Just like if the far jump never happened. This is in contrast with software multitasking (stack-based multitasking), where you use one TSS (that rules all ) and have to save/restore the stack and (at least nonvolatile) registers manually.
Well, actually I already have my MT up and running using save/restore stack-based... but I want try to use intel facility (better performance)...
...on my sequences, the steps 3 and 4 are automatic... I will remove the TR update (step 1)...
ru2aqare wrote:
If don't know offhand what gate type 11 is, but are you sure you are not jumping to a busy TSS?
I want to resume a task that was suspended...
Still, the descriptor of that TSS should be available, not busy. A busy TSS is the hardware task the processor is currently executing, if I remember correctly.
ru2aqare wrote:
If don't know offhand what gate type 11 is, but are you sure you are not jumping to a busy TSS?
I want to resume a task that was suspended...
Still, the descriptor of that TSS should be available, not busy. A busy TSS is the hardware task the processor is currently executing, if I remember correctly.
I'm confused right now... I have two different task up and running (each with its own TSS)
when the task 2 take place, the system saves automatically the sate of the task 1 (right?).
To back to the task 1. Should I clear the bit P???
InsightSoft wrote:I'm confused right now... I have two different task up and running (each with its own TSS)
when the task 2 take place, the system saves automatically the sate of the task 1 (right?).
That's right. Whenever you far jump to another task, the processor saves its state to the current TSS (pointer to by the TR), loads its new state from the new TSS (which must be available - busy TSS will result in #GP), and continues execution.
InsightSoft wrote:
To back to the task 1. Should I clear the bit P???
I have 2 entries on GDT reserved for TSS (just two simple endless loops)
(0=reserved; 1=4gb/32bits/code; 2=4gb/32bits/data; 3=TSS/32bits task 1; 4=TSS/32bits/task 2)
TR still pointing to gdt 4. should I change to gdt:3?
how to back to task 1? Simple far jmp to the gdt index 3? jmp using saved cs:eip? (on tss saved? (regarding to gdt:3))
Im really lost at this stage... I just want to put system switching between this two endless loops...
TR still pointing to gdt 4. should I change to gdt:3?
how to back to task 1? Simple far jmp to the gdt index 3? jmp using saved cs:eip? (on tss saved? (regarding to gdt:3))
Im really lost at this stage... I just want to put system switching between this two endless loops...
No, you dont need to touch TR once it was set by some initialization code. You should leave it as selector 4, and perform a simple far jump to selector 3. For example,
push selector
call switch_task
...
switch_task proc near
jmp far ptr [esp+0] ; make use of the fact that offset is ignored, and caller's EIP can be used as offset
retn
switch_task endp
Thanks,
but this is my big problem... it is exactly what Im doing right now...
when jmps to, I get the bochs error: "jump_protected: gate type 11 unsupported" (reading the bochs source code: this is a default switch escape message)
TR still pointing to gdt 4. should I change to gdt:3?
how to back to task 1? Simple far jmp to the gdt index 3? jmp using saved cs:eip? (on tss saved? (regarding to gdt:3))
Im really lost at this stage... I just want to put system switching between this two endless loops...
No, you dont need to touch TR once it was set by some initialization code. You should leave it as selector 4, and perform a simple far jump to selector 3. For example,
InsightSoft wrote:
the pushed selector is the TSS??? or is the CS of task???
The selector of the TSS. If it would be the selector of the cs: descriptor, the far jump wouldn't be a task switch, now would it?
when jmps to, I get the bochs error: "jump_protected: gate type 11 unsupported" (reading the bochs source code: this is a default switch escape message)
Check your descriptors, I can't say anything more specific.
edit: checked my sources. gate type 11 is the busy TSS descriptor. Are you sure you are not loading/reloading TR with the selector of the target task's TSS?
ru2aqare wrote:
edit: checked my sources. gate type 11 is the busy TSS descriptor. Are you sure you are not loading/reloading TR with the selector of the target task's TSS?
using a far return, far jump, far call, or task gate have severe implications on how the task state works.
I do this from memory, but you should *really* look all this up and not do all this shotgun debugging. If something did work out here, you would have learned little from it. And regrettably, you have not been doing your homework AT ALL (and next time you WILL be left without answer)
A far jump will mark the current tss as idle, and the new one as busy (must have been idle)
A far call will mark the new tss as busy (must have been idle), store a pointer in the backlink field, and leaves the original busy as well
An iret (with NT set) will jump to the task in the backlink pointer (must be busy) and marks the current one as idle A far return may never return to another TSS.
There is a reason why everybody else uses the far more simple software task switching.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]