mirror of
https://github.com/ipxe/ipxe
synced 2025-12-15 00:12:19 +03:00
BIOS floppy handling code moved to where it will really live.
This commit is contained in:
@@ -1,88 +1,28 @@
|
|||||||
#if (TRY_FLOPPY_FIRST > 0)
|
#include "console.h"
|
||||||
|
#include "disk.h"
|
||||||
|
#include "bios_disks.h"
|
||||||
|
|
||||||
/*
|
static void fill_floppy_name ( char *buf, uint8_t drive ) {
|
||||||
* This program is free software; you can redistribute it and/or
|
sprintf ( buf, "fd%d", drive );
|
||||||
* modify it under the terms of the GNU General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or (at
|
|
||||||
* your option) any later version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "etherboot.h"
|
|
||||||
|
|
||||||
#define BOOTSECT ((char *)0x7C00)
|
|
||||||
#define BOOTSIG ((unsigned short *)BOOTSECT)[0xFF]
|
|
||||||
#define PARTTAB ((partentry *)(BOOTSECT+0x1BE))
|
|
||||||
|
|
||||||
typedef struct partentry {
|
|
||||||
unsigned char flags;
|
|
||||||
unsigned char start_head;
|
|
||||||
unsigned char start_sector;
|
|
||||||
unsigned char start_cylinder;
|
|
||||||
unsigned char type;
|
|
||||||
unsigned char end_head;
|
|
||||||
unsigned char end_sector;
|
|
||||||
unsigned char end_cylinder;
|
|
||||||
unsigned long offset;
|
|
||||||
unsigned long length;
|
|
||||||
} partentry;
|
|
||||||
|
|
||||||
static unsigned int disk_read_retry(int dev,int c,int h,int s)
|
|
||||||
{
|
|
||||||
int retry = 3,rc;
|
|
||||||
|
|
||||||
while (retry-- && (rc = pcbios_disk_read(dev,c,h,s,BOOTSECT)) != 0);
|
|
||||||
if (BOOTSIG != 0xAA55) {
|
|
||||||
printf("not a boot sector");
|
|
||||||
return(0xFFFF); }
|
|
||||||
return(rc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int bootdisk(int dev,int part)
|
static struct disk_operations floppy_operations = {
|
||||||
{
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
disk_init();
|
};
|
||||||
if ((rc = disk_read_retry(dev,0,0,1)) != 0) {
|
|
||||||
readerr:
|
|
||||||
if (rc != 0xFFFF)
|
|
||||||
printf("read error (%#hhX)",rc/256);
|
|
||||||
return(0); }
|
|
||||||
if (part) {
|
|
||||||
partentry *ptr;
|
|
||||||
|
|
||||||
if (part >= 5) {
|
static int floppy_probe ( struct disk *disk,
|
||||||
int i;
|
struct bios_disk_device *bios_disk ) {
|
||||||
for (i = 0, ptr = PARTTAB; ptr->type != 5; ptr++)
|
|
||||||
if (++i == 4) {
|
return 1;
|
||||||
printf("partition not found");
|
|
||||||
return(0); }
|
|
||||||
if ((rc = disk_read_retry(dev,
|
|
||||||
ptr->start_cylinder,
|
|
||||||
ptr->start_head,
|
|
||||||
ptr->start_sector)) != 0)
|
|
||||||
goto readerr;
|
|
||||||
part -= 4; }
|
|
||||||
if (!(ptr = PARTTAB-1+part)->type) {
|
|
||||||
printf("empty partition");
|
|
||||||
return(0); }
|
|
||||||
if ((rc = disk_read_retry(dev,
|
|
||||||
ptr->start_cylinder,
|
|
||||||
ptr->start_head,
|
|
||||||
ptr->start_sector)) != 0)
|
|
||||||
goto readerr; }
|
|
||||||
cleanup();
|
|
||||||
gateA20_unset();
|
|
||||||
/* Set %edx to device number to emulate BIOS
|
|
||||||
Fortunately %edx is not used after this */
|
|
||||||
__asm__("movl %0,%%edx" : : "g" (dev));
|
|
||||||
xstart((unsigned long)BOOTSECT, 0, 0);
|
|
||||||
return(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
static void floppy_disable ( struct disk *disk,
|
||||||
|
struct bios_disk_device *bios_disk ) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
static struct bios_disk_driver floppy_driver =
|
||||||
* Local variables:
|
BIOS_DISK_DRIVER ( fill_floppy_name, 0x00, 0x7f );
|
||||||
* c-basic-offset: 8
|
|
||||||
* End:
|
DRIVER ( "floppy", disk_driver, bios_disk_driver, floppy_driver,
|
||||||
*/
|
floppy_probe, floppy_disable );
|
||||||
|
|||||||
68
src/arch/i386/include/bios_disks.h
Normal file
68
src/arch/i386/include/bios_disks.h
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
#ifndef BIOS_DISKS_H
|
||||||
|
#define BIOS_DISKS_H
|
||||||
|
|
||||||
|
#include "dev.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constants
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define BIOS_DISK_MAX_NAME_LEN 6
|
||||||
|
|
||||||
|
struct bios_disk_sector {
|
||||||
|
char data[512];
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The location of a BIOS disk
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
struct bios_disk_loc {
|
||||||
|
uint8_t drive;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A physical BIOS disk device
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
struct bios_disk_device {
|
||||||
|
char name[BIOS_DISK_MAX_NAME_LEN];
|
||||||
|
uint8_t drive;
|
||||||
|
uint8_t type;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A BIOS disk driver, with a valid device ID range and naming
|
||||||
|
* function.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
struct bios_disk_driver {
|
||||||
|
void ( *fill_drive_name ) ( char *buf, uint8_t drive );
|
||||||
|
uint8_t min_drive;
|
||||||
|
uint8_t max_drive;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define a BIOS disk driver
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define BIOS_DISK_DRIVER( _fill_drive_name, _min_drive, _max_drive ) { \
|
||||||
|
.fill_drive_name = _fill_drive_name, \
|
||||||
|
.min_drive = _min_drive, \
|
||||||
|
.max_drive = _max_drive, \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Functions in bios_disks.c
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bios_disk bus global definition
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
extern struct bus_driver bios_disk_driver;
|
||||||
|
|
||||||
|
#endif /* BIOS_DISKS_H */
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef DISK_H
|
#ifndef DISK_H
|
||||||
#define DISK_H
|
#define DISK_H
|
||||||
|
|
||||||
|
#include "etherboot.h" /* for sector_t */
|
||||||
#include "dev.h"
|
#include "dev.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -30,6 +31,9 @@ struct disk
|
|||||||
int direction;
|
int direction;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct disk_operations {
|
||||||
|
};
|
||||||
|
|
||||||
extern struct disk disk;
|
extern struct disk disk;
|
||||||
extern int url_file(const char *name,
|
extern int url_file(const char *name,
|
||||||
int (*fnc)(unsigned char *, unsigned int, unsigned int, int));
|
int (*fnc)(unsigned char *, unsigned int, unsigned int, int));
|
||||||
@@ -39,6 +43,7 @@ extern int disk_load_configuration(struct dev *dev);
|
|||||||
extern int disk_load(struct dev *dev);
|
extern int disk_load(struct dev *dev);
|
||||||
extern void disk_disable(void);
|
extern void disk_disable(void);
|
||||||
|
|
||||||
|
extern struct type_driver disk_driver;
|
||||||
|
|
||||||
#ifndef DOWNLOAD_PROTO_DISK
|
#ifndef DOWNLOAD_PROTO_DISK
|
||||||
#define disk_disable() do { } while(0)
|
#define disk_disable() do { } while(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user