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.

bios_disks.c 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "realmode.h"
  2. #define CF ( 1 << 0 )
  3. struct disk_sector {
  4. char data[512];
  5. };
  6. /*
  7. * Reset the disk system using INT 13,0. Forces both hard disks and
  8. * floppy disks to seek back to track 0.
  9. *
  10. */
  11. static void disk_init ( void ) {
  12. REAL_EXEC ( rm_disk_init,
  13. "sti\n\t"
  14. "xorw %%ax,%%ax\n\t"
  15. "movb $0x80,%%dl\n\t"
  16. "int $0x13\n\t"
  17. "cli\n\t",
  18. 0,
  19. OUT_CONSTRAINTS (),
  20. IN_CONSTRAINTS (),
  21. CLOBBER ( "eax", "ebx", "ecx", "edx",
  22. "ebp", "esi", "edi" ) );
  23. }
  24. /*
  25. * Read a single sector from a disk using INT 13,2.
  26. *
  27. * Returns the BIOS status code (%ah) - 0 indicates success
  28. *
  29. */
  30. static unsigned int pcbios_disk_read ( int drive, int cylinder, int head,
  31. int sector, struct disk_sector *buf ) {
  32. uint16_t basemem_buf, status, flags;
  33. int discard_c, discard_d;
  34. basemem_buf = BASEMEM_PARAMETER_INIT ( *buf );
  35. REAL_EXEC ( rm_pcbios_disk_read,
  36. "sti\n\t"
  37. "movw $0x0201, %%ax\n\t" /* Read a single sector */
  38. "int $0x13\n\t"
  39. "pushfw\n\t"
  40. "popw %%bx\n\t"
  41. "cli\n\t",
  42. 4,
  43. OUT_CONSTRAINTS ( "=a" ( status ), "=b" ( flags ),
  44. "=c" ( discard_c ), "=d" ( discard_d ) ),
  45. IN_CONSTRAINTS ( "c" ( ( ( cylinder & 0xff ) << 8 ) |
  46. ( ( cylinder >> 8 ) & 0x3 ) |
  47. sector ),
  48. "d" ( ( head << 8 ) | drive ),
  49. "b" ( basemem_buf ) ),
  50. CLOBBER ( "ebp", "esi", "edi" ) );
  51. BASEMEM_PARAMETER_DONE ( *buf );
  52. return ( flags & CF ) ? ( status >> 8 ) : 0;
  53. }