ebook img

The Undocumented PC. A Programmer's Guide to I/O, CPUs, and Fixed Memory Areas PDF

1128 Pages·1997·521.097 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview The Undocumented PC. A Programmer's Guide to I/O, CPUs, and Fixed Memory Areas

..a treasure trove of heretofore hard-to-find information about PCs. —PC Magazine THE UNDOCUMENTED PC A Programmer's Guide to I/O, CPUs, and Fixed Memory Areas SECOND EDITION Thoroughly revised and updated ! Undocumented Pentium®, Pentium Pro, and MMX functions Coverage of AMD's 5K86 processor and the new 5x86 and 6x86 CPUs from Cyrix Information on new Windows® 95 keyboard functions diss • Disk includes new and updated diagnostic tools, equipment and CPU detection routines, utilities, and more! rank van pcjs.org The Undocumented PC Second Edition A Programmer's Guide to I/O, CPUs, and Fixed Memory Areas Frank van Gilluwe ▲ TT ADDISON-WESLEY DEVELOPERS PRESS An imprint of Addison Wesley Longman, Inc. Reading, Massachusetts • Harlow, England • Menlo Park, California Berkeley, California • Don Mills, Ontario • Sydney Bonn • Amsterdam • Tokyo • Mexico City pcjs.org Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and Addison-Wesley was aware of a trademark claim, the designations have been printed in initial capital letters or all capital letters. The author and publisher have taken care in preparation of this book, but make no express or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. Library of Congress Cataloging-in-Publication Data Van Gilluwe, Frank. The undocumented PC : a programmer's guide to I/O, CPUs, and fixed memory areas / Frank van Gilluwe. — 2nd ed. p. cm. includes index. ISBN 0-201-47950-8 1. Microcomputers. 2. Electronic data processing documentation. I. Title. QA76.5V27 1997 004.165--dc20 96-33409 CIP Copyright © 1997 by Frank van Gilluwe A-W Developers Press is a division of Addison Wesley Longman, 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, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America. Published simultaneously in Canada. Sponsoring Editor: Kathleen Tibbetts Project Manager: Sarah Weaver Production Coordinator: Erin Sweeney Cover design: Robert Dietz Set in 10-point Galliard by Octal Publishing, Inc. 123456789- CRS- 0099989796 First printing, December 1996 Addison-Wesley books are available for bulk purchases by corporations, institutions, and other organizations. For more information please contact the Corporate, Government, and Special Sales Department at (800) 238-9682. Find A-W Developers Press on the World Wide Web at: http://www.aw.com/devpress/ pcjs.org Contents Acknowledgments ix Preface xi Chapter 1—Introduction 1 Sources of Information 2 System Types 3 Programmer's System Diagram 6 Chapter 2—Exploring the Undocumented PC 7 Introduction 7 Disassembly 9 Disassembling the BIOS 24 IOSPY—The I/O Port Monitor TSR 27 UNPC—I/O Port Viewer 30 Chapter 3—The CPU and Undocumented Instructions 33 Input/Output Basics 34 Input from Port 35 Instruction Timing 40 Timing Problems 41 CPU Modes Relating to I/O 45 Hardware Access Through C and C++ 45 Summary of CPUs 51 Undocumented Instructions 62 Using LOADALL 87 Register Detail 98 Hidden Address Space 115 In-Circuit-Emulation 124 CPU Reset i 124 Chapter 4—System and Equipment Detection 129 The Easy Stuff 130 System Detection 132 Code Sample 4-1. System Detection 132 CPU Information 146 Code Sample 4-2. Processor Identification 148 Code Sample 4-3. Simple Processor Identification 161 Code Sample 4-4. Floating-point Processor Detector 165 Code Sample 4-5. Floating-point Processor Location 167 Code Sample 4-6. Prefetch Queue Size Detector 169 Code Sample 4-7. Processor Version Detector 177 Code Sample 4-8. Processor Mode Detector 188 Code Sample 4-9. Vendor Identification 190 Code Sample 4-10. Measuring CPU Speed 196 pcjs.oIIIrg THE UNDOCUMENTED PC Code Sample 4-11. Processor Cache Detector 202 Code Sample 4-12. Processor Data Cache Size Analysis 205 Code Sample 4-13. Undocumented Instruction Tests 209 Code Sample 4-14. Find New Undocumented Instructions 221 Code Sample 4-15. Find and Display Model Specific Registers 222 Code Sample 4-16. Display Time Stamp Counter 224 Chapter 5—Adapter Card Development 225 The ROM Header and Initialization 225 MCA ROM Scan 226 Setting the ROM Size and Starting Address 227 ROM Code 228 Tricks to Getting Necessary RAM 229 Selecting I/O Port Numbers 232 Lots of Ports? 233 Disappearing ROM and RAM 234 Switches and lumpers 235 Plug and Play 235 Chapter 6—BIOS Data and Other Fixed Data Areas 237 BIOS Data Area 237 Extended BIOS Data Area 271 Display Memory 278 Adapter ROMs and UMB Memory 279 Chapter 7—Interrupt Vector Table 281 Interrupt Vectors and Data Descriptions 285 Chapter 8—The Keyboard System 309 Introduction 310 Basic Operation 310 A Typical Key Press Operation on the AT 311 A Typical Key-Pressed Operation on the PC/XT 313 Controller Communications 313 Keyboard to Motherboard Data 314 Motherboard to Keyboard Data on the AT 316 Keyboard BIOS—Low Level 316 Keyboard BIOS—Intermediate Level 318 Keyboard BIOS Data Areas 328 Hot Keys and Access to Undefined Keys 331 Scan Codes 332 Foreign Keyboards 337 A20 Access to Extended Memory 340 Code Sample 8-1. Get the Current A20 Status 341 Code Sample 8-2. A20 Control 343 Warnings 345 Keyboard Connection and Signals 346 Code Sample 8-3. Controller Access 347 Code Sample 8-4. System Reset 354 Code Sample 8-5. View Scan and Kscan Codes 355 Code Sample 8-6. Swap Keys TSR 362 Code Sample 8-7. Functionality Detect 366 Port Summary 369 Port Detail . 370 pcjs.org CONTENTS Chapter 9—Video System 391 Introduction 392 Video Adapter Standards 392 BIOS Services 395 Other Interrupts Related to the Video System 467 Relocated Screen Interface Specification (RSIS) 467 Code Sample 9-1. Getting the Relocated Screen Address, C Code 470 Code Sample 9-2. Getting the Relocated Screen Address, Assembly Code 471 Code Sample 9-3. Writing to Display Memory 475 How Environments Provide RSIS Support 477 Code Sample 9-4. Detecting the Video Adapter 478 Port Summary 485 Port Detail of Undocumented Video I/O Ports 487 Chapter 10—Diskette System 491 Introduction 492 Diskette Drive Media Chart 493 Diskette Data Format 494 Diskette Parameter Table 495 BIOS Initialization 498 Diskette BIOS 498 Diskette BIOS Data 507 Common Diskette Controller Parts 511 Sending Commands to the Diskette Controller 511 Warnings 512 Code Sample 10-1. Diskette Drive Detection 514 Port Summary 517 Port Detail 517 Chapter 11—Hard Disk System 549 Introduction 550 Will the Real Disk Size Please Stand Up? 552 Interface Standards and Controllers 554 Drive Operations 556 Large IDE Drives 557 Disk Parameter Table 557 Drive Type Table 560 BIOS Initialization 563 Hard Disk BIOS 563 Disk BIOS Data 606 Sending Commands to the Disk Controller 608 A Typical Read Sector Operation 608 Warnings 613 Code Sample 11-1. Disk Drive Detection 613 Code Sample 11-2. Interrupt 13h Disk Read Test 622 Port Summary 623 Port Detail 625 Command Detail 637 Chapter 12—Serial Ports 685 Introduction 685 BIOS Initialization 687 pcjs.org THE UNDOCUMENTED PC Serial BIOS 688 The Serial Frame 694 Control/Modem Signals 694 Sequence of Events—Serial Transmit 695 Sequence of Events—Serial Receive 696 Loopback Operations 697 Baud Rates 697 Interrupt Control 698 FIFO Mode 700 BIOS Data Areas 702 Debugging 703 UART Part Summary 704 Serial Port Connector 704 Warnings 705 Code Sample 12-1. Slow Baud Rate for Debugging 707 Code Sample 12-2. Serial Port Detector 708 Code Sample 12-3. Maximum Baud Rate Analyzer 716 Port Summary 732 UART Register Detail 733 Chapter 13—System Functions 745 BIOS Services 745 Port Summary 800 Port Detail 801 Chapter 14—Parallel Ports and Print Screen 841 Introduction 841 BIOS Initialization 843 Can a System Have a Fourth Parallel Port? 843 Printer BIOS 844 Print Screen 846 BIOS Data Areas 847 Parallel Port Timing 849 Parallel Port Connector 850 Fast Parallel Port 851 Warnings 852 Code Sample 14-1. Print ASCII Only 853 Code Sample 14-2. Swap Printers 856 Code Sample 14-3. Extended Mode Support Detect 858 Port Summary 862 Port Detail 863 Chapter 15—CMOS Memory and Real-Time Clock 867 Introduction 868 General Information About the Real-Time Clock (RTC) 868 Real-Time Clock BIOS 869 EISA System Differences 874 System Data Areas 881 Extended CMOS Registers 882 Warnings 882 Code Sample 15-1. Read CMOS 883 Code Sample 15-2. Write CMOS 884 Code Sample 15-3. Display AT CMOS 885 pcjs.org CONTENTS Code Sample 15-4. Display Extended MCA CMOS \ 888 Code Sample 15-5. Display Extended EISA CMOS 890 Port Summary 892 Port Detail 892 Chapter 16—System Timers 953 Introduction 953 Modes of Operation 954 Timer 0—System Timing 960 Timer 1—DRAM Refresh 961 Timer 2—General Use and Speaker 961 Timer 3—Watchdog Timer (MCA Only) 961 Timer 3—Watchdog Timer (EISA Only) 962 Timer 4—Not Implemented (EISA Only) 963 Timer 5—CPU Speed Control (EISA Only) i 963 Typical Timer Setup and Operation 963 Typical Uses 964 Access 964 Warnings 965 Code Sample 16-1. Precise Event Timing 965 Code Sample 16-2. Timer 0 Mode 968 Code Sample 16-3. Fast Interrupt Handler 972 Port Summary 978 Port Detail 978 Chapter 17—Interrupt Control and NMI 999 Introduction 999 A Typical Interrupt Occurrence 1000 Edge/Level Control 1002 NMI—Non-Maskable Interrupt 1002 Floating Point Coprocessor and NMI 1003 MCA System Differences 1004 EISA System Differences 1004 PCI System Differences 1005 Typical Uses 1005 Interrupt Data Areas 1007 Warnings 1007 Code Sample 17-1. IRQ Redirection 1009 Port Summary 1012 Port Detail 1013 Chapter 18—DMA Services and DRAM Refresh 1033 Introduction 1033 Confusion Resolved 1036 A Typical I/O-to-Memory Transfer 1036 Memory-to-Memory DMA 1038 Modes of Operation 1039 MCA System Differences 1040 EISA System Differences 1040 Virtual DMA Services (VDS) 1044 Typical Uses 1046 DMA BIOS Data Areas 1046 pcjs.org THE UNDOCUMENTED PC Warnings 1047 Code Sample 18-1. DMA Transfer Setup 1048 Port Summary 1050 Port Detail 1052 Appendix A—Programs on Disk 1085 Appendix B—Glossary 1091 Appendix C—Bibliography 1097 Index 1105 pcjs.org Acknowledgments Thanks go to Michael Schmit for reviewing this new edition and providing excellent feedback, corrections, and technical review. Thanks are also due to the many readers who took time to contact me and offer suggestions and ideas for this edition. This includes Bob Meister, who provided a detailed review of the first edition. Thanks also go to Andrew Schulman and Mark Nelson, who were invaluable in providing their detailed technical review and suggestions for the first edition. Special thanks are due Kathleen Tibbetts and the staff at Addison-Wesley for their work, excellent suggestions, and again accepting a book much larger than my original estimates. Thanks to V Communications for equipment use, and the use of their internal menu soft ware, used in making the UNPC program. Lastly, I need to thank all my family and friends for their continued support. IX pcjs.org

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.