david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

Merge branch 'master' of rom.etherboot.org:/pub/scm/gpxe

This commit is contained in:
Michael Brown 2007-07-03 21:09:26 +01:00
commit cbd4542dc0
10 changed files with 7 additions and 610 deletions

View File

@ -33,7 +33,7 @@ static void video_init(void)
{
static int inited=0;
vidmem = (unsigned char *)phys_to_virt(VIDBUFFER);
vidmem = (char *)phys_to_virt(VIDBUFFER);
if (!inited) {
video_line = 0;

View File

@ -1,204 +0,0 @@
#include "realmode.h"
#include "console.h"
#include "disk.h"
#include "bios_disks.h"
#warning "This file is obsolete"
#if 0
#define CF ( 1 << 0 )
#define BIOS_DISK_NONE 0
/*
* Reset the disk system using INT 13,0. Forces both hard disks and
* floppy disks to seek back to track 0.
*
*/
static void bios_disk_init ( void ) {
REAL_EXEC ( rm_bios_disk_init,
"sti\n\t"
"xorw %%ax,%%ax\n\t"
"movb $0x80,%%dl\n\t"
"int $0x13\n\t"
"cli\n\t",
0,
OUT_CONSTRAINTS (),
IN_CONSTRAINTS (),
CLOBBER ( "eax", "ebx", "ecx", "edx",
"ebp", "esi", "edi" ) );
}
/*
* Read a single sector from a disk using INT 13,2.
*
* Returns the BIOS status code (%ah) - 0 indicates success.
* Automatically retries up to three times to allow time for floppy
* disks to spin up, calling bios_disk_init() after each failure.
*
*/
static unsigned int bios_disk_read ( struct bios_disk_device *bios_disk,
unsigned int cylinder,
unsigned int head,
unsigned int sector,
struct bios_disk_sector *buf ) {
uint16_t basemem_buf, ax, flags;
unsigned int status, discard_c, discard_d;
int retry = 3;
basemem_buf = BASEMEM_PARAMETER_INIT ( *buf );
do {
REAL_EXEC ( rm_bios_disk_read,
"sti\n\t"
"movw $0x0201, %%ax\n\t" /* Read a single sector */
"int $0x13\n\t"
"pushfw\n\t"
"popw %%bx\n\t"
"cli\n\t",
4,
OUT_CONSTRAINTS ( "=a" ( ax ), "=b" ( flags ),
"=c" ( discard_c ),
"=d" ( discard_d ) ),
IN_CONSTRAINTS ( "c" ( ( (cylinder & 0xff) << 8 ) |
( (cylinder >> 8) & 0x3 ) |
sector ),
"d" ( ( head << 8 ) |
bios_disk->drive ),
"b" ( basemem_buf ) ),
CLOBBER ( "ebp", "esi", "edi" ) );
status = ( flags & CF ) ? ( ax >> 8 ) : 0;
} while ( ( status != 0 ) && ( bios_disk_init(), retry-- ) );
BASEMEM_PARAMETER_DONE ( *buf );
return status;
}
/*
* Increment a bus_loc structure to the next possible BIOS disk
* location. Leave the structure zeroed and return 0 if there are no
* more valid locations.
*
*/
static int bios_disk_next_location ( struct bus_loc *bus_loc ) {
struct bios_disk_loc *bios_disk_loc
= ( struct bios_disk_loc * ) bus_loc;
/*
* Ensure that there is sufficient space in the shared bus
* structures for a struct bios_disk_loc and a struct
* bios_disk_dev, as mandated by bus.h.
*
*/
BUS_LOC_CHECK ( struct bios_disk_loc );
BUS_DEV_CHECK ( struct bios_disk_device );
return ( ++bios_disk_loc->drive );
}
/*
* Fill in parameters for a BIOS disk device based on drive number
*
*/
static int bios_disk_fill_device ( struct bus_dev *bus_dev,
struct bus_loc *bus_loc ) {
struct bios_disk_loc *bios_disk_loc
= ( struct bios_disk_loc * ) bus_loc;
struct bios_disk_device *bios_disk
= ( struct bios_disk_device * ) bus_dev;
uint16_t flags;
/* Store drive in struct bios_disk_device */
bios_disk->drive = bios_disk_loc->drive;
REAL_EXEC ( rm_bios_disk_exists,
"sti\n\t"
"movb $0x15, %%ah\n\t"
"int $0x13\n\t"
"pushfw\n\t"
"popw %%dx\n\t"
"movb %%ah, %%al\n\t"
"cli\n\t",
2,
OUT_CONSTRAINTS ( "=a" ( bios_disk->type ),
"=d" ( flags ) ),
IN_CONSTRAINTS ( "d" ( bios_disk->drive ) ),
CLOBBER ( "ebx", "ecx", "esi", "edi", "ebp" ) );
if ( ( flags & CF ) || ( bios_disk->type == BIOS_DISK_NONE ) )
return 0;
DBG ( "BIOS disk found valid drive %hhx\n", bios_disk->drive );
return 1;
}
/*
* Test whether or not a driver is capable of driving the device.
*
*/
static int bios_disk_check_driver ( struct bus_dev *bus_dev,
struct device_driver *device_driver ) {
struct bios_disk_device *bios_disk
= ( struct bios_disk_device * ) bus_dev;
struct bios_disk_driver *driver
= ( struct bios_disk_driver * ) device_driver->bus_driver_info;
/* Compare against driver's valid ID range */
if ( ( bios_disk->drive >= driver->min_drive ) &&
( bios_disk->drive <= driver->max_drive ) ) {
driver->fill_drive_name ( bios_disk->name, bios_disk->drive );
DBG ( "BIOS disk found drive %hhx (\"%s\") "
"matching driver %s\n",
bios_disk->drive, bios_disk->name,
driver->name );
return 1;
}
return 0;
}
/*
* Describe a BIOS disk device
*
*/
static char * bios_disk_describe_device ( struct bus_dev *bus_dev ) {
struct bios_disk_device *bios_disk
= ( struct bios_disk_device * ) bus_dev;
static char bios_disk_description[] = "BIOS disk 00";
sprintf ( bios_disk_description + 10, "%hhx", bios_disk->drive );
return bios_disk_description;
}
/*
* Name a BIOS disk device
*
*/
static const char * bios_disk_name_device ( struct bus_dev *bus_dev ) {
struct bios_disk_device *bios_disk
= ( struct bios_disk_device * ) bus_dev;
return bios_disk->name;
}
/*
* BIOS disk bus operations table
*
*/
struct bus_driver bios_disk_driver __bus_driver = {
.name = "BIOS DISK",
.next_location = bios_disk_next_location,
.fill_device = bios_disk_fill_device,
.check_driver = bios_disk_check_driver,
.describe_device = bios_disk_describe_device,
.name_device = bios_disk_name_device,
};
/*
* Fill in a disk structure
*
*/
void bios_disk_fill_disk ( struct disk *disk __unused,
struct bios_disk_device *bios_disk __unused ) {
}
#endif

View File

@ -1,27 +0,0 @@
#include "console.h"
#include "disk.h"
#include "bios_disks.h"
static void fill_floppy_name ( char *buf, uint8_t drive ) {
sprintf ( buf, "fd%d", drive );
}
static struct disk_operations floppy_operations = {
};
static int floppy_probe ( struct disk *disk,
struct bios_disk_device *bios_disk ) {
return 1;
}
static void floppy_disable ( struct disk *disk,
struct bios_disk_device *bios_disk ) {
}
BIOS_DISK_DRIVER ( floppy_driver, fill_floppy_name, 0x00, 0x7f );
DRIVER ( "floppy", disk_driver, bios_disk_driver, floppy_driver,
floppy_probe, floppy_disable );

View File

@ -233,7 +233,7 @@ static const char * scancode_to_ansi_seq ( unsigned int scancode ) {
static int bios_getchar ( void ) {
uint16_t keypress;
unsigned int character;
char *ansi_seq;
const char *ansi_seq;
/* If we are mid-sequence, pass out the next byte */
if ( ( character = *ansi_input ) ) {

View File

@ -436,7 +436,7 @@ a20_done:
orb $CR0_PE, %al
movl %eax, %cr0
DATA32 ljmp %ds:(code32 - setup_code)
DATA32 ljmp *%ds:(code32 - setup_code)
code32:
.long 0x100000
.word __BOOT_CS, 0

View File

@ -25,7 +25,7 @@
* @bug Not yet implemented
*
*/
void exit_via_int19 ( struct i386_all_regs *ix86 ) {
void exit_via_int19 ( __unused struct i386_all_regs *ix86 ) {
bochsbp();
/* Placeholder */
}

View File

@ -1,289 +0,0 @@
#include <etherboot.h>
#include <disk.h>
#warning "disk.c is currently broken"
#if 0
#undef disk_disable
static int dummy(void *unused __unused)
{
return (0);
}
static unsigned char disk_buffer[DISK_BUFFER_SIZE];
struct disk disk =
{
{
0, /* dev.disable */
{
0,
0,
PCI_BUS_TYPE,
}, /* dev.devid */
0, /* index */
0, /* type */
PROBE_FIRST, /* how_probe */
PROBE_NONE, /* to_probe */
0, /* failsafe */
0, /* type_index */
{}, /* state */
},
(int (*)(struct disk *, sector_t ))dummy, /* read */
0 - 1, /* drive */
0, /* hw_sector_size */
0, /* sectors_per_read */
0, /* bytes */
0, /* sectors */
0, /* sector */
disk_buffer, /* buffer */
0, /* priv */
0, /* disk_offset */
0, /* direction */
};
static int disk_read(
struct disk *disk, unsigned char *buffer, sector_t sector)
{
int result;
sector_t base_sector;
/* Note: I do not handle disk wrap around here! */
/* Compute the start of the track cache */
base_sector = sector;
/* Support sectors_per_read > 1 only on small disks */
if ((sizeof(sector_t) > sizeof(unsigned long)) &&
(disk->sectors_per_read > 1)) {
unsigned long offset;
offset = ((unsigned long)sector) % disk->sectors_per_read;
base_sector -= offset;
}
/* See if I need to update the track cache */
if ((sector < disk->sector) ||
sector >= disk->sector + (disk->bytes >> 9)) {
twiddle();
result = disk->read(disk, base_sector);
if (result < 0)
return result;
}
/* Service the request from the track cache */
memcpy(buffer, disk->buffer + ((sector - base_sector)<<9), SECTOR_SIZE);
return 0;
}
static int disk_read_sectors(
struct disk *disk,
unsigned char *buffer,
sector_t base_sector, unsigned int sectors)
{
sector_t sector = 0;
unsigned long offset;
int result = 0;
for(offset = 0; offset < sectors; offset++) {
sector = base_sector + offset;
if (sector >= disk->sectors) {
sector -= disk->sectors;
}
result = disk_read(disk, buffer + (offset << 9), sector);
if (result < 0)
break;
}
if (result < 0) {
printf("disk read error at 0x%lx\n", sector);
}
return result;
}
static os_download_t probe_buffer(unsigned char *buffer, unsigned int len,
int increment, unsigned int offset, unsigned int *roffset)
{
os_download_t os_download;
unsigned int end;
end = 0;
os_download = 0;
if (increment > 0) {
end = len - SECTOR_SIZE;
}
do {
offset += increment;
os_download = probe_image(buffer + offset, len - offset);
} while(!os_download && (offset != end));
*roffset = offset;
return os_download;
}
static int load_image(
struct disk *disk,
unsigned char *buffer, unsigned int buf_sectors,
sector_t block, unsigned int offset,
os_download_t os_download)
{
sector_t skip_sectors;
skip_sectors = 0;
while(1) {
skip_sectors = os_download(buffer + offset,
(buf_sectors << 9) - offset, 0);
block += skip_sectors + buf_sectors;
if (block >= disk->sectors) {
block -= disk->sectors;
}
offset = 0;
buf_sectors = 1;
if (disk_read_sectors(disk, buffer, block, 1) < 0) {
return 0;
}
}
return -1;
}
int disk_probe(struct dev *dev)
{
struct disk *disk = (struct disk *)dev;
if (dev->how_probe == PROBE_NEXT) {
disk->drive += 1;
}
return probe(dev);
}
int disk_load_configuration(struct dev *dev)
{
/* Start with the very simplest possible disk configuration */
struct disk *disk = (struct disk *)dev;
disk->direction = (dev->failsafe)?-1:1;
disk->disk_offset = 0;
return 0;
}
int disk_load(struct dev *dev)
{
struct disk *disk = (struct disk *)dev;
/* 16K == 8K in either direction from the start of the disk */
static unsigned char buffer[32*SECTOR_SIZE];
os_download_t os_download;
unsigned int offset;
unsigned int len;
unsigned int buf_sectors;
volatile sector_t block;
volatile int inc, increment;
int i;
int result;
jmp_buf real_restart;
printf("Searching for image...\n");
result = 0;
/* Only check for 16byte aligned images */
increment = (disk->direction < 0)?-16:16;
/* Load a buffer, and see if it contains the start of an image
* we can boot from disk.
*/
len = sizeof(buffer);
buf_sectors = sizeof(buffer) / SECTOR_SIZE;
inc = increment;
block = (disk->disk_offset) >> 9;
if (buf_sectors/2 > block) {
block = (disk->sectors - (buf_sectors/2)) + block;
}
/* let probe buffer assume offset always needs to be incremented */
offset = (len/2 + ((disk->disk_offset) & 0x1ff)) - inc;
/* Catch longjmp so if this image fails to load, I start looking
* for the next image where I left off looking for this image.
*/
memcpy(&real_restart, &restart_etherboot, sizeof(jmp_buf));
i = setjmp(restart_etherboot);
if ((i != 0) && (i != -2)) {
memcpy(&restart_etherboot, &real_restart, sizeof(jmp_buf));
longjmp(restart_etherboot, i);
}
/* Read the canidate sectors into the buffer */
if (disk_read_sectors(disk, buffer, block, buf_sectors) < 0) {
result = -1;
goto out;
}
if (inc == increment) {
os_download = probe_buffer(buffer, len, inc, offset, &offset);
if (os_download)
goto load_image;
inc = -inc;
}
os_download = probe_buffer(buffer, len, inc, offset, &offset);
if (!os_download) {
result = -1;
goto out;
}
load_image:
printf("Loading image...\n");
result = load_image(disk, buffer, buf_sectors, block, offset, os_download);
out:
memcpy(&restart_etherboot, &real_restart, sizeof(jmp_buf));
return result;
}
int url_file(const char *name,
int (*fnc)(unsigned char *, unsigned int, unsigned int, int) __unused)
{
unsigned int drive;
unsigned long disk_offset;
int direction;
int type;
disk_offset = 0;
direction = 1;
if (memcmp(name, "disk", 4) == 0) {
type = DISK_DRIVER;
name += 4;
}
else if (memcmp(name, "floppy", 6) == 0) {
type = FLOPPY_DRIVER;
name += 6;
}
else {
printf("Unknown device type\n");
return 0;
}
drive = strtoul(name, &name, 10);
if ((name[0] == '+') || (name[0] == '-')) {
direction = (name[0] == '-')? -1 : 1;
name++;
disk_offset = strtoul(name, &name, 10);
}
if (name[0]) {
printf("Junk '%s' at end of disk url\n", name);
return 0;
}
memset(&disk, 0, sizeof(disk));
disk.buffer = disk_buffer;
disk.drive = 0;
disk.dev.how_probe = PROBE_FIRST;
disk.dev.type = type;
do {
disk_disable();
disk.dev.how_probe = disk_probe(&disk.dev);
if (disk.dev.how_probe == PROBE_FAILED) {
printf("Not that many drives\n");
return 0;
}
} while(disk.drive < drive);
disk.direction = direction;
disk.disk_offset = disk_offset;
return disk_load(&disk.dev);
}
void disk_disable(void)
{
disable(&disk.dev);
}
#endif

View File

@ -1,58 +0,0 @@
#ifndef DISK_H
#define DISK_H
#include "etherboot.h" /* for sector_t */
#include "dev.h"
/*
* Structure returned from disk_probe and passed to other driver
* functions.
*/
struct disk
{
struct dev dev; /* This must come first */
int (*read)(struct disk *, sector_t sector);
unsigned int drive;
unsigned long hw_sector_size; /* The hardware sector size for dealing
* with partition tables and the like.
* Must be >= 512
*/
unsigned int sectors_per_read; /* The number of 512 byte sectors
* returned by each read call.
* All I/O must be aligned to this size.
*/
unsigned int bytes; /* The number of bytes in the read buffer. */
sector_t sectors; /* The number of sectors on the drive. */
sector_t sector; /* The first sector in the driver buffer */
unsigned char *buffer; /* The data read from the drive */
void *priv; /* driver can hang private data here */
unsigned long disk_offset;
int direction;
};
struct disk_operations {
};
extern struct disk disk;
extern int url_file(const char *name,
int (*fnc)(unsigned char *, unsigned int, unsigned int, int));
extern int disk_probe(struct dev *dev);
extern int disk_load_configuration(struct dev *dev);
extern int disk_load(struct dev *dev);
extern void disk_disable(void);
extern struct type_driver disk_driver;
#ifndef DOWNLOAD_PROTO_DISK
#define disk_disable() do { } while(0)
#endif
#define SECTOR_SIZE 512
#define SECTOR_SHIFT 9
/* Maximum block_size that may be set. */
#define DISK_BUFFER_SIZE (18 * SECTOR_SIZE)
#endif /* DISK_H */

View File

@ -16,4 +16,7 @@ struct ramdisk {
userptr_t data;
};
int init_ramdisk ( struct ramdisk *ramdisk, userptr_t data, size_t len,
unsigned int blksize );
#endif /* _GPXE_RAMDISK_H */

View File

@ -43,34 +43,6 @@ static struct net_device * find_boot_netdev ( void ) {
return NULL;
}
/**
* Get the next network device to try
*
* @ret netdev 'Next' network device
*
* This function will cycle through all registered network devices in
* order, returning NULL.
*
* This function should be safe against registration/deregistration of
* net devices between calls to next_netdev().
*/
static struct net_device * next_netdev ( void ) {
static struct net_device *last_netdev = NULL;
struct net_device *netdev;
for_each_netdev ( netdev ) {
if ( ! last_netdev ) {
last_netdev = netdev;
return netdev;
}
if ( last_netdev == netdev )
last_netdev = NULL;
}
last_netdev = NULL;
return NULL;
}
/**
* Boot from a network device
*