Macintosh Toolbox - Advent and Implementation

Advent and Implementation

The original, Motorola 68000 family, implementation of the Macintosh operating system implements system calls using that processor's illegal opcode exception handling mechanism. Motorola specified that instructions beginning with 1111 and 1010 would never be used in future 68000 family processors, thus freeing them for use as such by an operating system. As 1111 was reserved for use by co-processors such as the 68881 FPU, Apple chose 1010, which is the binary equivalent of the decimal number ten, as the prefix for operating system calls. Ten is represented in hexadecimal as A, and handling illegal instructions is known as trapping, so these special instructions were called A-traps. When the processor encounters such an instruction, it transfers control to the operating system, which looks up and performs the appropriate task. There were two advantages to this mechanism:

  • It results in compact programs. Only two bytes are taken by every operating system access, in contrast to four or six when using regular jump instructions.
  • The table used to look up the appropriate function is stored in RAM. Then, even if the underlying code was stored in ROM, it could still be overridden (patched) by replacing the ROM memory address with a RAM address.

The system was further optimized by allotting some bits of the A-trap instruction to store parameters to the most common functions. For example, memory allocation is a very common task, so it should be expressed in as few bytes of code as possible. Sometimes the programmer wants to clear the memory block to zeros, so either the allocation function should take a boolean parameter, or there should be two allocation functions. To pass a parameter would require an additional two-byte instruction, which would be inefficient. Having two functions would require at least an extra four bytes of RAM used for the address in the function look-up table. The most efficient solution is to map multiple A-traps to the same subroutine, which then uses the A-trap as a parameter. This is true of the most commonly used subroutines. However, the Toolbox was composed of the less commonly used subroutines. The Toolbox was defined as the set of subroutines which took no parameters within the A-trap, and were indexed from a 1024-entry, 4-kilobyte dispatch table. (Machines shipped with less than one megabyte of RAM use a single table of 512 entries, which corresponds to the 256-entry OS dispatch table of later ROM revisions.)

Read more about this topic:  Macintosh Toolbox

Famous quotes containing the word advent:

    Not until the advent of Impressionism does the repudiation of principles set in which opened the way for the burlesque parade of the fashionable and publicity-crazed modernities of our century.
    Johan Huizinga (1872–1945)