Mac OS X Internals: A Systems Approach

4.1. Introduction

As we saw in Chapter 3, a representative computer system consists of a main logic board (or the motherboard), one or more CPUs, busses, memory, storage devices, and so on. The computer's operating system resides on a storage device that is either locally attached or is accessible over a network connection. The operating system must somehow be loaded into memory as the computer boots. In the most commonly used approach, the master CPU[2] has access to some read-only memory (ROM) from which it executes an initial piece of code. This code is commonly called the Basic Input/Output System (BIOS), particularly in the context of x86-based computers. Modern BIOSs usually reside in programmable read-only memory (PROM) or one of its variants, such as flash memory, to allow easy upgrades. This "software embedded in hardware" represents a middle ground between hardware and software and is therefore called firmware. A typical BIOS is also firmware, but not every piece of firmware is considered a BIOS. The BIOS's analog is called Open Firmware on modern PowerPC-based Apple computers and Extensible Firmware Interface (EFI) on x86-based Apple computers. It must be noted that the roles and capabilities of both Open Firmware and EFI far exceed those of a typical PC BIOS.

[2] In a multiprocessor system, one CPU is usually designated as a master (or main) CPU using some platform-specific algorithm.

The PC BIOS is as old as the PC itself, whereas the acronym BIOS is even older, dating back to the CP/M operating system. BIOS was one of the three primary components of CP/M, the other two being BDOS (Basic Disk Operating System) and CCP (Console Command Processor).

In a typical booting scenario, after the system is powered on, the CPU, or the designated master CPU in a multiprocessor system, finds and executes firmware-resident code. The firmware performs a power-on self-test (POST), which is a series of initialization and testing routines for various hardware components. The firmware then loads a bootloader, a program that can load a more complex program such as an operating system or perhaps the next-stage bootloader in what could be a multistage bootloading mechanism. A bootloader may provide a user interface for selecting one of many operating systems to boot and may also prompt for arguments to be passed to the selected operating system.

4.1.1. Varieties of Firmware

Specific firmware implementations may differ fromor may have details in addition tothe generic discussion so far. In most cases, a platform-dependent entity, such as an even lower-level firmware than the BIOS or Open Firmware, may be the very first stored program to gain control of the machine. This firmware may perform some fundamental initialization and tests before passing control to the main user-visible firmware, which is often called the CPU or system firmware. Installed hardware cards such as SCSI, network, and video adapter cards may contain their own firmware in their own ROMs. During boot, the main firmware passes control to these ancillary firmware modules.

In this chapter, we will discuss only user-visible firmware, which, for the sake of simplicity, may be visualized as sitting directly atop the hardware. Typically, both the bootloader and the operating system interact with the firmware. Moreover, we will use the term firmware by itself generically, to denote a BIOS, Open Firmware, EFI, or any other variant.

Note that although modern operating systems typically do not use the BIOS once they finish booting, older systems such as MS-DOS and CP/M made heavy use of BIOS services for implementing large parts of their functionality.

Entire operating systems may also reside in firmware, as is the case with many embedded systems that use a PROM as a boot device. It is even possibleand arguably usefulto use a conventional operating system as a computer's firmware. The LinuxBIOS project is one such example.

4.1.2. Preferential Storage

User-configurable settings that are referenced during boot by the BIOSand in some cases by the operating systemare stored in a low-power, battery-backed memory such as a CMOS-based device. A reserved area on a disk drive may also be used to store such settings.

Modern Apple computers have a power management unit (PMU), a microcontroller chip that controls the power consumption behavior of various devices. Still newer models have a more advanced system management unit (SMU) instead of the PMU. The SMU also is an onboard microcontroller that controls the computer's power functions.

The PMU takes care of spinning down hard disks and adjusting the backlight. It handles the machine's sleep, wake-up, idle, turn-on, and turn-off behaviors, including deciding when not to put the machine to sleepfor example, in the case of an active modem connection. The PMU also manages the onboard real-time clock and maintains the parameter memory (PRAM). The SMU performs many similar functions. Apple's SMU-related kernel extensions (such as AppleSMU.kext, AppleSMUMonitor.kext, and IOI2CControllerSMU.kext) provide internal APIs for accessing battery information, controlling fans, managing date and time, controlling the power supply, maintaining the PRAM, and so on.

The PRAM is a battery-backed memory used to store miscellaneous system configuration information such as startup chime volume, time zone, speaker volume, DVD region setting, and the text corresponding to a kernel panic. The PRAM's exact contents depend on the specific computer system and its configuration. On a system running Mac OS X, less information is stored in the PRAM as compared to the same computer running an earlier Apple operating system. The Mac OS X kernel accesses PRAM contents through the Platform Expert.

The Reset Set

The PMU and the SMU can be reset in a model-dependent manner. For example, whereas a notebook computer model may allow you to reset the PMU using a combination of the power button and one or more keys, a Power Mac model may require a button to be pressed on the logic board. The SMU on certain models can be reset by simply unplugging the power for a few seconds.

Note that resetting the PMU or the SMU does not reset the PRAM. You can reset a computer's PRAM by pressing and holding the key combination as you turn the computer on. You must press the keys before the gray screen appears and must keep them pressed until the computer restarts and you hear the startup chime for the second time.

Open Firmware uses another nonvolatile memorythe NVRAMfor storing its user-configurable variables and some other startup information. The NVRAM is accessed by Open Firmware during system startup. EFI similarly uses and accesses its own NVRAM. A typical NVRAM is based on flash memory.

Категории