Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

task.h

Go to the documentation of this file.
00001 /*!     \file include/kernel/task.h
00002  *      \brief Headers for the task manager.
00003  *      \author Andrea Righi <drizzt@inwind.it>
00004  *      \date Last update: 2003-12-16
00005  *      \note Copyright (&copy;) 2003 Andrea Righi
00006  */
00007 
00008 #ifndef TASK_H
00009 #define TASK_H
00010 
00011 #include <arch/paging.h>
00012 #include <arch/i386.h>
00013 
00014 //! Stack size in byte for every kernel-mode task.
00015 #define STACK_SIZE              0x8000
00016 
00017 //! The address where the user-privilege task stack is placed.
00018 #define TASK_STACK_START        0xC0000000
00019 //! The start of the heap for a user-mode task.
00020 #define TASK_HEAP_START         0x40000000
00021 //! The size of the heap for a user-mode task.
00022 #define TASK_HEAP_DEFAULT_SIZE  0x40000000
00023 
00024 #define READY                   1 //!< The task is ready for the CPU.
00025 #define WAIT                    2 //!< The task is waiting for I/O.
00026 #define ZOMBIE                  3 //!< The task is dying.
00027 
00028 #define KTHREAD_T               0x00 //!< A kernel thread type.
00029 #define PROCESS_T               0x01 //!< A task type.
00030 
00031 #define KERNEL_PRIVILEGE        0 //!< Max privilege (kernel).
00032 #define USER_PRIVILEGE          3 //!< Min privilege (user).
00033 
00034 //! TSS without I/O bit map.
00035 typedef struct tss
00036 {
00037         uint32_t        link;
00038         uint32_t        esp0;
00039         uint16_t        ss0, __ss0h;
00040         uint32_t        esp1;
00041         uint16_t        ss1, __ss1h;
00042         uint32_t        esp2;
00043         uint16_t        ss2, __ss2h;
00044         uint32_t        cr3;
00045         uint32_t        eip;
00046         uint32_t        eflags;
00047         uint32_t        eax, ecx, edx, ebx;
00048         uint32_t        esp;
00049         uint32_t        ebp;
00050         uint32_t        esi;
00051         uint32_t        edi;
00052         uint16_t        es, __esh;
00053         uint16_t        cs, __csh;
00054         uint16_t        ss, __ssh;
00055         uint16_t        ds, __dsh;
00056         uint16_t        fs, __fsh;
00057         uint16_t        gs, __gsh;
00058         uint16_t        ldtr, __ldtrh;
00059         uint16_t        trace, io_map_addr;
00060 } tss_t;
00061 
00062 //! TSS with I/O bit map.
00063 typedef struct tss_IO
00064 {
00065         uint32_t        link;
00066         uint32_t        esp0;
00067         uint16_t        ss0, __ss0h;
00068         uint32_t        esp1;
00069         uint16_t        ss1, __ss1h;
00070         uint32_t        esp2;
00071         uint16_t        ss2, __ss2h;
00072         uint32_t        cr3;
00073         uint32_t        eip;
00074         uint32_t        eflags;
00075         uint32_t        eax, ecx, edx, ebx;
00076         uint32_t        esp;
00077         uint32_t        ebp;
00078         uint32_t        esi;
00079         uint32_t        edi;
00080         uint16_t        es, __esh;
00081         uint16_t        cs, __csh;
00082         uint16_t        ss, __ssh;
00083         uint16_t        ds, __dsh;
00084         uint16_t        fs, __fsh;
00085         uint16_t        gs, __gsh;
00086         uint16_t        ldtr, __ldtrh;
00087         uint16_t        trace, io_map_addr;
00088         uint8_t         io_map[8192];   //!< I/O redirection bit map.
00089 } tss_IO_t;
00090 
00091 //! The task structure.
00092 typedef struct task
00093 {
00094         tss_IO_t        tss; //! MUST BE THE FIRST!!!
00095         word            tss_sel;
00096         pid_t           pid;
00097         size_t          pl0_stack;
00098         size_t          heap_start, heap_size;
00099         byte            state;
00100         struct task     *father;
00101         int             console;
00102         byte            type;
00103         byte            priority;
00104         char            name[256];
00105 } task_t;
00106 
00107 //! \brief
00108 //!     Halt the CPU until an interrupt occurs.
00109 static __inline__ void idle()
00110 {
00111         __asm__ __volatile__ ("hlt");
00112 }
00113 
00114 //! \brief
00115 //!     Perform a context switch between two tasks.
00116 //! \param tss_sel
00117 //!     The selector of the next task.
00118 /*!
00119  *      This is an asm routine to jump to a TSS (TSS-based multitasking)
00120  */
00121 static __inline__ void jmp_to_tss(word tss_sel)
00122 {
00123         static struct {
00124         unsigned eip : 32; // 32 bit
00125         unsigned cs  : 16; // 16 bit
00126         } __attribute__ ((packed)) tss_link = {0, 0};
00127 
00128         // Set the TSS link                                             //
00129         tss_link.cs = tss_sel;
00130 
00131         // Jump to the task                                             //
00132         __asm__ __volatile__ ("ljmp *(%0)" : : "m" (tss_link));
00133 }
00134 
00135 void dispatcher();
00136 void init_multitasking();
00137 int get_pid();
00138 char *get_pname();
00139 task_t *get_curr_task();
00140 
00141 //! Macro equivalent to get_curr_task() routine.
00142 #define MYSELF  ( get_curr_task() )
00143 
00144 void do_idle();
00145 
00146 task_t *create_kthread(void *address, char *pname);
00147 task_t *create_process(void *address, void *buffer, size_t size, char *pname, int privilege);
00148 task_t *new_task(char *filename, int argc, char **argv, int privilege);
00149 
00150 void auto_kill(int n);
00151 
00152 //! Macro equivalent to auto_kill() (...for now).
00153 /*!
00154  *      \todo
00155  *      The exit returning values between tasks.
00156  */
00157 #define _exit(n)        auto_kill(n)
00158 
00159 bool kill(pid_t pid);
00160 pid_t waitpid(pid_t pid, int *status, int options);
00161 void sleep_task(task_t *p);
00162 void wakeup_task(task_t *p);
00163 
00164 void sched_enter_critical_region();
00165 void sched_leave_critical_region();
00166 bool is_sched_enabled();
00167 
00168 void ps();
00169 
00170 #endif

Generated on Fri Feb 20 15:32:16 2004 for Minirighi by doxygen1.2.18