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