From 673106711664c4a4976537078b9b21177bf88c5d Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Tue, 5 Apr 2022 14:34:54 +0200 Subject: [PATCH] lx_emul: add basic ARM 32-bit support genodelabs/genode#4499 --- .../src/include/lx_emul/shadow/asm/irqflags.h | 44 ------------- .../lx_emul/shadow/linux/compiler-gcc.h | 0 .../spec/arm/lx_emul/shadow/asm/irqflags.h | 31 ++++++++++ .../spec/arm/lx_emul/shadow/asm/memory.h | 51 +++++++++++++++ .../spec/arm/lx_emul/shadow/asm/page.h | 62 +++++++++++++++++++ .../spec/arm/lx_emul/shadow/asm/pgtable.h | 42 +++++++++++++ .../spec/arm_64/lx_emul/shadow/asm/irqflags.h | 32 ++++++++++ .../spec/x86/lx_emul/shadow/asm/irqflags.h | 32 ++++++++++ .../x86/lx_emul/shadow/linux/compiler-gcc.h | 28 --------- .../src/lib/lx_emul/shadow/kernel/fork.c | 3 +- .../src/lib/lx_emul/shadow/mm/page_alloc.c | 2 + .../dde_linux/src/lib/lx_emul/virt_to_page.c | 1 + 12 files changed, 255 insertions(+), 73 deletions(-) delete mode 100644 repos/dde_linux/src/include/lx_emul/shadow/asm/irqflags.h rename repos/dde_linux/src/include/{spec/arm_64 => }/lx_emul/shadow/linux/compiler-gcc.h (100%) create mode 100644 repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/irqflags.h create mode 100644 repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/memory.h create mode 100644 repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/page.h create mode 100644 repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/pgtable.h create mode 100644 repos/dde_linux/src/include/spec/arm_64/lx_emul/shadow/asm/irqflags.h create mode 100644 repos/dde_linux/src/include/spec/x86/lx_emul/shadow/asm/irqflags.h delete mode 100644 repos/dde_linux/src/include/spec/x86/lx_emul/shadow/linux/compiler-gcc.h diff --git a/repos/dde_linux/src/include/lx_emul/shadow/asm/irqflags.h b/repos/dde_linux/src/include/lx_emul/shadow/asm/irqflags.h deleted file mode 100644 index 51440df6b5..0000000000 --- a/repos/dde_linux/src/include/lx_emul/shadow/asm/irqflags.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * \brief Shadows Linux kernel asm/irqflags.h - * \author Stefan Kalkowski - * \date 2021-04-14 - */ - -/* - * Copyright (C) 2021 Genode Labs GmbH - * - * This file is distributed under the terms of the GNU General Public License - * version 2. - */ - -#ifndef __ASM_IRQFLAGS_H -#define __ASM_IRQFLAGS_H - -static inline void arch_local_irq_enable(void) -{ -} - -static inline void arch_local_irq_disable(void) -{ -} - -static inline unsigned long arch_local_save_flags(void) -{ - return 1; -} - -static inline int arch_irqs_disabled_flags(unsigned long flags) -{ - return flags; -} - -static inline unsigned long arch_local_irq_save(void) -{ - return 1; -} - -static inline void arch_local_irq_restore(unsigned long flags) -{ -} - -#endif diff --git a/repos/dde_linux/src/include/spec/arm_64/lx_emul/shadow/linux/compiler-gcc.h b/repos/dde_linux/src/include/lx_emul/shadow/linux/compiler-gcc.h similarity index 100% rename from repos/dde_linux/src/include/spec/arm_64/lx_emul/shadow/linux/compiler-gcc.h rename to repos/dde_linux/src/include/lx_emul/shadow/linux/compiler-gcc.h diff --git a/repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/irqflags.h b/repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/irqflags.h new file mode 100644 index 0000000000..c89f318fdb --- /dev/null +++ b/repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/irqflags.h @@ -0,0 +1,31 @@ +/* + * \brief Shadows Linux kernel asm/irqflags.h + * \author Stefan Kalkowski + * \date 2021-04-14 + */ + +/* + * Copyright (C) 2021 Genode Labs GmbH + * + * This file is distributed under the terms of the GNU General Public License + * version 2. + */ + +#ifndef __ASM_IRQFLAGS_H +#define __ASM_IRQFLAGS_H + +static inline unsigned long arch_local_save_flags(void) { + return 1; } + +static inline void arch_local_irq_restore(unsigned long flags) { } + +#define arch_irqs_disabled_flags arch_irqs_disabled_flags +static inline int arch_irqs_disabled_flags(unsigned long flags) { + return 1; } + +#define local_fiq_enable() ({}) +#define local_fiq_disable() ({}) + +#include + +#endif diff --git a/repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/memory.h b/repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/memory.h new file mode 100644 index 0000000000..039aa72dee --- /dev/null +++ b/repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/memory.h @@ -0,0 +1,51 @@ +/* + * \brief Shadows Linux kernel arch/arm/include/asm/memory.h + * \author Stefan Kalkowski + * \date 2022-03-10 + */ + +/* + * Copyright (C) 2022 Genode Labs GmbH + * + * This file is distributed under the terms of the GNU General Public License + * version 2. + */ + +#ifndef __ASM_MEMORY_H +#define __ASM_MEMORY_H + +#include +#include +#include +#include + +#ifndef __ASSEMBLY__ +#include +#include + +#define PAGE_OFFSET (0) + +#define TASK_SIZE (UL(CONFIG_PAGE_OFFSET) - UL(SZ_16M)) +#define TASK_SIZE_26 (UL(1) << 26) +#define TASK_UNMAPPED_BASE ALIGN(TASK_SIZE / 3, SZ_16M) + +#define __va(x) ( lx_emul_trace_and_stop("__va"), (void *)0 ) +#define __pa(v) lx_emul_mem_dma_addr((void *)(v)) + +#define virt_addr_valid(kaddr) (kaddr != NULL) + +#ifndef __virt_to_bus +#define __virt_to_bus __pa +#define __bus_to_virt __va +#define __pfn_to_bus(x) __pfn_to_phys(x) +#define __bus_to_pfn(x) __phys_to_pfn(x) +#endif + +#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) + + +#endif /* __ASSEMBLY__ */ + +#include + +#endif /* __ASM_MEMORY_H */ diff --git a/repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/page.h b/repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/page.h new file mode 100644 index 0000000000..8106e4ea3e --- /dev/null +++ b/repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/page.h @@ -0,0 +1,62 @@ +/* + * \brief Shadows Linux kernel arch/arm/include/asm/page.h + * \author Stefan Kalkowski + * \date 2022-03-10 + */ + +/* + * Copyright (C) 2022 Genode Labs GmbH + * + * This file is distributed under the terms of the GNU General Public License + * version 2. + */ + +#ifndef __ASMARM_PAGE_H +#define __ASMARM_PAGE_H + +#define PAGE_SHIFT 12 +#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT) +#define PAGE_MASK (~((1 << PAGE_SHIFT) - 1)) + +#ifndef __ASSEMBLY__ + +#include +#include +#include + +/* + * The 'virtual' member of 'struct page' is needed by 'lx_emul_virt_to_phys' + * and 'page_to_virt'. + */ +#define WANT_PAGE_VIRTUAL + +#ifdef CONFIG_ARM_LPAE +#define PTRS_PER_PMD 512 +#else +#define PTRS_PER_PMD 1 +#endif + +#define PMD_SHIFT 21 +#define PMD_SIZE (1UL << PMD_SHIFT) +#define PMD_MASK (~(PMD_SIZE-1)) +#define PTRS_PER_PTE 512 + +int pud_none(pud_t pud); + +typedef struct page *pgtable_t; + +#define page_to_phys(p) __pa((p)->virtual) +#define page_to_virt(p) ((p)->virtual) + +static inline struct page *virt_to_page(void const *v) { return lx_emul_virt_to_pages(v, 1U); } + +/* needed by mm/internal.h */ +#define pfn_valid(pfn) (pfn != 0UL) + +#include + +#endif /* !__ASSEMBLY__ */ + +#include + +#endif /* __ASMARM_PAGE_H */ diff --git a/repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/pgtable.h b/repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/pgtable.h new file mode 100644 index 0000000000..0eae2a7ca7 --- /dev/null +++ b/repos/dde_linux/src/include/spec/arm/lx_emul/shadow/asm/pgtable.h @@ -0,0 +1,42 @@ +/* + * \brief Shadows Linux kernel arch/arm/include/asm/pgtable.h + * \author Stefan Kalkowski + * \date 2022-03-10 + */ + +/* + * Copyright (C) 2022 Genode Labs GmbH + * + * This file is distributed under the terms of the GNU General Public License + * version 2. + */ + +#ifndef __ASM_PGTABLE_H +#define __ASM_PGTABLE_H + +#include +#include +#include +#include +#include + +#ifndef __ASSEMBLY__ + +pte_t pte_mkwrite(pte_t pte); + +int pte_none(pte_t pte); +int pte_present(pte_t pte); +int pte_swp_soft_dirty(pte_t pte); +int pte_dirty(pte_t ptr); +int pte_write(pte_t ptr); + +#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) + +#define __swp_type(x) ( lx_emul_trace_and_stop(__func__), 0 ) +#define __swp_offset(x) ( lx_emul_trace_and_stop(__func__), 0 ) +#define __swp_entry(type, offset) ( lx_emul_trace_and_stop(__func__), (swp_entry_t) { 0 } ) +#define __swp_entry_to_pte(swp) ((pte_t) { (swp).val }) + +#endif /* !__ASSEMBLY__ */ + +#endif /* __ASM_PGTABLE_H */ diff --git a/repos/dde_linux/src/include/spec/arm_64/lx_emul/shadow/asm/irqflags.h b/repos/dde_linux/src/include/spec/arm_64/lx_emul/shadow/asm/irqflags.h new file mode 100644 index 0000000000..371143432f --- /dev/null +++ b/repos/dde_linux/src/include/spec/arm_64/lx_emul/shadow/asm/irqflags.h @@ -0,0 +1,32 @@ +/* + * \brief Shadows Linux kernel asm/irqflags.h + * \author Stefan Kalkowski + * \date 2021-04-14 + */ + +/* + * Copyright (C) 2021 Genode Labs GmbH + * + * This file is distributed under the terms of the GNU General Public License + * version 2. + */ + +#ifndef __ASM_IRQFLAGS_H +#define __ASM_IRQFLAGS_H + +static inline void arch_local_irq_enable(void) { } + +static inline void arch_local_irq_disable(void) { } + +static inline unsigned long arch_local_save_flags(void) { + return 1; } + +static inline int arch_irqs_disabled_flags(unsigned long flags) { + return flags; } + +static inline unsigned long arch_local_irq_save(void) { + return 1; } + +static inline void arch_local_irq_restore(unsigned long flags) { } + +#endif diff --git a/repos/dde_linux/src/include/spec/x86/lx_emul/shadow/asm/irqflags.h b/repos/dde_linux/src/include/spec/x86/lx_emul/shadow/asm/irqflags.h new file mode 100644 index 0000000000..371143432f --- /dev/null +++ b/repos/dde_linux/src/include/spec/x86/lx_emul/shadow/asm/irqflags.h @@ -0,0 +1,32 @@ +/* + * \brief Shadows Linux kernel asm/irqflags.h + * \author Stefan Kalkowski + * \date 2021-04-14 + */ + +/* + * Copyright (C) 2021 Genode Labs GmbH + * + * This file is distributed under the terms of the GNU General Public License + * version 2. + */ + +#ifndef __ASM_IRQFLAGS_H +#define __ASM_IRQFLAGS_H + +static inline void arch_local_irq_enable(void) { } + +static inline void arch_local_irq_disable(void) { } + +static inline unsigned long arch_local_save_flags(void) { + return 1; } + +static inline int arch_irqs_disabled_flags(unsigned long flags) { + return flags; } + +static inline unsigned long arch_local_irq_save(void) { + return 1; } + +static inline void arch_local_irq_restore(unsigned long flags) { } + +#endif diff --git a/repos/dde_linux/src/include/spec/x86/lx_emul/shadow/linux/compiler-gcc.h b/repos/dde_linux/src/include/spec/x86/lx_emul/shadow/linux/compiler-gcc.h deleted file mode 100644 index 486cf53d46..0000000000 --- a/repos/dde_linux/src/include/spec/x86/lx_emul/shadow/linux/compiler-gcc.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * \brief Shadow copy of linux/compiler-gcc.h - * \author Stefan Kalkowski - * \date 2021-03-17 - */ - -/* - * Copyright (C) 2021 Genode Labs GmbH - * - * This file is distributed under the terms of the GNU General Public License - * version 2. - */ - -#ifndef _LX_EMUL__SHADOW__LINUX__COMPILER_GCC_H_ -#define _LX_EMUL__SHADOW__LINUX__COMPILER_GCC_H_ - -#include_next - -/** - * We have to re-define `asm_volatile_goto`, because the original function - * uses `asm goto(...)`, which is a problem when building PIC code. - */ -#ifdef asm_volatile_goto -#undef asm_volatile_goto -#define asm_volatile_goto(x...) asm volatile("invalid use of asm_volatile_goto") -#endif - -#endif /* _LX_EMUL__SHADOW__LINUX__COMPILER_GCC_H_ */ diff --git a/repos/dde_linux/src/lib/lx_emul/shadow/kernel/fork.c b/repos/dde_linux/src/lib/lx_emul/shadow/kernel/fork.c index 58ad199049..26c7456eff 100644 --- a/repos/dde_linux/src/lib/lx_emul/shadow/kernel/fork.c +++ b/repos/dde_linux/src/lib/lx_emul/shadow/kernel/fork.c @@ -77,9 +77,10 @@ pid_t kernel_thread(int (* fn)(void *),void * arg,unsigned long flags) .signal = signal, }; -#ifndef CONFIG_X86 +#ifdef CONFIG_ARM_64 task->thread_info.preempt_count = 0; #endif + task->stack = kmalloc(sizeof(struct thread_info), THREADINFO_GFP); lx_emul_task_create(task, "kthread", task->pid, fn, arg); return task->pid; diff --git a/repos/dde_linux/src/lib/lx_emul/shadow/mm/page_alloc.c b/repos/dde_linux/src/lib/lx_emul/shadow/mm/page_alloc.c index a18697bfcb..2e6c2a6f9c 100644 --- a/repos/dde_linux/src/lib/lx_emul/shadow/mm/page_alloc.c +++ b/repos/dde_linux/src/lib/lx_emul/shadow/mm/page_alloc.c @@ -13,6 +13,8 @@ #include #include +#include +#include #include unsigned long __alloc_pages_bulk(gfp_t gfp,int preferred_nid, diff --git a/repos/dde_linux/src/lib/lx_emul/virt_to_page.c b/repos/dde_linux/src/lib/lx_emul/virt_to_page.c index 3e0e50b620..2c8cca1052 100644 --- a/repos/dde_linux/src/lib/lx_emul/virt_to_page.c +++ b/repos/dde_linux/src/lib/lx_emul/virt_to_page.c @@ -13,6 +13,7 @@ #include #include +#include #include