🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #7651

Is there any way to force MASM 5.1 to generate NEAR jumps?

#7651
From: Gary A. Hildebrand
Date: Thu, 21 Jan 1993 23:25
70 lines
2775 bytes
All,

Consider the following macro and code, which are the early stages of an
exception handler plus entry points for a virtual 8086 monitor:

;
; Macro acts as entry point to handler from IDT entry n
;
idt_vec		macro	n
		push	ax		; save a register
		mov	al,n		; load vector index
		jmp	near ptr mhandler	; chain to master handler
		endm

		.CODE

mhandler:
		pop	ax
		iretd

idt_vec0:
		idt_vec	0
idt_vec1:
x = 1
		rept	255
		idt_vec	x
x = x + 1
		endm

Here is the code which will place the offsets of the entry points in an IDT:

;
; load offsets for gate descriptors in IDT
;
		mov	ax,offset idt_vec0
		mov	di,offset idt
		mov	cx,256
		cld
next_idt_vec:
		stosw
		add	di,6
		add	ax,idt_vec1 - idt_vec0
		loop	next_idt_vec

What's wrong, you ask?  Even though the `mhandler:` label is not forward
referenced by the expanded `idt_vec` macro, and the jump to `mhandler:` has
been typed as a near one, MASM 5.1 tries to optimize the jumps
nevertheless.  The first 20 or so entry points will use short jumps instead
of near ones.  Normally this would be acceptable, but the IDT loader code
depends on the code size for each entry point being the *same*, since it
just uses the size of the first entry point.

Is there any trick to make MASM 5.1 not optimize these jumps?  It seems
kind of silly to place the `mhandler` and `idt_vec` sections in completely
different parts of the code segment, or stick a bunch of NOP's after the
IRETD.  Of course, it's very likely that the real `mhandler` section will
be large enough to prevent this problem from occurring, but there should be
a way to control what MASM is doing.  I haven't tried giving this to TASM,
to see what it would do.  Once again, this is one of those problems where I
swear I've seen it before (and one way or another, it was solved)!

Feel free to post or e-mail your responses on this.  Thanks in advance for
the help!

Gary
--
/ Gary A. Hildebrand                 Internet: gah@mew.mei.co.jp       \
/  Matsushita Electric Works, Ltd.   UUCP:     uunet!mew.mei.co.jp!gah \
/   13-2, Mita 5-chome, Minato-ku    Fax:      03-3451-0793            \
/    Tokyo 108, JAPAN                Tel:      03-3452-4941            \
Technical Details
Message-ID: <GAH.93Jan22082547@trcrik.trc.mew.mei.co.jp>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!sgiblab!adagio.panasonic.com!chorus.mei!saturn.mew!srl!gah

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!sgiblab!adagio.panasonic.com!chorus.mei!saturn.mew!srl!gah
From: gah@trc.mew.mei.co.jp (Gary A. Hildebrand)
Subject: Is there any way to force MASM 5.1 to generate NEAR jumps?
Message-ID: <GAH.93Jan22082547@trcrik.trc.mew.mei.co.jp>
Sender: news@srl.mew.mei.co.jp
Nntp-Posting-Host: akihabara.trc.mew.mei.co.jp
Organization: Matsushita Electric Works Ltd., Tokyo, Japan.
Date: Thu, 21 Jan 1993 23:25:47 GMT
Lines: 70