Import 2.1.81
[davej-history.git] / arch / i386 / kernel / entry.S
bloba13a96dab026714837643e7f00bf46acb0cd7c17
1 /*
2  *  linux/arch/i386/entry.S
3  *
4  *  Copyright (C) 1991, 1992  Linus Torvalds
5  */
7 /*
8  * entry.S contains the system-call and fault low-level handling routines.
9  * This also contains the timer-interrupt handler, as well as all interrupts
10  * and faults that can result in a task-switch.
11  *
12  * NOTE: This code handles signal-recognition, which happens every time
13  * after a timer-interrupt and after each system call.
14  *
15  * I changed all the .align's to 4 (16 byte alignment), as that's faster
16  * on a 486.
17  *
18  * Stack layout in 'ret_from_system_call':
19  *      ptrace needs to have all regs on the stack.
20  *      if the order here is changed, it needs to be
21  *      updated in fork.c:copy_process, signal.c:do_signal,
22  *      ptrace.c and ptrace.h
23  *
24  *       0(%esp) - %ebx
25  *       4(%esp) - %ecx
26  *       8(%esp) - %edx
27  *       C(%esp) - %esi
28  *      10(%esp) - %edi
29  *      14(%esp) - %ebp
30  *      18(%esp) - %eax
31  *      1C(%esp) - %ds
32  *      20(%esp) - %es
33  *      24(%esp) - orig_eax
34  *      28(%esp) - %eip
35  *      2C(%esp) - %cs
36  *      30(%esp) - %eflags
37  *      34(%esp) - %oldesp
38  *      38(%esp) - %oldss
39  *
40  * "current" is in register %ebx during any slow entries.
41  */
43 #include <linux/sys.h>
44 #include <linux/linkage.h>
45 #include <asm/segment.h>
46 #define ASSEMBLY
47 #include <asm/smp.h>
49 EBX             = 0x00
50 ECX             = 0x04
51 EDX             = 0x08
52 ESI             = 0x0C
53 EDI             = 0x10
54 EBP             = 0x14
55 EAX             = 0x18
56 DS              = 0x1C
57 ES              = 0x20
58 ORIG_EAX        = 0x24
59 EIP             = 0x28
60 CS              = 0x2C
61 EFLAGS          = 0x30
62 OLDESP          = 0x34
63 OLDSS           = 0x38
65 CF_MASK         = 0x00000001
66 IF_MASK         = 0x00000200
67 NT_MASK         = 0x00004000
68 VM_MASK         = 0x00020000
71  * these are offsets into the task-struct.
72  */
73 state           =  0
74 flags           =  4
75 sigpending      =  8
76 addr_limit      = 12
77 exec_domain     = 16
79 ENOSYS = 38
82 #define SAVE_ALL \
83         cld; \
84         push %es; \
85         push %ds; \
86         pushl %eax; \
87         pushl %ebp; \
88         pushl %edi; \
89         pushl %esi; \
90         pushl %edx; \
91         pushl %ecx; \
92         pushl %ebx; \
93         movl $(__KERNEL_DS),%edx; \
94         mov %dx,%ds; \
95         mov %dx,%es;
97 #define RESTORE_ALL \
98         popl %ebx; \
99         popl %ecx; \
100         popl %edx; \
101         popl %esi; \
102         popl %edi; \
103         popl %ebp; \
104         popl %eax; \
105         pop %ds; \
106         pop %es; \
107         addl $4,%esp; \
108         iret
110 #define GET_CURRENT(reg) \
111         movl %esp, reg; \
112         andl $-8192, reg;
114 ENTRY(lcall7)
115         pushfl                  # We get a different stack layout with call gates,
116         pushl %eax              # which has to be cleaned up later..
117         SAVE_ALL
118         movl EIP(%esp),%eax     # due to call gates, this is eflags, not eip..
119         movl CS(%esp),%edx      # this is eip..
120         movl EFLAGS(%esp),%ecx  # and this is cs..
121         movl %eax,EFLAGS(%esp)  #
122         movl %edx,EIP(%esp)     # Now we move them to their "normal" places
123         movl %ecx,CS(%esp)      #
124         movl %esp,%ebx
125         pushl %ebx
126         andl $-8192,%ebx        # GET_CURRENT
127         movl exec_domain(%ebx),%edx     # Get the execution domain
128         movl 4(%edx),%edx       # Get the lcall7 handler for the domain
129         call *%edx
130         popl %eax
131         jmp ret_from_sys_call
134 #ifdef __SMP__
135         ALIGN
136         .globl  ret_from_smpfork
137 ret_from_smpfork:
138         GET_CURRENT(%ebx)
139         btrl    $0, SYMBOL_NAME(scheduler_lock)
140         jmp     ret_from_sys_call
141 #endif /* __SMP__ */
144  * Return to user mode is not as complex as all this looks,
145  * but we want the default path for a system call return to
146  * go as quickly as possible which is why some of this is
147  * less clear than it otherwise should be.
148  */
150 ENTRY(system_call)
151         pushl %eax                      # save orig_eax
152         SAVE_ALL
153         GET_CURRENT(%ebx)
154         cmpl $(NR_syscalls),%eax
155         jae badsys
156         testb $0x20,flags(%ebx)         # PF_TRACESYS
157         jne tracesys
158         call SYMBOL_NAME(sys_call_table)(,%eax,4)
159         movl %eax,EAX(%esp)             # save the return value
160         ALIGN
161         .globl ret_from_sys_call
162         .globl ret_from_intr
163 ret_from_sys_call:
164         movl SYMBOL_NAME(bh_mask),%eax
165         andl SYMBOL_NAME(bh_active),%eax
166         jne handle_bottom_half
167 ret_with_reschedule:
168         cmpl $0,SYMBOL_NAME(need_resched)
169         jne reschedule
170         cmpl $0,sigpending(%ebx)
171         jne signal_return
172         RESTORE_ALL
173         ALIGN
174 signal_return:
175         testl $(VM_MASK),EFLAGS(%esp)
176         pushl %esp
177         jne v86_signal_return
178         pushl $0
179         call SYMBOL_NAME(do_signal)
180         addl $8,%esp
181         RESTORE_ALL
182         ALIGN
183 v86_signal_return:
184         call SYMBOL_NAME(save_v86_state)
185         movl %eax,%esp
186         pushl %eax
187         pushl $0
188         call SYMBOL_NAME(do_signal)
189         addl $8,%esp
190         RESTORE_ALL
191         ALIGN
192 tracesys:
193         movl $-ENOSYS,EAX(%esp)
194         call SYMBOL_NAME(syscall_trace)
195         movl ORIG_EAX(%esp),%eax
196         call SYMBOL_NAME(sys_call_table)(,%eax,4)
197         movl %eax,EAX(%esp)             # save the return value
198         call SYMBOL_NAME(syscall_trace)
199         jmp ret_from_sys_call
200 badsys:
201         movl $-ENOSYS,EAX(%esp)
202         jmp ret_from_sys_call
204         ALIGN
205 ret_from_exception:
206         movl SYMBOL_NAME(bh_mask),%eax
207         andl SYMBOL_NAME(bh_active),%eax
208         jne handle_bottom_half
209         ALIGN
210 ret_from_intr:
211         GET_CURRENT(%ebx)
212         movl EFLAGS(%esp),%eax          # mix EFLAGS and CS
213         movb CS(%esp),%al
214         testl $(VM_MASK | 3),%eax       # return to VM86 mode or non-supervisor?
215         jne ret_with_reschedule
216         RESTORE_ALL
218         ALIGN
219 handle_bottom_half:
220         pushl $ret_from_intr
221         jmp SYMBOL_NAME(do_bottom_half)
223         ALIGN
224 reschedule:
225         pushl $ret_from_sys_call
226         jmp SYMBOL_NAME(schedule)    # test
229 ENTRY(divide_error)
230         pushl $0                # no error code
231         pushl $ SYMBOL_NAME(do_divide_error)
232         ALIGN
233 error_code:
234         push %ds
235         pushl %eax
236         xorl %eax,%eax
237         pushl %ebp
238         pushl %edi
239         pushl %esi
240         pushl %edx
241         decl %eax                       # eax = -1
242         pushl %ecx
243         pushl %ebx
244         xorl %ecx,%ecx                  # zero ecx
245         cld
246         mov %es,%cx                     # get the lower order bits of es
247         xchgl %eax, ORIG_EAX(%esp)      # orig_eax (get the error code. )
248         movl %esp,%edx
249         xchgl %ecx, ES(%esp)            # get the address and save es.
250         pushl %eax                      # push the error code
251         pushl %edx
252         movl $(__KERNEL_DS),%edx
253         mov %dx,%ds
254         mov %dx,%es
255         GET_CURRENT(%ebx)
256         call *%ecx
257         addl $8,%esp
258         jmp ret_from_exception
260 ENTRY(coprocessor_error)
261         pushl $0
262         pushl $ SYMBOL_NAME(do_coprocessor_error)
263         jmp error_code
265 ENTRY(device_not_available)
266         pushl $-1               # mark this as an int
267         SAVE_ALL
268         GET_CURRENT(%ebx)
269         pushl $ret_from_exception
270         movl %cr0,%eax
271         testl $0x4,%eax                 # EM (math emulation bit)
272         je SYMBOL_NAME(math_state_restore)
273         pushl $0                # temporary storage for ORIG_EIP
274         call  SYMBOL_NAME(math_emulate)
275         addl $4,%esp
276         ret
278 ENTRY(debug)
279         pushl $0
280         pushl $ SYMBOL_NAME(do_debug)
281         jmp error_code
283 ENTRY(nmi)
284         pushl $0
285         pushl $ SYMBOL_NAME(do_nmi)
286         jmp error_code
288 ENTRY(int3)
289         pushl $0
290         pushl $ SYMBOL_NAME(do_int3)
291         jmp error_code
293 ENTRY(overflow)
294         pushl $0
295         pushl $ SYMBOL_NAME(do_overflow)
296         jmp error_code
298 ENTRY(bounds)
299         pushl $0
300         pushl $ SYMBOL_NAME(do_bounds)
301         jmp error_code
303 ENTRY(invalid_op)
304         pushl $0
305         pushl $ SYMBOL_NAME(do_invalid_op)
306         jmp error_code
308 ENTRY(coprocessor_segment_overrun)
309         pushl $0
310         pushl $ SYMBOL_NAME(do_coprocessor_segment_overrun)
311         jmp error_code
313 ENTRY(reserved)
314         pushl $0
315         pushl $ SYMBOL_NAME(do_reserved)
316         jmp error_code
318 ENTRY(double_fault)
319         pushl $ SYMBOL_NAME(do_double_fault)
320         jmp error_code
322 ENTRY(invalid_TSS)
323         pushl $ SYMBOL_NAME(do_invalid_TSS)
324         jmp error_code
326 ENTRY(segment_not_present)
327         pushl $ SYMBOL_NAME(do_segment_not_present)
328         jmp error_code
330 ENTRY(stack_segment)
331         pushl $ SYMBOL_NAME(do_stack_segment)
332         jmp error_code
334 ENTRY(general_protection)
335         pushl $ SYMBOL_NAME(do_general_protection)
336         jmp error_code
338 ENTRY(alignment_check)
339         pushl $ SYMBOL_NAME(do_alignment_check)
340         jmp error_code
342 ENTRY(page_fault)
343         pushl $ SYMBOL_NAME(do_page_fault)
344         jmp error_code
346 ENTRY(spurious_interrupt_bug)
347         pushl $0
348         pushl $ SYMBOL_NAME(do_spurious_interrupt_bug)
349         jmp error_code
351 .data
352 ENTRY(sys_call_table)
353         .long SYMBOL_NAME(sys_setup)            /* 0 */
354         .long SYMBOL_NAME(sys_exit)
355         .long SYMBOL_NAME(sys_fork)
356         .long SYMBOL_NAME(sys_read)
357         .long SYMBOL_NAME(sys_write)
358         .long SYMBOL_NAME(sys_open)             /* 5 */
359         .long SYMBOL_NAME(sys_close)
360         .long SYMBOL_NAME(sys_waitpid)
361         .long SYMBOL_NAME(sys_creat)
362         .long SYMBOL_NAME(sys_link)
363         .long SYMBOL_NAME(sys_unlink)           /* 10 */
364         .long SYMBOL_NAME(sys_execve)
365         .long SYMBOL_NAME(sys_chdir)
366         .long SYMBOL_NAME(sys_time)
367         .long SYMBOL_NAME(sys_mknod)
368         .long SYMBOL_NAME(sys_chmod)            /* 15 */
369         .long SYMBOL_NAME(sys_chown)
370         .long SYMBOL_NAME(sys_ni_syscall)                               /* old break syscall holder */
371         .long SYMBOL_NAME(sys_stat)
372         .long SYMBOL_NAME(sys_lseek)
373         .long SYMBOL_NAME(sys_getpid)           /* 20 */
374         .long SYMBOL_NAME(sys_mount)
375         .long SYMBOL_NAME(sys_umount)
376         .long SYMBOL_NAME(sys_setuid)
377         .long SYMBOL_NAME(sys_getuid)
378         .long SYMBOL_NAME(sys_stime)            /* 25 */
379         .long SYMBOL_NAME(sys_ptrace)
380         .long SYMBOL_NAME(sys_alarm)
381         .long SYMBOL_NAME(sys_fstat)
382         .long SYMBOL_NAME(sys_pause)
383         .long SYMBOL_NAME(sys_utime)            /* 30 */
384         .long SYMBOL_NAME(sys_ni_syscall)                               /* old stty syscall holder */
385         .long SYMBOL_NAME(sys_ni_syscall)                               /* old gtty syscall holder */
386         .long SYMBOL_NAME(sys_access)
387         .long SYMBOL_NAME(sys_nice)
388         .long SYMBOL_NAME(sys_ni_syscall)       /* 35 */                /* old ftime syscall holder */
389         .long SYMBOL_NAME(sys_sync)
390         .long SYMBOL_NAME(sys_kill)
391         .long SYMBOL_NAME(sys_rename)
392         .long SYMBOL_NAME(sys_mkdir)
393         .long SYMBOL_NAME(sys_rmdir)            /* 40 */
394         .long SYMBOL_NAME(sys_dup)
395         .long SYMBOL_NAME(sys_pipe)
396         .long SYMBOL_NAME(sys_times)
397         .long SYMBOL_NAME(sys_ni_syscall)                               /* old prof syscall holder */
398         .long SYMBOL_NAME(sys_brk)              /* 45 */
399         .long SYMBOL_NAME(sys_setgid)
400         .long SYMBOL_NAME(sys_getgid)
401         .long SYMBOL_NAME(sys_signal)
402         .long SYMBOL_NAME(sys_geteuid)
403         .long SYMBOL_NAME(sys_getegid)          /* 50 */
404         .long SYMBOL_NAME(sys_acct)
405         .long SYMBOL_NAME(sys_ni_syscall)                               /* old phys syscall holder */
406         .long SYMBOL_NAME(sys_ni_syscall)                               /* old lock syscall holder */
407         .long SYMBOL_NAME(sys_ioctl)
408         .long SYMBOL_NAME(sys_fcntl)            /* 55 */
409         .long SYMBOL_NAME(sys_ni_syscall)                               /* old mpx syscall holder */
410         .long SYMBOL_NAME(sys_setpgid)
411         .long SYMBOL_NAME(sys_ni_syscall)                               /* old ulimit syscall holder */
412         .long SYMBOL_NAME(sys_olduname)
413         .long SYMBOL_NAME(sys_umask)            /* 60 */
414         .long SYMBOL_NAME(sys_chroot)
415         .long SYMBOL_NAME(sys_ustat)
416         .long SYMBOL_NAME(sys_dup2)
417         .long SYMBOL_NAME(sys_getppid)
418         .long SYMBOL_NAME(sys_getpgrp)          /* 65 */
419         .long SYMBOL_NAME(sys_setsid)
420         .long SYMBOL_NAME(sys_sigaction)
421         .long SYMBOL_NAME(sys_sgetmask)
422         .long SYMBOL_NAME(sys_ssetmask)
423         .long SYMBOL_NAME(sys_setreuid)         /* 70 */
424         .long SYMBOL_NAME(sys_setregid)
425         .long SYMBOL_NAME(sys_sigsuspend)
426         .long SYMBOL_NAME(sys_sigpending)
427         .long SYMBOL_NAME(sys_sethostname)
428         .long SYMBOL_NAME(sys_setrlimit)        /* 75 */
429         .long SYMBOL_NAME(sys_getrlimit)
430         .long SYMBOL_NAME(sys_getrusage)
431         .long SYMBOL_NAME(sys_gettimeofday)
432         .long SYMBOL_NAME(sys_settimeofday)
433         .long SYMBOL_NAME(sys_getgroups)        /* 80 */
434         .long SYMBOL_NAME(sys_setgroups)
435         .long SYMBOL_NAME(old_select)
436         .long SYMBOL_NAME(sys_symlink)
437         .long SYMBOL_NAME(sys_lstat)
438         .long SYMBOL_NAME(sys_readlink)         /* 85 */
439         .long SYMBOL_NAME(sys_uselib)
440         .long SYMBOL_NAME(sys_swapon)
441         .long SYMBOL_NAME(sys_reboot)
442         .long SYMBOL_NAME(old_readdir)
443         .long SYMBOL_NAME(old_mmap)             /* 90 */
444         .long SYMBOL_NAME(sys_munmap)
445         .long SYMBOL_NAME(sys_truncate)
446         .long SYMBOL_NAME(sys_ftruncate)
447         .long SYMBOL_NAME(sys_fchmod)
448         .long SYMBOL_NAME(sys_fchown)           /* 95 */
449         .long SYMBOL_NAME(sys_getpriority)
450         .long SYMBOL_NAME(sys_setpriority)
451         .long SYMBOL_NAME(sys_ni_syscall)                               /* old profil syscall holder */
452         .long SYMBOL_NAME(sys_statfs)
453         .long SYMBOL_NAME(sys_fstatfs)          /* 100 */
454         .long SYMBOL_NAME(sys_ioperm)
455         .long SYMBOL_NAME(sys_socketcall)
456         .long SYMBOL_NAME(sys_syslog)
457         .long SYMBOL_NAME(sys_setitimer)
458         .long SYMBOL_NAME(sys_getitimer)        /* 105 */
459         .long SYMBOL_NAME(sys_newstat)
460         .long SYMBOL_NAME(sys_newlstat)
461         .long SYMBOL_NAME(sys_newfstat)
462         .long SYMBOL_NAME(sys_uname)
463         .long SYMBOL_NAME(sys_iopl)             /* 110 */
464         .long SYMBOL_NAME(sys_vhangup)
465         .long SYMBOL_NAME(sys_idle)
466         .long SYMBOL_NAME(sys_vm86old)
467         .long SYMBOL_NAME(sys_wait4)
468         .long SYMBOL_NAME(sys_swapoff)          /* 115 */
469         .long SYMBOL_NAME(sys_sysinfo)
470         .long SYMBOL_NAME(sys_ipc)
471         .long SYMBOL_NAME(sys_fsync)
472         .long SYMBOL_NAME(sys_sigreturn)
473         .long SYMBOL_NAME(sys_clone)            /* 120 */
474         .long SYMBOL_NAME(sys_setdomainname)
475         .long SYMBOL_NAME(sys_newuname)
476         .long SYMBOL_NAME(sys_modify_ldt)
477         .long SYMBOL_NAME(sys_adjtimex)
478         .long SYMBOL_NAME(sys_mprotect)         /* 125 */
479         .long SYMBOL_NAME(sys_sigprocmask)
480         .long SYMBOL_NAME(sys_create_module)
481         .long SYMBOL_NAME(sys_init_module)
482         .long SYMBOL_NAME(sys_delete_module)
483         .long SYMBOL_NAME(sys_get_kernel_syms)  /* 130 */
484         .long SYMBOL_NAME(sys_quotactl)
485         .long SYMBOL_NAME(sys_getpgid)
486         .long SYMBOL_NAME(sys_fchdir)
487         .long SYMBOL_NAME(sys_bdflush)
488         .long SYMBOL_NAME(sys_sysfs)            /* 135 */
489         .long SYMBOL_NAME(sys_personality)
490         .long SYMBOL_NAME(sys_ni_syscall)       /* for afs_syscall */
491         .long SYMBOL_NAME(sys_setfsuid)
492         .long SYMBOL_NAME(sys_setfsgid)
493         .long SYMBOL_NAME(sys_llseek)           /* 140 */
494         .long SYMBOL_NAME(sys_getdents)
495         .long SYMBOL_NAME(sys_select)
496         .long SYMBOL_NAME(sys_flock)
497         .long SYMBOL_NAME(sys_msync)
498         .long SYMBOL_NAME(sys_readv)            /* 145 */
499         .long SYMBOL_NAME(sys_writev)
500         .long SYMBOL_NAME(sys_getsid)
501         .long SYMBOL_NAME(sys_fdatasync)
502         .long SYMBOL_NAME(sys_sysctl)
503         .long SYMBOL_NAME(sys_mlock)            /* 150 */
504         .long SYMBOL_NAME(sys_munlock)
505         .long SYMBOL_NAME(sys_mlockall)
506         .long SYMBOL_NAME(sys_munlockall)
507         .long SYMBOL_NAME(sys_sched_setparam)
508         .long SYMBOL_NAME(sys_sched_getparam)   /* 155 */
509         .long SYMBOL_NAME(sys_sched_setscheduler)
510         .long SYMBOL_NAME(sys_sched_getscheduler)
511         .long SYMBOL_NAME(sys_sched_yield)
512         .long SYMBOL_NAME(sys_sched_get_priority_max)
513         .long SYMBOL_NAME(sys_sched_get_priority_min)  /* 160 */
514         .long SYMBOL_NAME(sys_sched_rr_get_interval)
515         .long SYMBOL_NAME(sys_nanosleep)
516         .long SYMBOL_NAME(sys_mremap)
517         .long SYMBOL_NAME(sys_setresuid)
518         .long SYMBOL_NAME(sys_getresuid)        /* 165 */
519         .long SYMBOL_NAME(sys_vm86)
520         .long SYMBOL_NAME(sys_query_module)
521         .long SYMBOL_NAME(sys_poll)
522         .long SYMBOL_NAME(sys_nfsservctl)
523         .long SYMBOL_NAME(sys_setresgid)        /* 170 */
524         .long SYMBOL_NAME(sys_getresgid)
525         .long SYMBOL_NAME(sys_prctl)
526         .long SYMBOL_NAME(sys_rt_sigreturn)
527         .long SYMBOL_NAME(sys_rt_sigaction)
528         .long SYMBOL_NAME(sys_rt_sigprocmask)   /* 175 */
529         .long SYMBOL_NAME(sys_rt_sigpending)
530         .long SYMBOL_NAME(sys_rt_sigtimedwait)
531         .long SYMBOL_NAME(sys_rt_sigqueueinfo)
532         .long SYMBOL_NAME(sys_rt_sigsuspend)
533         .long SYMBOL_NAME(sys_pread)            /* 180 */
534         .long SYMBOL_NAME(sys_pwrite)
535         .long SYMBOL_NAME(sys_lchown);
536         
537         .rept NR_syscalls-182
538                 .long SYMBOL_NAME(sys_ni_syscall)
539         .endr