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