From 83b4671e6262c5aa6b4f9fb5a384b1946dfc2e7f Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Tue, 16 Aug 2016 19:02:42 +0300 Subject: [PATCH] 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/{ficl => efi/boot1}/Makefile | 9 +- .../sys/boot/efi/boot1/{Makefile => Makefile.com} | 93 ++++++------ .../boot/{libstand => efi/boot1}/amd64/Makefile | 23 +-- .../sys/boot/{libstand => efi/boot1}/i386/Makefile | 23 +-- 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 --------- .../boot/sys/boot/{ficl => efi/libefi}/Makefile | 11 +- usr/src/boot/sys/boot/efi/libefi/Makefile.com | 73 ++++++++++ .../sys/boot/{zfs => efi/libefi}/amd64/Makefile | 13 +- .../sys/boot/{zfs => efi/libefi}/i386/Makefile | 14 +- .../boot/sys/boot/{ficl => efi/loader}/Makefile | 9 +- usr/src/boot/sys/boot/efi/loader/Makefile.com | 156 +++++++++++++++++++++ .../boot/{libstand => efi/loader}/amd64/Makefile | 23 +-- .../sys/boot/efi/loader/arch/amd64/Makefile.inc | 5 - .../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 +- .../boot/efi/loader/{arch/amd64 => }/framebuffer.c | 5 +- .../boot/efi/loader/{arch/amd64 => }/framebuffer.h | 0 .../boot/{libstand => efi/loader}/i386/Makefile | 23 +-- 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/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/{ficl => libficl}/Makefile | 0 .../{ficl/Makefile.inc => libficl/Makefile.com} | 13 +- .../boot/sys/boot/{ficl => libficl}/amd64/Makefile | 7 +- .../boot/sys/boot/{ficl => libficl}/ficllocal.h | 0 .../boot/sys/boot/{ficl => libficl}/i386/Makefile | 8 +- .../sys/boot/{ficl => libficl}/softcore/Makefile | 0 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 +- 56 files changed, 682 insertions(+), 375 deletions(-) copy usr/src/boot/sys/boot/{ficl => efi/boot1}/Makefile (88%) rename usr/src/boot/sys/boot/efi/boot1/{Makefile => Makefile.com} (53%) copy usr/src/boot/sys/boot/{libstand => efi/boot1}/amd64/Makefile (66%) copy usr/src/boot/sys/boot/{libstand => efi/boot1}/i386/Makefile (67%) copy usr/src/boot/sys/boot/{ficl => efi/libefi}/Makefile (88%) create mode 100644 usr/src/boot/sys/boot/efi/libefi/Makefile.com copy usr/src/boot/sys/boot/{zfs => efi/libefi}/amd64/Makefile (77%) copy usr/src/boot/sys/boot/{zfs => efi/libefi}/i386/Makefile (77%) copy usr/src/boot/sys/boot/{ficl => efi/loader}/Makefile (88%) create mode 100644 usr/src/boot/sys/boot/efi/loader/Makefile.com copy usr/src/boot/sys/boot/{libstand => efi/loader}/amd64/Makefile (65%) create mode 100644 usr/src/boot/sys/boot/efi/loader/arch/i386/multiboot_tramp.S rename usr/src/boot/sys/boot/efi/loader/{arch/amd64 => }/framebuffer.c (99%) rename usr/src/boot/sys/boot/efi/loader/{arch/amd64 => }/framebuffer.h (100%) copy usr/src/boot/sys/boot/{libstand => efi/loader}/i386/Makefile (65%) rename usr/src/boot/sys/boot/{ficl => libficl}/Makefile (100%) rename usr/src/boot/sys/boot/{ficl/Makefile.inc => libficl/Makefile.com} (83%) rename usr/src/boot/sys/boot/{ficl => libficl}/amd64/Makefile (82%) rename usr/src/boot/sys/boot/{ficl => libficl}/ficllocal.h (100%) rename usr/src/boot/sys/boot/{ficl => libficl}/i386/Makefile (82%) rename usr/src/boot/sys/boot/{ficl => libficl}/softcore/Makefile (100%) 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/ficl/Makefile b/usr/src/boot/sys/boot/efi/boot1/Makefile similarity index 88% copy from usr/src/boot/sys/boot/ficl/Makefile copy to usr/src/boot/sys/boot/efi/boot1/Makefile index 51e6a20ed9..fa72aaecd7 100644 --- a/usr/src/boot/sys/boot/ficl/Makefile +++ b/usr/src/boot/sys/boot/efi/boot1/Makefile @@ -13,17 +13,18 @@ # Copyright 2016 Toomas Soome # +.KEEP_STATE: + include $(SRC)/Makefile.master -SUBDIRS = softcore $(MACH) $(MACH64) +SUBDIRS = $(MACH) $(MACH64) all := TARGET = all -install := TARGET = install clean := TARGET = clean clobber := TARGET = clobber +install := TARGET = install -all install: $(SUBDIRS) -clean clobber: $(SUBDIRS) +all clean clobber install: $(SUBDIRS) $(SUBDIRS): FRC @cd $@; pwd; $(MAKE) $(MFLAGS) $(TARGET) diff --git a/usr/src/boot/sys/boot/efi/boot1/Makefile b/usr/src/boot/sys/boot/efi/boot1/Makefile.com similarity index 53% rename from usr/src/boot/sys/boot/efi/boot1/Makefile rename to usr/src/boot/sys/boot/efi/boot1/Makefile.com index 29014c6136..90a0ad00a5 100644 --- a/usr/src/boot/sys/boot/efi/boot1/Makefile +++ b/usr/src/boot/sys/boot/efi/boot1/Makefile.com @@ -11,7 +11,6 @@ # # Copyright 2016 Toomas Soome -# Copyright 2016 RackTop Systems. # include $(SRC)/Makefile.master @@ -23,7 +22,6 @@ 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 \ @@ -31,105 +29,102 @@ SRCS= multiboot.S boot1.c self_reloc.c start.S ufs_module.c zfs_module.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 += -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/ +CPPFLAGS += -I../../../zfs/ +CPPFLAGS += -I../../../../cddl/boot/zfs/ # Always add MI sources and REGULAR efi loader bits -CPPFLAGS += -I./../../common +CPPFLAGS += -I../../../common # For sys/skein.h CPPFLAGS += -I$(SRC)/uts/common -include ../Makefile.inc +include ../../Makefile.inc -FILES= boot1.efi +FILES= $(EFIPROG) FILEMODE= 0555 ROOT_BOOT= $(ROOT)/boot ROOTBOOTFILES=$(FILES:%=$(ROOT_BOOT)/%) -LDSCRIPT= ./../loader/arch/${MACHINE}/ldscript.${MACHINE} -LDFLAGS= -nostdlib --eh-frame-hdr -znocombreloc +LDSCRIPT= ../../loader/arch/$(MACHINE)/ldscript.$(MACHINE) +LDFLAGS= -nostdlib --eh-frame-hdr LDFLAGS += -shared --hash-style=both --enable-new-dtags -LDFLAGS += -T${LDSCRIPT} -Bsymbolic - -all: boot1.efi +LDFLAGS += -T$(LDSCRIPT) -Bsymbolic install: all $(ROOTBOOTFILES) -LIBEFI= ../libefi/libefi.a +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/$(MACH64)/libstand.a -LIBZFSBOOT= ../../zfs/$(MACH64)/libzfsboot.a +LIBSTAND= ../../../libstand/$(MACHINE)/libstand.a +LIBZFSBOOT= ../../../zfs/$(MACHINE)/libzfsboot.a DPADD= $(LIBEFI) $(LIBZFSBOOT) $(LIBSTAND) -LDADD= -L../libefi -lefi -LDADD += -L../../zfs/$(MACH64) -lzfsboot -LDADD += -L../../libstand/$(MACH64) -lstand - -DPADD += ${LDSCRIPT} +LDADD= -L../../libefi/$(MACHINE) -lefi +LDADD += -L../../../zfs/$(MACHINE) -lzfsboot +LDADD += -L../../../libstand/$(MACHINE) -lstand -EFI_TARGET= pei-x86-64 +DPADD += $(LDSCRIPT) -boot1.efi: ${PROG} - if [ `${OBJDUMP} -t ${PROG} | fgrep '*UND*' | wc -l` != 0 ]; then \ - ${OBJDUMP} -t ${PROG} | fgrep '*UND*'; \ +$(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 \ + $(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 $@ $@ + --output-target=$(EFI_TARGET) --subsystem efi-app $(PROG) $@ + $(BTXLD) -V $(BOOT_VERSION) -o $@ $@ -boot1.o: ./../../common/ufsread.c +boot1.o: ../../../common/ufsread.c -CLEANFILES= boot1.efi ${PROG} +CLEANFILES= $(EFIPROG) $(PROG) -${PROG}: $(OBJS) $(DPADD) +$(PROG): $(OBJS) $(DPADD) $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LDADD) -CLEANFILES += machine x86 - machine: $(RM) machine - $(SYMLINK) ./../../../${MACHINE}/include machine + $(SYMLINK) ../../../../$(MACHINE)/include machine x86: $(RM) x86 - $(SYMLINK) ./../../../x86/include x86 - -$(OBJS): machine x86 + $(SYMLINK) ../../../../x86/include x86 clean clobber: $(RM) $(CLEANFILES) $(OBJS) -%.o: ../loader/arch/${MACHINE}/%.S +%.o: ../../../common/%.S $(COMPILE.S) $< -%.o: ../loader/%.c +%.o: ../%.c $(COMPILE.c) $< -%.o: ../../common/%.S - $(COMPILE.S) $< +# +# 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 +%.o: ../../../common/%.c $(COMPILE.c) $< $(ROOT_BOOT)/%: % diff --git a/usr/src/boot/sys/boot/libstand/amd64/Makefile b/usr/src/boot/sys/boot/efi/boot1/amd64/Makefile similarity index 66% copy from usr/src/boot/sys/boot/libstand/amd64/Makefile copy to usr/src/boot/sys/boot/efi/boot1/amd64/Makefile index 3516128c65..24d3c17a1e 100644 --- a/usr/src/boot/sys/boot/libstand/amd64/Makefile +++ b/usr/src/boot/sys/boot/efi/boot1/amd64/Makefile @@ -11,20 +11,23 @@ # # Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. # -include ../Makefile.com - MACHINE= $(MACH64) +ASFLAGS= -m64 +EFIPROG= bootx64.efi + +all: $(EFIPROG) + +include ../Makefile.com -CFLAGS += -m64 -fPIC -mno-red-zone -ASFLAGS = -m64 -fPIC +EFI_TARGET= pei-x86-64 +LDFLAGS += -znocombreloc -# _setjmp/_longjmp -SRCS += $(LIBSTAND_SRC)/amd64/_setjmp.S -OBJS += _setjmp.o +CPPFLAGS += -DLOADER_EFI=\"loader64.efi\" +CFLAGS += -m64 -mno-red-zone -$(LIBRARY): $(SRCS) $(OBJS) +CLEANFILES += machine x86 -%.o: $(LIBSTAND_SRC)/amd64/%.S - $(COMPILE.S) $< +$(OBJS): machine x86 diff --git a/usr/src/boot/sys/boot/libstand/i386/Makefile b/usr/src/boot/sys/boot/efi/boot1/i386/Makefile similarity index 67% copy from usr/src/boot/sys/boot/libstand/i386/Makefile copy to usr/src/boot/sys/boot/efi/boot1/i386/Makefile index 80983da037..4d01edc6fa 100644 --- a/usr/src/boot/sys/boot/libstand/i386/Makefile +++ b/usr/src/boot/sys/boot/efi/boot1/i386/Makefile @@ -11,20 +11,23 @@ # # Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. # -include ../Makefile.com - MACHINE= $(MACH) +ASFLAGS= -m32 +EFIPROG= bootia32.efi + +all: $(EFIPROG) + +include ../Makefile.com -CFLAGS += -m32 -fno-reorder-functions -CFLAGS += -mpreferred-stack-boundary=2 +EFI_TARGET= pei-i386 +LDFLAGS += -znocombreloc -# _setjmp/_longjmp -SRCS += $(LIBSTAND_SRC)/i386/_setjmp.S -OBJS += _setjmp.o +CPPFLAGS += -DLOADER_EFI=\"loader32.efi\" +CFLAGS += -m32 -$(LIBRARY): $(SRCS) $(OBJS) +CLEANFILES += machine x86 -%.o: $(LIBSTAND_SRC)/i386/%.S - $(COMPILE.S) $< +$(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/ficl/Makefile b/usr/src/boot/sys/boot/efi/libefi/Makefile similarity index 88% copy from usr/src/boot/sys/boot/ficl/Makefile copy to usr/src/boot/sys/boot/efi/libefi/Makefile index 51e6a20ed9..482bfd2b4d 100644 --- a/usr/src/boot/sys/boot/ficl/Makefile +++ b/usr/src/boot/sys/boot/efi/libefi/Makefile @@ -13,17 +13,20 @@ # Copyright 2016 Toomas Soome # +.KEEP_STATE: + include $(SRC)/Makefile.master -SUBDIRS = softcore $(MACH) $(MACH64) +SUBDIRS = $(MACH) $(MACH64) all := TARGET = all -install := TARGET = install clean := TARGET = clean clobber := TARGET = clobber +install := TARGET = install + +all clean clobber: $(SUBDIRS) -all install: $(SUBDIRS) -clean clobber: $(SUBDIRS) +install: all $(SUBDIRS): FRC @cd $@; pwd; $(MAKE) $(MFLAGS) $(TARGET) 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/zfs/amd64/Makefile b/usr/src/boot/sys/boot/efi/libefi/amd64/Makefile similarity index 77% copy from usr/src/boot/sys/boot/zfs/amd64/Makefile copy to usr/src/boot/sys/boot/efi/libefi/amd64/Makefile index 80eb330468..5994a68d7a 100644 --- a/usr/src/boot/sys/boot/zfs/amd64/Makefile +++ b/usr/src/boot/sys/boot/efi/libefi/amd64/Makefile @@ -11,10 +11,19 @@ # # Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. # +MACHINE= $(MACH64) +ASFLAGS= -m64 + +all: libefi.a + +SRCS= time.c include ../Makefile.com -CFLAGS += -mno-red-zone -m64 -fPIC +CFLAGS += -m64 -MACHINE= $(MACH64) +CLEANFILES += machine x86 + +$(OBJS): machine x86 diff --git a/usr/src/boot/sys/boot/zfs/i386/Makefile b/usr/src/boot/sys/boot/efi/libefi/i386/Makefile similarity index 77% copy from usr/src/boot/sys/boot/zfs/i386/Makefile copy to usr/src/boot/sys/boot/efi/libefi/i386/Makefile index f2bb545d73..8e9691699c 100644 --- a/usr/src/boot/sys/boot/zfs/i386/Makefile +++ b/usr/src/boot/sys/boot/efi/libefi/i386/Makefile @@ -11,11 +11,19 @@ # # Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. # +MACHINE= $(MACH) +ASFLAGS= -m32 + +all: libefi.a + +SRCS= time.c include ../Makefile.com -CFLAGS += -march=i386 -m32 -fno-reorder-functions -CFLAGS += -mpreferred-stack-boundary=2 +CFLAGS += -m32 -MACHINE= $(MACH) +CLEANFILES += machine x86 + +$(OBJS): machine x86 diff --git a/usr/src/boot/sys/boot/ficl/Makefile b/usr/src/boot/sys/boot/efi/loader/Makefile similarity index 88% copy from usr/src/boot/sys/boot/ficl/Makefile copy to usr/src/boot/sys/boot/efi/loader/Makefile index 51e6a20ed9..fa72aaecd7 100644 --- a/usr/src/boot/sys/boot/ficl/Makefile +++ b/usr/src/boot/sys/boot/efi/loader/Makefile @@ -13,17 +13,18 @@ # Copyright 2016 Toomas Soome # +.KEEP_STATE: + include $(SRC)/Makefile.master -SUBDIRS = softcore $(MACH) $(MACH64) +SUBDIRS = $(MACH) $(MACH64) all := TARGET = all -install := TARGET = install clean := TARGET = clean clobber := TARGET = clobber +install := TARGET = install -all install: $(SUBDIRS) -clean clobber: $(SUBDIRS) +all clean clobber install: $(SUBDIRS) $(SUBDIRS): FRC @cd $@; pwd; $(MAKE) $(MFLAGS) $(TARGET) 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/libstand/amd64/Makefile b/usr/src/boot/sys/boot/efi/loader/amd64/Makefile similarity index 65% copy from usr/src/boot/sys/boot/libstand/amd64/Makefile copy to usr/src/boot/sys/boot/efi/loader/amd64/Makefile index 3516128c65..540894dce0 100644 --- a/usr/src/boot/sys/boot/libstand/amd64/Makefile +++ b/usr/src/boot/sys/boot/efi/loader/amd64/Makefile @@ -11,20 +11,23 @@ # # Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. # -include ../Makefile.com - MACHINE= $(MACH64) +ASFLAGS= -m64 +EFIPROG= loader64.efi + +all: $(EFIPROG) + +include ../Makefile.com -CFLAGS += -m64 -fPIC -mno-red-zone -ASFLAGS = -m64 -fPIC +EFI_TARGET= pei-x86-64 +LDFLAGS += -znocombreloc -# _setjmp/_longjmp -SRCS += $(LIBSTAND_SRC)/amd64/_setjmp.S -OBJS += _setjmp.o +efi_main.o := CPPFLAGS += -DLOADER_EFI=L\"loader64.efi\" +CFLAGS += -m64 -$(LIBRARY): $(SRCS) $(OBJS) +CLEANFILES += machine x86 $(EFIPROG) -%.o: $(LIBSTAND_SRC)/amd64/%.S - $(COMPILE.S) $< +$(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/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/arch/amd64/framebuffer.c b/usr/src/boot/sys/boot/efi/loader/framebuffer.c similarity index 99% rename from usr/src/boot/sys/boot/efi/loader/arch/amd64/framebuffer.c rename to usr/src/boot/sys/boot/efi/loader/framebuffer.c index f31704bdb9..77d01dfb64 100644 --- a/usr/src/boot/sys/boot/efi/loader/arch/amd64/framebuffer.c +++ b/usr/src/boot/sys/boot/efi/loader/framebuffer.c @@ -1,4 +1,4 @@ -/*- +/* * Copyright (c) 2013 The FreeBSD Foundation * All rights reserved. * @@ -27,11 +27,10 @@ */ #include -__FBSDID("$FreeBSD$"); +#include #include #include -#include #include #include diff --git a/usr/src/boot/sys/boot/efi/loader/arch/amd64/framebuffer.h b/usr/src/boot/sys/boot/efi/loader/framebuffer.h similarity index 100% rename from usr/src/boot/sys/boot/efi/loader/arch/amd64/framebuffer.h rename to usr/src/boot/sys/boot/efi/loader/framebuffer.h diff --git a/usr/src/boot/sys/boot/libstand/i386/Makefile b/usr/src/boot/sys/boot/efi/loader/i386/Makefile similarity index 65% copy from usr/src/boot/sys/boot/libstand/i386/Makefile copy to usr/src/boot/sys/boot/efi/loader/i386/Makefile index 80983da037..c4a451fba0 100644 --- a/usr/src/boot/sys/boot/libstand/i386/Makefile +++ b/usr/src/boot/sys/boot/efi/loader/i386/Makefile @@ -11,20 +11,23 @@ # # Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. # -include ../Makefile.com - MACHINE= $(MACH) +ASFLAGS= -m32 +EFIPROG= loader32.efi + +all: $(EFIPROG) + +include ../Makefile.com -CFLAGS += -m32 -fno-reorder-functions -CFLAGS += -mpreferred-stack-boundary=2 +EFI_TARGET= pei-i386 +LDFLAGS += -znocombreloc -# _setjmp/_longjmp -SRCS += $(LIBSTAND_SRC)/i386/_setjmp.S -OBJS += _setjmp.o +efi_main.o := CPPFLAGS += -DLOADER_EFI=L\"loader32.efi\" +CFLAGS += -m32 -$(LIBRARY): $(SRCS) $(OBJS) +CLEANFILES += machine x86 $(EFIPROG) -%.o: $(LIBSTAND_SRC)/i386/%.S - $(COMPILE.S) $< +$(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/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/ficl/Makefile b/usr/src/boot/sys/boot/libficl/Makefile similarity index 100% rename from usr/src/boot/sys/boot/ficl/Makefile rename to usr/src/boot/sys/boot/libficl/Makefile diff --git a/usr/src/boot/sys/boot/ficl/Makefile.inc b/usr/src/boot/sys/boot/libficl/Makefile.com similarity index 83% rename from usr/src/boot/sys/boot/ficl/Makefile.inc rename to usr/src/boot/sys/boot/libficl/Makefile.com index 0213ace089..3226faf88d 100644 --- a/usr/src/boot/sys/boot/ficl/Makefile.inc +++ b/usr/src/boot/sys/boot/libficl/Makefile.com @@ -11,23 +11,18 @@ # # 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= -nostdinc -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 +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 @@ -52,8 +47,6 @@ x86: $(RM) x86 $(SYMLINK) ../../../x86/include x86 -$(OBJECTS): machine x86 - %.o: ../softcore/%.c $(HEADERS) $(COMPILE.c) $< diff --git a/usr/src/boot/sys/boot/ficl/amd64/Makefile b/usr/src/boot/sys/boot/libficl/amd64/Makefile similarity index 82% rename from usr/src/boot/sys/boot/ficl/amd64/Makefile rename to usr/src/boot/sys/boot/libficl/amd64/Makefile index e9187ba9eb..bd9b9b4158 100644 --- a/usr/src/boot/sys/boot/ficl/amd64/Makefile +++ b/usr/src/boot/sys/boot/libficl/amd64/Makefile @@ -11,6 +11,7 @@ # # Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. # include $(SRC)/Makefile.master @@ -19,8 +20,10 @@ MACHINE= $(MACH64) all install: lib -include ../Makefile.inc +include ../Makefile.com -CFLAGS += -fPIC -m64 -mno-red-zone +CFLAGS += -m64 -mno-red-zone + +$(OBJECTS): machine x86 FRC: diff --git a/usr/src/boot/sys/boot/ficl/ficllocal.h b/usr/src/boot/sys/boot/libficl/ficllocal.h similarity index 100% rename from usr/src/boot/sys/boot/ficl/ficllocal.h rename to usr/src/boot/sys/boot/libficl/ficllocal.h diff --git a/usr/src/boot/sys/boot/ficl/i386/Makefile b/usr/src/boot/sys/boot/libficl/i386/Makefile similarity index 82% rename from usr/src/boot/sys/boot/ficl/i386/Makefile rename to usr/src/boot/sys/boot/libficl/i386/Makefile index 10e0c32dae..f4478a4c50 100644 --- a/usr/src/boot/sys/boot/ficl/i386/Makefile +++ b/usr/src/boot/sys/boot/libficl/i386/Makefile @@ -11,6 +11,7 @@ # # Copyright 2016 Toomas Soome +# Copyright 2016 RackTop Systems. # include $(SRC)/Makefile.master @@ -19,9 +20,10 @@ MACHINE= $(MACH) all install: lib -include ../Makefile.inc +include ../Makefile.com -CFLAGS += -m32 -march=i386 -mpreferred-stack-boundary=2 -CFLAGS += -fno-reorder-functions +CFLAGS += -m32 + +$(OBJECTS): machine x86 FRC: diff --git a/usr/src/boot/sys/boot/ficl/softcore/Makefile b/usr/src/boot/sys/boot/libficl/softcore/Makefile similarity index 100% rename from usr/src/boot/sys/boot/ficl/softcore/Makefile rename to usr/src/boot/sys/boot/libficl/softcore/Makefile 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 -- 2.11.4.GIT