home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / linux / 8699 < prev    next >
Encoding:
Text File  |  1992-08-20  |  2.1 KB  |  53 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!cs.utexas.edu!torn!pulp.cs.laurentian.ca!ron
  3. From: ron@ramsey.cs.laurentian.ca (Ron Prediger [Velociraptor])
  4. Subject: A technical question on CONTEXT (TASK) SWITCHING by the Kernel
  5. Message-ID: <1992Aug20.164928.24749@ramsey.cs.laurentian.ca>
  6. Keywords: task switch, context switch, task state segment, kernel
  7. Organization: Dept. of Computer Science, Laurentian University, Sudbury, ON
  8. Date: Thu, 20 Aug 1992 16:49:28 GMT
  9. Lines: 42
  10.  
  11. Here is another technical question about the Linux kernel.  Context
  12. switching in particular.
  13.  
  14. I have examined the task switch macro 'switch_to' in sched.h and have some
  15. difficulty comprehending what exactly is happening.  Part of my problem is
  16. deciphering the assembler syntax and how operands are being used (GNU RTL
  17. syntax).
  18.  
  19. I believe, that after checking that the requested task is not the current
  20. one, the code makes a far jump to the TASK STATE SEGMENT of the desired
  21. process.  (Jumping/calling a task state segment or gate should result
  22. in a task switch.)  My lack of understanding,  partly due to syntax , is
  23. figuring out what is in operand %0 (is it the the contents of __tmp with
  24. the upper 32 bits (__tmp.b) set to _TSS(n), the lower 16bits of which will
  25. select a task state segment descriptor in the GDT ?)
  26.  
  27. Also,  how does the line with '_last_task_used_math' ever get executed ?
  28. I assume it has to do with checking for which process last executed 
  29. instructions with the floating point coprocessor (387) ?
  30.  
  31. Below is the actual GNU C define macro in case anyone wishes to explain
  32. how it works:
  33.  
  34.         #define switch_to(n) {\
  35.         struct {long a,b;} __tmp;\
  36.         __asm__("cmpl %%ecx,_current\n\t"\
  37.                 "je 1f\n\t
  38.                 "movw %%dx, %1\n\t"\
  39.                 "xchgl %%ecx,_current\n\t"\
  40.                 "ljmp %0\n\t"\
  41.                 "cmpl %%ecx,_last_task_used_math\n\t"\
  42.                 "jne 1f\n\t"\
  43.                 "clts\n"\
  44.                 "1:"\
  45.                 "::"m" (*&__tmp.a),"m" (*&__tmp.b), \
  46.                 "d" (_TSS(n)), "c" ((long) task[n]) \
  47.                 :"cx");\
  48.         }
  49.  
  50. Thank you very appreciatively!
  51.  
  52. Ron Prediger.
  53.