1# $NetBSD: Makefile.bootprogs,v 1.6 2022/05/28 22:16:43 andvar Exp $
2
3NOSSP=yes
4NOPIE=yes
5
6.include <bsd.own.mk>
7.include <bsd.klinks.mk>
8
9S=	${.CURDIR}/../../../../..
10COMMON=	${.CURDIR}/../common
11
12.PATH:	${COMMON}
13
14.if ${MACHINE_ARCH:M*64*}
15.	if ${MACHINE_ARCH:M*eb}
16LDABI=	-melf32btsmipn32
17.	else
18LDABI=	-melf32ltsmipn32
19.	endif
20CPUFLAGS+=	-mabi=n32
21.endif
22
23STRIPFLAG=
24BINMODE= 444
25
26# XXX SHOULD NOT NEED TO DEFINE THESE!
27LIBCRT0=
28LIBCRTI=
29LIBC=
30LIBCRTBEGIN=
31LIBCRTEND=
32
33STRIP?=	strip
34
35CHECKSIZE_CMD=	SIZE=${SIZE} ${HOST_SH} ${COMMON}/checksize.sh
36
37AFLAGS+=	-DASSEMBLER -D_LOCORE -mno-abicalls -mips64 -msoft-float
38# -I${.CURDIR}/../.. done by Makefile.inc
39CPPFLAGS+=	-nostdinc -I${.OBJDIR} -D_STANDALONE -I${S}
40CFLAGS=		-Os -g -ffreestanding -mno-abicalls -msoft-float -G 0
41CFLAGS+=	-mips64
42CFLAGS+=	-Werror ${CWARNFLAGS}
43
44NETBSD_VERS!=${HOST_SH} ${S}/conf/osrelease.sh
45CPPFLAGS+= -DNETBSD_VERS='"${NETBSD_VERS}"'
46
47CWARNFLAGS+=	-Wno-main
48CWARNFLAGS+=	-Wall -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith
49CWARNFLAGS+=	-Wno-pointer-sign
50
51VERSIONFLAGS+=-n
52.include "${S}/conf/newvers_stand.mk"
53
54#
55# Refer to CFE documentation for a description of these regions.
56#
57
58REGION1_START=		0x20000000		# "Region 1 start"
59REGION1_SIZE!=		expr 256 \* 1024	# 256k
60
61LDSCRIPT=		${COMMON}/boot.ldscript
62
63# our memory lauout:
64
65#	'unified' boot loaders (e.g. netboot) can consume all of region
66#	1 for their text+data, or text+data+bss.
67
68UNIFIED_LOAD_ADDRESS=	${REGION1_START}
69UNIFIED_MAX_LOAD!=	expr ${REGION1_SIZE}
70UNIFIED_MAX_TOTAL!=	expr ${REGION1_SIZE}
71
72#UNIFIED_HEAP_START=	right after secondary bss
73UNIFIED_HEAP_LIMIT=	(${REGION1_START} + ${REGION1_SIZE})
74
75#	two-stage boot loaders must share region 1.  The first stage
76#	loads into the lowest portion, and uses the highest portion
77#	for its heap.  The second stage loads in between the primary image
78#	and the heap, and can reuse the memory after it (i.e. the primary's
79#	heap) for its own heap.
80
81PRIMARY_LOAD_ADDRESS=	${REGION1_START}
82#PRIMARY_MAX_LOAD=	booter dependent, no more than ${PRIMARY_MAX_TOTAL}
83PRIMARY_MAX_TOTAL!=	expr 16 \* 1024
84
85# XXX SECONDARY_LOAD_ADDRESS should be
86# XXX (${PRIMARY_LOAD_ADDRESS} + ${PRIMARY_MAX_TOTAL}) bt there's no easy
87# XXX way to do that calculation and 'ld' wants a single number.
88SECONDARY_LOAD_ADDRESS=	0x20004000	# XXX
89SECONDARY_MAX_LOAD!=	expr 112 \* 1024
90SECONDARY_MAX_TOTAL!=	expr ${REGION1_SIZE} - ${PRIMARY_MAX_TOTAL}
91
92PRIMARY_HEAP_START=	(${SECONDARY_LOAD_ADDRESS} + ${SECONDARY_MAX_LOAD})
93PRIMARY_HEAP_LIMIT=	(${REGION1_START} + ${REGION1_SIZE})
94
95#SECONDARY_HEAP_START=	right after secondary bss
96SECONDARY_HEAP_LIMIT=	(${REGION1_START} + ${REGION1_SIZE})
97
98#	standalone programs are like kernels.  They load at
99#	0xfffffc0000300000 and can use the rest of memory.
100
101STANDPROG_LOAD_ADDRESS=	0xfffffc0000300000
102
103
104FILE_FORMAT_CPPFLAGS=	-DBOOT_ELF
105
106UNIFIED_CPPFLAGS=	-DUNIFIED_BOOTBLOCK \
107			-DHEAP_LIMIT="${UNIFIED_HEAP_LIMIT}" \
108			${FILE_FORMAT_CPPFLAGS}
109
110PRIMARY_CPPFLAGS=	-DPRIMARY_BOOTBLOCK \
111			-DSECONDARY_LOAD_ADDRESS="${SECONDARY_LOAD_ADDRESS}" \
112			-DSECONDARY_MAX_LOAD="${SECONDARY_MAX_LOAD}" \
113			-DHEAP_LIMIT="${PRIMARY_HEAP_LIMIT}" \
114			-DHEAP_START="${PRIMARY_HEAP_START}"
115
116SECONDARY_CPPFLAGS=	-DSECONDARY_BOOTBLOCK \
117			-DHEAP_LIMIT="${SECONDARY_HEAP_LIMIT}" \
118			${FILE_FORMAT_CPPFLAGS}
119
120STANDPROG_CPPFLAGS=	-DSTANDALONE_PROGRAM
121
122.include <bsd.prog.mk>
123
124### find out what to use for libkern
125KERN_AS=	library
126.include "${S}/lib/libkern/Makefile.inc"
127LIBKERN=	${KERNLIB}
128
129### find out what to use for libz
130Z_AS=		library
131.include "${S}/lib/libz/Makefile.inc"
132LIBZ=		${ZLIB}
133
134### find out what to use for libsa
135SA_AS=		library
136SAMISCMAKEFLAGS+="SA_USE_LOADFILE=yes"
137.include "${S}/lib/libsa/Makefile.inc"
138LIBSA=		${SALIB}
139
140/usr/lib/crt0.o:
141	true
142
143/usr/lib/crtbegin.o:
144	true
145
146/usr/lib/crtend.o:
147	true
148
149cleandir: .WAIT cleandirlocal
150cleandirlocal:
151	-rm -rf lib
152