lx_emul: add basic ARM 32-bit support

genodelabs/genode#4499
This commit is contained in:
Stefan Kalkowski 2022-04-05 14:34:54 +02:00 committed by Christian Helmuth
parent 19574f7897
commit 6731067116
12 changed files with 255 additions and 73 deletions

View File

@ -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

View File

@ -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 <asm-generic/irqflags.h>
#endif

View File

@ -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 <linux/compiler.h>
#include <linux/const.h>
#include <linux/types.h>
#include <linux/sizes.h>
#ifndef __ASSEMBLY__
#include <lx_emul/debug.h>
#include <lx_emul/alloc.h>
#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 <asm-generic/memory_model.h>
#endif /* __ASM_MEMORY_H */

View File

@ -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 <lx_emul/page_virt.h>
#include <asm/page-nommu.h>
#include <asm-generic/pgtable-nopud.h>
/*
* 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 <asm/memory.h>
#endif /* !__ASSEMBLY__ */
#include <asm-generic/getorder.h>
#endif /* __ASMARM_PAGE_H */

View File

@ -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 <linux/const.h>
#include <asm/proc-fns.h>
#include <asm-generic/pgtable-nopud.h>
#include <asm-generic/pgtable_uffd.h>
#include <asm/pgtable-nommu.h>
#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 */

View File

@ -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

View File

@ -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

View File

@ -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 <linux/compiler-gcc.h>
/**
* 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_ */

View File

@ -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;

View File

@ -13,6 +13,8 @@
#include <linux/gfp.h>
#include <linux/version.h>
#include <lx_emul/alloc.h>
#include <lx_emul/debug.h>
#include <lx_emul/page_virt.h>
unsigned long __alloc_pages_bulk(gfp_t gfp,int preferred_nid,

View File

@ -13,6 +13,7 @@
#include <linux/slab.h>
#include <linux/page_ref.h>
#include <lx_emul/debug.h>
#include <lx_emul/page_virt.h>