00001
00002
00003 #ifndef __SYSTEM
00004 #include "routix/system.h"
00005 #endif
00006
00007 #include <routix/paging.h>
00008 #include "sys/list.h"
00009
00010
00011 #ifndef __ROUTIX_TYPES
00012 #include <sys/types.h>
00013 #endif
00014
00015 #ifndef __SIGNAL
00016 #include <signal.h>
00017 #endif
00018
00019 #ifndef __ROUTIX_TASK
00020 #define __ROUTIX_TASK
00021
00022 #include "routix/file.h"
00023
00024
00025 #define MAX_TASKS 7
00026
00027 typedef struct task_t {
00028 word previos_task_link;
00029 dword esp0;
00030 word ss0;
00031 dword esp1;
00032 word ss1;
00033 dword esp2;
00034 word ss2;
00035 dword cr3;
00036 dword eip;
00037 dword eflags;
00038 dword eax;
00039 dword ecx;
00040 dword edx;
00041 dword ebx;
00042 dword esp;
00043 dword ebp;
00044 dword esi;
00045 dword edi;
00046 word es;
00047 word cs;
00048 word ss;
00049 word ds;
00050 word fs;
00051 word gs;
00052 word ldt;
00053 word t;
00054 word iomap;
00055 } task_t;
00056
00057
00058 typedef struct tss_t {
00059 word previos_task_link;
00060 word reservado0;
00061 dword esp0;
00062 word ss0;
00063 word reservado1;
00064 dword esp1;
00065 word ss1;
00066 word reservado2;
00067 dword esp2;
00068 word ss2;
00069 word reservado3;
00070 dword cr3;
00071 dword eip;
00072 dword eflags;
00073 dword eax;
00074 dword ecx;
00075 dword edx;
00076 dword ebx;
00077 dword esp;
00078 dword ebp;
00079 dword esi;
00080 dword edi;
00081 word es;
00082 word reservado4;
00083 word cs;
00084 word reservado5;
00085 word ss;
00086 word reservado6;
00087 word ds;
00088 word reservado7;
00089 word fs;
00090 word reservado8;
00091 word gs;
00092 word reservado9;
00093 word ldt;
00094 word reservado10;
00095 word t;
00096 word iomap;
00097 } tss_t;
00098
00100 struct int_regs_ext
00101 {
00102 dword gs;
00103 dword fs;
00104 dword es;
00105 dword ds;
00106 dword eax;
00107 dword ebx;
00108 dword ecx;
00109 dword edx;
00110 dword edi;
00111 dword esi;
00112 dword ebp;
00113 dword eip;
00114 dword cs;
00115 dword eflags;
00116 dword esp;
00117 dword ss;
00118 };
00119
00120
00121 extern tss_t tss;
00122 extern task_t tarea[];
00123 void inicializarTss(tss_t *tss, word cs, word ds, dword eip, dword esp, dword eflags);
00124
00125 inline pid_t get_new_pid(void);
00126
00127 #define ltr(selector) __asm__ __volatile__("ltr %w0" : : "a" (selector));
00128
00129
00130
00131 #define MAX_PAGINAS_POR_TAREA 16
00132 #define MAX_DESCRIPTION 64
00133
00134 struct task_signals {
00135 struct sigaction signal[SIGMAX];
00136 unsigned char sigcount[SIGMAX];
00137 unsigned long sigpending;
00138 sigset_t sigmask;
00139 addr_t sigcheck_addr;
00140 };
00141
00142
00143
00144 extern unsigned int task_signals_alloc, task_signals_free;
00145
00146 extern unsigned int umalloc_alloc, umalloc_free;
00147 extern unsigned int file_alloc, file_free;
00148
00149
00150 #define TASK_SIGNALS(task) (task->_signals)
00151 #define TASK_SIGPENDING(task) (TASK_SIGNALS(task)->sigpending)
00152 #define TASK_SIGMASK(task) (TASK_SIGNALS(task)->sigmask)
00153 #define TASK_SIGADDR(task) (TASK_SIGNALS(task)->sigcheck_addr)
00154 #define TASK_SIGNAL(task, signo) (TASK_SIGNALS(task)->signal[signo])
00155 #define TASK_SIGNAL_HANDLER(task,signo) (TASK_SIGNAL(task,signo).sa_handler)
00156 #define TASK_SIGNAL_MASK(task,signo) (TASK_SIGNAL(task,signo).sa_mask)
00157 #define TASK_SIGNAL_FLAGS(task,signo) (TASK_SIGNAL(task,signo).sa_flags)
00158
00159 #define TASK_SIGNALS_ALLOC(task) TASK_SIGNALS(task) = (struct task_signals *) \
00160 malloc(sizeof(struct task_signals)); \
00161 task_signals_alloc++;
00162 #define TASK_SIGNALS_FREE(task) free(TASK_SIGNALS(task)); \
00163 task_signals_free++;
00164 #define TASK_SIGNALS_INIT(task) memset(TASK_SIGNALS(task), 0, sizeof(struct task_signals))
00165
00166 #define TASK_SIGNAL_COUNT(task, signo) ((TASK_SIGNALS(task)->sigcount)[signo])
00167
00168 struct std_header {
00169 struct std_header *next;
00170 struct std_header *prev;
00171 };
00172
00173
00174 typedef struct task_struct_t
00175 {
00176 dword esp0;
00177 dword cr3;
00178 dword cr3_backup;
00179 pid_t pid;
00180 struct task_struct_t *proxima;
00181 char descripcion[MAX_DESCRIPTION];
00182 byte estado;
00183 word prioridad;
00184 word cuenta;
00185 dword tiempo_cpu;
00186 struct file *open_files [MAX_FILES_POR_TAREA];
00187 word num_code, num_data, num_stack;
00188 int err_no;
00189 struct user_page *mcode;
00190 struct user_page *mdata;
00191 struct user_page *mstack;
00192 struct task_struct_t *padre;
00193 int retorno;
00194
00195 LIST_DATA(task_struct_t) io_pending;
00196
00197
00198
00199 LIST_NEW(struct task_struct_t) childs;
00200 LIST_DATA(task_struct_t) brothers;
00201
00202 struct task_signals *_signals;
00203
00204
00205
00206
00207
00208
00209
00210 } task_struct_t ;
00211
00212 #define TASK_STACK_USER(t) (t->esp0)
00213 #define TASK_CR3(t) (t->cr3)
00214 #define TASK_CR3_BACKUP(t) (t->cr3_backup)
00215 #define TASK_PID(t) (t->pid)
00216 #define TASK_DESCRIPTION(t) (t->descripcion)
00217 #define TASK_STATE(t) (t->estado)
00218 #define TASK_PRIORITY(t) (t->prioridad)
00219 #define TASK_COUNT(t) (t->cuenta)
00220 #define TASK_CPUTIME(t) (t->tiempo_cpu)
00221 #define TASK_CODEPAGES(t) (t->num_code)
00222 #define TASK_DATAPAGES(t) (t->num_data)
00223 #define TASK_STACKPAGES(t) (t->num_stack)
00224 #define TASK_ERRNO(t) (t->err_no)
00225 #define TASK_PPID(t) (t->padre->pid)
00226 #define TASK_PARENT(t) (t->padre)
00227
00228 enum estado { TASK_RUNNING, TASK_STOPPED, TASK_INTERRUMPIBLE, TASK_ININTERRUMPIBLE, TASK_ZOMBIE, TASK_CLEAN };
00229
00230 extern task_struct_t *init_task, *pre_init_task;
00231 inline void sleep_init();
00232 inline void wakeup_init();
00233
00234
00235 #define PAGINA_DATA 0 //pagina de datos
00236 #define PAGINA_CODE 1 //pagina de codigo
00237 #define PAGINA_STACK 0 //pagina de stack
00238 #define PAGINA_ALLOC 2 //pagina alocada dinamicamente
00239
00240 struct user_page
00241 {
00242 addr_t dir, vdir;
00243 word count;
00244 dword flags;
00245 struct user_page *next;
00246 };
00247
00248
00249
00250
00251
00252 extern task_struct_t *tareas_inicio;
00253 extern task_struct_t *actual;
00254
00255
00256 task_struct_t *init_new_task(word cs, word ds, dword eip, dword esp, dword eflags, char *descripcion, word prioridad);
00257 task_struct_t *encontrar_proceso_por_pid(pid_t pid);
00258 void tomar_nombre_tarea (const char *viejo, char *nuevo);
00259 inline void dormir_task(task_struct_t *tarea);
00260 inline void despertar_task(task_struct_t *tarea);
00261 int insertar_tarea(task_struct_t *nueva);
00262 int remover_task (task_struct_t *tarea);
00263
00264
00265
00266 #define _reschedule() __asm__ __volatile__("int $0x51")
00267
00268
00269
00270 #define TASK_TEXT 0x80000000
00271 #define TASK_DATA 0x88000000
00272 #define TASK_STACK 0x90000000
00273
00274
00275
00276
00277 #define EXIT_TASK (TASK_TEXT - PAGINA_SIZE)
00278
00279
00280 struct zombie_queue
00281 {
00282 pid_t ppid;
00283 task_struct_t *task_struct;
00284 LIST_DATA (zombie_queue) zombie_queue;
00285 };
00286
00287
00288 #define GET_CONTEXT(task) ((struct int_regs_ext *) ((task->esp0 & 0xfffff000) + PAGINA_SIZE - sizeof(struct int_regs_ext)))
00289
00290
00291
00292 extern int num_mallocs, num_frees;
00293 extern int num_alloc_signals, num_free_signals;
00294
00295 #endif