← Inside Macintosh: PowerPC System Software

Inside Macintosh: PowerPC System Software

From the originals

13 scans

Machine-transcribed text and image descriptions. Check the linked original for uncertain words or fine print.

These are transcribed pages from the documents, not the full publications. Open the original for the remaining pages.

Image 1

INSIDE MACINTOSH PowerPC System Software Addison-Wesley Publishing Company Reading, Massachusetts Menlo Park, California New York Don Mills, Ontario Wokingham, England Amsterdam Bonn Sydney Singapore Tokyo Madrid San Juan Paris Seoul Milan Mexico City Taipei

A plain white book title page with a black Apple logo at top, the title INSIDE MACINTOSH in spaced capitals, a horizontal rule, the subtitle PowerPC System Software, and a publisher's logo with city list at the bottom.

Reading notes: Publisher city list is in small type and read left to right by line; no date is printed on the page.

Languages
English
PDF page 1

Addison-Wesley Publishing Company Reading, Massachusetts Menlo Park, California New York Don Mills, Ontario Wokingham, England Amsterdam Bonn Sydney Singapore Tokyo Madrid San Juan Paris Seoul Milan Mexico City Taipei I N S I D E M A C I N T O S H PowerPC System Software

Reading notes: No image was provided, so visual layout, typography, and reading order are inferred from the supplied copy only. Title is printed with letter spacing as 'I N S I D E M A C I N T O S H'; the headline field normalizes it to 'INSIDE MACINTOSH'. Publisher office locations are listed in the supplied copy but are not advertised products, prices, or dates, so they are excluded from the product and date fields.

Printed product names
PowerPC System Software
Languages
English
PDF page 2

Apple Computer, Inc. © 1994 Apple Computer, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, mechanical, electronic, photocopying, recording, or otherwise, without prior written permission of Apple Computer, Inc. Printed in the United States of America. No licenses, express or implied, are granted with respect to any of the technology described in this book. Apple retains all intellectual property rights associated with the technology described in this book. This book is intended to assist application developers to develop applications only for Apple Macintosh computers. Every effort has been made to ensure that the information in this manual is accurate. Apple is not responsible for printing or clerical errors. Apple Computer, Inc. 20525 Mariani Avenue Cupertino, CA 95014 408-996-1010 Apple, the Apple logo, APDA, AppleLink, AppleShare, A/UX, HyperCard, LaserWriter, Macintosh, Macintosh Quadra, MPW, PowerBook, and SANE are trademarks of Apple Computer, Inc., registered in the United States and other countries. Finder, Macintosh Centris, QuickDraw, and QuickTime are trademarks of Apple Computer, Inc. Adobe Illustrator and PostScript are trademarks of Adobe Systems Incorporated, which may be registered in certain jurisdictions. America Online is a service mark of Quantum Computer Services, Inc. Classic is a registered trademark licensed to Apple Computer, Inc. CompuServe is a registered service mark of CompuServe, Inc. FrameMaker is a registered trademark of Frame Technology Corporation. Helvetica and Palatino are registered trademarks of Linotype Company. Internet is a trademark of Digital Equipment Corporation. ITC Zapf Dingbats is a registered trademark of International Typeface Corporation. Motorola is a registered trademark of Motorola Corporation. Optrotech is a trademark of Orbotech Corporation. PowerPC is a trademark of International Business Machines Corporation. THINK C is a trademark of Symantec Corporation. UNIX is a registered trademark of UNIX System Laboratories, Inc. Simultaneously published in the United States and Canada. LIMITED WARRANTY ON MEDIA AND REPLACEMENT ALL IMPLIED WARRANTIES ON THIS MANUAL, INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE LIMITED IN DURATION TO NINETY (90) DAYS FROM THE DATE OF THE ORIGINAL RETAIL PURCHASE OF THIS PRODUCT. Even though Apple has reviewed this manual, APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS MANUAL, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. AS A RESULT, THIS MANUAL IS SOLD “AS IS,” AND YOU, THE PURCHASER, ARE ASSUMING THE ENTIRE RISK AS TO ITS QUALITY AND ACCURACY. IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES RESULTING FROM ANY DEFECT OR INACCURACY IN THIS MANUAL, even if advised of the possibility of such damages. THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer, agent, or employee is authorized to make any modification, extension, or addition to this warranty. Some states do not allow the exclusion or limitation of implied warranties or liability for incidental or consequential damages, so the above limitation or exclusion may not apply to you. This warranty gives you specific legal rights, and you may also have other rights which vary from state to state. ISBN 0-201-40727-2 1 2 3 4 5 6 7 8 9-CRW-9897969594 First Printing, February 1994 Library of Congress Cataloging-in-Publication Data Inside Macintosh. PowerPC system software / Apple Computer, Inc. p. cm. Includes index. ISBN 0-201-40727-2 1. Macintosh (Computer) 2. PowerPC (Microprocessor) 3. Systems software. I. Title: PowerPC system software. QA76.8.M3I528 1994 005.4'469—dc20 93-50182 CIP

