Skip to content

Latest commit

 

History

History
142 lines (122 loc) · 7.04 KB

Format.md

File metadata and controls

142 lines (122 loc) · 7.04 KB

WaveAsm output formats

Format binary Flat [-ff] (default)

Flat binary format, contains no formatting, metadata or other info. The program code is placed in the file in the order it is assembled.

When assembling flat files, any includes normally should go at the bottom of the file, this is only a recommendation.

The use of .org macros will change the generation address, but not the order of the code in the binary file.

Format text S19 [-fs]

Simple text based format that allows addressable loading and a program entry address.

All values in s19 are uppercase ASCII and numbers, data are stored as sequential bytes (big endian) as two hex digits each.

All data are broken into "records" which can contain up to 254 bytes each, typical records will be shorter. Each record consists of: ASCII "S", a digit indicating record type, a byte length - 2 hex digits, variable size fields.

The first field is the address field, it is normally 2 bytes long, 3 bytes for S2,S8 records, 4 bytes for S3 and S9 records.

Next is the data field, the size of the data field is (length - 1) - address_bytes

After the data field is a one byte checksum field, this is computed by adding up the length and all other fields, taking the least significant byte and inverting the bits (ones complement).

The file is a sequence of records, seperated by newlines. All records must have a checksum. These are the record types:

  • S0 metadata or version string
  • S1,S2,S3 actual program data and addresses (which kind depends on address size).
  • S5 a count of previous S1,S2,S3 records, count stored in 16 bit address field + checksum.
  • S7,S8,S9 optional, program start address, just an address checksum fields, no data.

Format binary ELF [-fE]

A versatile and extendable format, but also more complex. Designed for 32 bit machines.

For CPU architectures that use less than 32 bits, the 32 bit spec is used, but all the high bits of addresses are set to 0 and ignored.

Main Header

Offset (hex)Length (bytes)FieldDescription
004MagicBig endian byte string that identifies the file (0x7F454C46)
041EndiannessEither 1 - little endian or 2 - big endian
051WordsizeThis field defines the address word size. For processors with addresses less than 32 bits: a 32 bit option is used with extra bits set to 0.
It also defines the size of individual words stored at each address. Values are as follows:
ValueAddress (bits)addrsize
0x01324
0x02648
061VersionNormally set to 0x01
071osabitypeuser definable OS type, set to 0x5E by default.
081osabiveruser definable, set to 0x00 by default.
097paddingunused, set to 0
Values below are stored in the endianness of the target machine.
102exetype Executable type
ValueMeaning
0No type
1Relocatable
2Executable (default)
3Shared object
4Core
122arch Architecture/CPU type. WaveAsm will support the following values for arch:
Value (dec)CPU
0None
380386 or x86
468000
1365816
20PowerPC
32TR3200
40ARM32
7068HC11
128DCPU-16
155AKI24
262CAK31135
144eversiondefault 0x00000001
18n=addrsize (see above)entrybeginning address of program execution
18+nnphstartabsolute file offset to start of program header
18+2nnshstartabsolute file offset to start of sections header
18+3n4flagsunused
1C+3n2headerszsize of this header: dec 40+3n; hex 0x28+3n
1E+3n2phszsize of program header
20+3n2phctentries in program header
22+3n2shszsize of section header
24+3n2shctentries in section header
26+3n2shsnindxindex of sections entry with section names.
### Program Header

The program header consists of an array of entries. The count entries and starting file offset are in the main header. Each entry in the program header table optionally points to a segment in the file with data.

Offset (hex)Length (bytes)FieldDescription
004type
ValueMeaning / Data pointed to
0x00Null entry - ignore this entry
0x01Loadable data (program code/data)
0x02Dynamic link info
0x03Interpreter name as Null terminated string
0x04A Note table
044offsetfile offset that segment starts at
084vaddrVirtual memory address segment should be loaded at
0C4paddrPhysical memory address segment should be loaded at.
(if applicable)
104fileszSize of segment in file
144memszamount of memory to be allocated for segment
184flagsBit mask of options
BitMeaning
1If set: allow Execute
2If set: allow Write
3If set: allow Read
21-28OS specific
29-32CPU specific
1C4alignThe alignment that should be used for the segment.
A value of 0 or 1 means no alignment, other values must be a power of 2

File structure

The typical ELF file generated by WaveAsm consists (minimally) of the main header, followed a two or more entries program header table. A 2 entry section table (the null section and string table). Then program segment(s).