[comp.sys.mac.programmer] Problems with XCMDs in MPW Object Pascal 3.0

am151fap@sdcc3.ucsd.EDU (Eric Krugler) (03/05/89)

I'm trying to create an XCMD using MPW Pascal 3.0. The problem is that if
I use the Object extensions provided by MPW Pascal the linker runs into
problems. The -rt link option is used to create the XCMD resource
and it causes A5 addressing modes to be converted to PC relative
addressing modes, but only for JSR, JMP, LEA, or PEA instructions.
The error that the linker produces (#41) states that a different
instruction specifying A5 relative addressing has been found.

The real question is can an XCMD, DRVR, or DA be created using the
Object extensions of MPW Pascal and if so, how do I work around the
problem with the linker.

Any comments would be greatly appreciated.

Eric Krugler, am151fap@sdcc3.UCSD.edu

NOTE: I am NOT using the MacApp libraries and I need a quick
response since this is being used as an assignment for a class.

keith@Apple.COM (Keith Rollin) (03/08/89)

In article <4321@sdcc3.ucsd.EDU> am151fap@sdcc3.ucsd.EDU (Eric Krugler) writes:
>
>I'm trying to create an XCMD using MPW Pascal 3.0. The problem is that if
>I use the Object extensions provided by MPW Pascal the linker runs into
>problems. The -rt link option is used to create the XCMD resource
>and it causes A5 addressing modes to be converted to PC relative
>addressing modes, but only for JSR, JMP, LEA, or PEA instructions.
>The error that the linker produces (#41) states that a different
>instruction specifying A5 relative addressing has been found.
>
>The real question is can an XCMD, DRVR, or DA be created using the
>Object extensions of MPW Pascal and if so, how do I work around the
>problem with the linker.
>
I don't think that you will ever be able to get this to work. I've only 
looked into the inner workings of method dispatching briefly, and they seem to 
depend on several things:

1) a jump table (and No, you can't use HyperCard's).
2) selection procedures (SelProcs) in a separate segment
3) method tables (MethTables) in a separate segment.

All three of these violate the conditions for standalone code resources, which
is what an XCMD is. However, I may be wrong on some of these points. For
instance, I wasn't aware that the -rt option caused the A5 relative addressing
to become PC relative. But I still don't think that it will also change the
method dispatching architecture.


------------------------------------------------------------------------------
Keith Rollin  ---  Apple Computer, Inc.  ---  Developer Technical Support
INTERNET: keith@apple.com
    UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith
"Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions

lsr@Apple.COM (Larry Rosenstein) (03/09/89)

In article <26942@apple.Apple.COM> keith@Apple.COM (Keith Rollin) writes:
> instance, I wasn't aware that the -rt option caused the A5 relative 
addressing
> to become PC relative. But I still don't think that it will also change 
the

I don't think it does.  The linker routinely changes A5-relative 
addressing to PC relative addressing if the instruction and the effective 
address end up in the same segment (and if the reference doesn't require 
A5-relative addressing).  

I don't think -rt affects this, except that when you use this option you 
generally are making one segment, so everything is changed to PC-relative 
addressing.  In MPW Pascal, one can turn on a compiler flag to require 
A5-relative addressing; if you did this and tried to link with -rt, you 
would get a linker error.

Larry Rosenstein, Apple Computer, Inc.

Internet: lsr@Apple.com   UUCP: {nsc, sun}!apple!lsr
AppleLink: Rosenstein1

Greg_Mark_Finnegan@cup.portal.com (03/10/89)

I have one related question (and onother somewhat unrelated):

Is it possible to create a multisegment XCMD? Let's say for example I want
to somehow shoehorn a small spreadsheet (about 90K) into an XCMD. Can I
do it (easily)?

Here's a question for the MPW compiler hacks out there: What is the most
efficient base index of arrays in MPW 3.0 Pascal 0 or 1?

Thanks in advance.

Greg.

keith@Apple.COM (Keith Rollin) (03/12/89)

In article <15634@cup.portal.com> Greg_Mark_Finnegan@cup.portal.com writes:
>
>I have one related question (and onother somewhat unrelated):
>
>Is it possible to create a multisegment XCMD? Let's say for example I want
>to somehow shoehorn a small spreadsheet (about 90K) into an XCMD. Can I
>do it (easily)?

Well, I suppose that it could be done. There are two ways that you could do
it, but neither qualify as being easy:

	1) create a multisegmented XCMD
	2) create a 90K XCMD

MPW will allow you to compile and link a code segment that is 90K in size.
However, there is major limitation when doing so: all intra segment calls
must involve a distance no greater than 32K. This comment only applies to
Pascal and C programmers. I am not an assembly language programmer so I don't
know if there is a PC relative addressing mode that allows 32-bit offsets
when calling subroutines. If there is, then you could write your XCMD in
assembly with no problems.

Creating a multisegmented XCMD is also nasty. You would have to handle the
loading of the other segments by yourself. This would amount to writing
several XCMDs, with the main one loading in and calling the others as needed.
This could be done with small subroutines.

I've heard that the LightSpeed development systems allow one to easily
create multisegmented DA's. I don't know how this is done, but perhaps their
techniques would apply to your problem.

If I were in your situation, I would re-examine what I was trying to do. If
I had 90K of code that I wanted to execute, I'd write an application, not
and XCMD that runs under HyperCard.


>Here's a question for the MPW compiler hacks out there: What is the most
>efficient base index of arrays in MPW 3.0 Pascal 0 or 1?

