aboutsummaryrefslogtreecommitdiffstats
path: root/sample/fd.c
blob: ccacc30cb8738bb296626c827723dd504bb842bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* ----------------------------------------------------------------------- *
 *
 *   Copyright 2003 H. Peter Anvin - All Rights Reserved
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
 *   Boston MA 02111-1307, USA; either version 2 of the License, or
 *   (at your option) any later version; incorporated herein by reference.
 *
 * ----------------------------------------------------------------------- */

/*
 * fd.c
 *
 * Chainload a floppy disk (currently rather braindead.)
 */

#include <com32.h>
#define NULL ((void *)0)

int printf(const char *, ...);
unsigned int atou(const char *);

int __start(void)
{
  int whichfd = atou(__com32.cs_cmdline);
  static com32sys_t inreg, outreg; /* In bss, so zeroed automatically */
  int retry;

  for ( retry = 0 ; retry < 6 ; retry++ ) {
    printf(">");
    inreg.eax.w[0] = 0x0201;	/* Read one sector */
    inreg.ecx.w[0] = 0x0001;	/* Cyl 0 sector 1 */
    inreg.edx.b[1] = 0;		/* Head 0 */
    inreg.edx.b[0] = whichfd;	/* Drive number */
    inreg.es = SEG(__com32.cs_bounce); /* Read into the bounce buffer */
    inreg.ebx.w[0] = OFFS(__com32.cs_bounce);
    __com32.cs_intcall(0x13, &inreg, &outreg);

    if ( (outreg.eflags.l & 1) == 0 )
      break;
  }

  if ( (outreg.eflags.l & 1) == 0 ) {
    printf("!\n");
    inreg.eax.w[0] = 0x000d;
    inreg.edx.w[0] = 0;
    inreg.edi.l    = (uint32_t) __com32.cs_bounce;
    inreg.ecx.l    = 512;
    inreg.ebx.l    = whichfd & 0xff;
    inreg.esi.l    = 0;		/* No partitions */
    inreg.ds       = 0;		/* No partitions */
    __com32.cs_intcall(0x22, &inreg, NULL);
  }

  /* If we get here, badness happened */
  return 255;
}