Changeset 3fcea34 in mainline for kernel/arch/arm64/src/arm64.c


Ignore:
Timestamp:
2024-09-20T12:16:28Z (5 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
d3109ff
Parents:
2cf8f994
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-09-20 11:42:13)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-09-20 12:16:28)
Message:

Simplify the SYS_THREAD_CREATE syscall interface

Removed the beefy uarg structure. Instead, the syscall gets two
parameters: %pc (program counter) and %sp (stack pointer). It starts
a thread with those values in corresponding registers, with no other
fuss whatsoever.

libc initializes threads by storing any other needed arguments on
the stack and retrieving them in thread_entry. Importantly, this
includes the address of the
thread_main function which is now
called indirectly to fix dynamic linking issues on some archs.

There's a bit of weirdness on SPARC and IA-64, because of their
stacked register handling. The current solution is that we require
some space *above* the stack pointer to be available for those
architectures. I think for SPARC, it can be made more normal.

For the remaining ones, we can (probably) just set the initial
%sp to the top edge of the stack. There's some lingering offsets
on some archs just because I didn't want to accidentally break
anything. The initial thread bringup should be functionally
unchanged from the previous state, and no binaries are currently
multithreaded except thread1 test, so there should be minimal
risk of breakage. Naturally, I tested all available emulator
builds, save for msim.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/arm64/src/arm64.c

    r2cf8f994 r3fcea34  
    146146}
    147147
     148uintptr_t arch_get_initial_sp(uintptr_t stack_base, uintptr_t stack_size)
     149{
     150        return stack_base + stack_size;
     151}
     152
    148153/** Change processor mode.
    149154 *
    150155 * @param kernel_uarg Userspace settings (entry point, stack, ...).
    151156 */
    152 void userspace(uspace_arg_t *kernel_uarg)
     157void userspace(uintptr_t pc, uintptr_t sp)
    153158{
    154159        /* Prepare return to EL0. */
     
    157162
    158163        /* Set program entry. */
    159         ELR_EL1_write(kernel_uarg->uspace_entry);
     164        ELR_EL1_write(pc);
    160165
    161166        /* Set user stack. */
    162         SP_EL0_write(kernel_uarg->uspace_stack +
    163             kernel_uarg->uspace_stack_size);
     167        SP_EL0_write(sp);
    164168
    165169        /* Clear Thread ID register. */
     
    170174             * Reset the kernel stack to its base value.
    171175             *
    172              * Clear all general-purpose registers,
    173              * except x0 that holds an argument for
    174              * the user space.
     176             * Clear all general-purpose registers.
    175177             */
    176178            "mov sp, %[kstack]\n"
    177             "mov x0, %[uspace_uarg]\n"
     179            "mov x0, #0\n"
    178180            "mov x1, #0\n"
    179181            "mov x2, #0\n"
     
    207209            "mov x30, #0\n"
    208210            "eret\n"
    209             :: [uspace_uarg] "r" (kernel_uarg->uspace_uarg),
    210               [kstack] "r" (((uint64_t) (THREAD->kstack)) +
     211            :: [kstack] "r" (((uint64_t) (THREAD->kstack)) +
    211212              MEM_STACK_SIZE - SP_DELTA)
    212213        );
Note: See TracChangeset for help on using the changeset viewer.