This source file includes following definitions.
- disable_hlt
- enable_hlt
- sys_idle
- kb_wait
- hard_reset_now
- show_regs
- exit_thread
- flush_thread
- copy_thread
- dump_thread
- sys_fork
- sys_clone
- sys_execve
1
2
3
4
5
6
7
8
9
10
11 #include <linux/errno.h>
12 #include <linux/sched.h>
13 #include <linux/kernel.h>
14 #include <linux/mm.h>
15 #include <linux/stddef.h>
16 #include <linux/unistd.h>
17 #include <linux/ptrace.h>
18 #include <linux/malloc.h>
19 #include <linux/ldt.h>
20 #include <linux/user.h>
21 #include <linux/a.out.h>
22
23 #include <asm/segment.h>
24 #include <asm/pgtable.h>
25 #include <asm/system.h>
26 #include <asm/io.h>
27
28 asmlinkage void ret_from_sys_call(void) __asm__("ret_from_sys_call");
29
30 static int hlt_counter=0;
31
32 void disable_hlt(void)
33 {
34 hlt_counter++;
35 }
36
37 void enable_hlt(void)
38 {
39 hlt_counter--;
40 }
41
42
43
44
45 asmlinkage int sys_idle(void)
46 {
47 int i;
48
49 if (current->pid != 0)
50 return -EPERM;
51
52
53 for (i = 0 ; i < 768 ; i++)
54 pgd_clear(swapper_pg_dir + i);
55
56
57 current->counter = -100;
58 for (;;) {
59 if (hlt_works_ok && !hlt_counter && !need_resched)
60 __asm__("hlt");
61 schedule();
62 }
63 }
64
65
66
67
68
69
70 static long no_idt[2] = {0, 0};
71
72 static inline void kb_wait(void)
73 {
74 int i;
75
76 for (i=0; i<0x10000; i++)
77 if ((inb_p(0x64) & 0x02) == 0)
78 break;
79 }
80
81 void hard_reset_now(void)
82 {
83 int i, j;
84
85 sti();
86
87 pg0[0] = 7;
88 *((unsigned short *)0x472) = 0x1234;
89 for (;;) {
90 for (i=0; i<100; i++) {
91 kb_wait();
92 for(j = 0; j < 100000 ; j++)
93 ;
94 outb(0xfe,0x64);
95 }
96 __asm__ __volatile__("\tlidt %0": "=m" (no_idt));
97 }
98 }
99
100 void show_regs(struct pt_regs * regs)
101 {
102 printk("\n");
103 printk("EIP: %04x:%08lx",0xffff & regs->cs,regs->eip);
104 if (regs->cs & 3)
105 printk(" ESP: %04x:%08lx",0xffff & regs->ss,regs->esp);
106 printk(" EFLAGS: %08lx\n",regs->eflags);
107 printk("EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
108 regs->eax,regs->ebx,regs->ecx,regs->edx);
109 printk("ESI: %08lx EDI: %08lx EBP: %08lx",
110 regs->esi, regs->edi, regs->ebp);
111 printk(" DS: %04x ES: %04x FS: %04x GS: %04x\n",
112 0xffff & regs->ds,0xffff & regs->es,
113 0xffff & regs->fs,0xffff & regs->gs);
114 }
115
116
117
118
119 void exit_thread(void)
120 {
121
122 __asm__ __volatile__("mov %w0,%%fs ; mov %w0,%%gs ; lldt %w0"
123 :
124 : "r" (0));
125 current->tss.ldt = 0;
126 if (current->ldt) {
127 void * ldt = current->ldt;
128 current->ldt = NULL;
129 vfree(ldt);
130 }
131 }
132
133 void flush_thread(void)
134 {
135 int i;
136
137 if (current->ldt) {
138 free_page((unsigned long) current->ldt);
139 current->ldt = NULL;
140 for (i=1 ; i<NR_TASKS ; i++) {
141 if (task[i] == current) {
142 set_ldt_desc(gdt+(i<<1)+
143 FIRST_LDT_ENTRY,&default_ldt, 1);
144 load_ldt(i);
145 }
146 }
147 }
148
149 for (i=0 ; i<8 ; i++)
150 current->debugreg[i] = 0;
151 }
152
153 void copy_thread(int nr, unsigned long clone_flags, unsigned long esp,
154 struct task_struct * p, struct pt_regs * regs)
155 {
156 int i;
157 struct pt_regs * childregs;
158
159 p->tss.es = KERNEL_DS;
160 p->tss.cs = KERNEL_CS;
161 p->tss.ss = KERNEL_DS;
162 p->tss.ds = KERNEL_DS;
163 p->tss.fs = USER_DS;
164 p->tss.gs = KERNEL_DS;
165 p->tss.ss0 = KERNEL_DS;
166 p->tss.esp0 = p->kernel_stack_page + PAGE_SIZE;
167 p->tss.tr = _TSS(nr);
168 childregs = ((struct pt_regs *) (p->kernel_stack_page + PAGE_SIZE)) - 1;
169 p->tss.esp = (unsigned long) childregs;
170 p->tss.eip = (unsigned long) ret_from_sys_call;
171 *childregs = *regs;
172 childregs->eax = 0;
173 childregs->esp = esp;
174 p->tss.back_link = 0;
175 p->tss.eflags = regs->eflags & 0xffffcfff;
176 p->tss.ldt = _LDT(nr);
177 if (p->ldt) {
178 p->ldt = (struct desc_struct*) vmalloc(LDT_ENTRIES*LDT_ENTRY_SIZE);
179 if (p->ldt != NULL)
180 memcpy(p->ldt, current->ldt, LDT_ENTRIES*LDT_ENTRY_SIZE);
181 }
182 set_tss_desc(gdt+(nr<<1)+FIRST_TSS_ENTRY,&(p->tss));
183 if (p->ldt)
184 set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,p->ldt, 512);
185 else
186 set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,&default_ldt, 1);
187 p->tss.bitmap = offsetof(struct thread_struct,io_bitmap);
188 for (i = 0; i < IO_BITMAP_SIZE+1 ; i++)
189 p->tss.io_bitmap[i] = ~0;
190 if (last_task_used_math == current)
191 __asm__("clts ; fnsave %0 ; frstor %0":"=m" (p->tss.i387));
192 }
193
194
195
196
197 void dump_thread(struct pt_regs * regs, struct user * dump)
198 {
199 int i;
200
201
202 dump->magic = CMAGIC;
203 dump->start_code = 0;
204 dump->start_stack = regs->esp & ~(PAGE_SIZE - 1);
205 dump->u_tsize = ((unsigned long) current->mm->end_code) >> 12;
206 dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> 12;
207 dump->u_dsize -= dump->u_tsize;
208 dump->u_ssize = 0;
209 for (i = 0; i < 8; i++)
210 dump->u_debugreg[i] = current->debugreg[i];
211
212 if (dump->start_stack < TASK_SIZE)
213 dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> 12;
214
215 dump->regs = *regs;
216
217
218
219 if (hard_math) {
220 if ((dump->u_fpvalid = current->used_math) != 0) {
221 if (last_task_used_math == current)
222 __asm__("clts ; fnsave %0": :"m" (dump->i387));
223 else
224 memcpy(&dump->i387,¤t->tss.i387.hard,sizeof(dump->i387));
225 }
226 } else {
227
228
229 dump->u_fpvalid = 0;
230 }
231 }
232
233 asmlinkage int sys_fork(struct pt_regs regs)
234 {
235 return do_fork(COPYVM | SIGCHLD, regs.esp, ®s);
236 }
237
238 asmlinkage int sys_clone(struct pt_regs regs)
239 {
240 #ifdef CLONE_ACTUALLY_WORKS_OK
241 unsigned long clone_flags;
242 unsigned long newsp;
243
244 newsp = regs.ebx;
245 clone_flags = regs.ecx;
246 if (!newsp)
247 newsp = regs.esp;
248 if (newsp == regs.esp)
249 clone_flags |= COPYVM;
250 return do_fork(clone_flags, newsp, ®s);
251 #else
252 return -ENOSYS;
253 #endif
254 }
255
256
257
258
259 asmlinkage int sys_execve(struct pt_regs regs)
260 {
261 int error;
262 char * filename;
263
264 error = getname((char *) regs.ebx, &filename);
265 if (error)
266 return error;
267 error = do_execve(filename, (char **) regs.ecx, (char **) regs.edx, ®s);
268 putname(filename);
269 return error;
270 }