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


Ignore:
Timestamp:
2024-09-20T12:16:28Z (2 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/ia64/src/ia64.c

    r2cf8f994 r3fcea34  
    218218}
    219219
     220uintptr_t arch_get_initial_sp(uintptr_t stack_base, uintptr_t stack_size)
     221{
     222        return ALIGN_DOWN(stack_base + stack_size / 2, STACK_ALIGNMENT);
     223}
     224
    220225/** Enter userspace and never return. */
    221 void userspace(uspace_arg_t *kernel_uarg)
     226void userspace(uintptr_t pc, uintptr_t sp)
    222227{
    223228        psr_t psr;
     
    241246         *
    242247         * When calculating stack addresses, mind the stack split between the
    243          * memory stack and the RSE stack. Each occuppies
    244          * uspace_stack_size / 2 bytes.
     248         * memory stack and the RSE stack.
     249         * Memory stack occupies area under sp, while RSE stack occupies area above.
    245250         */
    246         switch_to_userspace(kernel_uarg->uspace_entry,
    247             kernel_uarg->uspace_stack +
    248             kernel_uarg->uspace_stack_size / 2 -
    249             ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT),
    250             kernel_uarg->uspace_stack +
    251             kernel_uarg->uspace_stack_size / 2,
    252             kernel_uarg->uspace_uarg, psr.value, rsc.value);
     251        switch_to_userspace(pc,
     252            sp, sp + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT),
     253            0, psr.value, rsc.value);
    253254
    254255        while (true)
Note: See TracChangeset for help on using the changeset viewer.