home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 May / pcp151c.iso / misc / src / install / modutils / obj / obj_m68k.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-06  |  2.8 KB  |  122 lines

  1. /* m68k specific support for Elf loading and relocation.
  2.    Copyright 1996, 1997 Linux International.
  3.  
  4.    Contributed by Richard Henderson <rth@tamu.edu>
  5.  
  6.    This file is part of the Linux modutils.
  7.  
  8.    This program is free software; you can redistribute it and/or modify it
  9.    under the terms of the GNU General Public License as published by the
  10.    Free Software Foundation; either version 2 of the License, or (at your
  11.    option) any later version.
  12.  
  13.    This program is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software Foundation,
  20.    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  21.  
  22. #ident "$Id: obj_m68k.c,v 1.1.1.1 1998/01/06 20:51:08 ewt Exp $"
  23.  
  24. #include <stddef.h>
  25. #include <module.h>
  26. #include <obj.h>
  27. #include <util.h>
  28.  
  29.  
  30. /*======================================================================*/
  31.  
  32. struct obj_file *
  33. arch_new_file (void)
  34. {
  35.   return xmalloc(sizeof(struct obj_file));
  36. }
  37.  
  38. struct obj_section *
  39. arch_new_section (void)
  40. {
  41.   return xmalloc(sizeof(struct obj_section));
  42. }
  43.  
  44. struct obj_symbol *
  45. arch_new_symbol (void)
  46. {
  47.   return xmalloc(sizeof(struct obj_symbol));
  48. }
  49.  
  50.  
  51. enum obj_reloc
  52. arch_apply_relocation (struct obj_file *ef,
  53.                struct obj_section *targsec,
  54.                struct obj_section *symsec,
  55.                struct obj_symbol *sym,
  56.                Elf32_Rela *rel,
  57.                Elf32_Addr v)
  58. {
  59.   char *loc = targsec->contents + rel->r_offset;
  60.   Elf32_Addr dot = targsec->header.sh_addr + rel->r_offset;
  61.  
  62.   enum obj_reloc ret = obj_reloc_ok;
  63.  
  64.   switch (ELF32_R_TYPE(rel->r_info))
  65.     {
  66.     case R_68K_NONE:
  67.       break;
  68.  
  69.     case R_68K_8:
  70.       if (v > 0xff)
  71.     ret = obj_reloc_overflow;
  72.       *(char *)loc = v;
  73.       break;
  74.     case R_68K_16:
  75.       if (v > 0xffff)
  76.     ret = obj_reloc_overflow;
  77.       *(short *)loc = v;
  78.       break;
  79.     case R_68K_32:
  80.       *(int *)loc = v;
  81.       break;
  82.  
  83.     case R_68K_PC8:
  84.       v -= dot;
  85.       if ((Elf32_Sword)v > 0x7f || (Elf32_Sword)v < -(Elf32_Sword)0x80)
  86.     ret = obj_reloc_overflow;
  87.       *(char *)loc = v;
  88.       break;
  89.     case R_68K_PC16:
  90.       v -= dot;
  91.       if ((Elf32_Sword)v > 0x7fff || (Elf32_Sword)v < -(Elf32_Sword)0x8000)
  92.     ret = obj_reloc_overflow;
  93.       *(short *)loc = v;
  94.       break;
  95.     case R_68K_PC32:
  96.       *(int *)loc = v - dot;
  97.       break;
  98.  
  99.     case R_68K_RELATIVE:
  100.       *(int *)loc += ef->baseaddr;
  101.       break;
  102.  
  103.     default:
  104.       ret = obj_reloc_unhandled;
  105.       break;
  106.     }
  107.  
  108.   return ret;
  109. }
  110.  
  111. int
  112. arch_create_got (struct obj_file *ef)
  113. {
  114.   return 1;
  115. }
  116.  
  117. int
  118. arch_init_module (struct obj_file *f, struct new_module *mod)
  119. {
  120.   return 1;
  121. }
  122.