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


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

    r2cf8f994 r3fcea34  
    6161} ustate_t;
    6262
     63uintptr_t arch_get_initial_sp(uintptr_t stack_base, uintptr_t stack_size)
     64{
     65        return stack_base + stack_size;
     66}
     67
    6368/** Change processor mode
    6469 *
     
    6671 *
    6772 */
    68 void userspace(uspace_arg_t *kernel_uarg)
     73void userspace(uintptr_t pc, uintptr_t sp)
    6974{
    70         volatile ustate_t ustate;
    71 
    72         /* set first parameter */
    73         ustate.r0 = kernel_uarg->uspace_uarg;
    74 
    75         /* %r1 is defined to hold pcb_ptr - set it to 0 */
    76         ustate.r1 = 0;
     75        volatile ustate_t ustate = { };
    7776
    7877        /* pass the RAS page address in %r2 */
    7978        ustate.r2 = (uintptr_t) ras_page;
    8079
    81         /* clear other registers */
    82         ustate.r3 = 0;
    83         ustate.r4 = 0;
    84         ustate.r5 = 0;
    85         ustate.r6 = 0;
    86         ustate.r7 = 0;
    87         ustate.r8 = 0;
    88         ustate.r9 = 0;
    89         ustate.r10 = 0;
    90         ustate.r11 = 0;
    91         ustate.r12 = 0;
    92         ustate.lr = 0;
    93 
    94         /* set user stack */
    95         ustate.sp = kernel_uarg->uspace_stack +
    96             kernel_uarg->uspace_stack_size;
    97 
    98         /* set where uspace execution starts */
    99         ustate.pc = kernel_uarg->uspace_entry;
     80        ustate.sp = sp;
     81        ustate.pc = pc;
    10082
    10183        /* status register in user mode */
Note: See TracChangeset for help on using the changeset viewer.