You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

floppy.c 2.0KB

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