GIDE FDISK utility
Here is a hard-disk partitioning program I wrote for the P112. The program works only with IDE disks connected to the GIDE interface, is menu-driven and provides a look and feel similar to the fdisk program of the Linux operating system. The partition table created is similar (in principle, but not in structure) to the ones used on PCs, and supports booting of different operating systems.
Upon partitioning, the program writes the partition table and a small boot loader on the very first sector of the hard disk. Up to eight partitions of any arbitrary size and type can be defined, and can be activated (marked as bootable) independently.
The boot loader is written using either the standard way, or the "new"-style (Hal Bower's) format. When the standard method is used, the boot loader is just a single sector of machine code that is loaded into memory at address 8000h, and then executed (note that this requires you to upgrade the ROM monitor accordingly). For the "new" method, two sectors are required, but the partition table is always stored within the first sector.
The booting process
The very first sector of the hard disk (C/H/S=0/0/0) contains the partition table with a primary boot loader. The loader works a bit like Linux's LILO: it scans the partition table for "active" partitions and prompts the user (if it finds more than one) for which one to boot.
After the user selects the partition to boot, the primary loader determines where the partition resides on the disk, then loads the first sector of the partition (the partition's boot sector, or secondary loader) and executes it.
With this scheme it is possible to have in a single disk up to eight partitions, each one with a different operating system (I have, for example, three CP/M 3.0 partitions and two UZI180 partitions in a 60Mb hard disk). Note that the operating system should have either built-in support for dynamic partition recognition, or at least the partition bounds hard-coded in the BIOS or similar module. At this point, only CP/M 3.0 and UZI180 are able to read the partition table and recognize existing partitions.
The standard B/P BIOS follows a different principle, the partition boundaries are stored in the BIOS, located somewhere in the boot tracks of the hard-disk. That makes it difficult for other operating systems to find partition bounds.
It is possible, of course, to use a B/P BIOS with the fdisk partitioning scheme, if the system is stored in the boot tracks of the partition preceded by a suitable loader. Right now, the primary loader does not recognize partition boot sectors of the "new" type (they don't provide the flexibility the "standard" boot sector gives), but support might be added in the future.
This scheme could be extended if necessary to support more partitions, by introducing secondary partitions much like DOS/Windows/Linux do, but that would require a rewrite of the fdisk program.
The GIDE interface is assumed to be at address 50h (the same I/O address the ROM monitor uses).
The fdisk program is normally invoked from the command line without arguments (only the master device is supported by this version):
C>fdisk P112 FDISK version 1.1 (GIDE) Hard disk geometry: As reported by the drive: 1024 cylinders, 7 heads 17 sectors Capacity: 121856 sectors (62390272 bytes) As stored in the partition table: 1024 cylinders, 7 heads 17 sectors Capacity: 121856 sectors (62390272 bytes) Display/entry units are in UZI180 tracks (16 sectors or 8192 bytes) Using standard boot sector code Command (h for help):
The very first time you run fdisk, you'll probably get a warning message telling that the disk has an invalid boot sector. Additionally, the hard disk geometry reported below the "As stored in the partition table..." line may show meaningless numbers or not appear at all. Just ignore the warnings.
Note that the display/entry units are set to "UZI180 tracks". Both UZI180 and the B/P-BIOS use the notion of a "logical track", whose size is always 16 sectors (8192 bytes). That was done for convenience, to simplify the hard disk access routines and block-to-CHS computations. The fdisk program has a 'u' option for changing the display/entry units, but it has no effect and may be removed in the future.
To get a list of the available options, enter 'h' at the prompt:
Command (h for help): h Command action b toggle a bootable flag d delete a partition h print this menu l list known partition types m toggle boot code method n add a new partition p print the partition table q quit without saving t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit Command (h for help):
To list the current partitions, the 'p' command is used:
Command (h for help): p Partition Start End Size Bytes Bootable Type --------- ----- ----- ----- -------- -------- ------ 1 1 1999 1999 16375808 Y CP/M 3.0 2 2000 3899 1900 15564800 Y UZI 3 3900 3999 100 819200 UZI swap 4 4000 5699 1700 13926400 UZI 5 5700 6699 1000 8192000 CP/M 6 6700 7499 915 7495680 CP/M Command (h for help):
Partitions are added with the 'n' command, and deleted with 'd' (see the example below). Note how the upper boundary of a partition can be specified either as an absolute cylinder number, or as a size value in cylinders, kilobytes or megabytes:
Command (h for help): d Partition number (1-8): 6 Command (h for help): n Partition number (6-8): 6 First cylinder (6700-7614, default 6700):
Partition types are entered with the 't' command. They don't really mean anything for the boot loader, they are there to make it easier for the user to identify partitions. Also, some operating systems might use that information to automatically identify swap partitions and/or other special types.
Command (h for help): t Partition number (1-8): 6 Hex code (type L to list codes): l 00 Empty 52 CP/M B2 CP/M 3.0 D1 UZI D2 UZI swap Hex code (type L to list codes): 52 Changed system type of partition 6 to 52 (CP/M) Command (h for help):
Like with Linux fdisk, you can use this program to experiment with your partition table. You can add, remove and modify partitions as many times as you want; the changes will be saved only if you use the 'w' option. If you messed up things badly, you can always quit the program with the 'q' option and the mess will not be saved.
Now, when the P112 is reset, one of the following will happen:
For example, this is my machine booting with the partition layout shown above:
SMC IO chip identified (FDC37C665IR): configuring ROM-code built: 04 Feb 2006 CPU clock: 16.000MHz RAM available: 1024kB. From 00000 to FFFFF ROM shadowed into 1st 32kB Boot partition (1,2): 1 Loading... CP/M V3.0 Loader Copyright (C) 1998, Caldera Inc. BNKBIOS3 SPR F700 0900 BNKBIOS3 SPR 8B00 3500 RESBDOS3 SPR F100 0600 BNKBDOS3 SPR 5D00 2E00 60K TPA D-X Designs P112 BIOS built 12-Apr-2006 1024K total memory GIDE C: 15976K, D: 7984K, E: 7304K RAMdisk M: 832K CP/M Version 3.0 C>
Note how CP/M 3.0 recognized the three CP/M partitions (see the partition table listing) and assigned them sequential drive letters.
Booting the second partition:
Boot partition (1,2): 2 Loading UZI... UZI180 version 1.6.1 built Sat Jan 31 12:44:22 CET 2004 Copyright (c) 1998-2002 by H.F.Bower, D.Braun, S.Nitschke, H.Peraza 1024kB total RAM, 960kB available to processes (15 processes max) hda: hda2 hda4 Mounting root fs: OK init version 0.9 Welcome to UZI180 on /dev/tty1 (Z180) login:
Here, UZI180 also recognized automatically the partitions on device hda (the line "hda: hda2 hda4"), but named them according to their position in the partition table, instead of sequentially.
The partitions can be mounted for access as usual, for example:
# mount /dev/hda4 /mnt
Last updated: 10-Feb-2007