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:
----------------
s12test.s
----------------
.globl _start
.sect .text
_start:
ldx #linksymbol
ldy #linksymbol+4
ldaa #%hi (linksymbol+4)
ldab #%lo (linksymbol+4)
tfr d,y
rts
----------------
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:
00000000<_start>:
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:
0000c000<_start>:
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
missing.
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;
break;
----------------
Suggestions welcome.
regards
James Murray