Changeset 9f52563 in mainline


Ignore:
Timestamp:
2006-03-17T01:34:36Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8a0b0669
Parents:
5fceec7
Message:

Support for user space threads.

Files:
13 edited

Legend:

Unmodified
Added
Removed
  • arch/amd64/src/userspace.c

    r5fceec7 r9f52563  
    4040 *
    4141 */
    42 void userspace(__address entry)
     42void userspace(uspace_arg_t *uarg)
    4343{
    4444        ipl_t ipl;
     
    4747
    4848        __asm__ volatile (""
    49                           "movq %0, %%rax;"                   
    50                           "movq %1, %%rbx;"
    51                           "movq %2, %%rcx;"
    52                           "movq %3, %%rdx;"
    53                           "movq %4, %%rsi;"
    54                           "pushq %%rax;"
    55                           "pushq %%rbx;"
    56                           "pushq %%rcx;"
    57                           "pushq %%rdx;"
    58                           "pushq %%rsi;"
    59                           "iretq;"
    60                           : : "i" (gdtselector(UDATA_DES) | PL_USER),
    61                           "i" (USTACK_ADDRESS+THREAD_STACK_SIZE),
     49                          "pushq %0\n"
     50                          "pushq %1\n"
     51                          "pushq %2\n"
     52                          "pushq %3\n"
     53                          "pushq %4\n"
     54                          "iretq\n"
     55                          : :
     56                          "i" (gdtselector(UDATA_DES) | PL_USER),
     57                          "r" (uarg->uspace_stack+THREAD_STACK_SIZE),
    6258                          "r" (ipl),
    6359                          "i" (gdtselector(UTEXT_DES) | PL_USER),
    64                           "r" (entry));
     60                          "r" (uarg->uspace_entry));
    6561       
    6662        /* Unreachable */
  • arch/ia32/include/fpu_context.h

    r5fceec7 r9f52563  
    4040
    4141struct fpu_context {
    42         /* TODO: We need malloc that aligns structures on 16-byte boundary */
    4342        __u8 fpu[512];          /* FXSAVE & FXRSTOR storage area */
    4443};
  • arch/ia32/src/userspace.c

    r5fceec7 r9f52563  
    4040 *
    4141 */
    42 void userspace(__address entry)
     42void userspace(uspace_arg_t *uarg)
    4343{
    4444        ipl_t ipl;
     
    6161                "iret"
    6262                :
    63                 : "i" (selector(UDATA_DES) | PL_USER), "r" (USTACK_ADDRESS+(THREAD_STACK_SIZE)), "r" (ipl), "i" (selector(UTEXT_DES) | PL_USER), "r" (entry)
     63                : "i" (selector(UDATA_DES) | PL_USER), "r" (uarg->uspace_stack+THREAD_STACK_SIZE),
     64                  "r" (ipl), "i" (selector(UTEXT_DES) | PL_USER), "r" (uarg->uspace_entry)
    6465                : "eax");
    6566       
  • arch/ia64/src/ia64.c

    r5fceec7 r9f52563  
    4242#include <userspace.h>
    4343#include <console/console.h>
     44#include <proc/thread.h>
    4445
    4546void arch_pre_mm_init(void)
     
    7374
    7475/** Enter userspace and never return. */
    75 void userspace(__address entry)
     76void userspace(uspace_arg_t *uarg)
    7677{
    7778        psr_t psr;
     
    9192        rsc.mode = 3;                           /* eager mode */
    9293
    93         switch_to_userspace(entry, USTACK_ADDRESS+PAGE_SIZE-ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT), USTACK_ADDRESS, psr.value, rsc.value);
     94        switch_to_userspace(uarg->uspace_entry, uarg->uspace_stack+PAGE_SIZE-ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT), uarg->uspace_stack, psr.value, rsc.value);
    9495
    9596        while (1) {
  • arch/mips32/src/mips32.c

    r5fceec7 r9f52563  
    121121__address supervisor_sp __attribute__ ((section (".text")));
    122122
    123 void userspace(__address entry)
     123void userspace(uspace_arg_t *uarg)
    124124{
    125125        /* EXL=1, UM=1, IE=1 */
     
    127127                                              cp0_status_um_bit |
    128128                                              cp0_status_ie_enabled_bit));
    129         cp0_epc_write(entry);
    130         userspace_asm(USTACK_ADDRESS+PAGE_SIZE);
     129        cp0_epc_write(uarg->uspace_entry);
     130        userspace_asm(uarg->uspace_stack+PAGE_SIZE);
    131131        while (1)
    132132                ;
  • generic/include/ipc/ipc.h

    r5fceec7 r9f52563  
    7979 *
    8080 * The protocol for negotiating is:
    81  * - sys_connecttome - sends a message IPC_M_CONNECTTOME
     81 * - sys_connect_to_me - sends a message IPC_M_CONNECTTOME
    8282 * - sys_wait_for_call - upon receipt tries to allocate new phone
    8383 *                       - if it fails, responds with ELIMIT
  • generic/include/proc/thread.h

    r5fceec7 r9f52563  
    4444#define THREAD_STACK_SIZE       STACK_SIZE
    4545
    46 #define THREAD_USER_STACK       1
    47 
    4846enum state {
    4947        Invalid,        /**< It is an error, if thread is found in this state. */
     
    6058#define X_STOLEN        (1<<1)
    6159
     60#define THREAD_NAME_BUFLEN      20
     61
    6262/** Thread structure. There is one per thread. */
    6363struct thread {
    64         char *name;
    65        
    6664        link_t rq_link;                         /**< Run queue link. */
    6765        link_t wq_link;                         /**< Wait queue link. */
     
    7674         */
    7775        SPINLOCK_DECLARE(lock);
     76
     77        char name[THREAD_NAME_BUFLEN];
    7878
    7979        void (* thread_code)(void *);           /**< Function implementing the thread. */
     
    118118};
    119119
     120/** Structure passed to uinit kernel thread as argument. */
     121typedef struct uspace_arg {
     122        __address uspace_entry;
     123        __address uspace_stack;
     124} uspace_arg_t;
     125
    120126/** Thread list lock.
    121127 *
     
    140146extern void thread_destroy(thread_t *t);
    141147
    142 
    143148/* Fpu context slab cache */
    144149extern slab_cache_t *fpu_context_slab;
    145150
     151/** Thread syscall prototypes. */
     152__native sys_thread_create(__address function, void *arg, void *stack, char *name);
     153__native sys_thread_exit(int status);
     154
    146155#endif
  • generic/include/syscall/syscall.h

    r5fceec7 r9f52563  
    3131
    3232typedef enum {
    33         SYS_CTL = 0,
    34         SYS_IO,
     33        SYS_IO = 0,
     34        SYS_THREAD_CREATE,
     35        SYS_THREAD_EXIT,
    3536        SYS_MMAP,
    3637        SYS_MREMAP,
  • generic/include/userspace.h

    r5fceec7 r9f52563  
    3030#define __USERSPACE_H__
    3131
     32#include <proc/thread.h>
    3233#include <arch/types.h>
    3334
    34 extern void userspace(__address entry) __attribute__ ((noreturn)); /**< Switch to user-space (CPU user priviledge level) */
     35/** Switch to user-space (CPU user priviledge level) */
     36extern void userspace(uspace_arg_t *uarg) __attribute__ ((noreturn));
    3537
    3638#endif
  • generic/src/main/uinit.c

    r5fceec7 r9f52563  
    3131#include <proc/thread.h>
    3232#include <userspace.h>
     33#include <mm/slab.h>
    3334#include <print.h>
    3435
     36/** Thread used to bring up userspace thread.
     37 *
     38 * @param arg Pointer to structure containing userspace entry and stack addresses.
     39 */
    3540void uinit(void *arg)
    3641{
    37         printf("USER task, uinit thread: kernel mode\n");
    38         userspace((__address)(arg));
     42        uspace_arg_t uarg;
     43       
     44        uarg.uspace_entry = ((uspace_arg_t *) arg)->uspace_entry;
     45        uarg.uspace_stack = ((uspace_arg_t *) arg)->uspace_stack;
     46
     47        free((uspace_arg_t *) arg);
     48       
     49        userspace(&uarg);
    3950}
  • generic/src/proc/task.c

    r5fceec7 r9f52563  
    116116        thread_t *t;
    117117        task_t *task;
     118        uspace_arg_t *uarg;
    118119
    119120        as = as_create(0);
     
    125126        }
    126127       
     128        uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0);
     129        uarg->uspace_entry = (__address) ((elf_header_t *) program_addr)->e_entry;
     130        uarg->uspace_stack = USTACK_ADDRESS;
     131       
    127132        task = task_create(as, name);
    128         t = thread_create(uinit, (void *)((elf_header_t *)program_addr)->e_entry,
    129                           task, 0, "uinit");
     133        t = thread_create(uinit, uarg, task, 0, "uinit");
    130134       
    131135        /*
  • generic/src/proc/thread.c

    r5fceec7 r9f52563  
    5454#include <mm/slab.h>
    5555#include <debug.h>
     56#include <main/uinit.h>
    5657
    5758char *thread_states[] = {"Invalid", "Running", "Sleeping", "Ready", "Entering", "Exiting"}; /**< Thread states */
     
    281282        interrupts_restore(ipl);
    282283       
    283         t->name = name;
     284        memcpy(t->name, name, THREAD_NAME_BUFLEN);
     285       
    284286        t->thread_code = func;
    285287        t->thread_arg = arg;
     
    424426        interrupts_restore(ipl);
    425427}
     428
     429/** Process syscall to create new thread.
     430 *
     431 */
     432__native sys_thread_create(__address function, void *arg, void *stack, char *name)
     433{
     434        thread_t *t;
     435        char namebuf[THREAD_NAME_BUFLEN];
     436        uspace_arg_t *uarg;
     437        __u32 tid;
     438
     439        copy_from_uspace(namebuf, name, THREAD_NAME_BUFLEN);
     440        uarg = (uspace_arg_t *) malloc(sizeof(uarg), 0);
     441       
     442        uarg->uspace_entry = function;
     443        uarg->uspace_stack = (__address) stack;
     444
     445        if ((t = thread_create(uinit, uarg, TASK, 0, namebuf))) {
     446                tid = t->tid;
     447                thread_ready(t);
     448                return (__native) tid;
     449        } else {
     450                free(namebuf);
     451        }
     452
     453        return (__native) -1;
     454}
     455
     456/** Process syscall to terminate thread.
     457 *
     458 */
     459__native sys_thread_exit(int status)
     460{
     461        thread_exit();
     462        /* Unreachable */
     463        return 0;
     464}
  • generic/src/syscall/syscall.c

    r5fceec7 r9f52563  
    3838#include <ipc/sysipc.h>
    3939
    40 static __native sys_ctl(void) {
    41         printf("Thread finished\n");
    42         thread_exit();
    43         /* Unreachable */
    44         return 0;
    45 }
    46 
    4740static __native sys_io(int fd, const void * buf, size_t count) {
    4841       
     
    5649        return count;
    5750}
    58 
    5951
    6052static __native sys_mmap(void *address, size_t size, int flags)
     
    7264
    7365syshandler_t syscall_table[SYSCALL_END] = {
    74         sys_ctl,
    7566        sys_io,
     67        sys_thread_create,
     68        sys_thread_exit,
    7669        sys_mmap,
    7770        sys_mremap,
Note: See TracChangeset for help on using the changeset viewer.