Table Of ContentTHE ANDREW SCHULMANW PROGRAMMING SERIES
A PROGRAMMER'S GUIDE TO I/O, CPUs,
AND FIXED MEMORY AREAS
Includes invaluable diagnostic and
analytical tools and detection
routines on disk
FRANK VAN GILLUWE
rrii
Ine
i i i^^^—M ——————
Undocumented PC
i in i
Frank van Gilluwe
Series Editor
Andrew Schulman
Addison-Wesley Publishing Company
Reading, Massachusetts Mcnlo Park, California New York
Don Mills, Ontario Wokingham, England Amsterdam Bonn
Sydney Singapore Tokyo Madrid San Juan
Paris Seoul Milan Mexico City Taipei
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.
The authors and publishers have taken care in preparation of this book, but make no
expressed or implied warranty of any kind and assume no responsibility for errors or omis-
sions. 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 / Frank van Gilluwe.
p. cm.
Includes index.
ISBN 0-201-62277-7
1. Microcomputers. 2. Electronic data processing documentation.
I. Tide.
QA76.5.V27 1993
004.165-dc20 93-33259
CIP
Copyright © 1994 by Frank van Gilluwe
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.
Managing Editor: Amorette Pedersen
Production Editor: Jennifer A. Noble
Set in 10.5 point Galliard by Benchmark Productions, Inc.
12 3 4 5 6 7 8 9-CRW-9897969594
First Printing, January 1994
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 (617) 944-3700 x2915.
Contents
Acknowledgment viii
Preface ix
Chapter 1 — Introduction 1
Sources oflnformation 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— TheVo Port Monitor TSR 26
UN PC— I/O Port Viewer 29
Chapter 3 — The CPU and Undocumented Instructions 31
Overview 31
Input/Output Basics 32
Input from Port 33
Instruction Timing 38
Timing Problems 38
CPU Modes Relating to I/O 43
Hardware Access Through C and C++ 43
Summary of CPUs 49
Undocumented Instructions 57
Using LOADALI 67
Register Detail 77
Hidden Address Space 82
In-Circuit-Kmulation 90
CPU Reset 91
Chapter 4 — System and Equipment Detection 95
Overview 95
Inircxiuction 96
The Kasy Stuff. 96
Svstem Detection 98
CPU Information 102
Chapter 5 — Adapter Card Development 155
Introduction 155
The ROM Header and Initialization 155
MCA ROM Scan 156
Setting the ROM Size and Starting Address 157
ROM Code 158
Tricks to Getting Necessary RAM 159
Selecting I/O Port Numbers 162
iv THE UNDOCUMENTED PC
Lots of Ports? 163
Disappearing ROM and RAM 165
Switches and Jumpers 165
Chapter 6 — BIOS Data and Other Fixed Data Areas 167
Overview 167
BIOS Data Area 167
Extended BIOS Data Area 201
Display Memory 209
Adapter ROMs and UMB Memory 210
Chapter 7 — Interrupt Vector Table 211
Overview 211
Introduction 211
Interrupt Vectors and Data Descriptions 215
Chapter 8 — The Keyboard System 239
Overview 239
Introduction 240
Basic Operation 240
A Typical Key Press Operation on the AT 241
A Typical Key-Pressed Operation on the PC/XT 243
Controller Communications 243
Keyboard to Motherboard Data 244
Motherboard to Keyboard Data on the AT 246
Keyboard BIOS—Low Level 246
Keyboard BIOS—Intermediate Level 248
Keyboard BIOS Data Areas 257
Hot Keys and Access to Undefined Keys 260
Scan Codes 261
Foreign Keyboards 267
A20 Access to Extended Memory 269
Warnings 273
Keyboard Connection and Signals 274
Port Summary 291
Port Detail . ' 292
Chapter 9 — Video System 313
Overview 313
Introduction 314
Video Adapter Standards 315
BIOS Services 317
Other Interrupts Related to the Video System 391
Relocated Screen Interface Specification (RSIS) 392
How Environments Provide RSIS Support 401
Port Summary 409
Port Detail of Undocumented Video I/O Ports 411
Chapter 10 — Diskette System 415
Overview 415
Introduction 416
Diskette Drive Media Chart 417
Diskette Data Format 418
Diskette Parameter Table 419
BIOS Initialization 422
Diskette BIOS 422
Diskette BIOS Data 431
CONTENTS V
Common Diskette Controller Parts 433
Sending Commands to the Diskette Controller 434
Warnings 435
Port Summary 439
Port Detail .'. 439
Chapter 11 — Hard Disk System 467
Overview 467
Introduetion 468
Will the Real Disk Size Please Stand Up? 470
Interface Standards and Controllers 471
Drive Operations 473
Disk Parameter Table 474
Drive Type Table 475
BIOS Initialization 478
Hard Disk BIOS 478
Disk BIOS Data 504
Sending Commands to the Disk Controller 505
A Typical Read Sector Operation 506
Warnings 511
Port Summary 519
Port Detail . ' 521
Command Detail 528
Chapter 12 — Serial Ports 563
Overview 563
Introduction 563
BIOS Initialization 565
Serial BIOS 566
The Serial Frame 571
Control/Modem Signals 572
Sequence of Events—Serial Transmit 573
Sequence of Events—Serial Receive 573
Loopback Operations 574
Baud Rates 574
Interrupt Control 575
FIFO Mode 577
BIOS Data Areas 578
Debugging 580
UART Part Summary 580
Serial Port Connector 581
Warnings 582
Port Summary 605
UART Register Detail 606
Chapter 13 — System Functions 617
Overview 617
BIOS Services 617
Port Summary 664
Port Detail 665
Chapter 14 — Parallel Ports and Print Screen 701
Overview 701
Introduction 701
BIOS Initialization 703
Can a System Have a Fourth Parallel Port ? 703
Printer BIOS 704
VI THE UNDOCUMENTED PC
Print Screen 706
BIOS Data Areas 707
Parallel Port Timing 708
Parallel Port Connector 709
Fast Parallel Port 710
Warnings 711
Port Summary 719
Port Detail . .' 719
Chapter 15 — CMOS Memory and Real-Time Clock 723
Overview 723
Introduction 723
General Information About the Real Time Clock (R'l'C) 724
Real-Time-Clock BIOS 725
EISA System Differences 729
System Data Areas 736
Extended CMOS Registers 736
Warnings 736
Port Summary 746
Port Detail . .' 746
Chapter 16 — System Timers 777
Overview 777
Introduction 777
Modes of Operation 778
Timer 0—System Timing 782
Timer 1—DRAM Refresh 782
Timer 2—General Use and Speaker 783
Timer 3—Watchdog Timer (MCA Only) 783
Timer 3—Watchdog Timer (EISA Only) 784
Timer 4—Not Implemented (EISA Only) 784
Timer 5—CPU Speed Control (EISA Only) 784
Typical Timer Setup and Operation 785
Typical Uses 785
Access 786
Warnings 786
Port Summary 793
Port Detail . .' 794
Chapter 17 — Interrupt Control and NMI 811
Overview 811
Introduction 811
A Typical Interrupt Occurrence 812
Edge/Level Control 813
NMI—Non-Maskable Interrupt 814
Floating Point Coprocessor and NMI 815
MCA System Differences 816
F^ IS A Sys te m D i tie re nc es 816
Typical Uses 816
Interrupt Data Areas 818
Warnings 818
Port Sum man' 823
Port Detail . ." 823
Chapter 18 — DMA Services and DRAM Refresh 841
Overview 841
Introduction 841
CONTENTS Vli
Confusion Resolved 843
A Typical I/O-to-Memory Transfer 844
Memory-to-Memory DMA 845
Modes of Operation 846
MCA System Differences 847
EISA System Differences 848
Virtual DMA Services (VDS) 851
Typical Uses 853
DMA BIOS Data Areas 853
Warnings 853
Port Summary 856
Port Detail ' 858
Appendix A — Programs on Disk 887
Appendix B — Glossary 893
Appendix C — Bibliography 897
Index 903
Acknowledgment
Reading a technical book of this size is not easy, but I must thank both Andrew Schulman and
Mark Nelson for not only reading the book, but also providing their detailed technical review
and well thought out suggestions. I would also like to thank Handford Choy and David
Miller for reviewing a few key sections of the book and their comments.
Special thanks are due Amy Pedersen, and the staff at both Benchmark Productions and
Addison-Wesley for their work, excellent suggestions, and for accepting a book twice the size
of my original estimate.
On the hardware side, thanks are due Steve Lee for providing hardware used in testing a
wide range of CPUs, and the Center for Software Development, for access to the first Pent-
ium system in our area.
Thanks also go to V Communications for use of their internal menu software, used in
making the UNPC program. Lastly, I need to thank all my family and friends, who have seen
very little of me this last year!
Vlll