Name of user not set #1002476 has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/36929 )
Change subject: libpayload: Add openlibm support ......................................................................
libpayload: Add openlibm support
Openlibm is a high quality system independent portable C mathematical library (libm) and can be used standalone in applications and programming language implementations. Various projects are hampered by the lack of math functions. This CL inculcates a good libm (https://openlibm.org/) implementation to libpayload as a high quality, portable solution.
Fixes: https://ticket.coreboot.org/issues/214
Tested on x86 and provide sample application for the same.
Change-Id: Ie457c02c0cfdc697087cd3e9ee5558f84b8f06c6 Signed-off-by: Himanshu Sahdev himanshusah@hcl.com --- M payloads/libpayload/Kconfig M payloads/libpayload/Makefile.inc M payloads/libpayload/README R payloads/libpayload/samples/HelloWorld/Makefile R payloads/libpayload/samples/HelloWorld/hello.c C payloads/libpayload/samples/OpenlibmApp/Makefile A payloads/libpayload/samples/OpenlibmApp/README A payloads/libpayload/samples/OpenlibmApp/openlibm.c 8 files changed, 143 insertions(+), 12 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/29/36929/1
diff --git a/payloads/libpayload/Kconfig b/payloads/libpayload/Kconfig index 97b970b..cff95f6 100644 --- a/payloads/libpayload/Kconfig +++ b/payloads/libpayload/Kconfig @@ -171,6 +171,27 @@ bool "Enable C library support" default y
+config OPENLIBM + bool "Enable Math Library support" + default y + +choice + prompt "Explicit Building" + default NON_EXPLICIT + depends on OPENLIBM + +config EXPLICIT + bool "Explicit" + help + Allow explicit building openlibm. + +config NON_EXPLICIT + bool "Non explicit" + help + Don't allow explicit building openlibm. + +endchoice + config CURSES bool "Build a curses library" default y if !CHROMEOS diff --git a/payloads/libpayload/Makefile.inc b/payloads/libpayload/Makefile.inc index 4863d3f..e1272b8 100644 --- a/payloads/libpayload/Makefile.inc +++ b/payloads/libpayload/Makefile.inc @@ -37,7 +37,7 @@ ARCHDIR-$(CONFIG_LP_ARCH_X86) := x86 DESTDIR ?= install
-real-target: lib +real-target: libopenlibm lib
classes-$(CONFIG_LP_PCI) += libpci classes-$(CONFIG_LP_LIBC) += libc @@ -81,9 +81,32 @@ $(if $(wildcard $(1)$(call extract_nth,1,$(2))), \ $(eval includes += $(1)$(2)))
+MARCH--$(CONFIG_LP_ARCH_ARM) = corei7 +OPENARCH-$(CONFIG_LP_ARCH_ARM) = arm +OPENARCH-$(CONFIG_LP_ARCH_ARM64) = aarch64 +OPENARCH-$(CONFIG_LP_ARCH_MIPS) = mips +OPENARCH-$(CONFIG_LP_ARCH_X86) = i386 + +openlibdir = $(obj)/libopenlibm +openlibfiles-$(CONFIG_LP_OPENLIBM) = $(openlibdir)/*.o + +libopenlibm: +ifeq ($(CONFIG_LP_OPENLIBM),y) + printf " INCLUDING CONFIG_LP_OPENLIBM " +ifneq ($(CONFIG_LP_EXPLICIT),y) + make -C openlibm ARCH=$(OPENARCH-y) MARCH=$(MARCH-y) +endif + cp openlibm/libopenlibm.a $(obj) +ifeq ("$(wildcard $(obj)/libopenlibm)",y) + mkdir $(openlibdir); cd $(openlibdir); $(AR) -x ../libopenlibm.a; +else + rm -rf $(openlibdir); mkdir $(openlibdir); cd $(openlibdir); $(AR) -x ../libopenlibm.a; +endif +endif + $(obj)/libpayload.a: $(foreach class,$(libraries),$$($(class)-objs)) printf " AR $(subst $(CURDIR)/,,$(@))\n" - $(AR) rc $@ $^ + $(AR) rc $@ $^ $(openlibfiles-y)
$(obj)/%.a: $$(%-objs) printf " AR $(subst $(CURDIR)/,,$(@))\n" @@ -99,6 +122,7 @@ for lib in $(library-targets); do \ install -m 644 $$lib $(DESTDIR)/libpayload/lib/; \ done + install -m 644 $(obj)/libopenlibm.a $(DESTDIR)/libpayload/lib/ install -m 644 arch/$(ARCHDIR-y)/libpayload.ldscript $(DESTDIR)/libpayload/lib/ install -m 755 -d $(DESTDIR)/libpayload/lib/$(ARCHDIR-y) install -m 644 $(obj)/head.o $(DESTDIR)/libpayload/lib/$(ARCHDIR-y) @@ -121,7 +145,8 @@ install -m 755 .xcompile $(DESTDIR)/libpayload/libpayload.xcompile
clean-for-update-target: - rm -f $(addsuffix .a,$(addprefix $(obj)/,$(libraries))) $(obj)/libpayload.a + rm -f $(addsuffix .a,$(addprefix $(obj)/,$(libraries))) $(obj)/libopenlibm.a $(obj)/libpayload.a + make -C openlibm clean
clean-target: prepare: diff --git a/payloads/libpayload/README b/payloads/libpayload/README index d35f685..c1233f3 100644 --- a/payloads/libpayload/README +++ b/payloads/libpayload/README @@ -52,7 +52,15 @@
$ lpgcc -o hello.elf hello.c
-Please see the sample/ directory for details. +Please see the samples/ directory for example applications. + + +Openlibm +-------- + +Openlibm is built with portability in mind. Select CONFIG_LP_OPENLIBM to allow building with openlibm. + +CONFIG_LP_EXPLICIT can be selected if one wants to build explicitly.
Website and Mailing List diff --git a/payloads/libpayload/sample/Makefile b/payloads/libpayload/samples/HelloWorld/Makefile similarity index 89% rename from payloads/libpayload/sample/Makefile rename to payloads/libpayload/samples/HelloWorld/Makefile index 18121df..7fe5061 100644 --- a/payloads/libpayload/sample/Makefile +++ b/payloads/libpayload/samples/HelloWorld/Makefile @@ -28,8 +28,8 @@ ##
# Sample libpayload Makefile. -include ../.config -include ../.xcompile +include ../../.config +include ../../.xcompile
ARCH-$(CONFIG_LP_ARCH_ARM) := arm ARCH-$(CONFIG_LP_ARCH_X86) := x86_32 @@ -38,7 +38,14 @@
CC := $(CC_$(ARCH-y)) AS := $(AS_$(ARCH-y)) -LIBPAYLOAD_DIR := ../install/libpayload +DIRNAME = ../../install +ifneq "$(wildcard $(DIRNAME) )" "" + # if directory DIRNAME exists: + LIBPAYLOAD_DIR := ../../install/libpayload +else + # if it doesn't: + LIBPAYLOAD_DIR := ../.. +endif XCC := CC="$(CC)" $(LIBPAYLOAD_DIR)/bin/lpgcc XAS := AS="$(AS)" $(LIBPAYLOAD_DIR)/bin/lpas CFLAGS := -fno-builtin -Wall -Werror -Os diff --git a/payloads/libpayload/sample/hello.c b/payloads/libpayload/samples/HelloWorld/hello.c similarity index 100% rename from payloads/libpayload/sample/hello.c rename to payloads/libpayload/samples/HelloWorld/hello.c diff --git a/payloads/libpayload/sample/Makefile b/payloads/libpayload/samples/OpenlibmApp/Makefile similarity index 87% copy from payloads/libpayload/sample/Makefile copy to payloads/libpayload/samples/OpenlibmApp/Makefile index 18121df..ff6b8c6 100644 --- a/payloads/libpayload/sample/Makefile +++ b/payloads/libpayload/samples/OpenlibmApp/Makefile @@ -28,8 +28,8 @@ ##
# Sample libpayload Makefile. -include ../.config -include ../.xcompile +include ../../.config +include ../../.xcompile
ARCH-$(CONFIG_LP_ARCH_ARM) := arm ARCH-$(CONFIG_LP_ARCH_X86) := x86_32 @@ -38,17 +38,24 @@
CC := $(CC_$(ARCH-y)) AS := $(AS_$(ARCH-y)) -LIBPAYLOAD_DIR := ../install/libpayload +DIRNAME = ../../install +ifneq "$(wildcard $(DIRNAME) )" "" + # if directory DIRNAME exists: + LIBPAYLOAD_DIR := ../../install/libpayload +else + # if it doesn't: + LIBPAYLOAD_DIR := ../.. +endif XCC := CC="$(CC)" $(LIBPAYLOAD_DIR)/bin/lpgcc XAS := AS="$(AS)" $(LIBPAYLOAD_DIR)/bin/lpas CFLAGS := -fno-builtin -Wall -Werror -Os -TARGET := hello +TARGET := openlibm OBJS := $(TARGET).o
all: $(TARGET).elf
$(TARGET).elf: $(OBJS) - $(XCC) -o $@ $(OBJS) + $(XCC) $(OBJS) -lpayload -o $@
%.o: %.c $(XCC) $(CFLAGS) -c -o $@ $< diff --git a/payloads/libpayload/samples/OpenlibmApp/README b/payloads/libpayload/samples/OpenlibmApp/README new file mode 100644 index 0000000..a414853 --- /dev/null +++ b/payloads/libpayload/samples/OpenlibmApp/README @@ -0,0 +1,19 @@ +------------------------------------------------------------------------------- +Openlibm README +------------------------------------------------------------------------------- + +OpenLibm is an effort to have a high quality, portable, standalone C mathematical library (libm). It can be used standalone in applications and programming language implementations. + +See https://openlibm.org/ for details on openlibm. + + +Usage +----- + +This example contains a simple application for building with openlibm which can be statically linked with libpayload.a + +Select the CONFIG_LP_OPENLIBM option to include openlibm in libpayload building. + + $ make + +ELF executable can be used as coreboot payload after successful building. diff --git a/payloads/libpayload/samples/OpenlibmApp/openlibm.c b/payloads/libpayload/samples/OpenlibmApp/openlibm.c new file mode 100644 index 0000000..d7983d5 --- /dev/null +++ b/payloads/libpayload/samples/OpenlibmApp/openlibm.c @@ -0,0 +1,44 @@ +/* + * This file is part of the libpayload project. + * + * Copyright (C) 2008 Advanced Micro Devices, Inc. + * + * 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * 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. + */ + +/* Example file for openlibm. */ + +#include <libpayload-config.h> +#include <libpayload.h> + +int __signbit(double d); + +int main(void) +{ + printf("Openlibm sample application!\n"); +/* Evaluate sign bit, -ve value gives 1 */ + printf("sign: %d \n", __signbit(-544)); + halt(); + return 0; +}