[comp.sys.amiga] help on ON_DISPLAY OFF_DISPLAY

FATXC@USU.BITNET (01/30/88)

        I am trying to use the macros ON_DISPLAY and OFF_DISPLAY as
described by the ROM kernel manual.  Following the example program
using the CWAIT and other copper macros, I included the appropriate
files, and made the following declaration:
  extern struct Custom custom;
as instructed.  Well, the file compiles ok, but the linker can't resolve
the extern custom structure.  Can someone tell me where this thing is
declared properly?  Or do I need to declare it myself, and in either case,
where is this thing suppose to be pointing?  (I am guessing that it is
a structure with information for the custom chips... am I way off?)
  I can't seem to resolve this, so I would greatly appreciate any input
from someone who has seen this before, or can see what I am doing wrong.

   Thanks for your time,

                          J. Norman Gee
 ________________________________________________________________________
|                                     |                                  |
|  No one pays attention to what I    |  Email:  fatxc@usu.bitnet        |
|  say, so why bother disclaiming     |  USNail: usu trailer ct # 30     |
|  anything?                          |          Logan Ut.  84321        |
|_____________________________________|__________________________________|

toebes@sas.UUCP (John Toebes) (01/31/88)

In article <8801292118.AA05372@jade.berkeley.edu>, FATXC@USU.BITNET writes:
>         I am trying to use the macros ON_DISPLAY and OFF_DISPLAY as
> described by the ROM kernel manual. I included the appropriate
> files, and made the following declaration:
>   extern struct Custom custom;
> as instructed.  Well, the file compiles ok, but the linker can't resolve
> the extern custom structure.
>                           J. Norman Gee
Under the assumption that you are using Lattice 4.0, you are running into the
default for the compiler now being -B1 (to use the more efficient form of
Base relative addressing).  This was present in the 3.10 compiler (-B option)
and could also show up there (I can't speak for Manx).  What is happening is
that the compiler is using a 16 bit offset from a base register (A4) to
access the data:
           lea custom(A4),A0
The linker sees this in the form of a 16 bit relocation for the offset.
However, since the value for custon is out of the range for a 16-bit value,
the linker must give up and issue an error message.  Under the -B0 scheme
this comes across as:
           lea custom,A0
With a 32 bit relocation value that the linker can fill in.  However this
results in a penalty at runtime and in disk space usage:  The 16 bit method
takes 4 bytes and is relocated at link time, the 32 bit method uses 6 bytes
plus at least 4 more (as many as 12) bytes of relocation overhead taking up
between 6 and 14 more bytes of disk space for each reference.

So this should imply that you can't get both features at once: small/fast code
AND ability to address the chips.  The simple solution of compiling everything
with the -B0 switch takes away the advantage of the speed/size.  What I
generally do is to use the preprocessor to make life a little easier and do
the following:
        extern struct custom custom;
        static struct custom *customp = &custom;
        #define custom (*customp)
In this way, all references to custom are through a data item (in the data
section) that is relocated by a 32 bit relocation.  I still get the code
advantage of the 16 bit offsets.  Note that this trick also works for anything
that might be put into chip ram also.

Oposing opinions are always welcome, this is what I use in PopCLI... :->

/*---------------------All standard Disclaimers apply---------------------*/
/*----Working for but not officially representing SAS or Lattice Inc.-----*/
/*----John A. Toebes, VIII             usenet:...!mcnc!rti!sas!toebes-----*/
/*------------------------------------------------------------------------*/