Reading notes: The supplied copy appears to be a manual copyright page, not an advertisement, so no advertised products or prices were identified. Trademarked names such as Macintosh, HyperCard and PowerPC are listed in the copyright text as trademarks rather than as advertised products, so productNames is empty. Transcript is intentionally empty per instructions because the exact extracted text is preserved separately. Printed dates were taken only from the copyright line, the First Printing line and the Library of Congress cataloguing line; catalogue and printing code numbers were not treated as dates. Layout and reading order cannot be verified from the image because the fields were filled from the supplied extracted copy alone.

Printed dates
© 1994 · QA76.8.M3I528 1994 · First Printing, February 1994
Languages
English
PDF page 3

iii Contents Figures, Tables, and Listings vii Preface About This Book ix Related Documentation xi Format of a Typical Chapter xi Conventions Used in This Book xii Special Fonts xii Types of Notes xii Bit Numbering and Word Size xii Assembly-Language Information xiv Development Environment xiv For More Information xv Chapter 1 Introduction to PowerPC System Software 1-1 Overview of the PowerPC System Software 1-4 The 68LC040 Emulator 1-6 Emulator Operation 1-7 Emulator Limitations 1-8 Coprocessors 1-9 Instruction Timings 1-9 Deleted Instructions 1-9 Unsupported Instruction Features 1-10 Instruction Caches 1-10 Address Error Exceptions 1-10 Bus Error Exceptions 1-11 Memory-Mapped I/O Locations 1-11 Mixed Mode 1-13 Cross-Mode Calls 1-14 Routine Descriptors 1-15 Memory Considerations 1-19 The PowerPC Native Environment 1-19 Fragments 1-20 The Structure of Fragments 1-22 Imports and Exports 1-23 The Table of Contents 1-26 Special Routines 1-29 Fragment Storage 1-30 Executable Resources 1-34

Languages
English
PDF page 4

iv Calling Conventions 1-41 The 680x0 Calling Conventions 1-42 The PowerPC Calling Conventions 1-43 Parameter Passing 1-47 Import Libraries 1-50 The Organization of Memory 1-52 File Mapping 1-53 The System Partition 1-56 Application Partitions 1-57 Data Alignment 1-63 Compatibility and Performance 1-65 Patches 1-66 The Memory Manager 1-68 Performance Tuning 1-70 Mode Switches 1-71 Routine Parameters 1-72 Chapter 2 Mixed Mode Manager 2-1 About the Mixed Mode Manager 2-4 External Code 2-4 Procedure Pointers 2-5 Mode Switches 2-7 Calling PowerPC Code From 680x0 Code 2-8 Calling 680x0 Code From PowerPC Code 2-12 Using the Mixed Mode Manager 2-14 Specifying Procedure Information 2-14 Using Universal Procedure Pointers 2-21 Using Static Routine Descriptors 2-22 Executing Resource-Based Code 2-24 Mixed Mode Manager Reference 2-26 Constants 2-27 Routine Descriptor Flags 2-27 Procedure Information 2-27 Routine Flags 2-34 Instruction Set Architectures 2-35 Data Structures 2-36 Routine Records 2-36 Routine Descriptors 2-37 Mixed Mode Manager Routines 2-38 Creating and Disposing of Routine Descriptors 2-39 Calling Routines via Universal Procedure Pointers 2-42 Determining Instruction Set Architectures 2-44

Reading notes: Source is a table of contents excerpt with no headline or advertised content Page numbers appear as section locators rather than dates

Languages
English
PDF page 5

