syslinux-3.08-2 sources from FC4
[bootcd.git] / syslinux / sample / fd.c
1 #ident "$Id: fd.c,v 1.2 2004/12/14 22:46:25 hpa Exp $"
2 /* ----------------------------------------------------------------------- *
3  *   
4  *   Copyright 2003 H. Peter Anvin - All Rights Reserved
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9  *   Boston MA 02111-1307, USA; either version 2 of the License, or
10  *   (at your option) any later version; incorporated herein by reference.
11  *
12  * ----------------------------------------------------------------------- */
13
14 /*
15  * fd.c
16  *
17  * Chainload a floppy disk (currently rather braindead.)
18  */
19
20 #include <com32.h>
21 #define NULL ((void *)0)
22
23 int printf(const char *, ...);
24 unsigned int atou(const char *);
25
26 int __start(void)
27 {
28   int whichfd = atou(__com32.cs_cmdline);
29   static com32sys_t inreg, outreg; /* In bss, so zeroed automatically */
30   int retry;
31
32   for ( retry = 0 ; retry < 6 ; retry++ ) {
33     printf(">");
34     inreg.eax.w[0] = 0x0201;    /* Read one sector */
35     inreg.ecx.w[0] = 0x0001;    /* Cyl 0 sector 1 */
36     inreg.edx.b[1] = 0;         /* Head 0 */
37     inreg.edx.b[0] = whichfd;   /* Drive number */
38     inreg.es = SEG(__com32.cs_bounce); /* Read into the bounce buffer */
39     inreg.ebx.w[0] = OFFS(__com32.cs_bounce);
40     __com32.cs_intcall(0x13, &inreg, &outreg);
41
42     if ( (outreg.eflags.l & 1) == 0 )
43       break;
44   }
45
46   if ( (outreg.eflags.l & 1) == 0 ) {
47     printf("!\n");
48     inreg.eax.w[0] = 0x000d;
49     inreg.edx.w[0] = 0;
50     inreg.edi.l    = (uint32_t) __com32.cs_bounce;
51     inreg.ecx.l    = 512;
52     inreg.ebx.l    = whichfd & 0xff;
53     inreg.esi.l    = 0;         /* No partitions */
54     inreg.ds       = 0;         /* No partitions */
55     __com32.cs_intcall(0x22, &inreg, NULL);
56   }
57
58   /* If we get here, badness happened */
59   return 255;
60 }
61
62
63