Creating a CP/M boot sector

In Andy Johnson-Laird's book "The Programmer's CP/M Handbook" the major steps of bringing up your own CP/M system are well explained and in this order:

  1. Create your new BIOS with the appropriate device drivers in it. Assemble this so that it will execute at the top of memory (and determine the start address of the OS).
  2. Create the new versions of the CCP and BDOS with all addresses inthe instructions changed so that they will be correctly located in memory just below the new BIOS. (Nowadays you can assemble this code instead of using MOVCPM)
  3. Create or modify a CP/M bootstrap loader that will be loaded by the firmware that executes when you first switch on your computer.
  4. Using Digital Research tools to bring the bootstrap loader, CCP, BDOS, and BIOS in the first tracks of the floppy. (I used my ROM monitor for this).

I skipped steps 1 and 2 because in a previous "incarnation" of the system I did it and I know it will be the not so dificult part. So I rewrote my Monitor disk read and write to be a little more "efficient" and used them in the bootstrap code.

After a RESET, the 8085 checks if there is a disk in drive. If so, seeks drive 0 (or A:) to track 0, and tries to read sector 1 (sector zero does not exist, only for historical reasons) into memory address 100H.

Then jumps to address 100H if it contains the byte value 0F3H, it is the code of a disable interrupts instruction (DI) in the 8080, 8085, z80, nsc800 family of microprocessors.

The bootstrap loader then reads the rest of operating system into memory (CCP,BDOS,BIOS) from the first track (sectors 2 and on). Then a jump is made to the cold boot function in the BIOS, then CP/M starts.

I used SIMH and CP/M 2.2 for assembling the code, I fell in a little trap with ASM. It recognizes the instructions SIM and RIM as labels not as instructions... I only found this by reading the assembler print out. I had to use a DB 30H for SIM and a DB 20H for RIM, then it worked ok.

The Boot Sector Code is posted here.

No comments: