Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arm64 kernelmode #277

Merged
merged 24 commits into from
Sep 12, 2024
Merged

Arm64 kernelmode #277

merged 24 commits into from
Sep 12, 2024

Commits on Sep 5, 2024

  1. arm64_sync_exc: Use temporaries x9/x10 instead of x0/x1

    Why? Because this allows optimizing the user system call path in such
    a way that the parameter registers don't have to be read from the saved
    integer register context when the system call is executed.
    pussuw committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    f54ddc7 View commit details
    Browse the repository at this point in the history
  2. arm64/barriers.h: Generalize barrier macros

    Make it possible to define arguments for barriers
    pussuw committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    9f6c2f9 View commit details
    Browse the repository at this point in the history
  3. arm64: Initial implementation of CONFIG_BUILD_KERNEL

    This is the initial version for kernel mode build on the arm64 platform.
    It works much in the same way as the risc-v implementation so any
    highlights can be read from there.
    
    Features that have been tested working:
    - Creating address environments
    - Loading init (nsh) from elf file
    - Booting to nsh
    - Starting other processes from nsh
    - ostest runs to completion
    
    Features that are not tested / do not work:
    - SHM / shared memory support
    - Kernel memory mapping (MM_KMAP)
    - fork/vfork
    
    An example qemu target is provided as a separate patch:
    tools/configure.sh qemu-armv8a:knsh
    pussuw committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    097f8b2 View commit details
    Browse the repository at this point in the history
  4. arm64/qemu: Add knsh target for armv8a qemu board

    This adds a qemu test target for testing kernel mode with arm64
    pussuw committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    ea57681 View commit details
    Browse the repository at this point in the history
  5. imx9_usdhc.c: Fix build error when CONFIG_ARM64_DCACHE_DISABLE=y

    priv->rxbuffer does not exist when CONFIG_ARM64_DCACHE_DISABLE=y so
    references to it will create a build error -> flag / remove accesses
    to it.
    pussuw committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    f41582a View commit details
    Browse the repository at this point in the history
  6. arm64/imx9: Force 64-bit ELF format

    The format is always 64-bits
    pussuw committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    b129c9c View commit details
    Browse the repository at this point in the history
  7. arm64_checkstack.c: Fix traversing of user stack when ARCH_ADDRENV=Y

    Need to instantiate the correct address environment when reading from
    user stack, otherwise the result is very likely a crash
    pussuw committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    495453a View commit details
    Browse the repository at this point in the history
  8. arch/arm64: Move ELF_64BIT selection to arch/Kconfig

    Unify the elf file format for the whole arm64 architecture
    pussuw committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    7d75861 View commit details
    Browse the repository at this point in the history
  9. arch/arm64: make sure regs_context is aligned to 16

    Signed-off-by: Xu Xingliang <[email protected]>
    XuNeo authored and pussuw committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    a2fcbe1 View commit details
    Browse the repository at this point in the history
  10. arch/arm64: add DSB ISB where necessary

    Signed-off-by: Xu Xingliang <[email protected]>
    XuNeo authored and pussuw committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    7c5ca60 View commit details
    Browse the repository at this point in the history
  11. arm64_mmu: Add data synchronization barrier after page tables are wri…

    …tten
    
    The page tables must be committed to system memory before we can proceed
    enabling the MMU. ISB() is not enough to do this.
    pussuw committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    2d7bb51 View commit details
    Browse the repository at this point in the history
  12. [REVERTME] arm64_addrenc.c: Add more heap, if TLS_ALIGNED is set

    The TLS alignment requires more room in the stack, which means more
    _initial_ heap is required to accomodate the stack.
    
    Why 2x TLS_MAXSTACK ? No idea. This is a temporary fix, like the +1 page
    extra above.
    pussuw committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    5b6c5fc View commit details
    Browse the repository at this point in the history

Commits on Sep 11, 2024

  1. arm64_vector_table.S: Remove unnecessary instruction

    The expression "sub    x0,  x0, #8 * XCPTCONTEXT_GP_REGS" is void,
    as the next instruction overwrites x0 anyway.
    pussuw committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    ddff6a6 View commit details
    Browse the repository at this point in the history
  2. arm64_addrenv.c: Flush kernel page table copy to user mappings

    Make sure the user L1 page is updated to system memory when the kernel
    mappings are copied.
    
    Also, flush the I-cache when switching address environments.
    pussuw committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    e8145dd View commit details
    Browse the repository at this point in the history
  3. arm64_mmu: Do not set accessed-flag for table descriptors

    The 12:0 bits in table descriptors are RES0 and AF is the 10th bit, so
    it is not valid to set it in this case.
    
    Fix this by moving AF to the common MMU_MT_NORMAL_FLAGS field
    pussuw committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    0f74990 View commit details
    Browse the repository at this point in the history
  4. arm64_mmu: Fix TLBI instruction format

    The vaddr field in TLBI means: Bits[55:12] of the virtual address to match.
    This basically means the page offset of the virtual address, so the input
    vaddr must be shifted to the page offset.
    
    Reference TLBI VALE1IS register description from ARMv8-A reference manual.
    pussuw committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    cc148b0 View commit details
    Browse the repository at this point in the history
  5. arm64_mmu.c: Fix kernel L1 page table size

    The kernel L1 page table must be at least 1 page
    pussuw committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    8df8ed3 View commit details
    Browse the repository at this point in the history
  6. arm64_mmu.h: Change ordering of access flags for user data

    This makes it more readable, no functional changes
    pussuw committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    79a8c60 View commit details
    Browse the repository at this point in the history
  7. arm64_addrenv_pgmap.c: Revoke user execution access to kernel mmap'd …

    …pages
    
    Otherwise, user can run code from there
    pussuw committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    77f0337 View commit details
    Browse the repository at this point in the history
  8. arm64_syscall.c: Don't need to set register context during syscall

    The register context is not needed, the original idea was to provide
    the user stack pointer for signal handler delivery, but the user stack
    can be obtained via sp_el0 so the context registers are not needed.
    
    SP0 is not stored upon exception entry anyways, so this code is just
    completely redundant and wrong.
    pussuw committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    914004a View commit details
    Browse the repository at this point in the history
  9. arm64/crt0.c: Fix stack alignment when executing signal trampoline

    The stack alignment requirement is 16-bytes, not 8-bytes.
    pussuw committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    46a11c7 View commit details
    Browse the repository at this point in the history
  10. arm64/irq: Add mask for DAIF and SPSR DAIF bits

    Use them for critical section handling, removes a bit of copy&pasted
    code behind CONFIG_ARM64_DECODEFIQ flag
    pussuw committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    648c25d View commit details
    Browse the repository at this point in the history
  11. arm64/syscall: (Re-)enable interrupts only if they were previously en…

    …abled
    
    Don't change the CPU state unexpectedly
    pussuw committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    a6b43e6 View commit details
    Browse the repository at this point in the history
  12. arm64/task/pthread_start: Fix rare issue with context register location

    There is a tiny possibility that when a process is started a trap is
    taken which causes a context switch. This moves the kernel stack
    unexpectedly and the task start logic no longer works.
    
    Fix this by recording the initial context location, and use that to
    trampoline into the user process with interrupts disabled. This ensures
    the context stays intact AND the kernel stack is fully unwound before
    the user process starts.
    pussuw committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    33c1cdb View commit details
    Browse the repository at this point in the history