home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / intel / 1491 < prev    next >
Encoding:
Internet Message Format  |  1992-08-13  |  4.1 KB

  1. Path: sparky!uunet!gossip.pyramid.com!olivea!mintaka.lcs.mit.edu!ai-lab!zurich.ai.mit.edu!jinx
  2. From: jinx@zurich.ai.mit.edu (Guillermo J. Rozas)
  3. Newsgroups: comp.sys.intel
  4. Subject: Re: 386 <-> 486 incompatibilities
  5. Message-ID: <JINX.92Aug13131053@rolex.ai.mit.edu>
  6. Date: 13 Aug 92 17:10:53 GMT
  7. References: <16ds34INNpvn@fbi-news.Informatik.Uni-Dortmund.DE>
  8. Sender: news@ai.mit.edu
  9. Reply-To: jinx@zurich.ai.mit.edu
  10. Organization: M.I.T. Artificial Intelligence Lab.
  11. Lines: 79
  12. In-reply-to: eggenste@cantor.informatik.uni-dortmund.de's message of 13 Aug 92 14:37:24 GMT
  13.  
  14. In article <16ds34INNpvn@fbi-news.Informatik.Uni-Dortmund.DE> eggenste@cantor.informatik.uni-dortmund.de (Heinz-Bernd Eggenstein) writes:
  15.  
  16. |   From: eggenste@cantor.informatik.uni-dortmund.de (Heinz-Bernd Eggenstein)
  17. |   Newsgroups: comp.sys.intel
  18. |   Date: 13 Aug 92 14:37:24 GMT
  19. |
  20. |   Hello!
  21. |
  22. |   Among the few MS-DOS programs that will run on a 80386, but not on
  23. |   an i486 based machine, there's a program called "PC Scheme"
  24. |   by Texas Instruments (Scheme is a Lisp-like language). 
  25. |
  26. |   According to rumors, this is a result of the program changing 
  27. |   some instructions in its own code-segment at runtime. 
  28. |
  29. |   -How can this cause incompatibilities between 
  30. |    80386 and i486 processors?
  31. |   -I don't think every  self-modification of a program will
  32. |    cause problems. Exactly under what conditions may 
  33. |    problems occur? 
  34. |   -Is there a way to detect this kind of self-modification
  35. |    either at runtime (say, with a small TSR debugger-like program) or 
  36. |    scanning the assembly-code sources.
  37. |   -Are there any other mayor causes for i486 incompatibilities?
  38. |
  39.  
  40. The 486 does not have split I and D caches, so the only way this sort
  41. of practice can lose is if the instruction being modified is in the
  42. same pre-fetch block as the instruction doing the modification.
  43.  
  44. The i486 Microprocessor Programmer's Reference Manual states in
  45. section 12.2.3:
  46.  
  47. "12.2.3:
  48.  
  49. Self-modifying Code
  50.  
  51. A write to an instruction in the cache will modify it in both the
  52. cache and memory, but if the instruction was prefetched before the
  53. write, the old version of the instruction could be the one executed.
  54. To prevent this, flush the instruction prefetch unit by coding a jump
  55. instruction immediately after any write that modifies an instruction."
  56.  
  57. Of course, this has nothing to do with self-modifying code becase it
  58. applies equally well to newly generated code.
  59.  
  60. In general you can't detect such modification unless you emulate the
  61. code.  If you are replacing an old instruction, the old one will be
  62. executed, and there may be nothing wrong with it that the processor
  63. will detect.
  64.  
  65. However, if the instructions are always written into previously unused
  66. memory (and therefore it is not true self-modification), you could
  67. pre-initialize such memory with debugging instructions (e.g. `INT 3' =
  68. #xCC in Scheme = 0xcc in C).
  69.  
  70. You would have to add an interrupt handler for INT 3 which could check
  71. the contents of the address where the interrupt occurred.  If it was
  72. still `INT 3', you would continue into the normal handler.  If it was
  73. not, it would mean that it was a spurious prefetch problem, and merely
  74. backing up the PC (if necessary, I don't remember which of the PCs
  75. would be reported in the interrupt structure) and continuing normally
  76. would fix the problem, since the prefetch buffer would have been
  77. flushed by the interrupt.  Even more cleverly, if the alignment of the
  78. new instructions is fixed and sufficient, you could pre-initialize
  79. your memory with instructions to CALL an out-of-line handler at a
  80. fixed address.  This out-of-line handler would back up the PC and jump
  81. right back, since the prefetch buffer would already be clear.
  82.  
  83. There are other differences with the i386 processor.  The most
  84. noticeable are various new instructions and mode bits, especially the
  85. "Alignment Check" bit.  If the "Alignment Check" bit is turned on
  86. (which I doubt because many PC programs would lose, not only PC
  87. Scheme), reading and writing to memory (MOV instructions) is legal
  88. only at addresses which are integer multiples of the size of the
  89. transfer (e.g. even addresses for 16-bit moves, addresses divisible by
  90. 4 for 32-bit moves).
  91.  
  92. I hope this helps.
  93.