VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/Etherboot-src/drivers/disk/floppy.c@ 1434

Last change on this file since 1434 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.0 KB
Line 
1#if (TRY_FLOPPY_FIRST > 0)
2
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))
15
16typedef 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;
28
29static unsigned int disk_read_retry(int dev,int c,int h,int s)
30{
31 int retry = 3,rc;
32
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);
38}
39
40int 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);
80}
81
82#endif
83
84/*
85 * Local variables:
86 * c-basic-offset: 8
87 * End:
88 */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette