New developer version 0.6.8; added select () function; added demonstrating example...
[ZeXOS.git] / kernel / include / task.h
blob3dc8d574f5d8b27d2aba7cb80c5beafeb122369e
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef _TASK_H
22 #define _TASK_H
24 #include <build.h>
25 #include <setjmp.h>
26 #include <spinlock.h>
27 #include <paging.h>
28 #include <mytypes.h>
30 /* jmp_buf (E)IP and (E)SP register names for various environments:
31 Tinylib TurboC DJGPP Linux (glibc5) */
32 #define JMPBUF_IP eip /* j_ip __eip __pc */
33 #define JMPBUF_SP esp /* j_sp __esp __sp */
34 #define JMPBUF_FLAGS eflags /* j_flag __eflags ? */
36 #ifdef ARCH_i386
37 #define USER_STACK_SIZE 10240
38 #endif
40 #ifdef ARCH_arm
41 #define USER_STACK_SIZE 8192
42 #endif
44 /* Task structure */
45 typedef struct task_context {
46 struct task_context *next, *prev;
48 char name[25];
49 unsigned char stacks[USER_STACK_SIZE];
50 #ifdef ARCH_i386
51 jmp_buf state;
52 #endif
53 #ifdef ARCH_arm
54 unsigned int *sp;
55 unsigned int *entry;
56 #endif
57 unsigned char priority;
58 unsigned char attick;
59 unsigned short id;
60 unsigned lasttick;
62 spinlock_t *spinlock;
63 page_ent_t *page_cover;
65 enum {
66 TS_NULL = 0, TS_RUNNABLE = 1, TS_BLOCKED = 2, TS_ZOMBIE = 3
67 } status;
68 } task_t;
71 extern task_t *_curr_task;
72 extern task_t *task_create (char *name, unsigned entry, unsigned priority);
73 extern bool task_done (task_t *task);
74 extern task_t *task_find (unsigned short id);
76 #endif