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