Provide pc specific lx_emul API

This commit contains:

* Minimal Linux kernel target: pc_linux
* Library to generate a Linux build directory, config, generated headers
* API depot package

The actual work was provided by Josef Soentgen.

Ref genodelabs/genode#4416
This commit is contained in:
Stefan Kalkowski 2022-02-11 14:52:13 +01:00 committed by Norman Feske
parent 33b038e8a7
commit e72f39b484
10 changed files with 517 additions and 0 deletions

View File

@ -0,0 +1,189 @@
DDE_LINUX_DIR := $(subst /src/include/lx_kit,,$(call select_from_repositories,src/include/lx_kit))
ifeq ($(filter-out $(SPECS),x86_32),)
SPEC_ARCH := x86_32
endif
ifeq ($(filter-out $(SPECS),x86_64),)
SPEC_ARCH := x86_64
endif
INC_DIR += $(PRG_DIR)/../..
SRC_C += dummies.c lx_emul.c
SRC_C += $(notdir $(wildcard $(PRG_DIR)/../../generated_dummies.c))
#
# Create symbol alias for jiffies, sharing the value of jiffies_64
#
LD_OPT += --defsym=jiffies=jiffies_64
#
# Lx_emul + Lx_kit definitions
#
SRC_CC += lx_emul/alloc.cc
SRC_CC += lx_emul/clock.cc
SRC_CC += lx_emul/debug.cc
SRC_CC += lx_emul/init.cc
SRC_CC += lx_emul/pci_init.cc
SRC_CC += lx_emul/io_mem.cc
SRC_CC += lx_emul/irq.cc
SRC_CC += lx_emul/log.cc
SRC_CC += lx_emul/page_virt.cc
SRC_CC += lx_emul/task.cc
SRC_CC += lx_emul/time.cc
SRC_CC += lx_emul/pci_config_space.cc
SRC_C += lx_emul/clocksource.c
SRC_C += lx_emul/spec/x86/irqchip.c
SRC_C += lx_emul/start.c
SRC_C += lx_emul/spec/x86/start.c
SRC_C += lx_emul/shadow/fs/exec.c
SRC_C += lx_emul/shadow/kernel/cpu.c
SRC_C += lx_emul/shadow/kernel/dma/mapping.c
SRC_C += lx_emul/shadow/kernel/exit.c
SRC_C += lx_emul/shadow/kernel/fork.c
SRC_C += lx_emul/shadow/kernel/irq/spurious.c
SRC_C += lx_emul/shadow/kernel/pid.c
SRC_C += lx_emul/shadow/kernel/printk/printk.c
SRC_C += lx_emul/shadow/kernel/rcu/tree.c
SRC_C += lx_emul/shadow/kernel/sched/core.c
SRC_C += lx_emul/shadow/kernel/sched/sched.c
SRC_C += lx_emul/shadow/kernel/softirq.c
SRC_C += lx_emul/shadow/lib/devres.c
SRC_C += lx_emul/shadow/lib/smp_processor_id.c
SRC_C += lx_emul/shadow/mm/memblock.c
SRC_C += lx_emul/shadow/mm/percpu.c
SRC_C += lx_emul/shadow/mm/slab_common.c
SRC_C += lx_emul/shadow/mm/slub.c
SRC_C += lx_emul/virt_to_page.c
SRC_CC += lx_kit/console.cc
SRC_CC += lx_kit/device.cc
SRC_CC += lx_kit/env.cc
SRC_CC += lx_kit/init.cc
SRC_CC += lx_kit/memory.cc
SRC_CC += lx_kit/scheduler.cc
SRC_CC += lx_kit/task.cc
SRC_CC += lx_kit/timeout.cc
SRC_S += lx_kit/spec/$(SPEC_ARCH)/setjmp.S
SRC_CC += lx_kit/spec/x86/platform.cc
INC_DIR += $(DDE_LINUX_DIR)/src/include/spec/x86/lx_kit
# determine location of lx_emul / lx_kit headers by querying lx_emul/init.h
_LX_EMUL_INIT_H := $(call select_from_repositories,src/include/lx_emul/init.h)
DDE_LINUX_SRC_INC_DIR := $(_LX_EMUL_INIT_H:/lx_emul/init.h=)
SHADOW_INC_DIR := $(addsuffix /lx_emul/shadow, $(DDE_LINUX_SRC_INC_DIR))
X86_SHADOW_INC_DIR := $(addsuffix /lx_emul/shadow, $(DDE_LINUX_SRC_INC_DIR)/spec/x86)
SPEC_SHADOW_INC_DIR := $(addsuffix /lx_emul/shadow, $(DDE_LINUX_SRC_INC_DIR)/spec/$(SPEC_ARCH))
INC_DIR += $(DDE_LINUX_SRC_INC_DIR)
INC_DIR += $(DDE_LINUX_SRC_INC_DIR)/spec/x86
INC_DIR += $(DDE_LINUX_SRC_INC_DIR)/spec/$(SPEC_ARCH)
INC_DIR += $(SHADOW_INC_DIR)
INC_DIR += $(X86_SHADOW_INC_DIR)
INC_DIR += $(SPEC_SHADOW_INC_DIR)
DDE_LINUX_SRC_LIB_DIR := $(DDE_LINUX_SRC_INC_DIR:/include=/lib)
vpath % $(DDE_LINUX_SRC_LIB_DIR)
#
# Linux kernel definitions
#
LIBS += pc_linux_generated
LX_SRC_DIR := $(call select_from_ports,linux)/src/linux
ifeq ($(wildcard $(LX_SRC_DIR)),)
LX_SRC_DIR := $(call select_from_repositories,src/linux)
endif
LX_GEN_DIR := $(LIB_CACHE_DIR)/pc_linux_generated
INC_DIR += $(LX_SRC_DIR)/arch/x86/include
INC_DIR += $(LX_GEN_DIR)/arch/x86/include/generated
INC_DIR += $(LX_SRC_DIR)/include
INC_DIR += $(LX_GEN_DIR)/include
INC_DIR += $(LX_SRC_DIR)/arch/x86/include/uapi
INC_DIR += $(LX_GEN_DIR)/arch/x86/include/generated/uapi
INC_DIR += $(LX_SRC_DIR)/include/uapi
INC_DIR += $(LX_GEN_DIR)/include/generated/uapi
CC_C_OPT += -std=gnu89 -include $(LX_SRC_DIR)/include/linux/kconfig.h
CC_C_OPT += -include $(LX_SRC_DIR)/include/linux/compiler_types.h
CC_C_OPT += -D__KERNEL__ -DCONFIG_CC_HAS_K_CONSTRAINT=1
CC_C_OPT += -DKASAN_SHADOW_SCALE_SHIFT=3
CC_C_OPT += -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs
CC_C_OPT += -Werror=implicit-function-declaration -Werror=implicit-int
CC_C_OPT += -Wno-format-security -Wno-psabi
CC_C_OPT += -Wno-frame-address -Wno-format-truncation -Wno-format-overflow
CC_C_OPT += -Wframe-larger-than=2048 -Wno-unused-but-set-variable -Wimplicit-fallthrough
CC_C_OPT += -Wno-unused-const-variable -Wdeclaration-after-statement -Wvla
CC_C_OPT += -Wno-pointer-sign -Wno-stringop-truncation -Wno-array-bounds -Wno-stringop-overflow
CC_C_OPT += -Wno-restrict -Wno-maybe-uninitialized -Werror=date-time
CC_C_OPT += -Werror=incompatible-pointer-types -Werror=designated-init
CC_C_OPT += -Wno-packed-not-aligned
CC_C_OPT += -Wno-discarded-qualifiers
CC_C_OPT += -Wno-format
LX_SRC = $(shell grep ".*\.c" $(PRG_DIR)/source.list)
SRC_S += $(shell grep ".*\.S" $(PRG_DIR)/source.list)
SRC_C += $(LX_SRC)
SRC_S += $(LX_ASM:$(LX_SRC_DIR)/%=%)
vpath %.c $(LX_SRC_DIR)
vpath %.S $(LX_SRC_DIR)
vpath %.S $(LX_GEN_DIR)
CUSTOM_TARGET_DEPS += $(PRG_DIR)/source.list
# Define per-compilation-unit CC_OPT defines needed by MODULE* macros in Linux
define CC_OPT_LX_RULES =
CC_OPT_$(1) = -DKBUILD_MODFILE='"$(1)"' -DKBUILD_BASENAME='"$(notdir $(1))"' -DKBUILD_MODNAME='"$(notdir $(1))"'
endef
$(foreach file,$(LX_SRC),$(eval $(call CC_OPT_LX_RULES,$(file:%.c=%))))
$(eval $(call CC_OPT_LX_RULES,generated_dummies))
$(eval $(call CC_OPT_LX_RULES,dummies))
# Handle specific source requirements
CC_OPT_drivers/usb/host/xhci-trace += -I$(LX_SRC_DIR)/drivers/usb/host
#
# Generate crc32table.h header
#
crc32table.h: gen_crc32table
./gen_crc32table > $@
lib/crc32.c: crc32table.h
gen_crc32table: $(LX_SRC_DIR)/lib/gen_crc32table.c
$(HOST_CC) -I$(LX_GEN_DIR)/include $< -o $@
#
# Force rebuild whenever shadow headers appear or change
#
# Shadow headers are not handled well by the regular dependency-file mechanism
# and ccache.
#
# As new appearing shadow headers (e.g., when switching branches) are not
# covered by .d files, no rebuild is issued for existing object files that
# actually depend on the just appeared header. Specifying all shadow headers
# as global dependencies forces the rebuild of all potentially affected object
# files in such a situation.
#
GLOBAL_DEPS += $(wildcard $(addsuffix /linux/*.h,$(SHADOW_INC_DIR))) \
$(wildcard $(addsuffix /asm/*.h,$(SHADOW_INC_DIR)))
GLOBAL_DEPS += $(wildcard $(addsuffix /linux/*.h,$(SPEC_SHADOW_INC_DIR))) \
$(wildcard $(addsuffix /asm/*.h,$(SPEC_SHADOW_INC_DIR)))

View File

@ -0,0 +1,30 @@
CUSTOM_TARGET_DEPS := kernel_build.phony
LX_DIR := $(call select_from_ports,linux)/src/linux
PWD := $(shell pwd)
LX_MK_ARGS = ARCH=$(LINUX_ARCH) CROSS_COMPILE=$(CROSS_DEV_PREFIX)
#
# Linux kernel configuration
#
# define 'LX_ENABLE' and 'LX_DISABLE'
include $(REP_DIR)/src/pc_linux/target.inc
# filter for make output of kernel build system
BUILD_OUTPUT_FILTER = 2>&1 | sed "s/^/ [Linux] /"
kernel_config.tag:
$(MSG_CONFIG)Linux
$(VERBOSE)$(MAKE) -C $(LX_DIR) O=$(PWD) $(LX_MK_ARGS) tinyconfig $(BUILD_OUTPUT_FILTER)
$(VERBOSE)$(LX_DIR)/scripts/config $(addprefix --enable ,$(LX_ENABLE))
$(VERBOSE)$(LX_DIR)/scripts/config $(addprefix --disable ,$(LX_DISABLE))
$(VERBOSE)$(MAKE) $(LX_MK_ARGS) olddefconfig $(BUILD_OUTPUT_FILTER)
$(VERBOSE)$(MAKE) $(LX_MK_ARGS) prepare $(BUILD_OUTPUT_FILTER)
$(VERBOSE)touch $@
# update Linux kernel config on makefile changes
kernel_config.tag: $(MAKEFILE_LIST)
kernel_build.phony: kernel_config.tag

View File

@ -0,0 +1 @@
# the a64_lx_emul libray exists only for the import file

View File

@ -0,0 +1,3 @@
LINUX_ARCH=x86
include $(REP_DIR)/lib/mk/pc_linux_generated.inc

View File

@ -0,0 +1,3 @@
LINUX_ARCH=x86_64
include $(REP_DIR)/lib/mk/pc_linux_generated.inc

View File

@ -0,0 +1,190 @@
#
# Content hosted in the dde_linux repository
#
MIRRORED_FROM_DDE_LINUX := src/lib/lx_emul \
src/lib/lx_kit \
src/include/lx_emul \
src/include/lx_user \
src/include/spec/x86 \
src/include/spec/x86_32 \
src/include/spec/x86_64 \
src/include/lx_kit
content: $(MIRRORED_FROM_DDE_LINUX)
$(MIRRORED_FROM_DDE_LINUX):
mkdir -p $(dir $@); cp -r $(GENODE_DIR)/repos/dde_linux/$@ $(dir $@)
#
# Content hosted in the pc repository
#
MIRRORED_FROM_REP_DIR := lib/mk/pc_linux_generated.inc \
lib/mk/pc_lx_emul.mk \
lib/mk/spec/x86_64/pc_linux_generated.mk \
lib/mk/spec/x86_32/pc_linux_generated.mk \
lib/import/import-pc_lx_emul.mk \
src/pc_linux/target.inc
content: $(MIRRORED_FROM_REP_DIR)
$(MIRRORED_FROM_REP_DIR):
$(mirror_from_rep_dir)
#
# Content from the Linux source tree
#
PORT_DIR := $(call port_dir,$(GENODE_DIR)/repos/dde_linux/ports/linux)
LX_REL_DIR := src/linux
LX_ABS_DIR := $(addsuffix /$(LX_REL_DIR),$(PORT_DIR))
# ingredients needed for creating a Linux build directory / generated headers
LX_FILES += Kbuild \
Makefile \
arch/x86/Makefile \
arch/x86/Makefile_32.cpu \
arch/x86/configs \
arch/x86/entry/syscalls/Makefile \
arch/x86/entry/syscalls/syscall_32.tbl \
arch/x86/entry/syscalls/syscall_64.tbl \
arch/x86/include/asm/Kbuild \
arch/x86/include/asm/atomic64_32.h \
arch/x86/include/asm/cmpxchg_32.h \
arch/x86/include/asm/string.h \
arch/x86/include/asm/string_32.h \
arch/x86/include/asm/string_64.h \
arch/x86/include/uapi/asm/Kbuild \
arch/x86/include/uapi/asm/posix_types.h \
arch/x86/include/uapi/asm/posix_types_32.h \
arch/x86/include/uapi/asm/posix_types_64.h \
arch/x86/tools/Makefile \
arch/x86/tools/relocs.c \
arch/x86/tools/relocs.h \
arch/x86/tools/relocs_32.c \
arch/x86/tools/relocs_64.c \
arch/x86/tools/relocs_common.c \
include/asm-generic/bitops/fls64.h \
include/asm-generic/Kbuild \
include/linux/compiler-version.h \
include/linux/kbuild.h \
include/linux/license.h \
include/uapi/Kbuild \
include/uapi/asm-generic/Kbuild \
kernel/configs/tiny-base.config \
kernel/configs/tiny.config \
scripts/Kbuild.include \
scripts/Makefile \
scripts/Makefile.asm-generic \
scripts/Makefile.build \
scripts/Makefile.compiler \
scripts/Makefile.extrawarn \
scripts/Makefile.host \
scripts/Makefile.lib \
scripts/as-version.sh \
scripts/atomic/check-atomics.sh \
scripts/basic/Makefile \
scripts/basic/fixdep.c \
scripts/cc-version.sh \
scripts/checksyscalls.sh \
scripts/config \
scripts/dtc \
scripts/gcc-goto.sh \
scripts/kconfig/merge_config.sh \
scripts/ld-version.sh \
scripts/min-tool-version.sh \
scripts/mod \
scripts/remove-stale-files \
scripts/setlocalversion \
scripts/sorttable.c \
scripts/sorttable.h \
scripts/subarch.include \
scripts/syscallhdr.sh \
scripts/syscalltbl.sh \
tools/include/tools \
tools/objtool
LX_SCRIPTS_KCONFIG_FILES := $(notdir $(wildcard $(LX_ABS_DIR)/scripts/kconfig/*.c)) \
$(notdir $(wildcard $(LX_ABS_DIR)/scripts/kconfig/*.h)) \
Makefile lexer.l parser.y
LX_FILES += $(addprefix scripts/kconfig/,$(LX_SCRIPTS_KCONFIG_FILES)) \
LX_FILES += $(shell cd $(LX_ABS_DIR); find -name "Kconfig*" -printf "%P\n")
# needed for generated/asm-offsets.h
LX_FILES += arch/x86/include/asm/boot.h \
arch/x86/include/asm/cpufeature.h \
arch/x86/include/asm/current.h \
arch/x86/include/asm/fixmap.h \
arch/x86/include/asm/fpu/api.h \
arch/x86/include/asm/fpu/xstate.h \
arch/x86/include/asm/ia32.h \
arch/x86/include/asm/irqflags.h \
arch/x86/include/asm/nospec-branch.h \
arch/x86/include/asm/page.h \
arch/x86/include/asm/page_32.h \
arch/x86/include/asm/page_32_types.h \
arch/x86/include/asm/pgtable.h \
arch/x86/include/asm/pgtable-2level.h \
arch/x86/include/asm/pgtable-2level_types.h \
arch/x86/include/asm/pgtable_32.h \
arch/x86/include/asm/pgtable_32_areas.h \
arch/x86/include/asm/pgtable_32_types.h \
arch/x86/include/asm/pgtable_64.h \
arch/x86/include/asm/pgtable-invert.h \
arch/x86/include/asm/pkru.h \
arch/x86/include/asm/sigframe.h \
arch/x86/include/asm/suspend.h \
arch/x86/include/asm/suspend_32.h \
arch/x86/include/asm/suspend_64.h \
arch/x86/include/asm/sync_core.h \
arch/x86/include/asm/uaccess_32.h \
arch/x86/include/asm/user_32.h \
arch/x86/include/uapi/asm/ucontext.h \
arch/x86/kernel/asm-offsets.c \
arch/x86/kernel/asm-offsets_32.c \
arch/x86/kernel/asm-offsets_64.c \
include/acpi \
include/asm-generic/current.h \
include/asm-generic/fixmap.h \
include/asm-generic/memory_model.h \
include/asm-generic/pgtable_uffd.h \
include/asm-generic/pgtable-nopmd.h \
include/asm-generic/pgtable-nopud.h \
include/asm-generic/qspinlock.h \
include/linux/arm-smccc.h \
include/linux/arm_sdei.h \
include/linux/cper.h \
include/linux/crypto.h \
include/linux/efi.h \
include/linux/pgtable.h \
include/linux/pstore.h \
include/uapi/asm-generic/ucontext.h \
include/uapi/linux/arm_sdei.h \
kernel/bounds.c \
kernel/time/timeconst.bc
# needed for gen_crc32table
LX_FILES += lib/gen_crc32table.c \
lib/crc32.c
content: src/linux/include/linux/kvm_host.h
src/linux/include/linux/kvm_host.h: # cut dependencies from kvm via dummy header
mkdir -p $(dir $@)
touch $@
# add content listed in the repository's source.list or dep.list files
LX_FILE_LISTS := $(shell find -H $(REP_DIR) -name dep.list -or -name source.list)
LX_FILES += $(shell cat $(LX_FILE_LISTS))
LX_FILES := $(sort $(LX_FILES))
MIRRORED_FROM_PORT_DIR += $(addprefix $(LX_REL_DIR)/,$(LX_FILES))
content: $(MIRRORED_FROM_PORT_DIR)
$(MIRRORED_FROM_PORT_DIR):
mkdir -p $(dir $@)
cp -r $(addprefix $(PORT_DIR)/,$@) $@
content: LICENSE
LICENSE:
cp $(PORT_DIR)/src/linux/COPYING $@

View File

@ -0,0 +1 @@
2022-02-11-j 7496b6d0afc868c1d7de4be39741f850e82dd4e4

View File

@ -0,0 +1,26 @@
#
# Linux kernel configuration
#
# kernel fundamentals
LX_ENABLE += TTY SERIAL_EARLYCON SERIAL_OF_PLATFORM PRINTK HAS_IOMEM
# initrd support
LX_ENABLE += BINFMT_ELF BINFMT_SCRIPT BLK_DEV_INITRD
# UART device
LX_ENABLE += SERIAL_8250 SERIAL_8250_CONSOLE
# PCI support
LX_ENABLE += PCI
# USB host-controller support
LX_ENABLE += USB_SUPPORT USB USB_ARCH_HAS_HCD USB_XHCI_HCD USB_EHCI_HCD USB_OHCI_HCD
# mandatory fs support
LX_ENABLE += PROC_FS SYSFS
LX_DISABLE += CC_HAS_ASM_GOTO
# slim down kernel by removing superfluous drivers
LX_DISABLE += HID HID_GENERIC USB_HID VGA_CONSOLE DUMMY_CONSOLE NLS VGA_ARB DEBUG_LIST

View File

@ -0,0 +1,37 @@
TARGET := x86_32_pc_linux
REQUIRES := x86_32
CUSTOM_TARGET_DEPS := kernel_build.phony
LX_DIR := $(call select_from_ports,linux)/src/linux
PWD := $(shell pwd)
LX_MK_ARGS = ARCH=x86 CROSS_COMPILE=$(CROSS_DEV_PREFIX)
#
# Linux kernel configuration
#
# Start with 'make tinyconfig', enable/disable options via 'scripts/config',
# and resolve config dependencies via 'make olddefconfig'.
#
# define 'LX_ENABLE' and 'LX_DISABLE'
include $(REP_DIR)/src/pc_linux/target.inc
# filter for make output of kernel build system
BUILD_OUTPUT_FILTER = 2>&1 | sed "s/^/ [Linux] /"
kernel_config.tag:
$(MSG_CONFIG)Linux
$(VERBOSE)$(MAKE) -C $(LX_DIR) O=$(PWD) $(LX_MK_ARGS) tinyconfig $(BUILD_OUTPUT_FILTER)
$(VERBOSE)$(LX_DIR)/scripts/config --file $(PWD)/.config $(addprefix --enable ,$(LX_ENABLE))
$(VERBOSE)$(LX_DIR)/scripts/config --file $(PWD)/.config $(addprefix --disable ,$(LX_DISABLE))
$(VERBOSE)$(MAKE) $(LX_MK_ARGS) olddefconfig $(BUILD_OUTPUT_FILTER)
$(VERBOSE)touch $@
# update Linux kernel config on makefile changes
kernel_config.tag: $(MAKEFILE_LIST)
kernel_build.phony: kernel_config.tag
$(MSG_BUILD)Linux
$(VERBOSE)$(MAKE) $(LX_MK_ARGS) bzImage $(BUILD_OUTPUT_FILTER)

View File

@ -0,0 +1,37 @@
TARGET := x86_64_pc_linux
REQUIRES := x86_64
CUSTOM_TARGET_DEPS := kernel_build.phony
LX_DIR := $(call select_from_ports,linux)/src/linux
PWD := $(shell pwd)
LX_MK_ARGS = ARCH=x86_64 CROSS_COMPILE=$(CROSS_DEV_PREFIX)
#
# Linux kernel configuration
#
# Start with 'make tinyconfig', enable/disable options via 'scripts/config',
# and resolve config dependencies via 'make olddefconfig'.
#
# define 'LX_ENABLE' and 'LX_DISABLE'
include $(REP_DIR)/src/pc_linux/target.inc
# filter for make output of kernel build system
BUILD_OUTPUT_FILTER = 2>&1 | sed "s/^/ [Linux] /"
kernel_config.tag:
$(MSG_CONFIG)Linux
$(VERBOSE)$(MAKE) -C $(LX_DIR) O=$(PWD) $(LX_MK_ARGS) tinyconfig $(BUILD_OUTPUT_FILTER)
$(VERBOSE)$(LX_DIR)/scripts/config --file $(PWD)/.config $(addprefix --enable ,$(LX_ENABLE))
$(VERBOSE)$(LX_DIR)/scripts/config --file $(PWD)/.config $(addprefix --disable ,$(LX_DISABLE))
$(VERBOSE)$(MAKE) $(LX_MK_ARGS) olddefconfig $(BUILD_OUTPUT_FILTER)
$(VERBOSE)touch $@
# update Linux kernel config on makefile changes
kernel_config.tag: $(MAKEFILE_LIST)
kernel_build.phony: kernel_config.tag
$(MSG_BUILD)Linux
$(VERBOSE)$(MAKE) $(LX_MK_ARGS) bzImage $(BUILD_OUTPUT_FILTER)