Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 May 2000 20:54:19 -0700 (PDT)
From:      Peter Van Epp <vanepp@sfu.ca>
To:        hackers@freebsd.org
Subject:   The proper way to get a beep out of the kernel after a halt?
Message-ID:  <200005260354.UAA19087@fraser.sfu.ca>

next in thread | raw e-mail | index | archive | help
	Because I'm running a couple of boxes headless, I have modified
kern_shutdown.c to halt (rather than boot) on alt-ctl-delete and once the 
shutdown is complete beep three times via the speaker to indicate (in the 
absence of a tube) that it is now OK for the person to power down. Currently
(out of ignorance) I am doing this ugly kludge to get beeps. I expect there 
is a proper way to get a beep from code in the kernel (although printf isn't
it, the kernel version of printf don't seem to do no beeps!). Would some kind
person enlighten me please? If there is interest (or even someone willing to
add the change even if you don't see a need for it) I'll set this up as a 
kernel option (probably HEADLESS) which changes the SIGINT to SIGUSR1 in
the signal to init to change the reboot to a halt and set the beep stuff up
properly (which I expect isn't fiddling the bits directly althought this seems
to work just fine which is all I currently care about) since I expect there
are other folks running production machines headless (or more correctly
tubeless) who would like the functionality too.
	While I'm here I should check that I am correct and that alt-cntl-delete
is the only thing that calls shutdown_nice() as it appears to me?

void
shutdown_nice()
{
        /* Send a signal to init(8) and have it shutdown the world */
        if (initproc != NULL) {

		/* halt instead of reboot! */

                psignal(initproc, SIGUSR1);
...

static void
shutdown_halt(void *junk, int howto)
{

/* + needs to go! */

#define TIMER_FREQ   1193182

    u_int       timer_freq = TIMER_FREQ;
    unsigned int divisor;

/* - needs to go */

        if (howto & RB_HALT) {
                printf("\n");
                printf("The operating system has halted.\n");
                printf("Please press any key to reboot.\n\n");


/* + needs to go */

                /* set up timer2 for a 1 khz tone */

                divisor = timer_freq / 1000;

                outb(TIMER_MODE, TIMER_SEL2 | ((TIMER_SQWAVE | TIMER_16BIT) & 0x
3f));
                outb(TIMER_CNTR2, (divisor & 0xff));    /* send lo byte */
                outb(TIMER_CNTR2, (divisor >> 8));      /* send hi byte */

                /* turn the speaker on and off three times  */

                outb(IO_PPI, inb(IO_PPI) | PPI_SPKR);
                DELAY(1000 * 200); /* 2/10th second */
                outb(IO_PPI, inb(IO_PPI) & ~PPI_SPKR);
                DELAY(1000 * 200); /* 2/10th second */
                outb(IO_PPI, inb(IO_PPI) | PPI_SPKR);
                DELAY(1000 * 200); /* 2/10th second */
                outb(IO_PPI, inb(IO_PPI) & ~PPI_SPKR);
                DELAY(1000 * 200); /* 2/10th second */
                outb(IO_PPI, inb(IO_PPI) | PPI_SPKR);
                DELAY(1000 * 200); /* 2/10th second */
                outb(IO_PPI, inb(IO_PPI) & ~PPI_SPKR);

/* - needs to go */

                switch (cngetc()) {
                case -1:                /* No console, just die */
                        cpu_halt();
                        /* NOTREACHED */
                default:

Peter Van Epp / Operations and Technical Support 
Simon Fraser University, Burnaby, B.C. Canada



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200005260354.UAA19087>