Subject: PC-relative refs in assembly code
To: None <port-m68k@sun-lamp.cs.berkeley.edu>
From: Paul Mackerras <Paul.Mackerras@cs.anu.edu.au>
List: port-m68k
Date: 11/30/1993 13:20:41
I notice that locore.s in each of the m68k ports has some statements
like
	pea	pc@((argv-.)+2)
or
	lea	pc@((zero-.)+2),a0

It seems to me that, while this might have assembled to correct code
with some assembler(s), it's not correct.  The symbol . should mean
the address of the current instruction, and the offset in the instruction
should be (argv - (.+2)), since the offset is relative to the address
of the first extension word of the instruction, i.e. the instruction
address + 2.

I notice also that the hp300 port has changed this to

	pea	pc@(argv-.)

This sorta works with the gas which comes with NetBSD (gas-1.92.3),
because of a bug which basically makes gas ignore the "-.".  The
pc@((argv-.)+2) construct gives an offset which is too large by 2;
I found this out the hard way when I changed over to gas-1.92.3, and
my kernels would no longer run init, because this construct appears
in the icode.  Sun-3 as seems to give an offset which is too large
by 4 for pc@((argv-.)+2), and the correct offset for pc@((argv-.)-2).

The best thing to do is to change all these references to the form
pc@(argv).  All the assemblers I know of will correctly assemble this
as a PC-relative reference to argv.



------------------------------------------------------------------------------