ELF specification

This is version 0.1.2 (DRAFT) of this specification.

Overview
This is a specification to extend the Executable and Linking Format (ELF) to encompass MOS family of processors and their relatives. These include, but are not limited to, the MOS 6502, the MOS 65816, and similar processors.

This draft considers the Tool Interface Standard (TIS), Executable and Linking Format (ELF) Specification, Version 1.2 to be normative.

Comments and improvements are solicited at johnwbyrd at gmail dot com.

Machine type field
The e_machine field shall have a constant name of EM_MOS. The constant of EM_MOS shall be set to 6502 (hexadecimal, 0x1966).

The e_flags field bits shall have the following meanings. These values may be logically OR'ed to indicate that multiple features are present.


 * 1) Section flags

Each ELF section header contains a 32-bit word named sh_flags. For MOS-format ELF files, these flags have special meanings.


 * Name | Value | Description |
 * SHF_MOS_ZEROPAGE | 0x10000000 | This bit should be set to one if this ELF section is to be placed in zero page or direct page. An assembler or linker may use this information to determine whether addresses in this section will be 8 bits long.
 * SHF_MOS_ZEROPAGE | 0x10000000 | This bit should be set to one if this ELF section is to be placed in zero page or direct page. An assembler or linker may use this information to determine whether addresses in this section will be 8 bits long.


 * 1) Relocation types

Relocations generally work as specified in the Relocations section of the ELF specification as described earlier. Each relocation entry in a MOS ELF file describes a particular MOS relocation. The lowest byte in the r_info field in an Elf32_Rel or Elf32_Rela relocation entry, is treated as a MOS-specific relocation type. (The ELF specification refers to this as the ELF32_R_TYPE macro.)

The exact types of MOS-specific relocations for ELF can be viewed in [MOS.def](../blob/master/llvm/include/llvm/BinaryFormat/ELFRelocs/MOS.def).

Although the ELF format encompasses 32-bit address types, it does not require them. MOS processors can access 16 bits by default and 24 bits at most. When an 8-bit, 16-bit, or 24-bit address is stored in a 32-bit ELF address type, the unused high bits should be zeroed.


 * 1) References

Commodore Semiconductor Group CSG65CE02 Technical Reference

MCS6500 Family Microcomputer Programming Manual, January 1976

Tool Interface Standard (TIS), Executable and Linking Format (ELF) Specification, Version 1.2