Mp/M JIT.I. Operating System SYSTEM IMPLEMENTOR'S GUIDE Copyright @ 1981 Digital Research P.O. Box 579 801 Lighthouse Avenue Pacific Grove, CA 93950 (408) 6410-3896 TWX 910 360 5001 All Rights Reserved COPYRIGHT Copyright @ 1981 by Digital Research. All rights reserved. No part of this publication may be reproduced, transmitted, transcribed, storcd in a retrieval system, or translated into Fny language or computer LF.nguage, in any form or by any means, electronic, mechanical, magnetic, optical, chemical, manual or otherwise, without the prior written per-mission of Digital Research, Post Officc Box 579, Pacific Grove, CaliforniE-., 93950. DISCLAIMER Digital Research makes no r~.presentations or warranties with respect to the contents herLof and specifically disclaims any implied warr&ntics of merchantability or fitness for- any pzirticular purpose. Further, Digital Research reserves the right to revise this publication and to make changes from time to time in the contGnt hereof without obligation of Digitz~l Research to notify any person of such revision or clicnges. TRADEMARKS CP/M is a registered trademark of Digital Research. CP/NET, MP/M II, LINK-80, RMAC and PL/I-80 are trademarks of Digital Research. Z80 is a registered tr~demark of Zilog, Inc. The "MP/M Il SYSTEM GUIDE" was prepared using the Digital Research TEX-80 Text Formatter and printed in the United States of America by Commercial Press Monterey. First Printing: Septembcr 1981 FOREWORD MP/M Ii". is a. multi-user operating system for any microcomputer based on an 8-bit Zilog Z000 or Intel 8080 or 3085 microprocessor. Typically, an MP/M 1 7 system resides in approximately 27k. 16k of the operating system must reside in common memory. The version of NIP/M II that Digital Research ships cannot be directly booted on any specific hardware configuration. However, all the hardwEre-dependent code is isolated in specific subroutines that can be modified by the user. This document describes the procedures required to implement MP/M I! for a custom hardware environment. At minimum, the custom hardware environment must include an 8080, 8085, or Z-80 processor, 32K bytes of random access memory (RAM), a system console, and a real-time clock. This manual assumes the reader is familiar with the following Digital Rcsearch publications: • MP/M II UsE.i's Guide • MP/M II Programmer's Guide it is also assumed that the reader has &lready implemented a CP/M 2 Basic Input Output System (BIOS), preferrably on the tE,.rget MP/M 11 machine. i i i TABLE OF CONTENTS MP/M II Alteration Procedure 1.1 Preparation for MP/M II Alteration 1.2 Customizing the MPMLDR . . . 1.3 Customizing the XIOS . . . . 1.4 Debugging &n XIOS . . . . . . . . . . . . . . . . 4 1.5 Directly Booting MP/M II . . . . . . ... . . o . 6 1.5.1 Pieparing an MP/M II Boot Using SYSGEN . . . . 7 1.5.2 Custom Generation of an MP/M II Boot . . . . . 6 1.6 Loading MPM.SYS INithout the MPMLDR . . . . . . . . . . 1.1 1.7 Digital Research Copyright and Trademark . . . . . . 11 1.8 Disk Organiz&tion . . . . . . . . . . . . . . . . . . 12 2 The MP/M II BIOS 2.1 MP/M II BIOS Overview . . . . . . . . . . . . . . . . 15 2.2 BIOS Device Chatacteristics and Entry Points . . . . 16 2.3 BIOS Disk Definition Tables . . . . . . . . . . . . . 24 2.31.1 Disk Parameter Table Format . . . . . . . . . 24 2.3.2 The DISKDEF macro Library . . . . . . . . . . 29 2.4 External Procedure Access 33 2.5 Blocking and Deblocking Algorighms . . . . . . . . . 36 2.6 Common Memoty Poition of the BNKXIOS . . . . . . . . . 7 3 The MP/M II XIOS 3.1 MP/M II XIOS Overview 3.2 MP/M XIOS Entry Points . . . 3.3 Interrupt Service Routines a.4 Time Base Management . . . V I TABLE OF CONTENTS (continued) 4 Mp/m 11 System File Components 4.1 System Data . . . . . . . . . . . . . . . . . . . . . 4", 4.2 Customized XIOS . . . . . . . . . . . . . . . . . . . 48 4.3 BDOS . . . . . . . . . . . . . . . . . . . . . . . . 48 4.3.1 RESBDOS . . . . . . . . . . . . . . . . . . . 48 4.3.2 BNKBDOS . . . . . . . . . . . . . . . . . . . 49 4.4 XDOS . . . . . . . . . . . . . . . . . . . . . . . . 49 4.5 Resident System Processes 4.6 Banked Resident System Piocesses 5 System Generation 5.1 GENSYS Operation . . . . . . . . . . . . . . . . . . 51 5.2 System GencLFtion P~ramt-tcrs . . . . . . . . . . . . 52 5.2.1 Defaults . . . . . . . . . . . . . 52 5.2.2 Top Pagt- of Op(-16~ing Sys~cm . . . . . . . . . 53 5.2.3 Number of System Consoles . . . . . . . . . . 53 5.2.4 Number of Plinters . . . . . . . . . . . . . . 53 5.2.5 Breakpoint RST . . . . . . . . . . . . . . . . 53 1.2.6 System Call User Stacks . . . . . . . . . . . 53 5.2.7 Z80 CPU . . . . . . . o . . . . . . e - * - - 54 5.2.8 Numbc-r of Ticks / Second . . . . . . . . . . . 54 5.2.9 System Disk . . . . . . . . . . . . . . . . . 54 5.2.10 Temporary File DiivL . . . . . . . . . . . . . 54 5.2.11 Maximum Locked Records / Process . . . . . . . 54 5.2.12 Total Locked Records / Syst(im . . . . . . . . 54 5.2.13 maximum open Files / Process . . . . . . . . . 55 5.2.14 Total Open Files / System . . . . . . . . . . 55 5.2.15 Bank Switched Memory . . . . . . . . . . . . . 55 5.2.16 Number of Uset Memory Segments . . . . . . . . 55 5.2.17 Common Memory Base Page . . . . . . . . . . . 55 5.2.18 Dayfile Logging at Console . . . . . . . . . . 55 5.2.19 Accept System Data Page Entries . . . . . . . 56 5.2.20 Selcct Resident System Processes . . . . . . . 56 5.2.21 Memory Segment Table . . . . . . . . . . . . . 56 5.2.22 Accept Memoiy Segment Table . . . . . . . . . 57 5.3-1 GENSYS Execution . . . . . . . . . . . . . . . . . . 57 vi TABLE OF CONTENTS (continued) 6 MP/M Lozder 6.1 MP/M Loader Operation and Display . . . . . . . . . . 59 6.2 MPMLDR Ex,-cut-ion . . . . . . . . . . . . . . . . . . 60 APPENDIXES A Disk Definition Macro . . . . . . . . . . . . . . . . . . Gl B Sector Deblocking Algorithms . . . . . . . . . . . . . . . G7 C Sample MP/M II Loader BIOS . . . . . . . . . . . . . . . . 75 D Simple XIOS Source Listing . . . . . . . . . . . . . . . . . 177 E Sample MP/M 1I Banked XIOS . . . . . . . . . . . . . . . . 97 v i i I SECTION I MP/M II ALTERATION PROCEDURE The MP/M 11 operating system is designed so that the user can alter a specific set of subroutines thet define the hardware operating environment. By modifying these subroutines, the user can produce --) diskette that operates with any IBNI-3740 format compatible diskette subsystem and other peripheral devices. Although the standard MP/M !I is shipped on single-density floppy disks, f ield-alteration features allow the user to adapt MP/M II to ct wide variety of disk subsystems, including single drive minidisks and high-capacity "hard disk" systems. To ~chieve Kvice independence, MP/M I! has isolatcd vll hardware-dependent code into an XIOS module. The user can rewrite the distributed version of the XIOS to customize the interface between the remaining MP/M II modules and the user's own hardware system. ThQ user can also rewrite the distributed version of the LDRBIOS, which loads the MP/M II system from disk. Thu,(_ cLe cctually two vaisions of Lhe XIOS: the RESXIOS for non-banked systems, and the BNKXIOS for banked memory systems. To avoid repeating both nemies for each reference, the term XICS reftzrs to both versions. 1.1 Preparation for MP/M II Alteration To simplify the alteration process, this docurrient assumes that a CP/M 2 BIOS has already been implemented on the target MP/M II machine. You must implement both the BIOS as well as the XIOS because the MP/M II loader uses a CP/M 2 BIOS to load the MP/M II systa" Once loaded, MP/M II uses the XIOS and not the BIOS. The CP/M 2 BIOS used by the MP/M II loader is called the LDRBIOS. Anothui good reason for implementing CP/M 2 on the target NIP/bm machine is that debugging your XIOS is simpler when you can run SID or DDT under a CP/M 2 system. 1 MP/M II System Guide 1.2 Customizing the MPMLDR 1.2 Customizing the MPMLDR To customize the MPMLDR, you must integrate a LDRBIOS for your hardware configuration into the MPMLDR.COM file supplied on the distribution disk. The required LDRBIOS can be simply a version of your CP/M 2 BIOS, altered as described below and renamed to LDRBIOS. The customized LDRBIOS must have an ORG of 1700H, perform console outpuL functions, and be able to read data from a single disk drive. The first call MPMLDR makes to LDRBIOS is SELDSK: select disk. I f your system has devices t h a t r e q u i r c initialization, pl&ce initialization code or perhaps a call to the LDRBIOS cold start at the beginning of the SELDSK handler. The LDRBIOS need only perform the operations described above. Other functions can be deleted to conserve space. There is only one restriction on memory space for LDRBIOS: it cannot extend above the base of the MPM.SYS which it is loading. (GENSYS Lists MP/M II's base Fddress in its load map.) However, if you plan to boot MP/M II from floppy disks, you will encounter a LDRBIOS upper address limit of lA00H in order to place the MPMLDR.COM file on two system tracks. Test LDRBIOS completely to ensure that it properly performs console chaEacter output and disk reads. Be especially careful that no disk write operations occur accidently during read operations, and check that the proper track and sectors are addressed on all re,As. Use the following steps to integrate a custom LDRBIOS into the MPMLDR.COM: 1. obtain access to a CP/M system and prcpare a LDRBIOS.HEX file. 2. Read the MPMLDR.COM file into memory using either DDT or SID A>DDT MPMLDR.COM DDT VERS 2.0 NEXT PC 1780 0100 3. Using the input command (I) , specify that the LDRBIOS.HEX f il(--, is to be read in and then read (R) in the f i le . This operation overlays the LDRBIOS portion of the MP/M loader. --ILDRBIOS.HEX -R NEXT PC 1A00 0000 MP/m II Systcm Guide 1.2 Customizing the MPMLDR 4. Exit the debugger , returning to the CCP by executing a jump to location zeL-O. -GO 5. Write the updated memory image onto a disk file. Usc- the CP/M SAVE command to write the updated memory image onto a disk file. In the example below, the X in front of the filename simply designates an experimental version, and preserves the original. A>SAVE 26 XMPMLDR.COM 6. Test XMPNILDR.COM and then rename it to MPMLDR.COM. 1.3 Customizing the XIOS As you are tailoring MP/M Il for your computer system, your new X10S will require software development and tESting. Two sample XIOS's are listed in the Appendixes, and can be used as models for the customized package. The XIOS entry points, including both basic and extended, are desctibcd in Sections 2 and 3. These sections, along with the appendixes, give you the information you need to write your XIOS. Your initial implementation of an XIOS should use polled 1/0 without any inturrupts. This initial system can run without a clock interrupt. Implement interrupts only after your XIOS is fully developed and tested. Follow the procedure below to prepare, a BNKXIOS.SPR or RESXIOS.SPR file front your customized XIOS: 1. i-~ssemblc your BNKXIOS.ASM or RESXIOS.ASN, with RMAC or any other assembler that c,,n genei ate a f ile of type REL in Mictosof t' s relocatable object file format. A>RMAC BNKXIOS 2. Link the BNKXIOS.REL or RESXIOS.REL f ile using the Digital Rescarch LINK-80 to produce the BNKXIOS.SPR or RESXIOS.SPR file. A>LINK BNKXIOS [OSI 3 MP/M II System Guide 1.4 Debugging an Xios 1.4 Debugging an XIOS You can debug an XIOS or & resident system process with DDT or SID running under CP/M. The debugging technique is outlined in the following steps: 1. Determine the amount of memory available to MP/M II when the debugger- and CP/M are resident. Do this by loading the debugger and then listing the jump instruction at location 0005H. This jump is to the base of the debugger. A>DDT DDT VERS 2.0 -L5 0005 JMP CSOO 2. Using GENSYS running under CP/M, generate an MPM.SYS file that specifies the top of memory determined by the previous step, allowing at le&st 256 bytes for & patch area. To p page of operating system (xx) ? C6 Also while executing GENSYS, specify a breakpoint restart number different from the one used by the CPIM debugger you plan to use. The suggested MP/M II restart is #6; however, any restart from -.'fl to #6 can usually be used. The CP/M debuggers normally use restart 17. B I eakpoint RST (xx) ? 6 Note: If you are also debugging a resident system process, be sure to select it for inclusion in MPM.SYS during GENSYS execution. 3. Using CP/M, load the MPMLDR.COM file into memory. A>DDT MPMLDR.COM DDT VERS 2.0 NEXT PC lAOO 0100 MP/M II System Guide 1.4 Debugging an XIOS 4. Place the chatacters "$B" into locations 005DH and 005EH of the default FCB based at 005CH. This operation can be done with the I command: -I$B The "$B" c,-.iuses the MPMLDR to break after loading the MPM.SYS file. You can specify the breakpoint restart to be executed by the MPMLDR by adding one additional character to the string in the fourth position of the default FCB. --J$B6 in the example above, a restart 116 is to be executed by the MPMLDR when loading of the MPM.SYS file is completed. If no restart number is supplied, the default restart is #7. Remember, the restart number at the location 5FH is the CP/M debugger restart number, not the MP/M debugger restart. 5. Execute the MPMLDR.COM program by entering a G command; -G 6. Af ter the G command, the MP/M II loader loads the MP/M II operating system into memory and displays a, memory map. You may obtain a hard copy of your load map during the GENSYS operation by entering a, TP before executing GENSYS. 7. If you are debugging an XIOS , note the address of the BNKXIOS.SPR or RESXIOS.SPR memory seament. You must also note the address of SYSTEM.DAT. If you are debugging a resident system process, note its address as well. The debugger lists actual addresses at the console. If your hard copy listing of the XIOS or RSP starts at zero, you must add the base address listed in the GENSYS load map to each address on the listing to make the listing reflect actual addresses. Or you can assemble the code again with an additional ORG statement specifying the base listed in the load map, although the object code generated by this assembly is unusable. S. Using the X command, determine the MP/M II beginning execution address. The address is the first location past the current program counter. -X ....................... P = 09F2 In the example shown above, MP/M II execution starts at address 09F3H, which is the first instruction after the restart at 09F2H. 5 1 MP/M II System Guide 1.4 Debugging an Xios 9. begin execution of MP/M II using the G command, specifying the start address and any breakpoints you need in your code. Th e actual memory address can be determined by entering an H command to add the code segment base address given in the memory map to the relative displacement address in your XIOS or resident system process listing. The following example shows how to set a brc&kpoint in an XIOS at the list subroutine entry point given in the memory map: XIOSJMP TBL C300H 010011 -G9F3,C30F 09F3H is the beginning MP/M II execution address and C30FH is the XIOS jump vector address of the list subroutine. 10. At this point, you have MP/M II running with CP/M and the CP/M debugger also in memory. Because interrupts are left enabled during operation of the CP/M debugger, ensure that interrupt driven code does not execute through a breakpoint. Because the CP/M debugger operates with interrupts left enabled, it is a somewhat difficult task to d--bug an interrupt driven console handler. Approach this problem by leaving console #0 in a polled mode while debugging the other consoles in an interrupt-driven mode. Once this is done, very little, if any, debugging is required to adapt the interrupt-driven code from another console to console 10. It is further recommended that you maintain a debug version of your XIOS that has polled 1/0 for console #0. otherwise, it is not possible to run the CP/M debugger underneath the MP/M II system because the CP/M debugger cannot get any console input, as all of it is sent to the MP/M interrupt-driven console #0 handler. 1.5 Directly Booting MP/M II In systems where MP/M II is to be booted directly at cold start rather than loaded and run as a transient program under CP/M, the customized MPMLDR.COM file and cold start loader can be placed on the first two tracks of a eight-inch floppy disk. If a CP/M SYSGEN.COM program is available, use it to write the MPMLDR.COM file on the first two tracks. If a SYSGEN.COM program is not available, or if SYSGEN.COM does not work because a different media such as a five-inch floppy disk or hard disk is to be used, the user- must write two programs: a simple memory loader, called GETSYS, which brings the [viP/M loader into memory, and a program called PUTSYS, which places the MPMLDR on the first two tracks of a disk. If you have implemented a CP/M 2 BIOS, you have probably already prepared GETSYS and PUTSYS. 6 MP/M II System Guide 1.5 Directly Booting MP/M II You can use either the SID or DDT debugger insteLd of writing a GETSYS program. This method is shown in the following example, which also uses SYSGEN in place of PUTSYS. Sample skeletal GETSYS and PUTSYS programs are given in Section 1.5.3. To load and run the MP/M system automatically, you must elso supply a cold start loader that loads the MP/M loader into memory from the first two tracks of the diskette. Modify the CP/M 2 cold start loader in the following manner: change the load address to 0100H and the execution address to 0100H. The following bootstrap techniques ate specific to the Intel NiDS-800, which has a boot ROM that loads the first track into location 300011. However, the steps shown can be applied in a general sense to any custom hardware environment. 1.5.1 Preparing an MP/M Il Boot Using SYSGEN If a SYSGEN program is available, use the following steps to prepare a diskette that cold starts MP/M II: Prepare the MPMLDR.COM file by integrating your custom LDRBIOS as described in Section 1.2. Test the MPMLDR.COM and verify that it operates properly. 2. Execute cither DDT or SID. A>DDT DDT VERS 2.0 3. Using the input command (I), specify that the MPMLDR.HEX file is to be read in and then read (R) in the f ile wi th an of f set of 880H bytes. -IMPMLDR.HEX -R880 NEXT PC 2480 0100 4. Using the I command, specify that the BOOT.HEX file is to be read in and then read in the file with an offset that loads the boot into memory at 9001-1. You can use the H command to calculate the offset. -H900 3000 3900 D900 -IBOOT.HEX -RD900 NEXT PC 2480 0000 7 MP/M II System Guide 1.5 Directly Booting MP/M II 5. Return to the CPIM console command ptocessor (CCP) by jumping to location zero. -GO 6. Use the SYSCEN program to write the new cold start loader onto the first Lwo tracks of the diskette. A>SYSGEN SYSGEN VER 2.0 SOURCE DRIVE NAME (OR RETURN TO SKIP) DESTINATION DRIVE NAME (OR RETURN TO REBOOT)B DESTINATION ON B, THEN TYPE RETURN FUNCTION CO11,iPLETE 1.5.2 Custom Generation of an MP/M II Boot If a SYSGEN program is not available, then use the following steps to prepare a diskette that cold starts MP/M II: 1. Write a GETSYS program that reads the custom MPMLDR.COM file into locction 3380H and the cold start loader (or boot program) into location 330CH. Code GETSYS so that it starts at location 100H (base of the TPA). or, &s in the previous example, you can use either SID or DDT to perform this function instead of writing a GETSYS program 2. Run the GETSYS program using an initialized MP/'Ivi II diskette to see if GETSYS loads the MP/M loader statting at 333801-1 (the operating system actually starts 128 bytes later at 340011). 3. Write a PUTSYS program that writes memory starting at _31380H back onto the first two tracks of the diskette. The PuTsys program should be located at 200H. 4. Test the PUTSYS program using a blank, uninitialized diskette by writing a portion of memory to the first two tracks; clear memory and read it back. Test PUTSYS completely, because you will use this program to alter the MP/M II system diskette. 5. Use PUTSYS to place the MP/M II loader and cold start loader onto the first two tracks of a blank diskette. 8 MP/M ILI System Guide 1.5 Directly Booting MP/M II 1.5.3 Sample GETSYS and PUTSYS Programs The following programs provide a framework for the GETSYS and PUTSYS program. You must insert WRITESEC subroutines to write the specific sectors. GETSYS PROGRAM - READ TRACKS 0 AND I TO MEMORY AT 3380H REGISTER USE A (SCRATCH REGISTER) B TRACK COUNT (0, 1) C SECTOR COUNT (1,2, ,26) DE (SCRATCH REGISTER PAIR) HL LOAD ADDRESS SP SET TO STACK ADDRESS START: LXI SP,3380H ;SET STACK POINTER TO SCRATCH AREA LXI H, 3380H ;SET BASE LOAD ADDRESS MVI B, 0 ;START WITH TRACK 0 RDTRK: ;READ NEXT TRACK (INITIALLY 0) MVI C'i ;READ STARTING WITH SECTOR 1 RDSEC: ;READ NEXT SECTOR CALL READSEC ;USER-SUPPLIED SUBROUTINE LXI D,128 ;MOVE LOAD ADDRESS TO NEXT 1/2 PAGE DAD D ;HL = HL + 128 INR C ;SECTOR = SECTOR + 1 MOV A,C ;CHECK FOR END OF TRACK CPI 27 ic RDSEC ;CARRY GENERATED IF SEcroR < 27 ARRIVE HERE AT END OF TRACK, MOVE TO NEXT TRACK INR B MOV A,B ;TEST FOR LAST TRACK CPI 2 ic RDTRK ;CARRY GENERATED IF TRACK < 2 ARRIVE HERE AT END OF LOAD, HALT FOR NOW HLT USER-SUPPLIED SUBROUTINE TO READ THE DISK READSEC: ENTER WITH TRACK NUMBER IN REGISTER B, SECTOR NUMBER IN REGISTER C, AND ADDRESS TO FILL IN HL PUSH B ;SAVE B AND C REGISTERS PUSH H ;SAVE HL REGISTERS -------------------------------- - -- - - perform disk read at this point, branch to label START if an error occurs POP H ;RECOVER HL POP B ;RECOVER B AND C REGISTERS RET ;BACK TO MAIN PROGRAM END START 9 MP/M II System Guide 1.5 Directly Booting MP/M II PUTSYS PROGRAM - WRITE TRACKS 0 AND I FROM MEMORY AT 3380H REGISTER USE A (SCRATCH REGISTER) B TRACK COUNT (0, 1) C SECTOR COUNT (1,2, ,26) DE (SCRATCH REGISTER PAIR) HL LOAD ADDRESS SP SET TO STACK ADDRESS START: LXI SP,3380H ;SET STACK POINTER TO SCRATCH AREA LXI H, 3380H ;SET BASE LOAD ADDRESS MVI B, 0 ;START WITH TRACK 0 WRTRK: ;WRITE NEXT TRACK (INITIALLY 0) MVI C'i ;WRITE STARTING WITH SECTOR 1 WRSEC: ;WRITE NEXT SECTOR CALL WRITESEC ;USER-SUPPLIED SUBROUTINE LXI D,128 ;MOVE LOAD ADDRESS TO NEXT 1/2 PAGE DAD D ;HL = HL + 128 INR C ;SECTOR = SECTOR + 1 MOV A,C ;CHECK FOR END OF TRACK CPI 27 ic WRSEC ;CARRY GENERATED IF SECTOR < 27 ARRIVE HERE AT END OF TRACK, MOVE TO NEXT TRACK INR B MOV A,B ;TEST FOR LAST TRACK CPI 2 JC VvRTRK ;CARRY GENERATED IF TRACK < 2 ARRIVE HERE AT END OF LOAD, HALT FOR NOW HLT USER-SUPPLIED SUBROUTINE TO WRITE THE DISK WRITESEC: ENTER WITH TRACK NUMBER IN REGISTER B, SECTOR NUMBER IN REGISTER C, AND ADDRESS TO FILL IN HL PUSH B ;SAVE B AND C REGISTERS PUSH H ;SAVE HL REGISTERS . . pot -- f or m di s k write at this point, branch to label START if an error occurs . . POP H ;RECOVER HL POP B ;RECOVER B AND C REGISTERS RET ;BACK TO MAIN PROGRAM END START 10 MP/M II System Guide 1.6 Loading MPM.SYS ~%-ithout the MPMLDR 1.6 Loading MPM.SYS Without the MPMLDR The MPM.SYS file is e fully-relocated absolute file that can be moved directly into memory and then executed without the use of the MPMLDR. The format of the MPM.SYS file is in Table 1-1, below. Table 1-1. MPM.SYS File Format Record Contents 1 First 128 bytes of the SYSDAT pzge 2 Second 128 bytes of the SYSDAT page 3-n MP/M operating system in reverse ordei, top down. The actual base of the SYSDAT page in memory is specified in byte 000 of the SYSDAT page. The rest of MP/M II operating system is to be located directly below the SYSDAT page. In Table 1-1, n represents the number of records. Bytes 120-121 of the SYSDAT page contain the value of n. The execution address of MP/m is specifed by the page address given in byte Oll of the SYSDAT page. MPMLDR could load the MPM.SYS file into memoty and then movo it to its destination specified in the SYSDAT page (byte 000). Or the user could write a separate custom program to produce a directly loadable memory image from the MPM.SYS file. 1.7 Digital Research Copyright and Trademark Read your MP/M II Licensing Agreement; it specifies your legal responsibilities when copying the MP/M I! system. Place the copyright notice: Copyright C 1981 Digital Research on thie label of each copy you make of your customized MP/M II diskette. Digital Research also requests that you place your MP/M II serial number on the label of any copies you make. Remember also that MP/M II is a trademark of Digital Research, and the first time it appears on a disk label or in a document, it should be followed by a trademark symbol, as shown below: Mp/M I, TM I . I MP/M II System Guide 1.8 Disk organization 1.8 Disk organization This section describes mP/m Ii sector allocation for a system in which the MPMLDR resides on the first two tracks of a single density diskette. Tile first sector (see Table 1-2) contains an optional software boot section. Disk controllers are often set up to bring track 0, sector 1 into memory at a specific location, often location OOOOH. The program in this sector, called BOOT, is responsible for bringing the remaining sectors into memory starting at location 0100H. If your controller does not have a built-in sector load, you can ignore the program in track 0, sector 1, and begin the load from track 0 sector 2 to location 0100H. As on examplt-,, the Intel MDS-800 hardwate cold st~,rt lo&dCr brings track 0, sector 1 into absolute address 3000H. When this sector is loaded, control transfers to location 3000H, where the bootstrap operation commences by loading the remainder of track 0, and all of track I into memory, starting at 0100H. Remember that this bootstrap loader is of little use in a non-MDS environment, but it is useful to examine it because you will have to duplicate some of its actions in your own cold start loader. 12 MP/M II System Guide 1.8 Disk Organization Table 1-2. MP/M Il Sample Disk organization Track# Sector# Pageff Memory Address MP/M Module name 00 01 (boot &ddi-ess) Cold Stait Loader 00 02 00 0100H MPMLDR It 03 11 0180H 11 04 01 0200H if 05 if 0280H 06 02 0300H 07 Re 0 3'8 0 H 08 03 0400H 09 if 0480H If 10 04 0500H to If 11 of 0580H to 12 05 00600H If 13 of 068011 11 14 06 0700H 91 15 11 0780H If If 16 07 0800H 17 It 0880H is 08 0900H 19 is 0980H 20 09 OAOOH 21 If OA80H of 22 10 OBOOH if it 23 11 OBSOH If 11 24 11 OCOOH 11 00 25 11 OC80H MPMLDR 00 26 12 ODOOH LDRBDOS 01 01 of 0D80H If it 02 13 OEOOH it of 03 if OE80H it 04 14 OFOOH If 05 go OF80H If it 06 15 1000H 11 07 11 1080H It 08 16 1100H of 09 11 1180H It of 10 17 1200H to 11 ll 11 1280H 11 If 12 18 1300H of of 13 It 1380H If 11 14 19 1400H of if 15 If 1480H 11 16 20 1500H of 17 91 1580H It 11 18 21 1600H It 01 19 it 1680H LDRBDOS 01 20 22 1700H LDRBIOS of 21 if 1780H It 22 23 1800H It 23 11 1OU80H If 24 24 1900H If If 25 to 1980H of 01 26 25 lA00H LDRBIOS 13 SECTION 2 MP/M II BIOS 2.1 MP/M II BIOS Overview The MP/M II BDOS and XDOS access peripheral devices as "logical" devices within the BIOS and XIOS. To customize MP/M II for a specific hardware environment, the system implementor must prepare the BIOS and XIOS subroutines upon which the BDOS and XDOS depend. This section describes how the logical portions of MP/M II expect to interact with the BIOS; Section 3 describes the same for the XIOS. The BDOS and XDOS call BTOS subroutines through a "jump vector" located at the base of the BIOS as shown below and in Appendixes D and E. The jump vector is a sequence of 26 jump instructions that send program control to the individual BIOS subroutines. All subroutines must be represented in the jump vector during MP/M II system regeneuation. However, certain subroutines may be "empty", that is, they may contain only a single RET instruction. The BIOS jump vector must take the form shown below. The individual jump addresses for each entry point are listed to the left. Note that the XIOS entry points immediately follow the last BIOS entry point. BIOS+OOH JMP COMMONBASE ; COMMONBASE, TERMINATE PROCESS BIOS+03H JMP WBOOT ; WARM BOOT, TERMINATE PROCESS BIOS+06H JMP CONST CHECK FOR CONSOLE CHAR READY BIOS+09H JMP CONIN READ CONSOLE CHARACTER IN BIOS+OCH JMP CONOUT WRITE CONSOLE CHARACTER OUT BIOS+0FH JMP LIST WRITE LIST CHARACTER OUT BIOS+12H JMP PUNCH not used by MP/M II BIOS+15H JMP READER not used by MP/M 11 BIOS+18H JMP HOME MOVE TO TRACK 00 BIOS+iBH JMP SELDSK SELECT DISK DRIVE BIOS+IEH JMP SETTRK SET TRACK NUMBER BIOS+21H JMP SETSEC SET SECTOR NUMBER BIOS+24H JMP SETDMA SET DMA ADDRESS BIOS+27H JMP READ READ SELECTED SECTOR BlOS+2AH JMP WRITE WRITE SELECTED SECTOR BIOS+2DH JMP LISTST not used by MP/M II BIOS+30H JMP SECTRAN SECTOR TRANSLATE SUBROUTINE E~,ch jump address corresponds to a particular subroutine that putforras a specific function, as outlined in Section 2.3. Three major functions are performed by calls to the jump table: process termination from COMMONBASE and WBOOT; simple character 1/0 from CONST, CONIN, CONOUT, and LIST; and disk 1/0 from HOME, SELDSK, SETTRK, SETSEC, SETDMA, READ, WRITE, and SECTRAN. 15 MP/M II System Guide 2.1 MP/M II BIOS Overview All simple ch&racter 1/0 opt~r&tions are 3ssumcd to be performed in ASCII, upper and lower case, with high-order (parity) bit set to z e r o . The BDOS depends on only the CONST, CONIN, and CONOUT subroutines for simple character 1/0. An ASCII TZ (1AH) is interpreted as an end-of-file condition for an input device. 2.2 BIOS Device Characteristics and Entry Points The BIOS generally supports three types of devices: consoles, list devices and disks. The characteristics of each device are described below. Consoles are the principal interactive devices that communicate with operators, and are accessed through CONST, CONIN, and CONOUT. Typic&lly, consoles are devices such as CRTs or teletypes. MP/M II supports up to 16 console or character 1/0 devices. List Devices, if they exist on your system, are usu&lly hard copy devices, such as printers or teletypes. MP/M I! supports up to 16 list devices. Disks are accessed through a sequence of calls on the various disk i-/0subroutines. These subroutines set up the disk number to access, the track and sector on a particular disk, and the direct memory access (DMA) address involved in the 1/0 operation. After all these parameters have been set up, a call is made to the READ or WRITE function to perform the actual 1/0 operation. Note that there is often a single call to SELDSK to select a disk drive, followed by a number of read or write operations to the selected disk before selecting another drive for subsequent operations. Similarly, there may be a single call to set the DMA address, followed by several calls which read or write from the selected DMA address before the DNIA address is changed. The track and sector subroutines ate always called before the READ or, WRITE operations are performed. Note that the READ and WRITE routint--,s should perfotm several retries (10 is standard) before reporting an error condition to the BDOS. If the error condition is returned to the BDOS, it reports the error to the user. The HOME subroutine may or may not actually perform the track 00 seek, depending upon your controller characteristics; the important point is that track 00 has been selected for the next operation, and is often treated in exactly the same manner as SETTRK with a parameter of 00. Table 2-1 outlines the exact responsibil 1 ties of each subroutine entered through the BIOS jump table. 16 MP/M II System Guide 2.2 BIOS Device Characteristics Table 2-1. BIOS Subroutine Summary Subroutine Description COMMONBASE The COMMONBASE entry point establishes the base address of the portion of the XIOS that must reside in common memory. Th e COMMONBASE entry point also contains a jump vector that enables the XIOS to access user and system memory bank s w i t c h i n g subroutines, the MP/M II dispatcher, the XDOS and BDOS, the SYSDAT page, and COLDSTART. The ef f ect of a cal 1 to COMMONBASE is to terminate the calling program. Other external procedures accessed by COMMONBASE are described in Section 2.4. WBOOT The WBOOT subroutine performs an XDOS terminate process call, terminating the calling process. The subroutine must be re-entrant and this entry point must be above the COMMONBASE label. CONST The CONST subroutine obtains the status of the console device specified by register D and returns OFFH in register A if a character is ready to read, or OOH in register A if no console characters are ready. This subroutine must be re-entrant and this entry point must be above the COMMONBASE label. CONIN The CONIN subroutine reads the next character from the console device specified by register D into register A, and sets the parity bit (high-order bit) to zero. If no console character is ready, CONIN waits u n t i 1 a character is typed before returning. This subroutine must be re entrant and this entry point must be above the COMMONBASE label. MP/M II System Guide 2.2 BIOS Device Characteristics Table 2-1. (continued) Subroutine Description CONOUT The CONOUT subroutine sends the character f rom reg i s te r C to the console output device specified by register D. The character is in ASCII, with high-order parity bit set to zero. You may want to include a delay on a line feed or carriage return if your console device requires some time interval at the end of the line (such as a TI Silent 700 terminal) . You can, if you wish, filter out control characters that cause your console device to react in a strange way. For example, a TZ causes the Lear-Seigler terminal to clear the screen, and could be filtered out by CONOUT. This subroutine must be re-entrant and this entry point must be above the COMMONBASE label. LIST The LIST subroutine sends the character from register C to the list output device specified by register D. The character is in ASCII with zero parity. This subroutine must be re-entrant and this entry point must be above the COMMONBASE label. PUNCH The punch device is not implemented under MP/M II. The transfer vector position is preserved to maintain CP/M compatibility. Note that MP/M II supports up to 16 character 1/0 devices, any of which can be a reader/punch. READER The reader device is not implemented under MP/M II. See the note above for PUNCH. HOME The HOME subroutine returns the disk head of the currently-selected disk to the track 00 position. If your controller allows access to the track 0 flag from the drive, step the head until the track 0 flag is detected. If your controller does not support this feature, you can translate the HOME call into a call on SETTRK with a parameter of 0. 18 MP/M II System Guide 2.2 BIOS Device Characteristics Table 2-1. (continued) Subroutine Description SELDSK The SELDSK subroutine selects the disk drive given by register C for further operations, where register C contains 0 for drive A, 1 for drive B, and so up to 15 for drive P. On each disk select, SELDSK must return in HL the base address of a 16-byte area, called the Disk Parameter Header, described in Section 2.3. For standard floppy disk drives, the contents of the header and associated tables does not change, and thus the program segment included in the sample XIOS performs this operation automatically. If there is an attempt to select a non-existent drive, SELDSK returns HL=OOOOH as an error indicator. On entry to SELDSK, it is possible to determine whether it is the first time the specified disk has been selected. Register E, bit 0 (least significant bit) is a zero if the drive has not been previously selected. This information is of interest in systems that read conf iguration information f rom the disk to set up a dynamic disk definition table. Although SELDSK must return the header address on each call, it is advisable to postpone the actual physical disk select operation until an 1/0 function (read or write) is actually performed. This is because disk selects often occur without ultimately performing any disk 1/0, and many controllers unload the head of the current disk before selecting the new drive. This unloading can cause an excessive amount of noise and disk wear. The first SELDSK subroutine call that MP/M II makes is only for getting the DIRBUF address and need not perform any actual 1/0. MP/M II System Guide 2.2 BIOS Device Characteristics Table 2-1. (continued) Subroutine Description SETTRK For the SETTRK subroutine, register BC contains the track number for subsequent disk accesses on the currently selected drive. You can choose to seek the selected track at this time, or delay the seek until the next read or write actually occurs. Register BC can take on values in the range 0-76 corresponding to valid track numbers for standard floppy disk drives, and 0 65535 for non-standard disk subsystems. SETSEC For the SETSEC subroutine, register- BC contains the translated sector number for subsequent disk accesses on the currently selected drive (see SECTRAN, below). You can choose to send this information to the controller at this point, or instead delay sector selection until a read or write operation occurs. Register BC can take on values in the range 1-26 corresponding to valid sector numbers for standard floppy disk drives, and 0-65535 for non-standard disk subsystems. SETDMA For the SETDMA subroutine, register BC contains the DMA (disk memory access) address for subsequent read or write operations. For example, if B = OOH and C = 80H when SETDMA is called, then all subsequent read operations read their data into 80H through OFFH, and all subsequent write operations get their data from 80H through OFFH, until the next call to SETDMA occurs. The initial DMA address is assumed to be 80H (relative to the base of the memory segment from which the call was made). Note that the controller need not actually support direct memory access. If , for example, all data is received and sent through 1/0 ports, the XIOS you construct can use the 128 byte area starting at the selected DMA address for the memory buffer during subsequent read or write operations. A special case of the SETDMA subroutine occurs when the passed parameter in register BC contains a OFFFFH. This parameter indicates that the blocking buffer, if it exists, must be flushed. 20 MP/M II System Guide 2.2 BIOS Device Characteristics Table 2-1. (continued) Subroutine Description Thus, a call to the SETDMA subroutine is interpreted as a flush buffer call when a parameter of OFFFFH is passed. The BDOS function to flush buffers is translated to this form of a SETDMA subroutine call. If the flush buffer operation performed as a result of the OFFFFH parameter is successful a simple return should be executed. However, if a disk error occurs the current return address should be popped f rom the stack and one of the following error codes should be returned in the register A: 1 non-recoverable error condition occurred 2 disk read/only READ Assuming the drive has been selected, the track has been set, the sector has been set, and the DMA address has been specified, the READ subroutine attempts to read one sector based upon these parameters, and returns the following error codes in register A: 0 no errors occurred non-recoverable error condition occurred If the value in register A is 0, then MP/M II assumes that the disk operation was completed properly. If an error occurs, however, the XIOS should attempt at least 10 r e t r i e s to see if the e r r o r is recoverable. When an error is reported, the BDOS prints the message "BDOS ERR ON x: BAD SECTOR". Then, depending on the error mode of the calling process, the calling process is terminated or returned an error code. An additional parameter containing the absolute record number for the disk read is now passed by MP/M II on entry to the READ subroutine. The parameter is three bytes in length, with the high-order byte in register B and the low-order two bytes in register DE. This parameter may be useful in blocking/deblocking algorithms. 21 MP/M II System Guide 2.2 BIOS Device Characteristics Table 2-1. (continued) Subroutine Description The BNKXIOS of MP/M II allows portions of the XIOS to reside in bank-switched memory (non-common). This reduces the common memory requirements. The XIOS code for all the disk operations including READ and WRITE can reside in non-common memory with one exception: the code that actually performs the transfer of data into the DMA address must reside in common memory. Two additional entry points within the XIOS, named SWTUSER and SWTSYS, enable switching between the user's memory bank and the system bank containing the BNKXIOS. SWTUSER and SWTSYS are described in Section 2.4. If you perform deblocking in your READ and WRITE code, you must choose whether to place your deblocking buffer in common memory and then perform a single move into the user's DMA, or to place your deblocking buffer in non-common memory. If you choose the latter, you must then perform an extra move to first move the sector into common memory and then another move into the user's DMA. Blocking and deblocking are discussed in Section 2.5. WRITE The WRITE subroutine writes the data from the currently selected DMA address to the currently selected drive, track, and sector. The data should be marked as "non deleted data" to maintain compatibility with other CP/M and MP/M systems. WRITE returns the following error codes in register A, as shown below: 0 no errors occurred I non-recoverable error condition occurred 2 disk read/only If the value in register A is 0, then MP/M II assumes that the disk operation completed properly. If an error occurs, however, the XIOS should attempt at least 10 retries to see if the error is recover-able. When an error is reported, the BDOS prints the message "BDOS ERR ON x: BAD SECTOR". Then, depending on the error mode of the calling process, the calling process is terminated or returned an error code. 22 MP/M II System Guide 2.2 BIOS Device Characteristics Table 2-1. (continued) Subroutine Description On entry to the WRITE subroutine a parameter is passed in the C register which is intended for use by block ing/deblock ing algorithms. This parameter is described in Section 2.5 on blocking/deblocking. An additional parameter containing the absolute record number for the disk write is now passed by MP/M II on entry to the WRITE subroutine. The parameter is three bytes in length, with the high-order byte in register B and the low-order two bytes in register DE. This parameter can be useful in blocking/deblocking algoritms. See the previous section on disk READ for a discussion of placing disk WRITE code in bank-switched memory and deblocking in your WRITE code. LISTST The LISTST subroutine returns the ready status of the list device specified by register D. The value 00 is returned in A if the list device is not ready to accept a character, and OFFH if a character can be sent to the printer. Note that a 00 value always suffices. LISTST must be re entrant. This entry point is maintained solely for compatibility with CP/M and can generally be omitted from the MP/M II XIOS as none of the standard utilities use this entry point. SECTRAN The SECTRAN subroutine performs logical sector to physical sector translation and can improve the overall response of MP/M II. Standard MP/M II systems are shipped with a "skew factor" of 6, where six physical sectors are skipped between each logical read operation. This skew factor allows enough time between sectors for most programs to load their buffers without missing the next sector. 23 MP/M II System Guide 2.2 BIOS Device Characteristics Table 2-1. (continued) Subroutine Description For computer systems that use fast processors, memory and disk subsystems, you can change the skew factor to improve overall response. Note, however, that you should maintain a single-density !BM compatible version of MP/M II for information transfer into and out of your computer system, using a skew factor of 6. In general, SECTRAN receives a logical sector number in BC and a translate table address in DE. SECTRAN uses the sector number as an index into the translate table, and returns the resulting physical sector number in HL. For standard systems, the tables and indexing code are provided in the XIOS and need not be changed. 2.3 BIOS Disk Definition Tables This section presents the organization and construction of tables within the BIOS that define the characteristics of a particular disk system used with MP/M II. These tables can be either hand-coded or automatically generated using the DISKDEF utility provided with MP/M II. The elements of these tables are presented below. 2.3.1 Disk Parameter Table Format In general, each disk drive has an associated (16-byte) Disk Parameter Header which both contains information about the disk drive and provides a scratchpad area for certain BDOS operations. The format of the Disk Parameter Header for each drive is shown below. Disk Parameter Header XLT 0000 0000 0000 DIRBUF DPB CSV ALV l6b 16b l6b l6b l6b l6b l6b 16b Each element is a word (16-bit) value. The meaning of each Disk Parameter Header (DPH) element is given in Table 2-2. 24 MP/M II System Guide 2.3 BIOS Disk Definition Tables Table 2-2. Disk Parameter Header Elements Element Description XLT offset of the logical to physical translation vector, if used for this particular drive, or the value OOOOH if no sector translation takes place (i.e, the physical and logical sector numbers are the same). Disk drives with identical sector skew factors share the same translate tables. 0000 Scratchpad values for use within the BDOS (initial value is unimportant). DIRBUF Offset of a 128 byte scratchpad area for directory operations within BDOS. All DPHs address the same scratchpad area. The same DIRBUF is used by all drives. DPB offset of a disk parameter block for this drive. Drives with identical disk characteristics address the same disk parameter block. CSV offset of a scratchpad area used for software check for changed disks. This offset is different for each DPH. ALV offset of a scratchpad area used by the BDOS to keep disk storage allocation information. This offset is different for each DPH. Given n disk drives, the DPHs are arranged in a table whose first row of 16 bytes corresponds to drive 0, with the last row corresponding to drive n-l. The table thus appears as: DPBASE 00 XLT 00 0000 0000 0000 DIRBUF DBP 00 CSV 00 ALV 00 01 XLT 01 0000 0000 0000 DIRBUF DBP 01 CSV 01 ALV 01 n-l XLTn-1 0000 0000 0000 DIRBUF DBPn-1 CSVn-1 ALVn-l where the label DPBASE defines the offset of the DPH table relative to the beginning of the operating system. A responsibility of the SELDSK subroutine, defined in the previous section, is to return the offset of the DPH from the beginning of the operating system for the selected drive. The following sequence of operations returns the table offset, with a 0000H returned if the selected drive does not exist. 25 MP/M II System Guide 2.3 BIOS Disk Definition Tables NDISKS EQU 4 ;NUMBER OF DISK DRIVES S L SK: ;SELECT DISK N GIVEN BY C LXI H,OOOOH ;READY FOR ERR MOV A,C CPI NDISKS ;N BEYOND MAX DISKS? RNC ;RETURN IF SO ;0 <= N < NDISKS MOV L,C DAD H ;READY FOR * 16 DAD H DAD H DAD H LXI D,DPBASE DAD D ;DPBASE + N * 16 RET The translation vectors (XLT 00 through XLTn-1) are located elsewhere in the BIOS, and simply correspond one-for-one with the logical sector numbers zero through the sector count-1. The Disk Parameter Block (DPB) for each drive is more complex. A particular DPB, which is addressed by one or more DPHs, takes the general form: SPT BSH BLM EXM DSM DRM ALO ALI CKS OFF l6b 8b 8b 8b l6b l6b 8b 8b 16b l6b where each is a byte or word value, as shown by the "8b" or '116b" indicator below the field. The fields are defined in Table 2-3. 26 MP/M II System Guide 2.3 BIOS Disk Definition Tables Table 2-3. Disk Parameter Block Fields Field Definition SPT is the total number of sectors per track. BSH is the data allocation block shift factor, determined by the data block allocation size. BLM is the block mask which is also determined by the data block allocation size. EXM is the extent mask, determined by the data block allocation size and the number of disk blocks. DSM determines the total storage capacity of the disk drive. DRM determines the total number of directory entries which can be stored on this drive. ALO,ALl determine reserved directory blocks. CKS is the size of the directory check vector, a CKS of 8000H marks the drive as permanent with no directory records checked. OFF is the number of reserved tracks at the beginning of the (logical) disk. Although these table values are produced automatically by DISKDEF, it is worthwhile reviewing the derivation of each field so that the values may be cross-checked when necessary. The values of BSH and BLM determine (impl-icitly) the data allocation size BLS, which is not an entry in the disk parameter block. Given that you have selected a value for BLS, the values of BSH and BLM are shown in Table 2-4 below, where all values are in decimal. Table 2-4. BSH and BLM Values for Selected BLS BLS BSH BLM 1,024 3 7 2,048 4 15 4,096 5 31 8,192 6 63 16,384 7 127 The value of EXM depends upon both the BLS and whether the DSM value is less than 256 or greater than 255, as shown in the following table. 27 MP/M II System Guide 2.3 BIOS Disk Definition Tables Table 2-5. Maximum EXM Values BLS DSM < 256 DSM > 255 1,024 0 N/A 2,048 1 0 4,096 3 1 8,192 7 3 16,384 15 7 The value of DSM is the maximum data block number- supported by this particular drive, measured in BLS units. The product BLS times (DSM+l) is the total number of bytes held by the drive and, of course, must be within the capacity of the physical disk, not counting the reserved operating system tracks. The DRM entry is one less than the total numbcr of directory entries, which can take on a 16-bit value. The values of ALO and ALI, however, are determined by DRM. The two values ALO and ALI can together- be considered a string of 16-bits, as shown below. ALO ALI 00 01 02 03) 04 05 06 07 08 09 10 11 12 13 14 15 where position 00 corresponds to the high-order bit of the byte labeled ALO, and 15 corresponds to the low-order bit of the byte labeled ALI. Each bit position reserves a data block for a number of directory entries, thus allowing a total of 16 data blocks to be assigned for directory entries (bits are assigned starting at 00 and filled to the right until position 15). Each directory entry occupies 32 bytes, as shown in Table 2-6. Table 2-6. BLS and Number of Directory Entries BLS Directory Entries 1,024 32 times # bits 2,048 64 times # bits 4,096 128 times # bits 8,192 256 times # bits 16,384 512 times 4 bits Thus, if DRM = 127 (128 directory entries), and BLS = 1024, then there ate 32 directory entries per block, requiring 4 reserved blocks. In this case, the 4 high-order bits of ALO are set, resulting in the values ALO = OFOH and ALI = OOH. 28 MP/M II System Guide 2.3 BIOS Disk Definition Tables The CKS value is determined as follows: if the disk drive media is removable, then CKS = (DRM+1)/4, where DRM is the last directory entry number. If the media is fixed, then set CKS = 8000H (no directory records are checked in this case and drive marked as permanent). Finally, the OFF field determines the number of tracks which are skipped at the beginning of the physical disk. This value is automatically added whenever SETTRK is called, and can be used as a mechanism for skipping reserved operating system tracks, or for partitioning a large disk into smaller segmented sections. To complete the discussion of the DPB, recall that several DPHs can address the same DPB if their drive characteristics are identical. Further, the DPB can be dynamically changed when a new drive is addressed by simply changing the pointer in the DPH since the BDOS copies the DPB values to a local area whenever the SELDSK function is invoked. Returning back to the DPH for a particular drive, note that the two address values CSV and ALV remain. Both addresses reference an area of uninitialized memory following the BIOS. The areas must be unique for each drive, and the size of each area is determined by the values in the DPB. The size of the area addressed by CSV is CKS bytes, which is sufficient to hold the directory check information for this particular drive. If CKS = (DRM+1)/4, then you must reserve (DRM+1)/4 bytes for directory check use. If CKS = 0, indicating no checked directory entries, or CKS = 8000H, marking the drive as permanent with no checked directory entries, then no storage is reserved. The size of the area addressed by ALV is determined by the maximum number of data blocks allowed for this particular disk, and is computed as (DSM/8)+l. 2.3.2 The DISKDEF Macro Library A macro library called DISKDEF greatly simplifies the table construction process. You must have access to the MAC macro assembler or the RMAC relocatable macro assembler distributed with MP/M II to use the DISKDEF facility. The macro library is included with all MP/M II distribution disks. A BIOS disk definition consists of the following sequence of macro statements: 29 MP/M II System Guide 2.3 BIOS Disk Definition Tables MACLIB DISKDEF DISKS n DISKDEF 0 .... DISKDEF 1,... DISKDEF n-1 E~DEF where the MACLIB statement loads the DISKDEF.LIB file (on the same disk as your BIOS) into MACs internal tables. The DISKS macro call follows, which specifies the number of drives to be configured with your system, where n is an integer in the range I to 16. A series of DISKDEF macro calls then follow, which define the characteristics of each logical disk, 0 through n-1 (corresponding to logical drives A through P). Note that the DISKS and DISKDEF macros generate the in-line fixed data tables described in the previous section, and thus must be placed in a non-executable portion of your BIOS, typically directly following the BIOS jump vector. The remaining portion of your BIOS is defined following the DISKDEF macros, with the ENDEF macro call immediately preceding the END statement. The ENDEF (End of Diskdef) macro generates the necessary uninitialized RAM areas that are located in memory above your BIOS. The form of the DISKDEF macro call is DISKDEF dn,fsc,lsc,[skf],bls,dks,dir,cks,ofs,[kl6],[prm] where dn is the 'Logical disk number, 0 to n-1 fsc is the first physical sector number (0 or 1) lsC is the last sector number skf is the optional sector skew factor bls is the data allocation block size dks is the total number of blocks on the drive. dir is the number of directory entries cks is the number of "checked" directory entries ofs is the track offset to logical track 00 k16 is an optional 1.4 compatibility flag which forces 16K/directory entry prm is an optional flag which indicates that the drive is permanent (cannot be removed) The value dn is the drive number being defined with this DISKDEF macro invocation. The fsc Parameter accounts for differing sector numbering systems, and is usually 0 or 1. The Isc is the last numbered sector on a track. When present, the skf parameter defines the sector skew factor which is used to create a sector translation table according to the skew. If the number of sectors is less than 256, a single-byte table is created, otherwise each 30 MP/M II System Guide 2.3 BIOS Disk Definition Tables translation table element occupies two bytes. No translation table is created if the skf parameter is omitted (or equal to 0). The b1s parameter specifies the number of bytes allocated to each data block, and takes on the values 1024, 2048, 4096, 8192, or 16384. Generally, performance increases with larger data block sizes since there are fewer directory references and logically connected data records are physically close on the disk. Also " each directory entry addresses more data, and the BIOS-resident RAM space is reduced. The dks specifies the total disk size in b1s units. Tha t is , if the bls = 2048 and dks = 1000 , then the total disk capacity is 2,048,000 bytes. If dks is greater than 255, then the block size parameter bls must be greater than 1024. The value of dir is the total number of directory entries which may exceed 255, if desired. The cks parameter determines the number of directory items to check on each directory scan and is used internally to detect changed disks during system operation. When this situation is detected, MP/M II automatically marks the disk read/only, so that data is not subsequently destroyed. As stated in the previous section, the valLje of cks equals dir when the media is easily changed, as is the case with a floppy disk subsystem. If the disk is permanently mounted, then the value of cks is typically 0 and thus the prm parameter should be included to indicate that the drive is permanent. The ofs value determines the number of tracks to skip when this particular drive is addressed, which can be used to reserve additional operating system space or to simulate several logical drives on a single large-capacity physical drive. The k16 parameter is included when file compatibility is required with versions of CP/M 1.4 that have been modified for higher density disks. This parameter ensures that only 16K is allocated for each directory record, as was the case for previous versions. Normally, this parameter is left null. Finally, the prm parameter can be used to indicate that the drive is permanent. This parameter should only be included if the disk media cannot be removed from the drive. For convenience and economy of table space, the special form DISKDEF i1i gives disk i the same characteristics as a previously defined drive j. A standard four-drive single density system, which is compatible with CP/M 1.4, is defined using the following macro invocations: 31 MP/M II System Guide 2.3 BIOS Disk Definition Tables DISKS 4 DISKDEF 0,1,26,6,1024,243,64,64,2 DISKDEF 1,0 DISKDEF 2,0 DISKDEF 3,0 ENDEF with all disks having the same parameter values of 26 sectors per track (numbered 1 through 26), with 6 sectors skipped between each access, 1024 bytes per data block, 243 data blocks for a total of 243k byte disk capacity, 64 checked directory entries, and two operating system tracks. The DISKS macro generates n Disk Parameter Headers (DPHs) starting at the DPH table address DPBASE generated by the macro. Each disk header block contains sixteen bytes, as described above, and corresponds one-for-one to each of the defined drives. In the four drive standard system, for example, the DISKS macro generates a table of the form: DPBASE EQU $ DPEO: DW XLTO,OOOOH,OOOOH,OOOOH,DIRBUF,DPBO,CSVO,ALVO DPE1: DW XLTO,OOOOH,OOOOH,OOOOH,DIRBUF,DPBO,CSVI,ALVI DPE2: DW XLTO,OOOOH,OOOOH,OOOOH,DIRBUF,DPBD,CSV2,ALV2 DPE3: DW XLTO,OOOOH,OOOOH,00001i,DIRBUF,DPBO,CSV3,ALV3 where the DPH labels are included for reference purposes to show the beginning table addresses for each drive, 0 through 3. The values contained within the disk parameter header are described in detail in the previous section. The check and allocation vector addresses are generated by the ENDEF macro in the RAM area following the BIOS code and tables. Note that if the skf (skew factor) parameter is omitted (or equal to 0), the translation table is omitted, and a OOOOH value is inserted in the XLT position of the disk parameter header for the disk. In a subsequent call to perform the logical to physical translation, SECTRAN receives a translation table address of DE = OOOOH, and simply returns the original logical sector from BC in the HL register pair. A translate table is constructed when the skf parameter is present, and the (non-zero) table address is placed into the corresponding DPHs. The table shown below, for example, is constructed when the standard skew factor skf = 6 is specified in the DISKDEF macro call: XLTO: DB 1,7,13,19,25,5,11,17,23,3,9,15,21 DB 2,8,14,20,26,6,12,18,24,4,10,16,22 Following the ENDEF macro call, a number of uninitialized data areas are defined. rhese data areas need not be a part of the BIOS that is loaded upon cold start, but must be available between the BIOS and the end of memory. The size of the uninitialized RAM area is determined by EQU statements generated by the ENDEF macro. For a standard four-drive system, the ENDEF macro might produce: 32 MP/M II System Guide 2.3 BIOS Disk Definition Tables 4C72 = BEGDAT EQU $ (data areas) 4DBO = ENDDAT EQU $ 013C = DATSIZ EQU $-BEGDAT which indicates that uninitialized RAM begins at location 4C72H, ends at 4DBOH-1, and occupies 013CH bytes. You must ensure that these addresses are free for use after the system is loaded. Af ter mod if ication, you can use the STAT program to check your drive characteristics, because STAT uses the disk parameter block to decode the drive information. The STAT command form STAT d:DSK: decodes the disk parameter block for drive d (d=A, . . . P) and displays the values shown below. r: 128 Byte Record Capacity k: Kilobyte Drive Capacity d: 32 Byte Directory Entries c: Checked Directory Entries e: Records/ Extent b: Records/ Block s: Sectors/ Track t: Reserved Tracks Three examples of DISKDEF macro invocations are shown below with corresponding STAT parameter values. The last example produces an 8-megabyte system. DISKDEF 0,1,58,,2048,256,128,128,2 r=4096, k=512, d=128, c=128, e=256, b=16, s=58, t=2 DISKDEF 0,1,58,,2048,1024,300,0,2 r=16384, k=2048, d=300, c=O, e=128, b=16, s=58, t=2 DISKDEF 0,1,58,,16384,512,128,128,2 r=65536, k=8192, d=128, c=128, e=1024, b=128, s=58, t=2 2.4 External Procedure Access To help the XIOS access other MP/M entry points, a jump vector is dynamically built by the MP/M II GENSYS program and placed at the COMMONBASE subroutine entry point. The dynamic portion of the jump vector contains five entry points that provide access to user and system memory bank switching, the MP/M Il dispatcher, the XDOS, and the SYSDAT page. Table 2-7 describes external procedure entry points. 33 MP/M II System Guide 2.4 External Procedure Access The following example illustrates the code used to access external procedures: COMMONBASE: imp COLDSTART SWTUSER: JMP $-$ SWTSYS: imp $-$ PDISP: imp $-$ XDOS: imp $-$ SYSDAT: DW $-$ COLDSTART: WBOOT: mvi C,O imp XDOS ;terminate process MP/M II System Guide 2.4 External Procedure Access Table 2-7. External Procedure Summary Subroutine Description SWTUSER The SWTUSER entry point restores the bank of the user's calling program. There are no parameters passed or returned. The purpose of SWTUSER is to enable BIOS disk read and write code to transfer data from a disk controller or buffer in common memory to/from the DMA buffer in the user' s calling program. This procedure must be called only from common memory, that is above the COMMONBASE label, and it must be used only from BIOS disk functions. Internally the SWTUSER procedure disables and then re-enables interrupts. Thus, if you disable interrupts before calling SWTUSER they will be enabled on returning from SWTUSER. SWTSYS The SWTSYS entry point restores the bank of the BNKBDOS. There are no parameters passed or returned. The purpose of SWTSYS is to restore the bank containing the banked portion of the BDOS following the transfer of data from a disk controller or buffer in common memory to/from the DMA buffer in the user's calling program. This procedure must be called only from common memory. Internally the SWTSYS procedure disables and then re-enables interrupts. Thus, if you disable interrupts before calling SWTSYS they will be enabled on returning from SWTSYS. PDISP The PDISP entry point forces a dispatch call. It is intended to be used at the conclusion of interrupt handling when a process is to be dispatched. It is effectively a null procedure call from the point of view of the calling program. XDOS The XDOS entry point provides access to XDOS functions. XDOS functions are required f o r flag operations, queue operations and polling devices. SYSDAT The SYSDAT entry is not a true entry point, but the address of the system data page. Section 4 provides a definition of the system data page. MP/M II System Guide 2.5 Blocking and Deblocking Algorithms 2.5 Blocking and Deblocking Algorithms Upon each call to the BIOS WRITE entry point, the BDOS includes information that allows effective sector blocking and deblocking where the host disk subsystem has a sector size which is a multiple of the basic 128-byte unit. This section presents a general-purpose algorithm that can be included within your BIOS that uses the BDOS information to perform the operations automatically. Upon each call to WRITE, the BDOS provides the following information in register C: 0 deferred write sector 1 non-deferred write sector 2 deferred write to the first sector of a new data block 3 non-deferred write to the first sector of a new data block Conditions 0 and 2 occur only for permanent drives and allow deferred writes. Conditions 1 and 3 occur for non-permanent (removable) drives and force immediate (non-deferred) writes. Condition 1 also occurs on permanent drives for writes to the directory. Conditions 2 and 3 occur when a write operation is made to the first sector of a new data block. The block ing/deblock i ng algorithm does not perform physical record pre-reads if sequential writes are made to a new data block. In most cases, application programs read or write multiple 128-byte sectors in sequence, and thus there is little overhead involved in either operation when blocking and deblocking records because pre-read operations can be avoided when writing records. The blocking and deblocking algorithm is listed in Appendix B in skeletal form. The file is included on your MP/M II disk. Generally, the algorithms map all MP/M II sector read operations onto the host disk through an intermediate buffer which is the size of tile host disk sector. Throughout the program, values and variables which relate to the sector involved in a seek operation are prefixed by "sek," while those related to the host disk system are prefixed by "hst." The equate statements beginning on line 24 define the mapping between MP/M II and the host system, and must be changed if other than the sample host system is involved. The SELDSK entry point clears the host buffer flag whenever a new disk is logged-in. Note that although the SELDSK entry point computes and returns the Disk Parameter Header address, it does not physically select the host disk at this point (it is selected later at READHST or WRITEHST) . Further, SETTRK, SETSEC, and SETDMA simply store the values, but do not take any other action at this point. SECTRAN performs a trivial function of returning the physical sector number. MP/M II System Guide 2.5 Blocking and Deblocking Algorithms The principal entry points are READ and WRITE. Th e s e subroutines take the place of your previous READ and WRITE operations. The actual physical read or write takes place at either WRITEHST or READHST, where all values have been prepared: hstdsk is the host disk number, hsttrk is the host track number, and hstsec is the host sector number (which may require translation to a physical sector number) . You must insert code at this point which performs the full host sector read or write into, or out of, the buffer at hstbuf of length hstsiz. All other mapping functions are performed by the algorithms. 2.6 Common Memory Portion of the BNKXIOS Take care when selecting which XIOS code is to be placed in common memory. This section should give you some helpful guidelines. In general, all XIOS and BIOS entries (with the exception of the disk 1/0 entries) must be above the COMMONBASE subroutine entry point. Thus, the BNKXIOS enables you to place your disk drivers in a portion of code that is not in common memory. There are, however, some exceptions that affect both the code and data areas of of the disk handlers. The Disk Parameter Headers and Disk Parameter Blocks must be in common memory. The DIRBUF data structure, which is referenced by the disk parameter blocks, must reside in common memory. All disk device polling code and interrupt handlers must reside in common memory. While it is possible to place a deblocking buffer in non-common memory, it requires a sector buffer in common memory and an extra move of 128 bytes to move the data first into common memory and then into the users DMA buffer. Also, bank switching cannot be permitted while a physical DMA from a disk controller to a deblocking buffer in non-common memory is in operation. 37 SECTION 3 MP/M II XIOS 3.1 MP/M II XIOS Overview The Extended Input/Output System (XIOS) must include the hardware dependent code that polls devices, handles interrupts and performs memory management functions. The MP/M II system implementor must prepare subroutines that perform the functions described in Table 3-1, then place a jump vector containing the XIOS entry points immediately following the BIOS jump vector. Most of the XIOS subroutines need to be re entrant. The XIOS jump vector must take the following form: BIOS+33H JMP SELMEMORY SELECT MEMORY BIOS+36H JMP POLLDEVICE POLL DEVICE BIOS+39H JMP STARTCLOCK START CLOCK BIOS+3CH JMP STOPCLOCK STOP CLOCK BIOS+3FH JMP EXITREGION EXIT CRITICAL REGION BIOS+42H JMP MAXCONSOLE MAXIMUM CONSOLE NUMBER BIOS+45H JMP SYSTEMINIT SYSTEM INITIALIZATION BIOS+48H JMP IDLE IDLE PROCEDURE (Optional) 3.2 MP/M XIOS Entry Points Each jump address corresponds to a particular subroutine that performs the specific function. Table 3-1 outlines the exact responsibilities of each XIOS entry point subroutine. Table 3-1. XIOS Subroutine Summary Subroutine Function SELMEMORY The SELMEMORY subroutine identifies the segment of memory where a process is to execute. Each time a process is dispatched for execution, the operating system makes a call to this XIOS select memory procedure. If the hardware environment has memory bank select ion/protect ion, SELMEMORY can use the passed parameter to select/protect areas of memory. The passed parameter (in registers BC) is a pointer to a memory descriptor from which the memory base, size, attributes and bank of the executing process can be determined. Thus, all other regions of memory can be write-protected. 39 MP/M II System Guide 3.2 MP/M XIOS Entry Points Table 3-1. (continued) Subroutine Function MP/M II calls SELMEMORY with interrupts disabled from within the dispatcher. The SELMEMORY subroutine must not enable interrupts. This subroutine must reside abov- the COMMONBASE entry point. POLLDEVICE A polled environment can be created by coding XIOS device poll handlers. The purpose of implementing a polled environment is to avoid typical busy-wait code for device operation completion. There are also peripheral devices that may not operate efficiently under interrupts. XDOS calls the device poll handler (POLLDEVICE) with the device to be polled in the C register as a single parameter. The user-written POLLDEVICE procedure can be coded to access the device polling routines via a table that contains the addresses of the device polling procedures. An association is made between a device number to be polled and the polling procedure itself. The polling procedures must return a value of OFFH in the accumulator if the device is ready, or OOH if the device is not ready. POLLDEVICE is called from a critical region within the dispatcher; therefore, the POLLDEVICE subroutine must not enable interrups. This subroutine must reside above the COMMONBASE entry point. STARTCLOCK The STARTCLOCK and STOPCLOCK procedures eliminate unnecessary overhead for the system clock interrupt handler. The system clock provides a time base for both the real time f lag and the system tick procedure. However, the system tick procedure is needed only when where is a process on the delay list. MP/M II calls STARTCLOCK when a process enters the delay list to initiate the system tick time base (see Section 3.4). 40 MP/M II System Guide 3.2 MP/M XIOS Entry Points Table 3-1. (continued) Subroutine Function In some hardware environments, it is not possible to shut off the system time unit clock while maintaining the one-second flag used for keeping time of day. In this situation, the STARTCLOCK procedure simply sets a boolean variable to true, indicating that there is a delayed process. The clock interrupt handler can then determine if system time unit flag is to be set by testing the boolean. This subroutine must reside above the COMMONBASE entry point. STOPCLOCK When the system delay list is emptied, MP/M II calls the STOPCLOCK procedure to stop the system tick time base. This eliminates unnecessary overhead for the system clock interrupt handler. In some hardware environments, it is not possible to shut off the system time unit clock while maintaining the one second flag used for keeping time of day; that is, a single clock/timer interrupt source is used. In this situation, the STOPCLOCK procedure simply sets a boolean variable to false, indicating that there are no delayed processes. The clock interrupt handler can then determine if the system time unit flag is to be set by testing the boolean. This subroutine must reside above the COMMONBASE entry point. EXITREGION MP/M II calls the EXITREGION procedure to test a local parameter called the PREEMPT flag. If PREEMPT is true, EXITREGION leaves interrupts disabled. If PREEMPT is false, EXITREGION enables interrupts. Interrupt service routines must set the PREEMPT flag true at beginning of the interrupt handling. This procedure allows an interrupt service routine to make a flag set MP/M II system call, leaving interrupts disabled until completion of the interrupt handl ing . This subroutine must reside above the COMMONBASE entry point. 41 MP/M II System Guide 3.2 MP/M XIOS Entry Points Table 3-1. (continued) Subroutine Function MAXCONSOLE The maximum console procedure enables the calling program to determine the number of physical consoles the BIOS is capable of supporting. The number of physical consoles is returned in the A register. This subroutine must reside above the COMMONBASE entry point. SYSTEMINIT The system initialization procedure performs the required MP/M cold start initialization. The following is a typical initialization for a banked system: first, MP/M II initializes bank 0, disables interrupts and calls SYSTEMINIT. Then, SYSTEMINIT sets up interrupt jump vectors, interrupt masks, and the base page of each bank before returning to MP/M II. Finally, MP/M II enables interrupts. A typical initialization for a non-banked system would perform the same steps, but only one bank would be initialized. MP/M II disables interrupts and calls the SYSTEMINIT entry point prior to any other XIOS call. As stated above, MP/M II enables interrupts immediately upon return f rom SYSTEMINIT. This subroutine must reside above the COMMONBASE entry point. in systems with bank switched memory, it is necessary to set up the base page (OOOOH - OOFFH) within each bank of memory. Both the MPMLDR and MP/M itself assume that the base bank (bank #0) is switched in when the MPMLDR is executed. The base bank is properly initialized by MP/M prior to entering SYSTEMINIT. The information required for the initialization of other banks is provided on entry to SYSTEMINIT in the registers defined below: C MP/M debugger restart # DE MP/M entry point address for the debugger. Place a jump at the proper debugger restart location to the address contained in DE. 42 MP/M II System Guide 3.2 MP/M XIOS Entry Points Table 3-1. (continued) Subroutine Routine HL BIOS direct jump table address. Place a jump instruction at location OOOOH in each bank's base page to the address contained in HL. IDLE An IDLE process is the anchor of the process ready list. The MP/M II nucleus calls the IDLE procedure when there are no other processes ready to run. The normal IDLE procedure is a call to the dispatcher. This most efficiently serves polled d e v i c e s . If your system is entirely inter rupt-dr iven (i e . no polled devices) , you can supply your own IDLE procedure, which should be as follows: IDLE: HALT RET If you do not supply an IDLE procedure, place three bytes of zero at the BIOS +48H location. 3.3 Interrupt Service Routines The MP/M II operating system is designed to work with virtually any interrupt architecture, be it flat or vectored. The code operating at the interrupt level saves the required registers, determines the cause of the interrupt, removes the interrupting condition, sets an appropriate flag, and then forces a dispatch to take place. Be sure to use a minimum number of stack levels when saving the state of the interrupted process. This is because the interrupted application program, especially if it has been written for a CP/M environment, is not likely to provide extra stack area as a contigency for interrupts. The example Extended Input/Output Systems shown in the Appendixes illustrate a technique whereby no additional levels of stack are required beyond that of the interrupt restart itself. This technique is highly recommended. operation of the flags is described in Section 3 of the MP/M II Programmer's Guide, under the discussion of the Flag Set and Flag Wait XDOS Functions. Briefly, flags synchronize a process to an asynchronous event. In general, an interrupt service routine sets a particular flag while another process waits for the flag to be set. 43 MP/M II System Guide 3.3 Interrupt Service Routines At a logical level above the physical interrupts, the flags can be r--garded as providing 256 levels of virtual interrupts (32 flags are supported under MP/M II) . Thus, logical interrupt handlers wait on flags set by the physical interrupt handlers. This mechanism allows a common XDOS to operate on potentially all 8080, 8085 and Z80@ microcomputers, regardless of the hardware environment. As an example, consider a hardware environment with a flat interrupt structure. That is, a single interrupt level is provided and devices must be polled to determine the cause of the interrupt. Once the interrupt cause is determined, a specific flag is set indicating that that particular interrupt has occurred. At the conclusion of the interrupt processing, a jump should be made to the MP/M II dispatcher. This is done by jumping to the PDISP entry point. This jump gives the processor resource to the highest priority ready process, usually the process readied by setting the flag in the interrupt handler, and then enables interrupts before jumping to resume execution of that process. The only XDOS or BDOS call that should be made f i:om an interrupt handler is 133: Flag Set. Any other XDOS or BDOS call results in a dispatch which would then enable interrupts before the execution of the interrupt handler is completed. It is recommended that interrupts be used only for asynchronous operations such as console input or disk operation complete. In general, operations such as console output should not be interrupt driven, because the system has more elasticity when performing polled console outputs while idling, rather than incurring the dispatch overhead for each character transmitted. This is particularly true at higher baud rates. If a systein requires the execution of a return from interrupt (RETI) instruction, the interrupt handler must execute the RETI before branching to the dispatcher via the PDISP entry point. 3.4 Time Base Management The XIOS must provide two time bases: a one second flag for real time and a system tick for managing the delay list. The one second flag operation is logically separate from the system tick operation even though it may physically share the same clock/timer interrupt source. The one second flag procedure sets flag #2 at each one second of real time. MP/M II uses flag #2 to maintain a time of day clock. The system tick procedure, when enabled by STARTCLOCK, sets flag #1 at system time unit intervals. The recommended time unit is a period of 16.67 milliseconds, corresponding to a tick frequency of 60 Hz. When operating with 50 Hz, use a 20 millisecond period. MP/M II uses the system tick to manage the delay list until the delay list is empty, at which time the system tick procedure is disabled by STOPCLOCK. 44 MP/M II System Guide 3.4 Time Base Management The system tick frequency is critical because it determines the dispatch frequency for compute-bound processes. If the frequency is too high, a significant amount of system overhead is incurred by excessive dispatches. If the frequency is too low, compute-bound processes keep the CPU resource for accordingly longer periods. 45 SECTION 4 MP/M II SYSTEM FILE COMPONENTS The MP/M II system file, MPM.SYS, consists of a number of components: the system data page, the customized XIOS, the RESBDOS and BNKBDOS, the XDOS and BNKXDOS, the TMP, and the resident system processes. MPM.SYS resides in the directory with a user code of 0 and usually has the Read Only attribute. The MP/M II loader reads the MPM.SYS file into memory to bring up the MP/M II system. 4.1 System Data The system data page contains 256 bytes used by GENSYS to dynamically configure the MP/M II system. The system data page can be prepared using the GENSYS program or it can be manually prepared using DDT or SID. The Table 4-1 describes the byte assignments. Table 4-1. System Data Byte Assignments Byte Contents 000-000 Mem$top, top page of memory 001-001 Nmb$cns, number of system consoles (TMPs) 002-002 Brkpt$RST, breakpoint RST # 003-003 Add system call user stacks, boolean 004-004 Bank switched, boolean 005-005 Z80 version, boolean 006-006 banked bdos, boolean 007-007 XIOS jump table page 008-008 RESBDOS base page 009-010 CP/NET master configuration table address 011-011 XDOS base page 012-012 RSPs (BNKXIOS top+l) base page 013-013 BNKXIOS base page 014-014 BNKBDOS base page 015-015 Max$mem$seg, max memory segment number 016-047 Initial memory segment table 048-063 Breakpoint vector table, filled in by debuggers 064-079 Reserved for MP/M II 080-095 System call user stack pointer table 096-119 Reserved for MP/M II 120-121 Nmb records in MPM.SYS file 122-122 # ticks/sec 123-123 System Drive 124-124 Common Memory Base Page 125-125 Number of RSPs 126-127 Listcp array Address 128-143 Subflg, submit flag array 47 MP/M II System Guide 4.1 System Data Table 4-1. (continued) Byte Contents 144-186 Reserved for MP/M II 187-187 Max locked records/process 188-188 Max open files/process 189-190 # list items 191-192 Pointer to base of lock table free space 193-193 Total system locked records 194-194 Total system open files 195-195 Dayfile logging, boolean 196-196 Temporary file drive 197-197 Number of printers 197-241 Reserved for MP/M II 242-242 Banked XDOS base page 243-243 TMP process descriptor base 244-244 Console.dat base 245-246 BDOS/XDOS entry point 247-247 TMP.spr base 248-248 Nmbrsps, number of banked RSPs 249-249 Brsp base address 250-251 Brspl, non-resident rsp process link 252-253 Sysdatadr, XDOS internal data segment address 254-255 Rspl, resident system process link 4.2 Customized XIOS The customized XIOS is obtained either from a file named RESXIOS.SPR, or a file named BNKXIOS.SPR. The XIOS file of type SPR contains the page relocatable version of the user-customized XIOS. The standard method for the generation of the XIOS is to use the Digital Research LINK program. An alternative method is described in Section 1. 4.3 BDOS The Basic Disk Operating System (BDOS) resides in two page relocatable files named the RESBDOS and the BNKBDOS. These two files contain the console, list and disk file management code. 4.3.1 RESBDOS The file named RESBDOS.SPR is a page relocatable file containing the logical console and list handling, as well as the resident portion of the disk file system that provides an interface to the BNKBDOS. 48 MP/M II System Guide 4.3 BDOS 4.3.2 BNKBDOS The file named BNKBDOS.SPR is a page relocatable file containing the non-resident portion of the banked BDOS. 4.4 XDOS The XDOS file named XDOS.SPR is a page-relocatable file containing the priority-driven MP/M II nucleus. The nucleus contains the following code pieces: root module, dispatcher, queue management, flag management, memory management, terminal handler, terminal message process, command line interpreter, file name parser, and time base management. 4.5 Resident System Processes A file type of RSP identifies a resident system process. The RSP files distributed with MP/M II include: run-time system status display (MPMSTAT) , printer spooler (SPOOL) , abort named process (ABORT) , and a scheduler (SCHED) . At system generation time, GENSYS prompts you to select which RSPs to include in the MPM.SYS file. It is possible for the user to prepare custom resident system processes. The resident system processes must follow these rules: • The file must be page- re locatable. Page relocatable files can be generated by LINK, or by the submit files MACSPR.SUB or ASMSPR.SUB. The output file must be renamed to type RSP. • The first two bytes of the resident system process are reserved for the address of the BDOS/XDOS. Thus a resident system process can access the BDOS/XDOS by loading the two bytes at relative 0000-0001H and then performing a PCHL. • The process descriptor for the resident system process must begin at the third byte position. 4.6 Banked Resident System Processes A banked resident system process consists of two parts: a resident portion and the code for the process. The resident portion contains the process descriptor, and queues or other data structures that must be in common memory. This portion follows the rules given above for resident system processes. The presence of a banked portion is specified by setting the process descriptor memory segment index to zero rather than OFFH. The name provided in the process descriptor is used to obtain the banked portion which has a file type of BRS. 49 MP/M II System Guide 4.6 Non-Resident System Processes The second part of a banked system process is the actual code piece for the process. The rules for the BRS portion are as follows: • The file must be page relocatable. Page relocatable files can be generated by LINK, or the procedure outlined in Section 1. The output file must be renamed to type BRS. • Bytes 0000-0001H of the banked RSP are reserved for the address of the resident portion of the RSP. Thus, a banked RSP must access the BDOS/XDOS functions by indirectly loading from the two bytes at relative 0000-0001H, which point to the base of the resident portion of the RSP, which in turn contain the BDOS/XDOS entry point address. • Bytes 0002-0003H of the banked RSP must contain the initial stack pointer value for the process. Thus the stack for the banked RSP is in the banked portion of the RSP, and should be initialized such that the return address on top of the stack is the banked RSP entry point address. • Bytes 0004-OOOBH of the banked RSP must contain an ASCII name for the process. This is used for display purposes during GENSYS and MPMLDR execution. SECTION 5 SYSTEM GENERATION 5.1 GENSYS Operation MP/M II system generation consists of preparing a system data f ile and concatenating both required and optional code files to produce a file named MPM.SYS. A GENSYS program reforms these tasks and can be run under either MP/M II or CP/M. The GENSYS automates the system generation process by prompting the user for optional parameters and then prepares the MPM.SYS file. The following sample execution illustrates GENSYS operation. OA>gensys MP/M-80 V2.0 System Generation Copyright (C) 1981, Digital Research Default entries are shown in (parens). Default base is Hex, precede entry with for decimal use sYsTEM.DAT for defaults (Y) ? Top page of operating system (FF) ? Number of TMPs (system consoles) (#2) ? Number of Printers (#!) ? Breakpoint RST (06) ? Add system call user stacks (Y) ? Z80 CPU (Y) ? Number of ticks/second (#60) ? System Disk (E:) ? Temporary file drive (E:) ? Maximum locked records/process (#16) ? Total locked records/system (#32) ? Maximum open files/process (jfl6) ? Total open files/system (432) ? Bank switched memory (Y) ? Number of user memory segments (#3) ? Common memory base page (CO) ? Dayfile logging at console (Y) ? SYSTEM DAT FFOOH 0100H TMPD DAT FEOOH 0100H USERSYS STK FDOOH 0100H XIOSJMP TBL FC00H 0100H Accept new system data page entries (Y) ? RESBDOS SPR FOOOH OCOOH XDOS SPR CEOOH 2200H Select Resident System Processes: 51 MP/M II System Guide 5.1 System Generation overview SCHED RSP (N) ? ABORT RSP (N) ? y SPOOL RSP (N) ? y MPMSTAT RSP (N) ? y ABORT RSP CDOOH 0100H SPOOL RSP CCOOH 0100H MPMSTAT RSP CBOOH 0100H BNKXIOS SPR B800H 1300H BNKBDOS SPR 9500H 2300H BNKXDOS SPR 9200H 0300H TMP SPR 8FOOH 0300H SPOOL BRS 8700H 0800H MPMSTAT BRS 7900H OEOOH LCKLSTS DAT 7700H 0200H CONSOLE DAT 7500H 0200H Enter memory segment table: Base,size,attrib,bank (75,8B,80,00)? Base,size,attrib,bank (00,CO,00,01) ? Base,size,attrib,bank (00,CO,00,02) ? Base,size,attrib,bank (00,CO,00,03) ? 00,ff,0,0 *** Memory conflict - segment trimmed Base,size,attrib,bank (00,75,00,00)? MP/M II Sys 7500H 8BOOH Bank 00 Memseg Usr OOOOH COOOH Bank 01 Memseg Usr OOOOH COOOH Bank 02 Memseg Usr OOOOH 7500H Bank 00 Accept new memory segment table entries (Y) ? ** GENSYS DONE ** 5.2 System Generation Parameters This section discusses the issues involved in answering each of the GENSYS queries shown in the example above. 5.2.1 Defaults The GENSYS program displays default entry values within parentheses. The base is hex unless a # character preceeds the value to indicate a decimal base. The initial prompt determines if the internal GENSYS defaults are to be used, or those of the most recently generated SYSTEM.DAT file. 52 MP/M II System Guide 5.2 System Generation Parameters 5.2.2 Top Page of operating System Enter two hex ASCII digits to give the top page of the operating system. The highest address used by MP/M II is XXFFH, where XX is the entry. 5.2.3 Number of System Consoles This entry determines the number of system consoles for which Terminal Message Processes (TMP's) are created to generate user prompts and send command lines to the Command Line Interpreter (CLI). A region of common memory called TMPD.DAT is reserved for the TMP process descriptors. Four TMP process descriptors can be placed in each page of the TMPD.DAT. Each system console also requires 256 bytes of memory for stack and buffer areas in a non resident region of memory called CONSOLE.DAT. MP/M II supports up to a maximum of 16 character 1/0 console devices, of which 8 can be system consoles and have associated TMPs. During MP/M II initialization, an XIOS call obtains the actual maximum number of physical consoles supported by the XIOS. This number is used if it is less than the number specified during the GENSYS. 5.2.4 Number of Printers This entry determines the number of physical printers which the XIOS is capable of supporting. This number is used by the MPMSTAT program when it displays the status of the system printers. 5.2.5 Breakpoint RST Enter the breakpoint restart number to be used by the MP/M debuggers. Recommended restarts are RST #1 to RST #6. 5.2.6 System Call User Stacks If you want to execute CP/M *.COM files, enter yes. An affirmative response forces a stack switch to occur when system calls are made from a user program. BDOS calls require more stack space unde r MP/M I I than unde r CP/M. An af f i rmat ive response causes GENSYS to allocate a region of common memory called USERSYS.STK. The size of this region is determined by the number of user memory segments, where 0-3 segments require 100h bytes and 4-7 segments require 200h bytes. Note that this affects BDOS calls only, not XDOS calls. The XDOS is re-entrant and performs no stack switching. Therefore, if your program makes any XDOS calls, you need to make certain that you have allocated sufficient stack. 53 MP/M II System Guide 5.2 System Generation Parameters 5.2.7 Z80 CPU An affirmative response should only be made if you do have a Z80 CPU. If specified, the MP/M II dispatcher saves and restores the Z80 alternate register set. 5.2.8 Number of Ticks / Second This entry value can be used by applications programs to determine the number of ticks per second. This value may vary among MP/M II systems. 5.2.9 System Disk The drive entered here is used for a second search if the file requested to the CLI is not found on the default drive. 5.2.10 Temporary File Drive The drive entered here is used as the drive for temporary disk files. This entry is used by SUBMIT when it generates the $n$.SUB temporary file. This entry can also be accessed in the system data page by application programs as the drive on which to create temporary files. 5.2.11 Maximum Locked Records / Process This entry specifies the maximum number of records that a single process (usually one program) can lock at any given time. This number can range from 0 to 255 and must be less than or equal to the total locked records for the system. 5.2.12 Total Locked Records / System This entry specifies the total number of locked records for all the processes executing under MP/M II at any given time. This number can range from 0 to 255 and should be greater than or equal to the maximum locked records per process. It is possible to allow each process to either use up the total system lock record space, or to allow each process to lock only a fraction of the system total. The first technique implies a dynamic storage region in which one process can force other processes to block because it has consumed all available resources. MP/M II System Guide 5.2 System Generation Parameters 5.2.13 Maximum Open Files / Process This entry specifies the maximum number of files that a single process (usually one program) can open at any given time. This number can range from 0 to 255 and must be less than or equal to the total open files for the system. 5.2.14 Total Open Files / System This entry specifies.the total number of open files for all the processes executing under MP/M II at any given time. This number can range from 0 to 255 and should be greater than or equal to the maximum open files per process. It is possible either to allow each process to use up the total system open file space, or to allow each process to only open a fraction of the system total. The first technique implies a dynamic storage region in which one process can force other processes to block because it has consumed all available resources. 5.2.15 Bank Switched Memory If your system does not have bank-switched memory, then you should respond with a "No'. otherwise respond with a "Y" and additional questions and responses (as shown in Section 5.2.2) are required. 5.2.16 Number of User Memory Segments The number of user memory segments must be in the range 1 to 7 and should be greater than or equal the number of system consoles. 5.2.17 Common Memory Base Page In response to this prompt, enter the address of the lowest page of memory common to all banks. GENSYS checks that all modules requiring residence in common memory are located above this address. 5.2.18 Dayfile Logging at Console An affirmative response causes the generated MP/M 11 system to display the current time, file name and type, and user number of each executed command file. MP/M II System Guide 5.2 System Generation Parameters 5.2.19 Accept System Data Page Entries If the entries made for the first 16 queries are acceptable, then enter yes. Otherwise, any or all of the entries made can be changed by re-cycling through the GENSYS queries, entering a carriage return where values are not to be changed. 5.2.20 Select Resident System Processes GENSYS searches the directory for all files of type RSP. Each file found is listed and included in the generated system file if you respond with a "Y". Tests are performed to make certain that the specified RSPF reside at or above the common base address. 5.2.21 Memory Segment Table Memory segmentation is defined by the entries which are made. You are prompted for the base, size, attributes, and bank for each memory segment. The GENSYS program only allows you to enter the number of segments specified in the response to the query regarding the number of user memory segments. The first default entry made is for the operating system. This becomes the segment zero entry in the memory segment table. It is switched in during the banked MP/M II execution of the BNKXIOS, BRS's, and the BNKBDOS. The first entry is not counted in your number of user memory segments. A significant amount of error checking is performed using a memory bit map to ensure that no memory segments overlap each other. It will be possible to customize the GENSYS program such that non existent memory for a particular hardware configuration is pre allocated in the bit map. The order of entries in the memory segment table is also critical. The first entry is reserved for the operating system. The remaining entries can be specified by user. In specifying the user memory segments, the absolute TPA regions (segments based at OOOOH) should be specified in order of size, from the largest to the smallest. Entering the segments in this order causes the MP/M II memory manager to allocate the largest available TPA region for execution by a COM program because it linearly searchs through the memory segment table for the first available segment based at zero. The ordering of relocatable segments (those not based at OOOOH) is not critical because the MP/M II memory manager does a best fit for those segments. The attribute byte is normally defined as 00. However, if you wish to pre-allocate a memory segment, specify a value of FFH. The bank byte value is an index which can be used by the XIOS to obtain a value to be sent to the bank switching hardware to select the specified bank. Values of 0,1,2,... are used to identify 56 MP/M II System Guide 5.2 System Generation Parameters the memory banks. A bank byte value of 0 is used for the non resident portion of MP/M II. 5.2.22 Accept Memory Segment Table A negative response to this query allows memory segment entries to be re-edited prior to acceptance. 5.3 GENSYS Execution The GENSYS program has an automatic mode which simplifies repetitive generation of MPM.SYS files. This is useful in a debug mode of testing, XIOS editing, and a subsequent GENSYS execution to produce a new MPM.SYS file. The automatic mode is specified as follows: OA>GENSYS $A The effect of the automatic mode is to simulate the entry of a for each GENSYS query. 57 I SECTION 6 MP/M LOADER 6.1 MP/K Loader Operation and Display The MPMLDR program loads the MPM.SYS file and branches to the execution address of the MP/M II operating system. MPMLDR can be run under CP/M or loaded from the first two tracks of a disk by the cold start loader. The MPMLDR displays system loading and configuration. It does not require any operator interaction. In the following example, the MPM.SYS file prepared by the first GENSYS example shown in Section 5 is loaded into memory and executed. MP/M-II V2.0 Loader Copyright (C) 1981, Digital Research Nmb of consoles = 2 Breakpoint RST # = 6 Z80 Alternate register set saved/restored by dispatcher Memory Segment Table: SYSTEM DAT FFOOH 0100H TMPD DAT FEOOH 0100H USERSYS STK FDOOH 0100H XIOSJMP TBL FCOOH 0100H RESBDOS SPR FOOOH OCOOH XDOS SPR CEOOH 2200H ABORT RSP CDOOH 0100H spool RSP CCOOH 0100H MPMSTAT RSP CBOOH 0100H BNKXIOS SPR B800H 1300H BNKBDOS SPR 9500H 2300H BNKXDOS SPR 9200H 0300H TMP SPR 8FOOH 0300H Spool BRS 8700H 0800H Mpmstat BRS 7900H OEOOH LCKLSTS DAT 7700H 020011 CONSOLE DAT 7500H 0200H ------------------------- MP/M II Sys 7500H 8BOOH Bank 0 Memseg Usr OOOOH COOOH Bank 1 Memseg Usr OOOOH COOOH Bank 2 Memseg Usr OOOOH 7500H Bank 0 MP/M II V2.0 Copyright (C) 1981, Digital Research OA> 59 MP/M II System Guide 6.2 MPMLDR Execution 6.2 MPMLDR Execution Two parameters may be specified to the MPMLDR. The first parameter is used to cause a break to a CP/M debugger after the loading is completed. The parameter is a $Bn character string placed in the default FCB filename field beginning at 005DH. The character n is the CP/M debugger restart number. If n is not entered, a default of 7 is used. An example of this parameter is shown in Section 1.4. The second parameter can specify an alternate filename for loading other than the standard MPM.SYS file. This parameter is specified by placing a filename with a filetype of SYS in the default FCB beginning at 005CH, or, if the $Bn parameter is also being specified, in the second default FCB beginning at 006CH. A good application of this second parameter would be to incorporate a menu-driven SYS file selection in the LDRBIOS at the SELDSK entry point. Thus, the operator would be prompted to select the appropriate SYS file for his MP/M environment. Custom code at the SELDSK entry point would prompt the operator for a file name and then place the selected SYS file name into the default FCB beginning at 005CH. 60 APPENDIX A DISK DEFINITION MACRO MP/M II V2.0 disk re-definition library Copyright (c) 1979, 1980, 1981 Digital Research Box 579 Pacific Grove, CA 93950 MP/M II logical disk drives are defined using the macros given below, where the sequence of calls is: disks n diskdef parameter-list-0 diskdef parameter-list-1 diskdef parameter-list-n endef where n is the number of logical disk drives attached to the MP/M II system, and parameter-list-i defines the characteristics of the ith drive (i=0,l,...,n-1) each parameter-list-i takes the form dn,fsc,lsc,[skfl,bls,dks,dir,cks,ofs,[kl6j,[prm] where dn is the disk number 0,1, ,n-1 fsc is the first sector number (usually 0 or 1) lsc is the last sector number on a track skf is optional "skew factor" for sector translate bls is the data block size (1024,2048, ,16384) dks is the disk size in bls increments (word) dir is the number of directory elements (word) cks is the number of dir elements to chE-,cksum ofs is the number of tracks to skip (word) k16 is an optional 0 which forces 16K/directory entry prm is an optional 0 which marks drive as permanent for convenience, the form dn,dm defines disk dn as having the same characteristics as • previously definad disk dm. • standard four drive MP/M II system is defined by disks 4 diskdef 0,1,26,6,1024,243,64,64,2 dsk set 0 rept 3 I MP/M II System Guide Appendix A Disk Def Macro dsk set dsk+l diskdef %dsk,O endm endef the value of "begdat" at the end of assembly defines the beginning of the uninitialize ram area above the bios, while the value of "enddat" defines the next location following the end of the data area. the size of this area is given by the value of "datsiz" at the end of the assembly. note that the allocation vector will be quite large if a large disk size is defined with a small block size. dskhdr macro dn define a single disk header list dpe&dn: dw x1t&dn,0000h ;translate table dw 0000h,0000h ;scratch area dw dirbuf,dpb&dn ;dir buff,parm block dw csv&dn,alv&dn ;check, alloc vectors endm disks macro nd define nd disks ndisks set nd ;;for later reference dpbase equ $ ;base of disk parameter blocks generate the nd elements dsknxt set 0 tept nd dskhdr 00-dsknxt dsknxt set dsknxt+l endm endm dpbhdr macro dn dpb&dn equ $ ;disk parm block endm ddb macro data,comment define a db statement db data comment endm ddw macro data,comment define a dw statement dw data comment endm gcd macro m,n greatest common divisor of m,n produces value gcdn as result (used in sector translate table generation) gcdm set m ;;variable for m gcdn set n ;;variable for n gcdr set 0 ;;variable for r MP/M II System Guide Appendix A Disk Def Macro rept 65535 gcdx set ycdm/gcdn gcdr set 9cdm gcdx*gcdn if gcdr 0 ex i tm endif gcdm set gcdn gcdn set gcdr endm endm diskdef macro dn,fsc,lsc,skf,bls,dks,dir,cks,ofs,kl6 generate the set statements for later tables cksz set (cks)/4 if nul Isc current disk dn same as previous fsc dpb&dn equ dpb&fsc ;equivalent parameters als&dn equ als&fsc ;same allocation vector size css&dn equ css&fsc ;same checksum vector size xlt&dn equ xlt&fsc ;same translate table else secmax set lsc-(fsc) ;;sectors 0 secmax sectors set secmax+l;;nurnber of sectois als&dn set (dks)/8 ;;size of allocation vector if ((dks) mod 8) ne 0 als&dn set als&dn+l end i f css&dn set cksz ;;number of checksum elements generate the block shift value blkval set bls/128 ;;number of sectors/block blkshf set 0 ;;counts right O's in blkval blkmsk set 0 ;;fills with l's from right rept 16 ;;once for each bit position if blkval=l exitm endif otherwise, high order 1 not found yet blkshf set blkshf+l blkmsk set (blkmsk shl 1) or 1 blkval set blkval/2 endm generate the extent mask byte blkval set bls/1024 ;;number of kilobytes/block extmsk set 0 ;;fill from right with l's rept 16 if blkval=l ex i tni endif otherwise more to shift extiiisk set (extinsk shl 1) or I blkval set blkval/2 endm may be double byte allocation if (dks) > 256 extmsk set (extmsk shr 1) 63 MP/M II System Guide Appendix A Disk Def Macro endif may be optional [0] in last position if not nul k16 extmsk set k16 endif now generate directory reservation bit vector dirrem set dir ;;# remaining to piocess dirbks set bls/32 ;;number of entries per block dirblk set 0 ;;fill with l's on each loop rept 16 if dirrem=0 exitm endif riot complete, iterate once again shift right and add I high order bit dirblk set (dirblk shr 1) or 8000h if dirrem > dirbks dirrem set dirrem-ditbks else dirrem set 0 endif endm dpbhdr dn ;;generate equ $ ddw %sectors,<;sec per track> ddb %blkshf,<;block shift> ddb %blkmsk,<;block mask> ddb %extmsk,<;extnt mask> ddw %(dks)-l,<;disk size-l> ddw %(dir)-l,<;directory max> ddb %dirblk shr 8,<;allocO> ddb %dirblk and Offh,<;allocl> if nul prm ddw %(cks)/4,<;check size> else ddw 8000h+cksz,<;permanent disk with check size> end i f ddw %ofs,<;offset> generate the translate table, if requested if nul skf xlt&dn equ 0 ;no x1ate table else if skf = 0 xlt&dn equ 0 ;no x1ate table t~lse generate the translate table nxtsec set 0 ;;next sector to fill nxtbas set 0 ;;moves by one on overflow gcd %sectors,skf gcdn = gcd(sectors,skew) neltst set sectors/gcdn neltst is number of elements to generate before we overlap previous elements nelts set neltst ;;counter xlt&dn equ $ ;translate table rept sectors ;;once for each sector MP/M II System Guide Appendix A Disk Def Macro if sectois < 256 ddb %nxtsec+(fsc) clse ddw %nxtsec+(fsc) endif nxtsec set nxtsec+(skf) if nxtsec >= sectors nxtsec set nxtsec-sectors endif nelts set nelts-1 if nelts = 0 nxtbas set nxtbas+l nxtsec set nxtbas nelts set neltst endif endm endif ;;end of nul fac test endif ;;end of nul bls test endm defds macro lab,space lab: ds space andm lds macro lb,dn,val defds lb&dri,%val&dn endm endef macro generate the necessary ram data areas begdj;t equ $ dirbuf: ds 128 ;directory access buffer dsknxt set 0 rept ndisks ;;once for each disk lds alv,%dsknxt,als lds csv,%dsknxt,css dsknxt set dsknxt+l t=ndm enddat equ $ datsiz equ $-begdat force: db 0 ;force out last byte in hex file endm APPENDIX B SECTOR DEBLOCKING ALGORITHMS FOR MP/M II page 0 Sector Deblocking Algorithms for MP/M II V2.0 utility macro to compute sector mask smask macro hblk compute log2(liblk), return ex as result (2 ** @x = hblk on return) @y set hblk @x set 0 count right shifts of @y until = 1 rept 8 if @Y = 1 exitm endif @y is not 1, shift right one position @y set @y shr 1 @x set @x + 1 endm endm MP/M to host disk constants 0800 = blksiz equ 2048 ;MP/M allocation size 0200 = hstsiz equ 512 ;host disk sector size 0014 = hstspt equ 20 ;host disk sectors/trk 0004 = hstblk equ hstsiz/128 ;MP/M sects/host buff 0050 = cpmspt equ hstblk * hstspt ;MP/M sectors/track 0003 = secnisk equ hstblk-1 ;sector mask smask hstblk ;compute sector mask 0002 = secshf equ @x ;log2(hstblk) BDOS constants on entry to write 0000 = wrall equ 0 ;write to allocated 0001 = wrdir equ 1 ;write to directory 0002 = wrual equ 2 ;write to unallocated MP/M II System Guide Appendix B Sector Deblocking The BDOS entry points given below show the code which is relevant to deblocking only. DISKDEF macro, or hand coded tables go here 0000 dpbase equ $ ;disk param block bc-Ise boot: wboot: ;enter here on system boot to initialize 0000 AF xra a ;0 to accumulator 0001 326901 sta hstact ;host buffer inactive 0004 326BOl sta unacnt ;clear unalloc count 0007 C9 ret home: ;home the selected disk 0008 3A6AO1 lda hstwrt ;checkfor pending writ( OOOB B7 ora a OOOC C21200 jnz homed OOOF 326901 sta hstact ;clear host active flag homed: 0012 C9 r C- t seldsk: ;select disk 0013 79 r(lov a,c ;selected disk number 0014 326001 sta sekdsk ;seek disk number 0017 6F Mov l,a ;disk number to HL 0018 2600 mvi 11,0 rept 4 ;multiply by 16 d a d h endm 001A+29 DAD H 001B+29 DAD H 001C+29 DAD H 001D+29 DAD H 001E 110000 lxi d,dpbase ;baseof parm block 0021 19 dad d ;hl=.dpb(curdsk) 0022 C9 ret settrk: ;set track given by registers BC 0023 60 mov h,b 0024 69 mov l'c 0025 226101 shld sektrk ;track to seek 0028 C9 ret setsec: ;set sector given by register c 0029 79 mov a,c 002A 326301 sta seksec ;sectorto seek 002D C9 ret 68 MP/M II System Guide Appendix B Sector Deblocking setdina: ;set dma address given by BC 002E 60 mov h,b 002F 69 mov 1,c 0030 227401 shld dmaadr 0033 C9 ret ;translate sector number BC 0034 60 mov h,b 0035 69 mov 1,C 0036 C9 let The READ entry point takes the place of the previous BIOS defintion for READ. read: ;read the selected MP/M sector 0037 AF xra a 0038 326BOl sta unacnt ;unacnt = 0 003B 3C inr a 003C 327201 sta readop ;read operation 003F 327101 sta rsflag ;must read &,ta 0042 3EO2 mvi a,wrual 0044 327301 sta wrtype ;treat as unalloc 0047 C3B500 imp rwoper ;to pet-form the read The WRITE entry point takes the place of the previous BIOS defintion for WRITE. write: ;write the selected MP/M sector 004A AF xra a ;0 to accumulator 004B 327201 sta readop ;not a read operation 004E 79 mov a,c ;write type in c 004F 327301 sta wrtype 0052 E602 ani wrual ;write unallocated? 0054 CA6EOO jz chkuna ;check for unalloc write to unallocated, set parameters 0057 3E10 mvi a,blksiz/128 ;next unalloc recs 0059 326BOl sta unacnt 005C 3A6001 lda sekdsk ;disk to seek 005F 326COl sta unadsk ;unadsk = sekdsk 0062 2A6101 lhld sektrk 0065 226DO1 shld unatrk ;unatrk = sectrk 0068 3A6301 lda seksec 006B 326FOl sta unasec ;unasec = seksec MP/M II System Guide Appendix B Sector Deblocking chkuna: ;check for write to unallocated sector 006E 3A6BOl lda unacnt ;any unalloc remain? 0071 B7 o r a a 0072 CAADOO jz alloc ;skip if not more unallocated records remain 0075 3D dcr a ;unacnt = unacrit-i 0076 326BOi sta unacnt 00-/9 3A6001 Ida sekdsk ;same disk? 007C 216COl lxi h,unadsk 007F BE cmp in ;sekdsk unadsk? 0080 C2ADOO jnz alloc ;skip if not disks are the same 0083 216DO1 Ixi h,unatrk 0086 CD5201 call sektrkcmp ;sektrk unatrk? 0089 C2ADOO jnz alloc ;skip if not tracks are the same 008C 3A6301 lda seksec ;same sector? 008F 216FOl lxi h,unasec 0092 BE cmp in ;seksec = unasec? 0093 C2ADOO jnz alloc ;skip if not match, move to next sector for future ref 0096 34 inr in ;Linasec = unasec+l 0097 7E mov a,m ;end of track? 0098 FE50 cpi cpmspt ;count MP/M s-ectors 009A DAA600 jc noovf ;skip if no overflow overflow to next track 009D 3600 mvi In'O ;unasec = 0 009F 2A6DOl lhld unatrk OOA2 23 inx h OOA3 226DO1 shld unatrk ;unatrk = unatrk+l noovf: ;match found, mark as unnecessary read 0OA6 AF xra a ;0 to accumulator OOA7 327101 sta rsflag ;rsflag = 0 OOAA C3B500 imp rwoper ;to perform the write alloc: ;not an unallocated record, requires pre-read OOAD AF xra a ;0 to accum OOAE 326BOl sta unacnt ;unacnt = 0 OOBl 3C inr a ;I to accum OOB2 327101 sta rsflag ;rsflag = 1 Common code for READ and WRrrE follows 70 MP/M II System Guide Appendix B Sect-or Deblocking rwoper: ;enter here to perform the read/write 0OB5 AF xra a ;zero to accum 0OB6 327001 sta erf lag ;no errors (yet) 0OB9 3A6301 ida seksec ;compute host sector rept secshf ora a ;carry = 0 r a r ;shift right endm OOBC+B7 ORA A ;CARRY = 0 00BD+1F RAR ;SHIFT RIGHT OOBE+B7 ORA A ;CARRY = 0 00BF+lF RAR ;SHIFT RIGHT OOCO 326801 sta sekhst ;host sector to seek active host sector? 0OC3 216901 lxi h,hstact ;host active flag 00C6 7E mov a'M 0OC7 3601 mvi M'l ;always becomes 1 0OC9 B7 ora a ;was it already? OOCA CAF100 jz filhst ;fill host if not host buffer active, same as seek buffer? OOCD 3A6001 lda sekdsk OODO 216401 lxi h,hstdsk ;same disk? OOD3 BE cmP m ;sekdsk = hstdsk? OOD4 C2EAOO jnz nomatch same disk, same track? OOD7 216501 lxi h,hsttrk OODA CD5201 call sektrkcmp ;sektrk = hsttrk? OODD C2EAOO jnz nomatch same disk, same track, same buffer? OOEO 3A6801 lda sekhst OOE3 216701 lxi h,hstsec ;sekhst = hstsec? OOE6 BE cmP m OOE7 CAOE01 jz match ;skip if match nomatch: ;proper disk, but not correct sector OOEA 3A6AO1 lda hstwrt ;host written? OOED B7 ora a OOEE C45EO1 cnz writehst ;clear host buff filhst: ;may have to fill the host buffer 0OF1 3A6001 lda sekdsk 0OF4 326401 sta hstdsk 0OF7 2A6101 lhld sektrk OOFA 226501 shld hsttrk OOFD 3A6801 lda sekhst 0100 326701 sta hstsec 0103 3A7101 lda rsflag ;needto read? MP/M II System Guide Appendix B Sector Deblocking 0106 B7 Ora a 0107 C45FOl cnz readhst ;yes, if I 010A AF xia a ;0 to &CCUM 010B 326AO1 sta hstwrt ;no pending write match: ;copy data to or from buffer OlOE 3A6301 lda seksec ;mask buffer number 0111 E603 ani secmsk ;least signif bits 0113 6F mov I'a ;ready to shift 0114 2600 mvi h,O ;double count rept 7 ;shift left 7 dad h endm 0116+29 DAD H 0117+29 DAD H 0118+29 DAD H 0119+29 DAD H 011A+29 DAD Ii 011B+29 DAD H OIIC+29 DAD H hl has relative host buffer address 011D 117601 lxi d,hstbuf 0120 19 dad d ;hl = host address 0121 EB xcllg ;now in DE 0122 2A7401 lhld dmaadr ;get/put MP/M data 0125 OE80 mvi c,128 ;length of move 0127 3A7201 lda readop ;which way? 012A B7 ora a 012B C23401 jnz rwmove ;skip if read write operation, mark and switch direction 012E 3EOl mvi a'l 0130 326AO1 sta hstwrt ;hstwrt = 1 0133 EB xchg ;source/dest swap rwmove: ;C initially 128, DE is source, HL is dest 0134 IA ldax d ;source character 0135 13 inx d 0136 77 mov m,a ;to dest 0137 23 inx h 0138 OD dcr c ;loop 128 times 0139 C23401 jnz rwmove data has been moved to/from host buffer 013C 3A7301 lda wrtype ;write type 013F E601 ani wrdir ;to directory? 0141 3A7001 lda erflag ;in case of errors 0144 C8 rz ;no further processing clear host buffer for directory write 0145 B7 ora a ;errors? 0146 CO rnz ;skip if so 0147 AF xra a ;0 to accum 72 MP/M II System Guide Appendix B Sector Deblocking 0148 326AOI sta hstwrt ;buffet written 014B CD5EOi call writehst 014E 3A700i lda 01flag 0151 C9 ret Utility subroutine for 16-bit compare sektrkcmp: ;HL = unatrk or hsttrk, compare with sektrk 0152 EB xchg 0153 216101 lxi h,sektrk 0150' 1A Idax d ;low byte compare 0157 BE cmp in ;same? 0158 CO rnz ;return if not low bytes equal, test high Is 0159 13 inx d 015A 23 inx 11 015B 1A ld'ax d 015C BE cmp m ;sets flags 015D C9 ret WRITEHST performs the physical write to the host disk, READHST reads the physicj,l disk. writehst: ;hstdsk = host disk hsttrk = host track ;hstsec = host sect write "hstsiz" bytes ;from hstbuf and return error flag in erflag. ;return erflag non-zero if error 015E C9 ret readhst: ;hstdsk = host disk hsttrk = host track ;hstsec = host sect read "hstsiz" bytes ;into hstbuf and return error flag in erflag. 015F C9 let Unitialized RAM data areas 0160 sekdsk: ds 1 ;seek disk number 0161 sektrk: ds 2 ;seek track riumber 0163 seksec: ds 1 ;seek sector number 0164 hstdsk: ds I ;host disk number 73 MP/M II System Guide Appendix B Sector Deblocking 0165 hSLtrk: ds 2 ;host track number 0167 hstsec: ds 1 ;host sector number 0168 sekhst: ds 1 ;seek shr secshf 0169 hstact: ds 1 ;host active flag 016A hstwrt: ds 1 ;host written flag 016B unacnt: ds 1 ;unalloc rec cnt 016C unadsk: ds 1 ;last unalloc disk 016D unatrk: ds 2 ;last unalloc track 016F unasec: ds 1 ;last unalloc sector 0170 erflag: ds 1 ;error reporting 0171 rsflag: ds 1 ;read sector flag 0172 readop: ds 1 ;l if read operation 0173 witypc: ds 1 ;write operation type 0174 dmaadr: ds 2 ;1,-,st dma address 0176 hstbuf: ds hstsiz ;host buffer The ENDEF macro invocation goes here 0376 end OOAD ALLOC 0800 BLKSIZ 0000 BOOT 006E CHKUNA 0050 CPMSPT 0174 DMAADR 0000 DPBASE 0170 ERFLAG 00Fl FILIIST 0008 HOME 0012 HOMED 0169 HSTACT 0004 HSTBLK 0176 HSTBUF 0164 HSTDSK 0167 HSTSEC 0200 HSTSIZ 0014 HSTSPT 0165 HSTTRK 016A HSTWRT 010E MATCH OOEA NOMATCH 0OA6 NOOVF 0037 READ 015F READHST 0172 READOP 0171 RSFLAG 0134 RWMOVE 0OB5 RWOPER 0003 SECMSK 0002 SECSHF 0034 SECTRAN 0160 SEKDSK 0168 SEKHST 0163 SEKSEC 0161 SEKTRK 0152 SEKTRKCMP 0013 SELDSK 002E SETDMA 0029 SETSEC 0023 SETTRK 016B UNACNT 016C UNADSK 016F UNASEC 016D UNATRK 0000 WBOOT 0000 WRALL 0001 WRDIR 004A WRITE 015E VvRITEHST 0173 WRTYPE 0002WRUAL 74 APPENDIX C SAMPLE MP/M 11 LOADER BIOS page 0 title 'Skeleton MP/M-80 V2.0 Ldrbios' Copyright (C) 1978, 1979, 1980, 1981 Digital Research Box 579, Pacific Grove California, 93950 0000 = false equ 0 FFFF = true equ riot false 1700 org 1700h 0080 = buff equ 0080h ;default buffer address jump vector for indiviual routines 1700 C33317 imp boot 1703 C33317 wboote: imp wboot 1706 C33617 imp const 1709 C33417 imp conin 170C C33517 imp conout 170F C33)917 imp list 1712 C33817 imp punch 1715 C33717 jitip reader 1718 C33C17 imp home 171B C3--')Bi7 imp seldsk 171E C33D17 imp settrk 1721 C33E17 imp setsec 1724 C33F17 imp setdma 1727 C34117 imp read 172A C34217 imp write 172D C33A17 imp list$st ; list status poll 1730 C34017 imp sect$tran ; sector translation boot: wboot: gocpm: 1733 C9 ret crtin: ; crt: input 1734 C9 ret crtout: ; crt: output 1735 C9 ret MP/M 1I System Guide Appendix C MP/M Loader BIOS crt: status 1736 C9 ret ttyin: tty: input 1737 C9 tet ttyout: tty: output 1738 C9 ret lptout: lpt: output 1739 C9 ret I.pt$st: 173A C9 ret 1734 = conin equ crtin 1736 = const equ crtst 1735 = conout equ crtout 1737 = reader equ ttyin 1738 = punch equ ttyout 1739 = list equ lptout 173A = listst equ lptst seldsk: ;select disk given by register c 173B C9 ret home: ;move to home position 173C C9 ret settrk: ;set track number given by c 173D C9 ret setsec: ;set sector number given by c 173E C9 rc-t setdma: ;set dma address given by regs b,c 17 3 F C9 r e t sect$tran: translate the sector in