v Summary of the Mixed Mode Manager 2-45 C Summary 2-45 Constants 2-45 Data Types 2-48 Mixed Mode Manager Routines 2-49 Chapter 3 Code Fragment Manager 3-1 About the Code Fragment Manager 3-3 Fragments 3-4 Import Library Searching 3-5 Version Checking 3-7 Using the Code Fragment Manager 3-10 Loading Code Fragments 3-10 Creating a Code Fragment Resource 3-12 Getting Information About Exported Symbols 3-14 Code Fragment Manager Reference 3-15 Data Structures 3-15 Fragment Initialization Block 3-15 Fragment Location Record 3-16 Memory Location Record 3-17 Disk Location Record 3-17 Segment Location Record 3-18 Code Fragment Manager Routines 3-18 Loading Fragments 3-19 Unloading Fragments 3-23 Finding Symbols 3-24 Fragment-Defined Routines 3-26 Resources 3-28 The Code Fragment Resource 3-28 Summary of the Code Fragment Manager 3-32 C Summary 3-32 Constants 3-32 Data Types 3-33 Code Fragment Manager Routines 3-34 Fragment-Defined Routines 3-35 Result Codes 3-35 Chapter 4 Exception Manager 4-1 About the Exception Manager 4-3 Exception Contexts 4-4 Types of Exceptions 4-5

Reading notes: Source appears to be a table of contents rather than advertising copy; no headline or product or price information is present.

Languages
English
PDF page 6

vi Using the Exception Manager 4-6 Installing an Exception Handler 4-6 Writing an Exception Handler 4-7 Exception Manager Reference 4-9 Constants 4-9 Exception Kinds 4-9 Memory Reference Kinds 4-11 Data Structures 4-12 Machine Information Records 4-12 Register Information Records 4-12 Floating-Point Information Records 4-14 Memory Exception Records 4-15 Exception Information Records 4-16 Exception Manager Routines 4-17 Application-Defined Routines 4-17 Summary of the Exception Manager 4-19 C Summary 4-19 Constants 4-19 Data Types 4-19 Exception Manager Routines 4-22 Application-Defined Routines 4-22 Glossary GL-1 Index IN-1

Languages
English
PDF page 7

vii Figures, Tables, and Listings Preface About This Book ix Figure P-1 680x0 bit numbering xiii Figure P-2 PowerPC bit numbering xiii Table P-1 Sizes of memory operands xiii Chapter 1 Introduction to PowerPC System Software 1-1 Figure 1-1 The system software for PowerPC processor-based Macintosh computers 1-5 Figure 1-2 Creating imports in a fragment 1-24 Figure 1-3 A transition vector 1-27 Figure 1-4 The structure of a PowerPC application 1-31 Figure 1-5 The structure of a 680x0 application 1-32 Figure 1-6 The structure of a fat application 1-33 Figure 1-7 The structure of an accelerated resource 1-35 Figure 1-8 The structure of a private resource 1-36 Figure 1-9 A 680x0 stack frame 1-42 Figure 1-10 The PowerPC stack 1-44 Figure 1-11 The structure of a stack frame’s linkage area 1-45 Figure 1-12 The Red Zone 1-46 Figure 1-13 The organization of the parameter area on the stack 1-49 Figure 1-14 Organization of memory when virtual memory is enabled 1-54 Figure 1-15 Organization of memory when virtual memory is not enabled 1-56 Figure 1-16 The structure of a PowerPC application partition 1-60 Figure 1-17 The Memory control panel for PowerPC processor-based Macintosh computers 1-69 Listing 1-1 Creating a routine descriptor 1-17 Listing 1-2 The definition of the NewControlActionProc routine 1-18 Listing 1-3 Creating a routine descriptor for a control action procedure 1-19 Listing 1-4 Testing for unresolved soft imports 1-25 Listing 1-5 The Rez input for a sample 'cfrg' resource 1-32 Listing 1-6 Rez input for a list definition procedure stub 1-35 Listing 1-7 Using an accelerated resource 1-37 Listing 1-8 Some acceptable global declarations in an accelerated resource 1-39 Listing 1-9 Some unacceptable global declarations and code in an accelerated resource 1-39 Listing 1-10 Using a private resource 1-40 Listing 1-11 Declaring an application’s QuickDraw global variables 1-59 Listing 1-12 A sample 680x0 VBL task definition 1-61 Listing 1-13 A conditionalized VBL task definition 1-62 Listing 1-14 Patching an Operating System trap 1-67 Listing 1-15 Waiting to call the WaitNextEvent function 1-72

