[PATCH 1 of 1] General improvements to arch dependent code

Juan Perez-Sanchez <[email protected]>
Newsgroups org.kernel.vger.linux-8086
Message-ID <CAD6VGubjZ9gnLVP604qT_zT273_PNddERH4dZ9FnU5Yq6bOdnw@mail.gmail.com>
Hi,

  I examined the files under the "arch/i86" directory and found many
problems. The following set of 5 patches makes the code cleaner and
easier to understand. There is also a reduction of 64 bytes in code
size and a few bug fixes.

 After applying each patch, I tested the resulting image in the qemu
and dioscuri emulators, as well as in a ppro pc booting from floppy.
However, the patches are not independent and you must apply all them
in sequence. By suggestion from Jody, the patches will be sent  as an
attachment.

 Note that this is not the end of the problems with the code in these
directories. Just to mention a pair of problems:

   1. Interrupt handlers run with interrupts disabled. This is
unacceptable. But maybe this is a workaround to some deeper problems.

   2. Installed signal handlers do not work as they should.

This patch 1 of 1 implements:

1. Place a missing semicolon in file init/main.c lost in the last
patch commitment.

2. Attempting compilation of file "arch/i86/drivers/char/serial.c"
using an ansi C compiler results in numerous warnings and several
errors. This patch eliminates most warnings and errors.

After building the image, code size was unchanged.

Greetings,

Juan
elksB.patch (application/octet-stream, 7.3 KB)
diff -Nurb elks.orig/init/main.c elks/init/main.c
--- elks.orig/init/main.c	2012-05-11 13:26:27.000000000 -0500
+++ elks/init/main.c	2012-05-14 15:27:57.000000000 -0500
@@ -141,7 +141,7 @@
     do {
    	do {
     	} while((*((unsigned int *)(&loops)))--);
-    } while((*(((unsigned int *)(&loops))+1))--)
+    } while((*(((unsigned int *)(&loops))+1))--);
 }

 int calibrate_delay(void)
diff -Nurb elks.orig/arch/i86/drivers/char/serial.c elks/arch/i86/drivers/char/serial.c
--- elks.orig/arch/i86/drivers/char/serial.c	2012-05-09 13:27:38.000000000 -0500
+++ elks/arch/i86/drivers/char/serial.c	2012-05-10 14:18:20.000000000 -0500
@@ -111,10 +111,10 @@

     /* Set the divisor low and high byte */
     outb_p(divisor & 0xff, (void *) (port->io + UART_DLL));
-    outb_p((divisor >> 8) & 0xff, port->io + UART_DLM);
+    outb_p((divisor >> 8) & 0xff, (void *)(port->io + UART_DLM));

     /* Clear the divisor latch bit */
-    outb_p(port->lcr, port->io + UART_LCR);
+    outb_p(port->lcr, (void *)(port->io + UART_LCR));

     set_irq();
 }
@@ -127,7 +127,7 @@

     debug("SERIAL: rs_release called\n");
     port->flags &= ~SERF_INUSE;
-    outb_p(0, port->io + UART_IER);
+    outb_p(0, (void *)(port->io + UART_IER));
 }

 static int get_serial_info(struct serial_info *info,
@@ -154,29 +154,29 @@
     port->flags |= SERF_INUSE;

     /* clear RX buffer */
-    (void) inb_p(port->io + UART_LSR);
+    inb_p((void *)(port->io + UART_LSR));

-    countp = (int) MAX_RX_BUFFER_SIZE;
+    countp = (char *) MAX_RX_BUFFER_SIZE;
     do
-	(void) inb_p((void *) (port->io + UART_RX));
+	inb_p((void *) (port->io + UART_RX));
     while (--countp && (inb_p((void *) (port->io + UART_LSR)) & UART_LSR_DR));

-    (void) inb_p((void *) (port->io + UART_IIR));
-    (void) inb_p((void *) (port->io + UART_MSR));
+    inb_p((void *) (port->io + UART_IIR));
+    inb_p((void *) (port->io + UART_MSR));

     /* set serial port parameters to match ports[rs_minor] */
     update_port(port);

     /* enable reciever data interrupt; FIXME: update code to utilize full interrupt interface */
-    outb_p(UART_IER_RDI, port->io + UART_IER);
+    outb_p(UART_IER_RDI, (void *)(port->io + UART_IER));

-    outb_p(port->mcr, port->io + UART_MCR);
+    outb_p(port->mcr, (void *)(port->io + UART_MCR));

     /* clear Line/Modem Status, Intr ID and RX register */
-    (void) inb_p((void *) (port->io + UART_LSR));
-    (void) inb_p((void *) (port->io + UART_RX));
-    (void) inb_p((void *) (port->io + UART_IIR));
-    (void) inb_p((void *) (port->io + UART_MSR));
+    inb_p((void *) (port->io + UART_LSR));
+    inb_p((void *) (port->io + UART_RX));
+    inb_p((void *) (port->io + UART_IIR));
+    inb_p((void *) (port->io + UART_MSR));

     return 0;
 }
@@ -208,7 +208,7 @@
     unsigned char ch;

     while (chq_getch(&tty->outq, &ch, 0) != -1) {
-	while (!(inb_p(port->io + UART_LSR) & UART_LSR_TEMT))
+	while (!(inb_p((void *)(port->io + UART_LSR)) & UART_LSR_TEMT))
 	    /* Do nothing */ ;
 	outb(ch, (void *) (port->io + UART_TX));
     }
@@ -229,11 +229,11 @@
 	update_port(port);
 	break;
     case TIOCSSERIAL:
-	retvalp = (char *) set_serial_info(port, arg);
+	retvalp = (char *) set_serial_info(port, (struct serial_info *)arg);
 	break;

     case TIOCGSERIAL:
-	retvalp = (char *) get_serial_info(port, arg);
+	retvalp = (char *) get_serial_info(port, (struct serial_info *)arg);
 	break;
     }

@@ -256,7 +256,7 @@
 	    q->buf[(q->tail + q->len) & size] = (char) ch;
 	    q->len++;
 	}
-    } while (inb_p(sp->io + UART_LSR) & UART_LSR_DR);
+    } while (inb_p((void *)(sp->io + UART_LSR)) & UART_LSR_DR);
     wake_up(&q->wq);
 }

@@ -269,14 +269,14 @@
     debug1("SERIAL: Interrupt %d recieved.\n", irq);
     sp = &ports[irq_port[irq - 2]];
     do {
-	statusp = (int) inb_p(sp->io + UART_LSR);
-	if (((int) statusp) & UART_LSR_DR)
+	statusp = (char *)inb_p((void *)(sp->io + UART_LSR));
+	if ((int)statusp & UART_LSR_DR)
 	    receive_chars(sp);
 #if 0
-	if (((int) statusp) & UART_LSR_THRE)
+	if (((int)statusp) & UART_LSR_THRE)
 	    transmit_chars(sp);
 #endif
-    } while (!(inb_p(sp->io + UART_IIR) & UART_IIR_NO_INT));
+    } while (!(inb_p((void *)(sp->io + UART_IIR)) & UART_IIR_NO_INT));
 }

 int rs_probe(register struct serial_info *sp)
@@ -284,25 +284,25 @@
     int status1, status2;
     unsigned char scratch;

-    scratch = inb(sp->io + UART_IER);
-    outb_p(0, sp->io + UART_IER);
-    scratch = inb_p(sp->io + UART_IER);
-    outb_p(scratch, sp->io + UART_IER);
+    scratch = inb((void *)(sp->io + UART_IER));
+    outb_p(0, (void *)(sp->io + UART_IER));
+    scratch = inb_p((void *)(sp->io + UART_IER));
+    outb_p(scratch, (void *)(sp->io + UART_IER));
     if (scratch)
 	return -1;

     /* this code is weird, IMO */
