1 /* ----------------------------------------------------------------------- *
3 * Copyright 2009 Shao Miller - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
16 * Routines for probing BIOS disk drives
20 * Uncomment for debugging
22 * #define DBG_DSKPROBE 1
31 * We will probe a BIOS drive numer using INT 13h, AH=probe
32 * and will pass along that call's success or failure
34 int probe_int13_ah(uint8_t drive, uint8_t probe)
39 memset(®s, 0, sizeof regs);
41 regs.eax.b[1] = probe; /* AH = probe */
42 regs.edx.b[0] = drive; /* DL = drive number to probe */
43 intcall(0x13, ®s, ®s);
45 err = !(regs.eflags.l & 1);
47 printf("probe_int13_ah(0x%02x, 0x%02x) == %d\n", drive, probe, err);
53 * We will probe the BIOS Data Area and count the drives found there.
54 * This heuristic then assumes that all drives of 'drive's type are
55 * found in a contiguous range, and returns 1 if the probed drive
56 * is less than or equal to the BDA count.
57 * This particular function's code is derived from code in setup.c by
58 * H. Peter Anvin. Please respect that file's copyright for this function
60 int probe_bda_drive(uint8_t drive)
66 bios_drives = rdz_8(BIOS_HD_COUNT); /* HDD count */
68 uint8_t equip = rdz_8(BIOS_EQUIP);
70 bios_drives = (equip >> 6) + 1; /* Floppy count */
74 err = (drive - (drive & 0x80)) >= bios_drives ? 0 : 1;
76 printf("probe_bda_drive(0x%02x) == %d, count: %d\n",
77 drive, err, bios_drives);
83 * We will probe a drive with a few different methods, returning
84 * the count of succesful probes
86 int probe_drive(uint8_t drive)
89 /* Only probe the BDA for floppies */
91 c += probe_int13_ah(drive, 0x08);
92 c += probe_int13_ah(drive, 0x15);
93 c += probe_int13_ah(drive, 0x41);
95 c += probe_bda_drive(drive);
100 * We will probe a contiguous range of BIOS drive, starting with drive
101 * number 'start'. We probe with a few different methods, and return
102 * the first drive which doesn't respond to any of the probes.
104 uint8_t probe_drive_range(uint8_t start)
106 uint8_t drive = start;
107 while (probe_drive(drive)) {
109 /* Check for passing the floppy/HDD boundary */
110 if ((drive & 0x7F) == 0)