public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PATCH: Automatically apply an address offset when linking between XGATE and M68HC1x cores.
@ 2012-07-15  3:29 Sean Keys
  2012-07-15 20:04 ` James Murray
  0 siblings, 1 reply; 5+ messages in thread
From: Sean Keys @ 2012-07-15  3:29 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 337 bytes --]

Hi,

Users of XGATE and M68HC1x Binutils have requested that the linker apply 
an appropriate offset for one another, when linking between the two 
cores.  This  offset is only applied when the address is within "shared 
RAM".  If the address falls outside this area, no offset is applied and 
a warning is emitted.

Thanks,
Sean Keys



[-- Attachment #2: changelog-m68hc1x-ld.txt --]
[-- Type: text/plain, Size: 260 bytes --]

bfd/elf32-m68hc1x.c
2012-07-10  Sean Keys  <skeys@ipdatasys.com>
        * elf32-m68hc1x.c (elf32_m68hc11_relocate_section): Added code that
	enables the linker to offset addresses, when linking against
        symbols from the XGATE processor and vice versa.

[-- Attachment #3: elf32-m68hc1x.c.diff --]
[-- Type: text/x-patch, Size: 4787 bytes --]

diff --git a/bfd/elf32-m68hc1x.c b/bfd/elf32-m68hc1x.c
index d862c9f..ae34184 100644
--- a/bfd/elf32-m68hc1x.c
+++ b/bfd/elf32-m68hc1x.c
@@ -948,6 +948,8 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
       bfd_vma insn_addr;
       bfd_vma insn_page;
       bfd_boolean is_far = FALSE;
+      bfd_boolean is_xgate_symbol = FALSE;
+      bfd_boolean is_section_symbol = FALSE;
       struct elf_link_hash_entry *h;
       bfd_vma val;
 
@@ -972,6 +974,8 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
 			+ sec->output_offset
 			+ sym->st_value);
 	  is_far = (sym && (sym->st_other & STO_M68HC12_FAR));
+	  is_xgate_symbol = (sym && (sym->st_target_internal));
+	  is_section_symbol =   ELF_ST_TYPE (sym->st_info) & STT_SECTION;
 	}
       else
 	{
@@ -983,6 +987,7 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
 				   warned);
 
 	  is_far = (h && (h->other & STO_M68HC12_FAR));
+	  is_xgate_symbol = (h && (h->target_internal));
 	}
 
       if (sec != NULL && discarded_section (sec))
@@ -1122,6 +1127,39 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
 
           insn_page = m68hc11_phys_page (pinfo, insn_addr);
 
+         /* If we are linking an S12 instruction against an XGATE symbol, we
+            need to change the offset of the symbol value so that it's correct from the
+            S12's perspective. */
+          if (is_xgate_symbol)
+          {
+            /* The ram in the global space is mapped to 0x2000 in the 16-bit
+               address space for S12 and 0xE000 in the 16-bit address space
+               for XGATE.  */
+            if (relocation >= 0xE000)
+              {
+                /* We offset the address by the difference
+                   between these two mappings.  */
+                relocation -= 0xC000;
+                break;
+              }
+            else
+              {
+                const char* msg;
+                char* buf;
+
+                msg = _("XGATE address (%lx) is not within shared RAM"
+                    "(0xE000-0xFFFF), therefore you must manually offset "
+                    "the address, and possibly manage the page, in your "
+                    "code.");
+                buf = alloca (strlen (msg) + 128);
+                sprintf (buf, msg, phys_addr);
+                if (!((*info->callbacks->warning) (info, buf, name, input_bfd,
+                    input_section, insn_addr)))
+                  return FALSE;
+                break;
+              }
+          }
+
           if (m68hc11_addr_is_banked (pinfo, relocation + rel->r_addend)
               && m68hc11_addr_is_banked (pinfo, insn_addr)
               && phys_page != insn_page)
@@ -1169,6 +1207,45 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
           break;
         }
 
+      /* If we are linking an XGATE instruction against an S12 symbol, we
+         need to change the offset of the symbol value so that it's correct from the
+         XGATE's perspective.  */
+      if (!strcmp (howto->name, "R_XGATE_IMM8_LO")
+          || !strcmp (howto->name, "R_XGATE_IMM8_HI"))
+        {
+          /* We can only offset S12 addresses that lie within the non-paged
+             area of RAM.  */
+          if (!is_xgate_symbol && !is_section_symbol)
+            {
+              /* The ram in the global space is mapped to 0x2000 and stops at
+                 0x4000 in the 16-bit address space for S12 and 0xE000 in the
+                 16-bit address space for XGATE.  */
+              if (relocation >= 0x2000 && relocation < 0x4000)
+                 /* We offset the address by the difference
+                   between these two mappings.  */
+                relocation += 0xC000;
+              else
+                {
+                  const char* msg;
+                  char* buf;
+
+                  /* Get virtual address of instruction having the relocation.  */
+                  insn_addr = input_section->output_section->vma
+                      + input_section->output_offset + rel->r_offset;
+
+                  msg = _("S12 address (%lx) is not within shared RAM"
+                      "(0x2000-0x4000), therefore you must manually "
+                      "offset the address in your code");
+                  buf = alloca (strlen (msg) + 128);
+                  sprintf (buf, msg, phys_addr);
+                  if (!((*info->callbacks->warning) (info, buf, name, input_bfd,
+                      input_section, insn_addr)))
+                    return FALSE;
+                  break;
+                }
+            }
+        }
+
       if (r_type != R_M68HC11_NONE)
         {
           if ((r_type == R_M68HC12_PCREL_9) || (r_type == R_M68HC12_PCREL_10))

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: Automatically apply an address offset when linking between XGATE and M68HC1x cores.
  2012-07-15  3:29 PATCH: Automatically apply an address offset when linking between XGATE and M68HC1x cores Sean Keys
@ 2012-07-15 20:04 ` James Murray
  2012-07-15 20:36   ` Sean Keys
  0 siblings, 1 reply; 5+ messages in thread
From: James Murray @ 2012-07-15 20:04 UTC (permalink / raw)
  To: binutils; +Cc: Sean Keys

On Sat, 2012-07-14 at 20:23 -0700, Sean Keys wrote:
> Hi,
> 
> Users of XGATE and M68HC1x Binutils have requested that the linker apply 
> an appropriate offset for one another, when linking between the two 
> cores.  This  offset is only applied when the address is within "shared 
> RAM".  If the address falls outside this area, no offset is applied and 
> a warning is emitted.

How does this compare, interact (or conflict?) with the existing
--xgate-ramoffset option?

(I won't have time to check the source for a few days.)

regards

James

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: Automatically apply an address offset when linking between XGATE and M68HC1x cores.
  2012-07-15 20:04 ` James Murray
