A.out: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
m (Added basic description)
m (Added positions and ELF link)
Line 2: Line 2:
{{File formats}}
{{File formats}}


A.OUT is the "original" binary format for Unix machines. It is considered obsolete today because of several shortcomings. However, as it is extremely simple and supported by many compilers/assemblers, it may be a good choice if you're willing to develop your own format or have more information than 'raw binary' for your bootloader.
A.OUT is the "original" binary format for Unix machines. It is considered obsolete today because of several shortcomings. It was superseded by System V [[ELF]]. However, as it is extremely simple and supported by many compilers/assemblers, it may be a good choice if you're willing to develop your own format or have more information than 'raw binary' for your bootloader.


==Structure==
==Structure==
Line 33: Line 33:
|}
|}
===The exec header===
===The exec header===
Every binary file begins with an exec structure:
Every binary file begins with an exec structure, which is 32 or 64 bytes in size:
<source lang="c">
<source lang="c">
struct exec {
struct exec {
Line 49: Line 49:
{| class="wikitable"
{| class="wikitable"
|-
|-
! Position (32 bit)
! Position (64 bit)
! Field
! Field
! Description
! Description
|-
|-
|0-3
|0-7
|a_midmag
|a_midmag
|This field is stored in network byte-order so that binaries for machines with alternative byte orders can be distinguished. It has a number of sub-components accessed by the macros N_GETFLAG(), N_GETMID(), and N_GETMAGIC(), and set by the macro N_SETMAGIC().
|This field is stored in network byte-order so that binaries for machines with alternative byte orders can be distinguished. It has a number of sub-components accessed by the macros N_GETFLAG(), N_GETMID(), and N_GETMAGIC(), and set by the macro N_SETMAGIC().
|-
|-
|4-7
|8-15
|a_text
|a_text
|Contains the size of the text segment in bytes.
|Contains the size of the text segment in bytes.
|-
|-
|8-11
|16-23
|a_data
|a_data
|Contains the size of the data segment in bytes.
|Contains the size of the data segment in bytes.
|-
|-
|12-15
|24-31
|a_bss
|a_bss
|Contains the number of bytes in the `bss segment'. The kernel loads the program so that this amount of writable memory appears to follow the data segment and initially reads as zeroes.
|Contains the number of bytes in the `bss segment'. The kernel loads the program so that this amount of writable memory appears to follow the data segment and initially reads as zeroes.
|-
|-
|16-19
|32-39
|a_syms
|a_syms
|Contains the size in bytes of the symbol table section.
|Contains the size in bytes of the symbol table section.
|-
|-
|20-23
|40-47
|a_entry
|a_entry
|Contains the address in memory of the entry point of the program after the kernel has loaded it; the kernel starts the execution of the program from the machine instruction at this address.
|Contains the address in memory of the entry point of the program after the kernel has loaded it; the kernel starts the execution of the program from the machine instruction at this address.
|-
|-
|24-27
|48-55
|a_trsize
|a_trsize
|Contains the size in bytes of the text relocation table.
|Contains the size in bytes of the text relocation table.
|-
|-
|28-31
|56-63
|a_drsize
|a_drsize
|Contains the size in bytes of the data relocation table.
|Contains the size in bytes of the data relocation table.

Revision as of 14:09, 11 February 2019

This page is a stub.
You can help the wiki by accurately adding more contents to it.
Executable Formats
Microsoft

16 bit:
COM
MZ
NE
Mixed (16/32 bit):
LE
32/64 bit:
PE
COFF

*nix
Apple

A.OUT is the "original" binary format for Unix machines. It is considered obsolete today because of several shortcomings. It was superseded by System V ELF. However, as it is extremely simple and supported by many compilers/assemblers, it may be a good choice if you're willing to develop your own format or have more information than 'raw binary' for your bootloader.

Structure

An a.out binary file consists of up to 7 sections. In order, these sections are:

Section Description
exec header Contains parameters used by the kernel to load a binary file into memory and execute it, and by the link editor ld to combine a binary file with other binary files. This section is the only mandatory one.
text segment Contains machine code and related data that are loaded into memory when a program executes. Should be loaded read-only.
data segment Contains initialized data; always loaded into writable memory.
text relocations Contains records used by the link editor to update pointers in the text segment when combining binary files.
data relocations Like the text relocation section, but for data segment pointers.
symbol table Contains records used by the link editor to cross reference the addresses of named variables and functions (`symbols') between binary files.
string table Contains the character strings corresponding to the symbol names.

The exec header

Every binary file begins with an exec structure, which is 32 or 64 bytes in size:

struct exec {
	unsigned long   a_midmag;
	unsigned long   a_text;
	unsigned long   a_data;
	unsigned long   a_bss;
	unsigned long   a_syms;
	unsigned long   a_entry;
	unsigned long   a_trsize;
	unsigned long   a_drsize;
};

The fields have the following functions:

Position (32 bit) Position (64 bit) Field Description
0-3 0-7 a_midmag This field is stored in network byte-order so that binaries for machines with alternative byte orders can be distinguished. It has a number of sub-components accessed by the macros N_GETFLAG(), N_GETMID(), and N_GETMAGIC(), and set by the macro N_SETMAGIC().
4-7 8-15 a_text Contains the size of the text segment in bytes.
8-11 16-23 a_data Contains the size of the data segment in bytes.
12-15 24-31 a_bss Contains the number of bytes in the `bss segment'. The kernel loads the program so that this amount of writable memory appears to follow the data segment and initially reads as zeroes.
16-19 32-39 a_syms Contains the size in bytes of the symbol table section.
20-23 40-47 a_entry Contains the address in memory of the entry point of the program after the kernel has loaded it; the kernel starts the execution of the program from the machine instruction at this address.
24-27 48-55 a_trsize Contains the size in bytes of the text relocation table.
28-31 56-63 a_drsize Contains the size in bytes of the data relocation table.

See Also