This source file includes following definitions.
- disable_hlt
- enable_hlt
- hard_idle
- sys_idle
- sys_idle
- cpu_idle
- kb_wait
- hard_reset_now
- show_regs
- exit_thread
- flush_thread
- release_thread
- copy_thread
- dump_fpu
- dump_thread
- sys_fork
- sys_clone
- sys_execve
1
2
3
4
5
6
7
8
9
10
11 #define __KERNEL_SYSCALLS__
12 #include <stdarg.h>
13
14 #include <linux/errno.h>
15 #include <linux/sched.h>
16 #include <linux/kernel.h>
17 #include <linux/mm.h>
18 #include <linux/stddef.h>
19 #include <linux/unistd.h>
20 #include <linux/ptrace.h>
21 #include <linux/malloc.h>
22 #include <linux/ldt.h>
23 #include <linux/user.h>
24 #include <linux/a.out.h>
25 #include <linux/interrupt.h>
26 #include <linux/config.h>
27 #include <linux/unistd.h>
28
29 #include <asm/segment.h>
30 #include <asm/pgtable.h>
31 #include <asm/system.h>
32 #include <asm/io.h>
33 #include <linux/smp.h>
34
35
36 asmlinkage void ret_from_sys_call(void) __asm__("ret_from_sys_call");
37
38 #ifdef CONFIG_APM
39 extern int apm_do_idle(void);
40 extern void apm_do_busy(void);
41 #endif
42
43 static int hlt_counter=0;
44
45 #define HARD_IDLE_TIMEOUT (HZ / 3)
46
47 void disable_hlt(void)
48 {
49 hlt_counter++;
50 }
51
52 void enable_hlt(void)
53 {
54 hlt_counter--;
55 }
56
57 #ifndef __SMP__
58
59 static void hard_idle(void)
60 {
61 while (!need_resched) {
62 if (hlt_works_ok && !hlt_counter) {
63 #ifdef CONFIG_APM
64
65
66
67
68
69 start_bh_atomic();
70 if (!apm_do_idle() && !need_resched)
71 __asm__("hlt");
72 end_bh_atomic();
73 #else
74 __asm__("hlt");
75 #endif
76 }
77 if (need_resched)
78 break;
79 schedule();
80 }
81 #ifdef CONFIG_APM
82 apm_do_busy();
83 #endif
84 }
85
86
87
88
89
90 asmlinkage int sys_idle(void)
91 {
92 unsigned long start_idle = 0;
93
94 if (current->pid != 0)
95 return -EPERM;
96
97 current->counter = -100;
98 for (;;)
99 {
100
101
102
103
104
105 if (!start_idle)
106 start_idle = jiffies;
107 if (jiffies - start_idle > HARD_IDLE_TIMEOUT)
108 {
109 hard_idle();
110 }
111 else
112 {
113 if (hlt_works_ok && !hlt_counter && !need_resched)
114 __asm__("hlt");
115 }
116 if (need_resched)
117 start_idle = 0;
118 schedule();
119 }
120 }
121
122 #else
123
124
125
126
127
128
129 asmlinkage int sys_idle(void)
130 {
131 if(current->pid != 0)
132 return -EPERM;
133 #ifdef __SMP_PROF__
134 smp_spins_sys_idle[smp_processor_id()]+=
135 smp_spins_syscall_cur[smp_processor_id()];
136 #endif
137 current->counter= -100;
138 schedule();
139 return 0;
140 }
141
142
143
144
145
146 int cpu_idle(void *unused)
147 {
148 while(1)
149 {
150 if(cpu_data[smp_processor_id()].hlt_works_ok && !hlt_counter && !need_resched)
151 __asm("hlt");
152 if(0==(0x7fffffff & smp_process_available))
153 continue;
154 while(0x80000000 & smp_process_available);
155 cli();
156 while(set_bit(31,&smp_process_available))
157 while(test_bit(31,&smp_process_available));
158 if (0==(0x7fffffff & smp_process_available)){
159 clear_bit(31,&smp_process_available);
160 sti();
161 continue;
162 }
163 smp_process_available--;
164 clear_bit(31,&smp_process_available);
165 sti();
166 idle();
167 }
168 }
169
170 #endif
171
172
173
174
175
176
177 static long no_idt[2] = {0, 0};
178
179 static inline void kb_wait(void)
180 {
181 int i;
182
183 for (i=0; i<0x10000; i++)
184 if ((inb_p(0x64) & 0x02) == 0)
185 break;
186 }
187
188 void hard_reset_now(void)
189 {
190 int i, j;
191
192 sti();
193
194 pg0[0] = 7;
195 *((unsigned short *)0x472) = 0x1234;
196 for (;;) {
197 for (i=0; i<100; i++) {
198 kb_wait();
199 for(j = 0; j < 100000 ; j++)
200 ;
201 outb(0xfe,0x64);
202 }
203 __asm__ __volatile__("\tlidt %0": "=m" (no_idt));
204 }
205 }
206
207 void show_regs(struct pt_regs * regs)
208 {
209 printk("\n");
210 printk("EIP: %04x:[<%08lx>]",0xffff & regs->cs,regs->eip);
211 if (regs->cs & 3)
212 printk(" ESP: %04x:%08lx",0xffff & regs->ss,regs->esp);
213 printk(" EFLAGS: %08lx\n",regs->eflags);
214 printk("EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
215 regs->eax,regs->ebx,regs->ecx,regs->edx);
216 printk("ESI: %08lx EDI: %08lx EBP: %08lx",
217 regs->esi, regs->edi, regs->ebp);
218 printk(" DS: %04x ES: %04x FS: %04x GS: %04x\n",
219 0xffff & regs->ds,0xffff & regs->es,
220 0xffff & regs->fs,0xffff & regs->gs);
221 }
222
223
224
225
226
227 void exit_thread(void)
228 {
229
230 if (last_task_used_math == current)
231 last_task_used_math = NULL;
232
233 __asm__ __volatile__("mov %w0,%%fs ; mov %w0,%%gs ; lldt %w0"
234 :
235 : "r" (0));
236 current->tss.ldt = 0;
237 if (current->ldt) {
238 void * ldt = current->ldt;
239 current->ldt = NULL;
240 vfree(ldt);
241 }
242 }
243
244 void flush_thread(void)
245 {
246 int i;
247
248 if (current->ldt) {
249 free_page((unsigned long) current->ldt);
250 current->ldt = NULL;
251 for (i=1 ; i<NR_TASKS ; i++) {
252 if (task[i] == current) {
253 set_ldt_desc(gdt+(i<<1)+
254 FIRST_LDT_ENTRY,&default_ldt, 1);
255 load_ldt(i);
256 }
257 }
258 }
259
260 for (i=0 ; i<8 ; i++)
261 current->debugreg[i] = 0;
262 }
263
264 void release_thread(struct task_struct *dead_task)
265 {
266 }
267
268 void copy_thread(int nr, unsigned long clone_flags, unsigned long esp,
269 struct task_struct * p, struct pt_regs * regs)
270 {
271 int i;
272 struct pt_regs * childregs;
273
274 p->tss.es = KERNEL_DS;
275 p->tss.cs = KERNEL_CS;
276 p->tss.ss = KERNEL_DS;
277 p->tss.ds = KERNEL_DS;
278 p->tss.fs = USER_DS;
279 p->tss.gs = KERNEL_DS;
280 p->tss.ss0 = KERNEL_DS;
281 p->tss.esp0 = p->kernel_stack_page + PAGE_SIZE;
282 p->tss.tr = _TSS(nr);
283 childregs = ((struct pt_regs *) (p->kernel_stack_page + PAGE_SIZE)) - 1;
284 p->tss.esp = (unsigned long) childregs;
285 p->tss.eip = (unsigned long) ret_from_sys_call;
286 *childregs = *regs;
287 childregs->eax = 0;
288 childregs->esp = esp;
289 p->tss.back_link = 0;
290 p->tss.eflags = regs->eflags & 0xffffcfff;
291 p->tss.ldt = _LDT(nr);
292 if (p->ldt) {
293 p->ldt = (struct desc_struct*) vmalloc(LDT_ENTRIES*LDT_ENTRY_SIZE);
294 if (p->ldt != NULL)
295 memcpy(p->ldt, current->ldt, LDT_ENTRIES*LDT_ENTRY_SIZE);
296 }
297 set_tss_desc(gdt+(nr<<1)+FIRST_TSS_ENTRY,&(p->tss));
298 if (p->ldt)
299 set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,p->ldt, 512);
300 else
301 set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,&default_ldt, 1);
302 p->tss.bitmap = offsetof(struct thread_struct,io_bitmap);
303 for (i = 0; i < IO_BITMAP_SIZE+1 ; i++)
304 p->tss.io_bitmap[i] = ~0;
305 if (last_task_used_math == current)
306 __asm__("clts ; fnsave %0 ; frstor %0":"=m" (p->tss.i387));
307 }
308
309
310
311
312 int dump_fpu (struct user_i387_struct* fpu)
313 {
314 int fpvalid;
315
316
317
318 if (hard_math) {
319 if ((fpvalid = current->used_math) != 0) {
320 if (last_task_used_math == current)
321 __asm__("clts ; fnsave %0": :"m" (*fpu));
322 else
323 memcpy(fpu,¤t->tss.i387.hard,sizeof(*fpu));
324 }
325 } else {
326
327
328 fpvalid = 0;
329 }
330
331 return fpvalid;
332 }
333
334
335
336
337 void dump_thread(struct pt_regs * regs, struct user * dump)
338 {
339 int i;
340
341
342 dump->magic = CMAGIC;
343 dump->start_code = 0;
344 dump->start_stack = regs->esp & ~(PAGE_SIZE - 1);
345 dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
346 dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> PAGE_SHIFT;
347 dump->u_dsize -= dump->u_tsize;
348 dump->u_ssize = 0;
349 for (i = 0; i < 8; i++)
350 dump->u_debugreg[i] = current->debugreg[i];
351
352 if (dump->start_stack < TASK_SIZE)
353 dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
354
355 dump->regs = *regs;
356
357 dump->u_fpvalid = dump_fpu (&dump->i387);
358 }
359
360 asmlinkage int sys_fork(struct pt_regs regs)
361 {
362 return do_fork(SIGCHLD, regs.esp, ®s);
363 }
364
365 asmlinkage int sys_clone(struct pt_regs regs)
366 {
367 unsigned long clone_flags;
368 unsigned long newsp;
369
370 clone_flags = regs.ebx;
371 newsp = regs.ecx;
372 if (!newsp)
373 newsp = regs.esp;
374 return do_fork(clone_flags, newsp, ®s);
375 }
376
377
378
379
380 asmlinkage int sys_execve(struct pt_regs regs)
381 {
382 int error;
383 char * filename;
384
385 error = getname((char *) regs.ebx, &filename);
386 if (error)
387 return error;
388 error = do_execve(filename, (char **) regs.ecx, (char **) regs.edx, ®s);
389 putname(filename);
390 return error;
391 }