Sfoglia il codice sorgente

Add elf resource support for mips/mipsel CPU

git-svn-id: trunk@22603 -
pierre 13 anni fa
parent
commit
5a3078495b

+ 6 - 1
packages/fcl-res/src/elfconsts.pp

@@ -21,7 +21,8 @@ interface
 
 type
   TElfMachineType = (emtnone, emtsparc, emti386, emtm68k, emtppc, emtppc64,
-                     emtarm, emtarmeb, emtia64, emtx86_64, emtalpha);
+                     emtarm, emtarmeb, emtia64, emtx86_64, emtalpha,
+                     emtmips, emtmipsel);
 const
   ELFMAGIC     = chr($7f)+'ELF';
 
@@ -61,11 +62,14 @@ const
   EM_SPARC       =  2;
   EM_386         =  3;
   EM_68K         =  4;
+  EM_MIPS        =  8; // GNU readelf returns machine name: "MIPS R3000"
+  EM_MIPS_RS3_LE = 10; // GNU readelf returns machine name: "MIPS R4000 big endian"!
   EM_PPC         = 20;
   EM_PPC64       = 21;
   EM_ARM         = 40;
 //  EM_OLD_ALPHA       = 41;
   EM_IA_64       = 50;
+  EM_MIPS_X      = 51; // GNU readelf returns machine name "Stanford MIPS-X"
   EM_X86_64      = 62;
   EM_ALPHA       = $9026; //unofficial, but used by gnu toolchain
   
@@ -130,6 +134,7 @@ const
   R_SPARC_32      =   3;
   R_ALPHA_REFQUAD =   2;
   R_IA64_DIR64LSB = $27;
+  R_MIPS_32       =   2;
 
 
   //fpc resource constants

+ 7 - 0
packages/fcl-res/src/elfdefaulttarget.inc

@@ -45,6 +45,13 @@
   {$IFDEF CPUIA64}
   fMachineType:=emtia64;
   {$ENDIF}
+  {$IFDEF CPUMIPS}
+    {$IFDEF ENDIAN_LITTLE}
+    fMachineType:=emtmipsel;
+    {$ELSE}
+    fMachineType:=emtmips;
+    {$ENDIF}
+  {$ENDIF}
 
   fBits:=ELFCLASSNONE;
   {$IFDEF CPU32}

+ 4 - 0
packages/fcl-res/src/elfreader.pp

@@ -285,6 +285,10 @@ begin
       EM_ALPHA  : fMachineType:=emtalpha;
       EM_IA_64  : fMachineType:=emtia64;
       EM_X86_64 : fMachineType:=emtx86_64;
+      EM_MIPS   : if fOrder=ELFDATA2LSB then
+                    fMachineType:=emtmipsel
+                  else
+                    fMachineType:=emtmips;
     end;
   finally
     subreader.Free;

+ 1 - 0
packages/fcl-res/src/elfsubwriter.inc

@@ -424,6 +424,7 @@ begin
       EM_PPC64  : begin RelocType:=R_PPC64_ADDR64;  SectionType:=SHT_RELA; end;
       EM_ALPHA  : begin RelocType:=R_ALPHA_REFQUAD; SectionType:=SHT_RELA; end;
       EM_IA_64  : begin RelocType:=R_IA64_DIR64LSB; SectionType:=SHT_RELA; end;
+      EM_MIPS   : begin RelocType:=R_MIPS_32;      SectionType:=SHT_RELA; end;
       else
         raise EElfResourceWriterUnknownMachineException.Create('');
     end;

+ 3 - 1
packages/fcl-res/src/elfwriter.pp

@@ -553,7 +553,9 @@ begin
     emtarmeb  : begin fMachineTypeInt:=EM_ARM; fBits:=ELFCLASS32; fOrder:=ELFDATA2MSB; end;
     emtalpha  : begin fMachineTypeInt:=EM_ALPHA; fBits:=ELFCLASS64; fOrder:=ELFDATA2LSB; end;
     emtia64   : begin fMachineTypeInt:=EM_IA_64; fBits:=ELFCLASS64; fOrder:=ELFDATA2LSB; end;
-    emtx86_64 : begin fMachineTypeInt:=EM_X86_64; fBits:=ELFCLASS64; fOrder:=ELFDATA2LSB; end
+    emtx86_64 : begin fMachineTypeInt:=EM_X86_64; fBits:=ELFCLASS64; fOrder:=ELFDATA2LSB; end;
+    emtmips   : begin fMachineTypeInt:=EM_MIPS; fBits:=ELFCLASS32; fOrder:=ELFDATA2MSB; end;
+    emtmipsel : begin fMachineTypeInt:=EM_MIPS; fBits:=ELFCLASS32; fOrder:=ELFDATA2LSB; end
     else
       raise EElfResourceWriterUnknownMachineException.Create('');
   end;