1 /* -*- c -*- ------------------------------------------------------------- *
3 * Copyright 2003-2004 H. Peter Anvin - 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 * ----------------------------------------------------------------------- */
12 /* $Id: mdiskchk.c,v 1.7 2004/12/30 21:57:12 hpa Exp $ */
17 * DOS program to check for the existence of a memdisk.
19 * This program can be compiled for DOS with the OpenWatcom compiler
20 * (http://www.openwatcom.org/):
22 * wcl -3 -osx -mt mdiskchk.c
27 #include <i86.h> /* For MK_FP() */
29 typedef unsigned long uint32_t;
30 typedef unsigned short uint16_t;
31 typedef unsigned char uint8_t;
34 uint16_t bytes; /* Bytes from memdisk */
35 uint16_t version; /* Memdisk version */
36 uint32_t base; /* Base of disk in high memory */
37 uint32_t size; /* Size of disk in sectors */
38 char far * cmdline; /* Command line */
39 void far * oldint13; /* Old INT 13h */
40 void far * oldint15; /* Old INT 15h */
46 /* We add our own fields at the end */
52 struct memdiskinfo * query_memdisk(int drive)
54 static struct memdiskinfo mm;
55 uint32_t _eax, _ebx, _ecx, _edx;
57 unsigned char _dl = drive;
76 if ( _eax >> 16 != 0x4d21 ||
77 _ecx >> 16 != 0x4d45 ||
78 _edx >> 16 != 0x4944 ||
79 _ebx >> 16 != 0x4b53 )
82 memset(&mm, 0, sizeof mm);
84 bytes = *(uint16_t far *)MK_FP(_es, _di);
86 /* 27 is the most we know how to handle */
90 _fmemcpy((void far *)&mm, (void far *)MK_FP(_es,_di), bytes);
92 mm.cylinders = ((_ecx >> 8) & 0xff) + ((_ecx & 0xc0) << 2) + 1;
93 mm.heads = ((_edx >> 8) & 0xff) + 1;
94 mm.sectors = (_ecx & 0x3f);
99 const char *bootloadername(uint8_t id)
101 static const struct {
106 { 0x10, 0xf0, "LILO" },
107 { 0x20, 0xf0, "LOADLIN" },
108 { 0x31, 0xff, "SYSLINUX" },
109 { 0x32, 0xff, "PXELINUX" },
110 { 0x33, 0xff, "ISOLINUX" },
111 { 0x34, 0xff, "EXTLINUX" },
112 { 0x30, 0xf0, "SYSLINUX family" },
113 { 0x40, 0xf0, "Etherboot" },
114 { 0x50, 0xf0, "ELILO" },
115 { 0x70, 0xf0, "GrUB" },
116 { 0x80, 0xf0, "U-Boot" },
117 { 0x00, 0x00, "unknown" }
120 for ( lp = list ; ; lp++ ) {
121 if ( ((id ^ lp->id) & lp->mask) == 0 )
126 int main(int argc, char *argv[])
130 struct memdiskinfo *m;
132 for ( d = 0 ; d <= 0xff ; d++ ) {
133 if ( (m = query_memdisk(d)) != NULL ) {
134 printf("Drive %02X is MEMDISK %u.%02u:\n"
135 "\tAddress = 0x%08lx, len = %lu sectors, chs = %u/%u/%u,\n"
136 "\tloader = 0x%02x (%s),\n"
138 d, m->version >> 8, m->version & 0xff,
139 m->base, m->size, m->cylinders, m->heads, m->sectors,
140 m->bootloaderid, bootloadername(m->bootloaderid),