This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: m68hc11 %hi relocate problem with carry

Hi James,

Have a look at my latest XGATE patch. Actually it worked fine in the previous patch too but you would have to look at more than the opcode table file to notice that :). It's a simple port to follow and it appears to work as it should.

Test case:
.globl _start
.sect .text
    ldw     r1, linksymbol
    ldw     r2, linksymbol+4

xgate-as xgate.s -defsym linksymbol=0x20fe -o xgate.o

xgate-objdump xgate.o -d

Disassembly of section .text:

00000000 <_start>:
   0:    f1 fe           ldl R1, #0xfe
   2:    f9 20           ldh R1, #0x20 Abs* 0x20fe <linksymbol>
   4:    f2 02           ldl R2, #0x02
   6:    fa 21           ldh R2, #0x21 Abs* 0x2102 <linksymbol+0x4>
   8:    02 00           rts
   a:    01 00           nop


On 03/02/2012 12:25 PM, James Murray wrote:
I've found what appears to be a bug (or at least a limitation) when
using a %hi assembler directive in m68hc11. This is supposed to return
the high byte of the resolved symbol, but if the low byte overflows, the
carry is missed.

Could someone point me at some example code in other targets that I
could study in order to fix m68hc11 ?

Test case:
.globl _start
.sect .text

     ldx     #linksymbol
     ldy     #linksymbol+4

     ldaa   #%hi (linksymbol+4)
     ldab   #%lo (linksymbol+4)
     tfr     d,y


build commands
m68hc11-elf-as -m68hc12 -o t3.o s12test.s
m68hc11-elf-ld -mm68hc12elfb -o t3 -defsym linksymbol=0x20fe t3.o
m68hc11-elf-objdump -mm68hc12 -d t3

---------------- before linking ---------------- t3.o: file format elf32-m68hc12

Disassembly of section .text:

    0:	ce 00 00    	ldx	#0x0<_start>
			1: R_M68HC12_16	linksymbol
    3:	cd 00 04    	ldy	#0x4<_start+0x4>
			4: R_M68HC12_16	linksymbol
    6:	86 00       	ldaa	#0x0
			7: R_M68HC12_HI8	linksymbol
    8:	c6 04       	ldab	#0x4
			9: R_M68HC12_LO8	linksymbol
    a:	b7 46       	tfr	D,Y
    c:	3d          	rts

after linking
Disassembly of section .text:

     c000:	ce 20 fe    	ldx	#0x20fe<linksymbol>
     c003:	cd 21 02    	ldy	#0x2102<linksymbol+0x4>
     c006:	86 20       	ldaa	#0x20
     c008:	c6 02       	ldab	#0x2
     c00a:	b7 46       	tfr	D,Y
     c00c:	3d          	rts

Code at c006 is incorrect - should be ldaa #0x21 but the carry is

Part of the code in tc-m68hc11.c within md_apply_fix :
     case BFD_RELOC_M68HC11_HI8:
       value = value>>  8;
       /* Fall through.  */

     case BFD_RELOC_M68HC11_LO8:
     case BFD_RELOC_8:
     case BFD_RELOC_M68HC11_PAGE:
       ((bfd_byte *) where)[0] = (bfd_byte) value;


Suggestions welcome.


James Murray

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]