extipl::Develop.txt

			 April 30, 1999

			takamiti@tsden.org
			 extipl@tsden.org
		http://www.tsden.org/takamiti/extipl/
(translation into English by Ryutaroh Matsumoto <ryutaroh@tsden.org>)

==============================================================================

1. Who This Document Is For

This document is provided for skilled programmers want to modify
existing IPLs or write their own IPL. It cannot be used easily by
everyone. Please use it at your own risk. Expected readers of this
document are those who easily read the source code of Extended-IPL.

If you make a better IPL using this package, please email to extipl@tsden.org.

1.1. Usage

You can make your own IPL with following procedure. The current directory
is assumed to be extipl/sample.

(0) Get "nasm" from http://www.web-sites.co.uk/nasm/ and install it.

(1) Write you own IPL code and save it as myipl.asm.

(2) Adding the following line to Makefile:
	myipl.bin : myipl.asm
    and do "make myipl.bin".
    Then you will get myipl.bin. This is the binary image of your IPL.

(3) Examine carefully correctness of myipl.bin, otherwise critical results
    may happen. You can get file "_BootSec" by following command.
	extipl  -d install myipl.bin
    "_BootSec" is an image which extipl tries to replace MBR with.
    You can examine the correctness with "_BootSec" in more realistic setting.

(4) Following command write your IPL to MBR of hard disk.

	extipl install myipl.bin

    If your IPL behaves as if it was loaded from hard disk when it is loaded
    from floppy disk, you can write your IPL to floppy disk by following
    command and verify correctness without changing hard disk MBR.

	extipl fdtest myipl.bin

    When installation of your IPL, extipl discards 447th and later bytes
    of myipl.bin. Note that the length of space allowed for IPL is 446 bytes
    in MBR.

2. How to compile extipl

We verified that extipl can be compiled under Linux 2.0.36, FreeBSD
2.2.8R, and 3.1R.

2.1 FreeBSD
Enter the subdirectory "src" and type "make". If make fails, try Gnu make
or modify the Makefile appropriately.

2.2 Linux
Enter the subdirectory "src" and type "make".

3. About Example

We provide an example that can do both LBA (logical block addressing)
access and traditional CHS (cylinder/head/sector) adressing access.
It consists of 
    lba_xipl.asm, lbafdsim.asm, and lba_main.asm.
Since an IPL must be smaller than 447 bytes, we omit the function
as follows.  the example cannot change the bootable partition. The
password function of DR-DOS cannot be used because of the large size
of the IPL. The error processing is not strict.

It is easy to make the example LBA access only. If so, we can put more
function into the IPL, but a problem arise when it is used for non-LBA
harddisk.

4 Technical information

4.1 Memory map
In booting procedure of IBM PC/AT compatibles, BIOS load MBR to address
0x07c00 and execute it. Extended-IPL relocates itself to 0x0600 and starts
its job. After relocation, memory map becomes as follows.

        |                      |
	^                      ^
	|----------------------|
        |                      |
	|     512 bytes        | <- Extended-IPL loads first 512 bytes of
        |                      |    booting partition here. Extended-IPL also
        |		       |    loaded here.
0x07C00 +======================+ <- upper bound of Extended-IPL stack
	|                      |             (SP register is set to 0x07c000)
	^                      ^
	|------------------55AA| <- partition validity indicator 0xAA55
0x007BE |______64_bytes________| <- partition table
        |                      |
	|     446 bytes        | <- code and data of Extended-IPL
	|                      |
0x00600 +======================+
        |                      |
	^                      ^
        |                      |
	|                      | <- interrupt vector and system reserved region
	|                      |
0x00000 +----------------------+
/////////////////////////////////////////////////////////////////////////

4.2 What Extended-IPL is doing

After Extended-IPL relocate itself to 0x0600 do the following step.

(1) See if shift key is pressed while floppy drive motor is turned on.
    If shift key is pressed, go to (3).
(2) Search partition marked active. If it is found and has partition validity
    indicator 0xaa55, go to (4.5). If active partition does not have 0xaa55,
    makes beep sound.
(3) Display partition table and "Boot#h:d.p", which indicates that the
    partition `p' in the depth `d' in the harddisk `h' is selected.
(4) Wait for keyboard input. Check pressed key in following steps.
(4.1) If key is "0", "1", "2", "3" or "4", update and display selected
      partition number and return to (4).
(4.2) If key is neither <Enter> nor <End>, make beep sound
      and return to (4).
(4.3) If the selected number is "0", load first 512 bytes of next HD to
      0x07c000 and copy partition table to 0x07be and go to (3).
(4.4) If the selected partition is an empty partition, make beep sound and
      return to (4).
(4.5) If the selected partition is an extended partition, load first
      512 bytes of the extended partition 0x07c000, copy the partition
      table to 0x07be, increase the depth, and redisplay the prompt,
       and go to (3).
(4.6) Load first 512 bytes of selected partition to 0x7c00.
	(a) If key is <Enter> or it comes from (2), check 0xaa55 and go to (5).
	(b) If key is <End>, check 0xaa55, mark selected partition
	    bootable only if the selected partition is a primary
	    partition in the first HD, and go to (5).
(5) Execute OS specific loader in first 512 bytes in selected partition by
    jump to 0x7c00. Each register has following content.
        ax, bx, cx, dh, di, bp: undefined.
	dl = BIOS drive number of OS specific loader (0x80, 0x81, ...)
    	ds = data segment of Extended-IPL
    	si = relative address of selected partition information. Let n be
    	     the selected partition number, value of si is
    	     	si = 0x07be + 16 * (n - 1)
    	     OS specific loader can get its partition information from address
    	     indicated by ds:si. Extended-IPL set bootable flag in partition 
    	     information at address ds:si.
	(note: In IBM technical information, only value of ds:si is specified.)

4.3 How Extended-IPL boots OS on non-1st hard disk

In this section we explain how Extended-IPL passes the drive number to 
OS specific loader.

A partition table is equivalent to the following structure.

	    typedef unsigned char byte;

	    typedef struct {
		byte head;
		byte sector;
		byte cyl;
	    } hd_addr;

	    typedef struct {
		byte		bootind;	<<--- active flag
		hd_addr		start;
		byte		systemind;
		hd_addr		end;
		unsigned long	start_sector;
		unsigned long	nr_sectors;
	    } partition;

If partition.bootind is 0x80, its partition is marked bootable. If it is
0x00, its partition is marked not bootable. If HD unit number is n,
Extended-IPL sets partition.bootind to 0x80 + n, then execute OS specific
loader. Thus OS specific loader can know which HD unit it resides as
the value partition.bootind & 0x7f.
