home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / msdos / programm / 12316 < prev    next >
Encoding:
Text File  |  1993-01-21  |  2.6 KB  |  82 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!sgiblab!adagio.panasonic.com!chorus.mei!saturn.mew!srl!gah
  3. From: gah@trc.mew.mei.co.jp (Gary A. Hildebrand)
  4. Subject: Is there any way to force MASM 5.1 to generate NEAR jumps?
  5. Message-ID: <GAH.93Jan22082547@trcrik.trc.mew.mei.co.jp>
  6. Sender: news@srl.mew.mei.co.jp
  7. Nntp-Posting-Host: akihabara.trc.mew.mei.co.jp
  8. Organization: Matsushita Electric Works Ltd., Tokyo, Japan.
  9. Date: Thu, 21 Jan 1993 23:25:47 GMT
  10. Lines: 70
  11.  
  12. All,
  13.  
  14. Consider the following macro and code, which are the early stages of an
  15. exception handler plus entry points for a virtual 8086 monitor:
  16.  
  17. ;
  18. ; Macro acts as entry point to handler from IDT entry n
  19. ;
  20. idt_vec        macro    n
  21.         push    ax        ; save a register
  22.         mov    al,n        ; load vector index
  23.         jmp    near ptr mhandler    ; chain to master handler
  24.         endm
  25.  
  26.         .CODE
  27.  
  28. mhandler:
  29.         pop    ax
  30.         iretd
  31.  
  32. idt_vec0:
  33.         idt_vec    0
  34. idt_vec1:
  35. x = 1
  36.         rept    255
  37.         idt_vec    x
  38. x = x + 1
  39.         endm
  40.  
  41. Here is the code which will place the offsets of the entry points in an IDT:
  42.  
  43. ;
  44. ; load offsets for gate descriptors in IDT
  45. ;
  46.         mov    ax,offset idt_vec0
  47.         mov    di,offset idt
  48.         mov    cx,256
  49.         cld
  50. next_idt_vec:
  51.         stosw
  52.         add    di,6
  53.         add    ax,idt_vec1 - idt_vec0
  54.         loop    next_idt_vec
  55.  
  56. What's wrong, you ask?  Even though the `mhandler:` label is not forward
  57. referenced by the expanded `idt_vec` macro, and the jump to `mhandler:` has
  58. been typed as a near one, MASM 5.1 tries to optimize the jumps
  59. nevertheless.  The first 20 or so entry points will use short jumps instead
  60. of near ones.  Normally this would be acceptable, but the IDT loader code
  61. depends on the code size for each entry point being the *same*, since it
  62. just uses the size of the first entry point.
  63.  
  64. Is there any trick to make MASM 5.1 not optimize these jumps?  It seems
  65. kind of silly to place the `mhandler` and `idt_vec` sections in completely
  66. different parts of the code segment, or stick a bunch of NOP's after the
  67. IRETD.  Of course, it's very likely that the real `mhandler` section will
  68. be large enough to prevent this problem from occurring, but there should be
  69. a way to control what MASM is doing.  I haven't tried giving this to TASM,
  70. to see what it would do.  Once again, this is one of those problems where I
  71. swear I've seen it before (and one way or another, it was solved)!
  72.  
  73. Feel free to post or e-mail your responses on this.  Thanks in advance for
  74. the help!
  75.  
  76. Gary
  77. --
  78. / Gary A. Hildebrand                 Internet: gah@mew.mei.co.jp       \
  79. /  Matsushita Electric Works, Ltd.   UUCP:     uunet!mew.mei.co.jp!gah \
  80. /   13-2, Mita 5-chome, Minato-ku    Fax:      03-3451-0793            \
  81. /    Tokyo 108, JAPAN                Tel:      03-3452-4941            \
  82.