Reading notes: Source is a table of contents listing figures, tables, and listings; no primary heading is clearly printed. Some figure and listing titles contain typographic apostrophes and quotation marks that may not be reliably reproduced.

Languages
English
PDF page 8

viii Chapter 2 Mixed Mode Manager 2-1 Figure 2-1 680x0 and PowerPC procedure pointers 2-5 Figure 2-2 Calling PowerPC code from a 680x0 application 2-9 Figure 2-3 The stack before a mode switch 2-10 Figure 2-4 A 680x0-to-PowerPC switch frame 2-11 Figure 2-5 A PowerPC-to-680x0 switch frame 2-13 Figure 2-6 Procedure information for a stack-based routine 2-17 Figure 2-7 Procedure information for a register-based routine 2-19 Figure 2-8 General structure of an executable code resource 2-25 Figure 2-9 General structure of a fat resource 2-26 Table 2-1 Limits on the number of specifiable parameters in a procedure information 2-20 Listing 2-1 Sample glue code for a 680x0 routine 2-12 Listing 2-2 Creating global routine descriptors 2-21 Listing 2-3 Creating local routine descriptors 2-22 Listing 2-4 Creating static routine descriptors 2-23 Listing 2-5 Building a static routine descriptor 2-23 Chapter 3 Code Fragment Manager 3-1 Figure 3-1 Structure of a compiled code fragment ( 'cfrg' ) resource 3-29 Figure 3-2 The format of a code fragment information record 3-30 Listing 3-1 Pseudocode for the version-checking algorithm 3-9 Listing 3-2 Loading a resource-based fragment 3-11 Listing 3-3 Loading a disk-based fragment 3-11 Listing 3-4 The Rez input for a typical application’s 'cfrg' resource 3-12 Listing 3-5 The Rez input for a typical import library’s 'cfrg' resource 3-13 Listing 3-6 Finding symbol names 3-14 Chapter 4 Exception Manager 4-1 Listing 4-1 Installing an exception handler 4-6 Listing 4-2 A native exception handler 4-8

Languages
English
PDF page 9

ix P R E F A C E About This Book This book, Inside Macintosh: PowerPC System Software, describes the new process execution environment and system software services provided with the first version of the system software for Macintosh on PowerPC computers. It contains information you need to know to write applications and other software that can run on PowerPC processor-based Macintosh computers. The first release of the system software for Macintosh on PowerPC computers provides a mixed or hybrid environment: the system software provides the ability to execute both applications that use the native instruction set of the PowerPC microprocessor and applications that use the 680x0 instruction set. It accomplishes this by providing a very efficient 68LC040 Emulator that emulates 680x0 instructions with PowerPC instructions. As a result, virtually all existing 680x0-based Macintosh applications and other software modules that conform to the programming interfaces and techniques documented in the Inside Macintosh suite of books will execute without modification on PowerPC processor-based Macintosh computers. To take maximum advantage of the much greater processing speed of the PowerPC microprocessor, however, you’ll need to recompile your application’s source code into a PowerPC application. Apple Computer, Inc., provides MPW-based C and C++ compilers and other tools that you can use to create native PowerPC applications. In general, if your source code is already compliant with ANSI C standards or the de facto ANSI C++ standards, you should be able, with moderately little effort, to rework your source code so that it can be compiled and built using the Apple-supplied tools into a PowerPC application. This book is intended to provide much of the information you need to port your existing 680x0 application (or other software) to the PowerPC platform. Note There will also be third-party compilers and development environments capable of generating PowerPC code. u Although the native run-time execution environment of the first version of the system software for PowerPC processor-based Macintosh computers is significantly different from the execution environment of current 680x0-based Macintosh computers, you won’t need to worry about those differences unless your existing code relies on specific information about the 680x0 execution environment. For example, if for some reason you directly access information in your application’s A5 world, you’ll need to rewrite those parts of code when porting your application to the PowerPC environment. Similarly, you’ll need to rewrite any parts of your code that depend on data being passed in certain 680x0 registers. VBL tasks, for instance, very

Reading notes: Source text ends mid-sentence at 'VBL tasks, for instance, very' Page header 'ix' and 'P R E F A C E' spacing is irregular

Printed product names
Inside Macintosh: PowerPC System Software · 68LC040 Emulator · Apple Computer, Inc. · MPW-based C and C++ compilers · ANSI C · ANSI C++
Languages
English
PDF page 10

