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