home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / intel / 2272 < prev    next >
Encoding:
Text File  |  1992-11-18  |  3.0 KB  |  61 lines

  1. Newsgroups: comp.sys.intel
  2. Path: sparky!uunet!epicb!pauls
  3. From: pauls@truevision.com (Paul Scherf)
  4. Subject: Question about i386/i486 protected mode far jumps
  5. Message-ID: <1992Nov18.222722.26786@truevision.com>
  6. Summary: Why does it clear the NT flag of the destination
  7. Keywords: protected mode, far jumps
  8. Organization: Truevision Inc., Indianapolis, IN
  9. Date: Wed, 18 Nov 1992 22:27:22 GMT
  10. Lines: 49
  11.  
  12. In an attempt to better understand protected mode, I'm trying to figure out far
  13. CALL, far IRET and far JMP. Let me call them simply CALL, IRET and JMP.
  14.  
  15. When a CALL, IRET or JMP causes a task switch (e.g. by referencing a TSS or a
  16. task gate), it appears that the important things to understand are what happens
  17. to the busy bits, NT flags and link fields of the old and new tasks.
  18.  
  19. The busy bit seems straight forward. It keeps track of whether the TSS is in
  20. the middle of execution. JMP and IRET clear the busy bit of the old TSS (the
  21. old TSS is becoming inactive), while CALL leaves the busy bit of the old TSS
  22. (it will be on) alone. JMP and CALL ensure the busy bit of the new TSS was off
  23. and turn on the busy bit of the new TSS (the new TSS is becoming active), while
  24. IRET leaves the busy bit of the new TSS (it better already be on) alone.
  25.  
  26. The link field of a TSS is used to keep a stack of TSS's (implemented as a
  27. linked list). CALL pushes a TSS onto the stack. That is, CALL points the link
  28. field of the new TSS at the old TSS, and sets the NT flag. IRET pops a TSS from
  29. the stack. That is, IRET uses the link field of the old TSS to find the new
  30. TSS, and clears the NT flag of the old TSS.
  31.  
  32. JMP, well, I'm a bit confused about JMP. The book (i486 Programmer's Reference
  33. Manual) says that JMP clears the NT flag of the new TSS. If JMP left the NT
  34. flag of the new TSS alone, it would make more sense to me.
  35.  
  36. I can think of several possible scenarios where a system might have several TSS
  37. stacks. I can imagine the currently executing task (at the top of a TSS stack)
  38. wanting to switch to a particular other task (e.g. at the top of one of the
  39. other TSS stacks).
  40.  
  41. JMP seems to do the right thing with the busy bits. The new TSS becomes busy.
  42. The old TSS becomes not busy. JMP seems to do the right thing with the link
  43. fields of the old and new tasks, it leaves them alone. That seems reasonable,
  44. they should return to whatever CALL'd them. JMP doesn't seem to do quite the
  45. right thing with the NT flags. It does leave the NT flag alone on the old TSS,
  46. but it clears the NT flag on the new TSS. This invalidates the return chain of
  47. the new TSS.
  48.  
  49. I can see a work-around for this situation. CALL a "task switcher" TSS, that
  50. IRET's to the desired new TSS. This still leaves me wondering what JMP is good
  51. for.
  52.  
  53. Why does JMP clear the NT flag of the new TSS? JMP clearly doesn't do the right
  54. thing for my example. What are some correct uses of JMP? Am I missing something
  55. about CALL and IRET? Is there a good book that gets to at least this level of
  56. detail about the i486?
  57.  
  58. Paul Scherf
  59. pauls@truevision.com
  60. Truevision Inc., Indianapolis, IN
  61.