Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH -ac] Panicking in morse code

1 view
Skip to first unread message

Andrew Rodland

unread,
Jul 19, 2002, 1:13:00 AM7/19/02
to
No, it's not 1 April.

I was researching panic_blink() for someone who needed a little help,
when I noticed the comment above the function definition, not being the
kind to step down from a challenge (unless it's just really hard), I
decided to write morse code output code.

The option panicblink= has been hijacked to be a simple bitfield:
bit 1 : blink LEDs
bit 2 : sound the PC speaker.

the blinking option depends only on pc_keyb.c. the pcspeaker option
depends on kb_mksound() actually doing something. At the moment, both of
these mean i386. The call to panic_blink() in panic() is still guarded
by an i386 #ifdef, anyway, for the moment. The default is to blink only,
because I figured the beeps would be too annoying. Opinions?

It recognizes letters, and digits, and treats everything else as a
space. The timings are tunable by #defines. It repeats the message
indefinitely. And it should only bloat the kernel by a few hundred
bytes, although if someone wants to wrap this in its own config option,
well, that's good too.

Anyway, here's the patch. It's against linux-2.4.19-rc1-ac1+preempt, but
I suspect it applies against all recent -ac. If 2.5 has this, it will
hopefully apply with some fuzz against that, too. I don't have a tree.
(modem. ecch.)


diff -u -r -d linux.old/drivers/char/pc_keyb.c linux/drivers/char/pc_keyb.c
--- linux.old/drivers/char/pc_keyb.c Fri Jul 19 00:59:04 2002
+++ linux/drivers/char/pc_keyb.c Fri Jul 19 01:00:34 2002
@@ -1244,37 +1244,126 @@
#endif /* CONFIG_PSMOUSE */


-static int blink_frequency = HZ/2;
+static int blink_setting = 1;

/* Tell the user who may be running in X and not see the console that we have
panic'ed. This is to distingush panics from "real" lockups.
Could in theory send the panic message as morse, but that is left as an
- exercise for the reader. */
-void panic_blink(void)
-{
- static unsigned long last_jiffie;
- static char led;
- /* Roughly 1/2s frequency. KDB uses about 1s. Make sure it is
- different. */
- if (!blink_frequency)
- return;
- if (jiffies - last_jiffie > blink_frequency) {
- led ^= 0x01 | 0x04;
+ exercise for the reader.
+ And now it's done! LED and speaker morse code by Andrew Rodland, 18-19 Jul 2002
+*/
+
+static const char * morse[] = {
+ ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", /* A-H */
+ "..", ".---.", "-.-", ".-..", "--", "-.", "---", ".--.", /* I-P */
+ "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", /* Q-X */
+ "-.--", "--..", /* Y-Z */
+ "-----", ".----", "..---", "...--", "....-", /* 0-4 */
+ ".....", "-....", "--...", "---..", "----." /* 5-9 */
+};
+
+#define DITLEN (HZ / 4)
+#define DAHLEN 3 * DITLEN
+#define FREQ 1000
+
+static __inline__ void do_blink (int led) {
+
+ if (! blink_setting & 0x01)
+ return;
+
+ led = led ? (0x01 | 0x04) : 0x00;
+
while (kbd_read_status() & KBD_STAT_IBF) mdelay(1);
kbd_write_output(KBD_CMD_SET_LEDS);
mdelay(1);
while (kbd_read_status() & KBD_STAT_IBF) mdelay(1);
mdelay(1);
kbd_write_output(led);
- last_jiffie = jiffies;
+}
+
+void panic_blink(char * buf)
+{
+ static unsigned long next_jiffie = 0;
+ static char * bufpos = 0;
+ static char * morsepos = 0;
+ static char state;
+
+ if (!blink_setting)
+ return;
+
+ if (!buf)
+ buf="ABC";
+
+
+ if (jiffies > next_jiffie || !bufpos) { //messy. fix.
+
+ if (state) {
+ do_blink(0);
+ state = 0;
+ next_jiffie = jiffies + DITLEN;
+ return;
+ }
+
+ if (!bufpos) {
+ bufpos = (char *)buf;
+ return;
+ }
+
+
+ if (!morsepos || !*morsepos) {
+
+ if (!*bufpos) { /*Repeat the message */
+ bufpos = (char *)buf;
+ morsepos = 0;
+ next_jiffie = jiffies + 3 * DAHLEN;
+ return;
+ }
+ next_jiffie = jiffies + DITLEN;
+
+ if (*bufpos >= 'A' && *bufpos <= 'Z') {
+ morsepos = (char *)morse[*bufpos - 'A'];
+ } else if (*bufpos >= 'a' && *bufpos <= 'z') {
+ morsepos = (char *)morse[*bufpos - 'a'];
+ } else if (*bufpos >= '0' && *bufpos <= '9') {
+ morsepos = (char *)morse[*bufpos - '0' + 26];
+ } else {
+ next_jiffie += 2*DITLEN;
+ }
+ bufpos ++;
+
+ return;
+ }
+
+ if (*morsepos == '.') {
+ if (blink_setting & 0x02)
+ kd_mksound(FREQ, DITLEN);
+ next_jiffie = jiffies + DITLEN;
+ do_blink(1);
+ state = 1;
+ morsepos++;
+ return;
+ } else if (*morsepos == '-') {
+ if (blink_setting & 0x02)
+ kd_mksound(FREQ, DAHLEN);
+ next_jiffie = jiffies + DAHLEN;
+ do_blink(1);
+ state = 1;
+ morsepos++;
+ return;
+ }
+
+ /*impossible*/
+ morsepos = 0;
+
}
+
}

static int __init panicblink_setup(char *str)
{
int par;
if (get_option(&str,&par))
- blink_frequency = par*(1000/HZ);
+ blink_setting = par;
return 1;
}

diff -u -r -d linux.old/kernel/panic.c linux/kernel/panic.c
--- linux.old/kernel/panic.c Fri Jul 19 00:59:04 2002
+++ linux/kernel/panic.c Thu Jul 18 21:45:45 2002
@@ -97,8 +97,8 @@
sti();
for(;;) {
#if defined(__i386__) && defined(CONFIG_VT)
- extern void panic_blink(void);
- panic_blink();
+ extern void panic_blink(char * buf);
+ panic_blink(buf);
#endif
CHECK_EMERGENCY_SYNC
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

William Lee Irwin III

unread,
Jul 19, 2002, 1:29:30 AM7/19/02
to
On Fri, Jul 19, 2002 at 01:13:00AM -0400, Andrew Rodland wrote:
> No, it's not 1 April.
> I was researching panic_blink() for someone who needed a little help,
> when I noticed the comment above the function definition, not being the
> kind to step down from a challenge (unless it's just really hard), I
> decided to write morse code output code.

This is far more amusing than any of the April 1st Linus impersonations.

Good show!


Cheers,
Bill

Thorsten Kranzkowski

unread,
Jul 19, 2002, 12:36:55 PM7/19/02
to
On Fri, Jul 19, 2002 at 01:13:00AM -0400, Andrew Rodland wrote:
> I was researching panic_blink() for someone who needed a little help,
> when I noticed the comment above the function definition, not being the
> kind to step down from a challenge (unless it's just really hard), I
> decided to write morse code output code.

nice idea :)

> diff -u -r -d linux.old/drivers/char/pc_keyb.c linux/drivers/char/pc_keyb.c
> --- linux.old/drivers/char/pc_keyb.c Fri Jul 19 00:59:04 2002
> +++ linux/drivers/char/pc_keyb.c Fri Jul 19 01:00:34 2002
> @@ -1244,37 +1244,126 @@
> #endif /* CONFIG_PSMOUSE */

[...]

> +static const char * morse[] = {
> + ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", /* A-H */
> + "..", ".---.", "-.-", ".-..", "--", "-.", "---", ".--.", /* I-P */

This should read:

"..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", /* I-P */

i.e. there's a dot too much :)

> + "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", /* Q-X */
> + "-.--", "--..", /* Y-Z */
> + "-----", ".----", "..---", "...--", "....-", /* 0-4 */
> + ".....", "-....", "--...", "---..", "----." /* 5-9 */
> +};

73, Thorsten

--
| Thorsten Kranzkowski Internet: dl8...@dl8bcu.de |
| Mobile: ++49 170 1876134 Snail: Niemannsweg 30, 49201 Dissen, Germany |
| Ampr: dl8bcu@db0lj.#rpl.deu.eu, dl8...@marvin.dl8bcu.ampr.org [44.130.8.19] |

Andrew Rodland

unread,
Jul 19, 2002, 1:00:40 PM7/19/02
to
On Fri, 19 Jul 2002 16:36:55 +0000
Thorsten Kranzkowski <dl8...@dl8bcu.de> wrote:

> On Fri, Jul 19, 2002 at 01:13:00AM -0400, Andrew Rodland wrote:
> > I was researching panic_blink() for someone who needed a little
> > help, when I noticed the comment above the function definition, not
> > being the kind to step down from a challenge (unless it's just
> > really hard), I decided to write morse code output code.
>
> nice idea :)
>
> > diff -u -r -d linux.old/drivers/char/pc_keyb.c

> > linux/drivers/char/pc_keyb.c--- linux.old/drivers/char/pc_keyb.c Fri Jul 19 00:59:04 2002


> > +++ linux/drivers/char/pc_keyb.c Fri Jul 19 01:00:34 2002
> > @@ -1244,37 +1244,126 @@
> > #endif /* CONFIG_PSMOUSE */
>
> [...]
>
> > +static const char * morse[] = {
> > + ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", /* A-H

> > */+ "..", ".---.", "-.-", ".-..", "--", "-.", "---", ".--.", /* I-P


> > */
>
> This should read:
>
> "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", /* I-P
> */
>
> i.e. there's a dot too much :)
>

Thank you. Fixed locally.
Since you seem to be something of a morse-wiz (the only letters I know
by heart are 'S', 'O', and 'S'), could you either make corrections on
my timings (ditlen, dahlen, inter-letter space, inter-word space), or
tell me that they're good?

--Andrew

P.S. Yes, in case anyone is wondering, I did create a module that does
nothing but generate a user-supplied panic. :)

Andrew Rodland

unread,
Jul 19, 2002, 1:32:24 PM7/19/02
to
On Fri, 19 Jul 2002 12:27:51 -0500
Eli Carter <eli.c...@inet.com> wrote:

> Andrew Rodland wrote:
> [snip]


> > --Andrew
> >
> > P.S. Yes, in case anyone is wondering, I did create a module that
> > does nothing but generate a user-supplied panic. :)
>

> *ROTFL* Actually, I can see that being useful for testing... I fear
> you have tweaked my curiosity to see that particular implementation.
> :)
>

Actually, it was pretty simple. It was also my first module ever.
I had a lot of fun writing all of this stuff, but people keep
indicating that maybe some of it could actually be useful. If that's
the case, so much the better.

panictest.c follows.

--cut--

#define __KERNEL__
#define MODULE

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

static char *string = "SOS SOS SOS";

int __init panic_init(void) {
panic(string);
}

module_init(panic_init);
MODULE_LICENSE("GPL");
MODULE_PARM(string, "s");
MODULE_PARM_DESC(string, "The string to panic with.");

Eli Carter

unread,
Jul 19, 2002, 1:27:51 PM7/19/02
to
Andrew Rodland wrote:
[snip]
> --Andrew
>
> P.S. Yes, in case anyone is wondering, I did create a module that does
> nothing but generate a user-supplied panic. :)

*ROTFL* Actually, I can see that being useful for testing... I fear
you have tweaked my curiosity to see that particular implementation. :)

Oh, the fun of getting someone to feed that patch to Linus... *grin*

*giggle*

Eli
--------------------. "If it ain't broke now,
Eli Carter \ it will be soon." -- crypto-gram
eli.carter(a)inet.com `-------------------------------------------------

0 new messages