Hi All,
I've been $LINKing object files into my PB/DOS programs for about eight years now,
and up till now I've assumed that the code in the object file always starts at an
offset of 1 in the compiled program. This week I found the first case where that
isn't true, and I wonder if anyone here can instruct me in how the compiler decides
where to put the $LINKed code, and whether I can control it or not. If the answer
is that I can't control or count on the compiler to put it where I want, then no big
deal; it's just that after so many years and programs made with the assumption that
I knew where the code was going to land, that I'm startled to see it landing somewhere
else. And since programming in PB/DOS is my bread-and-butter, anything I can learn
about how it works is a plus.
To illustrate, when I throw some debugging code in after the $LINK statements, like so:
--------------------------------------------------------------
$LINK "Prottest.obj" 'unreal processor mode initiator
$LINK "MemUtil.obj"
$LINK "MiscUtil.obj"
$LINK "vac_he12.OBJ" 'head electronics uart polling routine
$LINK "COM1Hand.obj" ' com ports interrupt handler
$LINK "COM2Hand.obj" ' com ports interrupt handler
'-- Look at the start of each of these linked in object files
'-- Protect is the first procedure in Prottest.obj
PRINT "Protect="+STR$(CODESEG(PROTECT))+" "+STR$(CODEPTR(PROTECT))
'-- Memcopy is the first procedure in MemUtil.obj
PRINT "Memcopy="+STR$(CODESEG(MEMCopy))+" "+STR$(CODEPTR(MEMCopy))
'-- Leave out XMSCall; it isn't used in this program and so trying to get its
'-- address results in an error
'PRINT "XMSCall="+STR$(CODESEG(XMSCall))+" "+STR$(CODEPTR(XMSCall))
'-- PollHEUarts is the first procedure in vac_he12.obj
PRINT "PollHEUarts="+STR$(CODESEG(PollHEUarts))+" "+STR$(CODEPTR(PollHEUarts))
'-- Com1Handler is the first procedure in COM1Hand.obj
PRINT "Com1Handler="+STR$(CODESEG(Com1Handler))+" "+STR$(CODEPTR(Com1Handler))
'-- Com2Handler is the first procedure in COM2Hand.obj
PRINT "Com2Handler="+STR$(CODESEG(Com2Handler))+" "+STR$(CODEPTR(Com2Handler))
END
-----------------------------------------------------
... I get the following:
22552 1
22562 1
22613 1
22707 1
22707 294
The first four $LINKed files are found at offsets of 1, as I expected, but now,
and for the first time I've ever seen, the last $LINKed file is being put in the
same segment as it's predecessor.
(I've zipped up the full set of source code files and made them available at:
ftp.astronomy.ohio-state.edu/pub/isl/vacuum.zip)
By the way, the reason I need to know where the code is going is that the last three
$LINKed files are interrupt handlers, and I can't set the interrupt vectors, or pass
data structures to them, without knowing where they are.
Cheers, and any help appreciated,
Jerry
------------------
[This message has been edited by Jerry Mason (edited April 21, 2005).]
I've been $LINKing object files into my PB/DOS programs for about eight years now,
and up till now I've assumed that the code in the object file always starts at an
offset of 1 in the compiled program. This week I found the first case where that
isn't true, and I wonder if anyone here can instruct me in how the compiler decides
where to put the $LINKed code, and whether I can control it or not. If the answer
is that I can't control or count on the compiler to put it where I want, then no big
deal; it's just that after so many years and programs made with the assumption that
I knew where the code was going to land, that I'm startled to see it landing somewhere
else. And since programming in PB/DOS is my bread-and-butter, anything I can learn
about how it works is a plus.
To illustrate, when I throw some debugging code in after the $LINK statements, like so:
--------------------------------------------------------------
$LINK "Prottest.obj" 'unreal processor mode initiator
$LINK "MemUtil.obj"
$LINK "MiscUtil.obj"
$LINK "vac_he12.OBJ" 'head electronics uart polling routine
$LINK "COM1Hand.obj" ' com ports interrupt handler
$LINK "COM2Hand.obj" ' com ports interrupt handler
'-- Look at the start of each of these linked in object files
'-- Protect is the first procedure in Prottest.obj
PRINT "Protect="+STR$(CODESEG(PROTECT))+" "+STR$(CODEPTR(PROTECT))
'-- Memcopy is the first procedure in MemUtil.obj
PRINT "Memcopy="+STR$(CODESEG(MEMCopy))+" "+STR$(CODEPTR(MEMCopy))
'-- Leave out XMSCall; it isn't used in this program and so trying to get its
'-- address results in an error
'PRINT "XMSCall="+STR$(CODESEG(XMSCall))+" "+STR$(CODEPTR(XMSCall))
'-- PollHEUarts is the first procedure in vac_he12.obj
PRINT "PollHEUarts="+STR$(CODESEG(PollHEUarts))+" "+STR$(CODEPTR(PollHEUarts))
'-- Com1Handler is the first procedure in COM1Hand.obj
PRINT "Com1Handler="+STR$(CODESEG(Com1Handler))+" "+STR$(CODEPTR(Com1Handler))
'-- Com2Handler is the first procedure in COM2Hand.obj
PRINT "Com2Handler="+STR$(CODESEG(Com2Handler))+" "+STR$(CODEPTR(Com2Handler))
END
-----------------------------------------------------
... I get the following:
22552 1
22562 1
22613 1
22707 1
22707 294
The first four $LINKed files are found at offsets of 1, as I expected, but now,
and for the first time I've ever seen, the last $LINKed file is being put in the
same segment as it's predecessor.
(I've zipped up the full set of source code files and made them available at:
ftp.astronomy.ohio-state.edu/pub/isl/vacuum.zip)
By the way, the reason I need to know where the code is going is that the last three
$LINKed files are interrupt handlers, and I can't set the interrupt vectors, or pass
data structures to them, without knowing where they are.
Cheers, and any help appreciated,
Jerry
------------------
[This message has been edited by Jerry Mason (edited April 21, 2005).]
Comment