fix_m68k.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* fix_m68k.h: Routines for M68000 code fixup
  2. Copyright (C) 2003 Sebastian Reichelt
  3. Copyright (C) 2004 Kevin Kofler
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  15. #ifndef BINCODE_FIX_M68K_H
  16. #define BINCODE_FIX_M68K_H
  17. #include "../generic.h"
  18. #include "../data.h"
  19. // The alignment needed for sections with M68k code or data.
  20. #define M68K_SECTION_ALIGNMENT 2
  21. // Apply generic code fixes and optimizations to a section.
  22. void M68kFixCode (SECTION *Section);
  23. // Fix and optionally optimize code executable on the M68k processor family,
  24. // for two sections which are to be merged.
  25. // Src may be NULL.
  26. // If DestSize is nonzero, it specifies a fixed size for the destination
  27. // section, which will not change even when cutting ranges from it.
  28. void M68kFixCodePreMerge (SECTION *Dest, SECTION *Src, SIZE DestSize);
  29. // If the section ends with exactly one NOP instruction, remove the NOP.
  30. void M68kRemoveTrailingNOP (SECTION *Section);
  31. // Fix and possibly optimize a given relocation entry.
  32. // TargetDistance is the estimated (signed) distance of the relocation target,
  33. // including the fixed offset. OptimizeInfo contains information about what to
  34. // optimize.
  35. // The reloc may be removed during the process.
  36. void M68kFixReloc (RELOC *Reloc, OFFSET TargetDistance, OPTIMIZE_INFO *OptimizeInfo);
  37. // Checks if a specific reloc might be optimizable. This is currently
  38. // limited to 4-bytes absolute relocs because that is the only case
  39. // this is needed for.
  40. BOOLEAN M68kIsRelocOptimizable (const RELOC *Reloc);
  41. // Fix and return the target offset of a reloc.
  42. // In particular, for 1-byte relative relocs, the target offset is increased
  43. // by 1, so the the reloc points to the symbol and not to the symbol minus 1.
  44. OFFSET M68kFixTargetOffset (OFFSET Offset, SIZE RelocSize, BOOLEAN RelocRelative);
  45. // Determines the amount of relationship between the two sections, for the
  46. // situation that Section2 might be put just behind Section1. A reference
  47. // that could potentially be short gets 2048 points; a reference that could
  48. // potentially be removed gets twice as much.
  49. // The effect is that a section with one potentially short reference can
  50. // be at most 2048 bytes long for being inserted immediately by reordering,
  51. // and so on.
  52. COUNT M68kGetSectionRelationship (const SECTION *Section1, const SECTION *Section2);
  53. // Compute an estimate of how important it is to put the section containing this
  54. // reloc next during local section reordering.
  55. // Here are the estimates used:
  56. // 0-byte branches save 6 bytes and 1 reloc and cannot be deferred -> 512 points
  57. // 2-byte branches save 4 bytes and 1 reloc and can rarely be deferred -> 256
  58. // PC-relative references save 2 bytes and 1 reloc. They can be deferred based
  59. // on how far the accumulated distance is. We compute between 0 and 32 points
  60. // based on the offset, with the formula: (offset^2>>25)+2.
  61. COUNT M68kComputeRelocGoodness(OFFSET Offset, RELOC *Reloc);
  62. #endif