Home | History | Annotate | Download | only in disk
      1 /* ----------------------------------------------------------------------- *
      2  *
      3  *   Copyright 2009 Pierre-Alexandre Meyer
      4  *
      5  *   Some parts borrowed from chain.c32:
      6  *
      7  *   Copyright 2003-2009 H. Peter Anvin - All Rights Reserved
      8  *   Copyright 2009 Intel Corporation; author: H. Peter Anvin
      9  *
     10  *   This file is part of Syslinux, and is made available under
     11  *   the terms of the GNU General Public License version 2.
     12  *
     13  * ----------------------------------------------------------------------- */
     14 
     15 #include <com32.h>
     16 #include <stdlib.h>
     17 #include <string.h>
     18 #include <disk/geom.h>
     19 
     20 #define MAX_NB_RETRIES 6
     21 
     22 /**
     23  * int13_retry - int13h with error handling
     24  * @inreg:	int13h function parameters
     25  * @outreg:	output registers
     26  *
     27  * Call int 13h, but with retry on failure.  Especially floppies need this.
     28  **/
     29 int int13_retry(const com32sys_t * inreg, com32sys_t * outreg)
     30 {
     31     int retry = MAX_NB_RETRIES;	/* Number of retries */
     32     com32sys_t tmpregs;
     33 
     34     if (!outreg)
     35 	outreg = &tmpregs;
     36 
     37     while (retry--) {
     38 	__intcall(0x13, inreg, outreg);
     39 	if (!(outreg->eflags.l & EFLAGS_CF))
     40 	    return 0;		/* CF=0 => OK */
     41     }
     42 
     43     /* If we get here: error */
     44     return -1;
     45 }
     46