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

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