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_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->orig_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 #define IS_CLONE (regs->orig_eax == __NR_clone)
154
155 unsigned long copy_thread(int nr, unsigned long clone_flags, struct task_struct * p, struct pt_regs * regs)
156 {
157 int i;
158 struct pt_regs * childregs;
159
160 p->tss.es = KERNEL_DS;
161 p->tss.cs = KERNEL_CS;
162 p->tss.ss = KERNEL_DS;
163 p->tss.ds = KERNEL_DS;
164 p->tss.fs = USER_DS;
165 p->tss.gs = KERNEL_DS;
166 p->tss.ss0 = KERNEL_DS;
167 p->tss.esp0 = p->kernel_stack_page + PAGE_SIZE;
168 p->tss.tr = _TSS(nr);
169 childregs = ((struct pt_regs *) (p->kernel_stack_page + PAGE_SIZE)) - 1;
170 p->tss.esp = (unsigned long) childregs;
171 p->tss.eip = (unsigned long) ret_from_sys_call;
172 *childregs = *regs;
173 childregs->eax = 0;
174 p->tss.back_link = 0;
175 p->tss.eflags = regs->eflags & 0xffffcfff;
176 if (IS_CLONE) {
177 if (regs->ebx)
178 childregs->esp = regs->ebx;
179 clone_flags = regs->ecx;
180 if (childregs->esp == regs->esp)
181 clone_flags |= COPYVM;
182 }
183 p->tss.ldt = _LDT(nr);
184 if (p->ldt) {
185 p->ldt = (struct desc_struct*) vmalloc(LDT_ENTRIES*LDT_ENTRY_SIZE);
186 if (p->ldt != NULL)
187 memcpy(p->ldt, current->ldt, LDT_ENTRIES*LDT_ENTRY_SIZE);
188 }
189 set_tss_desc(gdt+(nr<<1)+FIRST_TSS_ENTRY,&(p->tss));
190 if (p->ldt)
191 set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,p->ldt, 512);
192 else
193 set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,&default_ldt, 1);
194 p->tss.bitmap = offsetof(struct thread_struct,io_bitmap);
195 for (i = 0; i < IO_BITMAP_SIZE+1 ; i++)
196 p->tss.io_bitmap[i] = ~0;
197 if (last_task_used_math == current)
198 __asm__("clts ; fnsave %0 ; frstor %0":"=m" (p->tss.i387));
199 return clone_flags;
200 }
201
202
203
204
205 void dump_thread(struct pt_regs * regs, struct user * dump)
206 {
207 int i;
208
209
210 dump->magic = CMAGIC;
211 dump->start_code = 0;
212 dump->start_stack = regs->esp & ~(PAGE_SIZE - 1);
213 dump->u_tsize = ((unsigned long) current->mm->end_code) >> 12;
214 dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> 12;
215 dump->u_dsize -= dump->u_tsize;
216 dump->u_ssize = 0;
217 for (i = 0; i < 8; i++)
218 dump->u_debugreg[i] = current->debugreg[i];
219
220 if (dump->start_stack < TASK_SIZE)
221 dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> 12;
222
223 dump->regs = *regs;
224
225
226
227 if (hard_math) {
228 if ((dump->u_fpvalid = current->used_math) != 0) {
229 if (last_task_used_math == current)
230 __asm__("clts ; fnsave %0": :"m" (dump->i387));
231 else
232 memcpy(&dump->i387,¤t->tss.i387.hard,sizeof(dump->i387));
233 }
234 } else {
235
236
237 dump->u_fpvalid = 0;
238 }
239 }
240
241
242
243
244 asmlinkage int sys_execve(struct pt_regs regs)
245 {
246 int error;
247 char * filename;
248
249 error = getname((char *) regs.ebx, &filename);
250 if (error)
251 return error;
252 error = do_execve(filename, (char **) regs.ecx, (char **) regs.edx, ®s);
253 putname(filename);
254 return error;
255 }