1e71ca95cSGerald Jelinek#
2e71ca95cSGerald Jelinek# CDDL HEADER START
3e71ca95cSGerald Jelinek#
4e71ca95cSGerald Jelinek# The contents of this file are subject to the terms of the
5e71ca95cSGerald Jelinek# Common Development and Distribution License (the "License").
6e71ca95cSGerald Jelinek# You may not use this file except in compliance with the License.
7e71ca95cSGerald Jelinek#
8e71ca95cSGerald Jelinek# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9e71ca95cSGerald Jelinek# or http://www.opensolaris.org/os/licensing.
10e71ca95cSGerald Jelinek# See the License for the specific language governing permissions
11e71ca95cSGerald Jelinek# and limitations under the License.
12e71ca95cSGerald Jelinek#
13e71ca95cSGerald Jelinek# When distributing Covered Code, include this CDDL HEADER in each
14e71ca95cSGerald Jelinek# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15e71ca95cSGerald Jelinek# If applicable, add the following below this CDDL HEADER, with the
16e71ca95cSGerald Jelinek# fields enclosed by brackets "[]" replaced with your own identifying
17e71ca95cSGerald Jelinek# information: Portions Copyright [yyyy] [name of copyright owner]
18e71ca95cSGerald Jelinek#
19e71ca95cSGerald Jelinek# CDDL HEADER END
20e71ca95cSGerald Jelinek#
21e71ca95cSGerald Jelinek#
228fd04b83SRoger A. Faulkner# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23e71ca95cSGerald Jelinek# Use is subject to license terms.
24e71ca95cSGerald Jelinek#
25e71ca95cSGerald Jelinek
26e71ca95cSGerald JelinekLIBRARY =	s10_brand.a
27e71ca95cSGerald JelinekVERS =		.1
28*bdf0047cSRoger A. FaulknerCOBJS =		s10_brand.o s10_deleted.o s10_signal.o
29e71ca95cSGerald JelinekASOBJS =	s10_crt.o s10_handler.o s10_runexe.o
30e71ca95cSGerald JelinekOFFSETS_SRC =	../common/offsets.in
31e71ca95cSGerald JelinekOFFSETS_H =	assym.h
32e71ca95cSGerald JelinekOBJECTS =	$(COBJS) $(ASOBJS)
33e71ca95cSGerald JelinekCLOBBERFILES +=	$(OFFSETS_H)
34e71ca95cSGerald Jelinek
35e71ca95cSGerald Jelinekinclude ../../Makefile.s10
36e71ca95cSGerald Jelinekinclude $(SRC)/lib/Makefile.lib
37e71ca95cSGerald Jelinek
38e71ca95cSGerald JelinekSRCDIR =	../common
39e71ca95cSGerald JelinekUTSBASE =	$(SRC)/uts
40e71ca95cSGerald Jelinek
41e71ca95cSGerald JelinekLIBS =		$(DYNLIB)
42e71ca95cSGerald JelinekCSRCS =		$(COBJS:%o=../common/%c)
43e71ca95cSGerald JelinekASSRCS =	$(ASOBJS:%o=$(ISASRCDIR)/%s)
44e71ca95cSGerald JelinekSRCS =		$(CSRCS) $(ASSRCS)
45e71ca95cSGerald Jelinek
46e71ca95cSGerald Jelinek#
47e71ca95cSGerald Jelinek# Ugh, this is a gross hack.  Our assembly routines uses lots of defines
48e71ca95cSGerald Jelinek# to simplify variable access.  All these defines work fine for amd64
49e71ca95cSGerald Jelinek# compiles because when compiling for amd64 we use the GNU assembler,
50e71ca95cSGerald Jelinek# gas.  For 32-bit code we use the Sun assembler, as.  Unfortunatly
51e71ca95cSGerald Jelinek# as does not handle certian constructs that gas does.  So rather than
52e71ca95cSGerald Jelinek# make our code less readable, we'll just use gas to compile our 32-bit
53e71ca95cSGerald Jelinek# code as well.
54e71ca95cSGerald Jelinek#
55e71ca95cSGerald Jelineki386_AS		= $(amd64_AS)
56e71ca95cSGerald Jelinek
57e71ca95cSGerald Jelinek#
58e71ca95cSGerald Jelinek# Note that the architecture specific makefiles MUST update DYNFLAGS to
59e71ca95cSGerald Jelinek# explicitly specify an interpreter for the brand emulation library so that we
60e71ca95cSGerald Jelinek# use /lib/ld.so.1 or /lib/64/ld.so.1, which in a s10 zone is the Solaris 10
61e71ca95cSGerald Jelinek# linker.  This is different from some other brands where the linker that is
62e71ca95cSGerald Jelinek# used is the native system linker (/.SUNWnative/.../ld.so.1).  We have to do
63e71ca95cSGerald Jelinek# this because the linker has a very incestuous relationship with libc and we
64e71ca95cSGerald Jelinek# don't want to use the native linker with the s10 version of libc.  (This may
65e71ca95cSGerald Jelinek# come as a surprise to the reader, but when our library is loaded it get's
66e71ca95cSGerald Jelinek# linked against the s10 version of libc.)  Although the linker interfaces are
67e71ca95cSGerald Jelinek# normally stable, there are examples, such as with the solaris8 brand, where
68e71ca95cSGerald Jelinek# we could not combine the brand's libc with the native linker.  Since we want
69e71ca95cSGerald Jelinek# to run in a known configuration, we use the S10 libc/linker combination.
70e71ca95cSGerald Jelinek#
71e71ca95cSGerald Jelinek# There is one more non-obvious side effect of using the s10 linker that
72e71ca95cSGerald Jelinek# should be mentioned.  Since the linker is used to setup processes before
73e71ca95cSGerald Jelinek# libc is loaded, it makes system calls directly (ie avoiding libc), and
74e71ca95cSGerald Jelinek# it makes these system calls before our library has been initialized.
75e71ca95cSGerald Jelinek# Since our library hasn't been initialized yet, there's no way for us
76e71ca95cSGerald Jelinek# to intercept and emulate any of those system calls.  So if any of those
77e71ca95cSGerald Jelinek# system calls ever change in the native code such that they break the s10
78e71ca95cSGerald Jelinek# linker then we're kinda screwed and will need to re-visit the current
79e71ca95cSGerald Jelinek# solution.  (The likely solution then will probably be to start using the
80e71ca95cSGerald Jelinek# native linker with our brand emulation library.)
81e71ca95cSGerald Jelinek#
82e71ca95cSGerald Jelinek# Note that we make sure to link our brand emulation library
83e71ca95cSGerald Jelinek# libmapmalloc.  This is required because in most cases there will be two
84e71ca95cSGerald Jelinek# copies of libc in the same process and we don't want them to fight over
85e71ca95cSGerald Jelinek# the heap.  So for our brand library we link against libmapmalloc so that
86e71ca95cSGerald Jelinek# if we (our or copy of libc) try to allocate any memory it will be done
87e71ca95cSGerald Jelinek# via mmap() instead of brk().
88e71ca95cSGerald Jelinek#
89e71ca95cSGerald JelinekCPPFLAGS +=	-D_REENTRANT -U_ASM \
90e71ca95cSGerald Jelinek		-I. -I../sys -I$(UTSBASE)/common/brand/solaris10 \
91e71ca95cSGerald Jelinek		-I$(SRC)/uts/common/fs/zfs
92e71ca95cSGerald JelinekCFLAGS +=	$(CCVERBOSE)
93e71ca95cSGerald Jelinek# Needed to handle zfs include files
94e71ca95cSGerald JelinekC99MODE=	-xc99=%all
95e71ca95cSGerald JelinekC99LMODE=	-Xc99=%all
96e71ca95cSGerald JelinekASFLAGS =	-P $(ASFLAGS_$(CURTYPE)) -D_ASM -I. -I../sys
97e71ca95cSGerald JelinekDYNFLAGS +=	$(DYNFLAGS_$(CLASS))
98e71ca95cSGerald JelinekDYNFLAGS +=	$(BLOCAL) $(ZNOVERSION) -Wl,-e_start
99e71ca95cSGerald JelinekLDLIBS +=	-lc -lmapmalloc
100e71ca95cSGerald Jelinek
101e71ca95cSGerald Jelinek.KEEP_STATE:
102e71ca95cSGerald Jelinek
103e71ca95cSGerald Jelinekall: $(LIBS)
104e71ca95cSGerald Jelinek
105e71ca95cSGerald Jelineklint: lintcheck
106e71ca95cSGerald Jelinek
107e71ca95cSGerald Jelinek#
108e71ca95cSGerald Jelinek# build the offset header before trying to compile any files.  (it's included
109e71ca95cSGerald Jelinek# by s10_misc.h, so it's needed for all objects, not just assembly ones.)
110e71ca95cSGerald Jelinek#
111e71ca95cSGerald Jelinek$(OBJECTS:%=pics/%): $(OFFSETS_H)
112e71ca95cSGerald Jelinek$(OFFSETS_H): $(OFFSETS_SRC)
113e71ca95cSGerald Jelinek	$(OFFSETS_CREATE) $(CTF_FLAGS) < $(OFFSETS_SRC) >$@
114e71ca95cSGerald Jelinek
115e71ca95cSGerald Jelinekpics/%.o: $(ISASRCDIR)/%.s
116e71ca95cSGerald Jelinek	$(COMPILE.s) -o $@ $<
117e71ca95cSGerald Jelinek	$(POST_PROCESS_O)
118e71ca95cSGerald Jelinek
119e71ca95cSGerald Jelinekinclude $(SRC)/lib/Makefile.targ
120