This source file includes following definitions.
- _get_base
- get_limit
1 #ifndef _SCHED_H
2 #define _SCHED_H
3
4 #define HZ 100
5
6 #define NR_TASKS 64
7 #define TASK_SIZE 0x04000000
8 #define LIBRARY_SIZE 0x00400000
9
10 #if (TASK_SIZE & 0x3fffff)
11 #error "TASK_SIZE must be multiple of 4M"
12 #endif
13
14 #if (LIBRARY_SIZE & 0x3fffff)
15 #error "LIBRARY_SIZE must be a multiple of 4M"
16 #endif
17
18 #if (LIBRARY_SIZE >= (TASK_SIZE/2))
19 #error "LIBRARY_SIZE too damn big!"
20 #endif
21
22 #if (((TASK_SIZE>>16)*NR_TASKS) != 0x10000)
23 #error "TASK_SIZE*NR_TASKS must be 4GB"
24 #endif
25
26 #define LIBRARY_OFFSET (TASK_SIZE - LIBRARY_SIZE)
27
28 #define CT_TO_SECS(x) ((x) / HZ)
29 #define CT_TO_USECS(x) (((x) % HZ) * 1000000/HZ)
30
31 #define FIRST_TASK task[0]
32 #define LAST_TASK task[NR_TASKS-1]
33
34 #include <linux/head.h>
35 #include <linux/fs.h>
36 #include <linux/mm.h>
37 #include <sys/param.h>
38 #include <sys/time.h>
39 #include <sys/resource.h>
40 #include <signal.h>
41
42 #if (NR_OPEN > 32)
43 #error "Currently the close-on-exec-flags and select masks are in one long, max 32 files/proc"
44 #endif
45
46 #define TASK_RUNNING 0
47 #define TASK_INTERRUPTIBLE 1
48 #define TASK_UNINTERRUPTIBLE 2
49 #define TASK_ZOMBIE 3
50 #define TASK_STOPPED 4
51
52 #ifndef NULL
53 #define NULL ((void *) 0)
54 #endif
55
56 extern int copy_page_tables(unsigned long from, unsigned long to, long size);
57 extern int free_page_tables(unsigned long from, unsigned long size);
58
59 extern void sched_init(void);
60 extern void schedule(void);
61 extern void trap_init(void);
62 extern void panic(const char * str);
63 extern int tty_write(unsigned minor,char * buf,int count);
64
65 typedef int (*fn_ptr)();
66
67 struct i387_struct {
68 long cwd;
69 long swd;
70 long twd;
71 long fip;
72 long fcs;
73 long foo;
74 long fos;
75 long st_space[20];
76 };
77
78 struct tss_struct {
79 long back_link;
80 long esp0;
81 long ss0;
82 long esp1;
83 long ss1;
84 long esp2;
85 long ss2;
86 long cr3;
87 long eip;
88 long eflags;
89 long eax,ecx,edx,ebx;
90 long esp;
91 long ebp;
92 long esi;
93 long edi;
94 long es;
95 long cs;
96 long ss;
97 long ds;
98 long fs;
99 long gs;
100 long ldt;
101 long trace_bitmap;
102 struct i387_struct i387;
103 };
104
105 struct task_struct {
106
107 long state;
108 long counter;
109 long priority;
110 long signal;
111 struct sigaction sigaction[32];
112 long blocked;
113
114 int exit_code;
115 unsigned long start_code,end_code,end_data,brk,start_stack;
116 long pid,pgrp,session,leader;
117 int groups[NGROUPS];
118
119
120
121
122
123 struct task_struct *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
124
125
126
127 struct task_struct *next_wait;
128 unsigned short uid,euid,suid;
129 unsigned short gid,egid,sgid;
130 unsigned long timeout,alarm;
131 long utime,stime,cutime,cstime,start_time;
132 struct rlimit rlim[RLIM_NLIMITS];
133 unsigned int flags;
134 unsigned short used_math;
135
136 int link_count;
137 int tty;
138 unsigned short umask;
139 struct inode * pwd;
140 struct inode * root;
141 struct inode * executable;
142 struct inode * library;
143 unsigned long close_on_exec;
144 struct file * filp[NR_OPEN];
145
146 struct desc_struct ldt[3];
147
148 struct tss_struct tss;
149 };
150
151
152
153
154 #define PF_ALIGNWARN 0x00000001
155
156 #define PF_PTRACED 0x00000010
157 #define PF_VM86 0x00000020
158
159
160
161
162
163
164
165 #define INIT_TASK \
166 { 0,15,15, \
167 0,{{},},0, \
168 0,0,0,0,0,0, \
169 0,0,0,0, \
170 {NOGROUP,}, \
171 &init_task.task,NULL,NULL,NULL,NULL, \
172 0,0,0,0,0,0, \
173 0,0,0,0,0,0,0, \
174 { {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}, \
175 {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}, \
176 {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}}, \
177 0, \
178 0, \
179 0,-1,0022,NULL,NULL,NULL,NULL,0, \
180 {NULL,}, \
181 { \
182 {0,0}, \
183 {0x9f,0xc0fa00}, \
184 {0x9f,0xc0f200}, \
185 }, \
186 {0,PAGE_SIZE+(long)&init_task,0x10,0,0,0,0,(long)&pg_dir,\
187 0,0,0,0,0,0,0,0, \
188 0,0,0x17,0x17,0x17,0x17,0x17,0x17, \
189 _LDT(0),0x80000000, \
190 {} \
191 }, \
192 }
193
194 extern struct task_struct *task[NR_TASKS];
195 extern struct task_struct *last_task_used_math;
196 extern struct task_struct *current;
197 extern unsigned long volatile jiffies;
198 extern unsigned long startup_time;
199 extern int jiffies_offset;
200
201 #define CURRENT_TIME (startup_time+(jiffies+jiffies_offset)/HZ)
202
203 extern void add_timer(long jiffies, void (*fn)(void));
204 extern void sleep_on(struct task_struct ** p);
205 extern void interruptible_sleep_on(struct task_struct ** p);
206 extern void wake_up(struct task_struct ** p);
207 extern int in_group_p(gid_t grp);
208
209
210
211
212
213 #define FIRST_TSS_ENTRY 4
214 #define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1)
215 #define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
216 #define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3))
217 #define ltr(n) __asm__("ltr %%ax"::"a" (_TSS(n)))
218 #define lldt(n) __asm__("lldt %%ax"::"a" (_LDT(n)))
219 #define str(n) \
220 __asm__("str %%ax\n\t" \
221 "subl %2,%%eax\n\t" \
222 "shrl $4,%%eax" \
223 :"=a" (n) \
224 :"0" (0),"i" (FIRST_TSS_ENTRY<<3))
225
226
227
228
229
230
231 #define switch_to(n) {\
232 struct {long a,b;} __tmp; \
233 __asm__("cmpl %%ecx,_current\n\t" \
234 "je 1f\n\t" \
235 "movw %%dx,%1\n\t" \
236 "xchgl %%ecx,_current\n\t" \
237 "ljmp %0\n\t" \
238 "cmpl %%ecx,_last_task_used_math\n\t" \
239 "jne 1f\n\t" \
240 "clts\n" \
241 "1:" \
242 ::"m" (*&__tmp.a),"m" (*&__tmp.b), \
243 "d" (_TSS(n)),"c" ((long) task[n]) \
244 :"cx"); \
245 }
246
247 #define PAGE_ALIGN(n) (((n)+0xfff)&0xfffff000)
248
249 #define _set_base(addr,base) \
250 __asm__("movw %%dx,%0\n\t" \
251 "rorl $16,%%edx\n\t" \
252 "movb %%dl,%1\n\t" \
253 "movb %%dh,%2" \
254 ::"m" (*((addr)+2)), \
255 "m" (*((addr)+4)), \
256 "m" (*((addr)+7)), \
257 "d" (base) \
258 :"dx")
259
260 #define _set_limit(addr,limit) \
261 __asm__("movw %%dx,%0\n\t" \
262 "rorl $16,%%edx\n\t" \
263 "movb %1,%%dh\n\t" \
264 "andb $0xf0,%%dh\n\t" \
265 "orb %%dh,%%dl\n\t" \
266 "movb %%dl,%1" \
267 ::"m" (*(addr)), \
268 "m" (*((addr)+6)), \
269 "d" (limit) \
270 :"dx")
271
272 #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )
273 #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 )
274
275 static unsigned long inline _get_base(char * addr)
276 {
277 unsigned long __base;
278 __asm__("movb %3,%%dh\n\t"
279 "movb %2,%%dl\n\t"
280 "shll $16,%%edx\n\t"
281 "movw %1,%%dx"
282 :"=&d" (__base)
283 :"m" (*((addr)+2)),
284 "m" (*((addr)+4)),
285 "m" (*((addr)+7)));
286 return __base;
287 }
288
289 #define get_base(ldt) _get_base( ((char *)&(ldt)) )
290
291 static unsigned long inline get_limit(unsigned long segment)
292 {
293 unsigned long __limit;
294 __asm__("lsll %1,%0"
295 :"=r" (__limit):"r" (segment));
296 return __limit+1;
297 }
298
299 #endif