COM: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
(added loading and see also sections)
m (Added a small amount of information and made nicer to read.)
Line 4: Line 4:
==COM Files==
==COM Files==
===Introduction===
===Introduction===
COM files are extremely simple, making them useful if you want to load programs but you don't want to worry about relocating symbols, reading file headers, and other complications. However, their simplicity makes their usefulness limited, so you'll definitely want to support something more complex but useful, once your OS is advanced.
COM files are extremely simple executable files. They are useful for loading programs without complications like relocating symbols, reading file headers, etc. However, their simplicity can make their usefulness limited, so you may want to support something more complex but useful, like [[ELF]], once your OS is advanced.


COM files were used by MS-DOS. They are raw binaries--there is no header data. Also, COM files are restricted to the size of one segment (a real-address mode segment, 64kb), minus 256 bytes. When a COM file is loaded, it is assumed that all code and data fits in one segment, and it is loaded to offset 0x100.
COM files were used by MS-DOS. They are raw binaries, meaning there is no header data. Also, COM files are restricted to the size of one segment (a real-address mode segment, 64kb), minus 256 bytes. When a COM file is loaded, it is assumed that all code and data fits in one segment, and it is loaded to offset 0x100.


MS-DOS creates and stores an info structure starting at offset 0 and ending just before 0x100, called the Program Segment Prefix (PSP). The PSP is made just before starting the COM program. More info about the PSP can be found [http://heim.ifi.uio.no/~stanisls/helppc/program_segment_prefix.html here]. Unless you plan on supporting actual DOS programs, you don't need a PSP.
MS-DOS creates and stores an info structure starting at offset 0 and ending just before 0x100, called the Program Segment Prefix (PSP). The PSP is made just before starting the COM program. More info about the PSP can be found [http://heim.ifi.uio.no/~stanisls/helppc/program_segment_prefix.html here]. PSP is only required for running DOS programs.

COM files usually terminate with a RET instruction. The operating system starts the COM program using a CALL instruction, so RET returns to the OS, allowing any cleanup (like restarting the command prompt) to be handled by the OS.


COM files usually terminate with a RET instruction. The operating system starts the COM program using a CALL instruction, so RET returns to the OS, allowing any cleanup (like restarting the command prompt).
===Loading===
===Loading===
To load a COM file you need to load it to a low memory location, set ds and es to be pointing to the start of the file with an 0x100 org, and jump to the start, with offset 0x100.
To load a COM file you need to load it to a low memory location, point ds and es to the start of the file with an 0x100 org, and jump to the start, with offset 0x100.
==See also==
==See also==
===Executables===
===Executables===

Revision as of 17:31, 7 May 2019

This is about the executable format, not Microsoft's Component Object Model

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

COM Files

Introduction

COM files are extremely simple executable files. They are useful for loading programs without complications like relocating symbols, reading file headers, etc. However, their simplicity can make their usefulness limited, so you may want to support something more complex but useful, like ELF, once your OS is advanced.

COM files were used by MS-DOS. They are raw binaries, meaning there is no header data. Also, COM files are restricted to the size of one segment (a real-address mode segment, 64kb), minus 256 bytes. When a COM file is loaded, it is assumed that all code and data fits in one segment, and it is loaded to offset 0x100.

MS-DOS creates and stores an info structure starting at offset 0 and ending just before 0x100, called the Program Segment Prefix (PSP). The PSP is made just before starting the COM program. More info about the PSP can be found here. PSP is only required for running DOS programs.

COM files usually terminate with a RET instruction. The operating system starts the COM program using a CALL instruction, so RET returns to the OS, allowing any cleanup (like restarting the command prompt) to be handled by the OS.

Loading

To load a COM file you need to load it to a low memory location, point ds and es to the start of the file with an 0x100 org, and jump to the start, with offset 0x100.

See also

Executables

16 bit

32 bit