This is the mail archive of the binutils@sources.redhat.com 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: STUB_MOVE in elfxx-mips.c


Atsushi Nemoto wrote:
> I found following codes in bfd/elfxx-mips.c:
> 
> #define STUB_MOVE(abfd)                                         \
>   (SGI_COMPAT (abfd) ? 0x03e07825 : 0x03e07821)         /* move t7,ra */
> 
> 0x03e07825 is "OR $15,$31,$0" and 0x03e07821 is "ADDU $15,$31,$0".
> 
> Why SGI_COMPAT() is used here?

Probably because it mimics what the SGI toolchain for N64 did.
AFAICS it should be API_64_P instead, and it's better to use
'daddu' instead of 'or', as this helps CPUs with several adders.

> The ADDU can not be used to copy 64bit register because the result is
> sign-extended value of the low 32bit of the source register.  So OR
> must be used for 64bit ABI, right?  Or using OR unconditionally is
> enough, isn't it?  Or am I missing something?

I'm surprised it doesn't crash spectacularily. The whole stup definitions
should IMHO read as:


diff -burpNX /bigdisk/src/gcc-exclude source-orig/bfd/elfxx-mips.c source/bfd/elfxx-mips.c
--- source-orig/bfd/elfxx-mips.c        Wed Oct  1 02:15:44 2003
+++ source/bfd/elfxx-mips.c     Wed Oct  1 16:35:02 2003
@@ -587,17 +588,20 @@ static bfd *reldyn_sorting_bfd;
    offsets from $gp.  */
 #define MIPS_ELF_GOT_MAX_SIZE(abfd) (ELF_MIPS_GP_OFFSET(abfd) + 0x7fff)

-/* Instructions which appear in a stub.  For some reason the stub is
-   slightly different on an SGI system.  */
+/* Instructions which appear in a stub.  */
 #define STUB_LW(abfd)                                          \
   ((ABI_64_P (abfd)                                            \
     ? 0xdf998010               /* ld t9,0x8010(gp) */          \
     : 0x8f998010))              /* lw t9,0x8010(gp) */
 #define STUB_MOVE(abfd)                                         \
-  (SGI_COMPAT (abfd) ? 0x03e07825 : 0x03e07821)         /* move t7,ra */
-#define STUB_JALR 0x0320f809                           /* jal t9 */
+   ((ABI_64_P (abfd)                                           \
+     ? 0x03e0782d              /* daddu t7,ra */               \
+     : 0x03e07821))            /* addu t7,ra */
+#define STUB_JALR 0x0320f809   /* jalr t9,ra */
 #define STUB_LI16(abfd)                                         \
-  (SGI_COMPAT (abfd) ? 0x34180000 : 0x24180000)         /* ori t8,zero,0 */
+  ((ABI_64_P (abfd)                                            \
+   ? 0x64180000                        /* daddiu t8,zero,0 */          \
+   : 0x24180000))              /* addiu t8,zero,0 */
 #define MIPS_FUNCTION_STUB_SIZE (16)

 /* The name of the dynamic interpreter.  This is put in the .interp


Beware, this patch is untested.


Thiemo


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