CVS commit: src/sys/dev/fdt

2021-02-21 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Mon Feb 22 06:21:35 UTC 2021

Modified Files:
src/sys/dev/fdt: cpufreq_dt.c

Log Message:
It is more appropriate to use clk_get_rate() rather than sc->sc_freq_target * 
100.
ci_data.cpu_cc_freq should be set to a higher precision value.

In addition, when cpufreq_dt_init(), or while throttling, sc->sc_freq_target 
should not
be referenced by cpufreq_dt_change_cb() because it does not have the correct 
value.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/fdt/cpufreq_dt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/fdt/cpufreq_dt.c
diff -u src/sys/dev/fdt/cpufreq_dt.c:1.18 src/sys/dev/fdt/cpufreq_dt.c:1.19
--- src/sys/dev/fdt/cpufreq_dt.c:1.18	Wed Jan 27 03:10:21 2021
+++ src/sys/dev/fdt/cpufreq_dt.c	Mon Feb 22 06:21:35 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufreq_dt.c,v 1.18 2021/01/27 03:10:21 thorpej Exp $ */
+/* $NetBSD: cpufreq_dt.c,v 1.19 2021/02/22 06:21:35 ryo Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.18 2021/01/27 03:10:21 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.19 2021/02/22 06:21:35 ryo Exp $");
 
 #include 
 #include 
@@ -86,7 +86,7 @@ cpufreq_dt_change_cb(void *arg1, void *a
 	struct cpufreq_dt_softc * const sc = arg1;
 	struct cpu_info *ci = curcpu();
 
-	ci->ci_data.cpu_cc_freq = sc->sc_freq_target * 100;
+	ci->ci_data.cpu_cc_freq = clk_get_rate(sc->sc_clk);
 }
 
 static int



CVS commit: src/sys/dev/fdt

2021-02-21 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Mon Feb 22 06:21:35 UTC 2021

Modified Files:
src/sys/dev/fdt: cpufreq_dt.c

Log Message:
It is more appropriate to use clk_get_rate() rather than sc->sc_freq_target * 
100.
ci_data.cpu_cc_freq should be set to a higher precision value.

In addition, when cpufreq_dt_init(), or while throttling, sc->sc_freq_target 
should not
be referenced by cpufreq_dt_change_cb() because it does not have the correct 
value.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/fdt/cpufreq_dt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/mac68k/obio

2021-02-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Feb 22 05:23:37 UTC 2021

Modified Files:
src/sys/arch/mac68k/obio: esp.c

Log Message:
Elucidate why synchronous transfer is disabled for AV Macs.

Sync negotiation times out when drive advertises that capability:


sd1 at scsibus0 target 1 lun 0:  disk fixed
sd1: 16384 MB, 2088 cyl, 255 head, 63 sec, 512 bytes/sect x 33554432 sectors
sd1: sync (160.00ns offset 15), 8-bit (6.250MB/s) transfers
...
sd1(esp0:0:1:0): esp0: timed out [ecb 0x9f7fc4 (flags 0x1, dleft 8, stat 0)], 

sd1(esp0:0:1:0): sync negotiation disabled
sd1(esp0:0:1:0): esp0: timed out [ecb 0x9f7fc4 (flags 0x41, dleft 8, stat 0)], 
 AGAIN
sd1: async, 8-bit transfers


This is observed for real SCSI drives as well as SCSI2SD (rev 6.0).

Note that this is not a fallout from DMA patch for AV Macs; timeout
takes place even if ``avdma'' code is forcibly disabled.

No binary changes.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/mac68k/obio/esp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/mac68k/obio/esp.c
diff -u src/sys/arch/mac68k/obio/esp.c:1.59 src/sys/arch/mac68k/obio/esp.c:1.60
--- src/sys/arch/mac68k/obio/esp.c:1.59	Mon Feb 22 04:24:41 2021
+++ src/sys/arch/mac68k/obio/esp.c	Mon Feb 22 05:23:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: esp.c,v 1.59 2021/02/22 04:24:41 rin Exp $	*/
+/*	$NetBSD: esp.c,v 1.60 2021/02/22 05:23:36 rin Exp $	*/
 
 /*
  * Copyright (c) 1997 Jason R. Thorpe.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: esp.c,v 1.59 2021/02/22 04:24:41 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: esp.c,v 1.60 2021/02/22 05:23:36 rin Exp $");
 
 #include 
 #include 
@@ -327,8 +327,9 @@ dafb_dreq:	bst = oa->oa_tag;
 		 * No synchronous xfers w/o DMA.
 		 *
 		 * XXXRO
-		 * Also disable synchronous xfers for avdma for now,
-		 * by which some disks cannot be read.
+		 * Also disable synchronous xfers for AV Macs;
+		 * sync negotiation times out when drive advertises that
+		 * capability, even if avdma code is forcibly disabled.
 		 */
 		sc->sc_minsync = 0;
 	}



CVS commit: src/sys/arch/mac68k/obio

2021-02-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Feb 22 05:23:37 UTC 2021

Modified Files:
src/sys/arch/mac68k/obio: esp.c

Log Message:
Elucidate why synchronous transfer is disabled for AV Macs.

Sync negotiation times out when drive advertises that capability:


sd1 at scsibus0 target 1 lun 0:  disk fixed
sd1: 16384 MB, 2088 cyl, 255 head, 63 sec, 512 bytes/sect x 33554432 sectors
sd1: sync (160.00ns offset 15), 8-bit (6.250MB/s) transfers
...
sd1(esp0:0:1:0): esp0: timed out [ecb 0x9f7fc4 (flags 0x1, dleft 8, stat 0)], 

sd1(esp0:0:1:0): sync negotiation disabled
sd1(esp0:0:1:0): esp0: timed out [ecb 0x9f7fc4 (flags 0x41, dleft 8, stat 0)], 
 AGAIN
sd1: async, 8-bit transfers


This is observed for real SCSI drives as well as SCSI2SD (rev 6.0).

Note that this is not a fallout from DMA patch for AV Macs; timeout
takes place even if ``avdma'' code is forcibly disabled.

No binary changes.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/mac68k/obio/esp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/mac68k/obio

2021-02-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Feb 22 04:24:42 UTC 2021

Modified Files:
src/sys/arch/mac68k/obio: esp.c

Log Message:
- Add missing \n's to printf(9).
- Whitespace fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/mac68k/obio/esp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/mac68k/obio

2021-02-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Feb 22 04:24:42 UTC 2021

Modified Files:
src/sys/arch/mac68k/obio: esp.c

Log Message:
- Add missing \n's to printf(9).
- Whitespace fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/mac68k/obio/esp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/mac68k/obio/esp.c
diff -u src/sys/arch/mac68k/obio/esp.c:1.58 src/sys/arch/mac68k/obio/esp.c:1.59
--- src/sys/arch/mac68k/obio/esp.c:1.58	Tue Jul 23 15:19:07 2019
+++ src/sys/arch/mac68k/obio/esp.c	Mon Feb 22 04:24:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: esp.c,v 1.58 2019/07/23 15:19:07 rin Exp $	*/
+/*	$NetBSD: esp.c,v 1.59 2021/02/22 04:24:41 rin Exp $	*/
 
 /*
  * Copyright (c) 1997 Jason R. Thorpe.
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: esp.c,v 1.58 2019/07/23 15:19:07 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: esp.c,v 1.59 2021/02/22 04:24:41 rin Exp $");
 
 #include 
 #include 
@@ -315,8 +315,8 @@ dafb_dreq:	bst = oa->oa_tag;
 	/* We need this to fit into the TCR... */
 	sc->sc_maxxfer = 64 * 1024;
 
