Re:problem with task-switching
Posted: Thu Apr 28, 2005 8:14 pm
Hi,
When you switch from USR_TSS to SYS_TSS you're using an IRET instruction, which should clear the busy bit for USR_TSS and return to SYS_TSS. In this case the busy bit for SYS_TSS must be set for a successful return.
From Intel's System Programmer's Guide, Section 6.4.1 "Use of Busy Flag To Prevent Recursive Task Switching":
"When switching to the new task (initiated by a CALL instruction, interrupt, or exception), the processor generates a general-protection exception (#GP) if the busy flag of the new task is already set. (If the task switch is initiated with an IRET instruction, the exception is not raised because the processor expects the busy flag to be set.)"
Now there's 2 things to note here. Firstly your busy bit is behaving exactly how it should for CALL/IRET. Secondly, if it was wrong you'd get a general protection exception, not an invalid TSS exception.
To save all the confusion please use the JMP instruction only (instead of CALL/IRET). You will need to use JMP anyway when you write the scheduler, as the scheduler should be able to switch to any task without caring about the busy bit (or NT flag).
Cheers,
Brendan
When you switch from SYS_TSS to USR_TSS you're using a CALL instruction, which shouldn't clear the busy bit for SYS_TSS. This is how CALL works, and is done like this to prevent recursive task switching.DIGIT4L_PUNK wrote:as you can see, int 0x0A is generated because of switch to busy SYS_TSS (type 0x8B) but I don't understand, why doesn't the CPU clear the busy bit in SYS_TSS?!!! if it does it in case of USR_TSS...
When you switch from USR_TSS to SYS_TSS you're using an IRET instruction, which should clear the busy bit for USR_TSS and return to SYS_TSS. In this case the busy bit for SYS_TSS must be set for a successful return.
From Intel's System Programmer's Guide, Section 6.4.1 "Use of Busy Flag To Prevent Recursive Task Switching":
"When switching to the new task (initiated by a CALL instruction, interrupt, or exception), the processor generates a general-protection exception (#GP) if the busy flag of the new task is already set. (If the task switch is initiated with an IRET instruction, the exception is not raised because the processor expects the busy flag to be set.)"
Now there's 2 things to note here. Firstly your busy bit is behaving exactly how it should for CALL/IRET. Secondly, if it was wrong you'd get a general protection exception, not an invalid TSS exception.
To save all the confusion please use the JMP instruction only (instead of CALL/IRET). You will need to use JMP anyway when you write the scheduler, as the scheduler should be able to switch to any task without caring about the busy bit (or NT flag).
Cheers,
Brendan