extipl::Develop.doc October 25 1997 takamiti@tsden.org extipl@tsden.org http://www.tsden.org/takamiti/extipl/ (translation into English by Ryutaroh Matsumoto ) ============================================================================== 1. Who This Document Is For Subdirectory "develop" has example source codes of IPL and MS-DOS batch file compiling these sources. They are provided for skilled programmers willing to modify existing IPLs or write their own IPL. They cannot be used easily by everyone. Please use them at your own risk. Expected readers of this document are 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. (1) Write you own IPL code and save it as myipl.asm. (2) Using mkipl.bat in this package, do mkipl myipl 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. If you have extipl.exe recompiled for debugging purpose (see section 4.1), you can get file "boot-sec" by following command. extipl debug myipl.bin "boot-sec" is a image which extipl.exe tries to replace MBR with. You can examine the correctness with "boot-sec" 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.exe discards 447th and later bytes of myipl.bin. Note that the length of space allowed for IPL is 446 bytes in MBR. 1.2. About Example Codes The difference between the example and boot code embedded in extipl.exe are: o Starting address of example is 0. o Boot selection of example appears with Caps-Lock key instead of shift key. 2. Technical Information 2.1 How to compile extipl.exe If you use bcc, just type "make" to compile extipl.exe. If you compile it with other C compiler, you must specify compiler to produce MS-DOS executable with tiny memory mode. You can get extipl.exe for debugging purpose compiling with -DDEBUG=1. 2.2 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 +----------------------+ ///////////////////////////////////////////////////////////////////////// 5.3 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#0:?". 0 indicates HD unit number currently selected. ? becomes partition number marked bootable. If all partition marked not bootable, ? becomes 1. (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 , or +, make beep sound and return to (4). (4.3) If current selected number is "0", load first 512 bytes of next HD to 0x07c000 and copy partition table to 0x07be and return to (3). (4.4) If current selected partition is an empty partition, make beep sound and return to (4). (4.5) Load first 512 bytes of selected partition to 0x7c00. (a) If key is or it comes from (2), check 0xaa55 and go to (5). (b) If key is , check 0xaa55 and mark selected partition bootable, then go to (5). (c) If key is +, go to (5) immediately. (5) Execute OS specific loader in first 512 bytes in selected partition by far jump to 0x7c00. Each register has following content. bx = starting address of OS specific loader (0x7c00) cx = cylinder and sector number of OS specific loader dh = head number of OS specific loader 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 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.) 2.4 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. Some OS loaders (e.g. FreeBSD's) use value of register dl as BIOS drive number of partition. These loaders successfully boot their OS from second or later HD. Another way is as follows. Each entry in partition table has 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.