From e1bf37b1abeb6653a6e35e2bd6924131cced1efe Mon Sep 17 00:00:00 2001 From: Richard Lowe Date: Sun, 11 Feb 2018 21:47:18 +0000 Subject: 9884 cw(1) should use -fpic rather than -Kpic Reviewed by: Jason King Reviewed by: Andy Stormont Reviewed by: Toomas Soome Reviewed by: John Levon Approved by: Garrett D'Amore --- usr/src/Makefile.master | 29 +++++++-------- usr/src/cmd/sgs/Makefile.com | 4 +-- usr/src/cmd/sgs/rtld/sparc/Makefile | 2 +- usr/src/cmd/sgs/rtld/sparcv9/Makefile | 6 ++-- usr/src/lib/c_synonyms/amd64/Makefile | 4 +-- usr/src/lib/c_synonyms/i386/Makefile | 4 +-- usr/src/lib/c_synonyms/sparc/Makefile | 4 +-- usr/src/lib/c_synonyms/sparcv9/Makefile | 4 +-- usr/src/lib/efcode/engine/sparcv9/Makefile | 4 +-- usr/src/lib/fm/libmdesc/Makefile.com | 4 +-- usr/src/lib/gss_mechs/mech_krb5/Makefile | 2 +- usr/src/lib/libast/amd64/Makefile | 2 +- usr/src/lib/libast/i386/Makefile | 2 +- usr/src/lib/libast/sparc/Makefile | 2 +- usr/src/lib/libast/sparcv9/Makefile | 2 +- usr/src/lib/libbc/sparc/Makefile | 24 ++++++------- .../lib/libc/capabilities/sun4u-opl/Makefile.com | 2 +- .../capabilities/sun4u-us3-hwcap1/Makefile.com | 2 +- .../capabilities/sun4u-us3-hwcap2/Makefile.com | 2 +- usr/src/lib/libc/capabilities/sun4u/Makefile.com | 2 +- .../libc/capabilities/sun4v-hwcap1/Makefile.com | 2 +- .../libc/capabilities/sun4v-hwcap2/Makefile.com | 2 +- usr/src/lib/libc/sparc/Makefile.com | 4 +-- usr/src/lib/libc/sparcv9/Makefile.com | 4 +-- usr/src/lib/libdtrace/sparc/Makefile | 2 +- usr/src/lib/libdtrace/sparcv9/Makefile | 2 +- usr/src/lib/libdtrace_jni/Makefile.com | 4 +-- usr/src/lib/libndmp/sparcv9/Makefile | 6 ++-- usr/src/lib/libnsl/sparcv9/Makefile | 5 +-- usr/src/lib/libresolv2/sparcv9/Makefile | 6 ++-- usr/src/lib/libtnfprobe/Makefile.com | 4 +-- usr/src/lib/libzfs/sparcv9/Makefile | 3 +- usr/src/lib/libzfs_core/sparcv9/Makefile | 2 +- usr/src/lib/smbsrv/libmlsvc/sparc/Makefile | 3 +- usr/src/lib/smbsrv/libmlsvc/sparcv9/Makefile | 5 +-- usr/src/lib/smbsrv/libsmbrp/sparcv9/Makefile | 3 +- usr/src/tools/cw/cw.c | 41 ++++++---------------- usr/src/ucbcmd/sbcp/Makefile | 2 +- 38 files changed, 83 insertions(+), 124 deletions(-) (limited to 'usr/src') diff --git a/usr/src/Makefile.master b/usr/src/Makefile.master index b2eb30ec16..e23b888d46 100644 --- a/usr/src/Makefile.master +++ b/usr/src/Makefile.master @@ -890,30 +890,31 @@ CCMT= -mt # Handle different PIC models on different ISAs # (May be overridden by lower-level Makefiles) -sparc_C_PICFLAGS = -K pic -sparcv9_C_PICFLAGS = -K pic -i386_C_PICFLAGS = -K pic -amd64_C_PICFLAGS = -K pic +sparc_C_PICFLAGS = -fpic +sparcv9_C_PICFLAGS = -fpic +i386_C_PICFLAGS = -fpic +amd64_C_PICFLAGS = -fpic C_PICFLAGS = $($(MACH)_C_PICFLAGS) C_PICFLAGS64 = $($(MACH64)_C_PICFLAGS) -sparc_C_BIGPICFLAGS = -K PIC -sparcv9_C_BIGPICFLAGS = -K PIC -i386_C_BIGPICFLAGS = -K PIC -amd64_C_BIGPICFLAGS = -K PIC +sparc_C_BIGPICFLAGS = -fPIC +sparcv9_C_BIGPICFLAGS = -fPIC +i386_C_BIGPICFLAGS = -fPIC +amd64_C_BIGPICFLAGS = -fPIC C_BIGPICFLAGS = $($(MACH)_C_BIGPICFLAGS) C_BIGPICFLAGS64 = $($(MACH64)_C_BIGPICFLAGS) # CC requires there to be no space between '-K' and 'pic' or 'PIC'. -sparc_CC_PICFLAGS = -Kpic -sparcv9_CC_PICFLAGS = -KPIC -i386_CC_PICFLAGS = -Kpic -amd64_CC_PICFLAGS = -Kpic +# and does not support -f +sparc_CC_PICFLAGS = -_cc=-Kpic -_gcc=-fpic +sparcv9_CC_PICFLAGS = -_cc=-KPIC -_gcc=-fPIC +i386_CC_PICFLAGS = -_cc=-Kpic -_gcc=-fpic +amd64_CC_PICFLAGS = -_cc=-Kpic -_gcc=-fpic CC_PICFLAGS = $($(MACH)_CC_PICFLAGS) CC_PICFLAGS64 = $($(MACH64)_CC_PICFLAGS) -AS_PICFLAGS= $(C_PICFLAGS) -AS_BIGPICFLAGS= $(C_BIGPICFLAGS) +AS_PICFLAGS= -K pic +AS_BIGPICFLAGS= -K PIC # # Default label for CTF sections diff --git a/usr/src/cmd/sgs/Makefile.com b/usr/src/cmd/sgs/Makefile.com index 6964761a4e..9230fd96de 100644 --- a/usr/src/cmd/sgs/Makefile.com +++ b/usr/src/cmd/sgs/Makefile.com @@ -66,8 +66,8 @@ CPPFLAGS = -I. -I../common -I../../include -I../../include/$(MACH) \ $(CPPFLAGS.master) -I$(ELFCAP) # PICS64 is unique to our environment -$(PICS64) := sparc_CFLAGS += -xregs=no%appl -K pic -$(PICS64) := sparcv9_CFLAGS += -xregs=no%appl -K pic +$(PICS64) := sparc_CFLAGS += -xregs=no%appl $(C_PICFLAGS) +$(PICS64) := sparcv9_CFLAGS += -xregs=no%appl $(C_PICFLAGS) $(PICS64) := CPPFLAGS += -DPIC -D_REENTRANT LDFLAGS += $(ZIGNORE) diff --git a/usr/src/cmd/sgs/rtld/sparc/Makefile b/usr/src/cmd/sgs/rtld/sparc/Makefile index d2630c52db..d3af26fc0b 100644 --- a/usr/src/cmd/sgs/rtld/sparc/Makefile +++ b/usr/src/cmd/sgs/rtld/sparc/Makefile @@ -68,7 +68,7 @@ include $(SRC)/cmd/sgs/rtld/Makefile.com CPPFLAGS += -I../../../../uts/sparc/krtld -DA_OUT CFLAGS += -xregs=no%appl -ASFLAGS += -K pic +ASFLAGS += $(AS_PICFLAGS) LINTFLAGS += -DA_OUT ADBGENCFLAGS += -erroff=%all ADBGENFLAGS += -milp32 diff --git a/usr/src/cmd/sgs/rtld/sparcv9/Makefile b/usr/src/cmd/sgs/rtld/sparcv9/Makefile index 0093a7b86e..d9863462a7 100644 --- a/usr/src/cmd/sgs/rtld/sparcv9/Makefile +++ b/usr/src/cmd/sgs/rtld/sparcv9/Makefile @@ -40,11 +40,11 @@ P_MACHOBJS= sparc_elf.o _setup.o CP_MACHOBJS= common_sparc.o -S_MACHOBJS= +S_MACHOBJS= P_ASOBJS= boot.o boot_elf.o caller.o -S_ASOBJS= +S_ASOBJS= CRTSRCS= ../../../../lib/crt/sparc CRTI= pics/crti.o @@ -68,7 +68,7 @@ include $(SRC)/lib/Makefile.lib.64 CPPFLAGS += -I../../../../uts/sparc/krtld CFLAGS += -xregs=no%appl -ASFLAGS += -s -K pic -D__sparcv9 -D_ELF64 $(sparcv9_XARCH) +ASFLAGS += -s $(AS_PICFLAGS) -D__sparcv9 -D_ELF64 $(sparcv9_XARCH) ADBGENFLAGS += -mlp64 ADBGENCFLAGS += -erroff=%all ADBSUB= $(ADBSUB64) diff --git a/usr/src/lib/c_synonyms/amd64/Makefile b/usr/src/lib/c_synonyms/amd64/Makefile index 5cfacdba09..f7402f33aa 100644 --- a/usr/src/lib/c_synonyms/amd64/Makefile +++ b/usr/src/lib/c_synonyms/amd64/Makefile @@ -22,10 +22,8 @@ # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# ident "%Z%%M% %I% %E% SMI" -# -ASFLAGS= -K pic -P -D__STDC__ -D_ASM $(amd64_AS_XARCH) +ASFLAGS= $(AS_PICFLAGS) -P -D__STDC__ -D_ASM $(amd64_AS_XARCH) include ../Makefile.com include ../../Makefile.lib.64 diff --git a/usr/src/lib/c_synonyms/i386/Makefile b/usr/src/lib/c_synonyms/i386/Makefile index 0670d3021e..56e547b520 100644 --- a/usr/src/lib/c_synonyms/i386/Makefile +++ b/usr/src/lib/c_synonyms/i386/Makefile @@ -22,10 +22,8 @@ # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# ident "%Z%%M% %I% %E% SMI" -# -ASFLAGS= -K pic -P -D__STDC__ -D_ASM $(i386_AS_XARCH) +ASFLAGS= $(AS_PICFLAGS) -P -D__STDC__ -D_ASM $(i386_AS_XARCH) include ../Makefile.com diff --git a/usr/src/lib/c_synonyms/sparc/Makefile b/usr/src/lib/c_synonyms/sparc/Makefile index f9643fd890..93df1b115c 100644 --- a/usr/src/lib/c_synonyms/sparc/Makefile +++ b/usr/src/lib/c_synonyms/sparc/Makefile @@ -22,10 +22,8 @@ # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# ident "%Z%%M% %I% %E% SMI" -# -ASFLAGS= -K pic -P -D__STDC__ -D_ASM $(sparc_AS_XARCH) +ASFLAGS= $(AS_PICFLAGS) -P -D__STDC__ -D_ASM $(sparc_AS_XARCH) include ../Makefile.com diff --git a/usr/src/lib/c_synonyms/sparcv9/Makefile b/usr/src/lib/c_synonyms/sparcv9/Makefile index 13d51d128a..0f5cceeeb9 100644 --- a/usr/src/lib/c_synonyms/sparcv9/Makefile +++ b/usr/src/lib/c_synonyms/sparcv9/Makefile @@ -22,10 +22,8 @@ # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# ident "%Z%%M% %I% %E% SMI" -# -ASFLAGS= -K pic -P -D__STDC__ -D_ASM $(sparcv9_AS_XARCH) +ASFLAGS= $(AS_PICFLAGS) -P -D__STDC__ -D_ASM $(sparcv9_AS_XARCH) include ../Makefile.com include ../../Makefile.lib.64 diff --git a/usr/src/lib/efcode/engine/sparcv9/Makefile b/usr/src/lib/efcode/engine/sparcv9/Makefile index af568ee0b3..3673ac4986 100644 --- a/usr/src/lib/efcode/engine/sparcv9/Makefile +++ b/usr/src/lib/efcode/engine/sparcv9/Makefile @@ -23,12 +23,10 @@ # Copyright 2004 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# ident "%Z%%M% %I% %E% SMI" -# include ../Makefile.com include $(SRC)/lib/Makefile.lib.64 -sparcv9_C_PICFLAGS = -KPIC +sparcv9_C_PICFLAGS = $(C_BIGPICFLAGS64) install: all $(ROOTLIBS64) diff --git a/usr/src/lib/fm/libmdesc/Makefile.com b/usr/src/lib/fm/libmdesc/Makefile.com index 7d3f814c59..c09447e182 100644 --- a/usr/src/lib/fm/libmdesc/Makefile.com +++ b/usr/src/lib/fm/libmdesc/Makefile.com @@ -50,8 +50,8 @@ LIBS = $(DYNLIB) $(LINTLIB) SRCDIR = ../common CPPFLAGS += -I../common -I. -CFLAGS += $(CCVERBOSE) -K PIC -CFLAGS64 += $(CCVERBOSE) -K PIC +CFLAGS += $(CCVERBOSE) $(C_BIGPICFLAGS) +CFLAGS64 += $(CCVERBOSE) $(C_BIGPICFLAGS64) LDLIBS += -lc LINTFLAGS += -erroff=E_BAD_PTR_CAST_ALIGN -v diff --git a/usr/src/lib/gss_mechs/mech_krb5/Makefile b/usr/src/lib/gss_mechs/mech_krb5/Makefile index 6d5fa74ac8..c725934855 100644 --- a/usr/src/lib/gss_mechs/mech_krb5/Makefile +++ b/usr/src/lib/gss_mechs/mech_krb5/Makefile @@ -39,7 +39,7 @@ include ../../Makefile.lib GREP= find . \( -name SCCS -prune -o -name '*.[ch]' \) -print | sort | xargs grep -sparcv9_C_PICFLAGS = -K PIC +sparcv9_C_PICFLAGS = $(sparcv9_C_BIGPICFLAGS) TEXT_DOMAIN = SUNW_OST_NETRPC POFILE = mech_krb5.po POFILES = generic.po diff --git a/usr/src/lib/libast/amd64/Makefile b/usr/src/lib/libast/amd64/Makefile index 0419980509..baa59970af 100644 --- a/usr/src/lib/libast/amd64/Makefile +++ b/usr/src/lib/libast/amd64/Makefile @@ -38,7 +38,7 @@ OBJDIRS = \ include ../Makefile.com include ../../Makefile.lib.64 -# Use -KPIC since libast is too big for -Kpic on 64bit +# Use big PIC since libast is too big for pic on 64bit # (and on 32bit it is close to the barrier) amd64_C_PICFLAGS = $(C_BIGPICFLAGS) diff --git a/usr/src/lib/libast/i386/Makefile b/usr/src/lib/libast/i386/Makefile index 309ec29f43..f601e12e04 100644 --- a/usr/src/lib/libast/i386/Makefile +++ b/usr/src/lib/libast/i386/Makefile @@ -37,7 +37,7 @@ OBJDIRS = \ include ../Makefile.com -# Use -KPIC since libast is too big for -Kpic on 64bit +# Use big PIC since libast is too big for pic on 64bit # (and on 32bit it is close to the barrier) i386_C_PICFLAGS = $(C_BIGPICFLAGS) diff --git a/usr/src/lib/libast/sparc/Makefile b/usr/src/lib/libast/sparc/Makefile index 63d22de006..54f6ad2f28 100644 --- a/usr/src/lib/libast/sparc/Makefile +++ b/usr/src/lib/libast/sparc/Makefile @@ -38,7 +38,7 @@ OBJDIRS = \ include ../Makefile.com -# Use -KPIC since libast is too big for -Kpic on 64bit +# Use big PIC since libast is too big for pic on 64bit # (and on 32bit it is close to the barrier) sparc_C_PICFLAGS = $(C_BIGPICFLAGS) diff --git a/usr/src/lib/libast/sparcv9/Makefile b/usr/src/lib/libast/sparcv9/Makefile index 6a680ee6c6..ec4370867f 100644 --- a/usr/src/lib/libast/sparcv9/Makefile +++ b/usr/src/lib/libast/sparcv9/Makefile @@ -39,7 +39,7 @@ OBJDIRS = \ include ../Makefile.com include ../../Makefile.lib.64 -# Use -KPIC since libast is too big for -Kpic on 64bit +# Use big PIC since libast is too big for pic on 64bit # (and on 32bit it is close to the barrier) sparcv9_C_PICFLAGS = $(C_BIGPICFLAGS) diff --git a/usr/src/lib/libbc/sparc/Makefile b/usr/src/lib/libbc/sparc/Makefile index c624b62c2f..b35b87a3f4 100644 --- a/usr/src/lib/libbc/sparc/Makefile +++ b/usr/src/lib/libbc/sparc/Makefile @@ -44,7 +44,7 @@ utime.o COMPAT4.1=\ ftime.o nice.o rand.o vlimit.o vtimes.o getpw.o times.o - + COMPATSYS5=\ nice.o rand.o getpw.o times.o @@ -97,14 +97,14 @@ calloc.o malloc.o \ getpass.o localtime.o ttyslot.o GENCOMSPARC=\ -alloca.o ffs.o insque.o remque.o isinf.o base_conv.o +alloca.o ffs.o insque.o remque.o isinf.o base_conv.o GEN4.2=\ nlist.o timezone.o sleep.o system.o GENSYS5=\ assert.o nlist.o sgetl.o sleep.o sputl.o system.o \ -sighold.o +sighold.o STDIOCOM=\ clrerr.o ctermid.o cuserid.o doprnt.o doscan.o fdopen.o \ @@ -150,7 +150,7 @@ creat.o execve.o getpgrp.o link.o mkdir.o \ mknod.o open.o readlink.o rename.o rmdir.o \ setpgrp.o stat.o symlink.o truncate.o unlink.o \ statfs.o fcntl.o read.o write.o readv.o \ -writev.o setjmp.o mount.o +writev.o setjmp.o mount.o SYS4.2SPARC=\ getgroups.o setgroups.o @@ -340,9 +340,9 @@ CERRWARN += -_gcc=-Wno-address $(DYNLIB4X) := SONAME = $(DYNLIB4X) $(DYNLIBS5) := SONAME = $(DYNLIBS5) -pics/%.o:= ASFLAGS += -K pic -DPIC -pics/%.o:= CPPFLAGS += -K pic -DPIC -s5pics/%.o:= ASFLAGS += -K pic -DPIC +pics/%.o:= ASFLAGS += $(AS_PICFLAGS) -DPIC +pics/%.o:= CPPFLAGS += $(C_PICFLAGS) -DPIC +s5pics/%.o:= ASFLAGS += $(AS_PICFLAGS) -DPIC DYNFLAGS += $(ZINTERPOSE) BUILD.s= $(AS) $(ASFLAGS) $< -o $@ @@ -352,14 +352,14 @@ BUILD.AR= $(RM) $@ ; \ $(AR) q $@ $(OBJECTS:%=$(DIR)/%) # the TXTS macro is used for NSE bootstrapping. -TXTS= inc/SYS.h inc/PIC.h inc/machine/asm_linkage.h +TXTS= inc/SYS.h inc/PIC.h inc/machine/asm_linkage.h LIBS = $(DYNLIB4X) $(DYNLIBS5) OBJECTS= $(COMPATCOM) $(COMPAT4.1) $(CRTSPARC) $(GENCOM) \ $(GENCOMSPARC) $(GEN4.2) $(STDIOCOM) $(STDIO4.2) \ $(INET) $(NET) $(NETSPARC) $(YP) \ -$(SYSCOM) $(SYSCOMSPARC) $(SYS4.2) +$(SYSCOM) $(SYSCOMSPARC) $(SYS4.2) # # Since this library is strictly for binary compability with ancient @@ -381,7 +381,7 @@ CLEANFILES= ../libc/yp/ypupdate_prot.c ../inc/include/rpcsvc/ypupdate_prot.h \ CLOBBERFILES= ../libc/compat/sys5/mkepoch # conditional assignments -s5pics/%.o:= CPPFLAGS = -Dsparc -DS5EMUL -K pic -DPIC -I. -Iinc \ +s5pics/%.o:= CPPFLAGS = -Dsparc -DS5EMUL $(C_PICFLAGS) -DPIC -I. -Iinc \ -I../inc/5include -I../inc/include -I../inc/include/sys \ $(CPPFLAGS.master) @@ -414,7 +414,7 @@ s5pics: # special cases PSEUDO_POBJS= $(PSEUDO_SRCS:%.s=pics/%.o) -PSEUDO_PS5OBJS= $(PSEUDO_SRCS:%.s=s5pics/%.o) +PSEUDO_PS5OBJS= $(PSEUDO_SRCS:%.s=s5pics/%.o) $(PSEUDO_POBJS) $(PSEUDO_PS5OBJS): @(echo '#include "SYS.h"'; \ @@ -451,7 +451,7 @@ s5pics/yp_update.o : ../inc/include/rpcsvc/ypupdate_prot.h ../libc/yp/yp_update. $(POST_PROCESS_O) pics/ypupdate_prot.o s5pics/ypupdate_prot.o : ../inc/include/rpcsvc/ypupdate_prot.h\ - ../libc/yp/ypupdate_prot.c + ../libc/yp/ypupdate_prot.c $(COMPILE.c) -o $@ ../libc/yp/ypupdate_prot.c $(POST_PROCESS_O) diff --git a/usr/src/lib/libc/capabilities/sun4u-opl/Makefile.com b/usr/src/lib/libc/capabilities/sun4u-opl/Makefile.com index 0080c16a0e..c50532689c 100644 --- a/usr/src/lib/libc/capabilities/sun4u-opl/Makefile.com +++ b/usr/src/lib/libc/capabilities/sun4u-opl/Makefile.com @@ -37,4 +37,4 @@ IFLAGS = -I$(SRC)/uts/$(GEN_PLATFORM) \ -I$(ROOT)/usr/platform/$(GEN_PLATFORM)/include AS_CPPFLAGS += -D__STDC__ -D_ASM -DPIC -D_REENTRANT -D$(MACH) $(IFLAGS) -ASFLAGS = -P -K pic +ASFLAGS = -P $(AS_PICFLAGS) diff --git a/usr/src/lib/libc/capabilities/sun4u-us3-hwcap1/Makefile.com b/usr/src/lib/libc/capabilities/sun4u-us3-hwcap1/Makefile.com index b459a6ac2d..1dab8dae63 100644 --- a/usr/src/lib/libc/capabilities/sun4u-us3-hwcap1/Makefile.com +++ b/usr/src/lib/libc/capabilities/sun4u-us3-hwcap1/Makefile.com @@ -39,4 +39,4 @@ MAPFILE-CAP += ../../$(TRG_PLATFORM)/common/mapfile-cap AS_CPPFLAGS += -D__STDC__ -D_ASM -DPIC -D_REENTRANT -D$(MACH) $(IFLAGS) \ -DBSTORE_SIZE=256 -ASFLAGS = -P -K pic +ASFLAGS = -P $(AS_PICFLAGS) diff --git a/usr/src/lib/libc/capabilities/sun4u-us3-hwcap2/Makefile.com b/usr/src/lib/libc/capabilities/sun4u-us3-hwcap2/Makefile.com index 039b50259c..6620a802f3 100644 --- a/usr/src/lib/libc/capabilities/sun4u-us3-hwcap2/Makefile.com +++ b/usr/src/lib/libc/capabilities/sun4u-us3-hwcap2/Makefile.com @@ -39,4 +39,4 @@ MAPFILE-CAP += ../../$(TRG_PLATFORM)/common/mapfile-cap AS_CPPFLAGS += -D__STDC__ -D_ASM -DPIC -D_REENTRANT -D$(MACH) $(IFLAGS) \ -DBSTORE_SIZE=65536 -DPANTHER_ONLY -ASFLAGS = -P -K pic +ASFLAGS = -P $(AS_PICFLAGS) diff --git a/usr/src/lib/libc/capabilities/sun4u/Makefile.com b/usr/src/lib/libc/capabilities/sun4u/Makefile.com index 0d8a28bfa1..033f0dc43e 100644 --- a/usr/src/lib/libc/capabilities/sun4u/Makefile.com +++ b/usr/src/lib/libc/capabilities/sun4u/Makefile.com @@ -36,7 +36,7 @@ IFLAGS = -I$(SRC)/uts/$(GEN_PLATFORM) \ -I$(ROOT)/usr/platform/$(GEN_PLATFORM)/include AS_CPPFLAGS += -D__STDC__ -D_ASM -DPIC -D_REENTRANT -D$(MACH) $(IFLAGS) -ASFLAGS = -P -K pic +ASFLAGS = -P $(AS_PICFLAGS) # memcpy.s provides __align_cpy_1 as an alias for memcpy. However, this isn't # a WEAK symbol, and hence ld(1)'s ability to cull duplicate local symbols with diff --git a/usr/src/lib/libc/capabilities/sun4v-hwcap1/Makefile.com b/usr/src/lib/libc/capabilities/sun4v-hwcap1/Makefile.com index 0b1a16be84..8e7800a6d2 100644 --- a/usr/src/lib/libc/capabilities/sun4v-hwcap1/Makefile.com +++ b/usr/src/lib/libc/capabilities/sun4v-hwcap1/Makefile.com @@ -38,7 +38,7 @@ IFLAGS = -I$(SRC)/uts/$(GEN_PLATFORM) \ AS_CPPFLAGS += -D__STDC__ -D_ASM -DPIC -D_REENTRANT -D$(MACH) $(IFLAGS) \ -DNIAGARA_IMPL -ASFLAGS = -P -K pic +ASFLAGS = -P $(AS_PICFLAGS) # memcpy.s provides __align_cpy_1 as an alias for memcpy. However, this isn't # a WEAK symbol, and hence ld(1)'s ability to cull duplicate local symbols with diff --git a/usr/src/lib/libc/capabilities/sun4v-hwcap2/Makefile.com b/usr/src/lib/libc/capabilities/sun4v-hwcap2/Makefile.com index af1273234c..a652b280be 100644 --- a/usr/src/lib/libc/capabilities/sun4v-hwcap2/Makefile.com +++ b/usr/src/lib/libc/capabilities/sun4v-hwcap2/Makefile.com @@ -38,7 +38,7 @@ IFLAGS = -I$(SRC)/uts/$(GEN_PLATFORM) \ AS_CPPFLAGS += -D__STDC__ -D_ASM -DPIC -D_REENTRANT -D$(MACH) $(IFLAGS) \ -DNIAGARA2_IMPL -ASFLAGS = -P -K pic +ASFLAGS = -P $(AS_PICFLAGS) # memcpy.s provides __align_cpy_1 as an alias for memcpy. However, this isn't # a WEAK symbol, and hence ld(1)'s ability to cull duplicate local symbols with diff --git a/usr/src/lib/libc/sparc/Makefile.com b/usr/src/lib/libc/sparc/Makefile.com index 92efd03df5..3513856775 100644 --- a/usr/src/lib/libc/sparc/Makefile.com +++ b/usr/src/lib/libc/sparc/Makefile.com @@ -1130,7 +1130,7 @@ MAPFILES = $(LIBCDIR)/port/mapfile-vers CFLAGS += $(EXTN_CFLAGS) CPPFLAGS= -D_REENTRANT -Dsparc $(EXTN_CPPFLAGS) $(THREAD_DEBUG) \ -I$(LIBCBASE)/inc -I$(LIBCDIR)/inc $(CPPFLAGS.master) -ASFLAGS= $(EXTN_ASFLAGS) -K pic -P -D__STDC__ -D_ASM $(CPPFLAGS) $(sparc_AS_XARCH) +ASFLAGS= $(EXTN_ASFLAGS) $(AS_PICFLAGS) -P -D__STDC__ -D_ASM $(CPPFLAGS) $(sparc_AS_XARCH) # As a favor to the dtrace syscall provider, libc still calls the # old syscall traps that have been obsoleted by the *at() interfaces. @@ -1382,7 +1382,7 @@ $(STRETS:%=pics/%): $(LIBCBASE)/crt/stret.s $(POST_PROCESS_O) $(LIBCBASE)/crt/_rtbootld.s: $(LIBCBASE)/crt/_rtboot.s $(LIBCBASE)/crt/_rtld.c - $(CC) $(CPPFLAGS) $(CTF_FLAGS) -O -S -K pic \ + $(CC) $(CPPFLAGS) $(CTF_FLAGS) -O -S $(C_PICFLAGS) \ $(LIBCBASE)/crt/_rtld.c -o $(LIBCBASE)/crt/_rtld.s $(CAT) $(LIBCBASE)/crt/_rtboot.s $(LIBCBASE)/crt/_rtld.s > $@ $(RM) $(LIBCBASE)/crt/_rtld.s diff --git a/usr/src/lib/libc/sparcv9/Makefile.com b/usr/src/lib/libc/sparcv9/Makefile.com index b756ad5ab2..39f4b4be28 100644 --- a/usr/src/lib/libc/sparcv9/Makefile.com +++ b/usr/src/lib/libc/sparcv9/Makefile.com @@ -1067,11 +1067,11 @@ $(DYNLIB) := BUILD.SO = $(LD) -o $@ -G $(DYNFLAGS) $(PICS) $(ALTPICS) $(EXTPICS) MAPFILES = $(LIBCDIR)/port/mapfile-vers -sparcv9_C_PICFLAGS= -K PIC +sparcv9_C_PICFLAGS= $(sparcv9_C_BIGPICFLAGS) CFLAGS64 += $(EXTN_CFLAGS) CPPFLAGS= -D_REENTRANT -Dsparc $(EXTN_CPPFLAGS) $(THREAD_DEBUG) \ -I$(LIBCBASE)/inc -I$(LIBCDIR)/inc $(CPPFLAGS.master) -ASFLAGS= $(EXTN_ASFLAGS) -K PIC -P -D__STDC__ -D_ASM -D__sparcv9 $(CPPFLAGS) \ +ASFLAGS= $(EXTN_ASFLAGS) $(AS_BIGPICFLAGS) -P -D__STDC__ -D_ASM -D__sparcv9 $(CPPFLAGS) \ $(sparcv9_AS_XARCH) # As a favor to the dtrace syscall provider, libc still calls the diff --git a/usr/src/lib/libdtrace/sparc/Makefile b/usr/src/lib/libdtrace/sparc/Makefile index 6065e14810..4c4ad06f89 100644 --- a/usr/src/lib/libdtrace/sparc/Makefile +++ b/usr/src/lib/libdtrace/sparc/Makefile @@ -23,7 +23,7 @@ # Use is subject to license terms. # -ASFLAGS += -D_ASM -K PIC -P +ASFLAGS += -D_ASM $(AS_BIGPICFLAGS) -P include ../Makefile.com diff --git a/usr/src/lib/libdtrace/sparcv9/Makefile b/usr/src/lib/libdtrace/sparcv9/Makefile index a45f315e94..d22653cb31 100644 --- a/usr/src/lib/libdtrace/sparcv9/Makefile +++ b/usr/src/lib/libdtrace/sparcv9/Makefile @@ -23,7 +23,7 @@ # Use is subject to license terms. # -ASFLAGS += -D_ASM -K PIC -P +ASFLAGS += -D_ASM $(AS_BIGPICFLAGS) -P include ../Makefile.com include ../../Makefile.lib.64 diff --git a/usr/src/lib/libdtrace_jni/Makefile.com b/usr/src/lib/libdtrace_jni/Makefile.com index 9d605b3c59..471746866f 100644 --- a/usr/src/lib/libdtrace_jni/Makefile.com +++ b/usr/src/lib/libdtrace_jni/Makefile.com @@ -46,8 +46,8 @@ SRCDIR = ../common CPPFLAGS += -I../common -I. CPPFLAGS += -I$(JAVA_ROOT)/include -I$(JAVA_ROOT)/include/solaris CPPFLAGS += -I../java/native -CFLAGS += $(CCVERBOSE) -K PIC -CFLAGS64 += $(CCVERBOSE) -K PIC +CFLAGS += $(CCVERBOSE) $(C_BIGPICFLAGS) +CFLAGS64 += $(CCVERBOSE) $(C_BIGPICFLAGS64) CERRWARN += -_gcc=-Wno-uninitialized diff --git a/usr/src/lib/libndmp/sparcv9/Makefile b/usr/src/lib/libndmp/sparcv9/Makefile index b84fb15f9e..c0e1bf7d54 100644 --- a/usr/src/lib/libndmp/sparcv9/Makefile +++ b/usr/src/lib/libndmp/sparcv9/Makefile @@ -11,10 +11,10 @@ # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: -# - Redistributions of source code must retain the above copyright +# - Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # -# - Redistributions in binary form must reproduce the above copyright +# - Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. @@ -39,6 +39,6 @@ include ../Makefile.com include $(SRC)/lib/Makefile.lib.64 -sparcv9_C_PICFLAGS= -K PIC +sparcv9_C_PICFLAGS= $(sparcv9_C_BIGPICFLAGS) install: all $(ROOTLIBS64) $(ROOTLINKS64) diff --git a/usr/src/lib/libnsl/sparcv9/Makefile b/usr/src/lib/libnsl/sparcv9/Makefile index da1777943b..249857bc50 100644 --- a/usr/src/lib/libnsl/sparcv9/Makefile +++ b/usr/src/lib/libnsl/sparcv9/Makefile @@ -23,8 +23,6 @@ # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# ident "%Z%%M% %I% %E% SMI" -# include ../Makefile.com include ../../Makefile.lib.64 @@ -33,7 +31,6 @@ include ../../Makefile.lib.64 # the whole 64-bit library with PIC instead of "generically" compiling # large parts of the 32-bit library with PIC unnecessarily. -sparcv9_C_PICFLAGS = -K PIC -sparcv9_CC_PICFLAGS = -KPIC +sparcv9_C_PICFLAGS = $(sparcv9_C_BIGPICFLAGS) install: all $(ROOTLIBS64) $(ROOTLINKS64) diff --git a/usr/src/lib/libresolv2/sparcv9/Makefile b/usr/src/lib/libresolv2/sparcv9/Makefile index ceed393e0d..2095629575 100644 --- a/usr/src/lib/libresolv2/sparcv9/Makefile +++ b/usr/src/lib/libresolv2/sparcv9/Makefile @@ -22,17 +22,15 @@ # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# ident "%Z%%M% %I% %E% SMI" # include ../Makefile.com include ../../Makefile.lib.64 # With the adition of BIND 8.3.3, the symbol table for 64 bit went over -# the limit for Kpic, so we've added -KPIC here, for just the 64 bit +# the limit for Kpic, so we've added -KPIC here, for just the 64 bit # library. This avoids compiling the 32-bit library with PIC unnecessarily. -sparcv9_C_PICFLAGS = -K PIC -sparcv9_CC_PICFLAGS = -KPIC +sparcv9_C_PICFLAGS = $(sparcv9_C_BIGPICFLAGS) install: all $(ROOTLIBS64) $(ROOTLINKS64) diff --git a/usr/src/lib/libtnfprobe/Makefile.com b/usr/src/lib/libtnfprobe/Makefile.com index 9dd31dd6f6..f0fe5a2658 100644 --- a/usr/src/lib/libtnfprobe/Makefile.com +++ b/usr/src/lib/libtnfprobe/Makefile.com @@ -53,7 +53,7 @@ HDRS= com.h writer.h probe.h ROOTHDRDIR= $(ROOT)/usr/include/tnf ROOTHDRS= $(HDRS:%=$(ROOTHDRDIR)/%) CHECKHDRS= $(HDRS:%.h=%.check) -$(ROOTHDRS) := FILEMODE = 0644 +$(ROOTHDRS) := FILEMODE = 0644 CHECKHDRS = $(HDRS:%.h=%.check) # Include .. first to pick up tnf_trace.h in current dir, Include UFSDIR to @@ -87,7 +87,7 @@ $(ROOTLIBDIR) $(ROOTHDRDIR): $(ROOTHDRDIR)/% : % $(INS.file) -#ASFLAGS= -K pic -P -D_SYS_SYS_S -D_LOCORE -D_ASM -DPIC -DLOCORE $(CPPFLAGS) +#ASFLAGS= $(AS_PICFLAGS) -P -D_SYS_SYS_S -D_LOCORE -D_ASM -DPIC -DLOCORE $(CPPFLAGS) ASFLAGS= -P -D_SYS_SYS_S -D_LOCORE -D_ASM -DPIC -DLOCORE $(CPPFLAGS) BUILD.s= $(AS) $(ASFLAGS) $< -o $@ diff --git a/usr/src/lib/libzfs/sparcv9/Makefile b/usr/src/lib/libzfs/sparcv9/Makefile index 24010f6fb4..fc812ba170 100644 --- a/usr/src/lib/libzfs/sparcv9/Makefile +++ b/usr/src/lib/libzfs/sparcv9/Makefile @@ -23,11 +23,10 @@ # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -#ident "%Z%%M% %I% %E% SMI" include ../Makefile.com include ../../Makefile.lib.64 -sparcv9_C_PICFLAGS= -K PIC +sparcv9_C_PICFLAGS= $(sparcv9_C_BIGPICFLAGS) install: all $(ROOTLIBS64) $(ROOTLINKS64) diff --git a/usr/src/lib/libzfs_core/sparcv9/Makefile b/usr/src/lib/libzfs_core/sparcv9/Makefile index c5b6ca49b4..fc812ba170 100644 --- a/usr/src/lib/libzfs_core/sparcv9/Makefile +++ b/usr/src/lib/libzfs_core/sparcv9/Makefile @@ -27,6 +27,6 @@ include ../Makefile.com include ../../Makefile.lib.64 -sparcv9_C_PICFLAGS= -K PIC +sparcv9_C_PICFLAGS= $(sparcv9_C_BIGPICFLAGS) install: all $(ROOTLIBS64) $(ROOTLINKS64) diff --git a/usr/src/lib/smbsrv/libmlsvc/sparc/Makefile b/usr/src/lib/smbsrv/libmlsvc/sparc/Makefile index afc42f3dbc..5f4cf20982 100644 --- a/usr/src/lib/smbsrv/libmlsvc/sparc/Makefile +++ b/usr/src/lib/smbsrv/libmlsvc/sparc/Makefile @@ -26,8 +26,7 @@ include ../Makefile.com # With compiling with gcc, the symbol table goes over # the limit for Kpic, so we add -KPIC here. -$(__GNUC)sparc_C_PICFLAGS = -K PIC -$(__GNUC)sparc_CC_PICFLAGS = -KPIC +$(__GNUC)sparc_C_PICFLAGS = $(sparc_C_BIGPICFLAGS) DYNFLAGS += -R/usr/lib/smbsrv diff --git a/usr/src/lib/smbsrv/libmlsvc/sparcv9/Makefile b/usr/src/lib/smbsrv/libmlsvc/sparcv9/Makefile index e18b286b0a..745535f9a9 100644 --- a/usr/src/lib/smbsrv/libmlsvc/sparcv9/Makefile +++ b/usr/src/lib/smbsrv/libmlsvc/sparcv9/Makefile @@ -22,8 +22,6 @@ # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# ident "%Z%%M% %I% %E% SMI" -# MACH_LDLIBS += -L$(ROOT)/usr/lib/smbsrv/$(MACH64) @@ -33,8 +31,7 @@ include ../../../Makefile.lib.64 # With the adition of BIND 8.3.3, the symbol table for 64 bit went over # the limit for Kpic, so we add -KPIC here, for just the 64 bit SPARC # library. This avoids compiling the 32-bit library with PIC unnecessarily. -sparcv9_C_PICFLAGS = -K PIC -sparcv9_CC_PICFLAGS = -KPIC +sparcv9_C_PICFLAGS = $(sparcv9_C_BIGPICFLAGS) DYNFLAGS += -R/usr/lib/smbsrv/$(MACH64) diff --git a/usr/src/lib/smbsrv/libsmbrp/sparcv9/Makefile b/usr/src/lib/smbsrv/libsmbrp/sparcv9/Makefile index d138cfc574..89460e9b3c 100644 --- a/usr/src/lib/smbsrv/libsmbrp/sparcv9/Makefile +++ b/usr/src/lib/smbsrv/libsmbrp/sparcv9/Makefile @@ -29,8 +29,7 @@ include ../../../Makefile.lib.64 # With the adition of BIND 8.3.3, the symbol table for 64 bit went over # the limit for Kpic, so we add -KPIC here, for just the 64 bit SPARC # library. This avoids compiling the 32-bit library with PIC unnecessarily. -sparcv9_C_PICFLAGS = -K PIC -sparcv9_CC_PICFLAGS = -KPIC +sparcv9_C_PICFLAGS = $(sparcv9_C_BIGPICFLAGS) $(ROOTLIBDIR64): $(INS.dir) diff --git a/usr/src/tools/cw/cw.c b/usr/src/tools/cw/cw.c index de3a57dcb9..4e09752e79 100644 --- a/usr/src/tools/cw/cw.c +++ b/usr/src/tools/cw/cw.c @@ -71,8 +71,6 @@ * -I Add to preprocessor #include file search path * -i Passed to linker to ignore any LD_LIBRARY_PATH setting * -keeptmp Keep temporary files created during compilation - * -KPIC Compile position independent code with 32-bit addresses - * -Kpic Compile position independent code * -L Pass to linker to add to the library search path * -l Link with library lib.a or lib.so * -mc Remove duplicate strings from .comment section of output files @@ -180,8 +178,6 @@ * -I pass-thru * -i pass-thru * -keeptmp -save-temps - * -KPIC -fPIC - * -Kpic -fpic * -L pass-thru * -l pass-thru * -mc error @@ -567,7 +563,7 @@ static void do_gcc(cw_ictx_t *ctx) { int c; - int pic = 0, nolibc = 0; + int nolibc = 0; int in_output = 0, seen_o = 0, c_files = 0; cw_op_t op = CW_O_LINK; char *model = NULL; @@ -703,6 +699,14 @@ do_gcc(cw_ictx_t *ctx) } error(arg); break; + case 'f': + if ((strcmp(arg, "-fpic") == 0) || + (strcmp(arg, "-fPIC") == 0)) { + newae(ctx->i_ae, arg); + break; + } + error(arg); + break; case 'g': newae(ctx->i_ae, "-gdwarf-2"); break; @@ -819,27 +823,6 @@ do_gcc(cw_ictx_t *ctx) } error(arg); break; - case 'K': - if (arglen == 1) { - if ((arg = *++ctx->i_oldargv) == NULL || - *arg == '\0') - error("-K"); - ctx->i_oldargc--; - } else { - arg += 2; - } - if (strcmp(arg, "pic") == 0) { - newae(ctx->i_ae, "-fpic"); - pic = 1; - break; - } - if (strcmp(arg, "PIC") == 0) { - newae(ctx->i_ae, "-fPIC"); - pic = 1; - break; - } - error("-K"); - break; case 'm': if (strcmp(arg, "-mt") == 0) { newae(ctx->i_ae, "-D_REENTRANT"); @@ -986,8 +969,6 @@ do_gcc(cw_ictx_t *ctx) } if (strncmp(arg, "-Wc,-xcode=", 11) == 0) { xlate(ctx->i_ae, arg + 11, xcode_tbl); - if (strncmp(arg + 11, "pic", 3) == 0) - pic = 1; break; } if (strncmp(arg, "-Wc,-Qiselect", 13) == 0) { @@ -1064,8 +1045,6 @@ do_gcc(cw_ictx_t *ctx) } if (strncmp(arg, "-xcode=", 7) == 0) { xlate(ctx->i_ae, arg + 7, xcode_tbl); - if (strncmp(arg + 7, "pic", 3) == 0) - pic = 1; break; } if (strncmp(arg, "-xcrossfile", 11) == 0) @@ -1288,7 +1267,7 @@ do_gcc(cw_ictx_t *ctx) (ctx->i_flags & CW_F_SHADOW)) exit(0); - if (model && !pic) + if (model != NULL) newae(ctx->i_ae, model); if (!nolibc) newae(ctx->i_ae, "-lc"); diff --git a/usr/src/ucbcmd/sbcp/Makefile b/usr/src/ucbcmd/sbcp/Makefile index 8417665637..ce1bf79e32 100644 --- a/usr/src/ucbcmd/sbcp/Makefile +++ b/usr/src/ucbcmd/sbcp/Makefile @@ -41,7 +41,7 @@ LIBBC= ../../lib/libbc/sparc/libc.so.1.9 LIBUCB= ../../ucblib/libucb/sparc/libucb.so.1 # need libc/sparc/inc for PIC.h -ASFLAGS= -P -D_ASM -DPIC -K pic +ASFLAGS= -P -D_ASM -DPIC $(AS_PICFLAGS) LDFLAGS= -R /usr/4lib:/usr/ucblib -e _start -G -t \ $(BLOCAL) $(ZNOVERSION) $(ZDEFS) $(ZTEXT) \ -I/usr/lib/ld.so.1 -- cgit v1.2.3 From 83b4671e6262c5aa6b4f9fb5a384b1946dfc2e7f Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Tue, 16 Aug 2016 19:02:42 +0300 Subject: 9664 loader: need UEFI32 support Reviewed by: Robert Mustacchi Reviewed by: Andrew Stormont Approved by: Gordon Ross --- usr/src/boot/sys/boot/Makefile | 2 +- usr/src/boot/sys/boot/common/bootstrap.h | 2 +- usr/src/boot/sys/boot/common/multiboot2.c | 16 +- usr/src/boot/sys/boot/common/paths.h | 2 +- usr/src/boot/sys/boot/efi/Makefile.inc | 6 +- usr/src/boot/sys/boot/efi/boot1/Makefile | 126 +---- usr/src/boot/sys/boot/efi/boot1/Makefile.com | 131 +++++ usr/src/boot/sys/boot/efi/boot1/amd64/Makefile | 33 ++ usr/src/boot/sys/boot/efi/boot1/i386/Makefile | 33 ++ usr/src/boot/sys/boot/efi/boot1/zfs_module.c | 5 +- usr/src/boot/sys/boot/efi/include/amd64/efibind.h | 65 --- usr/src/boot/sys/boot/efi/include/i386/efibind.h | 67 --- usr/src/boot/sys/boot/efi/libefi/Makefile | 87 +--- usr/src/boot/sys/boot/efi/libefi/Makefile.com | 73 +++ usr/src/boot/sys/boot/efi/libefi/amd64/Makefile | 29 ++ usr/src/boot/sys/boot/efi/libefi/i386/Makefile | 29 ++ usr/src/boot/sys/boot/efi/loader/Makefile | 157 +----- usr/src/boot/sys/boot/efi/loader/Makefile.com | 156 ++++++ usr/src/boot/sys/boot/efi/loader/amd64/Makefile | 33 ++ .../sys/boot/efi/loader/arch/amd64/Makefile.inc | 5 - .../sys/boot/efi/loader/arch/amd64/framebuffer.c | 568 --------------------- .../sys/boot/efi/loader/arch/amd64/framebuffer.h | 36 -- .../boot/efi/loader/arch/amd64/multiboot_tramp.S | 22 +- .../sys/boot/efi/loader/arch/i386/Makefile.inc | 19 +- .../sys/boot/efi/loader/arch/i386/ldscript.i386 | 3 +- .../boot/efi/loader/arch/i386/multiboot_tramp.S | 150 ++++++ usr/src/boot/sys/boot/efi/loader/bootinfo.c | 2 +- usr/src/boot/sys/boot/efi/loader/copy.c | 12 +- usr/src/boot/sys/boot/efi/loader/efi_main.c | 2 +- usr/src/boot/sys/boot/efi/loader/framebuffer.c | 567 ++++++++++++++++++++ usr/src/boot/sys/boot/efi/loader/framebuffer.h | 36 ++ usr/src/boot/sys/boot/efi/loader/i386/Makefile | 33 ++ usr/src/boot/sys/boot/efi/loader/loader_efi.h | 12 +- usr/src/boot/sys/boot/efi/loader/main.c | 8 +- usr/src/boot/sys/boot/ficl/Makefile | 31 -- usr/src/boot/sys/boot/ficl/Makefile.inc | 70 --- usr/src/boot/sys/boot/ficl/amd64/Makefile | 26 - usr/src/boot/sys/boot/ficl/ficllocal.h | 11 - usr/src/boot/sys/boot/ficl/i386/Makefile | 27 - usr/src/boot/sys/boot/ficl/softcore/Makefile | 34 -- usr/src/boot/sys/boot/i386/Makefile | 4 +- usr/src/boot/sys/boot/i386/Makefile.inc | 6 +- usr/src/boot/sys/boot/i386/btx/btx/Makefile | 2 +- usr/src/boot/sys/boot/i386/btx/btxldr/Makefile | 4 +- usr/src/boot/sys/boot/i386/btx/lib/Makefile | 2 +- usr/src/boot/sys/boot/i386/gptzfsboot/Makefile | 4 +- usr/src/boot/sys/boot/i386/libi386/Makefile | 4 +- usr/src/boot/sys/boot/i386/loader/Makefile | 10 +- usr/src/boot/sys/boot/libficl/Makefile | 31 ++ usr/src/boot/sys/boot/libficl/Makefile.com | 63 +++ usr/src/boot/sys/boot/libficl/amd64/Makefile | 29 ++ usr/src/boot/sys/boot/libficl/ficllocal.h | 11 + usr/src/boot/sys/boot/libficl/i386/Makefile | 29 ++ usr/src/boot/sys/boot/libficl/softcore/Makefile | 34 ++ usr/src/boot/sys/boot/libstand/Makefile.com | 20 +- usr/src/boot/sys/boot/libstand/amd64/Makefile | 14 +- usr/src/boot/sys/boot/libstand/i386/Makefile | 14 +- usr/src/boot/sys/boot/usb/Makefile | 1 - usr/src/boot/sys/boot/usb/Makefile.test | 1 - usr/src/boot/sys/boot/zfs/Makefile | 4 +- usr/src/boot/sys/boot/zfs/Makefile.com | 37 +- usr/src/boot/sys/boot/zfs/amd64/Makefile | 10 +- usr/src/boot/sys/boot/zfs/i386/Makefile | 11 +- usr/src/pkg/manifests/system-boot-loader.mf | 6 +- 64 files changed, 1688 insertions(+), 1389 deletions(-) create mode 100644 usr/src/boot/sys/boot/efi/boot1/Makefile.com create mode 100644 usr/src/boot/sys/boot/efi/boot1/amd64/Makefile create mode 100644 usr/src/boot/sys/boot/efi/boot1/i386/Makefile create mode 100644 usr/src/boot/sys/boot/efi/libefi/Makefile.com create mode 100644 usr/src/boot/sys/boot/efi/libefi/amd64/Makefile create mode 100644 usr/src/boot/sys/boot/efi/libefi/i386/Makefile create mode 100644 usr/src/boot/sys/boot/efi/loader/Makefile.com create mode 100644 usr/src/boot/sys/boot/efi/loader/amd64/Makefile delete mode 100644 usr/src/boot/sys/boot/efi/loader/arch/amd64/framebuffer.c delete mode 100644 usr/src/boot/sys/boot/efi/loader/arch/amd64/framebuffer.h create mode 100644 usr/src/boot/sys/boot/efi/loader/arch/i386/multiboot_tramp.S create mode 100644 usr/src/boot/sys/boot/efi/loader/framebuffer.c create mode 100644 usr/src/boot/sys/boot/efi/loader/framebuffer.h create mode 100644 usr/src/boot/sys/boot/efi/loader/i386/Makefile delete mode 100644 usr/src/boot/sys/boot/ficl/Makefile delete mode 100644 usr/src/boot/sys/boot/ficl/Makefile.inc delete mode 100644 usr/src/boot/sys/boot/ficl/amd64/Makefile delete mode 100644 usr/src/boot/sys/boot/ficl/ficllocal.h delete mode 100644 usr/src/boot/sys/boot/ficl/i386/Makefile delete mode 100644 usr/src/boot/sys/boot/ficl/softcore/Makefile create mode 100644 usr/src/boot/sys/boot/libficl/Makefile create mode 100644 usr/src/boot/sys/boot/libficl/Makefile.com create mode 100644 usr/src/boot/sys/boot/libficl/amd64/Makefile create mode 100644 usr/src/boot/sys/boot/libficl/ficllocal.h create mode 100644 usr/src/boot/sys/boot/libficl/i386/Makefile create mode 100644 usr/src/boot/sys/boot/libficl/softcore/Makefile (limited to 'usr/src') diff --git a/usr/src/boot/sys/boot/Makefile b/usr/src/boot/sys/boot/Makefile index 7f25b8f1ee..fbda11357b 100644 --- a/usr/src/boot/sys/boot/Makefile +++ b/usr/src/boot/sys/boot/Makefile @@ -18,7 +18,7 @@ include $(SRC)/Makefile.master INSTDIRS = i386 efi -SUBDIRS = libstand ficl zfs $(INSTDIRS) +SUBDIRS = libstand libficl zfs $(INSTDIRS) all := TARGET = all clean := TARGET = clean diff --git a/usr/src/boot/sys/boot/common/bootstrap.h b/usr/src/boot/sys/boot/common/bootstrap.h index 8ea4c6ff92..ed95d140b2 100644 --- a/usr/src/boot/sys/boot/common/bootstrap.h +++ b/usr/src/boot/sys/boot/common/bootstrap.h @@ -317,7 +317,7 @@ struct arch_switch /* * Interface to release the load address. */ - void (*arch_free_loadaddr)(uint64_t addr, uint64_t pages); + void (*arch_free_loadaddr)(vm_offset_t addr, size_t pages); /* * Interface to inform MD code about a loaded (ELF) segment. This diff --git a/usr/src/boot/sys/boot/common/multiboot2.c b/usr/src/boot/sys/boot/common/multiboot2.c index 386bcf2b7a..c0477ecc1a 100644 --- a/usr/src/boot/sys/boot/common/multiboot2.c +++ b/usr/src/boot/sys/boot/common/multiboot2.c @@ -1038,6 +1038,7 @@ multiboot2_exec(struct preloaded_file *fp) } #if defined (EFI) +#ifdef __LP64__ { multiboot_tag_efi64_t *tag; tag = (multiboot_tag_efi64_t *) @@ -1047,6 +1048,17 @@ multiboot2_exec(struct preloaded_file *fp) tag->mb_size = sizeof (*tag); tag->mb_pointer = (uint64_t)(uintptr_t)ST; } +#else + { + multiboot_tag_efi32_t *tag; + tag = (multiboot_tag_efi32_t *) + mb_malloc(sizeof (*tag)); + + tag->mb_type = MULTIBOOT_TAG_TYPE_EFI32; + tag->mb_size = sizeof (*tag); + tag->mb_pointer = (uint32_t)ST; + } +#endif /* __LP64__ */ if (have_framebuffer == true) { multiboot_tag_framebuffer_t *tag; @@ -1218,7 +1230,7 @@ multiboot2_exec(struct preloaded_file *fp) MULTIBOOT_TAG_ALIGN); } chunk = &relocator->rel_chunklist[i++]; - chunk->chunk_vaddr = (EFI_VIRTUAL_ADDRESS)mbi; + chunk->chunk_vaddr = (EFI_VIRTUAL_ADDRESS)(uintptr_t)mbi; chunk->chunk_paddr = efi_physaddr(module, tmp, map, map_size / desc_size, desc_size, mbi->mbi_total_size); chunk->chunk_size = mbi->mbi_total_size; @@ -1247,7 +1259,7 @@ error: free(cmdline); #if defined (EFI) if (mbi != NULL) - efi_free_loadaddr((uint64_t)mbi, EFI_SIZE_TO_PAGES(size)); + efi_free_loadaddr((vm_offset_t)mbi, EFI_SIZE_TO_PAGES(size)); #endif return (error); } diff --git a/usr/src/boot/sys/boot/common/paths.h b/usr/src/boot/sys/boot/common/paths.h index cb154b6caa..3934ef4909 100644 --- a/usr/src/boot/sys/boot/common/paths.h +++ b/usr/src/boot/sys/boot/common/paths.h @@ -30,7 +30,7 @@ #define PATH_DOTCONFIG "/boot.config" #define PATH_CONFIG "/boot/config" #define PATH_LOADER "/boot/loader" -#define PATH_LOADER_EFI "/boot/loader.efi" +#define PATH_LOADER_EFI "/boot/" LOADER_EFI #define PATH_KERNEL "/boot/kernel/kernel" #endif /* _PATHS_H_ */ diff --git a/usr/src/boot/sys/boot/efi/Makefile.inc b/usr/src/boot/sys/boot/efi/Makefile.inc index 2253891b5a..d25885fd01 100644 --- a/usr/src/boot/sys/boot/efi/Makefile.inc +++ b/usr/src/boot/sys/boot/efi/Makefile.inc @@ -17,8 +17,9 @@ BINDIR= /boot # Options used when building app-specific efi components # See conf/kern.mk for the correct set of these -CFLAGS += -m64 -fPIC -ffreestanding -Wformat -msoft-float -CFLAGS += -mno-mmx -mno-sse -mno-avx -fshort-wchar -mno-red-zone -mno-aes +CFLAGS += -fPIC -ffreestanding -Wformat -msoft-float +CFLAGS += -mno-mmx -mno-3dnow -mno-sse2 -mno-sse3 -mno-sse +CFLAGS += -mno-avx -fshort-wchar -mno-aes CFLAGS += -std=gnu99 -Wno-pointer-sign -Wno-empty-body #CFLAGS += -Wsystem-headers -Werror -Wall -Wno-format-y2k -W @@ -28,4 +29,5 @@ CFLAGS += -std=gnu99 -Wno-pointer-sign -Wno-empty-body #CFLAGS += -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls #CFLAGS += -Wold-style-definition +ASFLAGS += -fPIC # include ../Makefile.inc diff --git a/usr/src/boot/sys/boot/efi/boot1/Makefile b/usr/src/boot/sys/boot/efi/boot1/Makefile index 29014c6136..fa72aaecd7 100644 --- a/usr/src/boot/sys/boot/efi/boot1/Makefile +++ b/usr/src/boot/sys/boot/efi/boot1/Makefile @@ -11,126 +11,22 @@ # # Copyright 2016 Toomas Soome -# Copyright 2016 RackTop Systems. # -include $(SRC)/Makefile.master -include $(SRC)/boot/Makefile.version - -CC= $(GNUC_ROOT)/bin/gcc -LD= $(GNU_ROOT)/bin/gld -OBJCOPY= $(GNU_ROOT)/bin/gobjcopy -OBJDUMP= $(GNU_ROOT)/bin/gobjdump - -PROG= boot1.sym -MACHINE=$(MACH64) - -# architecture-specific loader code -SRCS= multiboot.S boot1.c self_reloc.c start.S ufs_module.c zfs_module.c \ - devopen.c -OBJS= multiboot.o boot1.o self_reloc.o start.o ufs_module.o zfs_module.o \ - devopen.o - -ASFLAGS=-m64 -fPIC -CFLAGS= -O2 -CPPFLAGS= -nostdinc -D_STANDALONE -CPPFLAGS += -I. -CPPFLAGS += -I./../include -CPPFLAGS += -I./../include/${MACHINE} -CPPFLAGS += -I$(SRC)/uts/intel/sys/acpi -CPPFLAGS += -I./../../../../include -CPPFLAGS += -I./../../../sys -CPPFLAGS += -I./../../.. -CPPFLAGS += -I../../../../lib/libstand -CPPFLAGS += -DUFS1_ONLY -# CPPFLAGS += -DEFI_DEBUG - -CPPFLAGS += -I./../../zfs/ -CPPFLAGS += -I./../../../cddl/boot/zfs/ - -# Always add MI sources and REGULAR efi loader bits -CPPFLAGS += -I./../../common +.KEEP_STATE: -# For sys/skein.h -CPPFLAGS += -I$(SRC)/uts/common - -include ../Makefile.inc - -FILES= boot1.efi -FILEMODE= 0555 -ROOT_BOOT= $(ROOT)/boot -ROOTBOOTFILES=$(FILES:%=$(ROOT_BOOT)/%) - -LDSCRIPT= ./../loader/arch/${MACHINE}/ldscript.${MACHINE} -LDFLAGS= -nostdlib --eh-frame-hdr -znocombreloc -LDFLAGS += -shared --hash-style=both --enable-new-dtags -LDFLAGS += -T${LDSCRIPT} -Bsymbolic - -all: boot1.efi - -install: all $(ROOTBOOTFILES) - -LIBEFI= ../libefi/libefi.a -# -# Add libstand for the runtime functions used by the compiler - for example -# __aeabi_* (arm) or __divdi3 (i386). -# as well as required string and memory functions for all platforms. -# -LIBSTAND= ../../libstand/$(MACH64)/libstand.a -LIBZFSBOOT= ../../zfs/$(MACH64)/libzfsboot.a -DPADD= $(LIBEFI) $(LIBZFSBOOT) $(LIBSTAND) -LDADD= -L../libefi -lefi -LDADD += -L../../zfs/$(MACH64) -lzfsboot -LDADD += -L../../libstand/$(MACH64) -lstand - -DPADD += ${LDSCRIPT} - -EFI_TARGET= pei-x86-64 - -boot1.efi: ${PROG} - if [ `${OBJDUMP} -t ${PROG} | fgrep '*UND*' | wc -l` != 0 ]; then \ - ${OBJDUMP} -t ${PROG} | fgrep '*UND*'; \ - exit 1; \ - fi - ${OBJCOPY} --readonly-text -j .peheader -j .text -j .sdata -j .data \ - -j .dynamic -j .dynsym -j .rel.dyn \ - -j .rela.dyn -j .reloc -j .eh_frame \ - --output-target=${EFI_TARGET} --subsystem efi-app ${PROG} $@ - $(BTXLD) -V ${BOOT_VERSION} -o $@ $@ - -boot1.o: ./../../common/ufsread.c - -CLEANFILES= boot1.efi ${PROG} - -${PROG}: $(OBJS) $(DPADD) - $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LDADD) - -CLEANFILES += machine x86 - -machine: - $(RM) machine - $(SYMLINK) ./../../../${MACHINE}/include machine - -x86: - $(RM) x86 - $(SYMLINK) ./../../../x86/include x86 - -$(OBJS): machine x86 - -clean clobber: - $(RM) $(CLEANFILES) $(OBJS) +include $(SRC)/Makefile.master -%.o: ../loader/arch/${MACHINE}/%.S - $(COMPILE.S) $< +SUBDIRS = $(MACH) $(MACH64) -%.o: ../loader/%.c - $(COMPILE.c) $< +all := TARGET = all +clean := TARGET = clean +clobber := TARGET = clobber +install := TARGET = install -%.o: ../../common/%.S - $(COMPILE.S) $< +all clean clobber install: $(SUBDIRS) -%.o: ../../common/%.c - $(COMPILE.c) $< +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(MFLAGS) $(TARGET) -$(ROOT_BOOT)/%: % - $(INS.file) +FRC: diff --git a/usr/src/boot/sys/boot/efi/boot1/Makefile.com b/usr/src/boot/sys/boot/efi/boot1/Makefile.com new file mode 100644 index 0000000000..90a0ad00a5 --- /dev/null +++ b/usr/src/boot/sys/boot/efi/boot1/Makefile.com @@ -0,0 +1,131 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome +# + +include $(SRC)/Makefile.master +include $(SRC)/boot/Makefile.version + +CC= $(GNUC_ROOT)/bin/gcc +LD= $(GNU_ROOT)/bin/gld +OBJCOPY= $(GNU_ROOT)/bin/gobjcopy +OBJDUMP= $(GNU_ROOT)/bin/gobjdump + +PROG= boot1.sym + +# architecture-specific loader code +SRCS= multiboot.S boot1.c self_reloc.c start.S ufs_module.c zfs_module.c \ + devopen.c +OBJS= multiboot.o boot1.o self_reloc.o start.o ufs_module.o zfs_module.o \ + devopen.o + +CFLAGS= -O2 +CPPFLAGS= -nostdinc -D_STANDALONE +CPPFLAGS += -I. +CPPFLAGS += -I../../include +CPPFLAGS += -I../../include/$(MACHINE) +CPPFLAGS += -I../../../../../include +CPPFLAGS += -I../../../../sys +CPPFLAGS += -I../../../.. +CPPFLAGS += -I../../../../../lib/libstand +CPPFLAGS += -DUFS1_ONLY +# CPPFLAGS += -DEFI_DEBUG + +CPPFLAGS += -I../../../zfs/ +CPPFLAGS += -I../../../../cddl/boot/zfs/ + +# Always add MI sources and REGULAR efi loader bits +CPPFLAGS += -I../../../common + +# For sys/skein.h +CPPFLAGS += -I$(SRC)/uts/common + +include ../../Makefile.inc + +FILES= $(EFIPROG) +FILEMODE= 0555 +ROOT_BOOT= $(ROOT)/boot +ROOTBOOTFILES=$(FILES:%=$(ROOT_BOOT)/%) + +LDSCRIPT= ../../loader/arch/$(MACHINE)/ldscript.$(MACHINE) +LDFLAGS= -nostdlib --eh-frame-hdr +LDFLAGS += -shared --hash-style=both --enable-new-dtags +LDFLAGS += -T$(LDSCRIPT) -Bsymbolic + +install: all $(ROOTBOOTFILES) + +LIBEFI= ../../libefi/$(MACHINE)/libefi.a +# +# Add libstand for the runtime functions used by the compiler - for example +# __aeabi_* (arm) or __divdi3 (i386). +# as well as required string and memory functions for all platforms. +# +LIBSTAND= ../../../libstand/$(MACHINE)/libstand.a +LIBZFSBOOT= ../../../zfs/$(MACHINE)/libzfsboot.a +DPADD= $(LIBEFI) $(LIBZFSBOOT) $(LIBSTAND) +LDADD= -L../../libefi/$(MACHINE) -lefi +LDADD += -L../../../zfs/$(MACHINE) -lzfsboot +LDADD += -L../../../libstand/$(MACHINE) -lstand + +DPADD += $(LDSCRIPT) + +$(EFIPROG): $(PROG) + if [ `$(OBJDUMP) -t $(PROG) | fgrep '*UND*' | wc -l` != 0 ]; then \ + $(OBJDUMP) -t $(PROG) | fgrep '*UND*'; \ + exit 1; \ + fi + $(OBJCOPY) --readonly-text -j .peheader -j .text -j .sdata -j .data \ + -j .dynamic -j .dynsym -j .rel.dyn \ + -j .rela.dyn -j .reloc -j .eh_frame \ + --output-target=$(EFI_TARGET) --subsystem efi-app $(PROG) $@ + $(BTXLD) -V $(BOOT_VERSION) -o $@ $@ + +boot1.o: ../../../common/ufsread.c + +CLEANFILES= $(EFIPROG) $(PROG) + +$(PROG): $(OBJS) $(DPADD) + $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LDADD) + +machine: + $(RM) machine + $(SYMLINK) ../../../../$(MACHINE)/include machine + +x86: + $(RM) x86 + $(SYMLINK) ../../../../x86/include x86 + +clean clobber: + $(RM) $(CLEANFILES) $(OBJS) + +%.o: ../../../common/%.S + $(COMPILE.S) $< + +%.o: ../%.c + $(COMPILE.c) $< + +# +# using -W to silence gas here, as for 32bit build, it will generate warning +# for start.S because hand crafted .reloc section does not have group name +# +%.o: ../../loader/arch/$(MACHINE)/%.S + $(COMPILE.S) -Wa,-W $< + +%.o: ../../loader/%.c + $(COMPILE.c) $< + +%.o: ../../../common/%.c + $(COMPILE.c) $< + +$(ROOT_BOOT)/%: % + $(INS.file) diff --git a/usr/src/boot/sys/boot/efi/boot1/amd64/Makefile b/usr/src/boot/sys/boot/efi/boot1/amd64/Makefile new file mode 100644 index 0000000000..24d3c17a1e --- /dev/null +++ b/usr/src/boot/sys/boot/efi/boot1/amd64/Makefile @@ -0,0 +1,33 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. +# + +MACHINE= $(MACH64) +ASFLAGS= -m64 +EFIPROG= bootx64.efi + +all: $(EFIPROG) + +include ../Makefile.com + +EFI_TARGET= pei-x86-64 +LDFLAGS += -znocombreloc + +CPPFLAGS += -DLOADER_EFI=\"loader64.efi\" +CFLAGS += -m64 -mno-red-zone + +CLEANFILES += machine x86 + +$(OBJS): machine x86 diff --git a/usr/src/boot/sys/boot/efi/boot1/i386/Makefile b/usr/src/boot/sys/boot/efi/boot1/i386/Makefile new file mode 100644 index 0000000000..4d01edc6fa --- /dev/null +++ b/usr/src/boot/sys/boot/efi/boot1/i386/Makefile @@ -0,0 +1,33 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. +# + +MACHINE= $(MACH) +ASFLAGS= -m32 +EFIPROG= bootia32.efi + +all: $(EFIPROG) + +include ../Makefile.com + +EFI_TARGET= pei-i386 +LDFLAGS += -znocombreloc + +CPPFLAGS += -DLOADER_EFI=\"loader32.efi\" +CFLAGS += -m32 + +CLEANFILES += machine x86 + +$(OBJS): machine x86 diff --git a/usr/src/boot/sys/boot/efi/boot1/zfs_module.c b/usr/src/boot/sys/boot/efi/boot1/zfs_module.c index a60e4432d7..6617e417df 100644 --- a/usr/src/boot/sys/boot/efi/boot1/zfs_module.c +++ b/usr/src/boot/sys/boot/efi/boot1/zfs_module.c @@ -180,8 +180,9 @@ load(const char *filepath, dev_info_t *devinfo, void **bufp, size_t *bufsize) if ((status = BS->AllocatePool(EfiLoaderData, (UINTN)st.st_size, &buf)) != EFI_SUCCESS) { - printf("Failed to allocate load buffer %zd for pool '%s' for '%s' " - "(%lu)\n", st.st_size, spa->spa_name, filepath, EFI_ERROR_CODE(status)); + printf("Failed to allocate load buffer %zd for pool '%s' " + "for '%s' (%lu)\n", (ssize_t)st.st_size, spa->spa_name, + filepath, EFI_ERROR_CODE(status)); return (EFI_INVALID_PARAMETER); } diff --git a/usr/src/boot/sys/boot/efi/include/amd64/efibind.h b/usr/src/boot/sys/boot/efi/include/amd64/efibind.h index 6b0465b627..4cd25ed54b 100644 --- a/usr/src/boot/sys/boot/efi/include/amd64/efibind.h +++ b/usr/src/boot/sys/boot/efi/include/amd64/efibind.h @@ -1,4 +1,3 @@ -/* $FreeBSD$ */ /*++ Copyright (c) 1999 - 2003 Intel Corporation. All rights reserved @@ -29,57 +28,6 @@ Revision History #include -#if 0 -// -// Basic int types of various widths -// - -#if (__STDC_VERSION__ < 199901L ) - - // No ANSI C 1999/2000 stdint.h integer width declarations - - #ifdef _MSC_EXTENSIONS - - // Use Microsoft C compiler integer width declarations - - typedef unsigned __int64 uint64_t; - typedef __int64 int64_t; - typedef unsigned __int32 uint32_t; - typedef __int32 int32_t; - typedef unsigned short uint16_t; - typedef short int16_t; - typedef unsigned char uint8_t; - typedef char int8_t; - #else - #ifdef UNIX_LP64 - - // Use LP64 programming model from C_FLAGS for integer width declarations - - typedef unsigned long uint64_t; - typedef long int64_t; - typedef unsigned int uint32_t; - typedef int int32_t; - typedef unsigned short uint16_t; - typedef short int16_t; - typedef unsigned char uint8_t; - typedef char int8_t; - #else - - // Assume P64 programming model from C_FLAGS for integer width declarations - - typedef unsigned long long uint64_t; - typedef long long int64_t; - typedef unsigned int uint32_t; - typedef int int32_t; - typedef unsigned short uint16_t; - typedef short int16_t; - typedef unsigned char uint8_t; - typedef char int8_t; - #endif - #endif -#endif -#endif - // // Basic EFI types of various widths // @@ -249,19 +197,6 @@ typedef uint64_t UINTN; #endif // EFI_FW_NT #define INTERFACE_DECL(x) struct x -#if 0 -// -// Some compilers don't support the forward reference construct: -// typedef struct XXXXX -// -// The following macro provide a workaround for such cases. -// -#ifdef NO_INTERFACE_DECL -#define INTERFACE_DECL(x) -#else -#define INTERFACE_DECL(x) typedef struct x -#endif -#endif /* __FreeBSD__ */ #ifdef _MSC_EXTENSIONS #pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP diff --git a/usr/src/boot/sys/boot/efi/include/i386/efibind.h b/usr/src/boot/sys/boot/efi/include/i386/efibind.h index fee8d3a92c..3bbed66176 100644 --- a/usr/src/boot/sys/boot/efi/include/i386/efibind.h +++ b/usr/src/boot/sys/boot/efi/include/i386/efibind.h @@ -1,4 +1,3 @@ -/* $FreeBSD$ */ /*++ Copyright (c) 1999 - 2003 Intel Corporation. All rights reserved @@ -28,58 +27,7 @@ Revision History #pragma pack() -#ifdef __FreeBSD__ #include -#else -// -// Basic int types of various widths -// - -#if (__STDC_VERSION__ < 199901L ) - - // No ANSI C 1999/2000 stdint.h integer width declarations - - #ifdef _MSC_EXTENSIONS - - // Use Microsoft C compiler integer width declarations - - typedef unsigned __int64 uint64_t; - typedef __int64 int64_t; - typedef unsigned __int32 uint32_t; - typedef __int32 int32_t; - typedef unsigned short uint16_t; - typedef short int16_t; - typedef unsigned char uint8_t; - typedef char int8_t; - #else - #ifdef UNIX_LP64 - - // Use LP64 programming model from C_FLAGS for integer width declarations - - typedef unsigned long uint64_t; - typedef long int64_t; - typedef unsigned int uint32_t; - typedef int int32_t; - typedef unsigned short uint16_t; - typedef short int16_t; - typedef unsigned char uint8_t; - typedef char int8_t; - #else - - // Assume P64 programming model from C_FLAGS for integer width declarations - - typedef unsigned long long uint64_t; - typedef long long int64_t; - typedef unsigned int uint32_t; - typedef int int32_t; - typedef unsigned short uint16_t; - typedef short int16_t; - typedef unsigned char uint8_t; - typedef char int8_t; - #endif - #endif -#endif -#endif /* __FreeBSD__ */ // // Basic EFI types of various widths @@ -245,23 +193,8 @@ typedef uint32_t UINTN; #endif // EFI_FW_NT -#ifdef __FreeBSD__ #define INTERFACE_DECL(x) struct x -#else -// -// Some compilers don't support the forward reference construct: -// typedef struct XXXXX -// -// The following macro provide a workaround for such cases. -// -#ifdef NO_INTERFACE_DECL -#define INTERFACE_DECL(x) -#else -#define INTERFACE_DECL(x) typedef struct x -#endif -#endif /* __FreeBSD__ */ #ifdef _MSC_EXTENSIONS #pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP #endif - diff --git a/usr/src/boot/sys/boot/efi/libefi/Makefile b/usr/src/boot/sys/boot/efi/libefi/Makefile index 768c792817..482bfd2b4d 100644 --- a/usr/src/boot/sys/boot/efi/libefi/Makefile +++ b/usr/src/boot/sys/boot/efi/libefi/Makefile @@ -10,86 +10,25 @@ # # -# Copyright 2015 Toomas Soome -# Copyright 2016 RackTop Systems. +# Copyright 2016 Toomas Soome # -include $(SRC)/Makefile.master - -CC= $(GNUC_ROOT)/bin/gcc - -LIB= efi - -all: lib$(LIB).a - -install: - -SRCS= delay.c \ - devicename.c \ - devpath.c \ - efi_console.c \ - efi_driver_utils.c \ - efichar.c \ - efienv.c \ - efinet.c \ - efipart.c \ - efizfs.c \ - env.c \ - errno.c \ - handles.c \ - libefi.c \ - time.c \ - wchar.c - -#.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" -#SRCS += time.c -#.elif ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "arm" -#SRCS+= time_event.c -#.endif +.KEEP_STATE: -OBJS= $(SRCS:%.c=%.o) - -CPPFLAGS= -D_STANDALONE -CFLAGS = -O2 - -#.if ${MACHINE_CPUARCH} == "aarch64" -#CFLAGS+= -msoft-float -mgeneral-regs-only -#.endif -#.if ${MACHINE_ARCH} == "amd64" -CFLAGS += -fPIC -#.endif - -CFLAGS += -nostdinc -I. -I../../../../include -I../../.. -CFLAGS += -I$(SRC)/common/ficl -I../../ficl -CFLAGS += -I../include -CFLAGS += -I../include/${MACH64} -CFLAGS += -I../../../../lib/libstand -CFLAGS += -I./../../zfs -CFLAGS += -I./../../../cddl/boot/zfs - -# Pick up the bootstrap header for some interface items -CFLAGS += -I../../common - -# Handle FreeBSD specific %b and %D printf format specifiers -# CFLAGS+= ${FORMAT_EXTENSIONS} -# CFLAGS += -D__printf__=__freebsd_kprintf__ -CFLAGS += -DTERM_EMU +include $(SRC)/Makefile.master -include ../Makefile.inc +SUBDIRS = $(MACH) $(MACH64) -lib$(LIB).a: $(SRCS) $(OBJS) - $(AR) $(ARFLAGS) $@ $(OBJS) +all := TARGET = all +clean := TARGET = clean +clobber := TARGET = clobber +install := TARGET = install -clean: clobber -clobber: - $(RM) $(CLEANFILES) $(OBJS) machine x86 lib$(LIB).a +all clean clobber: $(SUBDIRS) -machine: - $(RM) machine - $(SYMLINK) ../../../amd64/include machine +install: all -x86: - $(RM) x86 - $(SYMLINK) ../../../x86/include x86 +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(MFLAGS) $(TARGET) -$(OBJS): machine x86 +FRC: diff --git a/usr/src/boot/sys/boot/efi/libefi/Makefile.com b/usr/src/boot/sys/boot/efi/libefi/Makefile.com new file mode 100644 index 0000000000..84fffc9864 --- /dev/null +++ b/usr/src/boot/sys/boot/efi/libefi/Makefile.com @@ -0,0 +1,73 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome +# + +include $(SRC)/Makefile.master + +CC= $(GNUC_ROOT)/bin/gcc + +install: + +SRCS += delay.c \ + devicename.c \ + devpath.c \ + efi_console.c \ + efi_driver_utils.c \ + efichar.c \ + efienv.c \ + efinet.c \ + efipart.c \ + efizfs.c \ + env.c \ + errno.c \ + handles.c \ + libefi.c \ + wchar.c + +OBJS= $(SRCS:%.c=%.o) + +CPPFLAGS= -D_STANDALONE +CFLAGS = -O2 + +CPPFLAGS += -nostdinc -I. -I../../../../../include -I../../../.. +CPPFLAGS += -I$(SRC)/common/ficl -I../../../libficl +CPPFLAGS += -I../../include +CPPFLAGS += -I../../include/$(MACHINE) +CPPFLAGS += -I../../../../../lib/libstand +CPPFLAGS += -I../../../zfs +CPPFLAGS += -I../../../../cddl/boot/zfs + +# Pick up the bootstrap header for some interface items +CPPFLAGS += -I../../../common +CPPFLAGS += -DTERM_EMU + +include ../../Makefile.inc + +libefi.a: $(OBJS) + $(AR) $(ARFLAGS) $@ $(OBJS) + +clean: clobber +clobber: + $(RM) $(CLEANFILES) $(OBJS) libefi.a + +machine: + $(RM) machine + $(SYMLINK) ../../../../$(MACHINE)/include machine + +x86: + $(RM) x86 + $(SYMLINK) ../../../../x86/include x86 + +%.o: ../%.c + $(COMPILE.c) $< diff --git a/usr/src/boot/sys/boot/efi/libefi/amd64/Makefile b/usr/src/boot/sys/boot/efi/libefi/amd64/Makefile new file mode 100644 index 0000000000..5994a68d7a --- /dev/null +++ b/usr/src/boot/sys/boot/efi/libefi/amd64/Makefile @@ -0,0 +1,29 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. +# + +MACHINE= $(MACH64) +ASFLAGS= -m64 + +all: libefi.a + +SRCS= time.c +include ../Makefile.com + +CFLAGS += -m64 + +CLEANFILES += machine x86 + +$(OBJS): machine x86 diff --git a/usr/src/boot/sys/boot/efi/libefi/i386/Makefile b/usr/src/boot/sys/boot/efi/libefi/i386/Makefile new file mode 100644 index 0000000000..8e9691699c --- /dev/null +++ b/usr/src/boot/sys/boot/efi/libefi/i386/Makefile @@ -0,0 +1,29 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. +# + +MACHINE= $(MACH) +ASFLAGS= -m32 + +all: libefi.a + +SRCS= time.c +include ../Makefile.com + +CFLAGS += -m32 + +CLEANFILES += machine x86 + +$(OBJS): machine x86 diff --git a/usr/src/boot/sys/boot/efi/loader/Makefile b/usr/src/boot/sys/boot/efi/loader/Makefile index 40b1198998..fa72aaecd7 100644 --- a/usr/src/boot/sys/boot/efi/loader/Makefile +++ b/usr/src/boot/sys/boot/efi/loader/Makefile @@ -11,157 +11,22 @@ # # Copyright 2016 Toomas Soome -# Copyright 2016 RackTop Systems. # -include $(SRC)/Makefile.master -include $(SRC)/boot/Makefile.version - -CC= $(GNUC_ROOT)/bin/gcc -LD= $(GNU_ROOT)/bin/gld -OBJCOPY= $(GNU_ROOT)/bin/gobjcopy -OBJDUMP= $(GNU_ROOT)/bin/gobjdump - -PROG= loader.sym -MACHINE= $(MACH64) - -# architecture-specific loader code -SRCS= autoload.c bootinfo.c conf.c copy.c efi_main.c main.c \ - self_reloc.c smbios.c acpi.c vers.c memmap.c multiboot2.c -OBJS= autoload.o bootinfo.o conf.o copy.o efi_main.o main.o \ - self_reloc.o smbios.o acpi.o vers.o memmap.o multiboot2.o - -ASFLAGS=-m64 -fPIC -CFLAGS= -O2 -CPPFLAGS= -nostdinc -I../../../../include -I../../.. -CPPFLAGS += -I../../../../lib/libstand - -include ../Makefile.inc - -include arch/${MACHINE}/Makefile.inc - -CPPFLAGS += -I. -CPPFLAGS += -I./arch/${MACHINE} -CPPFLAGS += -I./../include -CPPFLAGS += -I./../include/${MACHINE} -CPPFLAGS += -I$(SRC)/uts/intel/sys/acpi -CPPFLAGS += -I./../../.. -CPPFLAGS += -I./../../i386/libi386 -CPPFLAGS += -I./../../zfs -CPPFLAGS += -I./../../../cddl/boot/zfs -CPPFLAGS += -DNO_PCI -DEFI -DTERM_EMU - -# Export serial numbers, UUID, and asset tag from loader. -CPPFLAGS += -DSMBIOS_SERIAL_NUMBERS -# Use little-endian UUID format as defined in SMBIOS 2.6. -CPPFLAGS += -DSMBIOS_LITTLE_ENDIAN_UUID -# Use network-endian UUID format for backward compatibility. -#CPPFLAGS += -DSMBIOS_NETWORK_ENDIAN_UUID - -LIBSTAND= ../../libstand/${MACHINE}/libstand.a - -BOOT_FORTH= yes -CPPFLAGS += -DBOOT_FORTH -D_STANDALONE -CPPFLAGS += -I$(SRC)/common/ficl -CPPFLAGS += -I../../ficl -LIBFICL= ../../ficl/${MACHINE}/libficl.a - -CPPFLAGS += -I../../zfs -LIBZFSBOOT= ../../zfs/${MACHINE}/libzfsboot.a - -#LOADER_FDT_SUPPORT?= no -#.if ${MK_FDT} != "no" && ${LOADER_FDT_SUPPORT} != "no" -#CFLAGS+= -I${.CURDIR}/../../fdt -#CFLAGS+= -I${.OBJDIR}/../../fdt -#CFLAGS+= -DLOADER_FDT_SUPPORT -#LIBEFI_FDT= ${.OBJDIR}/../../efi/fdt/libefi_fdt.a -#LIBFDT= ${.OBJDIR}/../../fdt/libfdt.a -#.endif - -# Always add MI sources -include ./Makefile.common -CPPFLAGS += -I../../common - -# For multiboot2.h, must be last, to avoid conflicts -CPPFLAGS += -I$(SRC)/uts/common - -FILES= loader.efi -FILEMODE= 0555 -ROOT_BOOT= $(ROOT)/boot -ROOTBOOTFILES=$(FILES:%=$(ROOT_BOOT)/%) - -LDSCRIPT= ./arch/${MACHINE}/ldscript.${MACHINE} -LDFLAGS = -nostdlib --eh-frame-hdr -znocombreloc -LDFLAGS += -shared --hash-style=both --enable-new-dtags -LDFLAGS += -T${LDSCRIPT} -Bsymbolic - -CLEANFILES= vers.c loader.efi +.KEEP_STATE: -NEWVERSWHAT= "EFI loader" ${MACHINE} - -all: loader.efi - -install: all $(ROOTBOOTFILES) - -vers.c: ../../common/newvers.sh $(SRC)/boot/Makefile.version - $(SH) ../../common/newvers.sh ${LOADER_VERSION} ${NEWVERSWHAT} - -EFI_TARGET= pei-x86-64 - -loader.efi: loader.sym - if [ `${OBJDUMP} -t loader.sym | fgrep '*UND*' | wc -l` != 0 ]; then \ - ${OBJDUMP} -t loader.sym | fgrep '*UND*'; \ - exit 1; \ - fi - ${OBJCOPY} --readonly-text -j .peheader -j .text -j .sdata -j .data \ - -j .dynamic -j .dynsym -j .rel.dyn \ - -j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \ - -j set_Xficl_compile_set \ - --output-target=${EFI_TARGET} --subsystem efi-app loader.sym $@ - -LIBEFI= ../libefi/libefi.a - -DPADD= ${LIBFICL} ${LIBZFSBOOT} ${LIBEFI} ${LIBFDT} ${LIBEFI_FDT} \ - ${LIBSTAND} ${LDSCRIPT} -LDADD= ${LIBFICL} ${LIBZFSBOOT} ${LIBEFI} ${LIBFDT} ${LIBEFI_FDT} \ - ${LIBSTAND} - - -loader.sym: $(OBJS) $(DPADD) - $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LDADD) - -CLEANFILES += machine x86 - -machine: - $(RM) machine - $(SYMLINK) ../../../${MACHINE}/include machine - -x86: - $(RM) x86 - $(SYMLINK) ../../../x86/include x86 - -$(OBJS): machine x86 - -clean clobber: - $(RM) $(CLEANFILES) $(OBJS) loader.sym loader.efi - -%.o: %.c - $(COMPILE.c) $< - -%.o: ./arch/${MACHINE}/%.c - $(COMPILE.c) $< +include $(SRC)/Makefile.master -%.o: ./arch/${MACHINE}/%.S - $(COMPILE.S) $< +SUBDIRS = $(MACH) $(MACH64) -%.o: ../../common/%.c - $(COMPILE.c) $< +all := TARGET = all +clean := TARGET = clean +clobber := TARGET = clobber +install := TARGET = install -%.o: ../../common/linenoise/%.c - $(COMPILE.c) $< +all clean clobber install: $(SUBDIRS) -%.o: ../../i386/libi386/%.c - $(COMPILE.c) $< +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(MFLAGS) $(TARGET) -$(ROOT_BOOT)/%: % - $(INS.file) +FRC: diff --git a/usr/src/boot/sys/boot/efi/loader/Makefile.com b/usr/src/boot/sys/boot/efi/loader/Makefile.com new file mode 100644 index 0000000000..e9397e10ec --- /dev/null +++ b/usr/src/boot/sys/boot/efi/loader/Makefile.com @@ -0,0 +1,156 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome +# + +include $(SRC)/Makefile.master +include $(SRC)/boot/Makefile.version + +CC= $(GNUC_ROOT)/bin/gcc +LD= $(GNU_ROOT)/bin/gld +OBJCOPY= $(GNU_ROOT)/bin/gobjcopy +OBJDUMP= $(GNU_ROOT)/bin/gobjdump + +PROG= loader.sym + +# architecture-specific loader code +SRCS= autoload.c bootinfo.c conf.c copy.c efi_main.c framebuffer.c main.c \ + self_reloc.c smbios.c acpi.c vers.c memmap.c multiboot2.c + +OBJS= autoload.o bootinfo.o conf.o copy.o efi_main.o framebuffer.o main.o \ + self_reloc.o smbios.o acpi.o vers.o memmap.o multiboot2.o + +CFLAGS= -O2 +CPPFLAGS= -nostdinc -I../../../../../include -I../../..../ +CPPFLAGS += -I../../../../../lib/libstand + +include ../../Makefile.inc + +include ../arch/$(MACHINE)/Makefile.inc + +CPPFLAGS += -I. -I.. +CPPFLAGS += -I../../include +CPPFLAGS += -I../../include/$(MACHINE) +CPPFLAGS += -I../../../.. +CPPFLAGS += -I../../../i386/libi386 +CPPFLAGS += -I../../../zfs +CPPFLAGS += -I../../../../cddl/boot/zfs +CPPFLAGS += -I$(SRC)/uts/intel/sys/acpi +CPPFLAGS += -DEFI_ZFS_BOOT +CPPFLAGS += -DNO_PCI -DEFI -DTERM_EMU + +# Export serial numbers, UUID, and asset tag from loader. +CPPFLAGS += -DSMBIOS_SERIAL_NUMBERS +# Use little-endian UUID format as defined in SMBIOS 2.6. +CPPFLAGS += -DSMBIOS_LITTLE_ENDIAN_UUID +# Use network-endian UUID format for backward compatibility. +#CPPFLAGS += -DSMBIOS_NETWORK_ENDIAN_UUID + +LIBSTAND= ../../../libstand/$(MACHINE)/libstand.a + +BOOT_FORTH= yes +CPPFLAGS += -DBOOT_FORTH -D_STANDALONE +CPPFLAGS += -I$(SRC)/common/ficl +CPPFLAGS += -I../../../libficl +LIBFICL= ../../../libficl/$(MACHINE)/libficl.a + +CPPFLAGS += -I../../../zfs +LIBZFSBOOT= ../../../zfs/$(MACHINE)/libzfsboot.a + +# Always add MI sources +include ../Makefile.common +CPPFLAGS += -I../../../common + +# For multiboot2.h, must be last, to avoid conflicts +CPPFLAGS += -I$(SRC)/uts/common + +FILES= $(EFIPROG) +FILEMODE= 0555 +ROOT_BOOT= $(ROOT)/boot +ROOTBOOTFILES=$(FILES:%=$(ROOT_BOOT)/%) + +LDSCRIPT= ../arch/$(MACHINE)/ldscript.$(MACHINE) +LDFLAGS = -nostdlib --eh-frame-hdr +LDFLAGS += -shared --hash-style=both --enable-new-dtags +LDFLAGS += -T$(LDSCRIPT) -Bsymbolic + +CLEANFILES= 8x16.c vers.c + +NEWVERSWHAT= "EFI loader" $(MACHINE) + +install: all $(ROOTBOOTFILES) + +vers.c: ../../../common/newvers.sh $(SRC)/boot/Makefile.version + $(SH) ../../../common/newvers.sh $(LOADER_VERSION) $(NEWVERSWHAT) + +$(EFIPROG): loader.sym + if [ `$(OBJDUMP) -t loader.sym | fgrep '*UND*' | wc -l` != 0 ]; then \ + $(OBJDUMP) -t loader.sym | fgrep '*UND*'; \ + exit 1; \ + fi + $(OBJCOPY) --readonly-text -j .peheader -j .text -j .sdata -j .data \ + -j .dynamic -j .dynsym -j .rel.dyn \ + -j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \ + -j set_Xficl_compile_set \ + --output-target=$(EFI_TARGET) --subsystem efi-app loader.sym $@ + +LIBEFI= ../../libefi/$(MACHINE)/libefi.a + +DPADD= $(LIBFICL) $(LIBZFSBOOT) $(LIBEFI) $(LIBSTAND) $(LDSCRIPT) +LDADD= $(LIBFICL) $(LIBZFSBOOT) $(LIBEFI) $(LIBSTAND) + + +loader.sym: $(OBJS) $(DPADD) + $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LDADD) + +machine: + $(RM) machine + $(SYMLINK) ../../../../$(MACHINE)/include machine + +x86: + $(RM) x86 + $(SYMLINK) ../../../../x86/include x86 + +clean clobber: + $(RM) $(CLEANFILES) $(OBJS) loader.sym + +%.o: ../%.c + $(COMPILE.c) $< + +%.o: ../arch/$(MACHINE)/%.c + $(COMPILE.c) $< + +# +# using -W to silence gas here, as for 32bit build, it will generate warning +# for start.S because hand crafted .reloc section does not have group name +# +%.o: ../arch/$(MACHINE)/%.S + $(COMPILE.S) -Wa,-W $< + +%.o: ../../../common/%.c + $(COMPILE.c) $< + +%.o: ../../../common/linenoise/%.c + $(COMPILE.c) $< + +%.o: ../../../i386/libi386/%.c + $(COMPILE.c) $< + +%.o: $(SRC)/common/list/%.c + $(COMPILE.c) -DNDEBUG $< + +%.o: $(SRC)/uts/common/io/font/%.c + $(COMPILE.c) $< + +$(ROOT_BOOT)/%: % + $(INS.file) diff --git a/usr/src/boot/sys/boot/efi/loader/amd64/Makefile b/usr/src/boot/sys/boot/efi/loader/amd64/Makefile new file mode 100644 index 0000000000..540894dce0 --- /dev/null +++ b/usr/src/boot/sys/boot/efi/loader/amd64/Makefile @@ -0,0 +1,33 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. +# + +MACHINE= $(MACH64) +ASFLAGS= -m64 +EFIPROG= loader64.efi + +all: $(EFIPROG) + +include ../Makefile.com + +EFI_TARGET= pei-x86-64 +LDFLAGS += -znocombreloc + +efi_main.o := CPPFLAGS += -DLOADER_EFI=L\"loader64.efi\" +CFLAGS += -m64 + +CLEANFILES += machine x86 $(EFIPROG) + +$(OBJS): machine x86 diff --git a/usr/src/boot/sys/boot/efi/loader/arch/amd64/Makefile.inc b/usr/src/boot/sys/boot/efi/loader/arch/amd64/Makefile.inc index 47dd322f91..be90666341 100644 --- a/usr/src/boot/sys/boot/efi/loader/arch/amd64/Makefile.inc +++ b/usr/src/boot/sys/boot/efi/loader/arch/amd64/Makefile.inc @@ -1,13 +1,11 @@ SRCS += multiboot_tramp.S \ start.S \ - framebuffer.c \ trap.c \ exc.S OBJS += multiboot_tramp.o \ start.o \ - framebuffer.o \ trap.o \ exc.o @@ -18,6 +16,3 @@ SRCS += nullconsole.c \ OBJS += nullconsole.o \ spinconsole.o \ comconsole.o - -CFLAGS += -fPIC -LDFLAGS += -znocombreloc diff --git a/usr/src/boot/sys/boot/efi/loader/arch/amd64/framebuffer.c b/usr/src/boot/sys/boot/efi/loader/arch/amd64/framebuffer.c deleted file mode 100644 index f31704bdb9..0000000000 --- a/usr/src/boot/sys/boot/efi/loader/arch/amd64/framebuffer.c +++ /dev/null @@ -1,568 +0,0 @@ -/*- - * Copyright (c) 2013 The FreeBSD Foundation - * All rights reserved. - * - * This software was developed by Benno Rice under sponsorship from - * the FreeBSD Foundation. - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "framebuffer.h" - -static EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; -static EFI_GUID pciio_guid = EFI_PCI_IO_PROTOCOL_GUID; -static EFI_GUID uga_guid = EFI_UGA_DRAW_PROTOCOL_GUID; - -static u_int -efifb_color_depth(struct efi_fb *efifb) -{ - uint32_t mask; - u_int depth; - - mask = efifb->fb_mask_red | efifb->fb_mask_green | - efifb->fb_mask_blue | efifb->fb_mask_reserved; - if (mask == 0) - return (0); - for (depth = 1; mask != 1; depth++) - mask >>= 1; - return (depth); -} - -static int -efifb_mask_from_pixfmt(struct efi_fb *efifb, EFI_GRAPHICS_PIXEL_FORMAT pixfmt, - EFI_PIXEL_BITMASK *pixinfo) -{ - int result; - - result = 0; - switch (pixfmt) { - case PixelRedGreenBlueReserved8BitPerColor: - efifb->fb_mask_red = 0x000000ff; - efifb->fb_mask_green = 0x0000ff00; - efifb->fb_mask_blue = 0x00ff0000; - efifb->fb_mask_reserved = 0xff000000; - break; - case PixelBlueGreenRedReserved8BitPerColor: - efifb->fb_mask_red = 0x00ff0000; - efifb->fb_mask_green = 0x0000ff00; - efifb->fb_mask_blue = 0x000000ff; - efifb->fb_mask_reserved = 0xff000000; - break; - case PixelBitMask: - efifb->fb_mask_red = pixinfo->RedMask; - efifb->fb_mask_green = pixinfo->GreenMask; - efifb->fb_mask_blue = pixinfo->BlueMask; - efifb->fb_mask_reserved = pixinfo->ReservedMask; - break; - default: - result = 1; - break; - } - return (result); -} - -static int -efifb_from_gop(struct efi_fb *efifb, EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *mode, - EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info) -{ - int result; - - efifb->fb_addr = mode->FrameBufferBase; - efifb->fb_size = mode->FrameBufferSize; - efifb->fb_height = info->VerticalResolution; - efifb->fb_width = info->HorizontalResolution; - efifb->fb_stride = info->PixelsPerScanLine; - result = efifb_mask_from_pixfmt(efifb, info->PixelFormat, - &info->PixelInformation); - return (result); -} - -static ssize_t -efifb_uga_find_pixel(EFI_UGA_DRAW_PROTOCOL *uga, u_int line, - EFI_PCI_IO_PROTOCOL *pciio, uint64_t addr, uint64_t size) -{ - EFI_UGA_PIXEL pix0, pix1; - uint8_t *data1, *data2; - size_t count, maxcount = 1024; - ssize_t ofs; - EFI_STATUS status; - u_int idx; - - status = uga->Blt(uga, &pix0, EfiUgaVideoToBltBuffer, - 0, line, 0, 0, 1, 1, 0); - if (EFI_ERROR(status)) { - printf("UGA BLT operation failed (video->buffer)"); - return (-1); - } - pix1.Red = ~pix0.Red; - pix1.Green = ~pix0.Green; - pix1.Blue = ~pix0.Blue; - pix1.Reserved = 0; - - data1 = calloc(maxcount, 2); - if (data1 == NULL) { - printf("Unable to allocate memory"); - return (-1); - } - data2 = data1 + maxcount; - - ofs = 0; - while (size > 0) { - count = min(size, maxcount); - - status = pciio->Mem.Read(pciio, EfiPciIoWidthUint32, - EFI_PCI_IO_PASS_THROUGH_BAR, addr + ofs, count >> 2, - data1); - if (EFI_ERROR(status)) { - printf("Error reading frame buffer (before)"); - goto fail; - } - status = uga->Blt(uga, &pix1, EfiUgaBltBufferToVideo, - 0, 0, 0, line, 1, 1, 0); - if (EFI_ERROR(status)) { - printf("UGA BLT operation failed (modify)"); - goto fail; - } - status = pciio->Mem.Read(pciio, EfiPciIoWidthUint32, - EFI_PCI_IO_PASS_THROUGH_BAR, addr + ofs, count >> 2, - data2); - if (EFI_ERROR(status)) { - printf("Error reading frame buffer (after)"); - goto fail; - } - status = uga->Blt(uga, &pix0, EfiUgaBltBufferToVideo, - 0, 0, 0, line, 1, 1, 0); - if (EFI_ERROR(status)) { - printf("UGA BLT operation failed (restore)"); - goto fail; - } - for (idx = 0; idx < count; idx++) { - if (data1[idx] != data2[idx]) { - free(data1); - return (ofs + (idx & ~3)); - } - } - ofs += count; - size -= count; - } - printf("No change detected in frame buffer"); - - fail: - printf(" -- error %lu\n", EFI_ERROR_CODE(status)); - free(data1); - return (-1); -} - -static EFI_PCI_IO_PROTOCOL * -efifb_uga_get_pciio(void) -{ - EFI_PCI_IO_PROTOCOL *pciio; - EFI_HANDLE *buf, *hp; - EFI_STATUS status; - UINTN bufsz; - - /* Get all handles that support the UGA protocol. */ - bufsz = 0; - status = BS->LocateHandle(ByProtocol, &uga_guid, NULL, &bufsz, NULL); - if (status != EFI_BUFFER_TOO_SMALL) - return (NULL); - buf = malloc(bufsz); - status = BS->LocateHandle(ByProtocol, &uga_guid, NULL, &bufsz, buf); - if (status != EFI_SUCCESS) { - free(buf); - return (NULL); - } - bufsz /= sizeof(EFI_HANDLE); - - /* Get the PCI I/O interface of the first handle that supports it. */ - pciio = NULL; - for (hp = buf; hp < buf + bufsz; hp++) { - status = BS->HandleProtocol(*hp, &pciio_guid, (void **)&pciio); - if (status == EFI_SUCCESS) { - free(buf); - return (pciio); - } - } - free(buf); - return (NULL); -} - -static EFI_STATUS -efifb_uga_locate_framebuffer(EFI_PCI_IO_PROTOCOL *pciio, uint64_t *addrp, - uint64_t *sizep) -{ - uint8_t *resattr; - uint64_t addr, size; - EFI_STATUS status; - u_int bar; - - if (pciio == NULL) - return (EFI_DEVICE_ERROR); - - /* Attempt to get the frame buffer address (imprecise). */ - *addrp = 0; - *sizep = 0; - for (bar = 0; bar < 6; bar++) { - status = pciio->GetBarAttributes(pciio, bar, NULL, - (void **)&resattr); - if (status != EFI_SUCCESS) - continue; - /* XXX magic offsets and constants. */ - if (resattr[0] == 0x87 && resattr[3] == 0) { - /* 32-bit address space descriptor (MEMIO) */ - addr = le32dec(resattr + 10); - size = le32dec(resattr + 22); - } else if (resattr[0] == 0x8a && resattr[3] == 0) { - /* 64-bit address space descriptor (MEMIO) */ - addr = le64dec(resattr + 14); - size = le64dec(resattr + 38); - } else { - addr = 0; - size = 0; - } - BS->FreePool(resattr); - if (addr == 0 || size == 0) - continue; - - /* We assume the largest BAR is the frame buffer. */ - if (size > *sizep) { - *addrp = addr; - *sizep = size; - } - } - return ((*addrp == 0 || *sizep == 0) ? EFI_DEVICE_ERROR : 0); -} - -static int -efifb_from_uga(struct efi_fb *efifb, EFI_UGA_DRAW_PROTOCOL *uga) -{ - EFI_PCI_IO_PROTOCOL *pciio; - char *ev, *p; - EFI_STATUS status; - ssize_t offset; - uint64_t fbaddr; - uint32_t horiz, vert, stride; - uint32_t np, depth, refresh; - - status = uga->GetMode(uga, &horiz, &vert, &depth, &refresh); - if (EFI_ERROR(status)) - return (1); - efifb->fb_height = vert; - efifb->fb_width = horiz; - /* Paranoia... */ - if (efifb->fb_height == 0 || efifb->fb_width == 0) - return (1); - - /* The color masks are fixed AFAICT. */ - efifb_mask_from_pixfmt(efifb, PixelBlueGreenRedReserved8BitPerColor, - NULL); - - /* pciio can be NULL on return! */ - pciio = efifb_uga_get_pciio(); - - /* Try to find the frame buffer. */ - status = efifb_uga_locate_framebuffer(pciio, &efifb->fb_addr, - &efifb->fb_size); - if (EFI_ERROR(status)) { - efifb->fb_addr = 0; - efifb->fb_size = 0; - } - - /* - * There's no reliable way to detect the frame buffer or the - * offset within the frame buffer of the visible region, nor - * the stride. Our only option is to look at the system and - * fill in the blanks based on that. Luckily, UGA was mostly - * only used on Apple hardware. - */ - offset = -1; - ev = getenv("smbios.system.maker"); - if (ev != NULL && !strcmp(ev, "Apple Inc.")) { - ev = getenv("smbios.system.product"); - if (ev != NULL && !strcmp(ev, "iMac7,1")) { - /* These are the expected values we should have. */ - horiz = 1680; - vert = 1050; - fbaddr = 0xc0000000; - /* These are the missing bits. */ - offset = 0x10000; - stride = 1728; - } else if (ev != NULL && !strcmp(ev, "MacBook3,1")) { - /* These are the expected values we should have. */ - horiz = 1280; - vert = 800; - fbaddr = 0xc0000000; - /* These are the missing bits. */ - offset = 0x0; - stride = 2048; - } - } - - /* - * If this is hardware we know, make sure that it looks familiar - * before we accept our hardcoded values. - */ - if (offset >= 0 && efifb->fb_width == horiz && - efifb->fb_height == vert && efifb->fb_addr == fbaddr) { - efifb->fb_addr += offset; - efifb->fb_size -= offset; - efifb->fb_stride = stride; - return (0); - } else if (offset >= 0) { - printf("Hardware make/model known, but graphics not " - "as expected.\n"); - printf("Console may not work!\n"); - } - - /* - * The stride is equal or larger to the width. Often it's the - * next larger power of two. We'll start with that... - */ - efifb->fb_stride = efifb->fb_width; - do { - np = efifb->fb_stride & (efifb->fb_stride - 1); - if (np) { - efifb->fb_stride |= (np - 1); - efifb->fb_stride++; - } - } while (np); - - ev = getenv("hw.efifb.address"); - if (ev == NULL) { - if (efifb->fb_addr == 0) { - printf("Please set hw.efifb.address and " - "hw.efifb.stride.\n"); - return (1); - } - - /* - * The visible part of the frame buffer may not start at - * offset 0, so try to detect it. Note that we may not - * always be able to read from the frame buffer, which - * means that we may not be able to detect anything. In - * that case, we would take a long time scanning for a - * pixel change in the frame buffer, which would have it - * appear that we're hanging, so we limit the scan to - * 1/256th of the frame buffer. This number is mostly - * based on PR 202730 and the fact that on a MacBoook, - * where we can't read from the frame buffer the offset - * of the visible region is 0. In short: we want to scan - * enough to handle all adapters that have an offset - * larger than 0 and we want to scan as little as we can - * to not appear to hang when we can't read from the - * frame buffer. - */ - offset = efifb_uga_find_pixel(uga, 0, pciio, efifb->fb_addr, - efifb->fb_size >> 8); - if (offset == -1) { - printf("Unable to reliably detect frame buffer.\n"); - } else if (offset > 0) { - efifb->fb_addr += offset; - efifb->fb_size -= offset; - } - } else { - offset = 0; - efifb->fb_size = efifb->fb_height * efifb->fb_stride * 4; - efifb->fb_addr = strtoul(ev, &p, 0); - if (*p != '\0') - return (1); - } - - ev = getenv("hw.efifb.stride"); - if (ev == NULL) { - if (pciio != NULL && offset != -1) { - /* Determine the stride. */ - offset = efifb_uga_find_pixel(uga, 1, pciio, - efifb->fb_addr, horiz * 8); - if (offset != -1) - efifb->fb_stride = offset >> 2; - } else { - printf("Unable to reliably detect the stride.\n"); - } - } else { - efifb->fb_stride = strtoul(ev, &p, 0); - if (*p != '\0') - return (1); - } - - /* - * We finalized on the stride, so recalculate the size of the - * frame buffer. - */ - efifb->fb_size = efifb->fb_height * efifb->fb_stride * 4; - return (0); -} - -int -efi_find_framebuffer(struct efi_fb *efifb) -{ - EFI_GRAPHICS_OUTPUT *gop; - EFI_UGA_DRAW_PROTOCOL *uga; - EFI_STATUS status; - - status = BS->LocateProtocol(&gop_guid, NULL, (VOID **)&gop); - if (status == EFI_SUCCESS) - return (efifb_from_gop(efifb, gop->Mode, gop->Mode->Info)); - - status = BS->LocateProtocol(&uga_guid, NULL, (VOID **)&uga); - if (status == EFI_SUCCESS) - return (efifb_from_uga(efifb, uga)); - - return (1); -} - -static void -print_efifb(int mode, struct efi_fb *efifb, int verbose) -{ - u_int depth; - - if (mode >= 0) - printf("mode %d: ", mode); - depth = efifb_color_depth(efifb); - printf("%ux%ux%u, stride=%u", efifb->fb_width, efifb->fb_height, - depth, efifb->fb_stride); - if (verbose) { - printf("\n frame buffer: address=%jx, size=%jx", - (uintmax_t)efifb->fb_addr, (uintmax_t)efifb->fb_size); - printf("\n color mask: R=%08x, G=%08x, B=%08x\n", - efifb->fb_mask_red, efifb->fb_mask_green, - efifb->fb_mask_blue); - } -} - -COMMAND_SET(gop, "gop", "graphics output protocol", command_gop); - -static int -command_gop(int argc, char *argv[]) -{ - struct efi_fb efifb; - EFI_GRAPHICS_OUTPUT *gop; - EFI_STATUS status; - u_int mode; - - status = BS->LocateProtocol(&gop_guid, NULL, (VOID **)&gop); - if (EFI_ERROR(status)) { - snprintf(command_errbuf, sizeof (command_errbuf), - "%s: Graphics Output Protocol not present (error=%lu)", - argv[0], EFI_ERROR_CODE(status)); - return (CMD_ERROR); - } - - if (argc < 2) - goto usage; - - if (!strcmp(argv[1], "set")) { - char *cp; - - if (argc != 3) - goto usage; - mode = strtol(argv[2], &cp, 0); - if (cp[0] != '\0') { - sprintf(command_errbuf, "mode is an integer"); - return (CMD_ERROR); - } - status = gop->SetMode(gop, mode); - if (EFI_ERROR(status)) { - snprintf(command_errbuf, sizeof (command_errbuf), - "%s: Unable to set mode to %u (error=%lu)", - argv[0], mode, EFI_ERROR_CODE(status)); - return (CMD_ERROR); - } - } else if (!strcmp(argv[1], "get")) { - if (argc != 2) - goto usage; - efifb_from_gop(&efifb, gop->Mode, gop->Mode->Info); - print_efifb(gop->Mode->Mode, &efifb, 1); - printf("\n"); - } else if (!strcmp(argv[1], "list")) { - EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info; - UINTN infosz; - - if (argc != 2) - goto usage; - pager_open(); - for (mode = 0; mode < gop->Mode->MaxMode; mode++) { - status = gop->QueryMode(gop, mode, &infosz, &info); - if (EFI_ERROR(status)) - continue; - efifb_from_gop(&efifb, gop->Mode, info); - print_efifb(mode, &efifb, 0); - if (pager_output("\n")) - break; - } - pager_close(); - } - return (CMD_OK); - - usage: - snprintf(command_errbuf, sizeof (command_errbuf), - "usage: %s [list | get | set ]", argv[0]); - return (CMD_ERROR); -} - -COMMAND_SET(uga, "uga", "universal graphics adapter", command_uga); - -static int -command_uga(int argc, char *argv[]) -{ - struct efi_fb efifb; - EFI_UGA_DRAW_PROTOCOL *uga; - EFI_STATUS status; - - status = BS->LocateProtocol(&uga_guid, NULL, (VOID **)&uga); - if (EFI_ERROR(status)) { - snprintf(command_errbuf, sizeof (command_errbuf), - "%s: UGA Protocol not present (error=%lu)", - argv[0], EFI_ERROR_CODE(status)); - return (CMD_ERROR); - } - - if (argc != 1) - goto usage; - - if (efifb_from_uga(&efifb, uga) != CMD_OK) { - snprintf(command_errbuf, sizeof (command_errbuf), - "%s: Unable to get UGA information", argv[0]); - return (CMD_ERROR); - } - - print_efifb(-1, &efifb, 1); - printf("\n"); - return (CMD_OK); - - usage: - snprintf(command_errbuf, sizeof (command_errbuf), "usage: %s", argv[0]); - return (CMD_ERROR); -} diff --git a/usr/src/boot/sys/boot/efi/loader/arch/amd64/framebuffer.h b/usr/src/boot/sys/boot/efi/loader/arch/amd64/framebuffer.h deleted file mode 100644 index 2ec9017dc3..0000000000 --- a/usr/src/boot/sys/boot/efi/loader/arch/amd64/framebuffer.h +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * Copyright (c) 2013 The FreeBSD Foundation - * All rights reserved. - * - * This software was developed by Benno Rice under sponsorship from - * the FreeBSD Foundation. - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef _EFIFB_H_ -#define _EFIFB_H_ - -int efi_find_framebuffer(struct efi_fb *efifb); - -#endif /* _EFIFB_H_ */ diff --git a/usr/src/boot/sys/boot/efi/loader/arch/amd64/multiboot_tramp.S b/usr/src/boot/sys/boot/efi/loader/arch/amd64/multiboot_tramp.S index 061c638b59..e8ba51324a 100644 --- a/usr/src/boot/sys/boot/efi/loader/arch/amd64/multiboot_tramp.S +++ b/usr/src/boot/sys/boot/efi/loader/arch/amd64/multiboot_tramp.S @@ -18,16 +18,15 @@ .file "multiboot_tramp.s" /* - * The current dboot in illumos kernel is running in 32bit mode - * and expecting following 32-bit multiboot execution environment: + * dboot expects a 32-bit multiboot environment and to execute in 32-bit mode. * * EAX: MB magic * EBX: 32-bit physical address of MBI * CS: 32-bit read/execute code segment with offset 0 and limit 0xFFFFFFFF - * DS: 32-bit read/write code segment with offset 0 and limit 0xFFFFFFFF - * ES: 32-bit read/write code segment with offset 0 and limit 0xFFFFFFFF - * FS: 32-bit read/write code segment with offset 0 and limit 0xFFFFFFFF - * GS: 32-bit read/write code segment with offset 0 and limit 0xFFFFFFFF + * DS: 32-bit read/write data segment with offset 0 and limit 0xFFFFFFFF + * ES: 32-bit read/write data segment with offset 0 and limit 0xFFFFFFFF + * FS: 32-bit read/write data segment with offset 0 and limit 0xFFFFFFFF + * GS: 32-bit read/write data segment with offset 0 and limit 0xFFFFFFFF * SS: 32-bit read/write data segment with offset 0 and limit 0xFFFFFFFF * A20 enabled * CR0: PG cleared, PE set @@ -45,7 +44,7 @@ /* * void multiboot_tramp(uint32_t magic, struct relocator *relocator, - * uint64_t entry) + * vm_offset_t entry) */ multiboot_tramp: cli @@ -103,6 +102,15 @@ multiboot_tramp_2: /* GDT record */ .p2align 4 gdt: +/* + * This will create access for 4GB flat memory with + * base = 0x00000000, segment limit = 0xffffffff + * page granulariy 4k + * 32-bit protected mode + * ring 0 + * code segment is executable RW + * data segment is not-executable RW + */ .word 0x0, 0x0 /* NULL entry */ .byte 0x0, 0x0, 0x0, 0x0 .word 0xffff, 0x0 /* code segment */ diff --git a/usr/src/boot/sys/boot/efi/loader/arch/i386/Makefile.inc b/usr/src/boot/sys/boot/efi/loader/arch/i386/Makefile.inc index 4e08c53763..7adb6b2fb5 100644 --- a/usr/src/boot/sys/boot/efi/loader/arch/i386/Makefile.inc +++ b/usr/src/boot/sys/boot/efi/loader/arch/i386/Makefile.inc @@ -1,13 +1,14 @@ -# $FreeBSD$ -SRCS+= start.S \ - efimd.c \ - elf32_freebsd.c \ - exec.c +SRCS += multiboot_tramp.S \ + start.S -.PATH: ${.CURDIR}/../../i386/libi386 -SRCS+= nullconsole.c \ +OBJS += multiboot_tramp.o \ + start.o + +SRCS += nullconsole.c \ + spinconsole.c \ comconsole.c -CFLAGS+= -fPIC -LDFLAGS+= -Wl,-znocombreloc +OBJS += nullconsole.o \ + spinconsole.o \ + comconsole.o diff --git a/usr/src/boot/sys/boot/efi/loader/arch/i386/ldscript.i386 b/usr/src/boot/sys/boot/efi/loader/arch/i386/ldscript.i386 index e17212a1bd..4920a319a4 100644 --- a/usr/src/boot/sys/boot/efi/loader/arch/i386/ldscript.i386 +++ b/usr/src/boot/sys/boot/efi/loader/arch/i386/ldscript.i386 @@ -1,5 +1,4 @@ -/* $FreeBSD$ */ -OUTPUT_FORMAT("elf32-i386-freebsd", "elf32-i386-freebsd", "elf32-i386-freebsd") +OUTPUT_FORMAT("elf32-i386-sol2", "elf32-i386-sol2", "elf32-i386-sol2") OUTPUT_ARCH(i386) ENTRY(_start) SECTIONS diff --git a/usr/src/boot/sys/boot/efi/loader/arch/i386/multiboot_tramp.S b/usr/src/boot/sys/boot/efi/loader/arch/i386/multiboot_tramp.S new file mode 100644 index 0000000000..60be6a378d --- /dev/null +++ b/usr/src/boot/sys/boot/efi/loader/arch/i386/multiboot_tramp.S @@ -0,0 +1,150 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2016 Toomas Soome + */ + +#include + + .file "multiboot_tramp.s" + +/* + * dboot expects a 32-bit multiboot environment and to execute in 32-bit mode. + * + * EAX: MB magic + * EBX: 32-bit physical address of MBI + * CS: 32-bit read/execute code segment with offset 0 and limit 0xFFFFFFFF + * DS: 32-bit read/write data segment with offset 0 and limit 0xFFFFFFFF + * ES: 32-bit read/write data segment with offset 0 and limit 0xFFFFFFFF + * FS: 32-bit read/write data segment with offset 0 and limit 0xFFFFFFFF + * GS: 32-bit read/write data segment with offset 0 and limit 0xFFFFFFFF + * SS: 32-bit read/write data segment with offset 0 and limit 0xFFFFFFFF + * A20 enabled + * CR0: PG cleared, PE set + * EFLAGS: VM cleared, IF cleared + * interrupts disabled + */ + + .set SEL_SCODE,0x8 + .set SEL_SDATA,0x10 + + .text + .p2align 4 + .globl multiboot_tramp + .type multiboot_tramp, STT_FUNC + +/* + * Note as we are running in 32-bit mode, all pointers are 32-bit. + * void multiboot_tramp(uint32_t magic, struct relocator *relocator, + * vm_offset_t entry) + */ +multiboot_tramp: + cli + pushl %ebp /* keep familiar stack frame */ + movl %esp, %ebp /* current SP */ + movl 0xc(%ebp),%eax /* relocator */ + movl (%eax), %eax /* new SP */ + movl %eax, %esp + + /* now copy arguments to new stack */ + movl 0x10(%ebp),%eax /* entry */ + pushl %eax + movl 0xc(%ebp),%eax /* relocator */ + pushl %eax + movl 0x8(%ebp),%eax /* magic */ + pushl %eax + xorl %eax,%eax + pushl %eax /* fake IP, just to keep stack frame */ + pushl %ebp + movl %esp, %ebp + subl $0x30, %esp /* local mbi, gdt and gdt desc */ + + movl 0xc(%ebp), %eax /* relocator */ + pushl %eax + movl 0x4(%eax), %eax /* relocator->copy */ + call *%eax + addl $0x4, %esp + movl %eax, -0x4(%ebp) /* save MBI */ + + /* set up GDT descriptor */ + lea -0x1c(%ebp), %eax /* address of GDT */ + movw $0x17, -0x22(%ebp) /* limit */ + movl %eax, -0x20(%ebp) /* base */ + +/* + * set up following GDT: + * .word 0x0, 0x0 NULL entry + * .byte 0x0, 0x0, 0x0, 0x0 + * .word 0xffff, 0x0 code segment + * .byte 0x0, 0x9a, 0xcf, 0x0 + * .word 0xffff, 0x0 data segment + * .byte 0x0, 0x92, 0xcf, 0x0 + * + * This will create access for 4GB flat memory with + * base = 0x00000000, segment limit = 0xffffffff + * page granulariy 4k + * 32-bit protected mode + * ring 0 + * code segment is executable RW + * data segment is not-executable RW + */ + movw $0x0, -0x1c(%ebp) + movw $0x0, -0x1a(%ebp) + movb $0x0, -0x18(%ebp) + movb $0x0, -0x17(%ebp) + movb $0x0, -0x16(%ebp) + movb $0x0, -0x15(%ebp) + + movw $0xffff, -0x14(%ebp) + movw $0x0, -0x12(%ebp) + movb $0x0, -0x10(%ebp) + movb $0x9a, -0xf(%ebp) + movb $0xcf, -0xe(%ebp) + movb $0x0, -0xd(%ebp) + + movw $0xffff, -0xc(%ebp) + movw $0x0, -0xa(%ebp) + movb $0x0, -0x8(%ebp) + movb $0x92, -0x7(%ebp) + movb $0xcf, -0x6(%ebp) + movb $0x0, -0x5(%ebp) + + lea -0x22(%ebp), %eax /* address of GDT */ + lgdt (%eax) + + movl 0x8(%ebp), %edx /* magic */ + movl -0x4(%ebp), %ebx /* MBI */ + movl 0x10(%ebp), %esi /* entry */ + + movl $SEL_SDATA, %eax + movw %ax, %ss + movw %ax, %ds + movw %ax, %es + movw %ax, %fs + movw %ax, %gs + + /* + * We most likely don't need to push SEL_SDATA and esp + * because we do not expect to perform a privilege transition. + * However, it doesn't hurt us to push them as dboot will set + * up its own stack. + */ + movl %esp, %eax + pushl $SEL_SDATA + pushl %eax + pushf + pushl $SEL_SCODE + pushl %esi + movl %edx, %eax + iretl + +multiboot_tramp_end: diff --git a/usr/src/boot/sys/boot/efi/loader/bootinfo.c b/usr/src/boot/sys/boot/efi/loader/bootinfo.c index 6c90871c06..81d648033b 100644 --- a/usr/src/boot/sys/boot/efi/loader/bootinfo.c +++ b/usr/src/boot/sys/boot/efi/loader/bootinfo.c @@ -300,7 +300,7 @@ bi_load_efi_data(struct preloaded_file *kfp) * memory map on a 16-byte boundary (the bootinfo block is page * aligned). */ - efihdr = (struct efi_map_header *)addr; + efihdr = (struct efi_map_header *)(uintptr_t)addr; mm = (void *)((uint8_t *)efihdr + efisz); sz = (EFI_PAGE_SIZE * pages) - efisz; diff --git a/usr/src/boot/sys/boot/efi/loader/copy.c b/usr/src/boot/sys/boot/efi/loader/copy.c index 9658a659d4..93923500b2 100644 --- a/usr/src/boot/sys/boot/efi/loader/copy.c +++ b/usr/src/boot/sys/boot/efi/loader/copy.c @@ -153,8 +153,8 @@ efi_physaddr(multiboot_tag_module_t *module, vm_offset_t addr, * address, we can not make any assumptions about actual location or * about the order of the allocated blocks. */ -uint64_t -efi_loadaddr(u_int type, void *data, uint64_t addr) +vm_offset_t +efi_loadaddr(u_int type, void *data, vm_offset_t addr) { EFI_PHYSICAL_ADDRESS paddr; struct stat st; @@ -192,7 +192,7 @@ efi_loadaddr(u_int type, void *data, uint64_t addr) } void -efi_free_loadaddr(uint64_t addr, uint64_t pages) +efi_free_loadaddr(vm_offset_t addr, size_t pages) { (void) BS->FreePages(addr, pages); } @@ -249,7 +249,7 @@ efi_copy_finish(struct relocator *relocator) /* MBI is the last chunk in the list. */ head = &relocator->rel_chunk_head; chunk = STAILQ_LAST(head, chunk, chunk_next); - mbi = (multiboot2_info_header_t *)chunk->chunk_paddr; + mbi = (multiboot2_info_header_t *)(uintptr_t)chunk->chunk_paddr; /* * If chunk paddr == vaddr, the chunk is in place. @@ -304,8 +304,8 @@ efi_copy_finish(struct relocator *relocator) } /* If there are no conflicts, move to place and restart. */ if (c == NULL) { - move((void *)chunk->chunk_paddr, - (void *)chunk->chunk_vaddr, + move((void *)(uintptr_t)chunk->chunk_paddr, + (void *)(uintptr_t)chunk->chunk_vaddr, chunk->chunk_size); chunk->chunk_vaddr = chunk->chunk_paddr; chunk = NULL; diff --git a/usr/src/boot/sys/boot/efi/loader/efi_main.c b/usr/src/boot/sys/boot/efi/loader/efi_main.c index de6e137467..86917da147 100644 --- a/usr/src/boot/sys/boot/efi/loader/efi_main.c +++ b/usr/src/boot/sys/boot/efi/loader/efi_main.c @@ -197,7 +197,7 @@ efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) argv = malloc((argc + 1) * sizeof(CHAR16*)); argc = 0; if (addprog) - argv[argc++] = (CHAR16 *)L"loader.efi"; + argv[argc++] = (CHAR16 *)LOADER_EFI; argp = args; while (argp != NULL && *argp != 0) { argp = arg_skipsep(argp); diff --git a/usr/src/boot/sys/boot/efi/loader/framebuffer.c b/usr/src/boot/sys/boot/efi/loader/framebuffer.c new file mode 100644 index 0000000000..77d01dfb64 --- /dev/null +++ b/usr/src/boot/sys/boot/efi/loader/framebuffer.c @@ -0,0 +1,567 @@ +/* + * Copyright (c) 2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Benno Rice under sponsorship from + * the FreeBSD Foundation. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "framebuffer.h" + +static EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; +static EFI_GUID pciio_guid = EFI_PCI_IO_PROTOCOL_GUID; +static EFI_GUID uga_guid = EFI_UGA_DRAW_PROTOCOL_GUID; + +static u_int +efifb_color_depth(struct efi_fb *efifb) +{ + uint32_t mask; + u_int depth; + + mask = efifb->fb_mask_red | efifb->fb_mask_green | + efifb->fb_mask_blue | efifb->fb_mask_reserved; + if (mask == 0) + return (0); + for (depth = 1; mask != 1; depth++) + mask >>= 1; + return (depth); +} + +static int +efifb_mask_from_pixfmt(struct efi_fb *efifb, EFI_GRAPHICS_PIXEL_FORMAT pixfmt, + EFI_PIXEL_BITMASK *pixinfo) +{ + int result; + + result = 0; + switch (pixfmt) { + case PixelRedGreenBlueReserved8BitPerColor: + efifb->fb_mask_red = 0x000000ff; + efifb->fb_mask_green = 0x0000ff00; + efifb->fb_mask_blue = 0x00ff0000; + efifb->fb_mask_reserved = 0xff000000; + break; + case PixelBlueGreenRedReserved8BitPerColor: + efifb->fb_mask_red = 0x00ff0000; + efifb->fb_mask_green = 0x0000ff00; + efifb->fb_mask_blue = 0x000000ff; + efifb->fb_mask_reserved = 0xff000000; + break; + case PixelBitMask: + efifb->fb_mask_red = pixinfo->RedMask; + efifb->fb_mask_green = pixinfo->GreenMask; + efifb->fb_mask_blue = pixinfo->BlueMask; + efifb->fb_mask_reserved = pixinfo->ReservedMask; + break; + default: + result = 1; + break; + } + return (result); +} + +static int +efifb_from_gop(struct efi_fb *efifb, EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *mode, + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info) +{ + int result; + + efifb->fb_addr = mode->FrameBufferBase; + efifb->fb_size = mode->FrameBufferSize; + efifb->fb_height = info->VerticalResolution; + efifb->fb_width = info->HorizontalResolution; + efifb->fb_stride = info->PixelsPerScanLine; + result = efifb_mask_from_pixfmt(efifb, info->PixelFormat, + &info->PixelInformation); + return (result); +} + +static ssize_t +efifb_uga_find_pixel(EFI_UGA_DRAW_PROTOCOL *uga, u_int line, + EFI_PCI_IO_PROTOCOL *pciio, uint64_t addr, uint64_t size) +{ + EFI_UGA_PIXEL pix0, pix1; + uint8_t *data1, *data2; + size_t count, maxcount = 1024; + ssize_t ofs; + EFI_STATUS status; + u_int idx; + + status = uga->Blt(uga, &pix0, EfiUgaVideoToBltBuffer, + 0, line, 0, 0, 1, 1, 0); + if (EFI_ERROR(status)) { + printf("UGA BLT operation failed (video->buffer)"); + return (-1); + } + pix1.Red = ~pix0.Red; + pix1.Green = ~pix0.Green; + pix1.Blue = ~pix0.Blue; + pix1.Reserved = 0; + + data1 = calloc(maxcount, 2); + if (data1 == NULL) { + printf("Unable to allocate memory"); + return (-1); + } + data2 = data1 + maxcount; + + ofs = 0; + while (size > 0) { + count = min(size, maxcount); + + status = pciio->Mem.Read(pciio, EfiPciIoWidthUint32, + EFI_PCI_IO_PASS_THROUGH_BAR, addr + ofs, count >> 2, + data1); + if (EFI_ERROR(status)) { + printf("Error reading frame buffer (before)"); + goto fail; + } + status = uga->Blt(uga, &pix1, EfiUgaBltBufferToVideo, + 0, 0, 0, line, 1, 1, 0); + if (EFI_ERROR(status)) { + printf("UGA BLT operation failed (modify)"); + goto fail; + } + status = pciio->Mem.Read(pciio, EfiPciIoWidthUint32, + EFI_PCI_IO_PASS_THROUGH_BAR, addr + ofs, count >> 2, + data2); + if (EFI_ERROR(status)) { + printf("Error reading frame buffer (after)"); + goto fail; + } + status = uga->Blt(uga, &pix0, EfiUgaBltBufferToVideo, + 0, 0, 0, line, 1, 1, 0); + if (EFI_ERROR(status)) { + printf("UGA BLT operation failed (restore)"); + goto fail; + } + for (idx = 0; idx < count; idx++) { + if (data1[idx] != data2[idx]) { + free(data1); + return (ofs + (idx & ~3)); + } + } + ofs += count; + size -= count; + } + printf("No change detected in frame buffer"); + + fail: + printf(" -- error %lu\n", EFI_ERROR_CODE(status)); + free(data1); + return (-1); +} + +static EFI_PCI_IO_PROTOCOL * +efifb_uga_get_pciio(void) +{ + EFI_PCI_IO_PROTOCOL *pciio; + EFI_HANDLE *buf, *hp; + EFI_STATUS status; + UINTN bufsz; + + /* Get all handles that support the UGA protocol. */ + bufsz = 0; + status = BS->LocateHandle(ByProtocol, &uga_guid, NULL, &bufsz, NULL); + if (status != EFI_BUFFER_TOO_SMALL) + return (NULL); + buf = malloc(bufsz); + status = BS->LocateHandle(ByProtocol, &uga_guid, NULL, &bufsz, buf); + if (status != EFI_SUCCESS) { + free(buf); + return (NULL); + } + bufsz /= sizeof(EFI_HANDLE); + + /* Get the PCI I/O interface of the first handle that supports it. */ + pciio = NULL; + for (hp = buf; hp < buf + bufsz; hp++) { + status = BS->HandleProtocol(*hp, &pciio_guid, (void **)&pciio); + if (status == EFI_SUCCESS) { + free(buf); + return (pciio); + } + } + free(buf); + return (NULL); +} + +static EFI_STATUS +efifb_uga_locate_framebuffer(EFI_PCI_IO_PROTOCOL *pciio, uint64_t *addrp, + uint64_t *sizep) +{ + uint8_t *resattr; + uint64_t addr, size; + EFI_STATUS status; + u_int bar; + + if (pciio == NULL) + return (EFI_DEVICE_ERROR); + + /* Attempt to get the frame buffer address (imprecise). */ + *addrp = 0; + *sizep = 0; + for (bar = 0; bar < 6; bar++) { + status = pciio->GetBarAttributes(pciio, bar, NULL, + (void **)&resattr); + if (status != EFI_SUCCESS) + continue; + /* XXX magic offsets and constants. */ + if (resattr[0] == 0x87 && resattr[3] == 0) { + /* 32-bit address space descriptor (MEMIO) */ + addr = le32dec(resattr + 10); + size = le32dec(resattr + 22); + } else if (resattr[0] == 0x8a && resattr[3] == 0) { + /* 64-bit address space descriptor (MEMIO) */ + addr = le64dec(resattr + 14); + size = le64dec(resattr + 38); + } else { + addr = 0; + size = 0; + } + BS->FreePool(resattr); + if (addr == 0 || size == 0) + continue; + + /* We assume the largest BAR is the frame buffer. */ + if (size > *sizep) { + *addrp = addr; + *sizep = size; + } + } + return ((*addrp == 0 || *sizep == 0) ? EFI_DEVICE_ERROR : 0); +} + +static int +efifb_from_uga(struct efi_fb *efifb, EFI_UGA_DRAW_PROTOCOL *uga) +{ + EFI_PCI_IO_PROTOCOL *pciio; + char *ev, *p; + EFI_STATUS status; + ssize_t offset; + uint64_t fbaddr; + uint32_t horiz, vert, stride; + uint32_t np, depth, refresh; + + status = uga->GetMode(uga, &horiz, &vert, &depth, &refresh); + if (EFI_ERROR(status)) + return (1); + efifb->fb_height = vert; + efifb->fb_width = horiz; + /* Paranoia... */ + if (efifb->fb_height == 0 || efifb->fb_width == 0) + return (1); + + /* The color masks are fixed AFAICT. */ + efifb_mask_from_pixfmt(efifb, PixelBlueGreenRedReserved8BitPerColor, + NULL); + + /* pciio can be NULL on return! */ + pciio = efifb_uga_get_pciio(); + + /* Try to find the frame buffer. */ + status = efifb_uga_locate_framebuffer(pciio, &efifb->fb_addr, + &efifb->fb_size); + if (EFI_ERROR(status)) { + efifb->fb_addr = 0; + efifb->fb_size = 0; + } + + /* + * There's no reliable way to detect the frame buffer or the + * offset within the frame buffer of the visible region, nor + * the stride. Our only option is to look at the system and + * fill in the blanks based on that. Luckily, UGA was mostly + * only used on Apple hardware. + */ + offset = -1; + ev = getenv("smbios.system.maker"); + if (ev != NULL && !strcmp(ev, "Apple Inc.")) { + ev = getenv("smbios.system.product"); + if (ev != NULL && !strcmp(ev, "iMac7,1")) { + /* These are the expected values we should have. */ + horiz = 1680; + vert = 1050; + fbaddr = 0xc0000000; + /* These are the missing bits. */ + offset = 0x10000; + stride = 1728; + } else if (ev != NULL && !strcmp(ev, "MacBook3,1")) { + /* These are the expected values we should have. */ + horiz = 1280; + vert = 800; + fbaddr = 0xc0000000; + /* These are the missing bits. */ + offset = 0x0; + stride = 2048; + } + } + + /* + * If this is hardware we know, make sure that it looks familiar + * before we accept our hardcoded values. + */ + if (offset >= 0 && efifb->fb_width == horiz && + efifb->fb_height == vert && efifb->fb_addr == fbaddr) { + efifb->fb_addr += offset; + efifb->fb_size -= offset; + efifb->fb_stride = stride; + return (0); + } else if (offset >= 0) { + printf("Hardware make/model known, but graphics not " + "as expected.\n"); + printf("Console may not work!\n"); + } + + /* + * The stride is equal or larger to the width. Often it's the + * next larger power of two. We'll start with that... + */ + efifb->fb_stride = efifb->fb_width; + do { + np = efifb->fb_stride & (efifb->fb_stride - 1); + if (np) { + efifb->fb_stride |= (np - 1); + efifb->fb_stride++; + } + } while (np); + + ev = getenv("hw.efifb.address"); + if (ev == NULL) { + if (efifb->fb_addr == 0) { + printf("Please set hw.efifb.address and " + "hw.efifb.stride.\n"); + return (1); + } + + /* + * The visible part of the frame buffer may not start at + * offset 0, so try to detect it. Note that we may not + * always be able to read from the frame buffer, which + * means that we may not be able to detect anything. In + * that case, we would take a long time scanning for a + * pixel change in the frame buffer, which would have it + * appear that we're hanging, so we limit the scan to + * 1/256th of the frame buffer. This number is mostly + * based on PR 202730 and the fact that on a MacBoook, + * where we can't read from the frame buffer the offset + * of the visible region is 0. In short: we want to scan + * enough to handle all adapters that have an offset + * larger than 0 and we want to scan as little as we can + * to not appear to hang when we can't read from the + * frame buffer. + */ + offset = efifb_uga_find_pixel(uga, 0, pciio, efifb->fb_addr, + efifb->fb_size >> 8); + if (offset == -1) { + printf("Unable to reliably detect frame buffer.\n"); + } else if (offset > 0) { + efifb->fb_addr += offset; + efifb->fb_size -= offset; + } + } else { + offset = 0; + efifb->fb_size = efifb->fb_height * efifb->fb_stride * 4; + efifb->fb_addr = strtoul(ev, &p, 0); + if (*p != '\0') + return (1); + } + + ev = getenv("hw.efifb.stride"); + if (ev == NULL) { + if (pciio != NULL && offset != -1) { + /* Determine the stride. */ + offset = efifb_uga_find_pixel(uga, 1, pciio, + efifb->fb_addr, horiz * 8); + if (offset != -1) + efifb->fb_stride = offset >> 2; + } else { + printf("Unable to reliably detect the stride.\n"); + } + } else { + efifb->fb_stride = strtoul(ev, &p, 0); + if (*p != '\0') + return (1); + } + + /* + * We finalized on the stride, so recalculate the size of the + * frame buffer. + */ + efifb->fb_size = efifb->fb_height * efifb->fb_stride * 4; + return (0); +} + +int +efi_find_framebuffer(struct efi_fb *efifb) +{ + EFI_GRAPHICS_OUTPUT *gop; + EFI_UGA_DRAW_PROTOCOL *uga; + EFI_STATUS status; + + status = BS->LocateProtocol(&gop_guid, NULL, (VOID **)&gop); + if (status == EFI_SUCCESS) + return (efifb_from_gop(efifb, gop->Mode, gop->Mode->Info)); + + status = BS->LocateProtocol(&uga_guid, NULL, (VOID **)&uga); + if (status == EFI_SUCCESS) + return (efifb_from_uga(efifb, uga)); + + return (1); +} + +static void +print_efifb(int mode, struct efi_fb *efifb, int verbose) +{ + u_int depth; + + if (mode >= 0) + printf("mode %d: ", mode); + depth = efifb_color_depth(efifb); + printf("%ux%ux%u, stride=%u", efifb->fb_width, efifb->fb_height, + depth, efifb->fb_stride); + if (verbose) { + printf("\n frame buffer: address=%jx, size=%jx", + (uintmax_t)efifb->fb_addr, (uintmax_t)efifb->fb_size); + printf("\n color mask: R=%08x, G=%08x, B=%08x\n", + efifb->fb_mask_red, efifb->fb_mask_green, + efifb->fb_mask_blue); + } +} + +COMMAND_SET(gop, "gop", "graphics output protocol", command_gop); + +static int +command_gop(int argc, char *argv[]) +{ + struct efi_fb efifb; + EFI_GRAPHICS_OUTPUT *gop; + EFI_STATUS status; + u_int mode; + + status = BS->LocateProtocol(&gop_guid, NULL, (VOID **)&gop); + if (EFI_ERROR(status)) { + snprintf(command_errbuf, sizeof (command_errbuf), + "%s: Graphics Output Protocol not present (error=%lu)", + argv[0], EFI_ERROR_CODE(status)); + return (CMD_ERROR); + } + + if (argc < 2) + goto usage; + + if (!strcmp(argv[1], "set")) { + char *cp; + + if (argc != 3) + goto usage; + mode = strtol(argv[2], &cp, 0); + if (cp[0] != '\0') { + sprintf(command_errbuf, "mode is an integer"); + return (CMD_ERROR); + } + status = gop->SetMode(gop, mode); + if (EFI_ERROR(status)) { + snprintf(command_errbuf, sizeof (command_errbuf), + "%s: Unable to set mode to %u (error=%lu)", + argv[0], mode, EFI_ERROR_CODE(status)); + return (CMD_ERROR); + } + } else if (!strcmp(argv[1], "get")) { + if (argc != 2) + goto usage; + efifb_from_gop(&efifb, gop->Mode, gop->Mode->Info); + print_efifb(gop->Mode->Mode, &efifb, 1); + printf("\n"); + } else if (!strcmp(argv[1], "list")) { + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info; + UINTN infosz; + + if (argc != 2) + goto usage; + pager_open(); + for (mode = 0; mode < gop->Mode->MaxMode; mode++) { + status = gop->QueryMode(gop, mode, &infosz, &info); + if (EFI_ERROR(status)) + continue; + efifb_from_gop(&efifb, gop->Mode, info); + print_efifb(mode, &efifb, 0); + if (pager_output("\n")) + break; + } + pager_close(); + } + return (CMD_OK); + + usage: + snprintf(command_errbuf, sizeof (command_errbuf), + "usage: %s [list | get | set ]", argv[0]); + return (CMD_ERROR); +} + +COMMAND_SET(uga, "uga", "universal graphics adapter", command_uga); + +static int +command_uga(int argc, char *argv[]) +{ + struct efi_fb efifb; + EFI_UGA_DRAW_PROTOCOL *uga; + EFI_STATUS status; + + status = BS->LocateProtocol(&uga_guid, NULL, (VOID **)&uga); + if (EFI_ERROR(status)) { + snprintf(command_errbuf, sizeof (command_errbuf), + "%s: UGA Protocol not present (error=%lu)", + argv[0], EFI_ERROR_CODE(status)); + return (CMD_ERROR); + } + + if (argc != 1) + goto usage; + + if (efifb_from_uga(&efifb, uga) != CMD_OK) { + snprintf(command_errbuf, sizeof (command_errbuf), + "%s: Unable to get UGA information", argv[0]); + return (CMD_ERROR); + } + + print_efifb(-1, &efifb, 1); + printf("\n"); + return (CMD_OK); + + usage: + snprintf(command_errbuf, sizeof (command_errbuf), "usage: %s", argv[0]); + return (CMD_ERROR); +} diff --git a/usr/src/boot/sys/boot/efi/loader/framebuffer.h b/usr/src/boot/sys/boot/efi/loader/framebuffer.h new file mode 100644 index 0000000000..2ec9017dc3 --- /dev/null +++ b/usr/src/boot/sys/boot/efi/loader/framebuffer.h @@ -0,0 +1,36 @@ +/*- + * Copyright (c) 2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Benno Rice under sponsorship from + * the FreeBSD Foundation. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _EFIFB_H_ +#define _EFIFB_H_ + +int efi_find_framebuffer(struct efi_fb *efifb); + +#endif /* _EFIFB_H_ */ diff --git a/usr/src/boot/sys/boot/efi/loader/i386/Makefile b/usr/src/boot/sys/boot/efi/loader/i386/Makefile new file mode 100644 index 0000000000..c4a451fba0 --- /dev/null +++ b/usr/src/boot/sys/boot/efi/loader/i386/Makefile @@ -0,0 +1,33 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. +# + +MACHINE= $(MACH) +ASFLAGS= -m32 +EFIPROG= loader32.efi + +all: $(EFIPROG) + +include ../Makefile.com + +EFI_TARGET= pei-i386 +LDFLAGS += -znocombreloc + +efi_main.o := CPPFLAGS += -DLOADER_EFI=L\"loader32.efi\" +CFLAGS += -m32 + +CLEANFILES += machine x86 $(EFIPROG) + +$(OBJS): machine x86 diff --git a/usr/src/boot/sys/boot/efi/loader/loader_efi.h b/usr/src/boot/sys/boot/efi/loader/loader_efi.h index 7339515b6b..cba9bf7d67 100644 --- a/usr/src/boot/sys/boot/efi/loader/loader_efi.h +++ b/usr/src/boot/sys/boot/efi/loader/loader_efi.h @@ -39,16 +39,16 @@ struct chunk { EFI_VIRTUAL_ADDRESS chunk_vaddr; EFI_PHYSICAL_ADDRESS chunk_paddr; - UINT64 chunk_size; + size_t chunk_size; STAILQ_ENTRY(chunk) chunk_next; }; STAILQ_HEAD(chunk_head, chunk); struct relocator { - UINT64 rel_stack; - UINT64 rel_copy; - UINT64 rel_memmove; + vm_offset_t rel_stack; + vm_offset_t rel_copy; + vm_offset_t rel_memmove; struct chunk_head rel_chunk_head; struct chunk rel_chunklist[]; }; @@ -58,8 +58,8 @@ int efi_autoload(void); ssize_t efi_copyin(const void *, vm_offset_t, const size_t); ssize_t efi_copyout(const vm_offset_t, void *, const size_t); ssize_t efi_readin(const int, vm_offset_t, const size_t); -uint64_t efi_loadaddr(u_int, void *, uint64_t); -void efi_free_loadaddr(uint64_t, uint64_t); +vm_offset_t efi_loadaddr(u_int, void *, vm_offset_t); +void efi_free_loadaddr(vm_offset_t, size_t); void * efi_translate(vm_offset_t); vm_offset_t efi_physaddr(multiboot_tag_module_t *, vm_offset_t, EFI_MEMORY_DESCRIPTOR *, size_t, UINTN, size_t); diff --git a/usr/src/boot/sys/boot/efi/loader/main.c b/usr/src/boot/sys/boot/efi/loader/main.c index fe4281ee3c..ef917ac632 100644 --- a/usr/src/boot/sys/boot/efi/loader/main.c +++ b/usr/src/boot/sys/boot/efi/loader/main.c @@ -535,11 +535,9 @@ command_memmap(int argc __unused, char *argv[] __unused) for (i = 0, p = map; i < ndesc; i++, p = NextMemoryDescriptor(p, dsz)) { - snprintf(line, 80, "%23s %012lx %012lx %08lx ", - efi_memory_type(p->Type), - p->PhysicalStart, - p->VirtualStart, - p->NumberOfPages); + snprintf(line, 80, "%23s %012jx %012jx %08jx ", + efi_memory_type(p->Type), p->PhysicalStart, + p->VirtualStart, p->NumberOfPages); rv = pager_output(line); if (rv) break; diff --git a/usr/src/boot/sys/boot/ficl/Makefile b/usr/src/boot/sys/boot/ficl/Makefile deleted file mode 100644 index 51e6a20ed9..0000000000 --- a/usr/src/boot/sys/boot/ficl/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -# -# This file and its contents are supplied under the terms of the -# Common Development and Distribution License ("CDDL"), version 1.0. -# You may only use this file in accordance with the terms of version -# 1.0 of the CDDL. -# -# A full copy of the text of the CDDL should have accompanied this -# source. A copy of the CDDL is also available via the Internet at -# http://www.illumos.org/license/CDDL. -# - -# -# Copyright 2016 Toomas Soome -# - -include $(SRC)/Makefile.master - -SUBDIRS = softcore $(MACH) $(MACH64) - -all := TARGET = all -install := TARGET = install -clean := TARGET = clean -clobber := TARGET = clobber - -all install: $(SUBDIRS) -clean clobber: $(SUBDIRS) - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(MFLAGS) $(TARGET) - -FRC: diff --git a/usr/src/boot/sys/boot/ficl/Makefile.inc b/usr/src/boot/sys/boot/ficl/Makefile.inc deleted file mode 100644 index 0213ace089..0000000000 --- a/usr/src/boot/sys/boot/ficl/Makefile.inc +++ /dev/null @@ -1,70 +0,0 @@ -# -# This file and its contents are supplied under the terms of the -# Common Development and Distribution License ("CDDL"), version 1.0. -# You may only use this file in accordance with the terms of version -# 1.0 of the CDDL. -# -# A full copy of the text of the CDDL should have accompanied this -# source. A copy of the CDDL is also available via the Internet at -# http://www.illumos.org/license/CDDL. -# - -# -# Copyright 2016 Toomas Soome -# Copyright 2016 RackTop Systems. -# - - -CC= $(GNUC_ROOT)/bin/gcc -FICLDIR= $(SRC)/common/ficl - -all: lib - -CPPFLAGS= -D_STANDALONE -I. -I.. -I../../../../include -CPPFLAGS += -I../../../../lib/libstand -CPPFLAGS += -I../../.. -I$(FICLDIR) -I../../common -CFLAGS= -O2 -Wall -nostdinc - -CFLAGS += -ffreestanding -CFLAGS += -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -msoft-float -CFLAGS += -std=gnu99 - -OBJECTS= dictionary.o system.o fileaccess.o float.o double.o prefix.o search.o -OBJECTS += softcore.o stack.o tools.o vm.o primitives.o unix.o utility.o -OBJECTS += hash.o callback.o word.o loader.o -HEADERS= $(FICLDIR)/ficl.h $(FICLDIR)/ficlplatform/unix.h ../ficllocal.h -# - -MAJOR = 4 -MINOR = 1.0 - -lib: libficl.a - -# static library build -libficl.a: $(OBJECTS) - $(AR) $(ARFLAGS) libficl.a $(OBJECTS) - -machine: - $(RM) machine - $(SYMLINK) ../../../$(MACHINE)/include machine - -x86: - $(RM) x86 - $(SYMLINK) ../../../x86/include x86 - -$(OBJECTS): machine x86 - -%.o: ../softcore/%.c $(HEADERS) - $(COMPILE.c) $< - -%.o: $(FICLDIR)/%.c $(HEADERS) - $(COMPILE.c) $< - -%.o: $(FICLDIR)/ficlplatform/%.c $(HEADERS) - $(COMPILE.c) $< - -# -# generic cleanup code -# -clobber clean: FRC - $(RM) *.o *.a libficl.* ficl machine x86 diff --git a/usr/src/boot/sys/boot/ficl/amd64/Makefile b/usr/src/boot/sys/boot/ficl/amd64/Makefile deleted file mode 100644 index e9187ba9eb..0000000000 --- a/usr/src/boot/sys/boot/ficl/amd64/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -# -# This file and its contents are supplied under the terms of the -# Common Development and Distribution License ("CDDL"), version 1.0. -# You may only use this file in accordance with the terms of version -# 1.0 of the CDDL. -# -# A full copy of the text of the CDDL should have accompanied this -# source. A copy of the CDDL is also available via the Internet at -# http://www.illumos.org/license/CDDL. -# - -# -# Copyright 2016 Toomas Soome -# - -include $(SRC)/Makefile.master - -MACHINE= $(MACH64) - -all install: lib - -include ../Makefile.inc - -CFLAGS += -fPIC -m64 -mno-red-zone - -FRC: diff --git a/usr/src/boot/sys/boot/ficl/ficllocal.h b/usr/src/boot/sys/boot/ficl/ficllocal.h deleted file mode 100644 index 964cd79780..0000000000 --- a/usr/src/boot/sys/boot/ficl/ficllocal.h +++ /dev/null @@ -1,11 +0,0 @@ -/* -** ficllocal.h -** -** Put all local settings here. This file will always ship empty. -** -*/ - -/* -** no need for float in loader -**/ -#define FICL_WANT_FLOAT (0) diff --git a/usr/src/boot/sys/boot/ficl/i386/Makefile b/usr/src/boot/sys/boot/ficl/i386/Makefile deleted file mode 100644 index 10e0c32dae..0000000000 --- a/usr/src/boot/sys/boot/ficl/i386/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# -# This file and its contents are supplied under the terms of the -# Common Development and Distribution License ("CDDL"), version 1.0. -# You may only use this file in accordance with the terms of version -# 1.0 of the CDDL. -# -# A full copy of the text of the CDDL should have accompanied this -# source. A copy of the CDDL is also available via the Internet at -# http://www.illumos.org/license/CDDL. -# - -# -# Copyright 2016 Toomas Soome -# - -include $(SRC)/Makefile.master - -MACHINE= $(MACH) - -all install: lib - -include ../Makefile.inc - -CFLAGS += -m32 -march=i386 -mpreferred-stack-boundary=2 -CFLAGS += -fno-reorder-functions - -FRC: diff --git a/usr/src/boot/sys/boot/ficl/softcore/Makefile b/usr/src/boot/sys/boot/ficl/softcore/Makefile deleted file mode 100644 index 7b42031180..0000000000 --- a/usr/src/boot/sys/boot/ficl/softcore/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -# -# This file and its contents are supplied under the terms of the -# Common Development and Distribution License ("CDDL"), version 1.0. -# You may only use this file in accordance with the terms of version -# 1.0 of the CDDL. -# -# A full copy of the text of the CDDL should have accompanied this -# source. A copy of the CDDL is also available via the Internet at -# http://www.illumos.org/license/CDDL. -# - -# -# Copyright 2018 Toomas Soome -# - -include $(SRC)/Makefile.master - -install all: softcore.c - -SOFTCORE= $(SRC)/common/ficl/softcore -PROG= $(ONBLD_TOOLS)/bin/$(MACH)/makesoftcore - -# -# not needed: file access -# -FR = softcore.fr ifbrack.fr prefix.fr ficl.fr jhlocal.fr marker.fr -FR += freebsd.fr ficllocal.fr oo.fr classes.fr string.fr wordsets.fr -SOURCES= $(FR:%=$(SOFTCORE)/%) - -softcore.c: $(SOURCES) - $(PROG) $(SOURCES) - -clobber clean: - $(RM) softcore.c diff --git a/usr/src/boot/sys/boot/i386/Makefile b/usr/src/boot/sys/boot/i386/Makefile index 55e7d5ca62..d2cd7d3e48 100644 --- a/usr/src/boot/sys/boot/i386/Makefile +++ b/usr/src/boot/sys/boot/i386/Makefile @@ -10,7 +10,7 @@ # # -# Copyright 2015 Toomas Soome +# Copyright 2017 Toomas Soome # include $(SRC)/Makefile.master @@ -33,7 +33,9 @@ all clean clobber: $(SUBDIRS) install: all .WAIT $(INSTDIRS) +loader: libi386 pxeldr: loader +cdboot gptzfsboot loader pxeldr: btx FRC: diff --git a/usr/src/boot/sys/boot/i386/Makefile.inc b/usr/src/boot/sys/boot/i386/Makefile.inc index 5398b4b545..5ef179f012 100644 --- a/usr/src/boot/sys/boot/i386/Makefile.inc +++ b/usr/src/boot/sys/boot/i386/Makefile.inc @@ -19,13 +19,11 @@ ROOT_BOOT= $(ROOT)/boot ROOTBOOTPROG=$(PROG:%=$(ROOT_BOOT)/%) LOADER_ADDRESS=0x200000 -CFLAGS += -march=i386 -ffreestanding -CFLAGS += -mpreferred-stack-boundary=2 +CFLAGS += -m32 -ffreestanding CFLAGS += -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -msoft-float -CFLAGS += -std=gnu99 -fno-reorder-functions +CFLAGS += -std=gnu99 LDFLAGS += -nostdlib -CFLAGS += -m32 ACFLAGS += -m32 AFLAGS += --32 diff --git a/usr/src/boot/sys/boot/i386/btx/btx/Makefile b/usr/src/boot/sys/boot/i386/btx/btx/Makefile index 3642e6e962..8fe11ab569 100644 --- a/usr/src/boot/sys/boot/i386/btx/btx/Makefile +++ b/usr/src/boot/sys/boot/i386/btx/btx/Makefile @@ -48,7 +48,7 @@ ORG= 0x9000 LDFLAGS=-e start -Ttext ${ORG} -N -S --oformat binary -all: $(PROG) +all install: $(PROG) $(PROG): $(OBJS) $(LD) $(LDFLAGS) -o $@ $(OBJS) diff --git a/usr/src/boot/sys/boot/i386/btx/btxldr/Makefile b/usr/src/boot/sys/boot/i386/btx/btxldr/Makefile index 4792ee0e16..151c95f9ab 100644 --- a/usr/src/boot/sys/boot/i386/btx/btxldr/Makefile +++ b/usr/src/boot/sys/boot/i386/btx/btxldr/Makefile @@ -32,14 +32,14 @@ CFLAGS += -DBTXLDR_VERBOSE LDFLAGS=-e start -Ttext ${LOADER_ADDRESS} -N -S --oformat binary +all install: $(PROG) + $(PROG): $(OBJS) $(LD) $(LDFLAGS) -o $@ $(OBJS) .S.o: $(COMPILE.S) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< -all: $(PROG) - clobber: clean clean: diff --git a/usr/src/boot/sys/boot/i386/btx/lib/Makefile b/usr/src/boot/sys/boot/i386/btx/lib/Makefile index 68dd201f26..bf89dbc619 100644 --- a/usr/src/boot/sys/boot/i386/btx/lib/Makefile +++ b/usr/src/boot/sys/boot/i386/btx/lib/Makefile @@ -31,7 +31,7 @@ OBJS= btxcsu.o btxsys.o btxv86.o LDFLAGS=-Wl,-r -nostdlib -all: $(PROG) +all install: $(PROG) $(PROG): $(OBJS) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) diff --git a/usr/src/boot/sys/boot/i386/gptzfsboot/Makefile b/usr/src/boot/sys/boot/i386/gptzfsboot/Makefile index 97eb446b90..892a9d7a81 100644 --- a/usr/src/boot/sys/boot/i386/gptzfsboot/Makefile +++ b/usr/src/boot/sys/boot/i386/gptzfsboot/Makefile @@ -63,8 +63,8 @@ CFLAGS += -fno-reorder-functions LD_FLAGS=-static -N --gc-sections CCASFLAGS=-Wa,--divide -LIBSTAND= ../../libstand/i386/libstand.a -LIBZFSBOOT= ../../zfs/i386/libzfsboot.a +LIBSTAND= ../../libstand/$(MACH)/libstand.a +LIBZFSBOOT= ../../zfs/$(MACH)/libzfsboot.a include ../Makefile.inc diff --git a/usr/src/boot/sys/boot/i386/libi386/Makefile b/usr/src/boot/sys/boot/i386/libi386/Makefile index 8b0d0bfc05..951a2dda64 100644 --- a/usr/src/boot/sys/boot/i386/libi386/Makefile +++ b/usr/src/boot/sys/boot/i386/libi386/Makefile @@ -19,7 +19,7 @@ include $(SRC)/Makefile.master CFLAGS= -O2 -I../../../../include -I../../.. CPPFLAGS= -D_STANDALONE -DLOADER_ZFS_SUPPORT -all: libi386.a +all install: libi386.a clean: clobber clobber: @@ -74,7 +74,7 @@ CFLAGS += -DTERM_EMU # XXX: make alloca() useable CFLAGS += -Dalloca=__builtin_alloca -CFLAGS += -I$(SRC)/common/ficl -I../../ficl \ +CFLAGS += -I$(SRC)/common/ficl -I../../libficl \ -I../../common -I../common \ -I../btx/lib \ -I$(SRC)/uts/intel/sys/acpi \ diff --git a/usr/src/boot/sys/boot/i386/loader/Makefile b/usr/src/boot/sys/boot/i386/loader/Makefile index e38284da08..ec9c6123aa 100644 --- a/usr/src/boot/sys/boot/i386/loader/Makefile +++ b/usr/src/boot/sys/boot/i386/loader/Makefile @@ -17,7 +17,7 @@ include $(SRC)/Makefile.master include $(SRC)/boot/Makefile.version -CFLAGS= -O2 +CFLAGS= -O2 -fno-reorder-functions CPPFLAGS= -D_STANDALONE -nostdinc -I../../../../include -I../../.. CPPFLAGS += -I$(SRC)/uts/intel/sys/acpi LOADER= loader @@ -26,7 +26,7 @@ NEWVERSWHAT= "ZFS enabled bootstrap loader" x86 # Set by loader Makefile CPPFLAGS += -DLOADER_ZFS_SUPPORT -I../../zfs CPPFLAGS += -I../libi386 -LIBZFSBOOT= ../../zfs/i386/libzfsboot.a +LIBZFSBOOT= ../../zfs/$(MACH)/libzfsboot.a LIBI386= ../libi386/libi386.a # loader.help build needs better awk @@ -57,8 +57,8 @@ SRCS= main.c conf.c vers.c chain.c CPPFLAGS += -DLOADER_GZIP_SUPPORT # Enable BootForth -CPPFLAGS += -DBOOT_FORTH -I$(SRC)/common/ficl -I../../ficl -LIBFICL= ../../ficl/i386/libficl.a +CPPFLAGS += -DBOOT_FORTH -I$(SRC)/common/ficl -I../../libficl +LIBFICL= ../../libficl/$(MACH)/libficl.a # Always add MI sources SRCS += boot.c commands.c console.c devopen.c interp.c @@ -94,7 +94,7 @@ LDFLAGS= -static -Ttext 0x0 # i386 standalone support library CPPFLAGS += -I.. -I../../../../lib/libstand -LIBSTAND= ../../libstand/i386/libstand.a +LIBSTAND= ../../libstand/$(MACH)/libstand.a # BTX components CPPFLAGS += -I../btx/lib diff --git a/usr/src/boot/sys/boot/libficl/Makefile b/usr/src/boot/sys/boot/libficl/Makefile new file mode 100644 index 0000000000..51e6a20ed9 --- /dev/null +++ b/usr/src/boot/sys/boot/libficl/Makefile @@ -0,0 +1,31 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome +# + +include $(SRC)/Makefile.master + +SUBDIRS = softcore $(MACH) $(MACH64) + +all := TARGET = all +install := TARGET = install +clean := TARGET = clean +clobber := TARGET = clobber + +all install: $(SUBDIRS) +clean clobber: $(SUBDIRS) + +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(MFLAGS) $(TARGET) + +FRC: diff --git a/usr/src/boot/sys/boot/libficl/Makefile.com b/usr/src/boot/sys/boot/libficl/Makefile.com new file mode 100644 index 0000000000..3226faf88d --- /dev/null +++ b/usr/src/boot/sys/boot/libficl/Makefile.com @@ -0,0 +1,63 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome +# + + +CC= $(GNUC_ROOT)/bin/gcc +FICLDIR= $(SRC)/common/ficl + +CPPFLAGS= -nostdinc -D_STANDALONE -I. -I.. -I../../../../include +CPPFLAGS += -I../../../../lib/libstand +CPPFLAGS += -I../../.. -I$(FICLDIR) -I../../common + +CFLAGS= -O2 -fPIC -Wall -ffreestanding -mno-mmx -mno-3dnow -mno-sse +CFLAGS += -mno-sse2 -mno-sse3 -msoft-float -std=gnu99 + +OBJECTS= dictionary.o system.o fileaccess.o float.o double.o prefix.o search.o +OBJECTS += softcore.o stack.o tools.o vm.o primitives.o unix.o utility.o +OBJECTS += hash.o callback.o word.o loader.o +HEADERS= $(FICLDIR)/ficl.h $(FICLDIR)/ficlplatform/unix.h ../ficllocal.h +# + +MAJOR = 4 +MINOR = 1.0 + +lib: libficl.a + +# static library build +libficl.a: $(OBJECTS) + $(AR) $(ARFLAGS) libficl.a $(OBJECTS) + +machine: + $(RM) machine + $(SYMLINK) ../../../$(MACHINE)/include machine + +x86: + $(RM) x86 + $(SYMLINK) ../../../x86/include x86 + +%.o: ../softcore/%.c $(HEADERS) + $(COMPILE.c) $< + +%.o: $(FICLDIR)/%.c $(HEADERS) + $(COMPILE.c) $< + +%.o: $(FICLDIR)/ficlplatform/%.c $(HEADERS) + $(COMPILE.c) $< + +# +# generic cleanup code +# +clobber clean: FRC + $(RM) *.o *.a libficl.* ficl machine x86 diff --git a/usr/src/boot/sys/boot/libficl/amd64/Makefile b/usr/src/boot/sys/boot/libficl/amd64/Makefile new file mode 100644 index 0000000000..bd9b9b4158 --- /dev/null +++ b/usr/src/boot/sys/boot/libficl/amd64/Makefile @@ -0,0 +1,29 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. +# + +include $(SRC)/Makefile.master + +MACHINE= $(MACH64) + +all install: lib + +include ../Makefile.com + +CFLAGS += -m64 -mno-red-zone + +$(OBJECTS): machine x86 + +FRC: diff --git a/usr/src/boot/sys/boot/libficl/ficllocal.h b/usr/src/boot/sys/boot/libficl/ficllocal.h new file mode 100644 index 0000000000..964cd79780 --- /dev/null +++ b/usr/src/boot/sys/boot/libficl/ficllocal.h @@ -0,0 +1,11 @@ +/* +** ficllocal.h +** +** Put all local settings here. This file will always ship empty. +** +*/ + +/* +** no need for float in loader +**/ +#define FICL_WANT_FLOAT (0) diff --git a/usr/src/boot/sys/boot/libficl/i386/Makefile b/usr/src/boot/sys/boot/libficl/i386/Makefile new file mode 100644 index 0000000000..f4478a4c50 --- /dev/null +++ b/usr/src/boot/sys/boot/libficl/i386/Makefile @@ -0,0 +1,29 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. +# + +include $(SRC)/Makefile.master + +MACHINE= $(MACH) + +all install: lib + +include ../Makefile.com + +CFLAGS += -m32 + +$(OBJECTS): machine x86 + +FRC: diff --git a/usr/src/boot/sys/boot/libficl/softcore/Makefile b/usr/src/boot/sys/boot/libficl/softcore/Makefile new file mode 100644 index 0000000000..7b42031180 --- /dev/null +++ b/usr/src/boot/sys/boot/libficl/softcore/Makefile @@ -0,0 +1,34 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2018 Toomas Soome +# + +include $(SRC)/Makefile.master + +install all: softcore.c + +SOFTCORE= $(SRC)/common/ficl/softcore +PROG= $(ONBLD_TOOLS)/bin/$(MACH)/makesoftcore + +# +# not needed: file access +# +FR = softcore.fr ifbrack.fr prefix.fr ficl.fr jhlocal.fr marker.fr +FR += freebsd.fr ficllocal.fr oo.fr classes.fr string.fr wordsets.fr +SOURCES= $(FR:%=$(SOFTCORE)/%) + +softcore.c: $(SOURCES) + $(PROG) $(SOURCES) + +clobber clean: + $(RM) softcore.c diff --git a/usr/src/boot/sys/boot/libstand/Makefile.com b/usr/src/boot/sys/boot/libstand/Makefile.com index fe4b002e7e..6b9bf4e253 100644 --- a/usr/src/boot/sys/boot/libstand/Makefile.com +++ b/usr/src/boot/sys/boot/libstand/Makefile.com @@ -11,7 +11,6 @@ # # Copyright 2016 Toomas Soome -# Copyright 2016 RackTop Systems. # include $(SRC)/Makefile.master @@ -20,29 +19,26 @@ AS= $(GNU_ROOT)/bin/gas LD= $(GNU_ROOT)/bin/gld CC= $(GNUC_ROOT)/bin/gcc -LIBRARY= libstand.a - -all install: $(LIBRARY) - LIB_BASE= $(SRC)/boot/lib LIBSTAND_SRC= $(LIB_BASE)/libstand -CPPFLAGS = -nostdinc -I../../../../include -I${LIBSTAND_SRC} -I../../.. -CPPFLAGS += -I../../../sys -I. -I$(SRC)/common/bzip2 +ASFLAGS = -fPIC +CPPFLAGS = -nostdinc -I../../../../include -I$(LIBSTAND_SRC) +CPPFLAGS += -I../../.. -I../../../sys -I. -I$(SRC)/common/bzip2 CPPFLAGS += -D_STANDALONE -CFLAGS = -O2 -ffreestanding -Wformat +CFLAGS = -O2 -fPIC -ffreestanding -Wformat CFLAGS += -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -msoft-float CFLAGS += -Wall -Werror -include ${LIBSTAND_SRC}/Makefile.inc - $(LIBRARY): $(SRCS) $(OBJS) $(AR) $(ARFLAGS) $@ $(OBJS) +include $(LIBSTAND_SRC)/Makefile.inc + clean: clobber clobber: - $(RM) $(CLEANFILES) $(OBJS) machine x86 libstand.a + $(RM) $(CLEANFILES) $(OBJS) machine $(LIBRARY) machine: $(RM) machine @@ -52,8 +48,6 @@ x86: $(RM) x86 $(SYMLINK) ../../../x86/include x86 -$(OBJS): machine x86 - %.o: $(LIBSTAND_SRC)/%.c $(COMPILE.c) $< diff --git a/usr/src/boot/sys/boot/libstand/amd64/Makefile b/usr/src/boot/sys/boot/libstand/amd64/Makefile index 3516128c65..de2359271f 100644 --- a/usr/src/boot/sys/boot/libstand/amd64/Makefile +++ b/usr/src/boot/sys/boot/libstand/amd64/Makefile @@ -11,14 +11,20 @@ # # Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. # +MACHINE= $(MACH64) +LIBRARY= libstand.a + +all install: $(LIBRARY) + include ../Makefile.com -MACHINE= $(MACH64) +CFLAGS += -m64 -mno-red-zone +ASFLAGS += -m64 -CFLAGS += -m64 -fPIC -mno-red-zone -ASFLAGS = -m64 -fPIC +CLEANFILES += x86 # _setjmp/_longjmp SRCS += $(LIBSTAND_SRC)/amd64/_setjmp.S @@ -26,5 +32,7 @@ OBJS += _setjmp.o $(LIBRARY): $(SRCS) $(OBJS) +$(OBJS): machine x86 + %.o: $(LIBSTAND_SRC)/amd64/%.S $(COMPILE.S) $< diff --git a/usr/src/boot/sys/boot/libstand/i386/Makefile b/usr/src/boot/sys/boot/libstand/i386/Makefile index 80983da037..8a26d7bc40 100644 --- a/usr/src/boot/sys/boot/libstand/i386/Makefile +++ b/usr/src/boot/sys/boot/libstand/i386/Makefile @@ -11,14 +11,20 @@ # # Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. # +MACHINE= $(MACH) +LIBRARY= libstand.a + +all install: $(LIBRARY) + include ../Makefile.com -MACHINE= $(MACH) +CFLAGS += -m32 +ASFLAGS += -m32 -CFLAGS += -m32 -fno-reorder-functions -CFLAGS += -mpreferred-stack-boundary=2 +CLEANFILES += x86 # _setjmp/_longjmp SRCS += $(LIBSTAND_SRC)/i386/_setjmp.S @@ -26,5 +32,7 @@ OBJS += _setjmp.o $(LIBRARY): $(SRCS) $(OBJS) +$(OBJS): machine x86 + %.o: $(LIBSTAND_SRC)/i386/%.S $(COMPILE.S) $< diff --git a/usr/src/boot/sys/boot/usb/Makefile b/usr/src/boot/sys/boot/usb/Makefile index 1b94b3db7d..6ad13d0173 100644 --- a/usr/src/boot/sys/boot/usb/Makefile +++ b/usr/src/boot/sys/boot/usb/Makefile @@ -43,7 +43,6 @@ CFLAGS+= -fno-pic .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" CFLAGS+= -march=i386 -CFLAGS.gcc+= -mpreferred-stack-boundary=2 .endif .if ${MACHINE_CPUARCH} == "amd64" CFLAGS+= -m32 diff --git a/usr/src/boot/sys/boot/usb/Makefile.test b/usr/src/boot/sys/boot/usb/Makefile.test index 7c6a66d173..9b6478a0bb 100644 --- a/usr/src/boot/sys/boot/usb/Makefile.test +++ b/usr/src/boot/sys/boot/usb/Makefile.test @@ -40,7 +40,6 @@ CFLAGS+= -g .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" CFLAGS+= -march=i386 -CFLAGS.gcc+= -mpreferred-stack-boundary=2 .endif .if ${MACHINE_CPUARCH} == "amd64" CFLAGS+= -m32 diff --git a/usr/src/boot/sys/boot/zfs/Makefile b/usr/src/boot/sys/boot/zfs/Makefile index 025cd562d3..660b8e3485 100644 --- a/usr/src/boot/sys/boot/zfs/Makefile +++ b/usr/src/boot/sys/boot/zfs/Makefile @@ -10,12 +10,12 @@ # # -# Copyright 2015 Toomas Soome +# Copyright 2016 Toomas Soome # include $(SRC)/Makefile.master -SUBDIRS= i386 amd64 +SUBDIRS= $(MACH) $(MACH64) all:= TARGET= all install:= TARGET= install diff --git a/usr/src/boot/sys/boot/zfs/Makefile.com b/usr/src/boot/sys/boot/zfs/Makefile.com index 7ece715f1d..96adde7a82 100644 --- a/usr/src/boot/sys/boot/zfs/Makefile.com +++ b/usr/src/boot/sys/boot/zfs/Makefile.com @@ -11,45 +11,44 @@ # # Copyright 2016 Toomas Soome -# Copyright 2016 RackTop Systems. # include $(SRC)/Makefile.master LIB= zfsboot -all: libzfsboot.a - clean: clobber clobber: $(RM) machine x86 $(OBJS) libzfsboot.a CC= $(GNUC_ROOT)/bin/gcc -CPPFLAGS= -SRCS += ../zfs.c ../gzip.c +CFLAGS= -O2 +CFLAGS += -fPIC -ffreestanding -msoft-float +CFLAGS += -mno-mmx -mno-3dnow -mno-sse2 -mno-sse3 -mno-sse +CFLAGS += -mno-avx -mno-aes -std=gnu99 + +SRCS += $(SRC)/boot/sys/boot/zfs/zfs.c $(SRC)/boot/sys/boot/zfs/gzip.c SRCS += $(SRC)/common/crypto/edonr/edonr.c SRCS += $(SRC)/common/crypto/skein/skein.c SRCS += $(SRC)/common/crypto/skein/skein_iv.c SRCS += $(SRC)/common/crypto/skein/skein_block.c OBJS += zfs.o gzip.o edonr.o skein.o skein_iv.o skein_block.o -CFLAGS= -O2 -D_STANDALONE -nostdinc -I../../../../include -I../../.. -CFLAGS += -I../../common -I../../.. -I.. -I. -CFLAGS += -I../../../../lib/libstand -CFLAGS += -I../../../../lib/libz -CFLAGS += -I../../../cddl/boot/zfs -CFLAGS += -I$(SRC)/uts/common +CPPFLAGS= -D_STANDALONE -nostdinc -I../../../../include -I../.. +CPPFLAGS += -I../../common -I../../.. -I.. -I. +CPPFLAGS += -I../../../../lib/libstand +CPPFLAGS += -I../../../../lib/libz +CPPFLAGS += -I../../../cddl/boot/zfs +CPPFLAGS += -I$(SRC)/uts/common # Do not unroll skein loops, reduce code size -CFLAGS += -DSKEIN_LOOP=111 +CPPFLAGS += -DSKEIN_LOOP=111 -CFLAGS += -ffreestanding -CFLAGS += -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -msoft-float -CFLAGS += -Wformat -Wall -std=gnu99 +#include ../../Makefile.inc -CLEANFILES += machine x86 +CLEANFILES += machine machine: $(RM) machine @@ -59,12 +58,10 @@ x86: $(RM) x86 $(SYMLINK) ../../../x86/include x86 -$(OBJS): machine x86 - libzfsboot.a: $(OBJS) $(AR) $(ARFLAGS) $@ $(OBJS) -%.o: ../%.c +%.o: $(SRC)/boot/sys/boot/zfs/%.c $(COMPILE.c) -o $@ $< %.o: $(SRC)/common/crypto/edonr/%.c @@ -73,4 +70,4 @@ libzfsboot.a: $(OBJS) %.o: $(SRC)/common/crypto/skein/%.c $(COMPILE.c) -o $@ $< -zfs.o: ../zfsimpl.c +zfs.o: $(SRC)/boot/sys/boot/zfs/zfsimpl.c diff --git a/usr/src/boot/sys/boot/zfs/amd64/Makefile b/usr/src/boot/sys/boot/zfs/amd64/Makefile index 80eb330468..da13c92b13 100644 --- a/usr/src/boot/sys/boot/zfs/amd64/Makefile +++ b/usr/src/boot/sys/boot/zfs/amd64/Makefile @@ -11,10 +11,16 @@ # # Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. # +MACHINE= $(MACH64) + +all install: libzfsboot.a + include ../Makefile.com -CFLAGS += -mno-red-zone -m64 -fPIC +CLEANFILES += x86 +CFLAGS += -mno-red-zone -m64 -MACHINE= $(MACH64) +$(OBJS): machine x86 diff --git a/usr/src/boot/sys/boot/zfs/i386/Makefile b/usr/src/boot/sys/boot/zfs/i386/Makefile index f2bb545d73..3875f9abd2 100644 --- a/usr/src/boot/sys/boot/zfs/i386/Makefile +++ b/usr/src/boot/sys/boot/zfs/i386/Makefile @@ -11,11 +11,16 @@ # # Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. # +MACHINE= $(MACH) + +all install: libzfsboot.a + include ../Makefile.com -CFLAGS += -march=i386 -m32 -fno-reorder-functions -CFLAGS += -mpreferred-stack-boundary=2 +CLEANFILES += x86 +CFLAGS += -m32 -MACHINE= $(MACH) +$(OBJS): machine x86 diff --git a/usr/src/pkg/manifests/system-boot-loader.mf b/usr/src/pkg/manifests/system-boot-loader.mf index 346acbc720..ce0af6a4f7 100644 --- a/usr/src/pkg/manifests/system-boot-loader.mf +++ b/usr/src/pkg/manifests/system-boot-loader.mf @@ -43,7 +43,8 @@ $(i386_ONLY)dir path=usr/share/man $(i386_ONLY)dir path=usr/share/man/man3 $(i386_ONLY)dir path=usr/share/man/man4 $(i386_ONLY)dir path=usr/share/man/man5 -$(i386_ONLY)file path=boot/boot1.efi group=sys mode=0555 +$(i386_ONLY)file path=boot/bootia32.efi group=sys mode=0555 +$(i386_ONLY)file path=boot/bootx64.efi group=sys mode=0555 $(i386_ONLY)file path=boot/cdboot group=sys mode=0444 $(i386_ONLY)file path=boot/defaults/loader.conf group=sys mode=0444 $(i386_ONLY)file path=boot/forth/beadm.4th group=sys mode=0444 @@ -73,9 +74,10 @@ $(i386_ONLY)file path=boot/forth/support.4th group=sys mode=0444 $(i386_ONLY)file path=boot/forth/version.4th group=sys mode=0444 $(i386_ONLY)file path=boot/gptzfsboot group=sys mode=0444 $(i386_ONLY)file path=boot/loader group=sys mode=0444 -$(i386_ONLY)file path=boot/loader.efi group=sys mode=0555 $(i386_ONLY)file path=boot/loader.help group=sys mode=0444 $(i386_ONLY)file path=boot/loader.rc group=sys mode=0444 +$(i386_ONLY)file path=boot/loader32.efi group=sys mode=0555 +$(i386_ONLY)file path=boot/loader64.efi group=sys mode=0555 $(i386_ONLY)file path=boot/pmbr group=sys mode=0444 $(i386_ONLY)file path=boot/pxeboot group=sys mode=0444 $(i386_ONLY)file path=usr/share/man/man4/loader.conf.4 -- cgit v1.2.3 From 4226f635096bf9d814aa9fb335518c4855bbe3a3 Mon Sep 17 00:00:00 2001 From: Jason King Date: Sat, 27 May 2017 18:46:17 -0500 Subject: 6375 Add native name demangling support Reviewed by: Robert Mustacchi Reviewed by: Richard Lowe Approved by: Dan McDonald --- exception_lists/packaging | 2 + usr/src/cmd/dis/Makefile | 6 +- usr/src/cmd/dis/dis_util.c | 60 +- usr/src/cmd/mdb/Makefile.mdb | 2 + usr/src/cmd/mdb/common/kmdb/kmdb_demangle.c | 6 +- usr/src/cmd/mdb/common/mdb/mdb_demangle.c | 146 +- usr/src/cmd/mdb/common/mdb/mdb_demangle.h | 11 +- usr/src/cmd/sgs/dump/common/dump.c | 29 +- usr/src/cmd/sgs/gprof/common/printgprof.c | 99 +- usr/src/cmd/sgs/libconv/Makefile.com | 45 +- usr/src/cmd/sgs/libconv/common/demangle.c | 48 +- usr/src/cmd/sgs/libconv/common/demangle.msg | 6 +- usr/src/cmd/sgs/libconv/common/lintsup.c | 2 +- usr/src/cmd/sgs/liblddbg/common/util.c | 29 +- usr/src/cmd/sgs/nm/common/nm.c | 56 +- usr/src/cmd/sgs/prof/common/prof.c | 12 +- usr/src/cmd/sgs/prof/common/profv.c | 8 +- usr/src/lib/Makefile | 3 + usr/src/lib/libdemangle/Makefile | 41 + usr/src/lib/libdemangle/Makefile.com | 43 + usr/src/lib/libdemangle/THIRDPARTYLICENSE | 76 + usr/src/lib/libdemangle/THIRDPARTYLICENSE.descrip | 1 + usr/src/lib/libdemangle/amd64/Makefile | 30 + usr/src/lib/libdemangle/common/cxx.c | 4217 +++ usr/src/lib/libdemangle/common/cxx.h | 87 + usr/src/lib/libdemangle/common/cxx_util.c | 600 + usr/src/lib/libdemangle/common/demangle-sys.h | 41 + usr/src/lib/libdemangle/common/demangle.c | 87 + usr/src/lib/libdemangle/common/demangle_int.h | 39 + usr/src/lib/libdemangle/common/llib-ldemangle-sys | 29 + usr/src/lib/libdemangle/common/mapfile-vers | 36 + usr/src/lib/libdemangle/common/str.c | 313 + usr/src/lib/libdemangle/common/str.h | 63 + usr/src/lib/libdemangle/common/util.c | 85 + usr/src/lib/libdemangle/i386/Makefile | 30 + usr/src/lib/libdemangle/sparc/Makefile | 30 + usr/src/lib/libdemangle/sparcv9/Makefile | 29 + usr/src/pkg/manifests/system-library-demangle.mf | 43 + usr/src/pkg/manifests/system-test-utiltest.mf | 7 + usr/src/test/util-tests/runfiles/default.run | 3 + usr/src/test/util-tests/tests/Makefile | 2 + usr/src/test/util-tests/tests/demangle/Makefile | 73 + usr/src/test/util-tests/tests/demangle/afl-fast.c | 2955 ++ .../test/util-tests/tests/demangle/gcc-libstdc++.c | 8670 ++++++ .../util-tests/tests/demangle/llvm-stdcxxabi.c | 29733 +++++++++++++++++++ 45 files changed, 47643 insertions(+), 290 deletions(-) create mode 100644 usr/src/lib/libdemangle/Makefile create mode 100644 usr/src/lib/libdemangle/Makefile.com create mode 100644 usr/src/lib/libdemangle/THIRDPARTYLICENSE create mode 100644 usr/src/lib/libdemangle/THIRDPARTYLICENSE.descrip create mode 100644 usr/src/lib/libdemangle/amd64/Makefile create mode 100644 usr/src/lib/libdemangle/common/cxx.c create mode 100644 usr/src/lib/libdemangle/common/cxx.h create mode 100644 usr/src/lib/libdemangle/common/cxx_util.c create mode 100644 usr/src/lib/libdemangle/common/demangle-sys.h create mode 100644 usr/src/lib/libdemangle/common/demangle.c create mode 100644 usr/src/lib/libdemangle/common/demangle_int.h create mode 100644 usr/src/lib/libdemangle/common/llib-ldemangle-sys create mode 100644 usr/src/lib/libdemangle/common/mapfile-vers create mode 100644 usr/src/lib/libdemangle/common/str.c create mode 100644 usr/src/lib/libdemangle/common/str.h create mode 100644 usr/src/lib/libdemangle/common/util.c create mode 100644 usr/src/lib/libdemangle/i386/Makefile create mode 100644 usr/src/lib/libdemangle/sparc/Makefile create mode 100644 usr/src/lib/libdemangle/sparcv9/Makefile create mode 100644 usr/src/pkg/manifests/system-library-demangle.mf create mode 100644 usr/src/test/util-tests/tests/demangle/Makefile create mode 100644 usr/src/test/util-tests/tests/demangle/afl-fast.c create mode 100644 usr/src/test/util-tests/tests/demangle/gcc-libstdc++.c create mode 100644 usr/src/test/util-tests/tests/demangle/llvm-stdcxxabi.c (limited to 'usr/src') diff --git a/exception_lists/packaging b/exception_lists/packaging index e5d28d6bc4..da8bc8d90b 100644 --- a/exception_lists/packaging +++ b/exception_lists/packaging @@ -28,6 +28,7 @@ # Copyright 2017 Toomas Soome # Copyright 2017 RackTop Systems. # Copyright 2018, Joyent, Inc. +# Copyright 2018 Jason King # # @@ -42,6 +43,7 @@ usr/include/auth_list.h usr/include/bsm/audit_door_infc.h usr/include/bsm/audit_private.h usr/include/bsm/devalloc.h +usr/include/demangle-sys.h usr/include/getxby_door.h usr/include/passwdutil.h usr/include/priv_utils.h diff --git a/usr/src/cmd/dis/Makefile b/usr/src/cmd/dis/Makefile index f17298c92b..c35932248f 100644 --- a/usr/src/cmd/dis/Makefile +++ b/usr/src/cmd/dis/Makefile @@ -22,14 +22,16 @@ # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # +# Copyright 2018 Jason King +# PROG= dis OBJS= dis_target.o dis_main.o dis_util.o dis_list.o SRCS= $(OBJS:%.o=%.c) -include ../Makefile.cmd +include ../Makefile.cmd -LDLIBS += -ldisasm -luutil -lelf +LDLIBS += -ldisasm -luutil -lelf -ldemangle-sys CERRWARN += -_gcc=-Wno-uninitialized .KEEP_STATE: diff --git a/usr/src/cmd/dis/dis_util.c b/usr/src/cmd/dis/dis_util.c index 816c41394c..f74e7cef67 100644 --- a/usr/src/cmd/dis/dis_util.c +++ b/usr/src/cmd/dis/dis_util.c @@ -22,15 +22,15 @@ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Copyright 2018 Jason King. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include #include #include #include -#include +#include #include "dis_util.h" @@ -92,56 +92,20 @@ safe_malloc(size_t size) /* - * Generic interface to demangle C++ names. Calls cplus_demangle to do the - * necessary translation. If the translation fails, the argument is returned - * unchanged. The memory returned is only valid until the next call to - * demangle(). - * - * We dlopen() libdemangle.so rather than linking directly against it in case it - * is not installed on the system. + * Since the -C flag explicitly says C++, for now at least, force language to + * C++ */ const char * dis_demangle(const char *name) { - static char *demangled_name; - static int (*demangle_func)() = NULL; - static int size = BUFSIZE; - static int first_flag = 0; - int ret; + static char *demangled_name = NULL; /* - * If this is the first call, allocate storage - * for the buffer. + * Since demangled_name is static, it may be preserved across + * invocations. As such, make sure any memory that might be present + * from previous invocations is freed. */ - if (first_flag == 0) { - void *demangle_hand; - - demangle_hand = dlopen("libdemangle.so.1", RTLD_LAZY); - if (demangle_hand != NULL) - demangle_func = (int (*)(int))dlsym( - demangle_hand, "cplus_demangle"); - - demangled_name = safe_malloc(size); - first_flag = 1; - } - - /* - * If libdemangle is not present, pass through unchanged. - */ - if (demangle_func == NULL) - return (name); - - /* - * The function returns -1 when the buffer size is not sufficient. - */ - while ((ret = (*demangle_func)(name, demangled_name, size)) == -1) { - free(demangled_name); - size = size + BUFSIZE; - demangled_name = safe_malloc(size); - } - - if (ret != 0) - return (name); - - return (demangled_name); + free(demangled_name); + demangled_name = sysdemangle(name, SYSDEM_LANG_CPP, NULL); + return ((demangled_name != NULL) ? demangled_name : name); } diff --git a/usr/src/cmd/mdb/Makefile.mdb b/usr/src/cmd/mdb/Makefile.mdb index 852ce281ac..529f3a9a12 100644 --- a/usr/src/cmd/mdb/Makefile.mdb +++ b/usr/src/cmd/mdb/Makefile.mdb @@ -27,6 +27,7 @@ # Copyright 2011 Nexenta Systems, Inc. All rights reserved. # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright (c) 2012 Joyent, Inc. All rights reserved. +# Copyright 2018 Jason King # .KEEP_STATE: @@ -99,6 +100,7 @@ CSTD= $(CSTD_GNU99) C99LMODE= -Xc99=%all LDLIBS += -lcurses -lkvm -lproc -lrtld_db -lctf -lumem -ldisasm -lscf +LDLIBS += -ldemangle-sys CERRWARN += -_gcc=-Wno-uninitialized CERRWARN += -_gcc=-Wno-char-subscripts diff --git a/usr/src/cmd/mdb/common/kmdb/kmdb_demangle.c b/usr/src/cmd/mdb/common/kmdb/kmdb_demangle.c index efa73d023c..2027b2f186 100644 --- a/usr/src/cmd/mdb/common/kmdb/kmdb_demangle.c +++ b/usr/src/cmd/mdb/common/kmdb/kmdb_demangle.c @@ -22,17 +22,17 @@ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Copyright 2017 Jason King. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include #include #include /*ARGSUSED*/ mdb_demangler_t * -mdb_dem_load(const char *path) +mdb_dem_load(void) { (void) set_errno(ENOTSUP); return (NULL); diff --git a/usr/src/cmd/mdb/common/mdb/mdb_demangle.c b/usr/src/cmd/mdb/common/mdb/mdb_demangle.c index 7ab7d19716..ad7555dcc0 100644 --- a/usr/src/cmd/mdb/common/mdb/mdb_demangle.c +++ b/usr/src/cmd/mdb/common/mdb/mdb_demangle.c @@ -22,55 +22,48 @@ /* * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Copyright 2018 Jason King */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include #include #include #include -#include #include #include #include #include -#ifdef _LP64 -static const char LIB_DEMANGLE[] = "/usr/lib/64/libdemangle.so.1"; -#else -static const char LIB_DEMANGLE[] = "/usr/lib/libdemangle.so.1"; -#endif - -mdb_demangler_t * -mdb_dem_load(const char *path) +static void * +mdb_dem_alloc(size_t len) { - mdb_demangler_t *dmp; - void *hdl, *func; + return (mdb_alloc(len, UM_SLEEP)); +} - if (access(path, F_OK) == -1) - return (NULL); +static void +mdb_dem_free(void *p, size_t len) +{ + mdb_free(p, len); +} - if ((hdl = dlmopen(LM_ID_BASE, path, RTLD_LAZY | RTLD_LOCAL)) == NULL) { - (void) set_errno(EMDB_RTLD); - return (NULL); - } +static sysdem_ops_t mdb_dem_demops = { + .alloc = mdb_dem_alloc, + .free = mdb_dem_free +}; - if ((func = dlsym(hdl, "cplus_demangle")) == NULL) { - (void) dlclose(hdl); - (void) set_errno(EMDB_NODEM); - return (NULL); - } +mdb_demangler_t * +mdb_dem_load(void) +{ + mdb_demangler_t *dmp; dmp = mdb_alloc(sizeof (mdb_demangler_t), UM_SLEEP); - (void) strncpy(dmp->dm_pathname, path, MAXPATHLEN); - dmp->dm_pathname[MAXPATHLEN - 1] = '\0'; - dmp->dm_handle = hdl; - dmp->dm_convert = (int (*)())func; - dmp->dm_len = MDB_SYM_NAMLEN * 2; - dmp->dm_buf = mdb_alloc(dmp->dm_len, UM_SLEEP); + dmp->dm_len = 0; + dmp->dm_buf = NULL; dmp->dm_flags = MDB_DM_SCOPE; + /* stick with C++ for now to match old behavior */ + dmp->dm_lang = SYSDEM_LANG_CPP; return (dmp); } @@ -78,7 +71,6 @@ mdb_dem_load(const char *path) void mdb_dem_unload(mdb_demangler_t *dmp) { - (void) dlclose(dmp->dm_handle); mdb_free(dmp->dm_buf, dmp->dm_len); mdb_free(dmp, sizeof (mdb_demangler_t)); } @@ -202,58 +194,65 @@ mdb_dem_filter(mdb_demangler_t *dmp, const char *name) static int mdb_dem_process(mdb_demangler_t *dmp, const char *name) { - char *buf = dmp->dm_buf; - size_t len = dmp->dm_len; + char *res = NULL; + size_t reslen = 0; char *prefix = strrchr(name, '`'); - size_t prefixlen; + size_t prefixlen = 0; if (prefix) { prefix++; /* the ` is part of the prefix */ prefixlen = prefix - name; + } - if (prefixlen >= len) - return (DEMANGLE_ESPACE); + res = sysdemangle(name + prefixlen, dmp->dm_lang, &mdb_dem_demops); + if (res == NULL) { + if (errno != EINVAL) + mdb_warn("Error while demangling"); + return (-1); + } - (void) strncpy(buf, name, prefixlen); + reslen = (res != NULL) ? strlen(res) : 0; + reslen += prefixlen; + reslen += 1; - /* - * Fix up the arguments to dmp->dm_convert() - */ - name += prefixlen; - buf += prefixlen; - len -= prefixlen; + if (reslen > dmp->dm_len) { + mdb_free(dmp->dm_buf, dmp->dm_len); + + dmp->dm_buf = mdb_zalloc(reslen, UM_SLEEP); + if (dmp->dm_buf == NULL) { + dmp->dm_len = 0; + mdb_warn("Unable to allocate memory for demangling"); + return (-1); + } + dmp->dm_len = reslen; + } + + if (prefixlen > 0) + (void) strlcpy(dmp->dm_buf, name, prefixlen + 1); + else + *dmp->dm_buf = '\0'; + + if (res != NULL) { + (void) strlcat(dmp->dm_buf, res, dmp->dm_len); + mdb_dem_free(res, strlen(res) + 1); } /* * Save the position of the demangled string for mdb_dem_filter() */ - dmp->dm_dem = buf; + dmp->dm_dem = dmp->dm_buf + prefixlen; - return (dmp->dm_convert(name, buf, len)); + return (0); } +/* used by mdb_io.c:iob_addr2str */ const char * mdb_dem_convert(mdb_demangler_t *dmp, const char *name) { - int err; - - while ((err = mdb_dem_process(dmp, name)) == DEMANGLE_ESPACE) { - size_t len = dmp->dm_len * 2; - char *buf = mdb_alloc(len, UM_NOSLEEP); - - if (buf == NULL) { - mdb_warn("failed to allocate memory for demangling"); - return (name); /* just return original name */ - } - - mdb_free(dmp->dm_buf, dmp->dm_len); - dmp->dm_buf = buf; - dmp->dm_len = len; - } - - if (err != 0 || strcmp(dmp->dm_buf, name) == 0) - return (name); /* return original name if not mangled */ + if (mdb_dem_process(dmp, name) != 0 || + strcmp(dmp->dm_buf, name) == 0) + return (name); return (mdb_dem_filter(dmp, name)); } @@ -263,27 +262,20 @@ int cmd_demangle(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) { mdb_demangler_t *dmp = mdb.m_demangler; - const char *path = LIB_DEMANGLE; - if (argc > 1 || (argc > 0 && argv->a_type != MDB_TYPE_STRING)) + if (argc > 0) return (DCMD_USAGE); - if (argc > 0) { - if (dmp != NULL) - mdb_dem_unload(mdb.m_demangler); - path = argv->a_un.a_str; - } - - if (dmp != NULL && argc == 0 && !(mdb.m_flags & MDB_FL_DEMANGLE)) { + if (dmp != NULL && !(mdb.m_flags & MDB_FL_DEMANGLE)) { mdb_printf("C++ symbol demangling enabled\n"); mdb.m_flags |= MDB_FL_DEMANGLE; - } else if (dmp == NULL || argc > 0) { - if ((mdb.m_demangler = mdb_dem_load(path)) != NULL) { + } else if (dmp == NULL) { + if ((mdb.m_demangler = mdb_dem_load()) != NULL) { mdb_printf("C++ symbol demangling enabled\n"); mdb.m_flags |= MDB_FL_DEMANGLE; } else { - mdb_warn("failed to load C++ demangler %s", path); + mdb_warn("no memory to load C++ demangler"); mdb.m_flags &= ~MDB_FL_DEMANGLE; } @@ -338,8 +330,8 @@ cmd_demstr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) return (DCMD_USAGE); if (mdb.m_demangler == NULL && (mdb.m_demangler = - mdb_dem_load(LIB_DEMANGLE)) == NULL) { - mdb_warn("failed to load C++ demangler %s", LIB_DEMANGLE); + mdb_dem_load()) == NULL) { + mdb_warn("failed to load demangler"); return (DCMD_ERR); } diff --git a/usr/src/cmd/mdb/common/mdb/mdb_demangle.h b/usr/src/cmd/mdb/common/mdb/mdb_demangle.h index 7c9e99fd22..a92d64a349 100644 --- a/usr/src/cmd/mdb/common/mdb/mdb_demangle.h +++ b/usr/src/cmd/mdb/common/mdb/mdb_demangle.h @@ -22,13 +22,13 @@ /* * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Copyright 2018 Jason King. */ #ifndef _MDB_DEMANGLE_H #define _MDB_DEMANGLE_H -#pragma ident "%Z%%M% %I% %E% SMI" - #ifdef __cplusplus extern "C" { #endif @@ -38,11 +38,10 @@ extern "C" { #include #include #include +#include typedef struct mdb_demangler { - char dm_pathname[MAXPATHLEN]; /* pathname of demangling library */ - void *dm_handle; /* rtld handle to demangling library */ - int (*dm_convert)(const char *, char *, size_t); /* demangler */ + sysdem_lang_t dm_lang; /* language to demangle */ char *dm_buf; /* demangling buffer */ size_t dm_len; /* size of dm_buf in bytes */ char *dm_dem; /* start of demangled string (in buf) */ @@ -55,7 +54,7 @@ typedef struct mdb_demangler { #define MDB_DM_MANGLED 0x8 /* show mangled name */ #define MDB_DM_ALL 0xf /* mask of all valid flags */ -extern mdb_demangler_t *mdb_dem_load(const char *); +extern mdb_demangler_t *mdb_dem_load(void); extern void mdb_dem_unload(mdb_demangler_t *); extern const char *mdb_dem_convert(mdb_demangler_t *, const char *); diff --git a/usr/src/cmd/sgs/dump/common/dump.c b/usr/src/cmd/sgs/dump/common/dump.c index 016f045dc1..10c10c5b19 100644 --- a/usr/src/cmd/sgs/dump/common/dump.c +++ b/usr/src/cmd/sgs/dump/common/dump.c @@ -24,6 +24,7 @@ * All Rights Reserved * * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2018, Joyent, Inc. */ /* Get definitions for the relocation types supported. */ @@ -477,28 +478,32 @@ static char * demangled_name(char *s) { static char *buf = NULL; - const char *dn; + size_t buflen = 0; + char *dn; size_t len; - dn = conv_demangle_name(s); + dn = (char *)conv_demangle_name(s); /* * If not demangled, just return the symbol name */ - if (strcmp(s, dn) == 0) + if (dn == s) return (s); + len = strlen(dn) + strlen(s) + 4; + + if (buflen < len) { + free(buf); + if ((buf = malloc(len)) == NULL) + return (s); + buflen = len; + } + /* * Demangled. Format it */ - if (buf != NULL) - free(buf); - - len = strlen(dn) + strlen(s) + 4; - if ((buf = malloc(len)) == NULL) - return (s); - - (void) snprintf(buf, len, "%s\t[%s]", dn, s); + (void) snprintf(buf, buflen, "%s\t[%s]", dn, s); + free(dn); return (buf); } @@ -526,7 +531,7 @@ print_symtab(Elf *elf_file, SCNTAB *p_symtab, Elf_Data *sym_data, adj = 8; while (range > 0) { - char *sym_name = (char *)0; + char *sym_name = NULL; int type, bind; int specsec; unsigned int shndx; diff --git a/usr/src/cmd/sgs/gprof/common/printgprof.c b/usr/src/cmd/sgs/gprof/common/printgprof.c index d02e9a3d9a..acabccaedd 100644 --- a/usr/src/cmd/sgs/gprof/common/printgprof.c +++ b/usr/src/cmd/sgs/gprof/common/printgprof.c @@ -22,10 +22,11 @@ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Copyright 2018 Jason King + * Copyright 2018, Joyent, Inc. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include #include #include @@ -34,7 +35,7 @@ #include "gprof.h" void print_demangled_name(int, nltype *); -void striped_name(char *, nltype **); +static void stripped_name(char **, size_t *, nltype **); extern long hz; @@ -65,7 +66,7 @@ printprof(void) nltype *np; nltype **sortednlp; int i, index; - int print_count = number_funcs_toprint; + int print_count = number_funcs_toprint; bool print_flag = TRUE; mod_info_t *mi; @@ -293,7 +294,7 @@ printgprof(nltype **timesortnlp) { int index; nltype *parentp; - int print_count = number_funcs_toprint; + int print_count = number_funcs_toprint; bool count_flag = TRUE; /* @@ -500,10 +501,7 @@ printname(nltype *selfp) c = demangled_name(selfp); if (selfp->name != 0) { - if (!Cflag) - (void) printf("%s", selfp->name); - else - (void) printf("%s", c); + (void) printf("%s", c); #ifdef DEBUG if (debug & DFNDEBUG) @@ -523,24 +521,26 @@ printname(nltype *selfp) else (void) printf(" (%d)", selfp->index); } + + if (c != selfp->name) + free((void *)c); } void print_demangled_name(int n, nltype *selfp) { - char *c; + char *c = (char *)demangled_name(selfp); int i; - c = selfp->name; - - if (strcmp(c, demangled_name(selfp)) == 0) + if (c == selfp->name) return; - else { - (void) printf("\n"); - for (i = 1; i < n; i++) - (void) printf(" "); - (void) printf("[%s]", selfp->name); - } + + (void) printf("\n"); + for (i = 1; i < n; i++) + (void) printf(" "); + (void) printf("[%s]", selfp->name); + + free(c); } void @@ -862,8 +862,6 @@ printblurb(char *blurbname) (void) fclose(blurbfile); } -char *s1, *s2; - static int namecmp(const void *arg1, const void *arg2) { @@ -873,20 +871,50 @@ namecmp(const void *arg1, const void *arg2) if (!Cflag) return (strcmp((*npp1)->name, (*npp2)->name)); else { - striped_name(s1, npp1); - striped_name(s2, npp2); + static char *s1 = NULL, *s2 = NULL; + static size_t s1len = 0, s2len = 0; + + stripped_name(&s1, &s1len, npp1); + stripped_name(&s2, &s2len, npp2); return (strcmp(s1, s2)); } } -void -striped_name(char *s, nltype **npp) +#define NAME_CHUNK 512 +#define ROUNDLEN(x) (((x) + NAME_CHUNK - 1) / NAME_CHUNK * NAME_CHUNK) +static void +adjust_size(char **pp, size_t *lenp, const char *name) { - const char *d; + void *newp; + size_t nlen = strlen(name); + size_t buflen; + + if (*lenp > nlen) { + (void) memset(*pp, '\0', *lenp); + return; + } + + buflen = ROUNDLEN(nlen + 1); + if ((newp = realloc(*pp, buflen)) == NULL) { + (void) fprintf(stderr, + "gprof: out of memory comparing names\n"); + exit(EXIT_FAILURE); + } + (void) memset(newp, '\0', buflen); + + *lenp = buflen; + *pp = newp; +} + +static void +stripped_name(char **sp, size_t *slenp, nltype **npp) +{ + const char *name, *d; char *c; - c = (char *)s; - d = demangled_name(*npp); + name = d = demangled_name(*npp); + adjust_size(sp, slenp, name); + c = *sp; while ((*d != '(') && (*d != '\0')) { if (*d != ':') @@ -895,6 +923,9 @@ striped_name(char *s, nltype **npp) d++; } *c = '\0'; + + if ((*npp)->name != name) + free((void *)name); } /* @@ -972,11 +1003,6 @@ printindex() } } - if (Cflag) { - s1 = malloc(500 * sizeof (char)); - s2 = malloc(500 * sizeof (char)); - } - qsort(namesortnlp, nnames, sizeof (nltype *), namecmp); for (index = 1, todo = nnames; index <= ncycle; index++) @@ -1038,13 +1064,16 @@ printindex() if (does_clash(namesortnlp, i, nnames)) { (void) printf("%6.6s %d:%s\n", peterbuffer, nlp->module->id, d); - } else + } else { (void) printf("%6.6s %s\n", peterbuffer, d); + } - if (d != nlp->name) + if (d != nlp->name) { (void) printf("%6.6s [%s]", "", nlp->name); + free((void *)d); + } } else { (void) printf("%6.6s ", peterbuffer); (void) sprintf(peterbuffer, "", diff --git a/usr/src/cmd/sgs/libconv/Makefile.com b/usr/src/cmd/sgs/libconv/Makefile.com index d95213e586..c6287c433c 100644 --- a/usr/src/cmd/sgs/libconv/Makefile.com +++ b/usr/src/cmd/sgs/libconv/Makefile.com @@ -21,12 +21,13 @@ # # Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright 2018, Joyent, Inc. # LIBRARY = libconv.a COMOBJS32 = cap_machelf32.o dynamic_machelf32.o \ - globals_machelf32.o sections_machelf32.o \ + globals_machelf32.o sections_machelf32.o \ symbols_machelf32.o symbols_sparc_machelf32.o COMOBJS64 = cap_machelf64.o dynamic_machelf64.o \ @@ -36,19 +37,19 @@ COMOBJS64 = cap_machelf64.o dynamic_machelf64.o \ COMOBJS= arch.o audit.o \ c_literal.o \ cap.o config.o \ - corenote.o data.o \ - deftag.o demangle.o \ + corenote.o data.o \ + deftag.o demangle.o \ dl.o dwarf.o \ - dwarf_ehe.o dynamic.o \ + dwarf_ehe.o dynamic.o \ elf.o entry.o \ globals.o group.o \ - lddstub.o map.o \ + lddstub.o map.o \ phdr.o relocate.o \ - relocate_i386.o relocate_amd64.o \ + relocate_i386.o relocate_amd64.o \ relocate_sparc.o sections.o \ - segments.o strproc.o \ - symbols.o syminfo.o \ - tokens.o time.o \ + segments.o strproc.o \ + symbols.o syminfo.o \ + tokens.o time.o \ version.o ELFCAP_OBJS= elfcap.o @@ -61,15 +62,15 @@ BLTOBJS= arch_msg.o audit_msg.o \ corenote_msg.o data_msg.o \ deftag_msg.o demangle_msg.o \ dl_msg.o dwarf_msg.o \ - dwarf_ehe_msg.o dynamic_msg.o \ - elf_msg.o entry_msg.o \ + dwarf_ehe_msg.o dynamic_msg.o \ + elf_msg.o entry_msg.o \ globals_msg.o group_msg.o \ - map_msg.o lddstub_msg.o \ - phdr_msg.o relocate_amd64_msg.o \ + map_msg.o lddstub_msg.o \ + phdr_msg.o relocate_amd64_msg.o \ relocate_i386_msg.o relocate_sparc_msg.o \ - sections_msg.o segments_msg.o \ - symbols_msg.o symbols_sparc_msg.o \ - syminfo_msg.o time_msg.o \ + sections_msg.o segments_msg.o \ + symbols_msg.o symbols_sparc_msg.o \ + syminfo_msg.o time_msg.o \ version_msg.o @@ -84,8 +85,8 @@ OBJECTS = $(COMOBJS) $(COMOBJS32) $(COMOBJS64) $(ELFCAP_OBJS) \ NOCTFOBJS = $(OBJECTS) CTFMERGE_LIB = : -include $(SRC)/lib/Makefile.lib -include $(SRC)/cmd/sgs/Makefile.com +include $(SRC)/lib/Makefile.lib +include $(SRC)/cmd/sgs/Makefile.com CERRWARN += -_gcc=-Wno-type-limits CERRWARN += -_gcc=-Wno-switch @@ -113,6 +114,14 @@ LINTSRCS= $(COMOBJS:%.o=../common/%.c) \ LINTSRCS32 = $(COMOBJS32:%32.o=../common/%.c) LINTSRCS64 = $(COMOBJS64:%64.o=../common/%.c) +# Since libconv uses dlopen(3C) to load libdemangle-sys.so (much like it did +# for the old Sun Studio libdemangle.so) in order to avoid messy bootstrapping +# problems, but it also needs the definitions from demangle-sys.h for +# SYSDEM_LANG_AUTO, lint will complain about sysdemangle() being defined but not +# used unless it is explicitly included during the lint pass +$(LINTOUT32) := LDLIBS += -ldemangle-sys +$(LINTOUT64) := LDLIBS += -ldemangle-sys + SGSMSGTARG= $(BLTOBJS:%_msg.o=../common/%.msg) LINTFLAGS += -u diff --git a/usr/src/cmd/sgs/libconv/common/demangle.c b/usr/src/cmd/sgs/libconv/common/demangle.c index 8b590d87e0..eb2961ea3a 100644 --- a/usr/src/cmd/sgs/libconv/common/demangle.c +++ b/usr/src/cmd/sgs/libconv/common/demangle.c @@ -21,10 +21,11 @@ /* * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2018, Joyent, Inc. */ #include -#include +#include #include "_conv.h" #include "demangle_msg.h" @@ -59,13 +60,11 @@ const char * conv_demangle_name(const char *name) { - static char _str[SYM_MAX], *str = _str; - static size_t size = SYM_MAX; - static int again = 1; - static int (*fptr)() = 0; - int error; + static char *(*fptr)() = 0; + static volatile int loading = 0; + char *d; - if (str == 0) + if (loading) return (name); /* @@ -78,38 +77,15 @@ conv_demangle_name(const char *name) if (fptr == 0) { void *hdl; - str = 0; + loading = 1; if (!(hdl = dlopen(MSG_ORIG(MSG_DEM_LIB), RTLD_LAZY)) || - !(fptr = (int (*)())dlsym(hdl, MSG_ORIG(MSG_DEM_SYM)))) + !(fptr = (char *(*)())dlsym(hdl, MSG_ORIG(MSG_DEM_SYM)))) return (name); - str = _str; + loading = 0; } - if ((error = (*fptr)(name, str, size)) == 0) - return ((const char *)str); - - while ((error == DEMANGLE_ESPACE) && again) { - char *_str; - size_t _size = size; - - /* - * If we haven't allocated our maximum try incrementing the - * present buffer size. Use malloc() rather than realloc() so - * that we at least have the old buffer on failure. - */ - if (((_size += SYM_MAX) > (SYM_MAX * 4)) || - ((_str = malloc(_size)) == 0)) { - again = 0; - break; - } - if (size != SYM_MAX) { - free(str); - } - str = _str; - size = _size; + if ((d = fptr(name, SYSDEM_LANG_AUTO, NULL)) == NULL) + return (name); - if ((error = (*fptr)(name, str, size)) == 0) - return ((const char *)str); - } - return (name); + return (d); } diff --git a/usr/src/cmd/sgs/libconv/common/demangle.msg b/usr/src/cmd/sgs/libconv/common/demangle.msg index c7cbeaf921..4a69427057 100644 --- a/usr/src/cmd/sgs/libconv/common/demangle.msg +++ b/usr/src/cmd/sgs/libconv/common/demangle.msg @@ -23,8 +23,8 @@ # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# ident "%Z%%M% %I% %E% SMI" +# Copyright 2018 Jason King # -@ MSG_DEM_SYM "cplus_demangle" -@ MSG_DEM_LIB "libdemangle.so.1" +@ MSG_DEM_SYM "sysdemangle" +@ MSG_DEM_LIB "libdemangle-sys.so.1" diff --git a/usr/src/cmd/sgs/libconv/common/lintsup.c b/usr/src/cmd/sgs/libconv/common/lintsup.c index 4c0d6e4fdd..6f1dfc4125 100644 --- a/usr/src/cmd/sgs/libconv/common/lintsup.c +++ b/usr/src/cmd/sgs/libconv/common/lintsup.c @@ -21,6 +21,7 @@ /* * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2018, Joyent, Inc. */ /* LINTLIBRARY */ /* PROTOLIB1 */ @@ -39,7 +40,6 @@ #include #include #include -#include #include #include #include "sgs.h" diff --git a/usr/src/cmd/sgs/liblddbg/common/util.c b/usr/src/cmd/sgs/liblddbg/common/util.c index 575a9bd15f..09bcd437e9 100644 --- a/usr/src/cmd/sgs/liblddbg/common/util.c +++ b/usr/src/cmd/sgs/liblddbg/common/util.c @@ -22,6 +22,8 @@ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Copyright 2018 Jason King */ #include "msg.h" @@ -342,16 +344,35 @@ Dbg_util_nl(Lm_list *lml, int flag) const char * Dbg_demangle_name(const char *name) { + static char *buf = NULL; + if (DBG_NOTCLASS(DBG_C_DEMANGLE)) return (name); - return (conv_demangle_name(name)); + free(buf); + buf = (char *)conv_demangle_name(name); + if (buf == name) { + buf = NULL; + return (name); + } + + return (buf); } const char * Elf_demangle_name(const char *name) { - if (DBG_ISDEMANGLE()) - return (conv_demangle_name(name)); - return (name); + static char *buf = NULL; + + if (!DBG_ISDEMANGLE()) + return (name); + + free(buf); + buf = (char *)conv_demangle_name(name); + if (buf == name) { + buf = NULL; + return (name); + } + + return (buf); } diff --git a/usr/src/cmd/sgs/nm/common/nm.c b/usr/src/cmd/sgs/nm/common/nm.c index 258bd9fd67..fc3ded721e 100644 --- a/usr/src/cmd/sgs/nm/common/nm.c +++ b/usr/src/cmd/sgs/nm/common/nm.c @@ -25,6 +25,7 @@ * All Rights Reserved * * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2018 Jason King */ #include @@ -260,7 +261,7 @@ main(int argc, char *argv[], char *envp[]) "%s: -u or -e set, -g ignored\n"), prog_name); break; - case 'r': if (R_flag) { + case 'r': if (R_flag) { R_flag = 0; (void) fprintf(stderr, gettext( "%s: -r set, -R ignored\n"), @@ -666,7 +667,7 @@ static void print_with_otherflags(int, Elf *, unsigned int, */ static void print_symtab(Elf *elf_file, unsigned int shstrndx, - Elf_Scn *p_sd, GElf_Shdr *shdr, char *filename) + Elf_Scn *p_sd, GElf_Shdr *shdr, char *filename) { Elf_Data * sd; @@ -781,7 +782,7 @@ is_bss_section(unsigned int shndx, Elf * elf_file, unsigned int shstrndx) */ static SYM * readsyms(Elf_Data * data, GElf_Sxword num, Elf *elf, - unsigned int link, unsigned int symscnndx) + unsigned int link, unsigned int symscnndx) { SYM *s, *buf; GElf_Sym sym; @@ -805,15 +806,15 @@ readsyms(Elf_Data * data, GElf_Sxword num, Elf *elf, if (sym.st_name == 0) buf->name = ""; else if (C_flag) { - const char *dn; + const char *dn = NULL; char *name = (char *)elf_strptr(elf, link, sym.st_name); + dn = conv_demangle_name(name); - if (strcmp(dn, name) == 0) { /* Not demangled */ - if (exotic(name)) { - name = FormatName(name, d_buf); - } - } else { /* name demangled */ + if (dn != name) { name = FormatName(name, dn); + free((void *)dn); + } else if (exotic(name)) { + name = FormatName(name, d_buf); } buf->name = name; } @@ -1014,10 +1015,7 @@ is_sym_print(SYM *sym_data) * -u flag specified */ static void -print_with_uflag( - SYM *sym_data, - char *filename -) +print_with_uflag(SYM *sym_data, char *filename) { if ((sym_data->shndx == SHN_UNDEF) && (strlen(sym_data->name))) { if (!r_flag) { @@ -1094,18 +1092,13 @@ print_brief_sym_type(Elf *elf_file, unsigned int shstrndx, SYM *sym_data) * -p flag specified */ static void -print_with_pflag( - int ndigits, - Elf *elf_file, - unsigned int shstrndx, - SYM *sym_data, - char *filename -) +print_with_pflag(int ndigits, Elf *elf_file, unsigned int shstrndx, + SYM *sym_data, char *filename) { const char * const fmt[] = { - "%.*llu ", /* FMT_T_DEC */ - "0x%.*llx ", /* FMT_T_HEX */ - "0%.*llo " /* FMT_T_OCT */ + "%.*llu ", /* FMT_T_DEC */ + "0x%.*llx ", /* FMT_T_HEX */ + "0%.*llo " /* FMT_T_OCT */ }; if (is_sym_print(sym_data) != 1) @@ -1148,12 +1141,8 @@ print_with_pflag( * -P flag specified */ static void -print_with_Pflag( - int ndigits, - Elf *elf_file, - unsigned int shstrndx, - SYM *sym_data -) +print_with_Pflag(int ndigits, Elf *elf_file, unsigned int shstrndx, + SYM *sym_data) { #define SYM_LEN 10 char sym_name[SYM_LEN+1]; @@ -1200,13 +1189,8 @@ print_with_Pflag( * other flags specified */ static void -print_with_otherflags( - int ndigits, - Elf *elf_file, - unsigned int shstrndx, - SYM *sym_data, - char *filename -) +print_with_otherflags(int ndigits, Elf *elf_file, unsigned int shstrndx, + SYM *sym_data, char *filename) { const char * const fmt_value_size[] = { "%*llu|%*lld|", /* FMT_T_DEC */ diff --git a/usr/src/cmd/sgs/prof/common/prof.c b/usr/src/cmd/sgs/prof/common/prof.c index 38a0aa0a9f..4b6086040c 100644 --- a/usr/src/cmd/sgs/prof/common/prof.c +++ b/usr/src/cmd/sgs/prof/common/prof.c @@ -22,6 +22,7 @@ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright 2018 Jason King */ /* Copyright (c) 1988 AT&T */ @@ -32,7 +33,7 @@ * * Usage: * - * prof [-ChsVz] [-a | c | n | t] [-o | x] [-g | l] + * prof [-ChsVz] [-a | c | n | t] [-o | x] [-g | l] * [-m mdata] [prog] * * Where "prog" is the program that was profiled; "a.out" by default. @@ -136,7 +137,7 @@ char *aformat = "%8o "; int gflag = 0; /* replaces gmatch and gmask */ int Cflag = 0; -PROF_FILE *ldptr; /* For program ("a.out") file. */ +PROF_FILE *ldptr; /* For program ("a.out") file. */ FILE *mon_iop; /* For profile (MON_OUT) file. */ char *sym_fn = "a.out"; /* Default program file name. */ @@ -197,7 +198,7 @@ struct snymEntry { char *sym_addr; /* address which has a synonym */ int howMany; /* # of synonyms for this symbol */ int snymReported; /* 'was printed in a report line already' */ - /* flag, */ + /* flag, */ /* > 0 report line printed for these syns. */ /* == 0 not printed yet. */ long tot_sl_count; /* total subr calls for these snyms */ @@ -1311,9 +1312,7 @@ demangled_name(char *s) const char *name; size_t len; - name = conv_demangle_name(s); - - if (strcmp(name, s) == 0) + if ((name = conv_demangle_name(s)) == s) return (s); if (format_buf != NULL) @@ -1324,6 +1323,7 @@ demangled_name(char *s) if (format_buf == NULL) return (s); (void) snprintf(format_buf, len, FORMAT_BUF, name, s); + free((void *)name); return (format_buf); } diff --git a/usr/src/cmd/sgs/prof/common/profv.c b/usr/src/cmd/sgs/prof/common/profv.c index 4f9b72596e..887b36bba5 100644 --- a/usr/src/cmd/sgs/prof/common/profv.c +++ b/usr/src/cmd/sgs/prof/common/profv.c @@ -22,10 +22,10 @@ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Copyright 2018, Joyent, Inc. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* * All routines in this file are for processing new-style, *versioned* * mon.out format. Together with rdelf.c, lookup.c and profv.h, these @@ -74,7 +74,8 @@ setup_demangled_names(void) nbe = namebuf + namebuf_sz; for (i = 0; i < total_funcs; i++) { - if ((p = conv_demangle_name(profsym[i].name)) == NULL) + p = conv_demangle_name(profsym[i].name); + if (p == profsym[i].name) continue; namelen = strlen(p); @@ -97,6 +98,7 @@ setup_demangled_names(void) nbp += namelen + 1; cur_len += namelen + 1; + free((void *)p); } } diff --git a/usr/src/lib/Makefile b/usr/src/lib/Makefile index 60b086a16c..07c8f13474 100644 --- a/usr/src/lib/Makefile +++ b/usr/src/lib/Makefile @@ -30,6 +30,7 @@ # Copyright 2018 Nexenta Systems, Inc. # Copyright (c) 2016, Chris Fraire . # Copyright 2017 RackTop Systems. +# Copyirght 2018 Jason King # include ../Makefile.master @@ -106,6 +107,7 @@ SUBDIRS += \ libctf \ libcurses \ libcustr \ + libdemangle \ libdevice \ libdevid \ libdevinfo \ @@ -379,6 +381,7 @@ HDRSUBDIRS= \ libctf \ libcurses \ libcustr \ + libdemangle \ libdevice \ libdevid \ libdevinfo \ diff --git a/usr/src/lib/libdemangle/Makefile b/usr/src/lib/libdemangle/Makefile new file mode 100644 index 0000000000..2d17d76e7f --- /dev/null +++ b/usr/src/lib/libdemangle/Makefile @@ -0,0 +1,41 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# +# Copyright 2018 Jason King. +# Copyright 2017, Joyent. Inc. +# + +include ../Makefile.lib + +HDRS = demangle-sys.h +HDRDIR = common +SUBDIRS = $(MACH) +$(BUILD64)SUBDIRS += $(MACH64) + +all := TARGET= all +clean := TARGET= clean +clobber := TARGET= clobber +install := TARGET= install +lint := TARGET= lint + +.KEEP_STATE: + +all clean clobber install lint: $(SUBDIRS) + +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(TARGET) + +install_h: $(ROOTHDRS) + +check: $(CHECKHDRS) + +FRC: + +include ../Makefile.targ diff --git a/usr/src/lib/libdemangle/Makefile.com b/usr/src/lib/libdemangle/Makefile.com new file mode 100644 index 0000000000..0b0d495df7 --- /dev/null +++ b/usr/src/lib/libdemangle/Makefile.com @@ -0,0 +1,43 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2018 Jason King +# Copyright 2018, Joyent, Inc. +# + +LIBRARY = libdemangle-sys.a +VERS = .1 +OBJECTS = str.o util.o cxx_util.o cxx.o demangle.o + +include ../../Makefile.lib + +LIBS = $(DYNLIB) $(LINTLIB) +LDLIBS += -lc + +SRCDIR = ../common +$(LINTLIB) := SRCS = $(SRCDIR)/$(LINTSRC) + +CSTD = $(CSTD_GNU99) +CFLAGS += $(CCVERBOSE) +CPPFLAGS += -I$(SRCDIR) -D_REENTRANT -D__EXTENSIONS__ + +LINTFLAGS += -erroff=E_BAD_FORMAT_ARG_TYPE2 +LINTFLAGS64 += -erroff=E_BAD_FORMAT_ARG_TYPE2 +C99LMODE = -Xc99=%all + +.KEEP_STATE: + +all: $(LIBS) + +lint: lintcheck + +include $(SRC)/lib/Makefile.targ diff --git a/usr/src/lib/libdemangle/THIRDPARTYLICENSE b/usr/src/lib/libdemangle/THIRDPARTYLICENSE new file mode 100644 index 0000000000..7381b74c4d --- /dev/null +++ b/usr/src/lib/libdemangle/THIRDPARTYLICENSE @@ -0,0 +1,76 @@ +============================================================================== +libc++abi License +============================================================================== + +The libc++abi library is dual licensed under both the University of Illinois +"BSD-Like" license and the MIT license. As a user of this code you may choose +to use it under either license. As a contributor, you agree to allow your code +to be used under both. + +Full text of the relevant licenses is included below. + +============================================================================== + +University of Illinois/NCSA +Open Source License + +Copyright (c) 2009-2015 by the contributors listed in CREDITS.TXT + +All rights reserved. + +Developed by: + + LLVM Team + + University of Illinois at Urbana-Champaign + + http://llvm.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal with +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimers. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimers in the + documentation and/or other materials provided with the distribution. + + * Neither the names of the LLVM Team, University of Illinois at + Urbana-Champaign, nor the names of its contributors may be used to + endorse or promote products derived from this Software without specific + prior written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE +SOFTWARE. + +============================================================================== + +Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/usr/src/lib/libdemangle/THIRDPARTYLICENSE.descrip b/usr/src/lib/libdemangle/THIRDPARTYLICENSE.descrip new file mode 100644 index 0000000000..ee4e5590cf --- /dev/null +++ b/usr/src/lib/libdemangle/THIRDPARTYLICENSE.descrip @@ -0,0 +1 @@ +PORTIONS OF LIBSYSDEMANGLE FUNCTIONALITY diff --git a/usr/src/lib/libdemangle/amd64/Makefile b/usr/src/lib/libdemangle/amd64/Makefile new file mode 100644 index 0000000000..137dd0cf23 --- /dev/null +++ b/usr/src/lib/libdemangle/amd64/Makefile @@ -0,0 +1,30 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# + +include ../Makefile.com +include ../../Makefile.lib.64 + +install: all $(ROOTLIBS64) $(ROOTLINKS64) $(ROOTLINT64) diff --git a/usr/src/lib/libdemangle/common/cxx.c b/usr/src/lib/libdemangle/common/cxx.c new file mode 100644 index 0000000000..66d7170544 --- /dev/null +++ b/usr/src/lib/libdemangle/common/cxx.c @@ -0,0 +1,4217 @@ +/* + * Ported from LLVM's libcxxabi trunk/src/cxa_demangle.cpp + * LICENSE.TXT contents is available as ../THIRDPARTYLICENSE + * + * The LLVM Compiler Infrastructure + * + * This file is dual licensed under the MIT and the University of Illinois Open + * Source Licenses. See LICENSE.TXT for details. + * + */ + +/* + * Copyright 2018 Jason King. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "demangle-sys.h" +#include "demangle_int.h" +#include "cxx.h" + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(x) (sizeof (x) / sizeof (x[0])) +#endif + +#define CPP_QUAL_CONST (1U) +#define CPP_QUAL_VOLATILE (2U) +#define CPP_QUAL_RESTRICT (4U) + +typedef struct cpp_db_s { + sysdem_ops_t *cpp_ops; + jmp_buf cpp_jmp; + name_t cpp_name; + sub_t cpp_subs; + templ_t cpp_templ; + unsigned cpp_cv; + unsigned cpp_ref; + unsigned cpp_depth; + boolean_t cpp_parsed_ctor_dtor_cv; + boolean_t cpp_tag_templates; + boolean_t cpp_fix_forward_references; + boolean_t cpp_try_to_parse_template_args; + locale_t cpp_loc; +} cpp_db_t; + +#define CK(x) \ + do { \ + if (!(x)) { \ + longjmp(db->cpp_jmp, 1); \ + } \ + NOTE(CONSTCOND) \ + } while (0) + +#define TOP_L(db) (&(name_top(&(db)->cpp_name)->strp_l)) +#define RLEN(f, l) ((size_t)((l) - (f))) +#define NAMT(db, n) (nlen(db) - n) + +static inline boolean_t is_xdigit(int); + +static boolean_t nempty(cpp_db_t *); +static size_t nlen(cpp_db_t *); +static void nadd_l(cpp_db_t *, const char *, size_t); +static void njoin(cpp_db_t *, size_t, const char *); +static void nfmt(cpp_db_t *, const char *, const char *); + +static void save_top(cpp_db_t *, size_t); +static void sub(cpp_db_t *, size_t); + +static boolean_t tempty(const cpp_db_t *); +static size_t ttlen(const cpp_db_t *); + +static void tsub(cpp_db_t *, size_t); +static void tpush(cpp_db_t *); +static void tpop(cpp_db_t *); +static void tsave(cpp_db_t *, size_t); + +static boolean_t db_init(cpp_db_t *, sysdem_ops_t *); +static void db_fini(cpp_db_t *); +static void dump(cpp_db_t *, FILE *); + +static void demangle(const char *, const char *, cpp_db_t *); + +static const char *parse_type(const char *, const char *, cpp_db_t *); +static const char *parse_builtin_type(const char *, const char *, cpp_db_t *); +static const char *parse_qual_type(const char *, const char *, cpp_db_t *); +static const char *parse_encoding(const char *, const char *, cpp_db_t *); +static const char *parse_dot_suffix(const char *, const char *, cpp_db_t *); +static const char *parse_block_invoke(const char *, const char *, cpp_db_t *); +static const char *parse_special_name(const char *, const char *, cpp_db_t *); +static const char *parse_name(const char *, const char *, boolean_t *, + cpp_db_t *); +static const char *parse_call_offset(const char *, const char *, locale_t); +static const char *parse_number(const char *, const char *, locale_t); +static const char *parse_nested_name(const char *, const char *, boolean_t *, + cpp_db_t *); +static const char *parse_local_name(const char *, const char *, boolean_t *, + cpp_db_t *); +static const char *parse_unscoped_name(const char *, const char *, cpp_db_t *); +static const char *parse_template_args(const char *, const char *, cpp_db_t *); +static const char *parse_substitution(const char *, const char *, cpp_db_t *); +static const char *parse_discriminator(const char *, const char *, locale_t); +static const char *parse_cv_qualifiers(const char *, const char *, unsigned *); +static const char *parse_template_param(const char *, const char *, cpp_db_t *); +static const char *parse_decltype(const char *, const char *, cpp_db_t *); +static const char *parse_template_args(const char *, const char *, cpp_db_t *); +static const char *parse_unqualified_name(const char *, const char *, + cpp_db_t *); +static const char *parse_template_arg(const char *, const char *, cpp_db_t *); +static const char *parse_expression(const char *, const char *, cpp_db_t *); +static const char *parse_expr_primary(const char *, const char *, cpp_db_t *); +static const char *parse_binary_expr(const char *, const char *, + const char *, cpp_db_t *); +static const char *parse_prefix_expr(const char *, const char *, + const char *, cpp_db_t *); +static const char *parse_gs(const char *, const char *, cpp_db_t *); +static const char *parse_idx_expr(const char *, const char *, cpp_db_t *); +static const char *parse_mm_expr(const char *, const char *, cpp_db_t *); +static const char *parse_pp_expr(const char *, const char *, cpp_db_t *); +static const char *parse_trinary_expr(const char *, const char *, cpp_db_t *); +static const char *parse_new_expr(const char *, const char *, cpp_db_t *); +static const char *parse_del_expr(const char *, const char *, cpp_db_t *); +static const char *parse_cast_expr(const char *, const char *, cpp_db_t *); +static const char *parse_sizeof_param_pack_expr(const char *, const char *, + cpp_db_t *); +static const char *parse_typeid_expr(const char *, const char *, cpp_db_t *); +static const char *parse_throw_expr(const char *, const char *, cpp_db_t *); +static const char *parse_dot_star_expr(const char *, const char *, cpp_db_t *); +static const char *parse_dot_expr(const char *, const char *, cpp_db_t *); +static const char *parse_call_expr(const char *, const char *, cpp_db_t *); +static const char *parse_arrow_expr(const char *, const char *, cpp_db_t *); +static const char *parse_conv_expr(const char *, const char *, cpp_db_t *); +static const char *parse_function_param(const char *, const char *, cpp_db_t *); +static const char *parse_base_unresolved_name(const char *, const char *, + cpp_db_t *); +static const char *parse_unresolved_name(const char *, const char *, + cpp_db_t *); +static const char *parse_noexcept_expr(const char *, const char *, cpp_db_t *); +static const char *parse_alignof(const char *, const char *, cpp_db_t *); +static const char *parse_sizeof(const char *, const char *, cpp_db_t *); +static const char *parse_unnamed_type_name(const char *, const char *, + cpp_db_t *); +static const char *parse_ctor_dtor_name(const char *, const char *, cpp_db_t *); +static const char *parse_source_name(const char *, const char *, cpp_db_t *); +static const char *parse_operator_name(const char *, const char *, cpp_db_t *); +static const char *parse_pack_expansion(const char *, const char *, cpp_db_t *); +static const char *parse_unresolved_type(const char *, const char *, + cpp_db_t *); +static const char *parse_unresolved_qualifier_level(const char *, const char *, + cpp_db_t *); +static const char *parse_destructor_name(const char *, const char *, + cpp_db_t *); +static const char *parse_function_type(const char *, const char *, cpp_db_t *); +static const char *parse_array_type(const char *, const char *, cpp_db_t *); +static const char *parse_pointer_to_member_type(const char *, const char *, + cpp_db_t *); +static const char *parse_vector_type(const char *, const char *, cpp_db_t *); + +size_t cpp_name_max_depth = 1024; /* max depth of name stack */ + +char * +cpp_demangle(const char *src, sysdem_ops_t *ops) +{ + char *result = NULL; + cpp_db_t db; + size_t srclen = strlen(src); + + if (!db_init(&db, ops)) + goto done; + if (setjmp(db.cpp_jmp) != 0) + goto done; + + errno = 0; + demangle(src, src + srclen, &db); + + if (errno == 0 && db.cpp_fix_forward_references && + !templ_empty(&db.cpp_templ) && + !sub_empty(&db.cpp_templ.tpl_items[0])) { + db.cpp_fix_forward_references = B_FALSE; + db.cpp_tag_templates = B_FALSE; + name_clear(&db.cpp_name); + sub_clear(&db.cpp_subs); + + if (setjmp(db.cpp_jmp) != 0) + goto done; + + demangle(src, src + srclen, &db); + + if (db.cpp_fix_forward_references) { + errno = EINVAL; + goto done; + } + } + + if (errno != 0) + goto done; + + if (nempty(&db)) { + errno = EINVAL; + goto done; + } + + njoin(&db, 1, ""); + + if (nlen(&db) > 0) { + str_t *s = TOP_L(&db); + result = zalloc(ops, s->str_len + 1); + if (result == NULL) + goto done; + + (void) memcpy(result, s->str_s, s->str_len); + } + +done: + if (demangle_debug) + dump(&db, stdout); + + db_fini(&db); + return (result); +} + +static void +demangle(const char *first, const char *last, cpp_db_t *db) +{ + const char *t = NULL; + + if (first >= last) { + errno = EINVAL; + return; + } + + if (first[0] != '_') { + t = parse_type(first, last, db); + if (t == first) { + errno = EINVAL; + return; + } + goto done; + } + + if (last - first < 4) { + errno = EINVAL; + return; + } + + if (first[1] == 'Z') { + t = parse_encoding(first + 2, last, db); + + if (t != first + 2 && t != last && t[0] == '.') { + t = parse_dot_suffix(t, last, db); + if (nlen(db) > 1) + njoin(db, 2, ""); + } + + goto done; + } + + if (first[1] != '_' || first[2] != '_' || first[3] != 'Z') + goto done; + + t = parse_encoding(first + 4, last, db); + if (t != first + 4 && t != last) + t = parse_block_invoke(t, last, db); + +done: + if (t != last) + errno = EINVAL; +} + +static const char * +parse_dot_suffix(const char *first, const char *last, cpp_db_t *db) +{ + VERIFY3P(first, <=, last); + + if (first == last || first[0] != '.') + return (first); + + if (nempty(db)) + return (first); + + nadd_l(db, first, RLEN(first, last)); + nfmt(db, " ({0})", NULL); + + return (last); +} + +/* + * _block_invoke + * _block_invoke* + * _block_invoke_+ + */ +static const char * +parse_block_invoke(const char *first, const char *last, cpp_db_t *db) +{ + VERIFY3P(first, <=, last); + + if (last - first < 13) + return (first); + + const char test[] = "_block_invoke"; + const char *t = first; + + if (strncmp(first, test, sizeof (test) - 1) != 0) + return (first); + + t += sizeof (test); + if (t == last) + goto done; + + if (t[0] == '_') { + /* need at least one digit */ + if (t + 1 == last || !isdigit_l(t[1], db->cpp_loc)) + return (first); + t += 2; + } + + while (t < last && isdigit_l(t[0], db->cpp_loc)) + t++; + +done: + if (nempty(db)) + return (first); + + nfmt(db, "invocation function for block in {0}", NULL); + return (t); +} + +/* + * ::= + * ::= + * ::= + */ +static const char * +parse_encoding(const char *first, const char *last, cpp_db_t *db) +{ + VERIFY3P(first, <=, last); + + if (first == last) + return (first); + + const char *t = NULL; + const char *t2 = NULL; + unsigned cv = 0; + unsigned ref = 0; + boolean_t tag_templ_save = db->cpp_tag_templates; + + if (++db->cpp_depth > 1) + db->cpp_tag_templates = B_TRUE; + + if (first[0] == 'G' || first[0] == 'T') { + t = parse_special_name(first, last, db); + goto done; + } + + boolean_t ends_with_template_args = B_FALSE; + t = parse_name(first, last, &ends_with_template_args, db); + if (t == first) + goto fail; + + cv = db->cpp_cv; + ref = db->cpp_ref; + + if (t == last || t[0] == 'E' || t[0] == '.') + goto done; + + db->cpp_tag_templates = B_FALSE; + if (nempty(db) || str_length(TOP_L(db)) == 0) + goto fail; + + if (!db->cpp_parsed_ctor_dtor_cv && ends_with_template_args) { + t2 = parse_type(t, last, db); + if (t2 == t || nlen(db) < 2) + goto fail; + + str_pair_t *sp = name_top(&db->cpp_name); + + if (str_length(&sp->strp_r) == 0) + (void) str_append(&sp->strp_l, " ", 1); + + nfmt(db, "{0:L}{1:L}", "{1:R}{0:R}"); + t = t2; + } + + if (t == last || nempty(db)) + goto fail; + + size_t n = nlen(db); + + if (t[0] == 'v') { + t++; + } else { + for (;;) { + t2 = parse_type(t, last, db); + if (t2 == t || t == last) + break; + + t = t2; + } + } + + /* + * a bit of a hack, but a template substitution can apparently be + * an empty string at the end of an argument list, so avoid + * <...., > + */ + if (NAMT(db, n) > 1 && str_pair_len(name_top(&db->cpp_name)) == 0) + name_pop(&db->cpp_name, NULL); + + njoin(db, NAMT(db, n), ", "); + nfmt(db, "({0})", NULL); + + str_t *s = TOP_L(db); + + if (cv & CPP_QUAL_CONST) { + CK(str_append(s, " const", 0)); + } + if (cv & CPP_QUAL_VOLATILE) { + CK(str_append(s, " volatile", 0)); + } + if (cv & CPP_QUAL_RESTRICT) { + CK(str_append(s, " restrict", 0)); + } + if (ref == 1) { + CK(str_append(s, " &", 0)); + } + if (ref == 2) { + CK(str_append(s, " &&", 0)); + } + + nfmt(db, "{1:L}{0}{1:R}", NULL); + +done: + db->cpp_tag_templates = tag_templ_save; + db->cpp_depth--; + return (t); + +fail: + db->cpp_tag_templates = tag_templ_save; + db->cpp_depth--; + return (first); +} + +/* + * ::= TV # virtual table + * ::= TT # VTT structure (construction vtable index) + * ::= TI # typeinfo structure + * ::= TS # typeinfo name (null-terminated byte string) + * ::= Tc + * # base is the nominal target function of thunk + * # first call-offset is 'this' adjustment + * # second call-offset is result adjustment + * ::= T + * # base is the nominal target function of thunk + * ::= GV # Guard variable for one-time init + * # No + * ::= TW # Thread-local wrapper + * ::= TH # Thread-local initialization + * extension ::= TC _ + * # construction vtable for second-in-first + * extension ::= GR # reference temporary for object + */ +static const char * +parse_special_name(const char *first, const char *last, cpp_db_t *db) +{ + VERIFY3P(first, <=, last); + + const char *t = first; + const char *t1 = NULL; + size_t n = nlen(db); + + if (last - first < 2) + return (first); + + switch (t[0]) { + case 'T': + switch (t[1]) { + case 'V': + nadd_l(db, "vtable for", 0); + t = parse_type(first + 2, last, db); + break; + case 'T': + nadd_l(db, "VTT for", 0); + t = parse_type(first + 2, last, db); + break; + case 'I': + nadd_l(db, "typeinfo for", 0); + t = parse_type(first + 2, last, db); + break; + case 'S': + nadd_l(db, "typeinfo name for", 0); + t = parse_type(first + 2, last, db); + break; + case 'c': + nadd_l(db, "covariant return thunk to", 0); + t1 = parse_call_offset(first + 2, last, db->cpp_loc); + if (t1 == t) + return (first); + t = parse_call_offset(t1, last, db->cpp_loc); + if (t == t1) + return (first); + t1 = parse_encoding(t, last, db); + if (t1 == t) + return (first); + break; + case 'C': + t = parse_type(first + 2, last, db); + if (t == first + 2) + return (first); + t1 = parse_number(t, last, db->cpp_loc); + if (*t1 != '_') + return (first); + t = parse_type(t1 + 1, last, db); + if (t == t1 + 1 || nlen(db) < 2) + return (first); + nfmt(db, "construction vtable for {0}-in-{1}", NULL); + return (t); + case 'W': + nadd_l(db, "thread-local wrapper routine for", 0); + t = parse_name(first + 2, last, NULL, db); + break; + case 'H': + nadd_l(db, "thread-local initialization routine for", + 0); + t = parse_name(first + 2, last, NULL, db); + break; + default: + if (first[1] == 'v') { + nadd_l(db, "virtual thunk to", 0); + } else { + nadd_l(db, "non-virtual thunk to", 0); + } + + t = parse_call_offset(first + 1, last, db->cpp_loc); + if (t == first + 1) + return (first); + t1 = parse_encoding(t, last, db); + if (t == t1) + return (first); + t = t1; + break; + } + break; + case 'G': + switch (first[1]) { + case 'V': + nadd_l(db, "guard variable for", 0); + t = parse_name(first + 2, last, NULL, db); + break; + case 'R': + nadd_l(db, "reference temporary for", 0); + t = parse_name(first + 2, last, NULL, db); + break; + default: + return (first); + } + break; + default: + return (first); + } + + size_t amt = NAMT(db, n); + if (t == first + 2 || amt < 2) + return (first); + + njoin(db, amt, " "); + return (t); +} + +/* + * ::= h _ + * ::= v _ + * + * ::= + * # non-virtual base override + * + * ::= _ + * # virtual base override, with vcall offset + */ +static const char * +parse_call_offset(const char *first, const char *last, locale_t loc) +{ + VERIFY3P(first, <=, last); + + const char *t = NULL; + const char *t1 = NULL; + + if (first == last) + return (first); + + if (first[0] != 'h' && first[0] != 'v') + return (first); + + t = parse_number(first + 1, last, loc); + if (t == first + 1 || t == last || t[0] != '_') + return (first); + + /* skip _ */ + t++; + + if (first[0] == 'h') + return (t); + + t1 = parse_number(t, last, loc); + if (t == t1 || t1 == last || t1[0] != '_') + return (first); + + /* skip _ */ + t1++; + + return (t1); +} + +/* + * ::= // N + * ::= # See Scope Encoding below // Z + * ::= + * ::= + * + * ::= + * ::= + */ +static const char * +parse_name(const char *first, const char *last, + boolean_t *ends_with_template_args, cpp_db_t *db) +{ + VERIFY3P(first, <=, last); + + const char *t = first; + const char *t1 = NULL; + + if (last - first < 2) + return (first); + + /* extension: ignore L here */ + if (t[0] == 'L') + t++; + + switch (t[0]) { + case 'N': + t1 = parse_nested_name(t, last, ends_with_template_args, db); + return ((t == t1) ? first : t1); + case 'Z': + t1 = parse_local_name(t, last, ends_with_template_args, db); + return ((t == t1) ? first : t1); + } + + /* + * + * + * + */ + t1 = parse_unscoped_name(t, last, db); + + /* */ + if (t != t1 && t1[0] != 'I') + return (t1); + + if (t == t1) { + t1 = parse_substitution(t, last, db); + if (t == t1 || t1 == last || t1[0] != 'I') + return (first); + } else { + save_top(db, 1); + } + + t = parse_template_args(t1, last, db); + if (t1 == t || nlen(db) < 2) + return (first); + + nfmt(db, "{1:L}{0}", "{1:R}"); + + if (ends_with_template_args != NULL) + *ends_with_template_args = B_TRUE; + + return (t); +} + +/* BEGIN CSTYLED */ +/* + * := Z E [] + * := Z E s [] + * := Z Ed [ ] _ + */ +/* END CSTYLED */ +const char * +parse_local_name(const char *first, const char *last, + boolean_t *ends_with_template_args, cpp_db_t *db) +{ + VERIFY3P(first, <=, last); + + const char *t = NULL; + const char *t1 = NULL; + const char *t2 = NULL; + + if (first == last || first[0] != 'Z') + return (first); + + t = parse_encoding(first + 1, last, db); + if (t == first + 1 || t == last || t[0] != 'E') + return (first); + + VERIFY(!nempty(db)); + + /* skip E */ + t++; + + if (t[0] == 's') { + nfmt(db, "{0:L}::string literal", "{0:R}"); + return (parse_discriminator(t, last, db->cpp_loc)); + } + + if (t[0] == 'd') { + t1 = parse_number(t + 1, last, db->cpp_loc); + if (t1[0] != '_') + return (first); + t1++; + } else { + t1 = t; + } + + t2 = parse_name(t1, last, ends_with_template_args, db); + if (t2 == t1) + return (first); + + nfmt(db, "{1:L}::{0}", "{1:R}"); + + /* parsed, but ignored */ + if (t[0] != 'd') + t2 = parse_discriminator(t2, last, db->cpp_loc); + + return (t2); +} + +/* BEGIN CSTYLED */ +/* + * ::= N [] [] E + * ::= N [] [] E + * + * ::= + * ::= + * ::= + * ::= + * ::= # empty + * ::= + * ::= + * extension ::= L + * + * ::=