x P R E F A C E often depend on the fact that a pointer to the VBL task record is passed in register A0. The first chapter in this book, “Introduction to PowerPC System Software,” provides a general overview of the system software that runs on PowerPC processor-based Macintosh computers. It also describes in detail the mixed environment provided by the 68LC040 Emulator and the Mixed Mode Manager, as well as the new run-time environment used for native PowerPC applications. You should read this chapter for general information about porting your existing software to the PowerPC environment. Even if you do not intend to port your existing 680x0 software, you might still want to read this chapter for information about running under the 68LC040 Emulator. The remaining chapters in this book provide reference material for the three new system software managers introduced in the first version of the system software for PowerPC processor-based Macintosh computers. You should read these chapters for specific information on using the services provided by those managers. The new system software managers are n the Mixed Mode Manager, which manages the mixed environment of PowerPC processor-based Macintosh computers running 680x0-based code n the Code Fragment Manager, which loads fragments (blocks of executable PowerPC code and their associated data) into memory and prepares them for execution n the Exception Manager, which handles exceptions that occur during the execution of PowerPC applications or other software IMPORTANT Some of the system software services introduced in the first version of the system software for PowerPC processor-based Macintosh computers might in the future be available on Macintosh computers that are not based on the PowerPC microprocessor. For example, it’s possible that the Code Fragment Manager (and the entire run-time environment based on fragments) will be included in future versions of the system software for 680x0-based Macintosh computers. As a result, some of the information in this book might eventually be more generally applicable than the title of this book might suggest. s If you are new to programming for Macintosh computers, you should read the book Inside Macintosh: Overview for an introduction to general concepts of Macintosh programming. You should also read other books in the Inside Macintosh series for specific information about other aspects of the Macintosh Toolbox and the Macintosh Operating System. In particular, to benefit most from this book, you should already be familiar with the run-time environment of 680x0 applications, as described in the two books Inside Macintosh: Processes and Inside Macintosh: Memory .

Reading notes: Text begins mid-sentence and a stray character 's' appears after the IMPORTANT note, suggesting possible reading-order or damage artifacts.

Printed product names
Inside Macintosh: Overview · Inside Macintosh: Processes · Inside Macintosh: Memory
Languages
English
PDF page 11

xi P R E F A C E Related Documentation This book is part of a larger suite of books that contain information essential for developing PowerPC applications and other software. n For information about the PPCC compiler that you can use to compile your source code into a PowerPC application, see the book C/C++ Compiler for Macintosh With PowerPC . n For information about the PPCAsm assembler, see the book Assembler for Macintosh With PowerPC . n For information about debugging and measuring the performance of PowerPC applications, see the book Macintosh Debugger Reference . n For information about performing floating-point calculations in PowerPC applications, see the book Inside Macintosh: PowerPC Numerics . n For information about building PowerPC applications and other kinds of PowerPC software for Macintosh computers, see Building Programs for Macintosh With PowerPC . Format of a Typical Chapter Almost all chapters in this book follow a standard structure. For example, the chapter “Mixed Mode Manager” contains these sections: n “About the Mixed Mode Manager.” This section describes the Mixed Mode Manager. You should read this section for a general understanding of what the Mixed Mode Manager does and when you might need to call it explicitly. n “Using the Mixed Mode Manager.” This section provides detailed instruc- tions on using the Mixed Mode Manager. You should read this section if you need to use the services provided by the Mixed Mode Manager. n “Mixed Mode Manager Reference.” This section provides a complete reference to the constants, data structures, and routines provided by the Mixed Mode Manager. Each routine description also follows a standard format, which presents the routine declaration followed by a description of every parameter of the routine. Some routine descriptions also give additional descriptive information, such as circumstances under which you cannot call the routine or result codes. n “Summary of the Mixed Mode Manager.” This section provides the C interfaces for the constants, data structures, routines, and result codes associated with the Mixed Mode Manager.

Reading notes: Preface section heading appears as 'P R E F A C E' with letter spacing, possibly a layout artifact

Printed product names
PPCC · PPCAsm · Inside Macintosh: PowerPC Numerics · Macintosh Debugger Reference · C/C++ Compiler for Macintosh With PowerPC · Assembler for Macintosh With PowerPC · Building Programs for Macintosh With PowerPC
Languages
English