Macintosh Toolbox
Encyclopedia
The Macintosh
Toolbox is a set of application programming interface
s with a particular access mechanism. They implement many of the high-level features of the Mac OS
. The Toolbox consists of a number of "managers," software components such as QuickDraw
, responsible for drawing onscreen graphics, and the Menu Manager, which maintain data structures describing the menu bar. As the Macintosh was designed without virtual memory
or memory protection
, it was important to classify code according to when it should be loaded into memory or kept on disk, and how it should be accessed. The Toolbox consists of subroutines essential enough to be permanently kept in memory and accessible by a two-byte machine instruction
; however it excludes core "kernel" functionality such as memory management
and the file system
. Note that the Toolbox does not draw the menu onscreen: menus were designed to have a customizable appearance, so the drawing code was stored in a resource
, which could be on a disk.
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:
The system was further optimized by allotting some bits of the A-trap instruction to store parameter
s 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.)
architecture, which lacked hardware support for the A-trap mechanism. Because of their use in applying software patches, however, the dispatch tables were retained. The API library code underlying any Toolbox routine then does nothing except reference the dispatch table. The dispatch table linked only to emulated 68000 family code. Toolbox functions implemented in native PowerPC code have to first disable the emulator using the Mixed Mode Manager. For the sake of uniformity and extensibility, new function entries even continued to be added to the Toolbox after the PowerPC transition.
An alternative mechanism did exist, however, in the Code Fragment Manager, which was used to load and dynamically link native PowerPC programs. The PowerPC system call facility, analogous to the A-trap mechanism, was used to interface with the Mac OS nanokernel
, which offered few services directly useful to applications.
, it was convenient to use as a bootloader environment. In conjunction with resources stored on the ROM chip, the Toolbox could turn the screen gray, show a dialog box with the signature "Welcome to Macintosh" greeting, and display the mouse cursor. The capability to interact with the user without loading an operating system is best known as a Basic Input/Output System, although Toolbox facilities were not used to provide the interactive diagnostic utilities familiar in IBM PC compatible
s. Indeed, in using the Toolbox to help boot the machine, a rudimentary Macintosh environment was initialized long before loading the System suitcase
from disk (in fact before ROMs on NuBus cards were executed), which is when the decision to use 24-bit or 32-bit addressing has to be made (hence why the System 7's support for 32-bit addressing requires 32-bit clean ROMs, as older Mac ROMs did not have support for this). The need for a BIOS diagnostics as in the IBM PC compatible
s was not widely necessary since Macintosh handled most of its diagnostics in POST and automatically reported errors via the "Sad Mac" codes.
The similarity between the boot-up environment and the actual operating system should not be confused with being identical, however. Although the "Classic Mac OS" boot process is convoluted and largely undocumented, it is not more limited than an IBM PC compatible
BIOS. Like a PC's master boot record
, a ROM-based Mac reads and executes code from the first blocks ("boot blocks") of the disk partition selected as the boot device. The boot blocks then verify that a suitable rudimentary environment exists, and use it to load the System suitcase. A different operating system with a different file system
can boot by simply using its own code in the boot blocks. This system was not used for PowerPC Linux, however, because Open Firmware
in New World ROM
machines requires a bootloader within an HFS filesystem—a reason having nothing to do with the Toolbox or "old-fashioned" Macs in general. More narrowly, the Startup Disk control panel in Mac OS and Mac OS X only allows the user to select a mounted filesystem with very particular constraints.
, the Toolbox is not used at all, though the Classic environment
loads the Toolbox ROM file into its virtual machine. Much of the Toolbox was restructured and implemented as part of Apple's Carbon programming API, allowing programmers familiar with the Toolbox to port
their program code more easily to Mac OS X.
Macintosh
The Macintosh , or Mac, is a series of several lines of personal computers designed, developed, and marketed by Apple Inc. The first Macintosh was introduced by Apple's then-chairman Steve Jobs on January 24, 1984; it was the first commercially successful personal computer to feature a mouse and a...
Toolbox is a set of application programming interface
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...
s with a particular access mechanism. They implement many of the high-level features of the Mac OS
Mac OS
Mac OS is a series of graphical user interface-based operating systems developed by Apple Inc. for their Macintosh line of computer systems. The Macintosh user experience is credited with popularizing the graphical user interface...
. The Toolbox consists of a number of "managers," software components such as QuickDraw
QuickDraw
QuickDraw is the 2D graphics library and associated Application Programming Interface which is a core part of the classic Apple Macintosh operating system. It was initially written by Bill Atkinson and Andy Hertzfeld. QuickDraw still exists as part of the libraries of Mac OS X, but has been...
, responsible for drawing onscreen graphics, and the Menu Manager, which maintain data structures describing the menu bar. As the Macintosh was designed without virtual memory
Virtual memory
In computing, virtual memory is a memory management technique developed for multitasking kernels. This technique virtualizes a computer architecture's various forms of computer data storage , allowing a program to be designed as though there is only one kind of memory, "virtual" memory, which...
or memory protection
Memory protection
Memory protection is a way to control memory access rights on a computer, and is a part of most modern operating systems. The main purpose of memory protection is to prevent a process from accessing memory that has not been allocated to it. This prevents a bug within a process from affecting...
, it was important to classify code according to when it should be loaded into memory or kept on disk, and how it should be accessed. The Toolbox consists of subroutines essential enough to be permanently kept in memory and accessible by a two-byte machine instruction
Instruction set
An instruction set, or instruction set architecture , is the part of the computer architecture related to programming, including the native data types, instructions, registers, addressing modes, memory architecture, interrupt and exception handling, and external I/O...
; however it excludes core "kernel" functionality such as memory management
Memory management
Memory management is the act of managing computer memory. The essential requirement of memory management is to provide ways to dynamically allocate portions of memory to programs at their request, and freeing it for reuse when no longer needed. This is critical to the computer system.Several...
and the file system
File system
A file system is a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve and update data, as well as manage the available space on the device which contain it. A file system organizes data in an efficient manner and is tuned to the...
. Note that the Toolbox does not draw the menu onscreen: menus were designed to have a customizable appearance, so the drawing code was stored in a resource
Resource fork
The resource fork is a construct of the Mac OS operating system used to store structured data in a file, alongside unstructured data stored within the data fork. A resource fork stores information in a specific form, such as icons, the shapes of windows, definitions of menus and their contents, and...
, which could be on a disk.
Advent and implementation
The original, Motorola 68000 family, implementation of the Macintosh operating system implements system calls using that processor's illegal opcodeIllegal opcode
An Illegal Opcode, also called an Undocumented Instruction, is an instruction to a CPU that is not mentioned in any official documentation released by the CPU's designer or manufacturer, which nevertheless has an effect. Illegal opcodes were common on older CPUs designed during the 1970s, such as...
exception handling
Interrupt
In computing, an interrupt is an asynchronous signal indicating the need for attention or a synchronous event in software indicating the need for a change in execution....
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
Floating point unit
A floating-point unit is a part of a computer system specially designed to carry out operations on floating point numbers. Typical operations are addition, subtraction, multiplication, division, and square root...
, Apple chose 1010, which is the binary equivalent of the decimal number ten
10 (number)
10 is an even natural number following 9 and preceding 11.-In mathematics:Ten is a composite number, its proper divisors being , and...
, as the prefix for operating system calls. Ten is represented in hexadecimal
Hexadecimal
In mathematics and computer science, hexadecimal is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen...
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 byteByteThe byte is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, a byte was the number of bits used to encode a single character of text in a computer and for this reason it is the basic addressable element in many computer...
s 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 (patchedPatch (computing)A patch is a piece of software designed to fix problems with, or update a computer program or its supporting data. This includes fixing security vulnerabilities and other bugs, and improving the usability or performance...
) by replacing the ROM memory addressMemory addressA digital computer's memory, more specifically main memory, consists of many memory locations, each having a memory address, a number, analogous to a street address, at which computer programs store and retrieve, machine code or data. Most application programs do not directly read and write to...
with a RAM address.
The system was further optimized by allotting some bits of the A-trap instruction to store parameter
Parameter (computer science)
In computer programming, a parameter is a special kind of variable, used in a subroutine to refer to one of the pieces of data provided as input to the subroutine. These pieces of data are called arguments...
s 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
Dispatch table
In computer science, a dispatch table is a table of pointers to functions or methods. Use of such a table is a common technique when implementing late binding in object-oriented programming.-Perl implementation:...
. (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.)
On PowerPC systems
In 1994, Apple released Macintoshes using the PowerPCPowerPC
PowerPC is a RISC architecture created by the 1991 Apple–IBM–Motorola alliance, known as AIM...
architecture, which lacked hardware support for the A-trap mechanism. Because of their use in applying software patches, however, the dispatch tables were retained. The API library code underlying any Toolbox routine then does nothing except reference the dispatch table. The dispatch table linked only to emulated 68000 family code. Toolbox functions implemented in native PowerPC code have to first disable the emulator using the Mixed Mode Manager. For the sake of uniformity and extensibility, new function entries even continued to be added to the Toolbox after the PowerPC transition.
An alternative mechanism did exist, however, in the Code Fragment Manager, which was used to load and dynamically link native PowerPC programs. The PowerPC system call facility, analogous to the A-trap mechanism, was used to interface with the Mac OS nanokernel
Mac OS nanokernel
Before Mac OS X, PowerPC versions of the Mac OS were based on a nanokernel, or extremely simple operating system kernel. The initial revision of this software is an extremely simple, single tasking system which delegates most tasks to an emulator running the Motorola 68K version of the operating...
, which offered few services directly useful to applications.
Functionality
The Toolbox is composed of commonly used functions, but not the most commonly used functions. As a result, it grew into a hodgepodge of different API libraries. The Toolbox encompasses most of the basic functionality which distinguished the Classic Mac OS. Apple's references “Inside Macintosh: Macintosh Toolbox Essentials” and “Inside Macintosh: More Macintosh Toolbox”, similarly vague in scope, also document most of the Toolbox.As a BIOS
Because much of the Toolbox is implemented in ROM, alongside the computer's firmwareFirmware
In electronic systems and computing, firmware is a term often used to denote the fixed, usually rather small, programs and/or data structures that internally control various electronic devices...
, it was convenient to use as a bootloader environment. In conjunction with resources stored on the ROM chip, the Toolbox could turn the screen gray, show a dialog box with the signature "Welcome to Macintosh" greeting, and display the mouse cursor. The capability to interact with the user without loading an operating system is best known as a Basic Input/Output System, although Toolbox facilities were not used to provide the interactive diagnostic utilities familiar in IBM PC compatible
IBM PC compatible
IBM PC compatible computers are those generally similar to the original IBM PC, XT, and AT. Such computers used to be referred to as PC clones, or IBM clones since they almost exactly duplicated all the significant features of the PC architecture, facilitated by various manufacturers' ability to...
s. Indeed, in using the Toolbox to help boot the machine, a rudimentary Macintosh environment was initialized long before loading the System suitcase
System suitcase
The System suitcase was one of two principal files comprising Mac OS from the original release to System 9.2.2, the other being the Macintosh Finder...
from disk (in fact before ROMs on NuBus cards were executed), which is when the decision to use 24-bit or 32-bit addressing has to be made (hence why the System 7's support for 32-bit addressing requires 32-bit clean ROMs, as older Mac ROMs did not have support for this). The need for a BIOS diagnostics as in the IBM PC compatible
IBM PC compatible
IBM PC compatible computers are those generally similar to the original IBM PC, XT, and AT. Such computers used to be referred to as PC clones, or IBM clones since they almost exactly duplicated all the significant features of the PC architecture, facilitated by various manufacturers' ability to...
s was not widely necessary since Macintosh handled most of its diagnostics in POST and automatically reported errors via the "Sad Mac" codes.
The similarity between the boot-up environment and the actual operating system should not be confused with being identical, however. Although the "Classic Mac OS" boot process is convoluted and largely undocumented, it is not more limited than an IBM PC compatible
IBM PC compatible
IBM PC compatible computers are those generally similar to the original IBM PC, XT, and AT. Such computers used to be referred to as PC clones, or IBM clones since they almost exactly duplicated all the significant features of the PC architecture, facilitated by various manufacturers' ability to...
BIOS. Like a PC's master boot record
Master boot record
A master boot record is a type of boot sector popularized by the IBM Personal Computer. It consists of a sequence of 512 bytes located at the first sector of a data storage device such as a hard disk...
, a ROM-based Mac reads and executes code from the first blocks ("boot blocks") of the disk partition selected as the boot device. The boot blocks then verify that a suitable rudimentary environment exists, and use it to load the System suitcase. A different operating system with a different file system
File system
A file system is a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve and update data, as well as manage the available space on the device which contain it. A file system organizes data in an efficient manner and is tuned to the...
can boot by simply using its own code in the boot blocks. This system was not used for PowerPC Linux, however, because Open Firmware
Open Firmware
Open Firmware, or OpenBoot in Sun Microsystems parlance, is a standard defining the interfaces of a computer firmware system, formerly endorsed by the Institute of Electrical and Electronics Engineers . It originated at Sun, and has been used by Sun, Apple, IBM, and most other non-x86 PCI chipset...
in New World ROM
New World ROM
New World ROM computers are Macintosh models that do not use a Macintosh Toolbox ROM on the logic board. Due to Mac OS X not requiring the availability of the Toolbox, this allowed ROM sizes to shrink dramatically , and facilitated the use of Flash memory for system firmware instead of the now more...
machines requires a bootloader within an HFS filesystem—a reason having nothing to do with the Toolbox or "old-fashioned" Macs in general. More narrowly, the Startup Disk control panel in Mac OS and Mac OS X only allows the user to select a mounted filesystem with very particular constraints.
Legacy
In Mac OS XMac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...
, the Toolbox is not used at all, though the Classic environment
Classic (Mac OS X)
Classic, or Classic Environment, was a hardware and software abstraction layer in Mac OS X that allowed applications compatible with Mac OS 9 to run on the Mac OS X operating system...
loads the Toolbox ROM file into its virtual machine. Much of the Toolbox was restructured and implemented as part of Apple's Carbon programming API, allowing programmers familiar with the Toolbox to port
Porting
In computer science, porting is the process of adapting software so that an executable program can be created for a computing environment that is different from the one for which it was originally designed...
their program code more easily to Mac OS X.