diff options
Diffstat (limited to 'payloads/libpayload/sample/arch_mock')
-rw-r--r-- | payloads/libpayload/sample/arch_mock/Makefile | 48 | ||||
-rw-r--r-- | payloads/libpayload/sample/arch_mock/hello.c | 13 | ||||
-rw-r--r-- | payloads/libpayload/sample/arch_mock/hello_mocks.c | 43 |
3 files changed, 104 insertions, 0 deletions
diff --git a/payloads/libpayload/sample/arch_mock/Makefile b/payloads/libpayload/sample/arch_mock/Makefile new file mode 100644 index 0000000000..a1e748111e --- /dev/null +++ b/payloads/libpayload/sample/arch_mock/Makefile @@ -0,0 +1,48 @@ +# SPDX-License-Identifier: GPL-2.0-only + +# Sample libpayload Makefile for ARCH_MOCK +# ARCH_MOCK is not intended to be used with xcompile +include ../../.config + +ifneq ($(CONFIG_LP_ARCH_MOCK),y) +$(error This example supports ARCH_MOCK only.) +endif + +CC := gcc +AS := as +OBJCOPY := objcopy +LIBPAYLOAD_DIR := ../../install/libpayload +CFLAGS := -fno-builtin -Wall -Werror -Os \ + -include $(LIBPAYLOAD_DIR)/include/kconfig.h \ + -include $(LIBPAYLOAD_DIR)/include/compiler.h \ + -I $(LIBPAYLOAD_DIR)/include \ + -I $(LIBPAYLOAD_DIR)/include/mock \ + -ffunction-sections \ + -fdata-sections -g3 +LDFLAGS := -Wl,--gc-sections +TARGET := hello +OBJS := $(TARGET).o +OBJS-mock := $(TARGET)_mocks.o +LIBPAYLOAD-local := libpayload.a +mocks := console_write + +all: $(TARGET).elf + +$(TARGET).elf: $(OBJS) $(OBJS-mock) $(LIBPAYLOAD-local) + $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBPAYLOAD-local) \ + -Wl,--exclude-libs,ALL -lc $(OBJS-mock) + +%.o: %.c + $(CC) $(CFLAGS) -c -o $@ $< + +%.S.o: %.S + $(AS) --32 -o $@ $< + +# Copy libpayload and weaken all mocked symbols +$(LIBPAYLOAD-local): $(LIBPAYLOAD_DIR)/lib/libpayload.a + $(OBJCOPY) $(foreach mock,$(mocks),--weaken-symbol=$(mock)) $< $@ + +clean: + rm -f $(TARGET).elf *.o $(LIBPAYLOAD-local) + +distclean: clean diff --git a/payloads/libpayload/sample/arch_mock/hello.c b/payloads/libpayload/sample/arch_mock/hello.c new file mode 100644 index 0000000000..5a96e42e75 --- /dev/null +++ b/payloads/libpayload/sample/arch_mock/hello.c @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +/* Example file for libpayload. */ + +#include <libpayload-config.h> +#include <libpayload.h> + +int main(void) +{ + printf("Hello world!\n"); + halt(); + return 0; +} diff --git a/payloads/libpayload/sample/arch_mock/hello_mocks.c b/payloads/libpayload/sample/arch_mock/hello_mocks.c new file mode 100644 index 0000000000..84e86ff257 --- /dev/null +++ b/payloads/libpayload/sample/arch_mock/hello_mocks.c @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <libpayload-config.h> +#include <arch/types.h> +#include <stddef.h> +#include <unistd.h> +#include <stdio.h> + +/* Use libc version. calling exit() or abort() would cause infinite recursion */ +__attribute__((noreturn)) +void _exit(int); + +__attribute__((noreturn)) +void halt(void) +{ + _exit(0); +} + +#define TEST_SYMBOL(symbol, value) asm(".set " #symbol ", " #value "\n\t.globl " #symbol) + +#define TEST_REGION(region, size) uint8_t _##region[size]; \ + TEST_SYMBOL(_e##region, _##region + size); \ + TEST_SYMBOL(_##region##_size, size) + +TEST_REGION(heap, CONFIG_LP_HEAP_SIZE); + +uint64_t timer_raw_value(void) +{ + return 0; +} + +uint64_t timer_hz(void) +{ + return 0; +} + +/* Not present in libpayload. Can be used to write to real stdout. */ +ssize_t write(int fildes, const void *buf, size_t nbyte); + +void console_write(const void *buffer, size_t count) +{ + write(1, buffer, count); +} |