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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* Etherboot routines for PCBIOS firmware.
  2. *
  3. * Body of routines taken from old pcbios.S
  4. */
  5. #include "stdint.h"
  6. #include "realmode.h"
  7. #include "compiler.h"
  8. #define BIOS_DATA_SEG 0x0040
  9. #define CF ( 1 << 0 )
  10. /**************************************************************************
  11. CURRTICKS - Get Time
  12. Use direct memory access to BIOS variables, longword 0040:006C (ticks
  13. today) and byte 0040:0070 (midnight crossover flag) instead of calling
  14. timeofday BIOS interrupt.
  15. **************************************************************************/
  16. #if defined(CONFIG_TSC_CURRTICKS)
  17. #undef CONFIG_BIOS_CURRTICKS
  18. #else
  19. #define CONFIG_BIOS_CURRTICKS 1
  20. #endif
  21. #if defined(CONFIG_BIOS_CURRTICKS)
  22. unsigned long currticks ( void ) {
  23. static uint32_t days = 0;
  24. uint32_t ticks;
  25. uint8_t midnight;
  26. /* Re-enable interrupts so that the timer interrupt can occur
  27. */
  28. REAL_EXEC ( rm_currticks,
  29. "sti\n\t"
  30. "nop\n\t"
  31. "nop\n\t"
  32. "cli\n\t",
  33. 0,
  34. OUT_CONSTRAINTS (),
  35. IN_CONSTRAINTS (),
  36. CLOBBER ( "eax" ) ); /* can't have an empty clobber list */
  37. get_real ( ticks, BIOS_DATA_SEG, 0x006c );
  38. get_real ( midnight, BIOS_DATA_SEG, 0x0070 );
  39. if ( midnight ) {
  40. midnight = 0;
  41. put_real ( midnight, BIOS_DATA_SEG, 0x0070 );
  42. days += 0x1800b0;
  43. }
  44. return ( days + ticks );
  45. }
  46. #endif /* CONFIG_BIOS_CURRTICKS */
  47. /**************************************************************************
  48. CPU_NAP - Save power by halting the CPU until the next interrupt
  49. **************************************************************************/
  50. void cpu_nap ( void ) {
  51. REAL_EXEC ( rm_cpu_nap,
  52. "sti\n\t"
  53. "hlt\n\t"
  54. "cli\n\t",
  55. 0,
  56. OUT_CONSTRAINTS (),
  57. IN_CONSTRAINTS (),
  58. CLOBBER ( "eax" ) ); /* can't have an empty clobber list */
  59. }
  60. #if (TRY_FLOPPY_FIRST > 0)
  61. /**************************************************************************
  62. DISK_INIT - Initialize the disk system
  63. **************************************************************************/
  64. void disk_init ( void ) {
  65. REAL_EXEC ( rm_disk_init,
  66. "sti\n\t"
  67. "xorw %ax,%ax\n\t"
  68. "movb $0x80,%dl\n\t"
  69. "int $0x13\n\t"
  70. "cli\n\t",
  71. 0,
  72. OUT_CONSTRAINTS (),
  73. IN_CONSTRAINTS (),
  74. CLOBBER ( "eax", "ebx", "ecx", "edx",
  75. "ebp", "esi", "edi" ) );
  76. }
  77. /**************************************************************************
  78. DISK_READ - Read a sector from disk
  79. **************************************************************************/
  80. unsigned int pcbios_disk_read ( int drive, int cylinder, int head, int sector,
  81. char *fixme_buf ) {
  82. uint16_t ax, flags, discard_c, discard_d;
  83. segoff_t buf = SEGOFF ( fixme_buf );
  84. /* FIXME: buf should be passed in as a segoff_t rather than a
  85. * char *
  86. */
  87. REAL_EXEC ( rm_pcbios_disk_read,
  88. "sti\n\t"
  89. "pushl %%ebx\n\t" /* Convert %ebx to %es:bx */
  90. "popl %%bx\n\t"
  91. "popl %%es\n\t"
  92. "movb $0x02, %%ah\n\t" /* INT 13,2 - Read disk sector */
  93. "movb $0x01, %%al\n\t" /* Read one sector */
  94. "int $0x13\n\t"
  95. "pushfw\n\t"
  96. "popw %%bx\n\t"
  97. "cli\n\t",
  98. 4,
  99. OUT_CONSTRAINTS ( "=a" ( ax ), "=b" ( flags ),
  100. "=c" ( discard_c ), "=d" ( discard_d ) ),
  101. IN_CONSTRAINTS ( "c" ( ( ( cylinder & 0xff ) << 8 ) |
  102. ( ( cylinder >> 8 ) & 0x3 ) |
  103. sector ),
  104. "d" ( ( head << 8 ) | drive ),
  105. "b" ( buf ) ),
  106. CLOBBER ( "ebp", "esi", "edi" ) );
  107. );
  108. return ( flags & CF ) ? ax : 0;
  109. }
  110. #endif /* TRY_FLOPPY_FIRST */