@ 2012-07-15 20:36   ` Sean Keys
  2012-07-23 15:47     ` PING " Sean Keys
  0 siblings, 1 reply; 5+ messages in thread
From: Sean Keys @ 2012-07-15 20:36 UTC (permalink / raw)
  To: James Murray; +Cc: binutils

Hi James,

It's basically the same concept. Although, if I recall correctly your 
code only applies an offset, when linking M68HC1X symbols against XGATE 
relocations. XGATE code generated using the M68HC1x assembler won't be 
affected, including the "--xgate-ramoffset" option.  The test suite 
yields the same results with this patch applied.

Thanks,
Sean

It only applies when you use the XGATE tools.  The --xgate-ramoffset

On 07/15/2012 01:04 PM, James Murray wrote:
> On Sat, 2012-07-14 at 20:23 -0700, Sean Keys wrote:
>> Hi,
>>
>> Users of XGATE and M68HC1x Binutils have requested that the linker apply
>> an appropriate offset for one another, when linking between the two
>> cores.  This  offset is only applied when the address is within "shared
>> RAM".  If the address falls outside this area, no offset is applied and
>> a warning is emitted.
> How does this compare, interact (or conflict?) with the existing
> --xgate-ramoffset option?
>
> (I won't have time to check the source for a few days.)
>
> regards
>
> James


^ permalink raw reply	[flat|nested] 5+ messages in thread

* PING Re: PATCH: Automatically apply an address offset when linking between XGATE and M68HC1x cores.
  2012-07-15 20:36   ` Sean Keys
@ 2012-07-23 15:47     ` Sean Keys
  2012-07-24 13:24       ` nick clifton
  0 siblings, 1 reply; 5+ messages in thread
From: Sean Keys @ 2012-07-23 15:47 UTC (permalink / raw)
  To: binutils; +Cc: James Murray

Hi,

I know a release is around the corner, please consider this friendly ping.

James, it has been a few days and a few more :-)  Anything I can do to help?

Thanks,
Sean

On 07/15/2012 01:36 PM, Sean Keys wrote:
> Hi James,
>
> It's basically the same concept. Although, if I recall correctly your 
> code only applies an offset, when linking M68HC1X symbols against 
> XGATE relocations. XGATE code generated using the M68HC1x assembler 
> won't be affected, including the "--xgate-ramoffset" option.  The test 
> suite yields the same results with this patch applied.
>
> Thanks,
> Sean
>
> It only applies when you use the XGATE tools.  The --xgate-ramoffset
>
> On 07/15/2012 01:04 PM, James Murray wrote:
>> On Sat, 2012-07-14 at 20:23 -0700, Sean Keys wrote:
>>> Hi,
>>>
>>> Users of XGATE and M68HC1x Binutils have requested that the linker 
>>> apply
>>> an appropriate offset for one another, when linking between the two
>>> cores.  This  offset is only applied when the address is within "shared
>>> RAM".  If the address falls outside this area, no offset is applied and
>>> a warning is emitted.
>> How does this compare, interact (or conflict?) with the existing
>> --xgate-ramoffset option?
>>
>> (I won't have time to check the source for a few days.)
>>
>> regards
>>
>> James
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PING Re: PATCH: Automatically apply an address offset when linking between XGATE and M68HC1x cores.
  2012-07-23 15:47     ` PING " Sean Keys
@ 2012-07-24 13:24       ` nick clifton
  0 siblings, 0 replies; 5+ messages in thread
From: nick clifton @ 2012-07-24 13:24 UTC (permalink / raw)
  To: Sean Keys; +Cc: binutils, James Murray

Hi Sean,

   Sorry for the delay.

   Patch approved and applied.

Cheers
   Nick

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-07-24 13:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-15  3:29 PATCH: Automatically apply an address offset when linking between XGATE and M68HC1x cores Sean Keys
2012-07-15 20:04 ` James Murray
2012-07-15 20:36   ` Sean Keys
2012-07-23 15:47     ` PING " Sean Keys
2012-07-24 13:24       ` nick clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).