- Timestamp:
- 2006-03-17T01:34:36Z (20 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8a0b0669
- Parents:
- 5fceec7
- Location:
- generic
- Files:
-
- 8 edited
-
include/ipc/ipc.h (modified) (1 diff)
-
include/proc/thread.h (modified) (5 diffs)
-
include/syscall/syscall.h (modified) (1 diff)
-
include/userspace.h (modified) (1 diff)
-
src/main/uinit.c (modified) (1 diff)
-
src/proc/task.c (modified) (2 diffs)
-
src/proc/thread.c (modified) (3 diffs)
-
src/syscall/syscall.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
generic/include/ipc/ipc.h
r5fceec7 r9f52563 79 79 * 80 80 * The protocol for negotiating is: 81 * - sys_connect tome - sends a message IPC_M_CONNECTTOME81 * - sys_connect_to_me - sends a message IPC_M_CONNECTTOME 82 82 * - sys_wait_for_call - upon receipt tries to allocate new phone 83 83 * - if it fails, responds with ELIMIT -
generic/include/proc/thread.h
r5fceec7 r9f52563 44 44 #define THREAD_STACK_SIZE STACK_SIZE 45 45 46 #define THREAD_USER_STACK 147 48 46 enum state { 49 47 Invalid, /**< It is an error, if thread is found in this state. */ … … 60 58 #define X_STOLEN (1<<1) 61 59 60 #define THREAD_NAME_BUFLEN 20 61 62 62 /** Thread structure. There is one per thread. */ 63 63 struct thread { 64 char *name;65 66 64 link_t rq_link; /**< Run queue link. */ 67 65 link_t wq_link; /**< Wait queue link. */ … … 76 74 */ 77 75 SPINLOCK_DECLARE(lock); 76 77 char name[THREAD_NAME_BUFLEN]; 78 78 79 79 void (* thread_code)(void *); /**< Function implementing the thread. */ … … 118 118 }; 119 119 120 /** Structure passed to uinit kernel thread as argument. */ 121 typedef struct uspace_arg { 122 __address uspace_entry; 123 __address uspace_stack; 124 } uspace_arg_t; 125 120 126 /** Thread list lock. 121 127 * … … 140 146 extern void thread_destroy(thread_t *t); 141 147 142 143 148 /* Fpu context slab cache */ 144 149 extern slab_cache_t *fpu_context_slab; 145 150 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 146 155 #endif -
generic/include/syscall/syscall.h
r5fceec7 r9f52563 31 31 32 32 typedef enum { 33 SYS_CTL = 0, 34 SYS_IO, 33 SYS_IO = 0, 34 SYS_THREAD_CREATE, 35 SYS_THREAD_EXIT, 35 36 SYS_MMAP, 36 37 SYS_MREMAP, -
generic/include/userspace.h
r5fceec7 r9f52563 30 30 #define __USERSPACE_H__ 31 31 32 #include <proc/thread.h> 32 33 #include <arch/types.h> 33 34 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) */ 36 extern void userspace(uspace_arg_t *uarg) __attribute__ ((noreturn)); 35 37 36 38 #endif -
generic/src/main/uinit.c
r5fceec7 r9f52563 31 31 #include <proc/thread.h> 32 32 #include <userspace.h> 33 #include <mm/slab.h> 33 34 #include <print.h> 34 35 36 /** Thread used to bring up userspace thread. 37 * 38 * @param arg Pointer to structure containing userspace entry and stack addresses. 39 */ 35 40 void uinit(void *arg) 36 41 { 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); 39 50 } -
generic/src/proc/task.c
r5fceec7 r9f52563 116 116 thread_t *t; 117 117 task_t *task; 118 uspace_arg_t *uarg; 118 119 119 120 as = as_create(0); … … 125 126 } 126 127 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 127 132 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"); 130 134 131 135 /* -
generic/src/proc/thread.c
r5fceec7 r9f52563 54 54 #include <mm/slab.h> 55 55 #include <debug.h> 56 #include <main/uinit.h> 56 57 57 58 char *thread_states[] = {"Invalid", "Running", "Sleeping", "Ready", "Entering", "Exiting"}; /**< Thread states */ … … 281 282 interrupts_restore(ipl); 282 283 283 t->name = name; 284 memcpy(t->name, name, THREAD_NAME_BUFLEN); 285 284 286 t->thread_code = func; 285 287 t->thread_arg = arg; … … 424 426 interrupts_restore(ipl); 425 427 } 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 38 38 #include <ipc/sysipc.h> 39 39 40 static __native sys_ctl(void) {41 printf("Thread finished\n");42 thread_exit();43 /* Unreachable */44 return 0;45 }46 47 40 static __native sys_io(int fd, const void * buf, size_t count) { 48 41 … … 56 49 return count; 57 50 } 58 59 51 60 52 static __native sys_mmap(void *address, size_t size, int flags) … … 72 64 73 65 syshandler_t syscall_table[SYSCALL_END] = { 74 sys_ctl,75 66 sys_io, 67 sys_thread_create, 68 sys_thread_exit, 76 69 sys_mmap, 77 70 sys_mremap,
Note:
See TracChangeset
for help on using the changeset viewer.
