wakemain.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "wakeup.h"
  2. #include "boot.h"
  3. static void udelay(int loops)
  4. {
  5. while (loops--)
  6. io_delay(); /* Approximately 1 us */
  7. }
  8. static void beep(unsigned int hz)
  9. {
  10. u8 enable;
  11. if (!hz) {
  12. enable = 0x00; /* Turn off speaker */
  13. } else {
  14. u16 div = 1193181/hz;
  15. outb(0xb6, 0x43); /* Ctr 2, squarewave, load, binary */
  16. io_delay();
  17. outb(div, 0x42); /* LSB of counter */
  18. io_delay();
  19. outb(div >> 8, 0x42); /* MSB of counter */
  20. io_delay();
  21. enable = 0x03; /* Turn on speaker */
  22. }
  23. inb(0x61); /* Dummy read of System Control Port B */
  24. io_delay();
  25. outb(enable, 0x61); /* Enable timer 2 output to speaker */
  26. io_delay();
  27. }
  28. #define DOT_HZ 880
  29. #define DASH_HZ 587
  30. #define US_PER_DOT 125000
  31. /* Okay, this is totally silly, but it's kind of fun. */
  32. static void send_morse(const char *pattern)
  33. {
  34. char s;
  35. while ((s = *pattern++)) {
  36. switch (s) {
  37. case '.':
  38. beep(DOT_HZ);
  39. udelay(US_PER_DOT);
  40. beep(0);
  41. udelay(US_PER_DOT);
  42. break;
  43. case '-':
  44. beep(DASH_HZ);
  45. udelay(US_PER_DOT * 3);
  46. beep(0);
  47. udelay(US_PER_DOT);
  48. break;
  49. default: /* Assume it's a space */
  50. udelay(US_PER_DOT * 3);
  51. break;
  52. }
  53. }
  54. }
  55. void main(void)
  56. {
  57. /* Kill machine if structures are wrong */
  58. if (wakeup_header.real_magic != 0x12345678)
  59. while (1)
  60. ;
  61. if (wakeup_header.realmode_flags & 4)
  62. send_morse("...-");
  63. if (wakeup_header.realmode_flags & 1)
  64. asm volatile("lcallw $0xc000,$3");
  65. if (wakeup_header.realmode_flags & 2) {
  66. /* Need to call BIOS */
  67. probe_cards(0);
  68. set_mode(wakeup_header.video_mode);
  69. }
  70. }