Add some code bulletproofing, I have had this around for some time
authorrahnds <rahnds@openbsd.org>
Fri, 10 May 1996 16:54:54 +0000 (16:54 +0000)
committerrahnds <rahnds@openbsd.org>
Fri, 10 May 1996 16:54:54 +0000 (16:54 +0000)
I actually thought it was checked in.

This should stop any extra transmit interupts occuring and a possible
crash if another system talks to the tty port before it is completely
configured.

Also allows debugging when no processes have the port open for writing.
If abort is pressed before getty starts.

sys/arch/mvme68k/dev/cl.c

index c74e7dd..6a1fdaf 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: cl.c,v 1.11 1996/05/07 07:47:34 deraadt Exp $ */
+/*     $OpenBSD: cl.c,v 1.12 1996/05/10 16:54:54 rahnds Exp $ */
 
 /*
  * Copyright (c) 1995 Dale Rahn. All rights reserved.
@@ -977,8 +977,14 @@ clcngetc(dev)
 {
        u_char val, reoir, licr, isrl, data, status, fifo_cnt;
        int got_char = 0;
+       u_char ier_old = 0xff;
        struct clreg *cl_reg = cl_cons.cl_vaddr;
        volatile struct pcctworeg *pcc2_base = cl_cons.pcctwoaddr;
+       cl_reg->cl_car = 0;
+       if (!(cl_reg->cl_ier & 0x08)) {
+               ier_old = cl_reg->cl_ier;
+               cl_reg->cl_ier  = 0x08;
+       }
        while (got_char == 0) {
                val = cl_reg->cl_rir;
                /* if no receive interrupt pending wait */
@@ -1009,6 +1015,9 @@ clcngetc(dev)
 #endif
                        fifo_cnt = cl_reg->cl_rfoc;
                        data = cl_reg->cl_rdr;
+                       if (ier_old != 0xff) {
+                               cl_reg->cl_ier  = ier_old;
+                       }
                        got_char = 1;
                        cl_reg->cl_teoir = 0x00;
                } else {
@@ -1491,6 +1500,7 @@ cl_txintr(sc)
 
        tp = sc->sc_cl[channel].tty;
        if (tp == NULL || (tp->t_state & TS_ISOPEN) == 0) {
+               sc->cl_reg->cl_ier = sc->cl_reg->cl_ier & ~0x3;
                sc->cl_reg->cl_teoir = 0x08;
                return 1;
        }
@@ -1729,6 +1739,14 @@ channel, nbuf, cnt, status);
                for (i = 0; i < fifocnt; i++) {
                        buffer[i] = sc->cl_reg->cl_rdr;
                }
+               if (NULL == tp) {
+                       /* if the channel is not configured,
+                        * dont send characters upstream.
+                        * also fix problem with NULL dereference
+                        */
+                       reoir = 0x00;
+                       break;
+               }
 
                sc->cl_reg->cl_reoir = reoir;
                for (i = 0; i < fifocnt; i++) {