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.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "realmode.h"
  2. #define CF ( 1 << 0 )
  3. /**************************************************************************
  4. DISK_INIT - Initialize the disk system
  5. **************************************************************************/
  6. void disk_init ( void ) {
  7. REAL_EXEC ( rm_disk_init,
  8. "sti\n\t"
  9. "xorw %%ax,%%ax\n\t"
  10. "movb $0x80,%%dl\n\t"
  11. "int $0x13\n\t"
  12. "cli\n\t",
  13. 0,
  14. OUT_CONSTRAINTS (),
  15. IN_CONSTRAINTS (),
  16. CLOBBER ( "eax", "ebx", "ecx", "edx",
  17. "ebp", "esi", "edi" ) );
  18. }
  19. /**************************************************************************
  20. DISK_READ - Read a sector from disk
  21. **************************************************************************/
  22. unsigned int pcbios_disk_read ( int drive, int cylinder, int head, int sector,
  23. char *fixme_buf ) {
  24. uint16_t ax, flags, discard_c, discard_d;
  25. segoff_t buf = SEGOFF ( fixme_buf );
  26. /* FIXME: buf should be passed in as a segoff_t rather than a
  27. * char *
  28. */
  29. REAL_EXEC ( rm_pcbios_disk_read,
  30. "sti\n\t"
  31. "pushl %%ebx\n\t" /* Convert %ebx to %es:bx */
  32. "popw %%bx\n\t"
  33. "popw %%es\n\t"
  34. "movb $0x02, %%ah\n\t" /* INT 13,2 - Read disk sector */
  35. "movb $0x01, %%al\n\t" /* Read one sector */
  36. "int $0x13\n\t"
  37. "pushfw\n\t"
  38. "popw %%bx\n\t"
  39. "cli\n\t",
  40. 4,
  41. OUT_CONSTRAINTS ( "=a" ( ax ), "=b" ( flags ),
  42. "=c" ( discard_c ), "=d" ( discard_d ) ),
  43. IN_CONSTRAINTS ( "c" ( ( ( cylinder & 0xff ) << 8 ) |
  44. ( ( cylinder >> 8 ) & 0x3 ) |
  45. sector ),
  46. "d" ( ( head << 8 ) | drive ),
  47. "b" ( buf ) ),
  48. CLOBBER ( "ebp", "esi", "edi" ) );
  49. return ( flags & CF ) ? ax : 0;
  50. }