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 0x0000;
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 <bsd.init.mk>
 
 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 src/sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile:1.3 src/sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile:1.3.94.1
--- src/sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile:1.3	Wed Nov 18 21:02:16 2009
+++ src/sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile	Thu Dec 14 17:56:08 2023
@@ -1,7 +1,11 @@
-# $NetBSD: Makefile,v 1.3 2009/11/18 21:02:16 dsl Exp $
+# $NetBSD: Makefile,v 1.3.94.1 2023/12/14 17:56:08 martin Exp $
+
+NOMAN=yes
+.include <bsd.init.mk>
 
 FS=ustarfs
 
 BOOTXX_SECTORS=16
 
 .include <../Makefile.bootxx>
+OPT_SIZE.clang += -Oz

Index: src/sys/arch/i386/stand/dosboot/Makefile
diff -u src/sys/arch/i386/stand/dosboot/Makefile:1.33 src/sys/arch/i386/stand/dosboot/Makefile:1.33.26.1
--- src/sys/arch/i386/stand/dosboot/Makefile:1.33	Mon Sep 23 13:42:36 2019
+++ src/sys/arch/i386/stand/dosboot/Makefile	Thu Dec 14 17:56:08 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.33 2019/09/23 13:42:36 christos Exp $
+#	$NetBSD: Makefile,v 1.33.26.1 2023/12/14 17:56:08 martin Exp $
 
 S=	${.CURDIR}/../../../..
 
@@ -31,6 +31,12 @@ SAMISCCPPFLAGS+= -DHEAP_START=0x20000 -D
 SAMISCMAKEFLAGS= SA_USE_CREAD=yes SA_INCLUDE_NET=no SA_ENABLE_LS_OP=yes
 I386MISCMAKEFLAGS= I386_INCLUDE_DOS=yes
 
+# DOS command line arguments are located at 0x0000.
+COPTS.doscommain.c+= -fno-delete-null-pointer-checks
+
+# Do not page-align data segment.
+LDFLAGS+= -Wl,-N
+
 VERSIONFILE= ${.CURDIR}/version
 
 .include <bsd.init.mk>

Reply via email to