[comp.sys.amiga] Problem with -b vs -b0 option on Lattice

erd@tut.cis.ohio-state.edu (Ethan R. Dicks) (12/14/88)

In my OnePlane program, I have to compile it with the -b0 option, to turn
off base A4 referencing, because it GURU's with a 0000003.addr if I just
run it, and a 0000004.addr if I examine it with the MetaScope debugger.

The line it chokes on is...

struct ExecBase *ExecBase, **EBase;

EBase = (struct ExecBase **) (4L);
ExecBase = *Ebase;

If I compile the code with the -b0 option, the code works perfectly, and
I get the contents of the address 0x0000004 loaded into A6.  If I compile
the code with the -b option, I never get up to the library open, immediately
following this code.

Under assembly, as I recall the proceedure is to simply do a

	LEA	$4, A0
	MOVE	(A0), A6

However, in C, this is not so easy.  The reason for this convolution is that
my program links with *nothing*; no startup code, no libraries.  I need to
generate the ExecBase pointer entirely in my own routine.  The reason I am
wanting to use the -b option (the default) is that the code size changes from
440 to 300.  I want to take advantage of this 30% reduction in executable
size.

So... enough background ...

What is the best way to aquire the ExecBase pointer manually?  I got my
technique from the WhatCPU program by Dave Haynie.

Why would base relative addressing cause code to begin GURUing with odd
offsets?

Thanks,
-ethan
-- 
Ethan R. Dicks       | ######  This signifies that the poster is a member in
Software Results Corp|   ##    good sitting of Inertia House: Bodies at rest.
2887 Silver Drive    |   ##
Columbus OH    43211 | ######  "You get it, you're closer.

scott@applix.UUCP (Scott Evernden) (12/16/88)

In article <29526@tut.cis.ohio-state.edu> erd@tut.cis.ohio-state.edu (Ethan R. Dicks) writes:

>struct ExecBase *ExecBase, **EBase;
>
>EBase = (struct ExecBase **) (4L);
>ExecBase = *Ebase;
 
        vs.
 
>       LEA     $4, A0
>       MOVE    (A0), A6
 
These don't say the same thing.   Your C code suggests that location 4
holds the address of a _pointer_ to ExecBase.  This isn't so- location 4 
_is_ a pointer to ExecBase.
 
Try:
 
        struct ExecBase *ExecBase = (struct ExecBase *) 4;
 
-scott

w-colinp@microsoft.UUCP (Colin Plumb) (12/17/88)

In article <882@applix.UUCP> scott@applix.UUCP (Scott Evernden) writes:
|In article <29526@tut.cis.ohio-state.edu> erd@tut.cis.ohio-state.edu (Ethan R. Dicks) writes:
|>struct ExecBase *ExecBase, **EBase;
|>
|>EBase = (struct ExecBase **) (4L);
|>ExecBase = *Ebase;
| 
|        vs.
| 
|>       LEA     $4, A0
|>       MOVE    (A0), A6
| 
|These don't say the same thing.   Your C code suggests that location 4
|holds the address of a _pointer_ to ExecBase.  This isn't so- location 4 
|_is_ a pointer to ExecBase.
| 
|Try:
| 
|        struct ExecBase *ExecBase = (struct ExecBase *) 4;

Wrong!  The *contents* of location 4 are a pointer to ExecBase, but
"4", the number, is a pointer to a pointer to ExecBase.  The original
code is right.  Yours says the ExecBase structure starts at address 4,
which is not correct.
-- 
	-Colin (uunet!microsof!w-colinp)

scott@applix.UUCP (Scott Evernden) (12/20/88)

In article <96@microsoft.UUCP> w-colinp@microsoft.UUCP (Colin Plumb) writes:
>In article <882@applix.UUCP> scott@applix.UUCP (Scott Evernden) writes:
>|>
>|>EBase = (struct ExecBase **) (4L);
>|>ExecBase = *Ebase;
>|        vs.
>|>       LEA     $4, A0
>|>       MOVE    (A0), A6
>|Try:
>|        struct ExecBase *ExecBase = (struct ExecBase *) 4;
>
>Wrong!  The *contents* of location 4 are a pointer to ExecBase, but
>"4", the number, is a pointer to a pointer to ExecBase.  The original
>code is right.  Yours says the ExecBase structure starts at address 4,
>which is not correct.

Of course you are correct.

I think I meant something more like:

	struct ExecBase *ExecBase = * (struct ExecBase **) 4;

but couldn't manage to spit it out on a Friday night.  This is exactly
equivalent to what Ethan had originally, so...


never mind...

-scott