pc_speaker.S 788 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* https://github.com/cirosantilli/x86-bare-metal-examples#pc-speaker */
  2. #include "common.h"
  3. BEGIN
  4. /* Chanel 2, square wave, load TODO?, binary */
  5. mov $0xb6, %al
  6. out %al, $0x43
  7. /* Set frequency of Channel 2. */
  8. .equ div, 1193181 / 1000
  9. mov div, %ax
  10. out %al, $0x42
  11. mov %ah, %al
  12. out %al, $0x42
  13. /* Dummy read of System Control Port B. TODO why? */
  14. in $0x61, %al
  15. /* Enable timer 2 output to speaker.
  16. * THIS is where the sound begins.
  17. */
  18. mov $0x03, %al
  19. out %al, $0x61
  20. /* Loop forever to keep hearing it. */
  21. loop:
  22. nop
  23. jmp loop
  24. /* This is how a sound can be stopped.
  25. * This code never reached in this example.
  26. * unless you hack it up.
  27. */
  28. in $0x61, %al
  29. mov $0x00, %al
  30. out %al, $0x61