login
Header Space

 
 

A technical question on CONTEXT (TASK) SWITCHING by the Kernel

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Here is another technical question about the Linux kernel.  Context
switching in particular.

I have examined the task switch macro 'switch_to' in sched.h and have some
difficulty comprehending what exactly is happening.  Part of my problem is
deciphering the assembler syntax and how operands are being used (GNU RTL
syntax).

I believe, that after checking that the requested task is not the current
one, the code makes a far jump to the TASK STATE SEGMENT of the desired
process.  (Jumping/calling a task state segment or gate should result
in a task switch.)  My lack of understanding,  partly due to syntax , is
figuring out what is in operand %0 (is it the the contents of __tmp with
the upper 32 bits (__tmp.b) set to _TSS(n), the lower 16bits of which will
select a task state segment descriptor in the GDT ?)

Also,  how does the line with '_last_task_used_math' ever get executed ?
I assume it has to do with checking for which process last executed 
instructions with the floating point coprocessor (387) ?

Below is the actual GNU C define macro in case anyone wishes to explain
how it works:

        #define switch_to(n) {\
        struct {long a,b;} __tmp;\
        __asm__("cmpl %%ecx,_current\n\t"\
                "je 1f\n\t
                "movw %%dx, %1\n\t"\
                "xchgl %%ecx,_current\n\t"\
                "ljmp %0\n\t"\
                "cmpl %%ecx,_last_task_used_math\n\t"\
                "jne 1f\n\t"\
                "clts\n"\
                "1:"\
                "::"m" (*&__tmp.a),"m" (*&__tmp.b), \
                "d" (_TSS(n)), "c" ((long) task[n]) \
                :"cx");\
        }

Thank you very appreciatively!

Ron Prediger.
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
A technical question on CONTEXT (TASK) SWITCHING by the Kernel, Ron Prediger [Velociraptor]..., (Thu Aug 20, 12:49 pm)
speck-geostationary