Amiga Hunk

From Wikipedia, the free encyclopedia

Hunk is the executable file format of tools and programs of the Amiga "Classic" Operating System (up to AmigaOS 3.9) based on Motorola 68000 CPU and other processors of the same family. This kind of executable got its name from the fact that the software programmed on Amiga is divided in its internal structure into many pieces called hunks, in which every portion could contain either code or data.

Contents

[edit] Hunk structure

The hunks in an Amiga executable file could exist in various types. There are 32-bit type hunks, 16-bit type hunks, and even some of 8-bit type.

Types of hunks were standardized in AmigaOS, and well documented in The AmigaDOS Manual edited by Commodore to explain to programmers how to code on the Amiga, during the years in which Commodore manufactured Amiga computers. Their structure was officially codified and could be changed only by a Commodore committee, which then communicated the modifications to the developers for new releases of the Amiga operating system.

The structure of an Amiga hunk is very simple: There is a header at the beginning of the hunk indicating that that kind of "portion of code" is a known and valid Amiga hunk type, then follows an ID which indicates the length of the hunk itself, and at the bottom is the segment of the hunk which contains the real code or data.

[edit] Features of Amiga executable files

Amiga executable files can be launched either from the graphical shell of the Amiga, the Workbench, from the Amiga's command line interpreter (called CLI, later AmigaShell), or even from a file manager tool.

No particular filename extension is required for Amiga executable files. For example, the calculator applet "Calculator" can be renamed to "Calculator.com", "Calculator.exe", "Calculator.bin", or even "Calculator.jpeg". These are all valid names for programs or tools, because AmigaOS does not differentiate between file extensions.

Some operating systems, such as MS-DOS or Windows, need filename extensions to recognize that a file is an executable. Usually, this extension is a three-character acronym separated from the real filename by a period ".".

