CVS commit: [netbsd-10] src/sys/arch/i386/stand

2024-01-14 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jan 14 15:46:00 UTC 2024

Modified Files:
src/sys/arch/i386/stand/efiboot [netbsd-10]: efidisk.c efidisk.h
src/sys/arch/i386/stand/lib [netbsd-10]: biosdisk.c exec.c

Log Message:
Pull up following revision(s) (requested by mlelstv in ticket #548):

sys/arch/i386/stand/efiboot/efidisk.h: revision 1.4
sys/arch/i386/stand/lib/exec.c: revision 1.80
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.11
sys/arch/i386/stand/lib/biosdisk.c: revision 1.61

In efiboot
- create bootinfo information only once.
- add fake biosgeom entries so that the kernel can distinguish between
  hard drives (with geom) and CD-ROM (without).


To generate a diff of this commit:
cvs rdiff -u -r1.9.26.1 -r1.9.26.2 src/sys/arch/i386/stand/efiboot/efidisk.c
cvs rdiff -u -r1.3 -r1.3.32.1 src/sys/arch/i386/stand/efiboot/efidisk.h
cvs rdiff -u -r1.58.4.1 -r1.58.4.2 src/sys/arch/i386/stand/lib/biosdisk.c
cvs rdiff -u -r1.78.4.1 -r1.78.4.2 src/sys/arch/i386/stand/lib/exec.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/i386/stand/efiboot/efidisk.c
diff -u src/sys/arch/i386/stand/efiboot/efidisk.c:1.9.26.1 src/sys/arch/i386/stand/efiboot/efidisk.c:1.9.26.2
--- src/sys/arch/i386/stand/efiboot/efidisk.c:1.9.26.1	Fri Nov  3 10:01:13 2023
+++ src/sys/arch/i386/stand/efiboot/efidisk.c	Sun Jan 14 15:46:00 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: efidisk.c,v 1.9.26.1 2023/11/03 10:01:13 martin Exp $	*/
+/*	$NetBSD: efidisk.c,v 1.9.26.2 2024/01/14 15:46:00 martin Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -38,9 +38,12 @@
 #include "biosdisk_ll.h"
 #include "devopen.h"
 #include "efidisk.h"
+#include "bootinfo.h"
 
 static struct efidiskinfo_lh efi_disklist;
 static int nefidisks;
+static struct btinfo_biosgeom *bibg;
+static size_t bibg_len;
 
 #define MAXDEVNAME 39 /* "NAME=" + 34 char part_name */
 
@@ -158,6 +161,23 @@ next:
 		if (edi->bootdev)
 			boot_biosdev = edi->dev;
 	}
+
+	bibg_len = sizeof(*bibg) + nefidisks * sizeof(struct bi_biosgeom_entry);
+	bibg = alloc(bibg_len);
+	if (bibg == NULL)
+		return;
+
+	bibg->num = nefidisks;
+
+	i = 0;
+	TAILQ_FOREACH(edi, _disklist, list) {
+		if (edi->type == BIOSDISK_TYPE_HD) {
+			memset(>disk[i], 0, sizeof(bibg->disk[i]));
+			bibg->disk[i].dev = edi->dev;
+			bibg->disk[i].flags = BI_GEOM_INVALID;
+		}
+		++i;
+	}
 }
 
 static void
@@ -383,3 +403,10 @@ efidisk_get_efi_system_partition(int dev
 	*partition = i;
 	return 0;
 }
+
+void
+efidisk_getbiosgeom()
+{
+	BI_ADD(bibg, BTINFO_BIOSGEOM, bibg_len);
+}
+

