Adding upstream version 4.00~pre54+dfsg.
[syslinux-debian/hramrach.git] / sample / fd.c
bloba1b1a51c7fc94bbef4fda12da80c2286720afc01
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2003-2008 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 * ----------------------------------------------------------------------- */
14 * fd.c
16 * Chainload a floppy disk (currently rather braindead.)
19 #include <com32.h>
20 #define NULL ((void *)0)
22 int printf(const char *, ...);
23 unsigned int atou(const char *);
25 int __start(void)
27 int whichfd = atou(__com32.cs_cmdline);
28 static com32sys_t inreg, outreg; /* In bss, so zeroed automatically */
29 int retry;
31 for (retry = 0; retry < 6; retry++) {
32 printf(">");
33 inreg.eax.w[0] = 0x0201; /* Read one sector */
34 inreg.ecx.w[0] = 0x0001; /* Cyl 0 sector 1 */
35 inreg.edx.b[1] = 0; /* Head 0 */
36 inreg.edx.b[0] = whichfd; /* Drive number */
37 inreg.es = SEG(__com32.cs_bounce); /* Read into the bounce buffer */
38 inreg.ebx.w[0] = OFFS(__com32.cs_bounce);
39 __com32.cs_intcall(0x13, &inreg, &outreg);
41 if ((outreg.eflags.l & 1) == 0)
42 break;
45 if ((outreg.eflags.l & 1) == 0) {
46 printf("!\n");
47 inreg.eax.w[0] = 0x000d;
48 inreg.edx.w[0] = 0;
49 inreg.edi.l = (uint32_t) __com32.cs_bounce;
50 inreg.ecx.l = 512;
51 inreg.ebx.l = whichfd & 0xff;
52 inreg.esi.l = 0; /* No partitions */
53 inreg.ds = 0; /* No partitions */
54 __com32.cs_intcall(0x22, &inreg, NULL);
57 /* If we get here, badness happened */
58 return 255;