I just looked at the output of the following program. Neither array base
seemed offer any advantage over the other. However, I seem to recal an
instance where a zero-based array was better, but I can't remember what the
circumstances were:

VAR
        t1: array [0..10] of integer;
        t2: array [1..10] of integer;
        i: integer;
        
begin
        t1[0] := 1;
        t1[1] := 2;
        t2[1] := 3;
        t2[2] := 4;
        
        i := 0;
        t1[i] := 5;
        
        i := 1;
        t1[i] := 6;
        t2[i] := 7;
end.

>Thanks in advance.
>
>Greg.


------------------------------------------------------------------------------
Keith Rollin  ---  Apple Computer, Inc.  ---  Developer Technical Support
INTERNET: keith@apple.com
    UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith
"Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions

svc@well.UUCP (Leonard Rosenthol) (03/13/89)

In article <15634@cup.portal.com>, Greg_Mark_Finnegan@cup.portal.com writes:
> 
> I have one related question (and onother somewhat unrelated):
> 
> Is it possible to create a multisegment XCMD? Let's say for example I want
> to somehow shoehorn a small spreadsheet (about 90K) into an XCMD. Can I
> do it (easily)?
> 
	You can create a multisegment XCMD BUT _YOU_ will have to do the 
segmentation yourself - the compiler WILL NOT do it for you!  I do this with
DA's all the time to break the 32K limit on DRVR's and with a bit of ASM glue
it is pretty trivial.

-- 
+--------------------------------------------------+
Leonard Rosenthol        |  GEnie : MACgician
Lazerware, inc.          |  MacNet: MACgician
UUCP: svc@well.UUCP      |  ALink : D0025

keith@Apple.COM (Keith Rollin) (03/13/89)

In article <27155@apple.Apple.COM> I write:
>In article <15634@cup.portal.com> Greg_Mark_Finnegan@cup.portal.com writes:
>
>>Here's a question for the MPW compiler hacks out there: What is the most
>>efficient base index of arrays in MPW 3.0 Pascal 0 or 1?
>
>I just looked at the output of the following program. Neither array base
>seemed offer any advantage over the other. However, I seem to recal an
>instance where a zero-based array was better, but I can't remember what the
>circumstances were:
>

I just got this note from Landon Dyer, one of the MPW engineers:

-----

Keith,

I didn't post this -- you may if you like....

Given
	zero: ARRAY[0..42] OF INTEGER;
	one: ARRAY[1..42] OF INTEGER;
	i: INTEGER;

	...

	zero[i] := 6;
	one[i] := 7;

With range checking turned off, the code for both array references is
essentially the same.  With range checking turned on (which, by the
way, is the default) the compiler generates an extra SUBQ and makes
use of an extra temp register.

You'd have to be in dire straits indeed for this to matter much...

--
Landon Dyer, Apple Computer, Inc.		"Why use a REAL development
Development Systems Group (MPW)			 system when you can bang
I speak for me.					 a rock against your head?"


------------------------------------------------------------------------------
Keith Rollin  ---  Apple Computer, Inc.  ---  Developer Technical Support
INTERNET: keith@apple.com
    UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith
"Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions

duggie@Jessica.stanford.edu (Doug Felt) (03/14/89)

In article <27155@apple.Apple.COM> keith@Apple.COM (Keith Rollin) writes:
>In article <15634@cup.portal.com> Greg_Mark_Finnegan@cup.portal.com writes:
>>
>>I have one related question (and onother somewhat unrelated):
>>
>>Is it possible to create a multisegment XCMD? Let's say for example I want
>>to somehow shoehorn a small spreadsheet (about 90K) into an XCMD. Can I
>>do it (easily)?
>
>Well, I suppose that it could be done. There are two ways that you could do
>it, but neither qualify as being easy:
>
>	1) create a multisegmented XCMD
>	2) create a 90K XCMD

A third alternative is to write a driver, and then communicate to the
driver with one or several XCMDs.  This has the advantages that you
can maintain state across calls, and use Lightspeed's ability to
create multi-segment drivers that Keith mentioned.  (I use LSC, so
don't know if LSP will do the same things for you, but perhaps it
will).  A spreadsheet could also use the driver idle time to do *very*
small pieces of a recalculation while letting Hypercard run, which
would be difficult to do in a straight XCMD.

>>Thanks in advance.
>>
>>Greg.
>
>Keith Rollin  ---  Apple Computer, Inc.  ---  Developer Technical Support

Doug Felt
Courseware Authoring Tools Project
Stanford University
duggie@jessica.stanford.edu

ech@pegasus.ATT.COM (Edward C Horvath) (03/14/89)

From article <15634@cup.portal.com>, by Greg_Mark_Finnegan@cup.portal.com:
 
> I have one related question (and onother somewhat unrelated):
 
> Is it possible to create a multisegment XCMD? Let's say for example I want
> to somehow shoehorn a small spreadsheet (about 90K) into an XCMD. Can I
> do it (easily)?
 
Do it, yes; easily depends on how bad you want it.

Aztec C supports the creation of arbitrary-sized code resources; the only
limitation is that static data + jump table is limited to 64K.  It works.
(I know, I modified the Aztec linker to do this when I worked for Manx).

And thanks for the kind words from Earle Horton and others on the Aztec
product.  I no longer work for Manx, but it's still nice to hear your
"children" are well-thought-of.  No, I didn't do the docs, perhaps I should
have paid more attention to them...

=Ned Horvath=