ktask.c

00001 /***************************************************************************
00002                           ktask.c  -  description
00003                              -------------------
00004     begin                : Sat Jan 3 2004
00005     copyright            : (C) 2004 by Dynacube Team
00006     email                : mdshah82@yahoo.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018  #include "core/ktask.h"
00019 
00020  extern void isr20h();
00021   
00022  TSS _system  __attribute__((aligned(_4KB))), _task[2]   __attribute__((aligned(_4KB))); //, _task2   __attribute__((aligned(_4KB)));
00023  TSS _int_tss  __attribute__((aligned(_4KB)));
00024 
00025  DB blank[sizeof(TSS)] = {0};
00026 
00027  SEG_DESC _sys_tss;
00028  DW _tss_flags;
00029  
00030  void task_init()
00031  {
00032          SEG_DESC tmp;
00033          DD cr3;
00034         
00035          memcpy(&_system,blank,sizeof(TSS));
00036          memcpy(&_task[0],blank,sizeof(TSS));
00037          memcpy(&_task[1],blank,sizeof(TSS));
00038 
00039          asm __volatile__("movl %%cr3,%%eax":"=a"(_system.cr3));
00040          asm __volatile__("movw %%cs,%%ax":"=a"(_system.cs));
00041          asm __volatile__("movw %%ds,%%ax":"=a"(_system.ds));
00042          asm __volatile__("movw %%ss,%%ax":"=a"(_system.ss));
00043          asm __volatile__("movw %%es,%%ax":"=a"(_system.es));
00044          asm __volatile__("movw %%fs,%%ax":"=a"(_system.fs));
00045          asm __volatile__("movw %%gs,%%ax":"=a"(_system.gs));
00046 
00047          _system.eflags = 0x2|(1<<9);
00048    
00049          asm __volatile__("movl %%esp,%%eax":"=a"(_system.esp0));        
00050          asm __volatile__("movw %%ss,%%ax":"=a"(_system.ss0));
00051 
00052          clearDESC(&tmp);
00053          createDESC(&tmp,0x0,0xF,0x882);
00054          addDesc(LDT_SYS_SEL,&tmp);
00055          
00056          printDESC(&tmp);
00057          
00058          _system.ldt_sel = LDT_SYS_SEL*8;
00059 
00060          _tss_flags = 0x889;
00061 
00062          _int_tss = _system;
00063          _int_tss.eip = isr20h;
00064          _int_tss.esp = KERNEL_SIZE;
00065          printTSS(&_int_tss);   
00066    
00067          printf("\n%x %d",&_system,sizeof(TSS));
00068          clearDESC(&_sys_tss);
00069          createDESC(&_sys_tss,&_system,sizeof(TSS),_tss_flags);
00070          addDesc(SYS_TSS_SEL,&_sys_tss);
00071          printDESC(&_sys_tss);
00072 
00073          clearDESC(&_sys_tss);
00074          createDESC(&_sys_tss,&_task[0],sizeof(TSS),_tss_flags);
00075          addDesc(TASK1_TSS_SEL,&_sys_tss);
00076          printDESC(&_sys_tss);
00077 
00078          clearDESC(&_sys_tss);
00079          createDESC(&_sys_tss,&_task[1],sizeof(TSS),_tss_flags);
00080          addDesc(TASK2_TSS_SEL,&_sys_tss);
00081          printDESC(&_sys_tss);
00082 
00083          clearDESC(&_sys_tss);
00084          createDESC(&_sys_tss,&_int_tss,sizeof(TSS),_tss_flags);
00085          addDesc(INT_TSS_SEL,&_sys_tss);
00086          printDESC(&_sys_tss);
00087                                  
00088          asm("lldt %%ax"::"a"((LDT_SYS_SEL*8)));
00089          printf("Addr: %x\n",&_task[0]);
00090  }
00091 
00092  void printTSS(const TSS *tmp)
00093  {
00094    printf("\ncs %x ds %x ss %x esp %x eip %x",tmp->cs,tmp->ds,tmp->ss,tmp->esp,tmp->eip);
00095    printf("\nss0 %x esp0 %x eflags %x ebp %x",tmp->ss0,tmp->esp0,tmp->eflags,tmp->ebp);
00096    printf("\nldtsel %x cr3 %x prev_link %x\n",tmp->ldt_sel,tmp->cr3,tmp->pre_task_link);
00097  }
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117  

Generated on Thu Jul 27 23:52:27 2006 for Dynacube by  doxygen 1.4.7