-switch (current_mac_model->machineid) {
-case MACH_MACQ630:
+	switch (current_mac_model->machineid) {
+	case MACH_MACQ630:
 		/* XXX on LC630 64k xfer causes timeout error */
 		sc->sc_maxxfer = 63 * 1024;
 		break;
@@ -382,7 +382,7 @@ dafb_dreq:	bst = oa->oa_tag;
 			printf("failed to map omess buffer.\n");
 			goto out2;
 		}
-		
+
 		if (bus_dmamem_alloc(esc->sc_dmat, NBPG, 16, NBPG,
 		, 1, , BUS_DMA_NOWAIT)) {
 			printf("failed to allocate imess buffer.\n");
@@ -391,8 +391,8 @@ dafb_dreq:	bst = oa->oa_tag;
 		if (bus_dmamem_map(esc->sc_dmat, , irsegs,
 		NCR_MAX_MSG_LEN + 1, (void **)>sc_imess,
 		BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) {
-			printf("failed to map imess buffer.");
-			
+			printf("failed to map imess buffer.\n");
+
 			bus_dmamem_free(esc->sc_dmat, , irsegs);
 		out3:	bus_dmamem_unmap(esc->sc_dmat, sc->sc_omess, NBPG);
 		out2:	bus_dmamem_free(esc->sc_dmat, , orsegs);
@@ -484,7 +484,7 @@ esp_dma_intr(struct ncr53c9x_softc *sc)
 
 	cnt = *esc->sc_dmalen;
 	if (*esc->sc_dmalen == 0) {
-		printf("data interrupt, but no count left.");
+		printf("data interrupt, but no count left.\n");
 	}
 
 	p = *esc->sc_dmaaddr;
@@ -624,7 +624,7 @@ esp_quick_dma_intr(struct ncr53c9x_softc
 
 	trans = esc->sc_dmasize - resid;
 	if (trans < 0) {
-		printf("dmaintr: trans < 0");
+		printf("dmaintr: trans < 0\n");
 		trans = *esc->sc_dmalen;
 	}
 
@@ -1107,7 +1107,7 @@ esp_av_pio_intr(struct ncr53c9x_softc *s
 	uint8_t *p;
 
 #if DEBUG
-	printf("[av_pio_intr: intr 0x%x stat 0x%x] ", sc->sc_espintr,
+	printf("[av_pio_intr: intr 0x%x stat 0x%x]\n", sc->sc_espintr,
 	sc->sc_espstat);
 #endif
 
@@ -1123,7 +1123,7 @@ esp_av_pio_intr(struct ncr53c9x_softc *s
 	 * Is this possible?
 	 */
 	if (cnt == 0)
-		printf("data interrupt, but no count left.");
+		printf("data interrupt, but no count left.\n");
 #endif
 
 	p = *esc->sc_dmaaddr;
@@ -1227,7 +1227,7 @@ esp_av_dma_setup(struct ncr53c9x_softc *
 #endif
 		return 0;
 	}
-	
+
 	/*
 	 * Ensure the transfer is on a 16-byte aligned boundary for
 	 * the DMA engine by doing PIO to the next 16-byte boundary.



CVS commit: src/sys/arch/aarch64/aarch64

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Feb 22 02:18:33 UTC 2021

Modified Files:
src/sys/arch/aarch64/aarch64: trap.c

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/aarch64/aarch64/trap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Feb 22 02:18:33 UTC 2021

Modified Files:
src/sys/arch/aarch64/aarch64: trap.c

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/aarch64/aarch64/trap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/aarch64/aarch64/trap.c
diff -u src/sys/arch/aarch64/aarch64/trap.c:1.43 src/sys/arch/aarch64/aarch64/trap.c:1.44
--- src/sys/arch/aarch64/aarch64/trap.c:1.43	Thu Feb 18 11:23:15 2021
+++ src/sys/arch/aarch64/aarch64/trap.c	Mon Feb 22 02:18:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.43 2021/02/18 11:23:15 jmcneill Exp $ */
+/* $NetBSD: trap.c,v 1.44 2021/02/22 02:18:33 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.43 2021/02/18 11:23:15 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.44 2021/02/22 02:18:33 jmcneill Exp $");
 
 #include "opt_arm_intr_impl.h"
 #include "opt_compat_netbsd32.h"
@@ -919,7 +919,8 @@ sigdebug(const struct trapframe *tf, con
 }
 #endif
 
-void do_trapsignal1(
+void
+do_trapsignal1(
 #ifdef TRAP_SIGDEBUG
 const char *func,
 size_t line,



CVS commit: src/external/mpl/bind/dist/lib/isc/unix

2021-02-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 22 01:31:52 UTC 2021

Modified Files:
src/external/mpl/bind/dist/lib/isc/unix: socket.c

Log Message:
Locking protocol changed again, adjust.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/external/mpl/bind/dist/lib/isc/unix/socket.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/mpl/bind/dist/lib/isc/unix/socket.c
diff -u src/external/mpl/bind/dist/lib/isc/unix/socket.c:1.19 src/external/mpl/bind/dist/lib/isc/unix/socket.c:1.20
--- src/external/mpl/bind/dist/lib/isc/unix/socket.c:1.19	Fri Feb 19 11:42:20 2021
+++ src/external/mpl/bind/dist/lib/isc/unix/socket.c	Sun Feb 21 20:31:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: socket.c,v 1.19 2021/02/19 16:42:20 christos Exp $	*/
+/*	$NetBSD: socket.c,v 1.20 2021/02/22 01:31:51 christos Exp $	*/
 
 /*
  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
@@ -3214,8 +3214,6 @@ internal_fdwatch_write(isc__socket_t *so
 	if (more_data)
 		select_poke(sock->manager, sock->threadid, sock->fd,
 		SELECT_POKE_WRITE);
-
-	UNLOCK(>lock);
 }
 
 static void
@@ -3242,8 +3240,6 @@ internal_fdwatch_read(isc__socket_t *soc
 	if (more_data)
 		select_poke(sock->manager, sock->threadid, sock->fd,
 		SELECT_POKE_READ);
-
-	UNLOCK(>lock);
 }
 
 /*



CVS commit: src/external/mpl/bind/dist/lib/isc/unix

2021-02-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 22 01:31:52 UTC 2021

Modified Files:
src/external/mpl/bind/dist/lib/isc/unix: socket.c

Log Message:
Locking protocol changed again, adjust.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/external/mpl/bind/dist/lib/isc/unix/socket.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 23:37:10 UTC 2021

Modified Files:
src/sys/arch/aarch64/aarch64: idle_machdep.S

Log Message:
When waking from cpu_idle(), only call dosoftints if ci_intr_depth == 0


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/aarch64/aarch64/idle_machdep.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/aarch64/aarch64/idle_machdep.S
diff -u src/sys/arch/aarch64/aarch64/idle_machdep.S:1.7 src/sys/arch/aarch64/aarch64/idle_machdep.S:1.8
--- src/sys/arch/aarch64/aarch64/idle_machdep.S:1.7	Thu Feb 11 08:35:12 2021
+++ src/sys/arch/aarch64/aarch64/idle_machdep.S	Sun Feb 21 23:37:09 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: idle_machdep.S,v 1.7 2021/02/11 08:35:12 ryo Exp $ */
+/* $NetBSD: idle_machdep.S,v 1.8 2021/02/21 23:37:09 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include 
 #include "assym.h"
 
-RCSID("$NetBSD: idle_machdep.S,v 1.7 2021/02/11 08:35:12 ryo Exp $");
+RCSID("$NetBSD: idle_machdep.S,v 1.8 2021/02/21 23:37:09 jmcneill Exp $");
 
 #ifdef ARM_INTR_IMPL
 #include ARM_INTR_IMPL
@@ -93,6 +93,7 @@ ENTRY(cpu_idle)
 	str	w28, [x1, #CI_INTR_DEPTH]	/* ci->ci_intr_depth = old */
 
 #if defined(__HAVE_FAST_SOFTINTS) && !defined(__HAVE_PIC_FAST_SOFTINTS)
+	cbnz	w28, 1f/* Skip if intr_depth > 0 */
 	ldr	w3, [x1, #CI_SOFTINTS]		/* Get pending softint mask */
 	/* CPL should be 0 */
 	ldr	w2, [x1, #CI_CPL]		/* Get current priority level */



CVS commit: src/sys/arch/aarch64/aarch64

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 23:37:10 UTC 2021

Modified Files:
src/sys/arch/aarch64/aarch64: idle_machdep.S

Log Message:
When waking from cpu_idle(), only call dosoftints if ci_intr_depth == 0


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/aarch64/aarch64/idle_machdep.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/usb

2021-02-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Feb 21 23:06:39 UTC 2021

Modified Files:
src/sys/dev/usb: usb.c

Log Message:
add ddb commands to inspect usb xfer and xferlist structures.


To generate a diff of this commit:
cvs rdiff -u -r1.188 -r1.189 src/sys/dev/usb/usb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/usb.c
diff -u src/sys/dev/usb/usb.c:1.188 src/sys/dev/usb/usb.c:1.189
--- src/sys/dev/usb/usb.c:1.188	Fri Dec 18 01:40:20 2020
+++ src/sys/dev/usb/usb.c	Sun Feb 21 23:06:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb.c,v 1.188 2020/12/18 01:40:20 thorpej Exp $	*/
+/*	$NetBSD: usb.c,v 1.189 2021/02/21 23:06:39 mrg Exp $	*/
 
 /*
  * Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,10 +37,11 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.188 2020/12/18 01:40:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.189 2021/02/21 23:06:39 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
+#include "opt_ddb.h"
 #include "opt_compat_netbsd.h"
 #endif
 
@@ -329,6 +330,70 @@ usb_attach(device_t parent, device_t sel
 	config_interrupts(self, usb_doattach);
 }
 
+#ifdef DDB
+#include 
+#include 
+#include 
+
+static void
+db_usb_xfer(db_expr_t addr, bool have_addr, db_expr_t count,
+const char *modif)
+{
+	struct usbd_xfer *xfer = (struct usbd_xfer *)addr;
+
+	if (!have_addr){
+		db_printf("%s: need usbd_xfer address\n", __func__);
+		return;
+	}
+
+	db_printf("usb xfer: %p pipe %p priv %p buffer %p\n",
+	xfer, xfer->ux_pipe, xfer->ux_priv, xfer->ux_buffer);
+	db_printf(" len %x actlen %x flags %x timeout %x status %x\n",
+	xfer->ux_length, xfer->ux_actlen, xfer->ux_flags, xfer->ux_timeout,
+	xfer->ux_status);
+	db_printf(" callback %p done %x state %x tm_set %x tm_reset %x\n",
+	xfer->ux_callback, xfer->ux_done, xfer->ux_state,
+	xfer->ux_timeout_set, xfer->ux_timeout_reset);
+}
+
+static void
+db_usb_xferlist(db_expr_t addr, bool have_addr, db_expr_t count,
+const char *modif)
+{
+	struct usbd_pipe *pipe = (struct usbd_pipe *)addr;
+	struct usbd_xfer *xfer;
+
+	if (!have_addr){
+		db_printf("%s: need usbd_pipe address\n", __func__);
+		return;
+	}
+
+	db_printf("usb pipe: %p\n", pipe);
+	SIMPLEQ_FOREACH(xfer, >up_queue, ux_next) {
+		db_printf(" xfer = %p", xfer);
+	}
+}
+
+const struct db_command db_usb_command_table[] = {
+	{ DDB_ADD_CMD("usbxfer",	db_usb_xfer,	0, 
+	  "display a USB xfer structure",
+	  NULL, NULL) },
+	{ DDB_ADD_CMD("usbxferlist",	db_usb_xferlist,	0, 
+	  "display a USB xfer structure given pipe",
+	  NULL, NULL) },
+	{ DDB_ADD_CMD(NULL,	NULL,	0, NULL, NULL, NULL) }
+};
+
+static void
+usb_init_ddb(void)
+{
+
+	(void)db_register_tbl(DDB_SHOW_CMD, db_usb_command_table);
+}
+#else
+#define usb_init_ddb() /* nothing */
+#endif
+
 static int
 usb_once_init(void)
 {
@@ -369,6 +434,8 @@ usb_once_init(void)
 	usb_async_sih = softint_establish(SOFTINT_CLOCK | SOFTINT_MPSAFE,
 	   usb_async_intr, NULL);
 
+	usb_init_ddb();
+
 	return 0;
 }
 



CVS commit: src/sys/dev/usb

2021-02-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Feb 21 23:06:39 UTC 2021

Modified Files:
src/sys/dev/usb: usb.c

Log Message:
add ddb commands to inspect usb xfer and xferlist structures.


To generate a diff of this commit:
cvs rdiff -u -r1.188 -r1.189 src/sys/dev/usb/usb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/usb

2021-02-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Feb 21 23:06:13 UTC 2021

Modified Files:
src/sys/dev/usb: if_urtwn.c

Log Message:
replace printf "ERROR" with device_printf() and useful messages.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/dev/usb/if_urtwn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.93 src/sys/dev/usb/if_urtwn.c:1.94
--- src/sys/dev/usb/if_urtwn.c:1.93	Tue Feb  2 10:46:17 2021
+++ src/sys/dev/usb/if_urtwn.c	Sun Feb 21 23:06:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.93 2021/02/02 10:46:17 yamt Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.94 2021/02/21 23:06:13 mrg Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.93 2021/02/02 10:46:17 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.94 2021/02/21 23:06:13 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2621,7 +2621,7 @@ urtwn_txeof(struct usbd_xfer *xfer, void
 struct usbd_pipe *pipe = sc->tx_pipe[pidx];
 usbd_clear_endpoint_stall_async(pipe);
 			}
-			printf("ERROR1\n");
+			device_printf(sc->sc_dev, "device timeout\n");
 			if_statinc(ifp, if_oerrors);
 		}
 		splx(s);
@@ -2916,7 +2916,7 @@ urtwn_start(struct ifnet *ifp)
 
 		if (m->m_len < (int)sizeof(*eh) &&
 		(m = m_pullup(m, sizeof(*eh))) == NULL) {
-			printf("ERROR6\n");
+			device_printf(sc->sc_dev, "m_pullup failed\n");
 			if_statinc(ifp, if_oerrors);
 			urtwn_put_tx_data(sc, data);
 			continue;
@@ -2925,7 +2925,8 @@ urtwn_start(struct ifnet *ifp)
 		ni = ieee80211_find_txnode(ic, eh->ether_dhost);
 		if (ni == NULL) {
 			m_freem(m);
-			printf("ERROR5\n");
+			device_printf(sc->sc_dev,
+			"unable to find transmit node\n");
 			if_statinc(ifp, if_oerrors);
 			urtwn_put_tx_data(sc, data);
 			continue;
@@ -2935,7 +2936,8 @@ urtwn_start(struct ifnet *ifp)
 
 		if ((m = ieee80211_encap(ic, m, ni)) == NULL) {
 			ieee80211_free_node(ni);
-			printf("ERROR4\n");
+			device_printf(sc->sc_dev,
+			"unable to encapsulate packet\n");
 			if_statinc(ifp, if_oerrors);
 			urtwn_put_tx_data(sc, data);
 			continue;
@@ -2946,7 +2948,8 @@ urtwn_start(struct ifnet *ifp)
 		if (urtwn_tx(sc, m, ni, data) != 0) {
 			m_freem(m);
 			ieee80211_free_node(ni);
-			printf("ERROR3\n");
+			device_printf(sc->sc_dev,
+			"unable to transmit packet\n");
 			if_statinc(ifp, if_oerrors);
 			continue;
 		}
@@ -2968,9 +2971,8 @@ urtwn_watchdog(struct ifnet *ifp)
 
 	if (sc->tx_timer > 0) {
 		if (--sc->tx_timer == 0) {
-			aprint_error_dev(sc->sc_dev, "device timeout\n");
+			device_printf(sc->sc_dev, "device timeout\n");
 			/* urtwn_init(ifp); XXX needs a process context! */
-			printf("ERROR2\n");
 			if_statinc(ifp, if_oerrors);
 			return;
 		}



CVS commit: src/sys/dev/usb

2021-02-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Feb 21 23:06:13 UTC 2021

Modified Files:
src/sys/dev/usb: if_urtwn.c

Log Message:
replace printf "ERROR" with device_printf() and useful messages.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/dev/usb/if_urtwn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 22:21:56 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram: allow navigation with KEY_PPAGE and KEY_NPAGE


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 22:21:56 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram: allow navigation with KEY_PPAGE and KEY_NPAGE


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/cgram/cgram.c
diff -u src/games/cgram/cgram.c:1.10 src/games/cgram/cgram.c:1.11
--- src/games/cgram/cgram.c:1.10	Sun Feb 21 20:33:42 2021
+++ src/games/cgram/cgram.c	Sun Feb 21 22:21:56 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cgram.c,v 1.10 2021/02/21 20:33:42 rillig Exp $ */
+/* $NetBSD: cgram.c,v 1.11 2021/02/21 22:21:56 rillig Exp $ */
 
 /*-
  * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.c,v 1.10 2021/02/21 20:33:42 rillig Exp $");
+__RCSID("$NetBSD: cgram.c,v 1.11 2021/02/21 22:21:56 rillig Exp $");
 #endif
 
 #include 
@@ -361,8 +361,8 @@ closecurses(void)
 static void
 saturate_cursor(void)
 {
-	assert(cursor_y >= 0);
-	assert(cursor_y <= cur_max_y());
+	cursor_y = imax(cursor_y, 0);
+	cursor_y = imin(cursor_y, cur_max_y());
 
 	assert(cursor_x >= 0);
 	cursor_x = imin(cursor_x, cur_max_x());
@@ -445,13 +445,17 @@ handle_key(void)
 		break;
 	case 14:		/* ^N */
 	case KEY_DOWN:
-		if (cursor_y < cur_max_y())
-			cursor_y++;
+		cursor_y++;
 		break;
 	case 16:		/* ^P */
 	case KEY_UP:
-		if (cursor_y > 0)
-			cursor_y--;
+		cursor_y--;
+		break;
+	case KEY_PPAGE:
+		cursor_y -= LINES - 2;
+		break;
+	case KEY_NPAGE:
+		cursor_y += LINES - 2;
 		break;
 	case '*':
 		hinting = !hinting;



CVS commit: src

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 21:26:26 UTC 2021

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/indent: Makefile
Added Files:
src/tests/usr.bin/indent: comment-line-end.0 comment-line-end.0.stdout

Log Message:
indent: add test demonstrating that indent cannot handle C99

indent cannot handle line-end comments.

The indent test suite requires each test file to have both a NetBSD and
a FreeBSD RCS ID.  If the FreeBSD RCS ID is missing, the test will
silently pass since in that case, an empty file is compared with an
empty file.  See the /start/,/end/ operator in t_indent.sh.


To generate a diff of this commit:
cvs rdiff -u -r1.1021 -r1.1022 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/indent/comment-line-end.0 \
src/tests/usr.bin/indent/comment-line-end.0.stdout

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 21:26:26 UTC 2021

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/indent: Makefile
Added Files:
src/tests/usr.bin/indent: comment-line-end.0 comment-line-end.0.stdout

Log Message:
indent: add test demonstrating that indent cannot handle C99

indent cannot handle line-end comments.

The indent test suite requires each test file to have both a NetBSD and
a FreeBSD RCS ID.  If the FreeBSD RCS ID is missing, the test will
silently pass since in that case, an empty file is compared with an
empty file.  See the /start/,/end/ operator in t_indent.sh.


To generate a diff of this commit:
cvs rdiff -u -r1.1021 -r1.1022 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/indent/comment-line-end.0 \
src/tests/usr.bin/indent/comment-line-end.0.stdout

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1021 src/distrib/sets/lists/tests/mi:1.1022
--- src/distrib/sets/lists/tests/mi:1.1021	Sun Feb 21 08:05:51 2021
+++ src/distrib/sets/lists/tests/mi	Sun Feb 21 21:26:26 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1021 2021/02/21 08:05:51 rillig Exp $
+# $NetBSD: mi,v 1.1022 2021/02/21 21:26:26 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4708,6 +4708,8 @@
 ./usr/tests/usr.bin/indent/Kyuafile			tests-usr.bin-tests	compattestfile,atf,kyua
 ./usr/tests/usr.bin/indent/binary.0			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/indent/binary.0.stdout		tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/indent/comment-line-end.0		tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/indent/comment-line-end.0.stdout	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/indent/comments.0			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/indent/comments.0.pro		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/indent/comments.0.stdout		tests-usr.bin-tests	compattestfile,atf

Index: src/tests/usr.bin/indent/Makefile
diff -u src/tests/usr.bin/indent/Makefile:1.1 src/tests/usr.bin/indent/Makefile:1.2
--- src/tests/usr.bin/indent/Makefile:1.1	Thu Apr  4 15:27:35 2019
+++ src/tests/usr.bin/indent/Makefile	Sun Feb 21 21:26:26 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.1 2019/04/04 15:27:35 kamil Exp $
+#	$NetBSD: Makefile,v 1.2 2021/02/21 21:26:26 rillig Exp $
 
 .include 
 
@@ -8,6 +8,8 @@ TESTS_SH=	t_indent
 FILESDIR=	${TESTSDIR}
 FILES=		binary.0
 FILES+=		binary.0.stdout
+FILES+=		comment-line-end.0
+FILES+=		comment-line-end.0.stdout
 FILES+=		comments.0
 FILES+=		comments.0.pro
 FILES+=		comments.0.stdout

Added files:

Index: src/tests/usr.bin/indent/comment-line-end.0
diff -u /dev/null src/tests/usr.bin/indent/comment-line-end.0:1.1
--- /dev/null	Sun Feb 21 21:26:27 2021
+++ src/tests/usr.bin/indent/comment-line-end.0	Sun Feb 21 21:26:26 2021
@@ -0,0 +1,20 @@
+/* $NetBSD: comment-line-end.0,v 1.1 2021/02/21 21:26:26 rillig Exp $ */
+/* This $FreeBSD$ tag is required by the test suite, for no reason. */
+
+/*
+ * Demonstrates that line-end comments can affect the following lines.
+ *
+ * FIXME: The '{' of main must be in column 1, not directly after the ')'.
+ *
+ * FIXME: The 'Note: removing' below gets "indented" to 'Note:removing'.
+ *
+ * FIXME: The 'line-end' gets "indented" to 'line - end'.
+ */
+
+// Note: removing one of these line-end comments affects the formatting
+// of the main function below.
+
+int
+main(void)
+{
+}
Index: src/tests/usr.bin/indent/comment-line-end.0.stdout
diff -u /dev/null src/tests/usr.bin/indent/comment-line-end.0.stdout:1.1
--- /dev/null	Sun Feb 21 21:26:27 2021
+++ src/tests/usr.bin/indent/comment-line-end.0.stdout	Sun Feb 21 21:26:26 2021
@@ -0,0 +1,19 @@
+/* $NetBSD: comment-line-end.0.stdout,v 1.1 2021/02/21 21:26:26 rillig Exp $ */
+/* This $FreeBSD$ tag is required by the test suite, for no reason. */
+
+/*
+ * Demonstrates that line-end comments can affect the following lines.
+ *
+ * FIXME: The '{' of main must be in column 1, not directly after the ')'.
+ *
+ * FIXME: The 'Note: removing' below gets "indented" to 'Note:removing'.
+ *
+ * FIXME: The 'line-end' gets "indented" to 'line - end'.
+ */
+
+// Note:removing one of these line - end comments affects the formatting
+// of the main function below.
+
+int
+main(void){
+}



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 20:33:43 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram: rewrite completely, fixing bugs and style

Fixed bugs:

Do not consider the puzzle solved if all letters in the visible area are
substituted correctly.  To be properly solved, the whole puzzle must be
solved, even those parts that are currently off-screen.

Never place the cursor at the very right edge of the screen since that
does not work well with some terminals.  The maximum valid x coordinate
is COLS - 1.

Add horizontal scrolling.  Make all coordinate handling symmetric in
regard to the horizontal and vertical axes.  Previously, lines longer
than 80 characters could not be seen on the screen.

Improvements:

Remove the arbitrary limit of 128 characters per line.  Even if
fortune(6) may never generate such long lines, the code is easy enough
to adapt to other sources.

Properly clean up the allocated memory.  Previously, only the string
arrays were freed but not the strings themselves.

Stylistic:

Add RCS ID.

Fix ctype functions in lint's strict bool mode.

Avoid excessive calls to strlen whenever the cursor moves.  Given that
the whole screen is redrawn every time a key is pressed, this is an
unnecessary optimization, but the code smelled nevertheless.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/cgram/cgram.c
diff -u src/games/cgram/cgram.c:1.9 src/games/cgram/cgram.c:1.10
--- src/games/cgram/cgram.c:1.9	Sun Feb 21 17:16:00 2021
+++ src/games/cgram/cgram.c	Sun Feb 21 20:33:42 2021
@@ -1,11 +1,11 @@
-/* $NetBSD: cgram.c,v 1.9 2021/02/21 17:16:00 rillig Exp $ */
+/* $NetBSD: cgram.c,v 1.10 2021/02/21 20:33:42 rillig Exp $ */
 
 /*-
- * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
- * by David A. Holland.
+ * by David A. Holland and Roland Illig.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -29,6 +29,11 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include 
+#if defined(__RCSID) && !defined(lint)
+__RCSID("$NetBSD: cgram.c,v 1.10 2021/02/21 20:33:42 rillig Exp $");
+#endif
+
 #include 
 #include 
 #include 
@@ -43,19 +48,6 @@
 
 
 
-static char *
-xstrdup(const char *s)
-{
-	char *ret;
-
-	ret = malloc(strlen(s) + 1);
-	if (ret == NULL) {
-		errx(1, "Out of memory");
-	}
-	strcpy(ret, s);
-	return ret;
-}
-
 static char
 ch_toupper(char ch)
 {
@@ -71,29 +63,74 @@ ch_tolower(char ch)
 static bool
 ch_isalpha(char ch)
 {
-	return isalpha((unsigned char)ch);
+	return isalpha((unsigned char)ch) != 0;
 }
 
 static bool
 ch_islower(char ch)
 {
-	return islower((unsigned char)ch);
+	return islower((unsigned char)ch) != 0;
 }
 
 static bool
 ch_isupper(char ch)
 {
-	return isupper((unsigned char)ch);
+	return isupper((unsigned char)ch) != 0;
+}
+
+static int
+imax(int a, int b)
+{
+	return a > b ? a : b;
+}
+
+static int
+imin(int a, int b)
+{
+	return a < b ? a : b;
 }
 
 
 
+struct string {
+	char *s;
+	size_t len;
+	size_t cap;
+};
+
 struct stringarray {
-	char **v;
+	struct string *v;
 	size_t num;
 };
 
 static void
+string_init(struct string *s)
+{
+	s->s = NULL;
+	s->len = 0;
+	s->cap = 0;
+}
+
+static void
+string_add(struct string *s, char ch)
+{
+	if (s->len >= s->cap) {
+		s->cap = 2 * s->cap + 16;
+		s->s = realloc(s->s, s->cap);
+		if (s->s == NULL)
+			errx(1, "Out of memory");
+	}
+	s->s[s->len++] = ch;
+}
+
+static void
+string_finish(struct string *s)
+{
+	string_add(s, '\0');
+	s->len--;
+}
+
+static void
 stringarray_init(struct stringarray *a)
 {
 	a->v = NULL;
@@ -103,18 +140,33 @@ stringarray_init(struct stringarray *a)
 static void
 stringarray_cleanup(struct stringarray *a)
 {
+	for (size_t i = 0; i < a->num; i++)
+		free(a->v[i].s);
 	free(a->v);
 }
 
 static void
-stringarray_add(struct stringarray *a, const char *s)
+stringarray_add(struct stringarray *a, struct string *s)
 {
-	a->v = realloc(a->v, (a->num + 1) * sizeof(a->v[0]));
-	if (a->v == NULL) {
+	size_t num = a->num++;
+	a->v = realloc(a->v, a->num * sizeof a->v[0]);
+	if (a->v == NULL)
 		errx(1, "Out of memory");
+	a->v[num] = *s;
+}
+
+static void
+stringarray_dup(struct stringarray *dst, const struct stringarray *src)
+{
+	assert(dst->num == 0);
+	for (size_t i = 0; i < src->num; i++) {
+		struct string str;
+		string_init();
+		for (const char *p = src->v[i].s; *p != '\0'; p++)
+			string_add(, *p);
+		string_finish();
+		stringarray_add(dst, );
 	}
-	a->v[a->num] = xstrdup(s);
-	a->num++;
 }
 
 

CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 20:33:43 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram: rewrite completely, fixing bugs and style

Fixed bugs:

Do not consider the puzzle solved if all letters in the visible area are
substituted correctly.  To be properly solved, the whole puzzle must be
solved, even those parts that are currently off-screen.

Never place the cursor at the very right edge of the screen since that
does not work well with some terminals.  The maximum valid x coordinate
is COLS - 1.

Add horizontal scrolling.  Make all coordinate handling symmetric in
regard to the horizontal and vertical axes.  Previously, lines longer
than 80 characters could not be seen on the screen.

Improvements:

Remove the arbitrary limit of 128 characters per line.  Even if
fortune(6) may never generate such long lines, the code is easy enough
to adapt to other sources.

Properly clean up the allocated memory.  Previously, only the string
arrays were freed but not the strings themselves.

Stylistic:

Add RCS ID.

Fix ctype functions in lint's strict bool mode.

Avoid excessive calls to strlen whenever the cursor moves.  Given that
the whole screen is redrawn every time a key is pressed, this is an
unnecessary optimization, but the code smelled nevertheless.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/xen/x86

2021-02-21 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Feb 21 20:11:59 UTC 2021

Modified Files:
src/sys/arch/xen/x86: xen_shm_machdep.c

Log Message:
in xen_shm_map(), make sure to unmap any successfully mapped pages
before returning failure if there is partial failure

fix detection of partial failure - GNTTABOP_map_grant_ref can actually return
zero for partial failure, so we need to always check all the entries
to detect it

previously, DIAGNOSTIC kernel triggered panic() for partial failure,
and non-DIAGNOSTIC kernel did not detect it at all, leading to Dom0 page
fault later; since the mapping failure can be triggered by malicious
DomU via bad grant reference, it's important to expect the calls
to fail, and handle it gracefully without crashing Dom0

part of fixes for XSA-362


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/xen/x86/xen_shm_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/xen/x86/xen_shm_machdep.c
diff -u src/sys/arch/xen/x86/xen_shm_machdep.c:1.16 src/sys/arch/xen/x86/xen_shm_machdep.c:1.17
--- src/sys/arch/xen/x86/xen_shm_machdep.c:1.16	Sat Apr 25 15:26:17 2020
+++ src/sys/arch/xen/x86/xen_shm_machdep.c	Sun Feb 21 20:11:59 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: xen_shm_machdep.c,v 1.16 2020/04/25 15:26:17 bouyer Exp $  */
+/*  $NetBSD: xen_shm_machdep.c,v 1.17 2021/02/21 20:11:59 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.16 2020/04/25 15:26:17 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.17 2021/02/21 20:11:59 jdolecek Exp $");
 
 #include 
 #include 
@@ -45,16 +45,13 @@ __KERNEL_RCSID(0, "$NetBSD: xen_shm_mach
  * Helper routines for the backend drivers. This implements the necessary
  * functions to map a bunch of pages from foreign domains into our kernel VM
  * space, do I/O to it, and unmap it.
- *
- * At boot time, we grab some kernel VM space that we'll use to map the foreign
- * pages. We also maintain a virtual-to-machine mapping table to give back
- * the appropriate address to bus_dma if requested.
- *
- * If no more VM space is available, we return an error. The caller can then
- * register a callback which will be called when the required VM space is
- * available.
  */
 
+/*
+ * Map the memory referenced via grefp to supplied VA space.
+ * If there is a failure for particular gref, no memory is mapped
+ * and error is returned.
+ */
 int
 xen_shm_map(int nentries, int domid, grant_ref_t *grefp, vaddr_t va,
 grant_handle_t *handlep, int flags)
@@ -77,20 +74,69 @@ xen_shm_map(int nentries, int domid, gra
 	}
 
 	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, op, nentries);
-	if (__predict_false(ret)) {
-		printf("%s: HYPERVISOR_grant_table_op failed\n", __func__);
+	if (__predict_false(ret < 0)) {
+#ifdef DIAGNOSTIC
+		printf("%s: HYPERVISOR_grant_table_op failed %d\n", __func__,
+		ret);
+#endif
 		return EINVAL;
 	}
 
+	/*
+	 * If ret is positive, it means there was an error in processing,
+	 * and only first ret entries were actually handled. If it's zero,
+	 * it only means all entries were processed, but there could still
+	 * be failure.
+	 */
+	if (__predict_false(ret > 0 && ret < nentries)) {
+		nentries = ret;
+	}
+
 	for (i = 0; i < nentries; i++) {
+		if (__predict_false(op[i].status)) {
 #ifdef DIAGNOSTIC
-		if (__predict_false(op[i].status))
-			panic("%s: op[%d] status %d", __func__, i,
-			op[i].status);
+			printf("%s: op[%d] bad status %d gref %u\n", __func__,
+			i, op[i].status, grefp[i]);
 #endif
+			ret = 1;
+			continue;
+		}
 		handlep[i] = op[i].handle;
 	}
 
+	if (__predict_false(ret > 0)) {
+		int uncnt = 0;
+		gnttab_unmap_grant_ref_t unop[XENSHM_MAX_PAGES_PER_REQUEST];
+
+		/*
+		 * When returning error, make sure the successfully mapped
+		 * entries are unmapped before returning the error.
+		 * xen_shm_unmap() can't be used, it assumes
+		 * linear consecutive space.
+		 */
+		for (i = uncnt = 0; i < nentries; i++) {
+			if (op[i].status == 0) {
+unop[uncnt].host_addr = va + i * PAGE_SIZE;
+unop[uncnt].dev_bus_addr = 0;
+unop[uncnt].handle = handlep[i];
+uncnt++;
+			}
+		}
+		if (uncnt > 0) {
+			ret = HYPERVISOR_grant_table_op(
+			GNTTABOP_unmap_grant_ref, unop, uncnt);
+			if (ret != 0) {
+panic("%s: unmap on error recovery failed"
+" %d", __func__, ret);
+			}
+		}
+#ifdef DIAGNOSTIC
+		printf("%s: HYPERVISOR_grant_table_op bad entry\n",
+		__func__);
+#endif
+		return EINVAL;
+	}
+
 	return 0;
 }
 



CVS commit: src/sys/arch/xen/x86

2021-02-21 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Feb 21 20:11:59 UTC 2021

Modified Files:
src/sys/arch/xen/x86: xen_shm_machdep.c

Log Message:
in xen_shm_map(), make sure to unmap any successfully mapped pages
before returning failure if there is partial failure

fix detection of partial failure - GNTTABOP_map_grant_ref can actually return
zero for partial failure, so we need to always check all the entries
to detect it

previously, DIAGNOSTIC kernel triggered panic() for partial failure,
and non-DIAGNOSTIC kernel did not detect it at all, leading to Dom0 page
fault later; since the mapping failure can be triggered by malicious
DomU via bad grant reference, it's important to expect the calls
to fail, and handle it gracefully without crashing Dom0

part of fixes for XSA-362


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/xen/x86/xen_shm_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/xen/xen

2021-02-21 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Feb 21 20:02:25 UTC 2021

Modified Files:
src/sys/arch/xen/xen: xbdback_xenbus.c

Log Message:
reset xio_xv before calling xbdback_io_error() so it won't try to unmap
the non-initialized handles when xen_shm_map() fails

remove the ratechecked error printf for shm error - xbdback_io_error() prints
the error too

part of fixes for XSA-362


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/arch/xen/xen/xbdback_xenbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/xen/xen/xbdback_xenbus.c
diff -u src/sys/arch/xen/xen/xbdback_xenbus.c:1.96 src/sys/arch/xen/xen/xbdback_xenbus.c:1.97
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.96	Thu May  7 19:49:29 2020
+++ src/sys/arch/xen/xen/xbdback_xenbus.c	Sun Feb 21 20:02:25 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: xbdback_xenbus.c,v 1.96 2020/05/07 19:49:29 bouyer Exp $  */
+/*  $NetBSD: xbdback_xenbus.c,v 1.97 2021/02/21 20:02:25 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.96 2020/05/07 19:49:29 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.97 2021/02/21 20:02:25 jdolecek Exp $");
 
 #include 
 #include 
@@ -1570,13 +1570,11 @@ xbdback_map_shm(struct xbdback_io *xbd_i
 #endif
 		return xbd_io;
 	default:
-		if (ratecheck(>xbdi_lasterr_time, _err_intvl)) {
-			printf("xbdback_map_shm: xen_shm error %d ", error);
-		}
-		/* this will also free xbd_io via xbdback_iodone() */
-		xbdback_io_error(xbd_io, error);
+		/* reset xio_xv so error handling won't try to unmap it */
 		SLIST_INSERT_HEAD(>xbdi_va_free, xbd_io->xio_xv, xv_next);
 		xbd_io->xio_xv = NULL;
+		/* this will also free xbd_io via xbdback_iodone() */
+		xbdback_io_error(xbd_io, error);
 		/* do not retry */
 		xbdi->xbdi_cont = xbdback_co_main_incr;
 		return xbdi;



CVS commit: src/sys/arch/xen/xen

2021-02-21 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Feb 21 20:02:25 UTC 2021

Modified Files:
src/sys/arch/xen/xen: xbdback_xenbus.c

Log Message:
reset xio_xv before calling xbdback_io_error() so it won't try to unmap
the non-initialized handles when xen_shm_map() fails

remove the ratechecked error printf for shm error - xbdback_io_error() prints
the error too

part of fixes for XSA-362


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/arch/xen/xen/xbdback_xenbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 17:16:00 UTC 2021

Modified Files:
src/games/cgram: Makefile cgram.c

Log Message:
cgram: WARNS=6, use int for all coordinates

Eliminate some frequently occurring subexpressions during substitution.

No functional change, assuming that fortune(6) always spits out less
than 2 gigacharacters of text.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/games/cgram/Makefile
cvs rdiff -u -r1.8 -r1.9 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/cgram/Makefile
diff -u src/games/cgram/Makefile:1.2 src/games/cgram/Makefile:1.3
--- src/games/cgram/Makefile:1.2	Sun Feb 21 16:05:44 2021
+++ src/games/cgram/Makefile	Sun Feb 21 17:16:00 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2021/02/21 16:05:44 rillig Exp $
+# $NetBSD: Makefile,v 1.3 2021/02/21 17:16:00 rillig Exp $
 
 PROG=		cgram
 DPADD=		${LIBCURSES} ${LIBTERMINFO}
@@ -7,5 +7,6 @@ SRCS=		cgram.c
 MAN=		cgram.6
 HIDEGAME=	hidegame
 LINTFLAGS+=	-T
+WARNS=		6
 
 .include 

Index: src/games/cgram/cgram.c
diff -u src/games/cgram/cgram.c:1.8 src/games/cgram/cgram.c:1.9
--- src/games/cgram/cgram.c:1.8	Sun Feb 21 16:50:57 2021
+++ src/games/cgram/cgram.c	Sun Feb 21 17:16:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD */
+/* $NetBSD: cgram.c,v 1.9 2021/02/21 17:16:00 rillig Exp $ */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@ ch_isupper(char ch)
 
 struct stringarray {
 	char **v;
-	int num;
+	size_t num;
 };
 
 static void
@@ -123,7 +123,7 @@ static struct stringarray lines;
 static struct stringarray sollines;
 static bool hinting;
 static int scrolldown;
-static unsigned curx;
+static int curx;
 static int cury;
 
 static void
@@ -167,34 +167,32 @@ static void
 encode(void)
 {
 	int key[26];
+
 	for (int i = 0; i < 26; i++)
 		key[i] = i;
+
 	for (int i = 26; i > 1; i--) {
-		int c = random() % i;
+		int c = (int)(random() % i);
 		int t = key[i - 1];
 		key[i - 1] = key[c];
 		key[c] = t;
 	}
 
-	for (int y = 0; y < lines.num; y++) {
-		for (unsigned x = 0; lines.v[y][x] != '\0'; x++) {
-			if (ch_islower(lines.v[y][x])) {
-int q = lines.v[y][x] - 'a';
-lines.v[y][x] = 'a' + key[q];
-			}
-			if (ch_isupper(lines.v[y][x])) {
-int q = lines.v[y][x] - 'A';
-lines.v[y][x] = 'A' + key[q];
-			}
+	for (int y = 0; y < (int)lines.num; y++) {
+		for (char *p = lines.v[y]; *p != '\0'; p++) {
+			if (ch_islower(*p))
+*p = (char)('a' + key[*p - 'a']);
+			if (ch_isupper(*p))
+*p = (char)('A' + key[*p - 'A']);
 		}
 	}
 }
 
 static bool
-substitute(int ch)
+substitute(char ch)
 {
-	assert(cury >= 0 && cury < lines.num);
-	if (curx >= strlen(lines.v[cury])) {
+	assert(cury >= 0 && cury < (int)lines.num);
+	if (curx >= (int)strlen(lines.v[cury])) {
 		beep();
 		return false;
 	}
@@ -210,17 +208,16 @@ substitute(int ch)
 	char lch = ch_tolower(ch);
 	char uch = ch_toupper(ch);
 
-	for (int y = 0; y < lines.num; y++) {
-		for (unsigned x = 0; lines.v[y][x] != '\0'; x++) {
-			if (lines.v[y][x] == loch) {
-lines.v[y][x] = lch;
-			} else if (lines.v[y][x] == uoch) {
-lines.v[y][x] = uch;
-			} else if (lines.v[y][x] == lch) {
-lines.v[y][x] = loch;
-			} else if (lines.v[y][x] == uch) {
-lines.v[y][x] = uoch;
-			}
+	for (int y = 0; y < (int)lines.num; y++) {
+		for (char *p = lines.v[y]; *p != '\0'; p++) {
+			if (*p == loch)
+*p = lch;
+			else if (*p == uoch)
+*p = uch;
+			else if (*p == lch)
+*p = loch;
+			else if (*p == uch)
+*p = uoch;
 		}
 	}
 	return true;
@@ -236,7 +233,7 @@ redraw(void)
 	for (int i = 0; i < LINES - 1; i++) {
 		move(i, 0);
 		int ln = i + scrolldown;
-		if (ln < lines.num) {
+		if (ln < (int)lines.num) {
 			for (unsigned j = 0; lines.v[i][j] != '\0'; j++) {
 char ch = lines.v[i][j];
 if (ch != sollines.v[i][j] && ch_isalpha(ch)) {
@@ -304,18 +301,18 @@ loop(void)
 curx--;
 			} else if (cury > 0) {
 cury--;
-curx = strlen(lines.v[cury]);
+curx = (int)strlen(lines.v[cury]);
 			}
 			break;
 		case 5:		/* ^E */
 		case KEY_END:
-			curx = strlen(lines.v[cury]);
+			curx = (int)strlen(lines.v[cury]);
 			break;
 		case 6:		/* ^F */
 		case KEY_RIGHT:
-			if (curx < strlen(lines.v[cury])) {
+			if (curx < (int)strlen(lines.v[cury])) {
 curx++;
-			} else if (cury < lines.num - 1) {
+			} else if (cury < (int)lines.num - 1) {
 cury++;
 curx = 0;
 			}
@@ -325,11 +322,11 @@ loop(void)
 			break;
 		case 14:	/* ^N */
 		case KEY_DOWN:
-			if (cury < lines.num - 1) {
+			if (cury < (int)lines.num - 1) {
 cury++;
 			}
-			if (curx > strlen(lines.v[cury])) {
-curx = strlen(lines.v[cury]);
+			if (curx > (int)strlen(lines.v[cury])) {
+curx = (int)strlen(lines.v[cury]);
 			}
 			if (scrolldown < cury - (LINES - 2)) {
 scrolldown = cury - (LINES - 2);
@@ -340,8 +337,8 @@ loop(void)
 			if (cury > 0) {
 cury--;
 

CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 17:16:00 UTC 2021

Modified Files:
src/games/cgram: Makefile cgram.c

Log Message:
cgram: WARNS=6, use int for all coordinates

Eliminate some frequently occurring subexpressions during substitution.

No functional change, assuming that fortune(6) always spits out less
than 2 gigacharacters of text.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/games/cgram/Makefile
cvs rdiff -u -r1.8 -r1.9 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/arm/pic

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 17:07:45 UTC 2021

Modified Files:
src/sys/arch/arm/pic: pic.c pic_splfuncs.c picvar.h

Log Message:
Inline pic_set_priority and use cpu_dosoftints_ci when available.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/arm/pic/pic.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/arm/pic/pic_splfuncs.c
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/arm/pic/picvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/arm/pic

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 17:07:45 UTC 2021

Modified Files:
src/sys/arch/arm/pic: pic.c pic_splfuncs.c picvar.h

Log Message:
Inline pic_set_priority and use cpu_dosoftints_ci when available.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/arm/pic/pic.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/arm/pic/pic_splfuncs.c
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/arm/pic/picvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/pic/pic.c
diff -u src/sys/arch/arm/pic/pic.c:1.68 src/sys/arch/arm/pic/pic.c:1.69
--- src/sys/arch/arm/pic/pic.c:1.68	Sun Feb 21 08:31:36 2021
+++ src/sys/arch/arm/pic/pic.c	Sun Feb 21 17:07:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pic.c,v 1.68 2021/02/21 08:31:36 skrll Exp $	*/
+/*	$NetBSD: pic.c,v 1.69 2021/02/21 17:07:45 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -33,7 +33,7 @@
 #include "opt_multiprocessor.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pic.c,v 1.68 2021/02/21 08:31:36 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pic.c,v 1.69 2021/02/21 17:07:45 jmcneill Exp $");
 
 #include 
 #include 
@@ -95,34 +95,6 @@ EVCNT_ATTACH_STATIC(pic_deferral_ev);
 
 static int pic_init(void);
 
-#ifdef __HAVE_PIC_SET_PRIORITY
-void
-pic_set_priority(struct cpu_info *ci, int newipl)
-{
-	register_t psw = cpsid(I32_bit);
-	if (pic_list[0] != NULL)
-		(pic_list[0]->pic_ops->pic_set_priority)(pic_list[0], newipl);
-	ci->ci_cpl = newipl;
-	if ((psw & I32_bit) == 0)
-		cpsie(I32_bit);
-}
-
-void
-pic_set_priority_psw(struct cpu_info *ci, register_t psw, int newipl)
-{
-	if ((psw & I32_bit) == 0) {
-		DISABLE_INTERRUPT();
-	}
-	if (pic_list[0] != NULL) {
-		(pic_list[0]->pic_ops->pic_set_priority)(pic_list[0], newipl);
-	}
-	ci->ci_cpl = newipl;
-	if ((psw & I32_bit) == 0) {
-		ENABLE_INTERRUPT();
-	}
-}
-#endif
-
 #ifdef MULTIPROCESSOR
 int
 pic_ipi_ast(void *arg)
@@ -564,7 +536,7 @@ pic_do_pending_ints(register_t psw, int 
 			if (ipl <= newipl)
 break;
 
-			pic_set_priority_psw(ci, psw, ipl);
+			pic_set_priority(ci, ipl);
 			pic_list_deliver_irqs(ci, psw, ipl, frame);
 			pic_list_unblock_irqs(ci);
 		}
@@ -573,12 +545,12 @@ pic_do_pending_ints(register_t psw, int 
 #ifdef __HAVE_PREEMPTION
 	struct lwp *l = curlwp;
 	if (newipl == IPL_NONE && (l->l_md.md_astpending & __BIT(1))) {
-		pic_set_priority_psw(ci, psw, IPL_SCHED);
+		pic_set_priority(ci, IPL_SCHED);
 		kpreempt(0);
 	}
 #endif
 	if (ci->ci_cpl != newipl)
-		pic_set_priority_psw(ci, psw, newipl);
+		pic_set_priority(ci, newipl);
 }
 
 static void

Index: src/sys/arch/arm/pic/pic_splfuncs.c
diff -u src/sys/arch/arm/pic/pic_splfuncs.c:1.16 src/sys/arch/arm/pic/pic_splfuncs.c:1.17
--- src/sys/arch/arm/pic/pic_splfuncs.c:1.16	Sat Feb 20 22:53:31 2021
+++ src/sys/arch/arm/pic/pic_splfuncs.c	Sun Feb 21 17:07:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pic_splfuncs.c,v 1.16 2021/02/20 22:53:31 jmcneill Exp $	*/
+/*	$NetBSD: pic_splfuncs.c,v 1.17 2021/02/21 17:07:45 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -28,7 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pic_splfuncs.c,v 1.16 2021/02/20 22:53:31 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pic_splfuncs.c,v 1.17 2021/02/21 17:07:45 jmcneill Exp $");
 
 #define _INTR_PRIVATE
 #include 
@@ -101,7 +101,7 @@ splx(int savedipl)
 break;
 			}
 
-			pic_set_priority_psw(ci, psw, ipl);
+			pic_set_priority(ci, ipl);
 			pic_list_deliver_irqs(ci, psw, ipl, NULL);
 			pic_list_unblock_irqs(ci);
 		}
@@ -113,11 +113,12 @@ splx(int savedipl)
 skip_pending:
 #endif
 
-	ci->ci_cpl = savedipl;
-	if (__predict_true(pic_list[0] != NULL)) {
-		(pic_list[0]->pic_ops->pic_set_priority)(pic_list[0], savedipl);
-	}
+	pic_set_priority(ci, savedipl);
+#if defined(__HAVE_CPU_DOSOFTINTS_CI)
+	cpu_dosoftints_ci(ci);
+#else
 	cpu_dosoftints();
+#endif
 
 	KASSERTMSG(ci->ci_cpl == savedipl, "cpl %d savedipl %d",
 	ci->ci_cpl, savedipl);

Index: src/sys/arch/arm/pic/picvar.h
diff -u src/sys/arch/arm/pic/picvar.h:1.30 src/sys/arch/arm/pic/picvar.h:1.31
--- src/sys/arch/arm/pic/picvar.h:1.30	Sat Feb 20 19:30:46 2021
+++ src/sys/arch/arm/pic/picvar.h	Sun Feb 21 17:07:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: picvar.h,v 1.30 2021/02/20 19:30:46 jmcneill Exp $	*/
+/*	$NetBSD: picvar.h,v 1.31 2021/02/21 17:07:45 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -176,18 +176,21 @@ struct pic_ops {
 #endif
 };
 
+/* Using an inline causes catch-22 problems with cpu.h */
 #ifdef __HAVE_PIC_SET_PRIORITY
 /*
  * This is used to update a hardware pic with a value corresponding
  * to the ipl being set.
  */
-struct cpu_info;
-void	pic_set_priority(struct cpu_info *, int);
-void	pic_set_priority_psw(struct cpu_info *, register_t, int);

CVS commit: src/sys/arch/aarch64/include

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 17:07:06 UTC 2021

Modified Files:
src/sys/arch/aarch64/include: cpu.h

Log Message:
Add cpu_dosoftints_ci(). Like cpu_dosoftints(), but takes a cpu_info ptr
so we can avoid the extra tpidr_el1 access if cpu_info is already known.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/aarch64/include/cpu.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/aarch64/include/cpu.h
diff -u src/sys/arch/aarch64/include/cpu.h:1.32 src/sys/arch/aarch64/include/cpu.h:1.33
--- src/sys/arch/aarch64/include/cpu.h:1.32	Sun Feb 21 15:00:04 2021
+++ src/sys/arch/aarch64/include/cpu.h	Sun Feb 21 17:07:06 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.32 2021/02/21 15:00:04 jmcneill Exp $ */
+/* $NetBSD: cpu.h,v 1.33 2021/02/21 17:07:06 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014, 2020 The NetBSD Foundation, Inc.
@@ -178,18 +178,29 @@ extern struct cpu_info cpu_info_store[];
 
 #define	LWP0_CPU_INFO	(_info_store[0])
 
+#define	__HAVE_CPU_DOSOFTINTS_CI
+
 static inline void
-cpu_dosoftints(void)
+cpu_dosoftints_ci(struct cpu_info *ci)
 {
 #if defined(__HAVE_FAST_SOFTINTS) && !defined(__HAVE_PIC_FAST_SOFTINTS)
 	void dosoftints(void);
-	struct cpu_info * const ci = curcpu();
 
-	if (ci->ci_intr_depth == 0 && (ci->ci_softints >> ci->ci_cpl) > 0)
+	if (ci->ci_intr_depth == 0 && (ci->ci_softints >> ci->ci_cpl) > 0) {
 		dosoftints();
+	}
+#endif
+}
+
+static inline void
+cpu_dosoftints(void)
+{
+#if defined(__HAVE_FAST_SOFTINTS) && !defined(__HAVE_PIC_FAST_SOFTINTS)
+	cpu_dosoftints_ci(curcpu());
 #endif
 }
 
+
 #endif /* _KERNEL */
 
 #endif /* _KERNEL || _KMEMUSER */



CVS commit: src/sys/arch/aarch64/include

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 17:07:06 UTC 2021

Modified Files:
src/sys/arch/aarch64/include: cpu.h

Log Message:
Add cpu_dosoftints_ci(). Like cpu_dosoftints(), but takes a cpu_info ptr
so we can avoid the extra tpidr_el1 access if cpu_info is already known.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/aarch64/include/cpu.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 16:50:58 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram: consistently use char for characters

Having to convert back and forth between char, unsigned char and int is
confusing.  Just stay with char, until the support for wide characters
is added.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/cgram/cgram.c
diff -u src/games/cgram/cgram.c:1.7 src/games/cgram/cgram.c:1.8
--- src/games/cgram/cgram.c:1.7	Sun Feb 21 16:37:26 2021
+++ src/games/cgram/cgram.c	Sun Feb 21 16:50:57 2021
@@ -56,6 +56,36 @@ xstrdup(const char *s)
 	return ret;
 }
 
+static char
+ch_toupper(char ch)
+{
+	return (char)toupper((unsigned char)ch);
+}
+
+static char
+ch_tolower(char ch)
+{
+	return (char)tolower((unsigned char)ch);
+}
+
+static bool
+ch_isalpha(char ch)
+{
+	return isalpha((unsigned char)ch);
+}
+
+static bool
+ch_islower(char ch)
+{
+	return islower((unsigned char)ch);
+}
+
+static bool
+ch_isupper(char ch)
+{
+	return isupper((unsigned char)ch);
+}
+
 
 
 struct stringarray {
@@ -148,11 +178,11 @@ encode(void)
 
 	for (int y = 0; y < lines.num; y++) {
 		for (unsigned x = 0; lines.v[y][x] != '\0'; x++) {
-			if (islower((unsigned char)lines.v[y][x])) {
+			if (ch_islower(lines.v[y][x])) {
 int q = lines.v[y][x] - 'a';
 lines.v[y][x] = 'a' + key[q];
 			}
-			if (isupper((unsigned char)lines.v[y][x])) {
+			if (ch_isupper(lines.v[y][x])) {
 int q = lines.v[y][x] - 'A';
 lines.v[y][x] = 'A' + key[q];
 			}
@@ -169,16 +199,16 @@ substitute(int ch)
 		return false;
 	}
 
-	int och = lines.v[cury][curx];
-	if (!isalpha((unsigned char)och)) {
+	char och = lines.v[cury][curx];
+	if (!ch_isalpha(och)) {
 		beep();
 		return false;
 	}
 
-	int loch = tolower((unsigned char)och);
-	int uoch = toupper((unsigned char)och);
-	int lch = tolower((unsigned char)ch);
-	int uch = toupper((unsigned char)ch);
+	char loch = ch_tolower(och);
+	char uoch = ch_toupper(och);
+	char lch = ch_tolower(ch);
+	char uch = ch_toupper(ch);
 
 	for (int y = 0; y < lines.num; y++) {
 		for (unsigned x = 0; lines.v[y][x] != '\0'; x++) {
@@ -208,14 +238,13 @@ redraw(void)
 		int ln = i + scrolldown;
 		if (ln < lines.num) {
 			for (unsigned j = 0; lines.v[i][j] != '\0'; j++) {
-int ch = lines.v[i][j];
-if (ch != sollines.v[i][j] &&
-isalpha((unsigned char)ch)) {
+char ch = lines.v[i][j];
+if (ch != sollines.v[i][j] && ch_isalpha(ch)) {
 	won = false;
 }
 bool bold = false;
 if (hinting && ch == sollines.v[i][j] &&
-isalpha((unsigned char)ch)) {
+ch_isalpha(ch)) {
 	bold = true;
 	attron(A_BOLD);
 }



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 16:50:58 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram: consistently use char for characters

Having to convert back and forth between char, unsigned char and int is
confusing.  Just stay with char, until the support for wide characters
is added.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 16:37:26 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram: fix undefined behavior when pressing function keys

The key codes for function keys are outside of the "range representable
by an unsigned char".  This resulted in parts of the screen being
cleaned.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 16:37:26 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram: fix undefined behavior when pressing function keys

The key codes for function keys are outside of the "range representable
by an unsigned char".  This resulted in parts of the screen being
cleaned.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/cgram/cgram.c
diff -u src/games/cgram/cgram.c:1.6 src/games/cgram/cgram.c:1.7
--- src/games/cgram/cgram.c:1.6	Sun Feb 21 16:05:44 2021
+++ src/games/cgram/cgram.c	Sun Feb 21 16:37:26 2021
@@ -325,7 +325,7 @@ loop(void)
 			done = true;
 			break;
 		default:
-			if (isalpha(ch)) {
+			if (isascii(ch) && isalpha(ch)) {
 if (substitute(ch)) {
 	if (curx < strlen(lines.v[cury])) {
 		curx++;



CVS commit: src/lib/libc/gen

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 16:33:23 UTC 2021

Modified Files:
src/lib/libc/gen: isascii.3

Log Message:
isascii.3: fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/libc/gen/isascii.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/gen/isascii.3
diff -u src/lib/libc/gen/isascii.3:1.18 src/lib/libc/gen/isascii.3:1.19
--- src/lib/libc/gen/isascii.3:1.18	Fri Apr 30 04:46:18 2010
+++ src/lib/libc/gen/isascii.3	Sun Feb 21 16:33:22 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: isascii.3,v 1.18 2010/04/30 04:46:18 jruoho Exp $
+.\"	$NetBSD: isascii.3,v 1.19 2021/02/21 16:33:22 rillig Exp $
 .\"
 .\" Copyright (c) 1989, 1991 The Regents of the University of California.
 .\" All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\" @(#)isascii.3	5.1 (Berkeley) 5/2/91
 .\"
-.Dd April 30, 2010
+.Dd February 21, 2021
 .Dt ISASCII 3
 .Os
 .Sh NAME
@@ -51,7 +51,7 @@ range from 0 to 127, inclusive.
 .Pp
 The
 .Fn isascii
-is defined on all integer values.
+function is defined on all integer values.
 .Sh SEE ALSO
 .Xr ctype 3 ,
 .Xr isalnum 3 ,



CVS commit: src/lib/libc/gen

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 16:33:23 UTC 2021

Modified Files:
src/lib/libc/gen: isascii.3

Log Message:
isascii.3: fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/libc/gen/isascii.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/arm/sunxi

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 16:07:43 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sunxi_emac.h

Log Message:
Align descriptors to 64 bytes instead of CACHE_LINE_SIZE (128) as all known
Allwinner SoCs with this part use 64-byte cache lines.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sunxi/sunxi_emac.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/sunxi/sunxi_emac.h
diff -u src/sys/arch/arm/sunxi/sunxi_emac.h:1.4 src/sys/arch/arm/sunxi/sunxi_emac.h:1.5
--- src/sys/arch/arm/sunxi/sunxi_emac.h:1.4	Sun Oct  1 15:05:09 2017
+++ src/sys/arch/arm/sunxi/sunxi_emac.h	Sun Feb 21 16:07:43 2021
@@ -203,8 +203,8 @@ struct sunxi_emac_desc {
 	uint32_t	addr;
 
 	uint32_t	next;
-} __packed __aligned(CACHE_LINE_SIZE);
+} __packed __aligned(64);
 
-__CTASSERT(sizeof(struct sunxi_emac_desc) == CACHE_LINE_SIZE);
+__CTASSERT(sizeof(struct sunxi_emac_desc) == 64);
 
 #endif /* !__SUNXI_EMAC_H__ */



CVS commit: src/sys/arch/arm/sunxi

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 16:07:43 UTC 2021

Modified Files:
src/sys/arch/arm/sunxi: sunxi_emac.h

Log Message:
Align descriptors to 64 bytes instead of CACHE_LINE_SIZE (128) as all known
Allwinner SoCs with this part use 64-byte cache lines.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sunxi/sunxi_emac.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 16:05:44 UTC 2021

Modified Files:
src/games/cgram: Makefile cgram.c

Log Message:
cgram: adjust style to survive lint's strict bool mode

The biggest change is the return type of substitute().  Before, 0 meant
success, now false means failure.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/games/cgram/Makefile
cvs rdiff -u -r1.5 -r1.6 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 16:05:44 UTC 2021

Modified Files:
src/games/cgram: Makefile cgram.c

Log Message:
cgram: adjust style to survive lint's strict bool mode

The biggest change is the return type of substitute().  Before, 0 meant
success, now false means failure.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/games/cgram/Makefile
cvs rdiff -u -r1.5 -r1.6 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/cgram/Makefile
diff -u src/games/cgram/Makefile:1.1 src/games/cgram/Makefile:1.2
--- src/games/cgram/Makefile:1.1	Sun Aug  4 05:42:47 2013
+++ src/games/cgram/Makefile	Sun Feb 21 16:05:44 2021
@@ -1,10 +1,11 @@
-# $NetBSD: Makefile,v 1.1 2013/08/04 05:42:47 dholland Exp $
+# $NetBSD: Makefile,v 1.2 2021/02/21 16:05:44 rillig Exp $
 
-PROG=cgram
-DPADD=${LIBCURSES} ${LIBTERMINFO}
-LDADD=-lcurses -lterminfo
-SRCS=cgram.c
-MAN=cgram.6
-HIDEGAME=hidegame
+PROG=		cgram
+DPADD=		${LIBCURSES} ${LIBTERMINFO}
+LDADD=		-lcurses -lterminfo
+SRCS=		cgram.c
+MAN=		cgram.6
+HIDEGAME=	hidegame
+LINTFLAGS+=	-T
 
 .include 

Index: src/games/cgram/cgram.c
diff -u src/games/cgram/cgram.c:1.5 src/games/cgram/cgram.c:1.6
--- src/games/cgram/cgram.c:1.5	Sun Feb 21 15:42:21 2021
+++ src/games/cgram/cgram.c	Sun Feb 21 16:05:44 2021
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -99,22 +100,22 @@ static void
 readquote(void)
 {
 	FILE *f = popen(_PATH_FORTUNE, "r");
-	if (!f) {
+	if (f == NULL) {
 		err(1, "%s", _PATH_FORTUNE);
 	}
 
 	char buf[128], buf2[8 * sizeof(buf)];
-	while (fgets(buf, sizeof(buf), f)) {
+	while (fgets(buf, sizeof buf, f) != NULL) {
 		char *s = strrchr(buf, '\n');
-		assert(s);
+		assert(s != NULL);
 		assert(strlen(s) == 1);
-		*s = 0;
+		*s = '\0';
 
 		int i, j;
-		for (i = j = 0; buf[i]; i++) {
+		for (i = j = 0; buf[i] != '\0'; i++) {
 			if (buf[i] == '\t') {
 buf2[j++] = ' ';
-while (j % 8)
+while (j % 8 != 0)
 	buf2[j++] = ' ';
 			} else if (buf[i] == '\b') {
 if (j > 0)
@@ -123,7 +124,7 @@ readquote(void)
 buf2[j++] = buf[i];
 			}
 		}
-		buf2[j] = 0;
+		buf2[j] = '\0';
 
 		stringarray_add(, buf2);
 		stringarray_add(, buf2);
@@ -146,7 +147,7 @@ encode(void)
 	}
 
 	for (int y = 0; y < lines.num; y++) {
-		for (unsigned x = 0; lines.v[y][x]; x++) {
+		for (unsigned x = 0; lines.v[y][x] != '\0'; x++) {
 			if (islower((unsigned char)lines.v[y][x])) {
 int q = lines.v[y][x] - 'a';
 lines.v[y][x] = 'a' + key[q];
@@ -159,19 +160,19 @@ encode(void)
 	}
 }
 
-static int
+static bool
 substitute(int ch)
 {
 	assert(cury >= 0 && cury < lines.num);
 	if (curx >= strlen(lines.v[cury])) {
 		beep();
-		return -1;
+		return false;
 	}
 
 	int och = lines.v[cury][curx];
 	if (!isalpha((unsigned char)och)) {
 		beep();
-		return -1;
+		return false;
 	}
 
 	int loch = tolower((unsigned char)och);
@@ -180,7 +181,7 @@ substitute(int ch)
 	int uch = toupper((unsigned char)ch);
 
 	for (int y = 0; y < lines.num; y++) {
-		for (unsigned x = 0; lines.v[y][x]; x++) {
+		for (unsigned x = 0; lines.v[y][x] != '\0'; x++) {
 			if (lines.v[y][x] == loch) {
 lines.v[y][x] = lch;
 			} else if (lines.v[y][x] == uoch) {
@@ -192,7 +193,7 @@ substitute(int ch)
 			}
 		}
 	}
-	return 0;
+	return true;
 }
 
 
@@ -206,7 +207,7 @@ redraw(void)
 		move(i, 0);
 		int ln = i + scrolldown;
 		if (ln < lines.num) {
-			for (unsigned j = 0; lines.v[i][j]; j++) {
+			for (unsigned j = 0; lines.v[i][j] != '\0'; j++) {
 int ch = lines.v[i][j];
 if (ch != sollines.v[i][j] &&
 isalpha((unsigned char)ch)) {
@@ -325,7 +326,7 @@ loop(void)
 			break;
 		default:
 			if (isalpha(ch)) {
-if (!substitute(ch)) {
+if (substitute(ch)) {
 	if (curx < strlen(lines.v[cury])) {
 		curx++;
 	}
@@ -364,7 +365,7 @@ main(void)
 	encode();
 	opencurses();
 
-	keypad(stdscr, TRUE);
+	keypad(stdscr, true);
 	loop();
 
 	closecurses();



CVS commit: src/sys/arch/arm/cortex

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 15:45:30 UTC 2021

Modified Files:
src/sys/arch/arm/cortex: gic.c

Log Message:
Apply PMR optimizations from gicv3


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/arm/cortex/gic.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/cortex/gic.c
diff -u src/sys/arch/arm/cortex/gic.c:1.44 src/sys/arch/arm/cortex/gic.c:1.45
--- src/sys/arch/arm/cortex/gic.c:1.44	Tue Feb  9 14:24:14 2021
+++ src/sys/arch/arm/cortex/gic.c	Sun Feb 21 15:45:30 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: gic.c,v 1.44 2021/02/09 14:24:14 jakllsch Exp $	*/
+/*	$NetBSD: gic.c,v 1.45 2021/02/21 15:45:30 jmcneill Exp $	*/
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -34,7 +34,7 @@
 #define _INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gic.c,v 1.44 2021/02/09 14:24:14 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gic.c,v 1.45 2021/02/21 15:45:30 jmcneill Exp $");
 
 #include 
 #include 
@@ -222,9 +222,14 @@ static void
 armgic_set_priority(struct pic_softc *pic, int ipl)
 {
 	struct armgic_softc * const sc = PICTOSOFTC(pic);
+	struct cpu_info * const ci = curcpu();
 
 	const uint32_t priority = armgic_ipl_to_priority(ipl);
-	gicc_write(sc, GICC_PMR, priority);
+	if (priority > ci->ci_hwpl) {
+		/* Lowering priority mask */
+		ci->ci_hwpl = priority;
+		gicc_write(sc, GICC_PMR, priority);
+	}
 }
 
 #ifdef MULTIPROCESSOR
@@ -322,6 +327,12 @@ armgic_irq_handler(void *tf)
 
 	ci->ci_data.cpu_nintr++;
 
+	const uint32_t priority = armgic_ipl_to_priority(old_ipl);
+	if (ci->ci_hwpl != priority) {
+		ci->ci_hwpl = priority;
+		gicc_write(sc, GICC_PMR, priority);
+	}
+
 	for (;;) {
 		uint32_t iar = gicc_read(sc, GICC_IAR);
 		uint32_t irq = __SHIFTOUT(iar, GICC_IAR_IRQ);
@@ -365,7 +376,7 @@ armgic_irq_handler(void *tf)
 			ipl, ci->ci_cpl,
 			gicc_read(sc, GICC_PMR));
 			gicc_write(sc, GICC_PMR, armgic_ipl_to_priority(ipl));
-			ci->ci_cpl = ipl;
+			ci->ci_hwpl = ci->ci_cpl = ipl;
 		}
 		ENABLE_INTERRUPT();
 		pic_dispatch(is, tf);
@@ -527,6 +538,7 @@ armgic_cpu_init(struct pic_softc *pic, s
 			sc->sc_enabled_local);
 		}
 	}
+	ci->ci_hwpl = armgic_ipl_to_priority(ci->ci_cpl);
 	gicc_write(sc, GICC_PMR, armgic_ipl_to_priority(ci->ci_cpl));	// set PMR
 	gicc_write(sc, GICC_CTRL, GICC_CTRL_V1_Enable);	// enable interrupt
 	ENABLE_INTERRUPT();// allow IRQ exceptions



CVS commit: src/sys/arch/arm/cortex

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 15:45:30 UTC 2021

Modified Files:
src/sys/arch/arm/cortex: gic.c

Log Message:
Apply PMR optimizations from gicv3


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/arm/cortex/gic.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 15:42:21 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram: sort includes


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/cgram/cgram.c
diff -u src/games/cgram/cgram.c:1.4 src/games/cgram/cgram.c:1.5
--- src/games/cgram/cgram.c:1.4	Sun Feb 21 15:41:04 2021
+++ src/games/cgram/cgram.c	Sun Feb 21 15:42:21 2021
@@ -29,14 +29,15 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include 
+#include 
+#include 
+#include 
 #include 
-#include 
 #include 
-#include 
+#include 
 #include 
-#include 
-#include 
-#include 
+
 #include "pathnames.h"
 
 



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 15:42:21 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram: sort includes


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 15:41:04 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram: indent

With manual corrections afterwards:

- indent removes empty lines between statement and declaration.  This
  had been a syntax error in C90, since C99 this is common style and
  should be accepted by indent.

- indent didn't format the first line of main for whatever reason, did
  that manually.

- indent removed the empty line above the '/' separators.  It should
  have left these empty lines as-is.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 15:41:04 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram: indent

With manual corrections afterwards:

- indent removes empty lines between statement and declaration.  This
  had been a syntax error in C90, since C99 this is common style and
  should be accepted by indent.

- indent didn't format the first line of main for whatever reason, did
  that manually.

- indent removed the empty line above the '/' separators.  It should
  have left these empty lines as-is.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/cgram/cgram.c
diff -u src/games/cgram/cgram.c:1.3 src/games/cgram/cgram.c:1.4
--- src/games/cgram/cgram.c:1.3	Sun Feb 21 13:35:37 2021
+++ src/games/cgram/cgram.c	Sun Feb 21 15:41:04 2021
@@ -1,3 +1,5 @@
+/* $NetBSD */
+
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -39,40 +41,48 @@
 
 
 
-static char *xstrdup(const char *s) {
-   char *ret;
-
-   ret = malloc(strlen(s) + 1);
-   if (ret == NULL) {
-  errx(1, "Out of memory");
-   }
-   strcpy(ret, s);
-   return ret;
+static char *
+xstrdup(const char *s)
+{
+	char *ret;
+
+	ret = malloc(strlen(s) + 1);
+	if (ret == NULL) {
+		errx(1, "Out of memory");
+	}
+	strcpy(ret, s);
+	return ret;
 }
 
 
 
 struct stringarray {
-   char **v;
-   int num;
+	char **v;
+	int num;
 };
 
-static void stringarray_init(struct stringarray *a) {
-   a->v = NULL;
-   a->num = 0;
-}
-
-static void stringarray_cleanup(struct stringarray *a) {
-   free(a->v);
-}
-
-static void stringarray_add(struct stringarray *a, const char *s) {
-   a->v = realloc(a->v, (a->num + 1) * sizeof(a->v[0]));
-   if (a->v == NULL) {
-  errx(1, "Out of memory");
-   }
-   a->v[a->num] = xstrdup(s);
-   a->num++;
+static void
+stringarray_init(struct stringarray *a)
+{
+	a->v = NULL;
+	a->num = 0;
+}
+
+static void
+stringarray_cleanup(struct stringarray *a)
+{
+	free(a->v);
+}
+
+static void
+stringarray_add(struct stringarray *a, const char *s)
+{
+	a->v = realloc(a->v, (a->num + 1) * sizeof(a->v[0]));
+	if (a->v == NULL) {
+		errx(1, "Out of memory");
+	}
+	a->v[a->num] = xstrdup(s);
+	a->num++;
 }
 
 
@@ -84,265 +94,279 @@ static int scrolldown;
 static unsigned curx;
 static int cury;
 
-static void readquote(void) {
-   FILE *f = popen(_PATH_FORTUNE, "r");
-   if (!f) {
-  err(1, "%s", _PATH_FORTUNE);
-   }
-
-   char buf[128], buf2[8*sizeof(buf)];
-   while (fgets(buf, sizeof(buf), f)) {
-  char *s = strrchr(buf, '\n');
-  assert(s);
-  assert(strlen(s)==1);
-  *s = 0;
-
-  int i,j;
-  for (i=j=0; buf[i]; i++) {
-	 if (buf[i]=='\t') {
-	buf2[j++] = ' ';
-	while (j%8) buf2[j++] = ' ';
-	 }
-	 else if (buf[i]=='\b') {
-	if (j>0) j--;
-	 }
-	 else {
-	buf2[j++] = buf[i];
-	 }
-  }
-  buf2[j] = 0;
-
-  stringarray_add(, buf2);
-  stringarray_add(, buf2);
-   }
-
-   pclose(f);
-}
-
-static void encode(void) {
-   int key[26];
-   for (int i=0; i<26; i++) key[i] = i;
-   for (int i=26; i>1; i--) {
-  int c = random() % i;
-  int t = key[i-1];
-  key[i-1] = key[c];
-  key[c] = t;
-   }
-
-   for (int y=0; y=0 && cury= strlen(lines.v[cury])) {
-  beep();
-  return -1;
-   }
-
-   int och = lines.v[cury][curx];
-   if (!isalpha((unsigned char)och)) {
-  beep();
-  return -1;
-   }
-
-   int loch = tolower((unsigned char)och);
-   int uoch = toupper((unsigned char)och);
-   int lch = tolower((unsigned char)ch);
-   int uch = toupper((unsigned char)ch);
-
-   for (int y=0; y 0)
+	j--;
+			} else {
+buf2[j++] = buf[i];
+			}
+		}
+		buf2[j] = 0;
+
+		stringarray_add(, buf2);
+		stringarray_add(, buf2);
+	}
+
+	pclose(f);
+}
+
+static void
+encode(void)
+{
+	int key[26];
+	for (int i = 0; i < 26; i++)
+		key[i] = i;
+	for (int i = 26; i > 1; i--) {
+		int c = random() % i;
+		int t = key[i - 1];
+		key[i - 1] = key[c];
+		key[c] = t;
+	}
+
+	for (int y = 0; y < lines.num; y++) {
+		for (unsigned x = 0; lines.v[y][x]; x++) {
+			if (islower((unsigned char)lines.v[y][x])) {
+int q = lines.v[y][x] - 'a';
+lines.v[y][x] = 'a' + key[q];
+			}
+			if (isupper((unsigned char)lines.v[y][x])) {
+int q = lines.v[y][x] - 'A';
+lines.v[y][x] = 'A' + key[q];
+			}
+		}
+	}
+}
+
+static int
+substitute(int ch)
+{
+	assert(cury >= 0 && cury < lines.num);
+	if (curx >= strlen(lines.v[cury])) {
+		beep();
+		return -1;
+	}
+
+	int och = lines.v[cury][curx];
+	if (!isalpha((unsigned char)och)) {
+		beep();
+		return -1;
+	}
+
+	int loch = tolower((unsigned char)och);
+	int uoch = 

CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 15:02:16 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: externs1.h init.c tree.c

Log Message:
lint: extract check_non_constant_initializer from init_using_expr

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/tree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 15:02:16 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: externs1.h init.c tree.c

Log Message:
lint: extract check_non_constant_initializer from init_using_expr

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/tree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.70 src/usr.bin/xlint/lint1/externs1.h:1.71
--- src/usr.bin/xlint/lint1/externs1.h:1.70	Sun Feb 21 07:59:17 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Sun Feb 21 15:02:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.70 2021/02/21 07:59:17 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.71 2021/02/21 15:02:16 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -219,7 +219,7 @@ extern	val_t	*constant(tnode_t *, bool);
 extern	void	expr(tnode_t *, bool, bool, bool, bool);
 extern	void	check_expr_misc(const tnode_t *, bool, bool, bool,
 		bool, bool, bool);
-extern	bool	constant_addr(tnode_t *, sym_t **, ptrdiff_t *);
+extern	bool	constant_addr(const tnode_t *, sym_t **, ptrdiff_t *);
 extern	strg_t	*cat_strings(strg_t *, strg_t *);
 extern  int64_t tsize(type_t *);
 #ifdef DEBUG

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.86 src/usr.bin/xlint/lint1/init.c:1.87
--- src/usr.bin/xlint/lint1/init.c:1.86	Sun Feb 21 14:57:25 2021
+++ src/usr.bin/xlint/lint1/init.c	Sun Feb 21 15:02:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.86 2021/02/21 14:57:25 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.87 2021/02/21 15:02:16 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.86 2021/02/21 14:57:25 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.87 2021/02/21 15:02:16 rillig Exp $");
 #endif
 
 #include 
@@ -742,6 +742,26 @@ check_bit_field_init(const tnode_t *ln, 
 	}
 }
 
+static void
+check_non_constant_initializer(const tnode_t *tn, scl_t sclass)
+{
+	if (tn == NULL || tn->tn_op == CON)
+		return;
+
+	sym_t *sym;
+	ptrdiff_t offs;
+	if (constant_addr(tn, , ))
+		return;
+
+	if (sclass == AUTO || sclass == REG) {
+		/* non-constant initializer */
+		c99ism(177);
+	} else {
+		/* non-constant initializer */
+		error(177);
+	}
+}
+
 void
 init_using_expr(tnode_t *tn)
 {
@@ -840,19 +860,7 @@ init_using_expr(tnode_t *tn)
 	if (lt != rt || (initstk->i_type->t_bitfield && tn->tn_op == CON))
 		tn = convert(INIT, 0, initstk->i_type, tn);
 
-	if (tn != NULL && tn->tn_op != CON) {
-		sym_t *sym;
-		ptrdiff_t offs;
-		if (!constant_addr(tn, , )) {
-			if (sclass == AUTO || sclass == REG) {
-/* non-constant initializer */
-c99ism(177);
-			} else {
-/* non-constant initializer */
-error(177);
-			}
-		}
-	}
+	check_non_constant_initializer(tn, sclass);
 
 	debug_initstack();
 	debug_leave();

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.215 src/usr.bin/xlint/lint1/tree.c:1.216
--- src/usr.bin/xlint/lint1/tree.c:1.215	Sun Feb 21 11:23:33 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sun Feb 21 15:02:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.215 2021/02/21 11:23:33 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.216 2021/02/21 15:02:16 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.215 2021/02/21 11:23:33 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.216 2021/02/21 15:02:16 rillig Exp $");
 #endif
 
 #include 
@@ -4185,7 +4185,7 @@ check_integer_comparison(op_t op, tnode_
  * representation (including width).
  */
 bool
-constant_addr(tnode_t *tn, sym_t **symp, ptrdiff_t *offsp)
+constant_addr(const tnode_t *tn, sym_t **symp, ptrdiff_t *offsp)
 {
 	sym_t	*sym;
 	ptrdiff_t offs1, offs2;



CVS commit: src/sys/arch

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 15:00:05 UTC 2021

Modified Files:
src/sys/arch/aarch64/include: cpu.h
src/sys/arch/arm/cortex: gicv3.c
src/sys/arch/arm/include: cpu.h

Log Message:
Keep current hardware priority value in struct cpu_info and use it instead
of reading icc_pmr_el1 in gicv3_set_priority.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/aarch64/include/cpu.h
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/arm/cortex/gicv3.c
cvs rdiff -u -r1.115 -r1.116 src/sys/arch/arm/include/cpu.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/aarch64/include/cpu.h
diff -u src/sys/arch/aarch64/include/cpu.h:1.31 src/sys/arch/aarch64/include/cpu.h:1.32
--- src/sys/arch/aarch64/include/cpu.h:1.31	Sat Feb 20 14:51:07 2021
+++ src/sys/arch/aarch64/include/cpu.h	Sun Feb 21 15:00:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.31 2021/02/20 14:51:07 jmcneill Exp $ */
+/* $NetBSD: cpu.h,v 1.32 2021/02/21 15:00:04 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014, 2020 The NetBSD Foundation, Inc.
@@ -100,7 +100,8 @@ struct cpu_info {
 	int ci_mtx_oldspl;
 	int ci_mtx_count;
 
-	int ci_cpl;
+	int ci_cpl;		/* current processor level (spl) */
+	int ci_hwpl;		/* current hardware priority */
 	volatile u_int ci_softints;
 	volatile u_int ci_intr_depth;
 	volatile uint32_t ci_blocked_pics;

Index: src/sys/arch/arm/cortex/gicv3.c
diff -u src/sys/arch/arm/cortex/gicv3.c:1.41 src/sys/arch/arm/cortex/gicv3.c:1.42
--- src/sys/arch/arm/cortex/gicv3.c:1.41	Tue Feb  9 17:44:01 2021
+++ src/sys/arch/arm/cortex/gicv3.c	Sun Feb 21 15:00:05 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: gicv3.c,v 1.41 2021/02/09 17:44:01 ryo Exp $ */
+/* $NetBSD: gicv3.c,v 1.42 2021/02/21 15:00:05 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -31,7 +31,7 @@
 #define	_INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.41 2021/02/09 17:44:01 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.42 2021/02/21 15:00:05 jmcneill Exp $");
 
 #include 
 #include 
@@ -222,11 +222,12 @@ static void
 gicv3_set_priority(struct pic_softc *pic, int ipl)
 {
 	struct gicv3_softc * const sc = PICTOSOFTC(pic);
-	const uint8_t curpmr = icc_pmr_read();
+	struct cpu_info * const ci = curcpu();
 	const uint8_t newpmr = IPL_TO_PMR(sc, ipl);
 
-	if (newpmr > curpmr) {
+	if (newpmr > ci->ci_hwpl) {
 		/* Lowering priority mask */
+		ci->ci_hwpl = newpmr;
 		icc_pmr_write(newpmr);
 	}
 }
@@ -414,7 +415,8 @@ gicv3_cpu_init(struct pic_softc *pic, st
 		;
 
 	/* Set initial priority mask */
-	icc_pmr_write(IPL_TO_PMR(sc, IPL_HIGH));
+	ci->ci_hwpl = IPL_TO_PMR(sc, IPL_HIGH);
+	icc_pmr_write(ci->ci_hwpl);
 
 	/* Set the binary point field to the minimum value */
 	icc_bpr1_write(0);
@@ -733,7 +735,8 @@ gicv3_irq_handler(void *frame)
 
 	ci->ci_data.cpu_nintr++;
 
-	if (icc_pmr_read() != pmr) {
+	if (ci->ci_hwpl != pmr) {
+		ci->ci_hwpl = pmr;
 		icc_pmr_write(pmr);
 	}
 
@@ -758,7 +761,7 @@ gicv3_irq_handler(void *frame)
 			pic_do_pending_ints(I32_bit, ipl, frame);
 		} else if (ci->ci_cpl != ipl) {
 			icc_pmr_write(IPL_TO_PMR(sc, ipl));
-			ci->ci_cpl = ipl;
+			ci->ci_hwpl = ci->ci_cpl = ipl;
 		}
 
 		if (early_eoi) {

Index: src/sys/arch/arm/include/cpu.h
diff -u src/sys/arch/arm/include/cpu.h:1.115 src/sys/arch/arm/include/cpu.h:1.116
--- src/sys/arch/arm/include/cpu.h:1.115	Sat Feb 20 14:51:06 2021
+++ src/sys/arch/arm/include/cpu.h	Sun Feb 21 15:00:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.115 2021/02/20 14:51:06 jmcneill Exp $	*/
+/*	$NetBSD: cpu.h,v 1.116 2021/02/21 15:00:04 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 1994-1996 Mark Brinicombe.
@@ -185,6 +185,7 @@ struct cpu_info {
 			ci_softc;	/* platform softc */
 
 	int		ci_cpl;		/* current processor level (spl) */
+	int		ci_hwpl;	/* current hardware priority */
 	int		ci_kfpu_spl;
 
 	volatile u_int	ci_intr_depth;	/* */



CVS commit: src/sys/arch

2021-02-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb 21 15:00:05 UTC 2021

Modified Files:
src/sys/arch/aarch64/include: cpu.h
src/sys/arch/arm/cortex: gicv3.c
src/sys/arch/arm/include: cpu.h

Log Message:
Keep current hardware priority value in struct cpu_info and use it instead
of reading icc_pmr_el1 in gicv3_set_priority.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/aarch64/include/cpu.h
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/arm/cortex/gicv3.c
cvs rdiff -u -r1.115 -r1.116 src/sys/arch/arm/include/cpu.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 14:57:25 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: extract check_bit_field_init from init_using_expr

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.85 src/usr.bin/xlint/lint1/init.c:1.86
--- src/usr.bin/xlint/lint1/init.c:1.85	Sun Feb 21 14:19:27 2021
+++ src/usr.bin/xlint/lint1/init.c	Sun Feb 21 14:57:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.85 2021/02/21 14:19:27 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.86 2021/02/21 14:57:25 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.85 2021/02/21 14:19:27 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.86 2021/02/21 14:57:25 rillig Exp $");
 #endif
 
 #include 
@@ -729,6 +729,19 @@ init_rbrace(void)
 	debug_leave();
 }
 
+/* In traditional C, bit-fields can be initialized only by integer constants. */
+static void
+check_bit_field_init(const tnode_t *ln, tspec_t lt, tspec_t rt)
+{
+	if (tflag &&
+	is_integer(lt) &&
+	ln->tn_type->t_bitfield &&
+	!is_integer(rt)) {
+		/* bit-field initialisation is illegal in traditional C */
+		warning(186);
+	}
+}
+
 void
 init_using_expr(tnode_t *tn)
 {
@@ -822,15 +835,7 @@ init_using_expr(tnode_t *tn)
 	expr(tn, true, false, true, false);
 	trestor(tmem);
 
-	if (is_integer(lt) && ln->tn_type->t_bitfield && !is_integer(rt)) {
-		/*
-		 * Bit-fields can be initialized in trad. C only by integer
-		 * constants.
-		 */
-		if (tflag)
-			/* bit-field initialisation is illegal in trad. C */
-			warning(186);
-	}
+	check_bit_field_init(ln, lt, rt);
 
 	if (lt != rt || (initstk->i_type->t_bitfield && tn->tn_op == CON))
 		tn = convert(INIT, 0, initstk->i_type, tn);



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 14:57:25 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: extract check_bit_field_init from init_using_expr

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 14:49:23 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_186.c msg_186.exp

Log Message:
lint: add test for bit-field initialisation in traditional C


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_186.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_186.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 14:49:23 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_186.c msg_186.exp

Log Message:
lint: add test for bit-field initialisation in traditional C


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_186.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_186.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/msg_186.c
diff -u src/tests/usr.bin/xlint/lint1/msg_186.c:1.2 src/tests/usr.bin/xlint/lint1/msg_186.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_186.c:1.2	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_186.c	Sun Feb 21 14:49:23 2021
@@ -1,7 +1,19 @@
-/*	$NetBSD: msg_186.c,v 1.2 2021/02/21 09:07:58 rillig Exp $	*/
+/*	$NetBSD: msg_186.c,v 1.3 2021/02/21 14:49:23 rillig Exp $	*/
 # 3 "msg_186.c"
 
-// Test for message: bit-field initialisation is illegal in traditional C [186]
+/* Test for message: bit-field initialisation is illegal in traditional C [186] */
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* lint1-flags: -tw */
+
+struct bit_field {
+	unsigned one: 1;
+	unsigned three: 3;
+	unsigned two: 2;
+};
+
+struct bit_field bit_field = {
+	1,
+	3.0,			/* expect: 186 */
+	2
+};
+/* XXX: The message is misleading.  Initialisation using integers is ok. */

Index: src/tests/usr.bin/xlint/lint1/msg_186.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_186.exp:1.1 src/tests/usr.bin/xlint/lint1/msg_186.exp:1.2
--- src/tests/usr.bin/xlint/lint1/msg_186.exp:1.1	Sat Jan  2 10:22:43 2021
+++ src/tests/usr.bin/xlint/lint1/msg_186.exp	Sun Feb 21 14:49:23 2021
@@ -1 +1,8 @@
-msg_186.c(6): syntax error ':' [249]
+(1): warning: 'long double' is illegal in traditional C [266]
+(1): warning: function prototypes are illegal in traditional C [270]
+(2): warning: 'long double' is illegal in traditional C [266]
+(2): warning: function prototypes are illegal in traditional C [270]
+(3): warning: 'long double' is illegal in traditional C [266]
+(3): warning: 'long double' is illegal in traditional C [266]
+(3): warning: function prototypes are illegal in traditional C [270]
+msg_186.c(16): warning: bit-field initialisation is illegal in traditional C [186]



CVS commit: src

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 14:19:27 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c
src/usr.bin/xlint/common: tyname.c
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: add debug logging for initializing an array of unknown size

It is possible that the type name 'array[unknown_size]' may spill into
the user-visible diagnostics.  The current test suite does not cover
such a case.  Anyway, saying 'array[unknown_size]' is still better than
saying 'array[0]', which would be misleading.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.84 -r1.85 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 14:19:27 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c
src/usr.bin/xlint/common: tyname.c
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: add debug logging for initializing an array of unknown size

It is possible that the type name 'array[unknown_size]' may spill into
the user-visible diagnostics.  The current test suite does not cover
such a case.  Anyway, saying 'array[unknown_size]' is still better than
saying 'array[0]', which would be misleading.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.84 -r1.85 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/d_c99_init.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.5 src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.6
--- src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.5	Sun Feb 21 13:10:57 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c	Sun Feb 21 14:19:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_init.c,v 1.5 2021/02/21 13:10:57 rillig Exp $	*/
+/*	$NetBSD: d_c99_init.c,v 1.6 2021/02/21 14:19:27 rillig Exp $	*/
 # 3 "d_c99_init.c"
 
 /*
@@ -50,3 +50,6 @@ initialization_with_redundant_braces(any
 	// FIXME: message 185 needs to be reworded to "cannot initialize '%s' from '%s'".
 	use();
 }
+
+// See initstack_push, 'extending array of unknown size'.
+const int primes[] = { 2, 3, 5, 7, 9 };

Index: src/usr.bin/xlint/common/tyname.c
diff -u src/usr.bin/xlint/common/tyname.c:1.30 src/usr.bin/xlint/common/tyname.c:1.31
--- src/usr.bin/xlint/common/tyname.c:1.30	Sun Feb 21 10:28:32 2021
+++ src/usr.bin/xlint/common/tyname.c	Sun Feb 21 14:19:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tyname.c,v 1.30 2021/02/21 10:28:32 rillig Exp $	*/
+/*	$NetBSD: tyname.c,v 1.31 2021/02/21 14:19:27 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tyname.c,v 1.30 2021/02/21 10:28:32 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.31 2021/02/21 14:19:27 rillig Exp $");
 #endif
 
 #include 
@@ -366,7 +366,14 @@ type_name(const type_t *tp)
 		buf_add(, " of ");
 		buf_add(, type_name(tp->t_subt));
 		buf_add(, "[");
+#ifdef t_str /* lint1 */
+		if (tp->t_incomplete_array)
+			buf_add(, "unknown_size");
+		else
+			buf_add_int(, tp->t_dim);
+#else
 		buf_add_int(, tp->t_dim);
+#endif
 		buf_add(, "]");
 		break;
 	case FUNC:

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.84 src/usr.bin/xlint/lint1/init.c:1.85
--- src/usr.bin/xlint/lint1/init.c:1.84	Sun Feb 21 14:02:36 2021
+++ src/usr.bin/xlint/lint1/init.c	Sun Feb 21 14:19:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.84 2021/02/21 14:02:36 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.85 2021/02/21 14:19:27 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.84 2021/02/21 14:02:36 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.85 2021/02/21 14:19:27 rillig Exp $");
 #endif
 
 #include 
@@ -466,16 +466,18 @@ initstack_push(void)
 
 	/* Extend an incomplete array type by one element */
 	if (istk->i_remaining == 0) {
-		debug_step("(extend) %s", type_name(istk->i_type));
 		/*
 		 * Inside of other aggregate types must not be an incomplete
 		 * type.
 		 */
 		lint_assert(istk->i_enclosing->i_enclosing == NULL);
-		istk->i_remaining = 1;
 		lint_assert(istk->i_type->t_tspec == ARRAY);
+		debug_step("extending array of unknown size '%s'",
+		type_name(istk->i_type));
+		istk->i_remaining = 1;
 		istk->i_type->t_dim++;
 		setcomplete(istk->i_type, true);
+		debug_step("extended type is '%s'", type_name(istk->i_type));
 	}
 
 	lint_assert(istk->i_remaining > 0);



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 14:02:36 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: rename and condense initstack_check_too_many

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.83 src/usr.bin/xlint/lint1/init.c:1.84
--- src/usr.bin/xlint/lint1/init.c:1.83	Sun Feb 21 13:52:21 2021
+++ src/usr.bin/xlint/lint1/init.c	Sun Feb 21 14:02:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.83 2021/02/21 13:52:21 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.84 2021/02/21 14:02:36 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.83 2021/02/21 13:52:21 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.84 2021/02/21 14:02:36 rillig Exp $");
 #endif
 
 #include 
@@ -601,35 +601,27 @@ again:
 }
 
 static void
-initstack_check_too_many(void)
+check_too_many_initializers(void)
 {
-	initstack_element *istk;
 
-	istk = initstk;
+	const initstack_element *istk = initstk;
+	if (istk->i_remaining > 0)
+		return;
+	if (istk->i_array_of_unknown_size || istk->i_seen_named_member)
+		return;
 
-	/*
-	 * If a closing brace is expected we have at least one initializer
-	 * too much.
-	 */
-	if (istk->i_remaining == 0 && !istk->i_array_of_unknown_size &&
-	!istk->i_seen_named_member) {
-		switch (istk->i_type->t_tspec) {
-		case ARRAY:
-			/* too many array initializers, expected %d */
-			error(173, istk->i_type->t_dim);
-			break;
-		case STRUCT:
-		case UNION:
-			/* too many struct/union initializers */
-			error(172);
-			break;
-		default:
-			/* too many initializers */
-			error(174);
-			break;
-		}
-		initerr = true;
+	tspec_t t = istk->i_type->t_tspec;
+	if (t == ARRAY) {
+		/* too many array initializers, expected %d */
+		error(173, istk->i_type->t_dim);
+	} else if (t == STRUCT || t == UNION) {
+		/* too many struct/union initializers */
+		error(172);
+	} else {
+		/* too many initializers */
+		error(174);
 	}
+	initerr = true;
 }
 
 static void
@@ -645,7 +637,7 @@ initstack_next_brace(void)
 		initerr = true;
 	}
 	if (!initerr)
-		initstack_check_too_many();
+		check_too_many_initializers();
 	if (!initerr)
 		initstack_push();
 	if (!initerr) {
@@ -670,6 +662,9 @@ initstack_next_nobrace(void)
 		error(181);
 	}
 
+	if (!initerr)
+		check_too_many_initializers();
+
 	/*
 	 * Make sure an entry with a scalar type is at the top of the stack.
 	 *
@@ -678,8 +673,6 @@ initstack_next_nobrace(void)
 	 *  perfectly fine to initialize a struct with a struct expression,
 	 *  see d_struct_init_nested.c for a demonstration.
 	 */
-	if (!initerr)
-		initstack_check_too_many();
 	while (!initerr) {
 		if ((initstk->i_type != NULL &&
 		 is_scalar(initstk->i_type->t_tspec)))



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 14:02:36 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: rename and condense initstack_check_too_many

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 13:52:21 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: remove redundant debug logging

In initstack_pop_nobrace, if anything happens to the initstack, it will
be logged by initstack_pop_item.

In init_using_expr, the address of the node is irrelevant, the node's
contents has already been logged above.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.82 src/usr.bin/xlint/lint1/init.c:1.83
--- src/usr.bin/xlint/lint1/init.c:1.82	Sun Feb 21 13:13:14 2021
+++ src/usr.bin/xlint/lint1/init.c	Sun Feb 21 13:52:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.82 2021/02/21 13:13:14 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.83 2021/02/21 13:52:21 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.82 2021/02/21 13:13:14 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.83 2021/02/21 13:52:21 rillig Exp $");
 #endif
 
 #include 
@@ -446,11 +446,9 @@ initstack_pop_nobrace(void)
 {
 
 	debug_enter();
-	debug_initstack();
 	while (!initstk->i_brace && initstk->i_remaining == 0 &&
 	   !initstk->i_array_of_unknown_size)
 		initstack_pop_item();
-	debug_initstack();
 	debug_leave();
 }
 
@@ -798,7 +796,8 @@ init_using_expr(tnode_t *tn)
 	}
 
 	initstk->i_remaining--;
-	debug_step("remaining=%d tn=%p", initstk->i_remaining, tn);
+	debug_step("%d elements remaining", initstk->i_remaining);
+
 	/* Create a temporary node for the left side. */
 	ln = tgetblk(sizeof (tnode_t));
 	ln->tn_op = NAME;



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 13:52:21 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: remove redundant debug logging

In initstack_pop_nobrace, if anything happens to the initstack, it will
be logged by initstack_pop_item.

In init_using_expr, the address of the node is irrelevant, the node's
contents has already been logged above.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 13:35:37 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram: fix Home key for cursor navigation

Reported by liweitianux via GitHub.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/games/cgram

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 13:35:37 UTC 2021

Modified Files:
src/games/cgram: cgram.c

Log Message:
cgram: fix Home key for cursor navigation

Reported by liweitianux via GitHub.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/games/cgram/cgram.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/cgram/cgram.c
diff -u src/games/cgram/cgram.c:1.2 src/games/cgram/cgram.c:1.3
--- src/games/cgram/cgram.c:1.2	Thu Jul  2 19:11:01 2020
+++ src/games/cgram/cgram.c	Sun Feb 21 13:35:37 2021
@@ -241,7 +241,7 @@ static void loop(void) {
   int ch = getch();
   switch (ch) {
case 1: /* ^A */
-   case KEY_BEG:
+   case KEY_HOME:
 	curx=0;
 	break;
case 2: /* ^B */



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 13:27:22 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: mem1.c

Log Message:
lint: clean up comments in mem1.c

The comment for tgetblk had been misplaced.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/xlint/lint1/mem1.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/mem1.c
diff -u src/usr.bin/xlint/lint1/mem1.c:1.25 src/usr.bin/xlint/lint1/mem1.c:1.26
--- src/usr.bin/xlint/lint1/mem1.c:1.25	Sat Jan 23 22:20:17 2021
+++ src/usr.bin/xlint/lint1/mem1.c	Sun Feb 21 13:27:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: mem1.c,v 1.25 2021/01/23 22:20:17 rillig Exp $	*/
+/*	$NetBSD: mem1.c,v 1.26 2021/02/21 13:27:22 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: mem1.c,v 1.25 2021/01/23 22:20:17 rillig Exp $");
+__RCSID("$NetBSD: mem1.c,v 1.26 2021/02/21 13:27:22 rillig Exp $");
 #endif
 
 #include 
@@ -62,9 +62,7 @@ static	fn_t	*fnames;
 
 static	fn_t	*srchfn(const char *, size_t);
 
-/*
- * Look for a Filename of length l.
- */
+/* Find the given filename, or return NULL. */
 static fn_t *
 srchfn(const char *s, size_t len)
 {
@@ -77,9 +75,7 @@ srchfn(const char *s, size_t len)
 	return fn;
 }
 
-/*
- * Return a shared string for filename s.
- */
+/* Return a copy of the filename s with unlimited lifetime. */
 const char *
 fnalloc(const char *s)
 {
@@ -140,7 +136,7 @@ fnnalloc(const char *s, size_t len)
 
 	if ((fn = srchfn(s, len)) == NULL) {
 		fn = xmalloc(sizeof (fn_t));
-		/* Do not use strdup() because string is not NUL-terminated.*/
+		/* Do not use strdup() because s is not NUL-terminated.*/
 		fn->fn_name = xmalloc(len + 1);
 		(void)memcpy(fn->fn_name, s, len);
 		fn->fn_name[len] = '\0';
@@ -157,9 +153,7 @@ fnnalloc(const char *s, size_t len)
 	return fn->fn_name;
 }
 
-/*
- * Get id of a filename.
- */
+/* Get the ID of a filename. */
 int
 getfnid(const char *s)
 {
@@ -295,9 +289,7 @@ initmem(void)
 }
 
 
-/*
- * Allocate memory associated with level l.
- */
+/* Allocate memory associated with level l. */
 void *
 getlblk(size_t l, size_t s)
 {
@@ -317,9 +309,7 @@ getblk(size_t s)
 	return getlblk(mblklev, s);
 }
 
-/*
- * Free all memory associated with level l.
- */
+/* Free all memory associated with level l. */
 void
 freelblk(int l)
 {
@@ -334,12 +324,12 @@ freeblk(void)
 	freelblk(mblklev);
 }
 
+static	mbl_t	*tmblk;
+
 /*
- * tgetblk() returns memory which is associated with the current
+ * Return zero-initialized memory that is freed at the end of the current
  * expression.
  */
-static	mbl_t	*tmblk;
-
 void *
 tgetblk(size_t s)
 {
@@ -347,9 +337,7 @@ tgetblk(size_t s)
 	return xgetblk(, s);
 }
 
-/*
- * Return a freshly allocated tree node.
- */
+/* Return a freshly allocated tree node. */
 tnode_t *
 getnode(void)
 {
@@ -358,9 +346,7 @@ getnode(void)
 	return tn;
 }
 
-/*
- * Free all memory which is allocated by the current expression.
- */
+/* Free all memory which is allocated by the current expression. */
 void
 tfreeblk(void)
 {



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 13:27:22 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: mem1.c

Log Message:
lint: clean up comments in mem1.c

The comment for tgetblk had been misplaced.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/xlint/lint1/mem1.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 13:13:15 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: document i_brace, add comments, rename initstack_string

No functional change outside debug mode.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 13:13:15 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: document i_brace, add comments, rename initstack_string

No functional change outside debug mode.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.81 src/usr.bin/xlint/lint1/init.c:1.82
--- src/usr.bin/xlint/lint1/init.c:1.81	Sun Feb 21 11:23:33 2021
+++ src/usr.bin/xlint/lint1/init.c	Sun Feb 21 13:13:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.81 2021/02/21 11:23:33 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.82 2021/02/21 13:13:14 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.81 2021/02/21 11:23:33 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.82 2021/02/21 13:13:14 rillig Exp $");
 #endif
 
 #include 
@@ -68,8 +68,18 @@ typedef	struct initstack_element {
 	type_t	*i_type;		/* type of initialisation */
 	type_t	*i_subt;		/* type of next level */
 
-	/* need '}' for pop; XXX: explain this */
+	/*
+	 * This level of the initializer requires a '}' to be completed.
+	 *
+	 * Multidimensional arrays do not need a closing brace to complete
+	 * an inner array; for example, { 1, 2, 3, 4 } is a valid initializer
+	 * for int arr[2][2].
+	 *
+	 * TODO: Do structs containing structs need a closing brace?
+	 * TODO: Do arrays of structs need a closing brace after each struct?
+	 */
 	bool i_brace: 1;
+
 	bool i_array_of_unknown_size: 1;
 	bool i_seen_named_member: 1;
 
@@ -133,7 +143,7 @@ initstack_element *initstk;
 namlist_t	*namedmem = NULL;
 
 
-static	bool	initstack_string(tnode_t *);
+static	bool	init_array_using_string(tnode_t *);
 
 #ifndef DEBUG
 #define debug_printf(fmt, ...)	do { } while (false)
@@ -759,24 +769,22 @@ init_using_expr(tnode_t *tn)
 	 */
 	if ((sclass == AUTO || sclass == REG) &&
 	initsym->s_type->t_tspec != ARRAY && initstk->i_enclosing == NULL) {
+		debug_step("handing over to ASSIGN");
 		ln = new_name_node(initsym, 0);
 		ln->tn_type = tduptyp(ln->tn_type);
 		ln->tn_type->t_const = false;
 		tn = build(ASSIGN, ln, tn);
 		expr(tn, false, false, false, false);
-		debug_initstack();
+		/* XXX: why not clean up the initstack here already? */
 		debug_leave();
 		return;
 	}
 
-	/*
-	 * Remove all entries which cannot be used for further initializers
-	 * and do not require a closing brace.
-	 */
 	initstack_pop_nobrace();
 
-	/* Initialisations by strings are done in initstack_string(). */
-	if (initstack_string(tn)) {
+	if (init_array_using_string(tn)) {
+		debug_step("after initializing the string:");
+		/* XXX: why not clean up the initstack here already? */
 		debug_initstack();
 		debug_leave();
 		return;
@@ -852,8 +860,9 @@ init_using_expr(tnode_t *tn)
 }
 
 
+/* Initialize a character array or wchar_t array with a string literal. */
 static bool
-initstack_string(tnode_t *tn)
+init_array_using_string(tnode_t *tn)
 {
 	tspec_t	t;
 	initstack_element *istk;
@@ -882,6 +891,7 @@ initstack_string(tnode_t *tn)
 			debug_leave();
 			return false;
 		}
+		/* XXX: duplicate code, see below */
 		/* Put the array at top of stack */
 		initstack_push();
 		istk = initstk;
@@ -894,6 +904,7 @@ initstack_string(tnode_t *tn)
 			debug_leave();
 			return false;
 		}
+		/* XXX: duplicate code, see above */
 		/*
 		 * If the array is already partly initialized, we are
 		 * wrong here.



CVS commit: src/tests/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 13:10:57 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c d_c99_init.exp

Log Message:
lint: add test for initializing a character array using a string

The previous attempt took another code path than expected.  The
initialization of static_duration actually calls initstack_string.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/d_c99_init.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 13:10:57 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c d_c99_init.exp

Log Message:
lint: add test for initializing a character array using a string

The previous attempt took another code path than expected.  The
initialization of static_duration actually calls initstack_string.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/d_c99_init.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/d_c99_init.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.4 src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.5
--- src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.4	Sun Feb 21 12:49:05 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c	Sun Feb 21 13:10:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_init.c,v 1.4 2021/02/21 12:49:05 rillig Exp $	*/
+/*	$NetBSD: d_c99_init.c,v 1.5 2021/02/21 13:10:57 rillig Exp $	*/
 # 3 "d_c99_init.c"
 
 /*
@@ -31,9 +31,13 @@ struct_initialization_via_assignment(any
 	use();
 }
 
+
 // See init_using_expr, initstack_string.
+char static_duration[] = "static duration";
+
+// See init_using_expr.
 void
-initialization_by_string(void)
+initialization_by_braced_string(void)
 {
 	any local = { "hello" };
 	use();

Index: src/tests/usr.bin/xlint/lint1/d_c99_init.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.3 src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.4
--- src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.3	Sun Feb 21 12:49:05 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.exp	Sun Feb 21 13:10:57 2021
@@ -1,3 +1,3 @@
 d_c99_init.c(22): invalid initializer type int [176]
 d_c99_init.c(23): too many initializers [174]
-d_c99_init.c(45): initialisation type mismatch (pointer to const void) and (struct any) [185]
+d_c99_init.c(49): initialisation type mismatch (pointer to const void) and (struct any) [185]



CVS commit: src/tests/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 12:49:05 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c d_c99_init.exp

Log Message:
lint: add more tests for C99 initialization


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/d_c99_init.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 12:49:05 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c d_c99_init.exp

Log Message:
lint: add more tests for C99 initialization


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/d_c99_init.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/d_c99_init.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.3 src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.4
--- src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.3	Sun Feb 21 09:19:53 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c	Sun Feb 21 12:49:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_init.c,v 1.3 2021/02/21 09:19:53 rillig Exp $	*/
+/*	$NetBSD: d_c99_init.c,v 1.4 2021/02/21 12:49:05 rillig Exp $	*/
 # 3 "d_c99_init.c"
 
 /*
@@ -7,7 +7,13 @@
  * See C99 6.7.8 "Initialization".
 */
 
-/* lint1-extra-flags: -p */
+
+void use(const void *);
+
+typedef struct any {
+	const void *value;
+} any;
+
 
 // C99 6.7.8p11 says "optionally enclosed in braces".  The intended
 // interpretation is "optionally enclosed in a single pair of braces".
@@ -15,3 +21,28 @@ int scalar_without_braces = 3;
 int scalar_with_optional_braces = { 3 };
 int scalar_with_too_many_braces = {{ 3 }};		/* expect: 176 */
 int scalar_with_too_many_initializers = { 3, 5 };	/* expect: 174 */
+
+
+// See init_using_expr, 'handing over to ASSIGN'.
+void
+struct_initialization_via_assignment(any arg)
+{
+	any local = arg;
+	use();
+}
+
+// See init_using_expr, initstack_string.
+void
+initialization_by_string(void)
+{
+	any local = { "hello" };
+	use();
+}
+
+void
+initialization_with_redundant_braces(any arg)
+{
+	any local = { arg };	/* expect: 185 */
+	// FIXME: message 185 needs to be reworded to "cannot initialize '%s' from '%s'".
+	use();
+}

Index: src/tests/usr.bin/xlint/lint1/d_c99_init.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.2 src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.3
--- src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.2	Sun Feb 21 09:19:53 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.exp	Sun Feb 21 12:49:05 2021
@@ -1,2 +1,3 @@
-d_c99_init.c(16): invalid initializer type int [176]
-d_c99_init.c(17): too many initializers [174]
+d_c99_init.c(22): invalid initializer type int [176]
+d_c99_init.c(23): too many initializers [174]
+d_c99_init.c(45): initialisation type mismatch (pointer to const void) and (struct any) [185]



CVS commit: src/sys/dev/usb

2021-02-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Feb 21 12:36:39 UTC 2021

Modified Files:
src/sys/dev/usb: usb_quirks.c

Log Message:
Add a bunch of USB loader devices for Freescale SoC that should not
attach as HID devices.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/dev/usb/usb_quirks.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/usb_quirks.c
diff -u src/sys/dev/usb/usb_quirks.c:1.96 src/sys/dev/usb/usb_quirks.c:1.97
--- src/sys/dev/usb/usb_quirks.c:1.96	Sat Dec 26 22:15:37 2020
+++ src/sys/dev/usb/usb_quirks.c	Sun Feb 21 12:36:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_quirks.c,v 1.96 2020/12/26 22:15:37 jym Exp $	*/
+/*	$NetBSD: usb_quirks.c,v 1.97 2021/02/21 12:36:38 martin Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_quirks.c,v 1.30 2003/01/02 04:15:55 imp Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_quirks.c,v 1.96 2020/12/26 22:15:37 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_quirks.c,v 1.97 2021/02/21 12:36:38 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -307,6 +307,55 @@ Static const struct usbd_quirk_entry {
  { USB_VENDOR_APPLE,		USB_PRODUCT_APPLE_IPHONE_3GS,		ANY,
 	{ UQ_HID_IGNORE | UQ_BAD_AUDIO, NULL }},
 
+ /*
+  * Various devices using serial boot loader protocol, as supported
+  * by pkgsrc/sysutils/imx_usb_loader
+  */
+ { 0x066f,			0x3780,		/* mx23 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x004f,		/* mx28 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0052,		/* mx50 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0054,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0061,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0063,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0071,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x007d,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0080,		/* mx6ull */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x1fc9,			0x0128,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0076,		/* mx7 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x1fc9,			0x0126,		/* mx7ulp */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0041,		/* mx51 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x004e,		/* mx53 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x006a,		/* vybrid */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x066f,			0x37ff,		/* linux_gadget */	ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x1b67,			0x4fff,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x0525,			0xb4a4,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x1fc9,			0x012b,		/* mx8mq */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x1fc9,			0x0134,		/* mx8mm */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x1fc9,			0x013e,		/* mx8mn */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x3016,			0x1001, 	/* mx8mn */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+
  { USB_VENDOR_LG,		USB_PRODUCT_LG_CDMA_MSM,		ANY,
 	{ UQ_ASSUME_CM_OVER_DATA, NULL }},
  { USB_VENDOR_QUALCOMM2,	USB_PRODUCT_QUALCOMM2_CDMA_MSM,		ANY,



CVS commit: src/sys/dev/usb

2021-02-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Feb 21 12:36:39 UTC 2021

Modified Files:
src/sys/dev/usb: usb_quirks.c

Log Message:
Add a bunch of USB loader devices for Freescale SoC that should not
attach as HID devices.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/dev/usb/usb_quirks.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 11:23:33 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c tree.c

Log Message:
lint: always initialize return values of constant_addr

Before, the caller was responsible for initializing the return values
from the function.  This was an unexpected burden.

Ensure that in each branch that returns true, both return values are
properly set.

Strangely, the only caller of that function, init_using_expr, uses
neither of the return values.  It just tests whether the expression is
constant or not.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.214 -r1.215 src/usr.bin/xlint/lint1/tree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.80 src/usr.bin/xlint/lint1/init.c:1.81
--- src/usr.bin/xlint/lint1/init.c:1.80	Sun Feb 21 10:03:35 2021
+++ src/usr.bin/xlint/lint1/init.c	Sun Feb 21 11:23:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.80 2021/02/21 10:03:35 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.81 2021/02/21 11:23:33 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.80 2021/02/21 10:03:35 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.81 2021/02/21 11:23:33 rillig Exp $");
 #endif
 
 #include 
@@ -729,12 +729,10 @@ init_rbrace(void)
 void
 init_using_expr(tnode_t *tn)
 {
-	ptrdiff_t offs;
-	sym_t	*sym;
 	tspec_t	lt, rt;
 	tnode_t	*ln;
 	struct	mbl *tmem;
-	scl_t	sc;
+	scl_t	sclass;
 
 	debug_enter();
 	debug_named_member();
@@ -746,7 +744,7 @@ init_using_expr(tnode_t *tn)
 		return;
 	}
 
-	sc = initsym->s_scl;
+	sclass = initsym->s_scl;
 
 	/*
 	 * Do not test for automatic aggregate initialisation. If the
@@ -759,7 +757,7 @@ init_using_expr(tnode_t *tn)
 	 * Local initialisation of non-array-types with only one expression
 	 * without braces is done by ASSIGN
 	 */
-	if ((sc == AUTO || sc == REG) &&
+	if ((sclass == AUTO || sclass == REG) &&
 	initsym->s_type->t_tspec != ARRAY && initstk->i_enclosing == NULL) {
 		ln = new_name_node(initsym, 0);
 		ln->tn_type = tduptyp(ln->tn_type);
@@ -836,10 +834,10 @@ init_using_expr(tnode_t *tn)
 		tn = convert(INIT, 0, initstk->i_type, tn);
 
 	if (tn != NULL && tn->tn_op != CON) {
-		sym = NULL;
-		offs = 0;
+		sym_t *sym;
+		ptrdiff_t offs;
 		if (!constant_addr(tn, , )) {
-			if (sc == AUTO || sc == REG) {
+			if (sclass == AUTO || sclass == REG) {
 /* non-constant initializer */
 c99ism(177);
 			} else {

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.214 src/usr.bin/xlint/lint1/tree.c:1.215
--- src/usr.bin/xlint/lint1/tree.c:1.214	Sun Feb 21 10:28:33 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sun Feb 21 11:23:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.214 2021/02/21 10:28:33 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.215 2021/02/21 11:23:33 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.214 2021/02/21 10:28:33 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.215 2021/02/21 11:23:33 rillig Exp $");
 #endif
 
 #include 
@@ -4215,19 +4215,22 @@ constant_addr(tnode_t *tn, sym_t **symp,
 		}
 		*symp = sym;
 		*offsp = offs1 + offs2;
-		break;
+		return true;
 	case ADDR:
 		if (tn->tn_left->tn_op == NAME) {
 			*symp = tn->tn_left->tn_sym;
 			*offsp = 0;
-		} else if (tn->tn_left->tn_op == STRING) {
+			return true;
+		} else {
 			/*
 			 * If this would be the front end of a compiler we
-			 * would return a label instead of 0.
+			 * would return a label instead of 0, at least if
+			 * 'tn->tn_left->tn_op == STRING'.
 			 */
+			*symp = NULL;
 			*offsp = 0;
+			return true;
 		}
-		break;
 	case CVT:
 		t = tn->tn_type->t_tspec;
 		ot = tn->tn_left->tn_type->t_tspec;
@@ -4248,13 +4251,10 @@ constant_addr(tnode_t *tn, sym_t **symp,
 		else if (psize(t) != psize(ot))
 			return -1;
 #endif
-		if (!constant_addr(tn->tn_left, symp, offsp))
-			return false;
-		break;
+		return constant_addr(tn->tn_left, symp, offsp);
 	default:
 		return false;
 	}
-	return true;
 }
 
 /*



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 11:23:33 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c tree.c

Log Message:
lint: always initialize return values of constant_addr

Before, the caller was responsible for initializing the return values
from the function.  This was an unexpected burden.

Ensure that in each branch that returns true, both return values are
properly set.

Strangely, the only caller of that function, init_using_expr, uses
neither of the return values.  It just tests whether the expression is
constant or not.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.214 -r1.215 src/usr.bin/xlint/lint1/tree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 10:28:33 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: d_struct_init_nested.exp msg_210.exp
src/usr.bin/xlint/common: tyname.c
src/usr.bin/xlint/lint1: err.c tree.c

Log Message:
lint: add type information to message about enum mismatch


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_210.exp
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.213 -r1.214 src/usr.bin/xlint/lint1/tree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp
diff -u src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp:1.3 src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp:1.4
--- src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp:1.3	Sun Jan 31 14:39:31 2021
+++ src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp	Sun Feb 21 10:28:33 2021
@@ -1,4 +1,4 @@
 d_struct_init_nested.c(35): initialisation type mismatch (enum I1) and (struct Inner1) [185]
 d_struct_init_nested.c(37): too many struct/union initializers [172]
 d_struct_init_nested.c(62): initialisation type mismatch (enum I1) and (struct Inner2) [185]
-d_struct_init_nested.c(64): warning: enum type mismatch in initialisation [210]
+d_struct_init_nested.c(64): warning: enum type mismatch between 'enum I2' and 'enum O3' in initialisation [210]

Index: src/tests/usr.bin/xlint/lint1/msg_210.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_210.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_210.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_210.exp:1.2	Sun Feb 21 10:12:29 2021
+++ src/tests/usr.bin/xlint/lint1/msg_210.exp	Sun Feb 21 10:28:33 2021
@@ -1,2 +1,2 @@
-msg_210.c(23): warning: enum type mismatch in initialisation [210]
-msg_210.c(25): warning: enum type mismatch in initialisation [210]
+msg_210.c(23): warning: enum type mismatch between 'enum A' and 'enum B' in initialisation [210]
+msg_210.c(25): warning: enum type mismatch between 'C' and 'D' in initialisation [210]

Index: src/usr.bin/xlint/common/tyname.c
diff -u src/usr.bin/xlint/common/tyname.c:1.29 src/usr.bin/xlint/common/tyname.c:1.30
--- src/usr.bin/xlint/common/tyname.c:1.29	Fri Feb 19 22:27:49 2021
+++ src/usr.bin/xlint/common/tyname.c	Sun Feb 21 10:28:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tyname.c,v 1.29 2021/02/19 22:27:49 rillig Exp $	*/
+/*	$NetBSD: tyname.c,v 1.30 2021/02/21 10:28:32 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tyname.c,v 1.29 2021/02/19 22:27:49 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.30 2021/02/21 10:28:32 rillig Exp $");
 #endif
 
 #include 
@@ -337,10 +337,17 @@ type_name(const type_t *tp)
 		buf_add(, type_name(tp->t_subt));
 		break;
 	case ENUM:
-		buf_add(, " ");
 #ifdef t_enum
-		buf_add(, tp->t_enum->en_tag->s_name);
+		if (tp->t_enum->en_tag->s_name == unnamed &&
+		tp->t_enum->en_first_typedef != NULL) {
+			buf.len -= strlen(tspec_name(t));
+			buf_add(, tp->t_enum->en_first_typedef->s_name);
+		} else {
+			buf_add(, " ");
+			buf_add(, tp->t_enum->en_tag->s_name);
+		}
 #else
+		buf_add(, " ");
 		buf_add(,
 		tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name);
 #endif

Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.79 src/usr.bin/xlint/lint1/err.c:1.80
--- src/usr.bin/xlint/lint1/err.c:1.79	Fri Feb 19 12:28:56 2021
+++ src/usr.bin/xlint/lint1/err.c	Sun Feb 21 10:28:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: err.c,v 1.79 2021/02/19 12:28:56 rillig Exp $	*/
+/*	$NetBSD: err.c,v 1.80 2021/02/21 10:28:33 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.79 2021/02/19 12:28:56 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.80 2021/02/21 10:28:33 rillig Exp $");
 #endif
 
 #include 
@@ -269,7 +269,7 @@ const	char *msgs[] = {
 	"loop not entered at top",  /* 207 */
 	"break outside loop or switch",  /* 208 */
 	"continue outside loop",  /* 209 */
-	"enum type mismatch in initialisation",			  /* 210 */
+	"enum type mismatch between '%s' and '%s' in initialisation", /* 210 */
 	"return value type mismatch (%s) and (%s)",		  /* 211 */
 	"cannot return incomplete type",			  /* 212 */
 	"void function %s cannot return value",			  /* 213 */

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.213 src/usr.bin/xlint/lint1/tree.c:1.214
--- src/usr.bin/xlint/lint1/tree.c:1.213	Sun Feb 21 07:21:57 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sun Feb 21 10:28:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 

CVS commit: src

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 10:28:33 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: d_struct_init_nested.exp msg_210.exp
src/usr.bin/xlint/common: tyname.c
src/usr.bin/xlint/lint1: err.c tree.c

Log Message:
lint: add type information to message about enum mismatch


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_210.exp
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.213 -r1.214 src/usr.bin/xlint/lint1/tree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 10:12:30 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_210.c msg_210.exp

Log Message:
lint: add test for enum mismatch in initialization

This warning is currently not user-friendly because it omits any type
information, but that information is crucial.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_210.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_210.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/msg_210.c
diff -u src/tests/usr.bin/xlint/lint1/msg_210.c:1.2 src/tests/usr.bin/xlint/lint1/msg_210.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_210.c:1.2	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_210.c	Sun Feb 21 10:12:29 2021
@@ -1,7 +1,25 @@
-/*	$NetBSD: msg_210.c,v 1.2 2021/02/21 09:07:58 rillig Exp $	*/
+/*	$NetBSD: msg_210.c,v 1.3 2021/02/21 10:12:29 rillig Exp $	*/
 # 3 "msg_210.c"
 
 // Test for message: enum type mismatch in initialisation [210]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+enum A {
+	A1
+};
+
+enum B {
+	B1
+};
+
+typedef enum {
+	C1
+} C;
+
+typedef enum {
+	D1
+} D;
+
+enum A a1 = A1;
+enum A a2 = B1;			/* expect: 210 */
+C c1 = C1;
+C c2 = D1;			/* expect: 210 */

Index: src/tests/usr.bin/xlint/lint1/msg_210.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_210.exp:1.1 src/tests/usr.bin/xlint/lint1/msg_210.exp:1.2
--- src/tests/usr.bin/xlint/lint1/msg_210.exp:1.1	Sat Jan  2 10:22:44 2021
+++ src/tests/usr.bin/xlint/lint1/msg_210.exp	Sun Feb 21 10:12:29 2021
@@ -1 +1,2 @@
-msg_210.c(6): syntax error ':' [249]
+msg_210.c(23): warning: enum type mismatch in initialisation [210]
+msg_210.c(25): warning: enum type mismatch in initialisation [210]



CVS commit: src/tests/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 10:12:30 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_210.c msg_210.exp

Log Message:
lint: add test for enum mismatch in initialization

This warning is currently not user-friendly because it omits any type
information, but that information is crucial.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_210.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_210.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 10:03:35 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: clean up debug logging in initstack_pop_item

The debug logging contained much redundant information and was
misleading in a few places.  For example, "pop" did not actually pop an
item, plus there are several things that could be popped, so that didn't
help either.

Sprinkle some comments in places where the code needs to become clearer.

No functional change outside debug mode.  The condition
'istk->i_remaining >= 0' was redundant due to the assertion directly
above it.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 10:03:35 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: clean up debug logging in initstack_pop_item

The debug logging contained much redundant information and was
misleading in a few places.  For example, "pop" did not actually pop an
item, plus there are several things that could be popped, so that didn't
help either.

Sprinkle some comments in places where the code needs to become clearer.

No functional change outside debug mode.  The condition
'istk->i_remaining >= 0' was redundant due to the assertion directly
above it.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.79 src/usr.bin/xlint/lint1/init.c:1.80
--- src/usr.bin/xlint/lint1/init.c:1.79	Sun Feb 21 09:24:32 2021
+++ src/usr.bin/xlint/lint1/init.c	Sun Feb 21 10:03:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.79 2021/02/21 09:24:32 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.80 2021/02/21 10:03:35 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.79 2021/02/21 09:24:32 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.80 2021/02/21 10:03:35 rillig Exp $");
 #endif
 
 #include 
@@ -292,6 +292,7 @@ debug_initstack(void)
 	}
 }
 #else
+#define debug_initstack_element(elem) do { } while (false)
 #define debug_initstack()	do { } while (false)
 #endif
 
@@ -339,55 +340,53 @@ initstack_pop_item(void)
 	debug_enter();
 
 	istk = initstk;
-	debug_step("pop type=%s, brace=%d remaining=%d named=%d",
-	type_name(istk->i_type != NULL ? istk->i_type : istk->i_subt),
-	istk->i_brace, istk->i_remaining, istk->i_seen_named_member);
+	debug_step("popping:");
+	debug_initstack_element(istk);
 
 	initstk = istk->i_enclosing;
 	free(istk);
 	istk = initstk;
 	lint_assert(istk != NULL);
 
-	debug_step("top type=%s, brace=%d remaining=%d named=%d",
-	type_name(istk->i_type != NULL ? istk->i_type : istk->i_subt),
-	istk->i_brace, istk->i_remaining, istk->i_seen_named_member);
-
 	istk->i_remaining--;
 	lint_assert(istk->i_remaining >= 0);
 
-	debug_step("top remaining=%d rhs.name=%s",
-	istk->i_remaining, namedmem != NULL ? namedmem->n_name : "*null*");
-
-	if (istk->i_remaining >= 0 && namedmem != NULL) {
+	debug_step("new top element with updated remaining:");
+	debug_initstack_element(istk);
 
-		debug_step("named remaining=%d type=%s, rhs.name=%s",
-		istk->i_remaining, type_name(istk->i_type),
-		namedmem->n_name);
+	if (namedmem != NULL) {
+		debug_step("initializing named member '%s'", namedmem->n_name);
 
+		/* XXX: undefined behavior if this is reached with an array? */
 		for (m = istk->i_type->t_str->sou_first_member;
 		 m != NULL; m = m->s_next) {
-			debug_step("pop lhs.name=%s rhs.name=%s",
-			m->s_name, namedmem->n_name);
+
 			if (m->s_bitfield && m->s_name == unnamed)
 continue;
+
 			if (strcmp(m->s_name, namedmem->n_name) == 0) {
+debug_step("found matching member");
 istk->i_subt = m->s_type;
+/* XXX: why ++? */
 istk->i_remaining++;
+/* XXX: why is i_seen_named_member not set? */
 pop_member();
 debug_initstack();
 debug_leave();
 return;
 			}
 		}
+
 		/* undefined struct/union member: %s */
 		error(101, namedmem->n_name);
-		debug_step("end rhs.name=%s", namedmem->n_name);
+
 		pop_member();
 		istk->i_seen_named_member = true;
 		debug_initstack();
 		debug_leave();
 		return;
 	}
+
 	/*
 	 * If the removed element was a structure member, we must go
 	 * to the next structure member.
@@ -397,9 +396,11 @@ initstack_pop_item(void)
 		do {
 			m = istk->i_current_object =
 			istk->i_current_object->s_next;
+			/* XXX: can this assertion be made to fail? */
 			lint_assert(m != NULL);
 			debug_step("pop %s", m->s_name);
 		} while (m->s_bitfield && m->s_name == unnamed);
+		/* XXX: duplicate code for skipping unnamed bit-fields */
 		istk->i_subt = m->s_type;
 	}
 	debug_initstack();



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 09:24:32 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: rename istk to initstack_element

The longer name is more expressive and more correct.  The previous name
called each stack element a stack itself, which was unnecessarily
confusing.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.78 src/usr.bin/xlint/lint1/init.c:1.79
--- src/usr.bin/xlint/lint1/init.c:1.78	Sun Feb 21 08:27:41 2021
+++ src/usr.bin/xlint/lint1/init.c	Sun Feb 21 09:24:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.78 2021/02/21 08:27:41 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.79 2021/02/21 09:24:32 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.78 2021/02/21 08:27:41 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.79 2021/02/21 09:24:32 rillig Exp $");
 #endif
 
 #include 
@@ -62,7 +62,7 @@ __RCSID("$NetBSD: init.c,v 1.78 2021/02/
  * See C99 6.7.8, which spans 6 pages full of tricky details and carefully
  * selected examples.
  */
-typedef	struct istk {
+typedef	struct initstack_element {
 
 	/* XXX: Why is i_type often null? */
 	type_t	*i_type;		/* type of initialisation */
@@ -93,8 +93,8 @@ typedef	struct istk {
 	 * The initialization state of the enclosing data structure
 	 * (struct, union, array).
 	 */
-	struct istk *i_enclosing;
-} istk_t;
+	struct initstack_element *i_enclosing;
+} initstack_element;
 
 /*
  * The names for a nested C99 initialization designator, in a circular list.
@@ -127,7 +127,7 @@ bool	initerr;
 sym_t	*initsym;
 
 /* Points to the top element of the initialisation stack. */
-istk_t	*initstk;
+initstack_element *initstk;
 
 /* Points to a c9x named member; */
 namlist_t	*namedmem = NULL;
@@ -252,7 +252,7 @@ debug_named_member(void)
 
 #ifdef DEBUG
 static void
-debug_initstack_element(const istk_t *elem)
+debug_initstack_element(const initstack_element *elem)
 {
 	if (elem->i_type != NULL)
 		debug_step("  i_type   = %s", type_name(elem->i_type));
@@ -284,7 +284,7 @@ debug_initstack(void)
 	}
 
 	size_t i = 0;
-	for (const istk_t *elem = initstk;
+	for (const initstack_element *elem = initstk;
 	 elem != NULL; elem = elem->i_enclosing) {
 		debug_step("initstk[%zu]:", i);
 		debug_initstack_element(elem);
@@ -302,7 +302,7 @@ debug_initstack(void)
 void
 initstack_init(void)
 {
-	istk_t	*istk;
+	initstack_element *istk;
 
 	if (initerr)
 		return;
@@ -322,7 +322,7 @@ initstack_init(void)
 	if (initsym->s_type->t_tspec == ARRAY && is_incomplete(initsym->s_type))
 		initsym->s_type = duptyp(initsym->s_type);
 
-	istk = initstk = xcalloc(1, sizeof (istk_t));
+	istk = initstk = xcalloc(1, sizeof (initstack_element));
 	istk->i_subt = initsym->s_type;
 	istk->i_remaining = 1;
 
@@ -333,7 +333,7 @@ initstack_init(void)
 static void
 initstack_pop_item(void)
 {
-	istk_t	*istk;
+	initstack_element *istk;
 	sym_t	*m;
 
 	debug_enter();
@@ -446,7 +446,7 @@ initstack_pop_nobrace(void)
 static void
 initstack_push(void)
 {
-	istk_t	*istk, *inxt;
+	initstack_element *istk, *inxt;
 	int	cnt;
 	sym_t	*m;
 
@@ -472,7 +472,7 @@ initstack_push(void)
 	lint_assert(istk->i_remaining > 0);
 	lint_assert(istk->i_type == NULL || !is_scalar(istk->i_type->t_tspec));
 
-	initstk = xcalloc(1, sizeof (istk_t));
+	initstk = xcalloc(1, sizeof (initstack_element));
 	initstk->i_enclosing = istk;
 	initstk->i_type = istk->i_subt;
 	lint_assert(initstk->i_type->t_tspec != FUNC);
@@ -594,7 +594,7 @@ again:
 static void
 initstack_check_too_many(void)
 {
-	istk_t	*istk;
+	initstack_element *istk;
 
 	istk = initstk;
 
@@ -857,7 +857,7 @@ static bool
 initstack_string(tnode_t *tn)
 {
 	tspec_t	t;
-	istk_t	*istk;
+	initstack_element *istk;
 	int	len;
 	strg_t	*strg;
 



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 09:24:32 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: rename istk to initstack_element

The longer name is more expressive and more correct.  The previous name
called each stack element a stack itself, which was unnecessarily
confusing.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 09:19:53 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c d_c99_init.exp

Log Message:
lint: add another test case for initializing an object


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/d_c99_init.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 09:19:53 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c d_c99_init.exp

Log Message:
lint: add another test case for initializing an object


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/d_c99_init.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/d_c99_init.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.2 src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.3
--- src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.2	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c	Sun Feb 21 09:19:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_init.c,v 1.2 2021/02/21 09:07:58 rillig Exp $	*/
+/*	$NetBSD: d_c99_init.c,v 1.3 2021/02/21 09:19:53 rillig Exp $	*/
 # 3 "d_c99_init.c"
 
 /*
@@ -13,4 +13,5 @@
 // interpretation is "optionally enclosed in a single pair of braces".
 int scalar_without_braces = 3;
 int scalar_with_optional_braces = { 3 };
-int scalar_with_too_many_braces = {{ 3 }};	/* expect: 176 */
+int scalar_with_too_many_braces = {{ 3 }};		/* expect: 176 */
+int scalar_with_too_many_initializers = { 3, 5 };	/* expect: 174 */

Index: src/tests/usr.bin/xlint/lint1/d_c99_init.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.1 src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.2
--- src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.1	Sun Feb 21 08:05:51 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.exp	Sun Feb 21 09:19:53 2021
@@ -1 +1,2 @@
 d_c99_init.c(16): invalid initializer type int [176]
+d_c99_init.c(17): too many initializers [174]



CVS commit: src

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 09:17:56 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: d_cvt_constant.c d_cvt_constant.exp
msg_217.c
src/usr.bin/xlint/lint1: func.c

Log Message:
lint: fix wrong warning about main falling off the bottom in C99 mode

This gets lint a small step closer to implementing C99.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/d_cvt_constant.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/d_cvt_constant.exp \
src/tests/usr.bin/xlint/lint1/msg_217.c
cvs rdiff -u -r1.71 -r1.72 src/usr.bin/xlint/lint1/func.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 09:17:56 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: d_cvt_constant.c d_cvt_constant.exp
msg_217.c
src/usr.bin/xlint/lint1: func.c

Log Message:
lint: fix wrong warning about main falling off the bottom in C99 mode

This gets lint a small step closer to implementing C99.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/d_cvt_constant.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/d_cvt_constant.exp \
src/tests/usr.bin/xlint/lint1/msg_217.c
cvs rdiff -u -r1.71 -r1.72 src/usr.bin/xlint/lint1/func.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/d_cvt_constant.c
diff -u src/tests/usr.bin/xlint/lint1/d_cvt_constant.c:1.4 src/tests/usr.bin/xlint/lint1/d_cvt_constant.c:1.5
--- src/tests/usr.bin/xlint/lint1/d_cvt_constant.c:1.4	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/d_cvt_constant.c	Sun Feb 21 09:17:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_cvt_constant.c,v 1.4 2021/02/21 09:07:58 rillig Exp $	*/
+/*	$NetBSD: d_cvt_constant.c,v 1.5 2021/02/21 09:17:55 rillig Exp $	*/
 # 3 "d_cvt_constant.c"
 
 /* the second assignment assumes failed before */
@@ -9,6 +9,4 @@ main(void)
 	int foo = 0;
 	if (foo)
 		x = 1;
-}/* expect: 217 */
-// FIXME: Since C99, main may fall off the bottom without returning a value.
-//  Therefore there should be no warning 217.
+}

Index: src/tests/usr.bin/xlint/lint1/d_cvt_constant.exp
diff -u src/tests/usr.bin/xlint/lint1/d_cvt_constant.exp:1.3 src/tests/usr.bin/xlint/lint1/d_cvt_constant.exp:1.4
--- src/tests/usr.bin/xlint/lint1/d_cvt_constant.exp:1.3	Sun Jan 31 14:57:28 2021
+++ src/tests/usr.bin/xlint/lint1/d_cvt_constant.exp	Sun Feb 21 09:17:55 2021
@@ -1,2 +1 @@
 d_cvt_constant.c(8): warning: x set but not used in function main [191]
-d_cvt_constant.c(12): warning: function main falls off bottom without returning value [217]
Index: src/tests/usr.bin/xlint/lint1/msg_217.c
diff -u src/tests/usr.bin/xlint/lint1/msg_217.c:1.3 src/tests/usr.bin/xlint/lint1/msg_217.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_217.c:1.3	Sun Jan 31 13:33:10 2021
+++ src/tests/usr.bin/xlint/lint1/msg_217.c	Sun Feb 21 09:17:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_217.c,v 1.3 2021/01/31 13:33:10 rillig Exp $	*/
+/*	$NetBSD: msg_217.c,v 1.4 2021/02/21 09:17:55 rillig Exp $	*/
 # 3 "msg_217.c"
 
 // Test for message: function %s falls off bottom without returning value [217]
@@ -30,3 +30,15 @@ do_while_return(int i)
 		return i;
 	} while (/*CONSTCOND*/0);	/*FIXME*//* expect: 193 */
 }	/*FIXME*//* expect: 217 */
+
+/*
+ * C99 5.1.2.2.3 "Program termination" p1 defines that as a special exception,
+ * the function 'main' does not have to return a value, reaching the bottom
+ * is equivalent to returning 0.
+ *
+ * Before func.c 1.72 from 2021-02-21, lint had wrongly warned about this.
+ */
+int
+main(void)
+{
+}

Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.71 src/usr.bin/xlint/lint1/func.c:1.72
--- src/usr.bin/xlint/lint1/func.c:1.71	Fri Feb 19 22:27:49 2021
+++ src/usr.bin/xlint/lint1/func.c	Sun Feb 21 09:17:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: func.c,v 1.71 2021/02/19 22:27:49 rillig Exp $	*/
+/*	$NetBSD: func.c,v 1.72 2021/02/21 09:17:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.71 2021/02/19 22:27:49 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.72 2021/02/21 09:17:55 rillig Exp $");
 #endif
 
 #include 
@@ -337,6 +337,22 @@ funcdef(sym_t *fsym)
 	reached = true;
 }
 
+static void
+check_missing_return_value(void)
+{
+	if (funcsym->s_type->t_subt->t_tspec == VOID)
+		return;
+	if (funcsym->s_return_type_implicit_int)
+		return;
+
+	/* C99 5.1.2.2.3 "Program termination" p1 */
+	if (Sflag && strcmp(funcsym->s_name, "main") == 0)
+		return;
+
+	/* function %s falls off bottom without returning value */
+	warning(217, funcsym->s_name);
+}
+
 /*
  * Called at the end of a function definition.
  */
@@ -348,11 +364,7 @@ funcend(void)
 
 	if (reached) {
 		cstmt->c_had_return_noval = true;
-		if (funcsym->s_type->t_subt->t_tspec != VOID &&
-		!funcsym->s_return_type_implicit_int) {
-			/* func. %s falls off bottom without returning value */
-			warning(217, funcsym->s_name);
-		}
+		check_missing_return_value();
 	}
 
 	/*



CVS commit: src/tests/usr.bin/xlint

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 09:07:58 UTC 2021

Modified Files:
src/tests/usr.bin/xlint: check-expect.lua
src/tests/usr.bin/xlint/lint1: d_c99_bool.c d_c99_init.c
d_c99_union_cast.c d_constant_conv1.c d_constant_conv2.c
d_cvt_constant.c d_decl_old_style_arguments.c d_fold_test.c
d_gcc_extension.c d_incorrect_array_size.c d_lint_assert.c
d_long_double_int.c d_return_type.c d_struct_init_nested.c
d_type_conv1.c d_type_conv2.c d_type_conv3.c msg_011.c msg_012.c
msg_013.c msg_014.c msg_015.c msg_016.c msg_017.c msg_018.c
msg_020.c msg_022.c msg_023.c msg_024.c msg_025.c msg_026.c
msg_028.c msg_030.c msg_032.c msg_033.c msg_038.c msg_039.c
msg_040.c msg_041.c msg_042.c msg_043.c msg_044.c msg_045.c
msg_046.c msg_047.c msg_048.c msg_049.c msg_052.c msg_053.c
msg_058.c msg_059.c msg_062.c msg_063.c msg_064.c msg_065.c
msg_067.c msg_069.c msg_070.c msg_076.c msg_077.c msg_078.c
msg_079.c msg_080.c msg_090.c msg_091.c msg_092.c msg_102.c
msg_103.c msg_104.c msg_105.c msg_106.c msg_107.c msg_110.c
msg_111.c msg_112.c msg_113.c msg_118.c msg_119.c msg_128.c
msg_131.c msg_132.c msg_134.c msg_135.c msg_137.c msg_138.c
msg_139.c msg_140.c msg_141.c msg_147.c msg_148.c msg_149.c
msg_151.c msg_152.c msg_153.c msg_154.c msg_155.c msg_157.c
msg_158.c msg_159.c msg_162.c msg_176.c msg_179.c msg_181.c
msg_182.c msg_183.c msg_184.c msg_185.c msg_186.c msg_187.c
msg_188.c msg_190.c msg_195.c msg_196.c msg_197.c msg_198.c
msg_199.c msg_200.c msg_201.c msg_202.c msg_203.c msg_205.c
msg_206.c msg_207.c msg_208.c msg_209.c msg_210.c msg_211.c
msg_212.c msg_213.c msg_214.c msg_215.c msg_218.c msg_222.c
msg_226.c msg_227.c msg_228.c msg_229.c msg_233.c msg_234.c
msg_235.c msg_236.c msg_237.c msg_238.c msg_239.c msg_240.c
msg_241.c msg_242.c msg_244.c msg_245.c msg_246.c msg_247.c
msg_248.c msg_249.c msg_250.c msg_251.c msg_252.c msg_253.c
msg_254.c msg_255.c msg_256.c msg_257.c msg_258.c msg_260.c
msg_261.c msg_262.c msg_263.c msg_264.c msg_266.c msg_267.c
msg_268.c msg_269.c msg_270.c msg_271.c msg_272.c msg_273.c
msg_274.c msg_275.c msg_276.c msg_277.c msg_278.c msg_279.c
msg_280.c msg_281.c msg_282.c msg_283.c msg_284.c msg_285.c
msg_286.c msg_287.c msg_288.c msg_289.c msg_290.c msg_291.c
msg_292.c msg_293.c msg_294.c msg_295.c msg_296.c msg_297.c
msg_298.c msg_299.c msg_300.c msg_301.c msg_302.c msg_303.c
msg_304.c msg_305.c msg_306.c msg_307.c msg_309.c msg_310.c
msg_311.c msg_312.c msg_313.c msg_314.c msg_315.c msg_316.c
msg_317.c msg_318.c msg_319.c msg_320.c msg_321.c msg_322.c
msg_323.c msg_325.c msg_326.c msg_327.c msg_328.c

Log Message:
lint: force each test to declare the expected diagnostics

By listing the expected diagnostics directly at the code that triggers
the diagnostics, it is easier to cross-check whether the diagnostics
make sense.

No functional change to lint itself.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/check-expect.lua
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/d_c99_bool.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/d_c99_init.c \
src/tests/usr.bin/xlint/lint1/d_decl_old_style_arguments.c \
src/tests/usr.bin/xlint/lint1/msg_012.c \
src/tests/usr.bin/xlint/lint1/msg_013.c \
src/tests/usr.bin/xlint/lint1/msg_014.c \
src/tests/usr.bin/xlint/lint1/msg_015.c \
src/tests/usr.bin/xlint/lint1/msg_016.c \
src/tests/usr.bin/xlint/lint1/msg_017.c \
src/tests/usr.bin/xlint/lint1/msg_018.c \
src/tests/usr.bin/xlint/lint1/msg_020.c \
src/tests/usr.bin/xlint/lint1/msg_022.c \
src/tests/usr.bin/xlint/lint1/msg_023.c \
src/tests/usr.bin/xlint/lint1/msg_024.c \
src/tests/usr.bin/xlint/lint1/msg_025.c \
src/tests/usr.bin/xlint/lint1/msg_026.c \
src/tests/usr.bin/xlint/lint1/msg_028.c \
src/tests/usr.bin/xlint/lint1/msg_030.c \
src/tests/usr.bin/xlint/lint1/msg_032.c \
src/tests/usr.bin/xlint/lint1/msg_033.c \
src/tests/usr.bin/xlint/lint1/msg_038.c \
src/tests/usr.bin/xlint/lint1/msg_039.c \
src/tests/usr.bin/xlint/lint1/msg_040.c \
src/tests/usr.bin/xlint/lint1/msg_041.c \
src/tests/usr.bin/xlint/lint1/msg_042.c \
src/tests/usr.bin/xlint/lint1/msg_043.c \
src/tests/usr.bin/xlint/lint1/msg_044.c \
src/tests/usr.bin/xlint/lint1/msg_045.c \
src/tests/usr.bin/xlint/lint1/msg_046.c \
src/tests/usr.bin/xlint/lint1/msg_047.c \
src/tests/usr.bin/xlint/lint1/msg_048.c \
src/tests/usr.bin/xlint/lint1/msg_049.c \

CVS commit: src/sys/arch/arm/arm

2021-02-21 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Feb 21 08:47:13 UTC 2021

Modified Files:
src/sys/arch/arm/arm: arm_machdep.c

Log Message:
KNF consistency


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/arch/arm/arm/arm_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/arm/arm_machdep.c
diff -u src/sys/arch/arm/arm/arm_machdep.c:1.66 src/sys/arch/arm/arm/arm_machdep.c:1.67
--- src/sys/arch/arm/arm/arm_machdep.c:1.66	Sun Feb 21 08:46:28 2021
+++ src/sys/arch/arm/arm/arm_machdep.c	Sun Feb 21 08:47:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: arm_machdep.c,v 1.66 2021/02/21 08:46:28 skrll Exp $	*/
+/*	$NetBSD: arm_machdep.c,v 1.67 2021/02/21 08:47:13 skrll Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: arm_machdep.c,v 1.66 2021/02/21 08:46:28 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm_machdep.c,v 1.67 2021/02/21 08:47:13 skrll Exp $");
 
 #include 
 #include 
@@ -310,12 +310,14 @@ cpu_intr_p(void)
 struct lwp *
 arm_curlwp(void)
 {
+
 	return curlwp;
 }
 
 struct cpu_info *
 arm_curcpu(void)
 {
+
 	return curcpu();
 }
 #endif
@@ -340,6 +342,7 @@ cpu_kpreempt_exit(uintptr_t where)
 bool
 cpu_kpreempt_disabled(void)
 {
+
 	return curcpu()->ci_cpl != IPL_NONE;
 }
 #endif /* __HAVE_PREEMPTION */



CVS commit: src/sys/arch/arm/arm

2021-02-21 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Feb 21 08:47:13 UTC 2021

Modified Files:
src/sys/arch/arm/arm: arm_machdep.c

Log Message:
KNF consistency


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/arch/arm/arm/arm_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/arm/arm

2021-02-21 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Feb 21 08:46:28 UTC 2021

Modified Files:
src/sys/arch/arm/arm: arm_machdep.c

Log Message:
Some preemption updates - still not being used (yet)


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/arm/arm/arm_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/arm/arm_machdep.c
diff -u src/sys/arch/arm/arm/arm_machdep.c:1.65 src/sys/arch/arm/arm/arm_machdep.c:1.66
--- src/sys/arch/arm/arm/arm_machdep.c:1.65	Tue Dec  1 02:43:13 2020
+++ src/sys/arch/arm/arm/arm_machdep.c	Sun Feb 21 08:46:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: arm_machdep.c,v 1.65 2020/12/01 02:43:13 rin Exp $	*/
+/*	$NetBSD: arm_machdep.c,v 1.66 2021/02/21 08:46:28 skrll Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: arm_machdep.c,v 1.65 2020/12/01 02:43:13 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm_machdep.c,v 1.66 2021/02/21 08:46:28 skrll Exp $");
 
 #include 
 #include 
@@ -223,6 +223,8 @@ void
 cpu_need_resched(struct cpu_info *ci, struct lwp *l, int flags)
 {
 
+	KASSERT(kpreempt_disabled());
+
 	if (flags & RESCHED_IDLE) {
 #ifdef MULTIPROCESSOR
 		/*
@@ -322,13 +324,17 @@ arm_curcpu(void)
 bool
 cpu_kpreempt_enter(uintptr_t where, int s)
 {
+
+	KASSERT(kpreempt_disabled());
+
 	return s == IPL_NONE;
 }
 
 void
 cpu_kpreempt_exit(uintptr_t where)
 {
-	atomic_and_uint(()->ci_astpending, (unsigned int)~__BIT(1));
+
+	/* do nothing */
 }
 
 bool



CVS commit: src/sys/arch/arm/arm

2021-02-21 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Feb 21 08:46:28 UTC 2021

Modified Files:
src/sys/arch/arm/arm: arm_machdep.c

Log Message:
Some preemption updates - still not being used (yet)


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/arm/arm/arm_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/arm/pic

2021-02-21 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Feb 21 08:31:36 UTC 2021

Modified Files:
src/sys/arch/arm/pic: pic.c

Log Message:
Fixup with __HAVE_PREEMPTION code which is currently unused


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/arm/pic/pic.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/pic/pic.c
diff -u src/sys/arch/arm/pic/pic.c:1.67 src/sys/arch/arm/pic/pic.c:1.68
--- src/sys/arch/arm/pic/pic.c:1.67	Sat Feb 20 19:30:46 2021
+++ src/sys/arch/arm/pic/pic.c	Sun Feb 21 08:31:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pic.c,v 1.67 2021/02/20 19:30:46 jmcneill Exp $	*/
+/*	$NetBSD: pic.c,v 1.68 2021/02/21 08:31:36 skrll Exp $	*/
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -33,7 +33,7 @@
 #include "opt_multiprocessor.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pic.c,v 1.67 2021/02/20 19:30:46 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pic.c,v 1.68 2021/02/21 08:31:36 skrll Exp $");
 
 #include 
 #include 
@@ -166,7 +166,9 @@ pic_ipi_ddb(void *arg)
 int
 pic_ipi_kpreempt(void *arg)
 {
-	atomic_or_uint(()->ci_astpending, __BIT(1));
+	struct lwp *l = curlwp;
+
+	l->l_md.md_astpending |= __BIT(1);
 	return 1;
 }
 #endif /* __HAVE_PREEMPTION */
@@ -569,7 +571,8 @@ pic_do_pending_ints(register_t psw, int 
 	}
 #endif /* __HAVE_PIC_PENDING_INTRS */
 #ifdef __HAVE_PREEMPTION
-	if (newipl == IPL_NONE && (ci->ci_astpending & __BIT(1))) {
+	struct lwp *l = curlwp;
+	if (newipl == IPL_NONE && (l->l_md.md_astpending & __BIT(1))) {
 		pic_set_priority_psw(ci, psw, IPL_SCHED);
 		kpreempt(0);
 	}



CVS commit: src/sys/arch/arm/pic

2021-02-21 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Feb 21 08:31:36 UTC 2021

Modified Files:
src/sys/arch/arm/pic: pic.c

Log Message:
Fixup with __HAVE_PREEMPTION code which is currently unused


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/arm/pic/pic.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 08:27:41 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: reduce amount of debug output during initialization


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.77 src/usr.bin/xlint/lint1/init.c:1.78
--- src/usr.bin/xlint/lint1/init.c:1.77	Sun Feb 21 08:01:14 2021
+++ src/usr.bin/xlint/lint1/init.c	Sun Feb 21 08:27:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.77 2021/02/21 08:01:14 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.78 2021/02/21 08:27:41 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.77 2021/02/21 08:01:14 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.78 2021/02/21 08:27:41 rillig Exp $");
 #endif
 
 #include 
@@ -74,8 +74,8 @@ typedef	struct istk {
 	bool i_seen_named_member: 1;
 
 	/*
-	 * For structs (XXX: and unions?), the next member to be initialized
-	 * by an initializer without an optional designator.
+	 * For structs, the next member to be initialized by an initializer
+	 * without an optional designator.
 	 */
 	sym_t *i_current_object;
 
@@ -251,10 +251,28 @@ debug_named_member(void)
 #endif
 
 #ifdef DEBUG
-static const char *
-noyes(bool cond)
+static void
+debug_initstack_element(const istk_t *elem)
 {
-	return cond ? "yes" : "no";
+	if (elem->i_type != NULL)
+		debug_step("  i_type   = %s", type_name(elem->i_type));
+	if (elem->i_subt != NULL)
+		debug_step("  i_subt   = %s", type_name(elem->i_subt));
+
+	if (elem->i_brace)
+		debug_step("  i_brace");
+	if (elem->i_array_of_unknown_size)
+		debug_step("  i_array_of_unknown_size");
+	if (elem->i_seen_named_member)
+		debug_step("  i_seen_named_member");
+
+	const type_t *eff_type = elem->i_type != NULL
+	? elem->i_type : elem->i_subt;
+	if (eff_type->t_tspec == STRUCT && elem->i_current_object != NULL)
+		debug_step("  i_current_object = %s",
+		elem->i_current_object->s_name);
+
+	debug_step("  i_remaining  = %d", elem->i_remaining);
 }
 
 static void
@@ -269,22 +287,7 @@ debug_initstack(void)
 	for (const istk_t *elem = initstk;
 	 elem != NULL; elem = elem->i_enclosing) {
 		debug_step("initstk[%zu]:", i);
-		debug_step("  i_type   = %s", type_name(elem->i_type));
-		debug_step("  i_subt   = %s", type_name(elem->i_subt));
-		debug_step("  flags=%s%s%s%s",
-		elem->i_brace
-			? " brace" : "",
-		elem->i_array_of_unknown_size
-			? "array_of_unknown_size" : "",
-		elem->i_seen_named_member ? "seen_named_member" : "",
-		!(elem->i_brace || elem->i_array_of_unknown_size ||
-		  elem->i_seen_named_member)
-			? " none" : "");
-		debug_step("  i_current_object = %s",
-		elem->i_current_object != NULL
-			? elem->i_current_object->s_name
-			: "(null)");
-		debug_step("  i_remaining  = %d", elem->i_remaining);
+		debug_initstack_element(elem);
 		i++;
 	}
 }



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 08:27:41 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: reduce amount of debug output during initialization


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 08:05:51 UTC 2021

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: Makefile t_integration.sh
Added Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c d_c99_init.exp

Log Message:
lint: add another test for C99 initializers


To generate a diff of this commit:
cvs rdiff -u -r1.1020 -r1.1021 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.31 -r1.32 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/d_c99_init.c \
src/tests/usr.bin/xlint/lint1/d_c99_init.exp
cvs rdiff -u -r1.29 -r1.30 src/tests/usr.bin/xlint/lint1/t_integration.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1020 src/distrib/sets/lists/tests/mi:1.1021
--- src/distrib/sets/lists/tests/mi:1.1020	Fri Feb 19 12:28:56 2021
+++ src/distrib/sets/lists/tests/mi	Sun Feb 21 08:05:51 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1020 2021/02/19 12:28:56 rillig Exp $
+# $NetBSD: mi,v 1.1021 2021/02/21 08:05:51 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -5772,6 +5772,8 @@
 ./usr/tests/usr.bin/xlint/lint1/d_c99_flex_array_packed.c	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_c99_for_loops.c		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_c99_func.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/d_c99_init.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/d_c99_init.exp			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_c99_nested_struct.c		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_c99_recursive_init.c		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_c99_struct_init.c		tests-usr.bin-tests	compattestfile,atf

Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.31 src/tests/usr.bin/xlint/lint1/Makefile:1.32
--- src/tests/usr.bin/xlint/lint1/Makefile:1.31	Fri Feb 19 12:28:56 2021
+++ src/tests/usr.bin/xlint/lint1/Makefile	Sun Feb 21 08:05:51 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.31 2021/02/19 12:28:56 rillig Exp $
+# $NetBSD: Makefile,v 1.32 2021/02/21 08:05:51 rillig Exp $
 
 NOMAN=		# defined
 
@@ -28,6 +28,8 @@ FILES+=		d_c99_decls_after_stmt3.c
 FILES+=		d_c99_flex_array_packed.c
 FILES+=		d_c99_for_loops.c
 FILES+=		d_c99_func.c
+FILES+=		d_c99_init.c
+FILES+=		d_c99_init.exp
 FILES+=		d_c99_nested_struct.c
 FILES+=		d_c99_recursive_init.c
 FILES+=		d_c99_struct_init.c

Index: src/tests/usr.bin/xlint/lint1/t_integration.sh
diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.29 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.30
--- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.29	Fri Feb 19 12:28:56 2021
+++ src/tests/usr.bin/xlint/lint1/t_integration.sh	Sun Feb 21 08:05:51 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.29 2021/02/19 12:28:56 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.30 2021/02/21 08:05:51 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -98,6 +98,7 @@ test_case c99_bool_strict_syshdr
 test_case c99_compound_literal_comma
 test_case c99_decls_after_stmt2
 test_case c99_flex_array_packed
+test_case c99_init
 test_case c99_nested_struct
 test_case c99_union_cast
 test_case c99_union_init4

Added files:

Index: src/tests/usr.bin/xlint/lint1/d_c99_init.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.1
--- /dev/null	Sun Feb 21 08:05:52 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c	Sun Feb 21 08:05:51 2021
@@ -0,0 +1,16 @@
+/*	$NetBSD: d_c99_init.c,v 1.1 2021/02/21 08:05:51 rillig Exp $	*/
+# 3 "d_c99_init.c"
+
+/*
+ * Test C99 initializers.
+ *
+ * See C99 6.7.8 "Initialization".
+*/
+
+/* lint1-extra-flags: -p */
+
+// C99 6.7.8p11 says "optionally enclosed in braces".  The intended
+// interpretation is "optionally enclosed in a single pair of braces".
+int scalar_without_braces = 3;
+int scalar_with_optional_braces = { 3 };
+int scalar_with_too_many_braces = {{ 3 }};
Index: src/tests/usr.bin/xlint/lint1/d_c99_init.exp
diff -u /dev/null src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.1
--- /dev/null	Sun Feb 21 08:05:52 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.exp	Sun Feb 21 08:05:51 2021
@@ -0,0 +1 @@
+d_c99_init.c(16): invalid initializer type int [176]



CVS commit: src

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 08:05:51 UTC 2021

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: Makefile t_integration.sh
Added Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c d_c99_init.exp

Log Message:
lint: add another test for C99 initializers


To generate a diff of this commit:
cvs rdiff -u -r1.1020 -r1.1021 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.31 -r1.32 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/d_c99_init.c \
src/tests/usr.bin/xlint/lint1/d_c99_init.exp
cvs rdiff -u -r1.29 -r1.30 src/tests/usr.bin/xlint/lint1/t_integration.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/xlint/lint1

2021-02-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 21 08:01:14 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: init.c

Log Message:
lint: rename members of struct istk to be more expressive

No functional change outside debug mode.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.76 src/usr.bin/xlint/lint1/init.c:1.77
--- src/usr.bin/xlint/lint1/init.c:1.76	Sun Feb 21 07:21:57 2021
+++ src/usr.bin/xlint/lint1/init.c	Sun Feb 21 08:01:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.76 2021/02/21 07:21:57 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.77 2021/02/21 08:01:14 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.76 2021/02/21 07:21:57 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.77 2021/02/21 08:01:14 rillig Exp $");
 #endif
 
 #include 
@@ -63,14 +63,37 @@ __RCSID("$NetBSD: init.c,v 1.76 2021/02/
  * selected examples.
  */
 typedef	struct istk {
+
+	/* XXX: Why is i_type often null? */
 	type_t	*i_type;		/* type of initialisation */
 	type_t	*i_subt;		/* type of next level */
-	bool	i_brace : 1;		/* need } for pop */
-	bool	i_nolimit : 1;		/* incomplete array type */
-	bool	i_namedmem : 1;		/* has c9x named members */
-	sym_t	*i_mem;			/* next structure member */
-	int	i_remaining;		/* # of remaining elements */
-	struct	istk *i_next;		/* previous level */
+
+	/* need '}' for pop; XXX: explain this */
+	bool i_brace: 1;
+	bool i_array_of_unknown_size: 1;
+	bool i_seen_named_member: 1;
+
+	/*
+	 * For structs (XXX: and unions?), the next member to be initialized
+	 * by an initializer without an optional designator.
+	 */
+	sym_t *i_current_object;
+
+	/*
+	 * The number of remaining elements.
+	 *
+	 * XXX: for scalars?
+	 * XXX: for structs?
+	 * XXX: for unions?
+	 * XXX: for arrays?
+	 */
+	int i_remaining;
+
+	/*
+	 * The initialization state of the enclosing data structure
+	 * (struct, union, array).
+	 */
+	struct istk *i_enclosing;
 } istk_t;
 
 /*
@@ -243,16 +266,25 @@ debug_initstack(void)
 	}
 
 	size_t i = 0;
-	for (const istk_t *elem = initstk; elem != NULL; elem = elem->i_next) {
+	for (const istk_t *elem = initstk;
+	 elem != NULL; elem = elem->i_enclosing) {
 		debug_step("initstk[%zu]:", i);
-		debug_step("  i_type  = %s", type_name(elem->i_type));
-		debug_step("  i_subt  = %s", type_name(elem->i_subt));
-		debug_step("  i_brace = %s", noyes(elem->i_brace));
-		debug_step("  i_nolimit   = %s", noyes(elem->i_nolimit));
-		debug_step("  i_namedmem  = %s", noyes(elem->i_namedmem));
-		debug_step("  i_mem   = %s",
-		elem->i_mem != NULL ? elem->i_mem->s_name : "(null)");
-		debug_step("  i_remaining = %d", elem->i_remaining);
+		debug_step("  i_type   = %s", type_name(elem->i_type));
+		debug_step("  i_subt   = %s", type_name(elem->i_subt));
+		debug_step("  flags=%s%s%s%s",
+		elem->i_brace
+			? " brace" : "",
+		elem->i_array_of_unknown_size
+			? "array_of_unknown_size" : "",
+		elem->i_seen_named_member ? "seen_named_member" : "",
+		!(elem->i_brace || elem->i_array_of_unknown_size ||
+		  elem->i_seen_named_member)
+			? " none" : "");
+		debug_step("  i_current_object = %s",
+		elem->i_current_object != NULL
+			? elem->i_current_object->s_name
+			: "(null)");
+		debug_step("  i_remaining  = %d", elem->i_remaining);
 		i++;
 	}
 }
@@ -261,7 +293,7 @@ debug_initstack(void)
 #endif
 
 /*
- * Initialize the initialisation stack by putting an entry for the variable
+ * Initialize the initialisation stack by putting an entry for the object
  * which is to be initialized on it.
  */
 void
@@ -274,14 +306,14 @@ initstack_init(void)
 
 	/* free memory used in last initialisation */
 	while ((istk = initstk) != NULL) {
-		initstk = istk->i_next;
+		initstk = istk->i_enclosing;
 		free(istk);
 	}
 
 	debug_enter();
 
 	/*
-	 * If the type which is to be initialized is an incomplete type,
+	 * If the type which is to be initialized is an incomplete array,
 	 * it must be duplicated.
 	 */
 	if (initsym->s_type->t_tspec == ARRAY && is_incomplete(initsym->s_type))
@@ -306,16 +338,16 @@ initstack_pop_item(void)
 	istk = initstk;
 	debug_step("pop type=%s, brace=%d remaining=%d named=%d",
 	type_name(istk->i_type != NULL ? istk->i_type : istk->i_subt),
-	istk->i_brace, istk->i_remaining, istk->i_namedmem);
+	istk->i_brace, istk->i_remaining, istk->i_seen_named_member);
 
-	initstk = istk->i_next;
+	initstk = istk->i_enclosing;
 	free(istk);
 	istk = initstk;
 	lint_assert(istk != NULL);
 
 	debug_step("top type=%s, brace=%d remaining=%d named=%d",
 	type_name(istk->i_type != NULL ? istk->i_type : istk->i_subt),

  1   2   >