Index: src/sys/arch/i386/stand/efiboot/efidisk.h
diff -u src/sys/arch/i386/stand/efiboot/efidisk.h:1.3 src/sys/arch/i386/stand/efiboot/efidisk.h:1.3.32.1
--- src/sys/arch/i386/stand/efiboot/efidisk.h:1.3	Mon Apr  2 09:44:18 2018
+++ src/sys/arch/i386/stand/efiboot/efidisk.h	Sun Jan 14 15:46:00 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: efidisk.h,v 1.3 2018/04/02 09:44:18 nonaka Exp $	*/
+/*	$NetBSD: efidisk.h,v 1.3.32.1 2024/01/14 15:46:00 martin Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -41,3 +41,4 @@ TAILQ_HEAD(efidiskinfo_lh, efidiskinfo);
 
 const struct efidiskinfo *efidisk_getinfo(int);
 int efidisk_get_efi_system_partition(int, int *);
+void efidisk_getbiosgeom(void);

Index: src/sys/arch/i386/stand/lib/biosdisk.c
diff -u src/sys/arch/i386/stand/lib/biosdisk.c:1.58.4.1 src/sys/arch/i386/stand/lib/biosdisk.c:1.58.4.2
--- src/sys/arch/i386/stand/lib/biosdisk.c:1.58.4.1	Wed Oct 18 11:44:22 2023
+++ src/sys/arch/i386/stand/lib/biosdisk.c	Sun Jan 14 15:46:00 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: biosdisk.c,v 1.58.4.1 2023/10/18 11:44:22 martin Exp $	*/
+/*	$NetBSD: biosdisk.c,v 1.58.4.2 2024/01/14 15:46:00 martin Exp $	*/
 
 /*
  * Copyright (c) 1996, 1998
@@ -1198,11 +1198,13 @@ out:
 static void
 add_biosdisk_bootinfo(void)
 {
+#ifndef EFIBOOT
 	if (bootinfo == NULL) {
 		return;
 	}
 	BI_ADD(_disk, BTINFO_BOOTDISK, sizeof(bi_disk));
 	BI_ADD(_wedge, BTINFO_BOOTWEDGE, sizeof(bi_wedge));
+#endif
 	return;
 }
 #endif

Index: src/sys/arch/i386/stand/lib/exec.c
diff -u src/sys/arch/i386/stand/lib/exec.c:1.78.4.1 src/sys/arch/i386/stand/lib/exec.c:1.78.4.2
--- src/sys/arch/i386/stand/lib/exec.c:1.78.4.1	Sat May 13 13:26:57 2023
+++ src/sys/arch/i386/stand/lib/exec.c	Sun Jan 14 15:46:00 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec.c,v 1.78.4.1 2023/05/13 13:26:57 martin Exp $	 */
+/*	$NetBSD: exec.c,v 1.78.4.2 2024/01/14 15:46:00 martin Exp $	 */
 
 /*
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -108,6 +108,8 @@
 #endif
 #ifdef EFIBOOT
 #include "efiboot.h"
+#include "biosdisk.h"
+#include "efidisk.h"
 #undef DEBUG	/* XXX */
 #endif
 
@@ -498,6 +500,10 @@ exec_netbsd(const char *file, physaddr_t
 		goto out;
 	}
 #ifdef EFIBOOT
+	BI_ADD(_disk, BTINFO_BOOTDISK, sizeof(bi_disk));
+	BI_ADD(_wedge, BTINFO_BOOTWEDGE, sizeof(bi_wedge));
+	efidisk_getbiosgeom();
+
 	

CVS commit: [netbsd-10] src/sys/arch/i386/stand

2024-01-14 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jan 14 15:46:00 UTC 2024

Modified Files:
src/sys/arch/i386/stand/efiboot [netbsd-10]: efidisk.c efidisk.h
src/sys/arch/i386/stand/lib [netbsd-10]: biosdisk.c exec.c