AmigaOS adopted another method to recognize it is dealing with a valid executable. There is a particular sequence of bytes in the file header, yielding the hexadecimal value $000003f3. This sequence, which signifies an executable file and lets it be self-running, is called a magic cookie (from the magic cookies in Alice's Adventures in Wonderland by Lewis Carroll).[citation needed]

This kind of solution to identify executables on the Amiga was taken from similar solutions which were adopted by UNIX/Unix-like operating systems, where magic cookies are called magic numbers.

Even if this solution for identifying executable files is still in use in Unix, Unix-like systems have nowadays adopted a different system. The new system deals with file attribute bits and consists of setting the attribute bit "X" (stands for "eXecutable") in the table of attribute bits of the structure of the file itself.

[edit] Structure of an Amiga executable file

The internal structure of an Amiga executable file is very simple. In the beginning of the file there is the magic cookie, then is declared the total number of hunks in the executable, and just after this is the progressive numbers of hunks starting from "0" (zero).

The first hunk is always numbered zero, so if the executable is (for example) subdivided into three hunks, they will be numbered "0" for the first one, "1" the second and "2" the third hunk, and so on.

Just before the real hunks start is a table containing information about the length of any hunks present in the executable, and in the last part of the file are positioned the real hunks, each one described by its type name: HUNK_CODE, HUNK_DATA, et cetera.

Representation of the structure:

Magic Cookie Total number of hunks Progressive number of hunks Table of length Various Hunks (Hunk_Code, Hunk_Data, etc)

[edit] Hunk Types

Known hunk types into Amiga are:

Name Value
HUNK_UNIT 999
HUNK_NAME 1000
HUNK_CODE 1001
HUNK_DATA 1002
HUNK_BSS 1003
HUNK_RELOC32 1004
HUNK_RELOC16 1005
HUNK_RELOC8 1006
HUNK_EXT 1007
HUNK_SYMBOL 1008
HUNK_DEBUG 1009
HUNK_END 1010
HUNK_HEADER 1011
(not used) 1012
HUNK_OVERLAY 1013
HUNK_BREAK 1014
HUNK_DREL32 1015
HUNK_DREL16 1016
HUNK_DREL8 1017
HUNK_LIB 1018
HUNK_INDEX 1019
HUNK_RELOC32SHORT 1020
HUNK_RELRELOC32 1021
HUNK_ABSRELOC16 1022
HUNK_PPC_CODE 1257
HUNK_RELRELOC26 1260

[edit] Metadata


[edit] Other executable file formats recognized by AmigaOS

AmigaOS up to 3.9 recognizes various kinds of executable files other than Hunk format created for Motorola 68000.

[edit] Hunk_Overlay

The Hunk_Overlay type for Amiga executables was one of the standard hunk types created by Commodore. It was intended to solve the common problem of having a very small amount of RAM, which afflicted early low-end Amiga models. It implemented a method to run huge programs even on machines equipped with little RAM, in a time when a RAM expansion card and some RAM modules could cost more than an entire low-end computer.

Executables based on Hunk_Overlay structure have a root node which is in memory at all times, and the rest of the program is split into smaller modules. These smaller parts are loaded and unloaded as needed, so any programmer could fit a very large program into a small amount of memory.

Even if the creation of this hunk type could be considered smart in principle, the use of Hunk_Overlay in practice was so complicated and developer-unfriendly that developers usually avoided using this Hunk Type structure.

[edit] Extended Hunk format

In 1997, Phase5, an Amiga hardware manufacturer, launched their range of PowerPC (PPC) accelerators. The PowerUP boards were dual-processor boards, incorporating the PPC and a 68K processor (68LC040, 68040 or 68060). The AmigaOS still requires a 68K processor, while the PPC acts as an extremely fast coprocessor that carries out specific instructions. Unfortunately, this causes significant slowdown when the OS task switches between the 68K and PPC. In an attempt to solve the problems that were raised and the lack of performance by PPC processor, Haage & Partner, an Amiga software and hardware manufacturer (which also created AmigaOS 3.9), developed a competing API called WarpOS. Phase 5 reacted by implementing Executable and Linkable Format (ELF) that was aimed to promote their own A/Box solution. The best feature of WarpOS is that it is system friendly with original Amiga executables which implemented the Amiga HUNK format. This format was called EHF (Extended Hunk format)[1], and implemented the hunk type named HUNK_PPC_CODE[2].

[edit] WarpUP

The new Amiga software following the EHF standard was called WarpUP Amiga software.

[edit] ELF

Phase 5 implemented ELF excutables for its accelerator boards. This format was then adopted as standard by AmigaOS 4.0 and MorphOS.

[edit] PowerUP

PowerUP is the system of libraries born for the PowerUP accelerated cards of Amiga. It implemented ELF executables, and it is composed mainly of PPC.Library which is capable of recognising these executables and performing these actions:

  1. turning off the 68000 Motorola processor present on the accelerator card,
  2. turning on the PPC processor present as second processor,
  3. passing the PPC programs to the PowerPC processor, and hence the task is completed, then
  4. returning all power to Motorola 68000, this time by quitting PPC.

This reduces performances of accelerator cards with a continuous processor switching on and off.

[edit] PPClibemu

PPCLibEmu was an emulation of the PPC.library on WarpOS that allowed the user to run programs for PowerUP under WarpOS.

[edit] AmigaOS 4.0 and MorphOS

AmigaOS 4.0 and MorphOS can run ELF natively, but as these systems were designed to run on PowerPC processor-based machines, the developers wisely added also compatibility for Amiga WarpUP software, created for AmigaOS 3.9.

All software created for Amiga accelerator cards can run on new Amiga-like systems.

Both new operating systems could also run Amiga Hunk format because they implemented internally the old Amiga API environment based on AmigaOS 3.1, and can run 68000 code through emulators equipped with internal JITM (Just In Time Machine) which maps all instruction sets of the 680X0 family, much enhancing the emulation speed. The JIT machine of AmigaOS is called Petunia. The one running on MorphOS is called Trance.

  • Notes:
  1. ^  See also pages regarding history of the PPC processor on Amiga at Amiga.History site.
  2. ^  EHF specifications on Haage&Partners site.

[edit] References

  • The AmigaDOS Manual Third Edition (Bantam Books), Commodore Business Machines, July 1991. ISBN 0-553-35403-5
  • Amiga ROM Kernel Reference Manual, Includes and Autodocs (3rd edition; dark gray cover) Addison-Wesley, 1991. ISBN 0-201-56773-3
  • Commodore Business Machines: 1989 Amiga Developers Conference Notes, Commodore, 1989. CATS part numbers: NOTES89 and NOTES89D
  • Commodore Business Machines: V3.1 Amiga Developer Update Disk Set, Commodore, 1994. CATS part number: AMDEV3.1

(information from this set of floppies distributed by Commodore to Amiga developers are obsolete and updated and replaced into "The Developer CD")

  • Commodore Business Machines: 1988 Amiga Developers Conference Notes Commodore, 1988. CATS part numbers: NOTES88 and NOTES88D
  • Stephen Levy: Amiga Programmer's Guide, Compute! Publications, 1986. ISBN 0-87455-028-9
  • Eugene P. Mortimore: Amiga Programmer's Handbook, Sybex, 1985. ISBN 0-89588-343-0

[edit] External links