Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include "wakeup.h"
0003 #include "boot.h"
0004 
0005 static void udelay(int loops)
0006 {
0007     while (loops--)
0008         io_delay(); /* Approximately 1 us */
0009 }
0010 
0011 static void beep(unsigned int hz)
0012 {
0013     u8 enable;
0014 
0015     if (!hz) {
0016         enable = 0x00;      /* Turn off speaker */
0017     } else {
0018         u16 div = 1193181/hz;
0019 
0020         outb(0xb6, 0x43);   /* Ctr 2, squarewave, load, binary */
0021         io_delay();
0022         outb(div, 0x42);    /* LSB of counter */
0023         io_delay();
0024         outb(div >> 8, 0x42);   /* MSB of counter */
0025         io_delay();
0026 
0027         enable = 0x03;      /* Turn on speaker */
0028     }
0029     inb(0x61);      /* Dummy read of System Control Port B */
0030     io_delay();
0031     outb(enable, 0x61); /* Enable timer 2 output to speaker */
0032     io_delay();
0033 }
0034 
0035 #define DOT_HZ      880
0036 #define DASH_HZ     587
0037 #define US_PER_DOT  125000
0038 
0039 /* Okay, this is totally silly, but it's kind of fun. */
0040 static void send_morse(const char *pattern)
0041 {
0042     char s;
0043 
0044     while ((s = *pattern++)) {
0045         switch (s) {
0046         case '.':
0047             beep(DOT_HZ);
0048             udelay(US_PER_DOT);
0049             beep(0);
0050             udelay(US_PER_DOT);
0051             break;
0052         case '-':
0053             beep(DASH_HZ);
0054             udelay(US_PER_DOT * 3);
0055             beep(0);
0056             udelay(US_PER_DOT);
0057             break;
0058         default:    /* Assume it's a space */
0059             udelay(US_PER_DOT * 3);
0060             break;
0061         }
0062     }
0063 }
0064 
0065 struct port_io_ops pio_ops;
0066 
0067 void main(void)
0068 {
0069     init_default_io_ops();
0070 
0071     /* Kill machine if structures are wrong */
0072     if (wakeup_header.real_magic != 0x12345678)
0073         while (1)
0074             ;
0075 
0076     if (wakeup_header.realmode_flags & 4)
0077         send_morse("...-");
0078 
0079     if (wakeup_header.realmode_flags & 1)
0080         asm volatile("lcallw   $0xc000,$3");
0081 
0082     if (wakeup_header.realmode_flags & 2) {
0083         /* Need to call BIOS */
0084         probe_cards(0);
0085         set_mode(wakeup_header.video_mode);
0086     }
0087 }