Log Message:
Pull up following revision(s) (requested by mlelstv in ticket #548):

sys/arch/i386/stand/efiboot/efidisk.h: revision 1.4
sys/arch/i386/stand/lib/exec.c: revision 1.80
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.11
sys/arch/i386/stand/lib/biosdisk.c: revision 1.61

In efiboot
- create bootinfo information only once.
- add fake biosgeom entries so that the kernel can distinguish between
  hard drives (with geom) and CD-ROM (without).


To generate a diff of this commit:
cvs rdiff -u -r1.9.26.1 -r1.9.26.2 src/sys/arch/i386/stand/efiboot/efidisk.c
cvs rdiff -u -r1.3 -r1.3.32.1 src/sys/arch/i386/stand/efiboot/efidisk.h
cvs rdiff -u -r1.58.4.1 -r1.58.4.2 src/sys/arch/i386/stand/lib/biosdisk.c
cvs rdiff -u -r1.78.4.1 -r1.78.4.2 src/sys/arch/i386/stand/lib/exec.c

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



CVS commit: [netbsd-10] src/sys/arch/i386/stand

2023-12-14 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Dec 14 17:56:09 UTC 2023

Modified Files:
src/sys/arch/i386/stand [netbsd-10]: Makefile.booters Makefile.inc
src/sys/arch/i386/stand/bootxx/bootxx_msdos [netbsd-10]: Makefile
src/sys/arch/i386/stand/bootxx/bootxx_ustarfs [netbsd-10]: Makefile
src/sys/arch/i386/stand/dosboot [netbsd-10]: Makefile

Log Message:
Pull up following revision(s) (requested by rin in ticket #498):

sys/arch/i386/stand/dosboot/Makefile: revision 1.35
sys/arch/i386/stand/Makefile.booters: revision 1.95
sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile: revision 1.5
sys/arch/i386/stand/Makefile.inc: revision 1.19
sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile: revision 1.4
sys/arch/i386/stand/dosboot/Makefile: revision 1.34

Fix the clang build by setting -z noseparate-code

Merge the OPT_SIZE flags. -Oz is not always producing smaller code that -Os,
so default to -Os for both, and we'll override where needed.

Override these two booters with -Oz for clang since it produces smaller code
here.

x86/dosboot: Allow NULL dereference to fetch command line arguments
DOS command line arguments are provided as struct psp at 0x;
see doscommain.c.

Recent versions of gcc and clang are clever enough to optimize code
block involving NULL dereference into ud2 insn.

Sprinkle -fno-delete-null-pointer-checks to doscommain.c to
prevent this behavior.

Note that dosboot.com for netbsd-9 and later was broken due to
this ``over optimization''. gcc 5.5.0 and clang 4.0.0 in netbsd-8
generate correct codes without this workaround.

XXX
Are there still use cases for dosboot.com? Does anyone want to
boot NetBSD from real-mode DOS in 2023?

x86/dosboot: Do not page-align data segment
4K alignment is too heavy burden for COM executable with 64K limit :)
Fix binary size overflow for clang/amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.94.20.1 src/sys/arch/i386/stand/Makefile.booters
cvs rdiff -u -r1.18 -r1.18.30.1 src/sys/arch/i386/stand/Makefile.inc
cvs rdiff -u -r1.4 -r1.4.24.1 \
src/sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile
cvs rdiff -u -r1.3 -r1.3.94.1 \
src/sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile
cvs rdiff -u -r1.33 -r1.33.26.1 src/sys/arch/i386/stand/dosboot/Makefile

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/i386/stand/Makefile.booters
diff -u src/sys/arch/i386/stand/Makefile.booters:1.94 src/sys/arch/i386/stand/Makefile.booters:1.94.20.1
--- src/sys/arch/i386/stand/Makefile.booters:1.94	Sun Sep  6 07:20:28 2020
+++ src/sys/arch/i386/stand/Makefile.booters	Thu Dec 14 17:56:08 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.booters,v 1.94 2020/09/06 07:20:28 mrg Exp $
+#	$NetBSD: Makefile.booters,v 1.94.20.1 2023/12/14 17:56:08 martin Exp $
 
 NOLIBCSANITIZER=
 NOSANITIZER=
@@ -77,7 +77,7 @@ cleandir distclean: .WAIT cleanlibdir
 cleanlibdir:
 	-rm -rf lib
 
-LDFLAGS+=-Wl,-M -Wl,-e,start 	# -N does not work properly.
+LDFLAGS+=-Wl,-z,noseparate-code -Wl,-M -Wl,-e,start 	# -N does not work properly.
 
 LIBLIST=${LIBI386} ${LIBSA} ${LIBZ} ${LIBSA} ${LIBKERN} ${LIBI386} ${LIBSA}
 

Index: src/sys/arch/i386/stand/Makefile.inc
diff -u src/sys/arch/i386/stand/Makefile.inc:1.18 src/sys/arch/i386/stand/Makefile.inc:1.18.30.1
--- src/sys/arch/i386/stand/Makefile.inc:1.18	Sun Jan 27 04:56:46 2019
+++ src/sys/arch/i386/stand/Makefile.inc	Thu Dec 14 17:56:08 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.18 2019/01/27 04:56:46 dholland Exp $
+#	$NetBSD: Makefile.inc,v 1.18.30.1 2023/12/14 17:56:08 martin Exp $
 
 NOLIBCSANITIZER=
 NOSANITIZER=
@@ -10,8 +10,6 @@ NOMAN=
 BINDIR=	/usr/mdec
 
 OPT_SIZE.gcc=	-Os -ffreestanding -fomit-frame-pointer -fno-unwind-tables \
-		-fno-asynchronous-unwind-tables -fno-exceptions -mno-sse
-OPT_SIZE.clang=	-Oz -ffreestanding -fomit-frame-pointer -DNDEBUG \
-		-fno-stack-protector -mno-sse \
-		-mstack-alignment=4 \
-		-fno-unwind-tables
+		-fno-asynchronous-unwind-tables -fno-exceptions -mno-sse \
+		-fno-stack-protector
+OPT_SIZE.clang=	${OPT_SIZE.gcc} -mstack-alignment=4  -DNDEBUG

Index: src/sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile
diff -u src/sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile:1.4 src/sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile:1.4.24.1
--- src/sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile:1.4	Wed Jan 22 06:13:18 2020
+++ src/sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile	Thu Dec 14 17:56:08 2023
@@ -1,7 +1,11 @@
-# $NetBSD: Makefile,v 1.4 2020/01/22 06:13:18 martin Exp $
+# $NetBSD: Makefile,v 1.4.24.1 2023/12/14 17:56:08 martin Exp $
+
+NOMAN=yes
+.include 
 
 PROG=	bootxx_msdos
 FS=	dosfs
 CPPFLAGS=-DBOOT_FROM_FAT -DTERSE_ERROR -DSA_DOSFS_NO_BIG_PART_SUPPORT
 
 .include <../Makefile.bootxx>
+OPT_SIZE.clang += -Oz

Index: src/sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile
diff -u 

CVS commit: [netbsd-10] src/sys/arch/i386/stand

2023-12-14 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Dec 14 17:56:09 UTC 2023

Modified Files:
src/sys/arch/i386/stand [netbsd-10]: Makefile.booters Makefile.inc
src/sys/arch/i386/stand/bootxx/bootxx_msdos [netbsd-10]: Makefile
src/sys/arch/i386/stand/bootxx/bootxx_ustarfs [netbsd-10]: Makefile
src/sys/arch/i386/stand/dosboot [netbsd-10]: Makefile

Log Message:
Pull up following revision(s) (requested by rin in ticket #498):

sys/arch/i386/stand/dosboot/Makefile: revision 1.35
sys/arch/i386/stand/Makefile.booters: revision 1.95
sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile: revision 1.5
sys/arch/i386/stand/Makefile.inc: revision 1.19
sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile: revision 1.4
sys/arch/i386/stand/dosboot/Makefile: revision 1.34

Fix the clang build by setting -z noseparate-code

Merge the OPT_SIZE flags. -Oz is not always producing smaller code that -Os,
so default to -Os for both, and we'll override where needed.

Override these two booters with -Oz for clang since it produces smaller code
here.

x86/dosboot: Allow NULL dereference to fetch command line arguments
DOS command line arguments are provided as struct psp at 0x;
see doscommain.c.

Recent versions of gcc and clang are clever enough to optimize code
block involving NULL dereference into ud2 insn.

Sprinkle -fno-delete-null-pointer-checks to doscommain.c to
prevent this behavior.

Note that dosboot.com for netbsd-9 and later was broken due to
this ``over optimization''. gcc 5.5.0 and clang 4.0.0 in netbsd-8
generate correct codes without this workaround.

XXX
Are there still use cases for dosboot.com? Does anyone want to
boot NetBSD from real-mode DOS in 2023?

x86/dosboot: Do not page-align data segment
4K alignment is too heavy burden for COM executable with 64K limit :)
Fix binary size overflow for clang/amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.94.20.1 src/sys/arch/i386/stand/Makefile.booters
cvs rdiff -u -r1.18 -r1.18.30.1 src/sys/arch/i386/stand/Makefile.inc
cvs rdiff -u -r1.4 -r1.4.24.1 \
src/sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile
cvs rdiff -u -r1.3 -r1.3.94.1 \
src/sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile
cvs rdiff -u -r1.33 -r1.33.26.1 src/sys/arch/i386/stand/dosboot/Makefile

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



CVS commit: [netbsd-10] src/sys/arch/i386/stand/efiboot

2023-11-03 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Nov  3 10:01:13 UTC 2023

Modified Files:
src/sys/arch/i386/stand/efiboot [netbsd-10]: boot.c devopen.c efidisk.c
efimemory.c
src/sys/arch/i386/stand/efiboot/bootia32 [netbsd-10]: efibootia32.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #452):

sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.8
sys/arch/i386/stand/efiboot/boot.c: revision 1.23
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.10
sys/arch/i386/stand/efiboot/devopen.c: revision 1.14
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.10

x86/efiboot: Nix trailing whitespace.

whitespace -> tab, blank line, no binary changes.

``int i'' is used only for SUPPORT_NFS || SUPPORT_TFTP.


To generate a diff of this commit:
cvs rdiff -u -r1.21.4.1 -r1.21.4.2 src/sys/arch/i386/stand/efiboot/boot.c
cvs rdiff -u -r1.13 -r1.13.4.1 src/sys/arch/i386/stand/efiboot/devopen.c
cvs rdiff -u -r1.9 -r1.9.26.1 src/sys/arch/i386/stand/efiboot/efidisk.c \
src/sys/arch/i386/stand/efiboot/efimemory.c
cvs rdiff -u -r1.5.26.1 -r1.5.26.2 \
src/sys/arch/i386/stand/efiboot/bootia32/efibootia32.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/i386/stand/efiboot/boot.c
diff -u src/sys/arch/i386/stand/efiboot/boot.c:1.21.4.1 src/sys/arch/i386/stand/efiboot/boot.c:1.21.4.2
--- src/sys/arch/i386/stand/efiboot/boot.c:1.21.4.1	Sat May 13 13:26:56 2023
+++ src/sys/arch/i386/stand/efiboot/boot.c	Fri Nov  3 10:01:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.21.4.1 2023/05/13 13:26:56 martin Exp $	*/
+/*	$NetBSD: boot.c,v 1.21.4.2 2023/11/03 10:01:13 martin Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -483,7 +483,7 @@ command_dev(char *arg)
 	if (*arg == '\0') {
 		efi_disk_show();
 		efi_net_show();
-	
+
 		if (default_part_name != NULL)
 			printf("default NAME=%s\n", default_part_name);
 		else
@@ -647,7 +647,7 @@ void
 command_reloc(char *arg)
 {
 	char *ep;
-	
+
 	if (*arg == '\0') {
 		switch (efi_reloc_type) {
 		case RELOC_NONE:

Index: src/sys/arch/i386/stand/efiboot/devopen.c
diff -u src/sys/arch/i386/stand/efiboot/devopen.c:1.13 src/sys/arch/i386/stand/efiboot/devopen.c:1.13.4.1
--- src/sys/arch/i386/stand/efiboot/devopen.c:1.13	Mon Dec 27 12:19:27 2021
+++ src/sys/arch/i386/stand/efiboot/devopen.c	Fri Nov  3 10:01:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: devopen.c,v 1.13 2021/12/27 12:19:27 simonb Exp $	 */
+/*	$NetBSD: devopen.c,v 1.13.4.1 2023/11/03 10:01:13 martin Exp $	 */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -154,13 +154,13 @@ devopen(struct open_file *f, const char 
 	const char *xname = NULL;
 	int unit, partition;
 	int biosdev;
-	int i, error;
+	int error;
 #if defined(SUPPORT_NFS) || defined(SUPPORT_TFTP)
 	struct devdesc desc;
 	const struct netboot_fstab *nf;
 	char *filename;
 	size_t fsnamelen;
-	int n;
+	int i, n;
 #endif
 
 	error = parsebootfile(fname, , , , ,

Index: src/sys/arch/i386/stand/efiboot/efidisk.c
diff -u src/sys/arch/i386/stand/efiboot/efidisk.c:1.9 src/sys/arch/i386/stand/efiboot/efidisk.c:1.9.26.1
--- src/sys/arch/i386/stand/efiboot/efidisk.c:1.9	Tue Dec 17 01:37:52 2019
+++ src/sys/arch/i386/stand/efiboot/efidisk.c	Fri Nov  3 10:01:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: efidisk.c,v 1.9 2019/12/17 01:37:52 manu Exp $	*/
+/*	$NetBSD: efidisk.c,v 1.9.26.1 2023/11/03 10:01:13 martin Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -70,9 +70,9 @@ dealloc_biosdisk_part(struct biosdisk_pa
 			part[i].part_name = NULL;
 		}
 	}
-	
+
 	dealloc(part, sizeof(*part) * nparts);
-	
+
 	return;
 }
 
@@ -194,7 +194,6 @@ efi_raidframe_probe(struct efi_raidframe
 	return;
 }
 
-
 void
 efi_disk_show(void)
 {
@@ -293,7 +292,7 @@ efi_disk_show(void)
 		raidframe[i].size,
 		, ))
 			continue;
-			
+
 		first = 1;
 		for (j = 0; j < nparts; j++) {
 			bool bootme = part[j].attr & GPT_ENT_ATTR_BOOTME;
Index: src/sys/arch/i386/stand/efiboot/efimemory.c
diff -u src/sys/arch/i386/stand/efiboot/efimemory.c:1.9 src/sys/arch/i386/stand/efiboot/efimemory.c:1.9.26.1
--- src/sys/arch/i386/stand/efiboot/efimemory.c:1.9	Fri Sep 13 02:19:45 2019
+++ src/sys/arch/i386/stand/efiboot/efimemory.c	Fri Nov  3 10:01:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: efimemory.c,v 1.9 2019/09/13 02:19:45 manu Exp $	*/
+/*	$NetBSD: efimemory.c,v 1.9.26.1 2023/11/03 10:01:13 martin Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -221,7 +221,7 @@ efi_memory_get_memmap(struct bi_memmap_e
 
 		next = NextMemoryDescriptor(md, DescriptorSize);
 	}
-	
+
 	*memmapp = memmap;
 	*num = NoEntries;
 	return 0;

Index: src/sys/arch/i386/stand/efiboot/bootia32/efibootia32.c
diff -u src/sys/arch/i386/stand/efiboot/bootia32/efibootia32.c:1.5.26.1 

CVS commit: [netbsd-10] src/sys/arch/i386/stand/efiboot

2023-11-03 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Nov  3 10:01:13 UTC 2023

Modified Files:
src/sys/arch/i386/stand/efiboot [netbsd-10]: boot.c devopen.c efidisk.c
efimemory.c
src/sys/arch/i386/stand/efiboot/bootia32 [netbsd-10]: efibootia32.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #452):

sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.8
sys/arch/i386/stand/efiboot/boot.c: revision 1.23
sys/arch/i386/stand/efiboot/efidisk.c: revision 1.10
sys/arch/i386/stand/efiboot/devopen.c: revision 1.14
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.10

x86/efiboot: Nix trailing whitespace.

whitespace -> tab, blank line, no binary changes.

``int i'' is used only for SUPPORT_NFS || SUPPORT_TFTP.


To generate a diff of this commit:
cvs rdiff -u -r1.21.4.1 -r1.21.4.2 src/sys/arch/i386/stand/efiboot/boot.c
cvs rdiff -u -r1.13 -r1.13.4.1 src/sys/arch/i386/stand/efiboot/devopen.c
cvs rdiff -u -r1.9 -r1.9.26.1 src/sys/arch/i386/stand/efiboot/efidisk.c \
src/sys/arch/i386/stand/efiboot/efimemory.c
cvs rdiff -u -r1.5.26.1 -r1.5.26.2 \
src/sys/arch/i386/stand/efiboot/bootia32/efibootia32.c

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



CVS commit: [netbsd-10] src/sys/arch/i386/stand/efiboot

2023-09-11 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Sep 11 13:25:42 UTC 2023

Modified Files:
src/sys/arch/i386/stand/efiboot [netbsd-10]: Makefile.efiboot eficons.c
Added Files:
src/sys/arch/i386/stand/efiboot [netbsd-10]: eficpufunc.c eficpufunc.h

Log Message:
Pull up following revision(s) (requested by rin in ticket #361):

sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.22
sys/arch/i386/stand/efiboot/eficpufunc.c: revision 1.1
sys/arch/i386/stand/efiboot/eficpufunc.h: revision 1.1
sys/arch/i386/stand/efiboot/eficons.c: revision 1.13

efiboot/x86: Add serial console support via raw I/O port access

Unfortunately, some (most?) UEFI implementations do not support
com ports by ``Serial I/O Protocol''.
``PNP0501-0'' and friends are not recognized also.

In this case, if user explicitly requires to switch to serial
console by ``consdev'' command, try to use raw I/O port access.

Ugly, but what FreeBSD does, at least.
Proposed as PR port-amd64/57523


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.19.4.1 \
src/sys/arch/i386/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.12 -r1.12.4.1 src/sys/arch/i386/stand/efiboot/eficons.c
cvs rdiff -u -r0 -r1.1.2.2 src/sys/arch/i386/stand/efiboot/eficpufunc.c \
src/sys/arch/i386/stand/efiboot/eficpufunc.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/i386/stand/efiboot/Makefile.efiboot
diff -u src/sys/arch/i386/stand/efiboot/Makefile.efiboot:1.19 src/sys/arch/i386/stand/efiboot/Makefile.efiboot:1.19.4.1
--- src/sys/arch/i386/stand/efiboot/Makefile.efiboot:1.19	Thu Nov 18 16:17:40 2021
+++ src/sys/arch/i386/stand/efiboot/Makefile.efiboot	Mon Sep 11 13:25:42 2023
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.19 2021/11/18 16:17:40 manu Exp $
+# $NetBSD: Makefile.efiboot,v 1.19.4.1 2023/09/11 13:25:42 martin Exp $
 
 S=		${.CURDIR}/../../../../..
 
@@ -14,9 +14,11 @@ AFLAGS.start.S= ${${ACTIVE_CC} == "clang
 
 SOURCES= start.S boot.c conf.c devopen.c dev_net.c self_reloc.c panic.c
 SOURCES+= efiboot.c efichar.c eficons.c efidelay.c efidev.c
+SOURCES+= eficpufunc.c
 SOURCES+= efidisk.c efidisk_ll.c efigetsecs.c efimemory.c
 SOURCES+= efinet.c efipxe.c
 LIBI386SRCS= biosdisk.c bootinfo.c bootinfo_biosgeom.c bootmenu.c
+LIBI386SRCS+= comio_direct.c
 LIBI386SRCS+= diskbuf.c exec.c menuutils.c parseutils.c pread.c
 LIBI386SRCS+= exec_multiboot1.c exec_multiboot2.c
 # use our own nfs implementation

Index: src/sys/arch/i386/stand/efiboot/eficons.c
diff -u src/sys/arch/i386/stand/efiboot/eficons.c:1.12 src/sys/arch/i386/stand/efiboot/eficons.c:1.12.4.1
--- src/sys/arch/i386/stand/efiboot/eficons.c:1.12	Thu Oct 28 06:13:13 2021
+++ src/sys/arch/i386/stand/efiboot/eficons.c	Mon Sep 11 13:25:42 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: eficons.c,v 1.12 2021/10/28 06:13:13 kim Exp $	*/
+/*	$NetBSD: eficons.c,v 1.12.4.1 2023/09/11 13:25:42 martin Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -29,6 +29,8 @@
 #include 
 #include 
 
+#include 
+
 #include "efiboot.h"
 
 #include "bootinfo.h"
@@ -60,6 +62,8 @@ static u_char serbuf[16];
 static int serbuf_read = 0;
 static int serbuf_write = 0;
 
+static int raw_com_addr = 0;
+
 static void eficons_init_video(void);
 static void efi_switch_video_to_text_mode(void);
 
@@ -76,6 +80,12 @@ static int efi_com_putc(int);
 static int efi_com_status(int);
 static int efi_com_waitforinputevent(uint64_t);
 
+static int raw_com_init(int, int);
+static int raw_com_getc(void);
+static int raw_com_putc(int);
+static int raw_com_status(int);
+static int raw_com_waitforinputevent(uint64_t);
+
 static int efi_find_gop_mode(char *);
 
 static int iodev;
@@ -134,11 +144,8 @@ ok:
 	case CONSDEV_COM3:
 		iodev = dev;
 		btinfo_console.addr = ioport;
-		if (btinfo_console.addr == 0) {
-			if (!efi_valid_com(iodev))
-goto nocom;
+		if (btinfo_console.addr == 0)
 			btinfo_console.addr = getcomaddr(iodev - CONSDEV_COM0);
-		}
 		if (speed != 0)
 			btinfo_console.speed = speed;
 		efi_com_init(btinfo_console.addr, btinfo_console.speed);
@@ -149,8 +156,6 @@ ok:
 	case CONSDEV_COM2KBD:
 	case CONSDEV_COM3KBD:
 		iodev = dev - CONSDEV_COM0KBD + CONSDEV_COM0;
-		if (!efi_valid_com(iodev))
-			goto nocom;
 		btinfo_console.addr = getcomaddr(iodev - CONSDEV_COM0);
 
 		efi_cons_putc('0' + iodev - CONSDEV_COM0);
@@ -869,7 +874,7 @@ efi_com_init(int addr, int speed)
 		return 0;
 
 	if (!efi_valid_com(iodev))
-		return 0;
+		return raw_com_init(addr, speed);
 
 	serio = serios[iodev - CONSDEV_COM0];
 
@@ -885,6 +890,7 @@ efi_com_init(int addr, int speed)
 		}
 	}
 
+	raw_com_addr = 0;
 	default_comspeed = speed;
 	internal_getchar = efi_com_getc;
 	internal_putchar = efi_com_putc;
@@ -1019,3 +1025,65 @@ efi_com_waitforinputevent(uint64_t timeo
 		return ETIMEDOUT;
 	return EINVAL;
 }
+
+static int
+raw_com_init(int addr, int speed)
+{
+
+	if (addr == 0 || speed <= 0)
+		

CVS commit: [netbsd-10] src/sys/arch/i386/stand/efiboot

2023-09-11 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Sep 11 13:25:42 UTC 2023

Modified Files:
src/sys/arch/i386/stand/efiboot [netbsd-10]: Makefile.efiboot eficons.c
Added Files:
src/sys/arch/i386/stand/efiboot [netbsd-10]: eficpufunc.c eficpufunc.h

Log Message:
Pull up following revision(s) (requested by rin in ticket #361):

sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.22
sys/arch/i386/stand/efiboot/eficpufunc.c: revision 1.1
sys/arch/i386/stand/efiboot/eficpufunc.h: revision 1.1
sys/arch/i386/stand/efiboot/eficons.c: revision 1.13

efiboot/x86: Add serial console support via raw I/O port access

Unfortunately, some (most?) UEFI implementations do not support
com ports by ``Serial I/O Protocol''.
``PNP0501-0'' and friends are not recognized also.

In this case, if user explicitly requires to switch to serial
console by ``consdev'' command, try to use raw I/O port access.

Ugly, but what FreeBSD does, at least.
Proposed as PR port-amd64/57523


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.19.4.1 \
src/sys/arch/i386/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.12 -r1.12.4.1 src/sys/arch/i386/stand/efiboot/eficons.c
cvs rdiff -u -r0 -r1.1.2.2 src/sys/arch/i386/stand/efiboot/eficpufunc.c \
src/sys/arch/i386/stand/efiboot/eficpufunc.h

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



CVS commit: [netbsd-10] src/sys/arch/i386/stand/bootxx

2023-06-30 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jun 30 17:20:28 UTC 2023

Modified Files:
src/sys/arch/i386/stand/bootxx [netbsd-10]: boot1.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #222):

sys/arch/i386/stand/bootxx/boot1.c: revision 1.22

Primary bootstrap is now able to read a GPT inside RAIDframe.

Previously, primary bootstrap was able to boot on RAID-1 RAIDframe set
with the limitation that the FFS filesystem had to start at bloc 0 in the
RAID. That allowed inner RAID partitionning with a disklabel, but not with
a GPT.

When booting on a RAID-1 RAIDframe, primary bootstrap now first try a
filesystem at bloc 0 of the RAID as before. On failure, it tries to
read a GPT and load secondary bootstrap from, by priority;
1) the first partition with the bootme attribute set
2) the first partition of type FFS, LFS, CCD or CGD
3) the first partition present in the GPT


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.21.10.1 src/sys/arch/i386/stand/bootxx/boot1.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/i386/stand/bootxx/boot1.c
diff -u src/sys/arch/i386/stand/bootxx/boot1.c:1.21 src/sys/arch/i386/stand/bootxx/boot1.c:1.21.10.1
--- src/sys/arch/i386/stand/bootxx/boot1.c:1.21	Thu Jun 24 01:23:16 2021
+++ src/sys/arch/i386/stand/bootxx/boot1.c	Fri Jun 30 17:20:28 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot1.c,v 1.21 2021/06/24 01:23:16 gutteridge Exp $	*/
+/*	$NetBSD: boot1.c,v 1.21.10.1 2023/06/30 17:20:28 martin Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -30,15 +30,17 @@
  */
 
 #include 
-__RCSID("$NetBSD: boot1.c,v 1.21 2021/06/24 01:23:16 gutteridge Exp $");
+__RCSID("$NetBSD: boot1.c,v 1.21.10.1 2023/06/30 17:20:28 martin Exp $");
 
 #include 
 #include 
 #include 
 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 	/* For RF_PROTECTED_SECTORS */
 
 #define XSTR(x) #x
@@ -49,6 +51,9 @@ static daddr_t bios_sector;
 static struct biosdisk_ll d;
 
 const char *boot1(uint32_t, uint64_t *);
+#ifndef NO_GPT
+static daddr_t gpt_lookup(daddr_t);
+#endif
 extern void putstr(const char *);
 
 extern struct disklabel ptn_disklabel;
@@ -90,6 +95,17 @@ boot1(uint32_t biosdev, uint64_t *sector
 	fd = ob();
 	if (fd != -1)
 		goto done;
+
+#ifndef NO_GPT
+	/*
+	 * Test for a GPT inside the RAID
+	 */
+	bios_sector += gpt_lookup(bios_sector);
+	fd = ob();
+	if (fd != -1)
+		goto done;
+#endif
+
 	/*
 	 * Nothing at the start of the MBR partition, fallback on
 	 * partition 'a' from the disklabel in this MBR partition.
@@ -144,3 +160,146 @@ blkdevstrategy(void *devdata, int flag, 
 
 	return 0;
 }
+
+#ifndef NO_GPT
+static int
+is_unused(struct gpt_ent *ent)
+{
+	const struct uuid unused = GPT_ENT_TYPE_UNUSED;
+
+	return (memcmp(ent->ent_type, , sizeof(unused)) == 0);
+}
+
+static int
+is_bootable(struct gpt_ent *ent)
+{
+	/* GPT_ENT_TYPE_NETBSD_RAID omitted as we are already in a RAID */
+	const struct uuid bootable[] = {
+		GPT_ENT_TYPE_NETBSD_FFS,
+		GPT_ENT_TYPE_NETBSD_LFS,
+		GPT_ENT_TYPE_NETBSD_CCD,
+		GPT_ENT_TYPE_NETBSD_CGD,
+	};
+	int i;
+
+	for (i = 0; i < sizeof(bootable) / sizeof(*bootable); i++) {
+		if (memcmp(ent->ent_type, [i],
+		sizeof(struct uuid)) == 0)
+			return 1;
+	}
+
+	return 0;
+}
+
+static daddr_t
+gpt_lookup(daddr_t sector)
+{
+	char buf[BIOSDISK_DEFAULT_SECSIZE];
+	struct mbr_sector *pmbr;	
+	const char gpt_hdr_sig[] = GPT_HDR_SIG;
+	struct gpt_hdr *hdr;
+	struct gpt_ent *ent;
+	uint32_t nents;
+	uint32_t entsz;
+	uint32_t entries_per_sector;
+	uint32_t sectors_per_entry;
+	uint64_t firstpart_lba = 0;
+	uint64_t bootable_lba = 0;
+	uint64_t bootme_lba = 0;
+	int i, j;
+
+	/*
+	 * Look for a PMBR
+	 */
+	if (readsects(, sector, 1, buf, 1) != 0)
+		return 0;
+
+	pmbr = (struct mbr_sector *)buf;
+
+	if (pmbr->mbr_magic != htole16(MBR_MAGIC))
+		return 0;
+
+	if (pmbr->mbr_parts[0].mbrp_type != MBR_PTYPE_PMBR)
+		return 0;
+
+	sector++; /* skip PMBR */
+
+	/*
+	 * Look for a GPT header
+	 * Space is scarce, we do not check CRC.
+	 */
+	if (readsects(, sector, 1, buf, 1) != 0)
+		return 0;
+
+	hdr = (struct gpt_hdr *)buf;
+
+	if (memcmp(gpt_hdr_sig, hdr->hdr_sig, sizeof(hdr->hdr_sig)) != 0)
+		return 0;
+
+	if (hdr->hdr_revision != htole32(GPT_HDR_REVISION))
+		return 0;
+
+	if (le32toh(hdr->hdr_size) > BIOSDISK_DEFAULT_SECSIZE)
+		return 0;
+
+	nents = le32toh(hdr->hdr_entries);
+	entsz = le32toh(hdr->hdr_entsz);
+
+	sector++; /* skip GPT header */
+
+	/*
+	 * Read partition table
+	 *
+	 * According to UEFI specification section 5.3.2, entries
+	 * are 128 * (2^n) bytes long. The most common scenario is
+	 * 128 bytes (n = 0) where there are 4 entries per sector.
+	 * If n > 2, then entries spans multiple sectors, but they
+	 * remain sector-aligned.
+	 */
+	entries_per_sector = BIOSDISK_DEFAULT_SECSIZE / entsz;
+	if (entries_per_sector == 0)
+		entries_per_sector = 1;
+
+	

CVS commit: [netbsd-10] src/sys/arch/i386/stand/bootxx

2023-06-30 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jun 30 17:20:28 UTC 2023

Modified Files:
src/sys/arch/i386/stand/bootxx [netbsd-10]: boot1.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #222):

sys/arch/i386/stand/bootxx/boot1.c: revision 1.22

Primary bootstrap is now able to read a GPT inside RAIDframe.

Previously, primary bootstrap was able to boot on RAID-1 RAIDframe set
with the limitation that the FFS filesystem had to start at bloc 0 in the
RAID. That allowed inner RAID partitionning with a disklabel, but not with
a GPT.

When booting on a RAID-1 RAIDframe, primary bootstrap now first try a
filesystem at bloc 0 of the RAID as before. On failure, it tries to
read a GPT and load secondary bootstrap from, by priority;
1) the first partition with the bootme attribute set
2) the first partition of type FFS, LFS, CCD or CGD
3) the first partition present in the GPT


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.21.10.1 src/sys/arch/i386/stand/bootxx/boot1.c

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