⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bios.c

📁 grub4dos-0.4.4-2008- 08-src.zip
💻 C
📖 第 1 页 / 共 2 页
字号:
			geometry->sectors = fd_geom[d].sectors;			geometry->cylinders = fd_geom[d].cylinders;			return 0;		}	    }	}    }#endif#ifndef STAGE1_5//      if (debug > 0)//	grub_printf ("Debug: get_diskinfo: AH=41, drive=%x ...", drive);#endif#ifndef STAGE1_5      if (debug > 1)      	grub_printf (" int13/41(%X),", drive);#endif      version = check_int13_extensions (drive);#ifndef STAGE1_5      if (debug > 1)      	grub_printf ("version=%X, ", version);#endif#ifndef STAGE1_5//      if (debug > 0)//	/* wipe out debug message. *///	grub_printf ("\r                                                                             \r");#endif//      err = 1;            /* It is safe to clear out DRP.  */      grub_memset (drp, 0, sizeof (struct drive_parameters));      /* Buggy KT133A(AWARD BIOS 6.00PG) does not return valid version.       * So we don't check version for now. - Tinybit       */      /* PhoenixBIOS 4.0 Revision 6.0 for ZF Micro might understand the	 greater buffer size for the "get drive parameters" int 13 call in 	 its own way.  Supposedly the BIOS assumes even bigger space is	 available and thus corrupts the stack. This is why we specify the  	 exactly necessary size of 0x42 bytes. */      drp->size = sizeof (struct drive_parameters) - 16;	  #ifndef STAGE1_5	  if (drive & 0x80)	  if (debug > 1)		grub_printf (" int13/48(%X),", drive);#endif#if 1	  if (drive & 0x80)	    err = biosdisk_int13_extensions (0x4800, drive, drp);	  else#endif	    err = 0;#ifndef STAGE1_5	  if (drive & 0x80)	  if (debug > 1)		grub_printf ("err=%X, C/H/S=%d/%d/%d, Sector Count/Size=%d/%d, ", err, drp->cylinders, drp->heads, drp->sectors, drp->total_sectors, drp->bytes_per_sector);#endif	  if (! err)	    {		/* Set the LBA flag.  */		if (version & 1) /* support functions 42h-44h, 47h-48h */		{			flags = BIOSDISK_FLAG_LBA_EXTENSION;	      			/* Set the CDROM flag.  */			if (drp->bytes_per_sector == ISO_SECTOR_SIZE)				flags |= BIOSDISK_FLAG_CDROM;		}		total_sectors = drp->total_sectors;	    }#ifndef STAGE1_5//      if (debug > 0)//	grub_printf ("Debug: get_diskinfo: AH=08, drive=%x ...", drive);#endif#ifndef STAGE1_5	if (debug > 1)		grub_printf (" int13/08(%X),", drive);#endif	/* Don't pass GEOMETRY directly, but pass each element instead,		 so that we can change the structure easily.  */	version = get_diskinfo_standard ((unsigned char)drive, &geometry->cylinders, &geometry->heads, &geometry->sectors);#ifndef STAGE1_5	if (debug > 1)		grub_printf ("version=%X, C/H/S=%d/%d/%d, ", version, geometry->cylinders, geometry->heads, geometry->sectors);#endif#ifndef STAGE1_5//      if (debug > 0)//	/* wipe out debug message. *///	grub_printf ("\r                                                                             \r");#endif	if (version && err)		return err; /* When we return with ERROR, we should not change the geometry!! */      	geometry->flags = flags;	geometry->sector_size = (drp->bytes_per_sector ? drp->bytes_per_sector : SECTOR_SIZE);	if (geometry->cylinders < drp->cylinders)	    geometry->cylinders = drp->cylinders;	if (geometry->heads < drp->heads)	    geometry->heads = drp->heads;	if (geometry->sectors < drp->sectors)	    geometry->sectors = drp->sectors;	if (geometry->heads > 256)	    geometry->heads = 256;	if (geometry->sectors * geometry->sector_size > 63 * 512)	    geometry->sectors = 63 * 512 / geometry->sector_size;	tmp = (unsigned long long)(geometry->cylinders) *	      (unsigned long long)(geometry->heads) *	      (unsigned long long)(geometry->sectors);	if (total_sectors < tmp)	    total_sectors = tmp;	geometry->total_sectors = total_sectors;#ifndef STAGE1_5	if (geometry->sector_size != SECTOR_SIZE) /* CD */		return 0;	/* workaround for buggy USB-bootable board QDI 848E.	 * try a further probe in the boot sector.	 */	if (debug > 1)		grub_printf (" int13/02(%X),", drive);	/* read the boot sector: int 13, AX=0x201, CX=1, DH=0 */#ifndef STAGE1_5//      if (debug > 0)//	grub_printf ("Debug: get_diskinfo: AH=02, drive=%x, C=0, H=0, S=1, nsec=1, segment=5FE0 ...", drive);#endif	err = biosdisk_standard (0x02, drive, 0, 0, 1, 1, 0x5FE0/*SCRATCHSEG*/);#ifndef STAGE1_5//      if (debug > 0)//	/* wipe out debug message. *///	grub_printf ("\r                                                                             \r");#endif	if (debug > 1)		grub_printf ("err=%X, ", err);	if (err)	{		/* try again using LBA */		if (geometry->flags & BIOSDISK_FLAG_LBA_EXTENSION)		{			struct disk_address_packet			{				unsigned char length;				unsigned char reserved;				unsigned short blocks;				unsigned long buffer;				unsigned long long block;				unsigned char dummy[16];			} __attribute__ ((packed)) *dap;			dap = (struct disk_address_packet *)0x580;			dap->length = 0x10;			dap->reserved = 0;			dap->blocks = 1;			dap->buffer = 0x5FE0/*SCRATCHSEG*/ << 16;			dap->block = 0;#ifndef STAGE1_5//      if (debug > 0)//	grub_printf ("Debug: get_diskinfo: AH=42, drive=%x, sector=0, nsec=1, segment=5FE0 ...", drive);#endif			err = biosdisk_int13_extensions (0x4200, drive, dap);#ifndef STAGE1_5//      if (debug > 0)//	/* wipe out debug message. *///	grub_printf ("\r                                                                             \r");#endif		} /* if (geometry->flags & BIOSDISK_FLAG_LBA_EXTENSION) */	}	if (err)		goto failure_probe_boot_sector;	/* successfully read boot sector */	if (drive & 0x80)	{		/* hard disk */		if ((err = probe_mbr((struct master_and_dos_boot_sector *)0x5FE00/*SCRATCHADDR*/, 0, total_sectors, 0)))		{			if (debug > 1)				grub_printf ("\nWarning: Unrecognized partition table for drive %X. Please rebuild it using\na Microsoft-compatible FDISK tool(err=%d). Current C/H/S=%d/%d/%d\n", drive, err, geometry->cylinders, geometry->heads, geometry->sectors);			goto failure_probe_boot_sector;		}		err = (int)"MBR";	}else{		/* floppy */		if (probe_bpb((struct master_and_dos_boot_sector *)0x5FE00/*SCRATCHADDR*/))		{#if 0			/* try INT13/AH=48h here. This could hang on some buggy USB BIOSes. */			/* It is safe to clear out DRP.  */			grub_memset (drp, 0, sizeof (struct drive_parameters));			drp->size = sizeof (struct drive_parameters) - 16;			if (debug > 0)				grub_printf ("\nBPB geometry probe failed, so try int13/48(%X), but this could hang on buggy USB BIOSes...", drive);			err = biosdisk_int13_extensions (0x4800, drive, drp);			if (debug > 0)				grub_printf (" err=%X, C/H/S=%d/%d/%d, Sector Count/Size=%d/%d.\n", err, drp->cylinders, drp->heads, drp->sectors, drp->total_sectors, drp->bytes_per_sector);			if (drp->heads > 0 && drp->heads <= 256 && drp->sectors > 0 && drp->sectors <= 63)			{				geometry->sectors = drp->sectors;				geometry->heads = drp->heads;				geometry->cylinders = drp->cylinders;				geometry->total_sectors = drp->cylinders * drp->heads * drp->sectors;			}			if (geometry->total_sectors < drp->total_sectors)			    geometry->total_sectors = drp->total_sectors;#endif			goto failure_probe_boot_sector;		}		err = (int)"BPB";	}	if (drive & 0x80)	if (probed_cylinders != geometry->cylinders)	    if (debug > 1)		grub_printf ("\nWarning: %s cylinders(%d) is not equal to the BIOS one(%d).\n", (char *)err, probed_cylinders, geometry->cylinders);	geometry->cylinders = probed_cylinders;	if (probed_heads != geometry->heads)	    if (debug > 1)		grub_printf ("\nWarning: %s heads(%d) is not equal to the BIOS one(%d).\n", (char *)err, probed_heads, geometry->heads);	geometry->heads	= probed_heads;	if (probed_sectors_per_track != geometry->sectors)	    if (debug > 1)		grub_printf ("\nWarning: %s sectors per track(%d) is not equal to the BIOS one(%d).\n", (char *)err, probed_sectors_per_track, geometry->sectors);	geometry->sectors = probed_sectors_per_track;	if (probed_total_sectors > total_sectors)	{	    if (drive & 0x80)	    if (debug > 1)		grub_printf ("\nWarning: %s total sectors(%d) is greater than the BIOS one(%d).\nSome buggy BIOSes could hang when you access sectors exceeding the BIOS limit.\n", (char *)err, probed_total_sectors, total_sectors);	    geometry->total_sectors	= probed_total_sectors;	}	if (drive & 0x80)	if (probed_total_sectors < total_sectors)	    if (debug > 1)		grub_printf ("\nWarning: %s total sectors(%d) is less than the BIOS one(%d).\n", (char *)err, probed_total_sectors, total_sectors);failure_probe_boot_sector:	#ifndef GRUB_UTIL#if 1	if (!(geometry->flags & BIOSDISK_FLAG_LBA_EXTENSION))	{		err = geometry->heads;		version = geometry->sectors;		/* DH non-zero for geometry_tune */		get_diskinfo_standard (drive | 0x0100, &geometry->cylinders, &geometry->heads, &geometry->sectors);		if (debug > 0)		{		    if (err != geometry->heads)			grub_printf ("\nNotice: number of heads for drive %X tuned from %d to %d.\n", drive, err, geometry->heads);		    if (version != geometry->sectors)			grub_printf ("\nNotice: sectors-per-track for drive %X tuned from %d to %d.\n", drive, version, geometry->sectors);		}	}#endif#endif	/* if C/H/S=0/0/0, use a safe default one. */	if (geometry->sectors == 0)	{		if (drive & 0x80)		{			/* hard disk */			geometry->sectors = 63;		}else{			/* floppy */			if (geometry->total_sectors > 5760)				geometry->sectors = 63;			else if (geometry->total_sectors > 2880)				geometry->sectors = 36;			else				geometry->sectors = 18;		}	}	if (geometry->heads == 0)	{		if (drive & 0x80)		{			/* hard disk */			geometry->heads = 255;		}else{			/* floppy */			if (geometry->total_sectors > 5760)				geometry->heads = 255;			else				geometry->heads = 2;		}	}	if (geometry->cylinders == 0)	{		geometry->cylinders = (geometry->total_sectors / geometry->heads / geometry->sectors);	}	if (geometry->cylinders == 0)		geometry->cylinders = 1;#endif	/* ! STAGE1_5 */  /* backup the geometry into array hd_geom or fd_geom. */#if (! defined(GRUB_UTIL)) && (! defined(STAGE1_5))    {	unsigned long j;	unsigned long d;	/* check if the drive is virtual. */	d = drive;	j = DRIVE_MAP_SIZE;		/* real drive */	if (! unset_int13_handler (1))	    for (j = 0; j < DRIVE_MAP_SIZE; j++)	    {		if (drive != hooked_drive_map[j].from_drive)			continue;		if ((hooked_drive_map[j].max_sector & 0x3F) == 1 && hooked_drive_map[j].start_sector == 0 && hooked_drive_map[j].sector_count <= 1)		{			/* this is a map for the whole drive. */			d = hooked_drive_map[j].to_drive;			j = DRIVE_MAP_SIZE;	/* real drive */		}		break;	    }	if (j == DRIVE_MAP_SIZE)	/* real drive */	{	    if (d >= 0x80 && d < 0x84)	    {		d -= 0x80;		if (hd_geom[d].sector_size != 512 || hd_geom[d].sectors <= 0 || hd_geom[d].sectors > 63 || hd_geom[d].heads > 256)		{			hd_geom[d].flags		= geometry->flags;			hd_geom[d].sector_size		= geometry->sector_size;			hd_geom[d].total_sectors	= geometry->total_sectors;			hd_geom[d].heads		= geometry->heads;			hd_geom[d].sectors		= geometry->sectors;			hd_geom[d].cylinders		= geometry->cylinders;		}	    } else if (d < 4) {		if (fd_geom[d].sector_size != 512 || fd_geom[d].sectors <= 0 || fd_geom[d].sectors > 63 || fd_geom[d].heads > 256)		{			fd_geom[d].flags		= geometry->flags;			fd_geom[d].sector_size		= geometry->sector_size;			fd_geom[d].total_sectors	= geometry->total_sectors;			fd_geom[d].heads		= geometry->heads;			fd_geom[d].sectors		= geometry->sectors;			fd_geom[d].cylinders		= geometry->cylinders;		}	    }	}    }#endif  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -