|  | @@ -1,88 +1,28 @@
 | 
		
	
		
			
			| 1 |  | -#if	(TRY_FLOPPY_FIRST > 0)
 | 
		
	
		
			
			|  | 1 | +#include "console.h"
 | 
		
	
		
			
			|  | 2 | +#include "disk.h"
 | 
		
	
		
			
			|  | 3 | +#include "bios_disks.h"
 | 
		
	
		
			
			| 2 | 4 |  
 | 
		
	
		
			
			| 3 |  | -/*
 | 
		
	
		
			
			| 4 |  | - * This program is free software; you can redistribute it and/or
 | 
		
	
		
			
			| 5 |  | - * modify it under the terms of the GNU General Public License as
 | 
		
	
		
			
			| 6 |  | - * published by the Free Software Foundation; either version 2, or (at
 | 
		
	
		
			
			| 7 |  | - * your option) any later version.
 | 
		
	
		
			
			| 8 |  | - */
 | 
		
	
		
			
			| 9 |  | -
 | 
		
	
		
			
			| 10 |  | -#include "etherboot.h"
 | 
		
	
		
			
			| 11 |  | -
 | 
		
	
		
			
			| 12 |  | -#define BOOTSECT ((char *)0x7C00)
 | 
		
	
		
			
			| 13 |  | -#define BOOTSIG  ((unsigned short *)BOOTSECT)[0xFF]
 | 
		
	
		
			
			| 14 |  | -#define PARTTAB  ((partentry *)(BOOTSECT+0x1BE))
 | 
		
	
		
			
			|  | 5 | +static void fill_floppy_name ( char *buf, uint8_t drive ) {
 | 
		
	
		
			
			|  | 6 | +	sprintf ( buf, "fd%d", drive );
 | 
		
	
		
			
			|  | 7 | +}
 | 
		
	
		
			
			| 15 | 8 |  
 | 
		
	
		
			
			| 16 |  | -typedef struct partentry {
 | 
		
	
		
			
			| 17 |  | -	unsigned char flags;
 | 
		
	
		
			
			| 18 |  | -	unsigned char start_head;
 | 
		
	
		
			
			| 19 |  | -	unsigned char start_sector;
 | 
		
	
		
			
			| 20 |  | -	unsigned char start_cylinder;
 | 
		
	
		
			
			| 21 |  | -	unsigned char type;
 | 
		
	
		
			
			| 22 |  | -	unsigned char end_head;
 | 
		
	
		
			
			| 23 |  | -	unsigned char end_sector;
 | 
		
	
		
			
			| 24 |  | -	unsigned char end_cylinder;
 | 
		
	
		
			
			| 25 |  | -	unsigned long offset;
 | 
		
	
		
			
			| 26 |  | -	unsigned long length;
 | 
		
	
		
			
			| 27 |  | -} partentry;
 | 
		
	
		
			
			|  | 9 | +static struct disk_operations floppy_operations = {
 | 
		
	
		
			
			| 28 | 10 |  
 | 
		
	
		
			
			| 29 |  | -static unsigned int disk_read_retry(int dev,int c,int h,int s)
 | 
		
	
		
			
			| 30 |  | -{
 | 
		
	
		
			
			| 31 |  | -	int retry = 3,rc;
 | 
		
	
		
			
			|  | 11 | +};
 | 
		
	
		
			
			| 32 | 12 |  
 | 
		
	
		
			
			| 33 |  | -	while (retry-- && (rc = pcbios_disk_read(dev,c,h,s,BOOTSECT)) != 0);
 | 
		
	
		
			
			| 34 |  | -	if (BOOTSIG != 0xAA55) {
 | 
		
	
		
			
			| 35 |  | -		printf("not a boot sector");
 | 
		
	
		
			
			| 36 |  | -		return(0xFFFF); }
 | 
		
	
		
			
			| 37 |  | -	return(rc);
 | 
		
	
		
			
			|  | 13 | +static int floppy_probe ( struct disk *disk,
 | 
		
	
		
			
			|  | 14 | +			  struct bios_disk_device *bios_disk ) {
 | 
		
	
		
			
			|  | 15 | +	
 | 
		
	
		
			
			|  | 16 | +	return 1;
 | 
		
	
		
			
			| 38 | 17 |  }
 | 
		
	
		
			
			| 39 | 18 |  
 | 
		
	
		
			
			| 40 |  | -int bootdisk(int dev,int part)
 | 
		
	
		
			
			| 41 |  | -{
 | 
		
	
		
			
			| 42 |  | -	int rc;
 | 
		
	
		
			
			| 43 |  | -
 | 
		
	
		
			
			| 44 |  | -	disk_init();
 | 
		
	
		
			
			| 45 |  | -	if ((rc = disk_read_retry(dev,0,0,1)) != 0) {
 | 
		
	
		
			
			| 46 |  | -	readerr:
 | 
		
	
		
			
			| 47 |  | -		if (rc != 0xFFFF)
 | 
		
	
		
			
			| 48 |  | -			printf("read error (%#hhX)",rc/256);
 | 
		
	
		
			
			| 49 |  | -		return(0); }
 | 
		
	
		
			
			| 50 |  | -	if (part) {
 | 
		
	
		
			
			| 51 |  | -		partentry *ptr;
 | 
		
	
		
			
			| 52 |  | -
 | 
		
	
		
			
			| 53 |  | -		if (part >= 5) {
 | 
		
	
		
			
			| 54 |  | -			int i;
 | 
		
	
		
			
			| 55 |  | -			for (i = 0, ptr = PARTTAB; ptr->type != 5; ptr++)
 | 
		
	
		
			
			| 56 |  | -				if (++i == 4) {
 | 
		
	
		
			
			| 57 |  | -					printf("partition not found");
 | 
		
	
		
			
			| 58 |  | -					return(0); }
 | 
		
	
		
			
			| 59 |  | -			if ((rc = disk_read_retry(dev,
 | 
		
	
		
			
			| 60 |  | -						  ptr->start_cylinder,
 | 
		
	
		
			
			| 61 |  | -						  ptr->start_head,
 | 
		
	
		
			
			| 62 |  | -						  ptr->start_sector)) != 0)
 | 
		
	
		
			
			| 63 |  | -				goto readerr;
 | 
		
	
		
			
			| 64 |  | -			part -= 4; }
 | 
		
	
		
			
			| 65 |  | -		if (!(ptr = PARTTAB-1+part)->type) {
 | 
		
	
		
			
			| 66 |  | -			printf("empty partition");
 | 
		
	
		
			
			| 67 |  | -			return(0); }
 | 
		
	
		
			
			| 68 |  | -		if ((rc = disk_read_retry(dev,
 | 
		
	
		
			
			| 69 |  | -					  ptr->start_cylinder,
 | 
		
	
		
			
			| 70 |  | -					  ptr->start_head,
 | 
		
	
		
			
			| 71 |  | -					  ptr->start_sector)) != 0)
 | 
		
	
		
			
			| 72 |  | -			goto readerr; }
 | 
		
	
		
			
			| 73 |  | -	cleanup();
 | 
		
	
		
			
			| 74 |  | -	gateA20_unset();
 | 
		
	
		
			
			| 75 |  | -	/* Set %edx to device number to emulate BIOS
 | 
		
	
		
			
			| 76 |  | -	   Fortunately %edx is not used after this */
 | 
		
	
		
			
			| 77 |  | -	__asm__("movl %0,%%edx" : : "g" (dev));
 | 
		
	
		
			
			| 78 |  | -	xstart((unsigned long)BOOTSECT, 0, 0);
 | 
		
	
		
			
			| 79 |  | -	return(0);
 | 
		
	
		
			
			|  | 19 | +static void floppy_disable ( struct disk *disk,
 | 
		
	
		
			
			|  | 20 | +			     struct bios_disk_device *bios_disk ) {
 | 
		
	
		
			
			|  | 21 | +	
 | 
		
	
		
			
			| 80 | 22 |  }
 | 
		
	
		
			
			| 81 | 23 |  
 | 
		
	
		
			
			| 82 |  | -#endif
 | 
		
	
		
			
			|  | 24 | +static struct bios_disk_driver floppy_driver =
 | 
		
	
		
			
			|  | 25 | +	BIOS_DISK_DRIVER ( fill_floppy_name, 0x00, 0x7f );
 | 
		
	
		
			
			| 83 | 26 |  
 | 
		
	
		
			
			| 84 |  | -/*
 | 
		
	
		
			
			| 85 |  | - * Local variables:
 | 
		
	
		
			
			| 86 |  | - *  c-basic-offset: 8
 | 
		
	
		
			
			| 87 |  | - * End:
 | 
		
	
		
			
			| 88 |  | - */
 | 
		
	
		
			
			|  | 27 | +DRIVER ( "floppy", disk_driver, bios_disk_driver, floppy_driver,
 | 
		
	
		
			
			|  | 28 | +	 floppy_probe, floppy_disable );
 |