00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <agnix/agnix.h>
00020 #include <asm/tss.h>
00021 #include <agnix/tasks.h>
00022 #include <agnix/list.h>
00023 #include <agnix/console.h>
00024 #include <agnix/spinlock.h>
00025 #include <agnix/panic.h>
00026 #include <agnix/errno.h>
00027 #include <agnix/unistd.h>
00028 #include <agnix/linkage.h>
00029
00030 #define MOD_NAME "THREAD: "
00031
00032 int create_kernel_thread(const char *name, void (*thread_proc)(void *), void *data)
00033 {
00034 __asm__ __volatile__ (
00035 "movl %%esp, %%esi\n\t"
00036 "int $0x80\n\t"
00037 "cmpl %%esp, %%esi\n\t"
00038 "je 1f\n\t"
00039
00040 "pushl %%edi\n\t"
00041 "call *%2\n\t"
00042 "1:"
00043 :
00044 :"a"(__NR_fork), "b"(name), "r"(thread_proc), "D"((u32)data)
00045 );
00046
00047 if (current_task->t_pid)
00048 kernel_panic("Kernel thread terminated...\n");
00049
00050 return 0;
00051 }
00052
00053 int create_user_thread(const char *name, void (*thread_proc)(void *data), void *data)
00054 {
00055 fork();
00056
00057 if (current_task->t_pid > 0) {
00058
00059 (*thread_proc)(data);
00060 } else
00061 if (current_task->t_pid < 0) {
00062 kernel_panic(MOD_NAME "I can not create kernel thread\n");
00063 }
00064
00065 return 0;
00066 }
00067
00068 int threads_init(void)
00069 {
00070 return 0;
00071 }