wakemain.c 1.5 KB

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