-    scratch = inb_p(sp->io + UART_LCR);
-    outb_p(scratch | UART_LCR_DLAB, sp->io + UART_LCR);
-    outb_p(0, sp->io + UART_EFR);
-    outb_p(scratch, sp->io + UART_LCR);
+    scratch = inb_p((void *)(sp->io + UART_LCR));
+    outb_p(scratch | UART_LCR_DLAB, (void *)(sp->io + UART_LCR));
+    outb_p(0, (void *)(sp->io + UART_EFR));
+    outb_p(scratch, (void *)(sp->io + UART_LCR));

-    outb_p(UART_FCR_ENABLE_FIFO, sp->io + UART_FCR);
+    outb_p(UART_FCR_ENABLE_FIFO, (void *)(sp->io + UART_FCR));

     /* upper two bits of IIR define UART type, but according to both RB's
      * intlist and HelpPC this code is wrong, see comments marked with [*]
      */
-    scratch = inb_p(sp->io + UART_IIR) >> 6;
+    scratch = inb_p((void *)(sp->io + UART_IIR)) >> 6;
     switch (scratch) {
     case 0:
 	sp->flags = (unsigned char) (SERF_EXIST | ST_16450);
@@ -321,12 +321,12 @@

     /* 8250 UART if scratch register isn't present */
     if (!scratch) {
-	scratch = inb_p(sp->io + UART_SCR);
-	outb_p(0xA5, sp->io + UART_SCR);
-	status1 = inb_p(sp->io + UART_SCR);
-	outb_p(0x5A, sp->io + UART_SCR);
-	status2 = inb_p(sp->io + UART_SCR);
-	outb_p(scratch, sp->io + UART_SCR);
+	scratch = inb_p((void *)(sp->io + UART_SCR));
+	outb_p(0xA5, (void *)(sp->io + UART_SCR));
+	status1 = inb_p((void *)(sp->io + UART_SCR));
+	outb_p(0x5A, (void *)(sp->io + UART_SCR));
+	status2 = inb_p((void *)(sp->io + UART_SCR));
+	outb_p(scratch, (void *)(sp->io + UART_SCR));
 	if ((status1 != 0xA5) || (status2 != 0x5A))
 	    sp->flags = (unsigned char) (SERF_EXIST | ST_8250);
     }
@@ -335,18 +335,18 @@
      *      Reset the chip
      */

-    outb_p(0x00, sp->io + UART_MCR);
+    outb_p(0x00, (void *)(sp->io + UART_MCR));

     /* clear RX and TX FIFOs */
     outb_p((unsigned char) (UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
-			sp->io + UART_FCR);
+			(void *)(sp->io + UART_FCR));

     /* clear RX register */
     {
 	register char *countp = (char *) MAX_RX_BUFFER_SIZE;
 	do {
-	    (void) inb_p((void *) (sp->io + UART_RX));
-	} while (--countp && (inb_p(sp->io + UART_LSR) & UART_LSR_DR));
+	    inb_p((void *) (sp->io + UART_RX));
+	} while (--countp && (inb_p((void *)(sp->io + UART_LSR)) & UART_LSR_DR));
     }

     return 0;
@@ -395,7 +395,7 @@
 		sp->tty = &ttys[ttyno++];
 		update_port(sp);
 #if 0
-		outb_p(? ? ? ?, sp->io + UART_MCR);
+		outb_p(? ? ? ?, (void *)(sp->io + UART_MCR));
 #endif
 	    }
 	}
@@ -420,7 +420,7 @@
 void con_charout(char Ch)
 {
     if (con_init) {
-	while (!(inb_p(ports[CONSOLE_PORT].io + UART_LSR) & UART_LSR_TEMT));
+	while (!(inb_p((void *)(ports[CONSOLE_PORT].io + UART_LSR)) & UART_LSR_TEMT));
 	outb(Ch, ports[CONSOLE_PORT].io + UART_TX);
     }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.