Path: blob/master/arch/x86/kernel/acpi/realmode/wakemain.c
10821 views
#include "wakeup.h"1#include "boot.h"23static void udelay(int loops)4{5while (loops--)6io_delay(); /* Approximately 1 us */7}89static void beep(unsigned int hz)10{11u8 enable;1213if (!hz) {14enable = 0x00; /* Turn off speaker */15} else {16u16 div = 1193181/hz;1718outb(0xb6, 0x43); /* Ctr 2, squarewave, load, binary */19io_delay();20outb(div, 0x42); /* LSB of counter */21io_delay();22outb(div >> 8, 0x42); /* MSB of counter */23io_delay();2425enable = 0x03; /* Turn on speaker */26}27inb(0x61); /* Dummy read of System Control Port B */28io_delay();29outb(enable, 0x61); /* Enable timer 2 output to speaker */30io_delay();31}3233#define DOT_HZ 88034#define DASH_HZ 58735#define US_PER_DOT 1250003637/* Okay, this is totally silly, but it's kind of fun. */38static void send_morse(const char *pattern)39{40char s;4142while ((s = *pattern++)) {43switch (s) {44case '.':45beep(DOT_HZ);46udelay(US_PER_DOT);47beep(0);48udelay(US_PER_DOT);49break;50case '-':51beep(DASH_HZ);52udelay(US_PER_DOT * 3);53beep(0);54udelay(US_PER_DOT);55break;56default: /* Assume it's a space */57udelay(US_PER_DOT * 3);58break;59}60}61}6263void main(void)64{65/* Kill machine if structures are wrong */66if (wakeup_header.real_magic != 0x12345678)67while (1);6869if (wakeup_header.realmode_flags & 4)70send_morse("...-");7172if (wakeup_header.realmode_flags & 1)73asm volatile("lcallw $0xc000,$3");7475if (wakeup_header.realmode_flags & 2) {76/* Need to call BIOS */77probe_cards(0);78set_mode(wakeup_header.video_mode);79}80}818283