Main Page | Directories | File List | Globals

task.c File Reference

#include <agnix/init.h>
#include <asm/segment.h>
#include <agnix/adi/chips/cpu.h>
#include <asm/desc.h>
#include <agnix/memory.h>
#include <agnix/console.h>
#include <agnix/tasks.h>

Include dependency graph for task.c:

Go to the source code of this file.

Defines

#define jmp_to_task(indirect)

Functions

int idle_task_init (void)
tss_wrap_s * get_free_tss (void)
void put_free_tss (struct tss_wrap_s *tss)
void task_switch (u16 nr_task)
void task_set_handler (struct task_s *task, u32 eip, u32 esp)
void task_restore_state (struct task_s *task, struct task_state_s *state)
void task_save_state (struct task_s *task, struct task_state_s *state)
int task_set_user_mode (struct tss_s *tss, u32 eip, u32 esp)
u16 task_kernel_create (struct tss_wrap_s *tss_wrap, u32 eip, u32 esp)
tss_wrap_s * task_fork (struct regs_s *regs, u32 esp)
int task_exit (struct tss_wrap_s *tss_wrap)
int __init tasks_init (void)

Variables

tss_wrap_s init_tss [MAX_TASKS]
main_memory_s main_memory
list_head tss_list
indirect_s task_indirect


Define Documentation

#define jmp_to_task indirect   ) 
 

Value:

__asm__ __volatile__ (  \
    "ljmp *(%%edi)\n\t"         \
    :                           \
    :"D"(&indirect)             \
    )

Definition at line 28 of file task.c.

Referenced by task_switch().


Function Documentation

struct tss_wrap_s* get_free_tss void   ) 
 

Definition at line 40 of file task.c.

References tss_list.

Referenced by kernel_task_init(), and task_fork().

00041 {
00042     struct tss_wrap_s *tss = 0;
00043 
00044     if (!list_empty(&tss_list)) {
00045         if ((tss = list_entry(tss_list.next, struct tss_wrap_s, tss_list)) != 0) {
00046             list_del(tss_list.next);
00047             return tss;
00048         }
00049     }
00050     
00051     return 0;   
00052 }

int idle_task_init void   ) 
 

Definition at line 50 of file init_task.c.

References kernel_task_init().

Referenced by tasks_init().

00051 {
00052     u16 entry;
00053     
00054     entry = kernel_task_init(&idle_task, &idle_tss, (u32)idle_esp, 0);
00055     load_TR(entry);
00056 
00057     return entry;
00058 }

Here is the call graph for this function:

void put_free_tss struct tss_wrap_s *  tss  ) 
 

Definition at line 54 of file task.c.

References tss_list.

Referenced by task_exit(), and tasks_init().

00055 {
00056     list_add_tail(&tss->tss_list, &tss_list);
00057 }

int task_exit struct tss_wrap_s *  tss_wrap  ) 
 

Definition at line 207 of file task.c.

References put_free_tss(), and set_TSS_desc().

Referenced by do_task_exit().

00208 {
00209     u16 desc_nr;
00210     u16 entry;
00211 
00212     put_free_tss(tss_wrap);
00213 
00214     entry = tss_wrap->tss_entry;
00215     desc_nr = __TSS(entry);
00216 
00217     set_TSS_desc(desc_nr, (void *)0, 235, 0);
00218     
00219     return 0;
00220 }

Here is the call graph for this function:

struct tss_wrap_s* task_fork struct regs_s *  regs,
u32  esp
 

Definition at line 155 of file task.c.

References get_free_tss(), main_memory, memset(), and set_TSS_desc().

Referenced by do_sys_fork().

00156 {
00157     struct tss_s *current_tss;
00158     struct tss_wrap_s *tss_wrap;
00159     struct tss_s *tss;
00160     u16 desc_nr;
00161     u16 entry;
00162 
00163     current_tss = &current_task->tss_wrap->tss;
00164 
00165     if ((tss_wrap = get_free_tss()) == 0)
00166         return 0;
00167 
00168     tss = &tss_wrap->tss;
00169 
00170     entry = tss_wrap->tss_entry;
00171     desc_nr = __TSS(entry);
00172 
00173     memset(tss, 0, sizeof(struct tss_s));
00174 
00175     tss->eax  = regs->eax;
00176     tss->ebx  = regs->ebx;
00177     tss->ecx  = regs->ecx;
00178     tss->edx  = regs->edx;
00179     tss->esp  = esp;
00180     tss->esp0 = esp;
00181     tss->ss0  = __KERNEL_DS;
00182     tss->ss1  = __KERNEL_DS;
00183     tss->ss2  = __KERNEL_DS;
00184     tss->esi  = regs->esi;
00185     tss->edi  = regs->edi;
00186     tss->eip  = regs->eip;
00187     tss->ebp  = regs->ebp;
00188     tss->cs   = current_tss->cs;
00189     tss->ss   = current_tss->ss;
00190     tss->ds   = current_tss->ds;
00191     tss->es   = current_tss->es;
00192     tss->fs   = current_tss->fs;
00193     tss->gs   = current_tss->gs;
00194 
00195     tss->__cr3  = (u32)main_memory.pdbr - 0xC0000000;
00196     tss->ldt  = 0;
00197     tss->eflags = regs->eflags;
00198     tss->task_link = 0;
00199     tss->bitmap = 0x8000;
00200     tss->io_bitmap[0] = ~0;
00201 
00202     set_TSS_desc(desc_nr, (void *)tss, 235, 0);
00203 
00204     return tss_wrap;
00205 }

Here is the call graph for this function:

u16 task_kernel_create struct tss_wrap_s *  tss_wrap,
u32  eip,
u32  esp
 

Definition at line 119 of file task.c.

References init_tss, main_memory, memset(), and set_TSS_desc().

Referenced by kernel_task_init().

00120 {
00121     struct tss_s *tss = &(tss_wrap->tss);
00122     u16 desc_nr;
00123     u16 entry;
00124 
00125     entry = tss_wrap->tss_entry;
00126     desc_nr = __TSS(entry);
00127 
00128     memset(tss, 0, sizeof(struct tss_s));
00129 
00130     tss->eflags = CPU_EFLAGS_IF;
00131     tss->eip  = eip;
00132     tss->esp  = esp;
00133     tss->esp0 = esp;
00134     tss->esp1 = 0;
00135     tss->esp2 = 0;
00136     tss->ss0  = __KERNEL_DS;
00137     tss->ss1  = __KERNEL_DS;
00138     tss->ss2  = __KERNEL_DS;
00139     tss->cs   = __KERNEL_CS;
00140     tss->ss   = __KERNEL_DS;
00141     tss->ds   = __KERNEL_DS;    
00142     tss->es   = __KERNEL_DS;
00143     tss->fs   = __KERNEL_DS;
00144     tss->gs   = __KERNEL_DS;
00145     tss->ldt  = 0;
00146     tss->__cr3  = (u32)main_memory.pdbr - 0xC0000000;
00147     tss->bitmap = 0x8000;
00148     tss->io_bitmap[0] = ~0;
00149 
00150     set_TSS_desc(desc_nr, (void *)&init_tss[entry].tss, 235, 0);
00151 
00152     return entry;
00153 }

Here is the call graph for this function:

void task_restore_state struct task_s *  task,
struct task_state_s *  state
 

Definition at line 86 of file task.c.

00086                                                                          {
00087 /*    struct tss_s *tss_state = &(state->tss_regs);
00088     struct tss_s *tss_task = &(task->tss_wrap->tss);
00089     
00090     memcpy(tss_task, tss_state, sizeof(struct tss_s));*/
00091 }

void task_save_state struct task_s *  task,
struct task_state_s *  state
 

Definition at line 93 of file task.c.

00093                                                                       {
00094 /*    struct tss_s *tss_state = &(state->tss);
00095     struct tss_s *tss_task = &(task->tss_wrap->tss);
00096     
00097     memcpy(tss_state, tss_task, sizeof(struct tss_s));*/
00098 }

void task_set_handler struct task_s *  task,
u32  eip,
u32  esp
 

Definition at line 79 of file task.c.

00079                                                              {
00080     struct tss_s *tss = &(task->tss_wrap->tss);
00081     
00082     tss->eip = eip;
00083     tss->esp = esp;
00084 }

int task_set_user_mode struct tss_s *  tss,
u32  eip,
u32  esp
 

Definition at line 100 of file task.c.

00101 {       
00102     /* user mode esp, cr3 */
00103 
00104     tss->eip  = eip;
00105     tss->esp  = esp;
00106     tss->ss0  = __KERNEL_DS;
00107     tss->ss1  = __KERNEL_DS;
00108     tss->ss2  = __KERNEL_DS;
00109     tss->cs   = __USER_CS;
00110     tss->ss   = __USER_DS;
00111     tss->ds   = __USER_DS;    
00112     tss->es   = __USER_DS;
00113     tss->fs   = __USER_DS;
00114     tss->gs   = __USER_DS;
00115 
00116     return 0;    
00117 }

void task_switch u16  nr_task  ) 
 

Definition at line 59 of file task.c.

References init_tss, jmp_to_task, printk(), and task_indirect.

Referenced by schedule_task().

00060 {
00061 #ifdef DEBUG_THREAD
00062     printk("jmp to %d\n", nr_task);
00063     printk("eip == %x\n", init_tss[nr_task].tss.eip);
00064     printk("cr3 == %x\n", init_tss[nr_task].tss.__cr3);
00065     printk("cs  == %x\n", init_tss[nr_task].tss.cs);
00066     printk("ds  == %x\n", init_tss[nr_task].tss.ds);
00067     printk("esp  == %x\n", init_tss[nr_task].tss.esp);
00068     printk("ebp  == %x\n", init_tss[nr_task].tss.ebp);
00069     printk("link  == %x\n", init_tss[nr_task].tss.task_link);
00070     printk("trace == %x\n", init_tss[nr_task].tss.trace);
00071 #endif
00072 
00073     task_indirect.segment = __TSS(nr_task) << 3;
00074     task_indirect.offset = 0;
00075 
00076     jmp_to_task(task_indirect);
00077 }

Here is the call graph for this function:

int __init tasks_init void   ) 
 

Definition at line 222 of file task.c.

References idle_task_init(), init_tss, put_free_tss(), and tss_list.

Referenced by start_kernel().

00223 {
00224     int i;
00225 
00226     INIT_LIST_HEAD(&tss_list);
00227     
00228     for (i = 0; i < MAX_TASKS; i++) {
00229         INIT_LIST_HEAD(&init_tss[i].tss_list);
00230         init_tss[i].tss_entry = (u16)i;
00231         put_free_tss(&init_tss[i]);
00232     }
00233 
00234     idle_task_init();
00235 
00236     return 0;
00237 }

Here is the call graph for this function:


Variable Documentation

struct tss_wrap_s init_tss[MAX_TASKS]
 

struct main_memory_s main_memory
 

Definition at line 23 of file memory.c.

struct indirect_s task_indirect
 

Referenced by task_switch().

struct list_head tss_list
 

Definition at line 26 of file task.c.

Referenced by get_free_tss(), put_free_tss(), and tasks_init().

Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix