aboutsummaryrefslogtreecommitdiffstats
path: root/com32/gpllib/disk/util.c
blob: 6faac3993b264bc6921d8600db92f1682b6609f6 (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
/* ----------------------------------------------------------------------- *
 *
 *   Copyright 2009 Pierre-Alexandre Meyer
 *
 *   Some parts borrowed from chain.c32:
 *
 *   Copyright 2003-2009 H. Peter Anvin - All Rights Reserved
 *   Copyright 2009 Intel Corporation; author: H. Peter Anvin
 *
 *   This file is part of Syslinux, and is made available under
 *   the terms of the GNU General Public License version 2.
 *
 * ----------------------------------------------------------------------- */

#include <com32.h>
#include <stdlib.h>
#include <string.h>
#include <disk/geom.h>

#define MAX_NB_RETRIES 6

/**
 * int13_retry - int13h with error handling
 * @inreg:	int13h function parameters
 * @outreg:	output registers
 *
 * Call int 13h, but with retry on failure.  Especially floppies need this.
 **/
int int13_retry(const com32sys_t *inreg, com32sys_t *outreg)
{
	int retry = MAX_NB_RETRIES;		/* Number of retries */
	com32sys_t tmpregs;

	if ( !outreg ) outreg = &tmpregs;

	while ( retry-- ) {
		__intcall(0x13, inreg, outreg);
		if ( !(outreg->eflags.l & EFLAGS_CF) )
			return 0;			/* CF=0 => OK */
	}

	/* If we get here: error */
	return -1;
}