xref: /freebsd/stand/i386/loader/Makefile (revision 2982c70852395fad40959072ed90c8676a4b9a1c)
1HAVE_ZFS=		${MK_LOADER_ZFS}
2
3LOADER_NET_SUPPORT?=	yes
4LOADER_NFS_SUPPORT?=	yes
5LOADER_TFTP_SUPPORT?=	yes
6LOADER_CD9660_SUPPORT?=	yes
7LOADER_EXT2FS_SUPPORT?=	no
8LOADER_MSDOS_SUPPORT?=	no
9LOADER_UFS_SUPPORT?=	yes
10LOADER_GZIP_SUPPORT?=	yes
11LOADER_BZIP2_SUPPORT?=	yes
12
13.include <bsd.init.mk>
14
15LOADER?=	loader_${LOADER_INTERP}
16PROG=		${LOADER}.sym
17INTERNALPROG=
18NEWVERSWHAT?=	"bootstrap loader" x86
19VERSION_FILE?=	${.CURDIR}/../loader/version
20#
21# There's 640k - 40k maximum space, less however much memory the BIOS uses.  A
22# non-random survey suggests that 20k-25k is a good value for 'most' machines.
23# We also need to subtract maximum stack usage (20-25k).
24#
25# So 640k - 40k - 25k - 25k = 550k = 563,200 bytes, but use 560,000 below for
26# some extra buffer for more complex setups and/or wider BIOS lomem variation.
27#
28# Some systems use more stack or have BIOS reserve more RAM (or both), and will
29# need to set this lower in /etc/src.conf if the above buffer is too small.
30#
31# sudo dd if=/dev/mem bs=1 iseek=0x413 count=2 | hd -d
32#
33# will tell you how many kiB of lomem are available.
34#
35# We further reduce this to 500k, though, to give PXE an additional 64k of space
36# so pxeloader will fit. If you have special needs that do not include pxeboot,
37# you can safely set this as high as 560000 generally, or a bit higher if you
38# have tight control over the machines you are booting on.
39#
40LOADERSIZE?=	500000		# Largest known safe size for loader.bin
41
42.PATH:		${BOOTSRC}/i386/loader
43
44# architecture-specific loader code
45SRCS+=		chain.c
46SRCS+=		conf.c
47SRCS+=		gfx_bios.c
48SRCS+=		main.c
49SRCS+=		vers.c
50
51.if ${MK_LOADER_BIOS_TEXTONLY} == "no"
52SRCS+=		gfx_fb.c
53SRCS+=		8x16.c
54
55CFLAGS.gfx_fb.c += -I${.CURDIR}/../libi386
56CFLAGS.gfx_fb.c += -I$(SRCTOP)/sys/teken
57CFLAGS.gfx_fb.c += -I${SRCTOP}/sys/cddl/contrib/opensolaris/common/lz4
58CFLAGS.gfx_fb.c += -I${SRCTOP}/contrib/pnglite
59CFLAGS.gfx_fb.c += -DHAVE_MEMCPY -I${SRCTOP}/sys/contrib/zlib
60CFLAGS.gfx_bios.c += -I$(SRCTOP)/sys/teken
61CFLAGS.gfx_bios.c += -I${SRCTOP}/contrib/pnglite
62.else
63CFLAGS.gfx_bios.c += -DBIOS_TEXT_ONLY
64CFLAGS.conf.c	+= -DBIOS_TEXT_ONLY
65.endif
66
67# Include bcache code.
68HAVE_BCACHE=	yes
69
70# Enable PnP and ISA-PnP code.
71HAVE_PNP=	yes
72HAVE_ISABUS=	yes
73
74.if ${MK_LOADER_ZFS} == "yes"
75CFLAGS.main.c+=	-I${SYSDIR}/contrib/openzfs/include
76CFLAGS.main.c+=	-I${SYSDIR}/contrib/openzfs/include/os/freebsd/zfs
77.endif
78
79.if exists(${.CURDIR}/help.i386)
80HELP_FILES=	${.CURDIR}/help.i386
81.endif
82HELP_FILENAME=	loader.help.bios
83
84# Always add MI sources
85.include	"${BOOTSRC}/loader.mk"
86
87CLEANFILES+=	${LOADER} ${LOADER}.bin 8x16.c
88
89ORG=		0x0
90
91CFLAGS+=	-Wall
92LDFLAGS+=	-static ${LDFLAGS_ORG} -Wl,--gc-sections
93.if (${LINKER_TYPE} == "lld" && ${LINKER_VERSION} >= 130000) || \
94    (${LINKER_TYPE} == "bfd" && ${LINKER_VERSION} >= 23700)
95# lld 13 and higher default to garbage collecting start/stop symbols,
96# completely ruining our linker sets. For now, work around it by
97# disabling this un-feature.
98LDFLAGS+=	-Wl,-z,nostart-stop-gc
99.endif
100
101# i386 standalone support library
102LIBI386=	${BOOTOBJ}/i386/libi386/libi386.a
103CFLAGS+=	-I${BOOTSRC}/i386
104
105# Debug me!
106#CFLAGS+=	-g
107#LDFLAGS+=	-g
108
1098x16.c: ${SRCTOP}/contrib/terminus/ter-u16b.bdf
110	vtfontcvt -f compressed-source -o ${.TARGET} ${.ALLSRC}
111
112
113${LOADER}: ${LOADER}.bin ${BTXLDR} ${BTXKERN}
114	btxld -v -f aout -e ${LOADER_ADDRESS} -o ${.TARGET} -l ${BTXLDR} \
115		-b ${BTXKERN} ${LOADER}.bin
116
117${LOADER}.bin: ${LOADER}.sym
118	${STRIPBIN} -R .comment -R .note -o ${.TARGET} ${.ALLSRC}
119	@set -- `ls -l ${.TARGET}` ; x=$$((${LOADERSIZE}-$$5)); \
120	    echo "$$x bytes available"; test $$x -ge 0
121
122.if ${MK_LOADER_ZFS} == "yes" && ${LOADER_INTERP} == ${LOADER_DEFAULT_INTERP}
123LINKS+=		${BINDIR}/${LOADER} ${BINDIR}/zfsloader
124.endif
125.if ${LOADER_INTERP} == ${LOADER_DEFAULT_INTERP}
126LINKS+=		${BINDIR}/${LOADER} ${BINDIR}/loader
127.endif
128FILES+=	${LOADER}
129FILESMODE_${LOADER}= ${BINMODE} -b
130
131# Note: crt0.o needs to be first for pxeboot(8) to work. It assumes that the
132# startup code is located at the start of the loader and will jump
133# there. Although btx is more flexible than this, the emulated boot2 environment
134# that pxeldr provides has none of that flexibility and assumes the entry point
135# is 0. Finally, both pxeldr and cdboot assume they are loading an a.out file.
136#
137# We must add it to the LDFLAGS instead of the OBJS because the former won't try
138# to clean it. When it is in OBJS, this cleaning can lead to races where
139# btxcrt.o is rebuilt, but boot2 isn't, leading to errors at installation time.
140# LDFLAGS does not have this baggage and will be included first in the list of
141# files.
142LDFLAGS+=	${BTXCRT}
143
144# Force the linker max page size to 4k so that we fit in the limited space even
145# if someone has set a larger default linker max page size via /etc/src.conf.
146LDFLAGS+= -Wl,-z,max-page-size=0x1000
147
148DPADD=	${LDR_INTERP32} ${LIBI386} ${LIBSA32}
149LDADD=	${LDR_INTERP32} ${LIBI386} ${LIBSA32}
150
151.if ${MACHINE_CPUARCH} == "amd64"
152CFLAGS+=	-DLOADER_PREFER_AMD64
153.endif
154
155.include <bsd.prog.mk>
156