Import 2.1.116pre2
[davej-history.git] / arch / i386 / kernel / entry.S
blob469ad752fdc86fe3aae8114e56741484ebc82df6
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
78 need_resched    = 20
80 ENOSYS = 38
83 #define SAVE_ALL \
84         cld; \
85         pushl %es; \
86         pushl %ds; \
87         pushl %eax; \
88         pushl %ebp; \
89         pushl %edi; \
90         pushl %esi; \
91         pushl %edx; \
92         pushl %ecx; \
93         pushl %ebx; \
94         movl $(__KERNEL_DS),%edx; \
95         movl %dx,%ds; \
96         movl %dx,%es;
98 #define RESTORE_ALL     \
99         popl %ebx;      \
100         popl %ecx;      \
101         popl %edx;      \
102         popl %esi;      \
103         popl %edi;      \
104         popl %ebp;      \
105         popl %eax;      \
106 1:      popl %ds;       \
107 2:      popl %es;       \
108 3:      addl $4,%esp;   \
109 4:      iret;           \
110 .section fixup,"ax";    \
111 5:      pushl $0;       \
112         popl %ds;       \
113         jmp 2b;         \
114 6:      pushl $0;       \
115         popl %es;       \
116         jmp 3b;         \
117 7:      pushl $11;      \
118         call do_exit;   \
119 .previous;              \
120 .section __ex_table,"a";\
121         .align 4;       \
122         .long 1b,5b;    \
123         .long 2b,6b;    \
124         .long 4b,7b;    \
125 .previous
127 #define GET_CURRENT(reg) \
128         movl %esp, reg; \
129         andl $-8192, reg;
131 ENTRY(lcall7)
132         pushfl                  # We get a different stack layout with call gates,
133         pushl %eax              # which has to be cleaned up later..
134         SAVE_ALL
135         movl EIP(%esp),%eax     # due to call gates, this is eflags, not eip..
136         movl CS(%esp),%edx      # this is eip..
137         movl EFLAGS(%esp),%ecx  # and this is cs..
138         movl %eax,EFLAGS(%esp)  #
139         movl %edx,EIP(%esp)     # Now we move them to their "normal" places
140         movl %ecx,CS(%esp)      #
141         movl %esp,%ebx
142         pushl %ebx
143         andl $-8192,%ebx        # GET_CURRENT
144         movl exec_domain(%ebx),%edx     # Get the execution domain
145         movl 4(%edx),%edx       # Get the lcall7 handler for the domain
146         call *%edx
147         popl %eax
148         jmp ret_from_sys_call
151 #ifdef __SMP__
152         ALIGN
153         .globl  ret_from_smpfork
154 ret_from_smpfork:
155         GET_CURRENT(%ebx)
156 call __putlock
157         btrl    $0, SYMBOL_NAME(scheduler_lock)
158         jmp     ret_from_sys_call
159 #endif /* __SMP__ */
162  * Return to user mode is not as complex as all this looks,
163  * but we want the default path for a system call return to
164  * go as quickly as possible which is why some of this is
165  * less clear than it otherwise should be.
166  */
168 ENTRY(system_call)
169         pushl %eax                      # save orig_eax
170         SAVE_ALL
171         GET_CURRENT(%ebx)
172         cmpl $(NR_syscalls),%eax
173         jae badsys
174         testb $0x20,flags(%ebx)         # PF_TRACESYS
175         jne tracesys
176         call *SYMBOL_NAME(sys_call_table)(,%eax,4)
177         movl %eax,EAX(%esp)             # save the return value
178         ALIGN
179         .globl ret_from_sys_call
180         .globl ret_from_intr
181 ret_from_sys_call:
182         movl SYMBOL_NAME(bh_mask),%eax
183         andl SYMBOL_NAME(bh_active),%eax
184         jne handle_bottom_half
185 ret_with_reschedule:
186         cmpl $0,need_resched(%ebx)
187         jne reschedule
188         cmpl $0,sigpending(%ebx)
189         jne signal_return
190         RESTORE_ALL
191         ALIGN
192 signal_return:
193         testl $(VM_MASK),EFLAGS(%esp)
194         pushl %esp
195         jne v86_signal_return
196         pushl $0
197         call SYMBOL_NAME(do_signal)
198         addl $8,%esp
199         RESTORE_ALL
200         ALIGN
201 v86_signal_return:
202         call SYMBOL_NAME(save_v86_state)
203         movl %eax,%esp
204         pushl %eax
205         pushl $0
206         call SYMBOL_NAME(do_signal)
207         addl $8,%esp
208         RESTORE_ALL
209         ALIGN
210 tracesys:
211         movl $-ENOSYS,EAX(%esp)
212         call SYMBOL_NAME(syscall_trace)
213         movl ORIG_EAX(%esp),%eax
214         call *SYMBOL_NAME(sys_call_table)(,%eax,4)
215         movl %eax,EAX(%esp)             # save the return value
216         call SYMBOL_NAME(syscall_trace)
217         jmp ret_from_sys_call
218 badsys:
219         movl $-ENOSYS,EAX(%esp)
220         jmp ret_from_sys_call
222         ALIGN
223 ret_from_exception:
224         movl SYMBOL_NAME(bh_mask),%eax
225         andl SYMBOL_NAME(bh_active),%eax
226         jne handle_bottom_half
227         ALIGN
228 ret_from_intr:
229         GET_CURRENT(%ebx)
230         movl EFLAGS(%esp),%eax          # mix EFLAGS and CS
231         movb CS(%esp),%al
232         testl $(VM_MASK | 3),%eax       # return to VM86 mode or non-supervisor?
233         jne ret_with_reschedule
234         RESTORE_ALL
236         ALIGN
237 handle_bottom_half:
238         pushl $ret_from_intr
239         jmp SYMBOL_NAME(do_bottom_half)
241         ALIGN
242 reschedule:
243         pushl $ret_from_sys_call
244         jmp SYMBOL_NAME(schedule)    # test
247 ENTRY(divide_error)
248         pushl $0                # no error code
249         pushl $ SYMBOL_NAME(do_divide_error)
250         ALIGN
251 error_code:
252         pushl %ds
253         pushl %eax
254         xorl %eax,%eax
255         pushl %ebp
256         pushl %edi
257         pushl %esi
258         pushl %edx
259         decl %eax                       # eax = -1
260         pushl %ecx
261         pushl %ebx
262         cld
263         movl %es,%cx
264         xchgl %eax, ORIG_EAX(%esp)      # orig_eax (get the error code. )
265         movl %esp,%edx
266         xchgl %ecx, ES(%esp)            # get the address and save es.
267         pushl %eax                      # push the error code
268         pushl %edx
269         movl $(__KERNEL_DS),%edx
270         movl %dx,%ds
271         movl %dx,%es
272         GET_CURRENT(%ebx)
273         call *%ecx
274         addl $8,%esp
275         jmp ret_from_exception
277 ENTRY(coprocessor_error)
278         pushl $0
279         pushl $ SYMBOL_NAME(do_coprocessor_error)
280         jmp error_code
282 ENTRY(device_not_available)
283         pushl $-1               # mark this as an int
284         SAVE_ALL
285         GET_CURRENT(%ebx)
286         pushl $ret_from_exception
287         movl %cr0,%eax
288         testl $0x4,%eax                 # EM (math emulation bit)
289         je SYMBOL_NAME(math_state_restore)
290         pushl $0                # temporary storage for ORIG_EIP
291         call  SYMBOL_NAME(math_emulate)
292         addl $4,%esp
293         ret
295 ENTRY(debug)
296         pushl $0
297         pushl $ SYMBOL_NAME(do_debug)
298         jmp error_code
300 ENTRY(nmi)
301         pushl $0
302         pushl $ SYMBOL_NAME(do_nmi)
303         jmp error_code
305 ENTRY(int3)
306         pushl $0
307         pushl $ SYMBOL_NAME(do_int3)
308         jmp error_code
310 ENTRY(overflow)
311         pushl $0
312         pushl $ SYMBOL_NAME(do_overflow)
313         jmp error_code
315 ENTRY(bounds)
316         pushl $0
317         pushl $ SYMBOL_NAME(do_bounds)
318         jmp error_code
320 ENTRY(invalid_op)
321         pushl $0
322         pushl $ SYMBOL_NAME(do_invalid_op)
323         jmp error_code
325 ENTRY(coprocessor_segment_overrun)
326         pushl $0
327         pushl $ SYMBOL_NAME(do_coprocessor_segment_overrun)
328         jmp error_code
330 ENTRY(reserved)
331         pushl $0
332         pushl $ SYMBOL_NAME(do_reserved)
333         jmp error_code
335 ENTRY(double_fault)
336         pushl $ SYMBOL_NAME(do_double_fault)
337         jmp error_code
339 ENTRY(invalid_TSS)
340         pushl $ SYMBOL_NAME(do_invalid_TSS)
341         jmp error_code
343 ENTRY(segment_not_present)
344         pushl $ SYMBOL_NAME(do_segment_not_present)
345         jmp error_code
347 ENTRY(stack_segment)
348         pushl $ SYMBOL_NAME(do_stack_segment)
349         jmp error_code
351 ENTRY(general_protection)
352         pushl $ SYMBOL_NAME(do_general_protection)
353         jmp error_code
355 ENTRY(alignment_check)
356         pushl $ SYMBOL_NAME(do_alignment_check)
357         jmp error_code
359 ENTRY(page_fault)
360         pushl $ SYMBOL_NAME(do_page_fault)
361         jmp error_code
363 ENTRY(spurious_interrupt_bug)
364         pushl $0
365         pushl $ SYMBOL_NAME(do_spurious_interrupt_bug)
366         jmp error_code
368 .data
369 ENTRY(sys_call_table)
370         .long SYMBOL_NAME(sys_setup)            /* 0 */
371         .long SYMBOL_NAME(sys_exit)
372         .long SYMBOL_NAME(sys_fork)
373         .long SYMBOL_NAME(sys_read)
374         .long SYMBOL_NAME(sys_write)
375         .long SYMBOL_NAME(sys_open)             /* 5 */
376         .long SYMBOL_NAME(sys_close)
377         .long SYMBOL_NAME(sys_waitpid)
378         .long SYMBOL_NAME(sys_creat)
379         .long SYMBOL_NAME(sys_link)
380         .long SYMBOL_NAME(sys_unlink)           /* 10 */
381         .long SYMBOL_NAME(sys_execve)
382         .long SYMBOL_NAME(sys_chdir)
383         .long SYMBOL_NAME(sys_time)
384         .long SYMBOL_NAME(sys_mknod)
385         .long SYMBOL_NAME(sys_chmod)            /* 15 */
386         .long SYMBOL_NAME(sys_lchown)
387         .long SYMBOL_NAME(sys_ni_syscall)                               /* old break syscall holder */
388         .long SYMBOL_NAME(sys_stat)
389         .long SYMBOL_NAME(sys_lseek)
390         .long SYMBOL_NAME(sys_getpid)           /* 20 */
391         .long SYMBOL_NAME(sys_mount)
392         .long SYMBOL_NAME(sys_oldumount)
393         .long SYMBOL_NAME(sys_setuid)
394         .long SYMBOL_NAME(sys_getuid)
395         .long SYMBOL_NAME(sys_stime)            /* 25 */
396         .long SYMBOL_NAME(sys_ptrace)
397         .long SYMBOL_NAME(sys_alarm)
398         .long SYMBOL_NAME(sys_fstat)
399         .long SYMBOL_NAME(sys_pause)
400         .long SYMBOL_NAME(sys_utime)            /* 30 */
401         .long SYMBOL_NAME(sys_ni_syscall)                               /* old stty syscall holder */
402         .long SYMBOL_NAME(sys_ni_syscall)                               /* old gtty syscall holder */
403         .long SYMBOL_NAME(sys_access)
404         .long SYMBOL_NAME(sys_nice)
405         .long SYMBOL_NAME(sys_ni_syscall)       /* 35 */                /* old ftime syscall holder */
406         .long SYMBOL_NAME(sys_sync)
407         .long SYMBOL_NAME(sys_kill)
408         .long SYMBOL_NAME(sys_rename)
409         .long SYMBOL_NAME(sys_mkdir)
410         .long SYMBOL_NAME(sys_rmdir)            /* 40 */
411         .long SYMBOL_NAME(sys_dup)
412         .long SYMBOL_NAME(sys_pipe)
413         .long SYMBOL_NAME(sys_times)
414         .long SYMBOL_NAME(sys_ni_syscall)                               /* old prof syscall holder */
415         .long SYMBOL_NAME(sys_brk)              /* 45 */
416         .long SYMBOL_NAME(sys_setgid)
417         .long SYMBOL_NAME(sys_getgid)
418         .long SYMBOL_NAME(sys_signal)
419         .long SYMBOL_NAME(sys_geteuid)
420         .long SYMBOL_NAME(sys_getegid)          /* 50 */
421         .long SYMBOL_NAME(sys_acct)
422         .long SYMBOL_NAME(sys_umount)                                   /* recycled never used phys() */
423         .long SYMBOL_NAME(sys_ni_syscall)                               /* old lock syscall holder */
424         .long SYMBOL_NAME(sys_ioctl)
425         .long SYMBOL_NAME(sys_fcntl)            /* 55 */
426         .long SYMBOL_NAME(sys_ni_syscall)                               /* old mpx syscall holder */
427         .long SYMBOL_NAME(sys_setpgid)
428         .long SYMBOL_NAME(sys_ni_syscall)                               /* old ulimit syscall holder */
429         .long SYMBOL_NAME(sys_olduname)
430         .long SYMBOL_NAME(sys_umask)            /* 60 */
431         .long SYMBOL_NAME(sys_chroot)
432         .long SYMBOL_NAME(sys_ustat)
433         .long SYMBOL_NAME(sys_dup2)
434         .long SYMBOL_NAME(sys_getppid)
435         .long SYMBOL_NAME(sys_getpgrp)          /* 65 */
436         .long SYMBOL_NAME(sys_setsid)
437         .long SYMBOL_NAME(sys_sigaction)
438         .long SYMBOL_NAME(sys_sgetmask)
439         .long SYMBOL_NAME(sys_ssetmask)
440         .long SYMBOL_NAME(sys_setreuid)         /* 70 */
441         .long SYMBOL_NAME(sys_setregid)
442         .long SYMBOL_NAME(sys_sigsuspend)
443         .long SYMBOL_NAME(sys_sigpending)
444         .long SYMBOL_NAME(sys_sethostname)
445         .long SYMBOL_NAME(sys_setrlimit)        /* 75 */
446         .long SYMBOL_NAME(sys_getrlimit)
447         .long SYMBOL_NAME(sys_getrusage)
448         .long SYMBOL_NAME(sys_gettimeofday)
449         .long SYMBOL_NAME(sys_settimeofday)
450         .long SYMBOL_NAME(sys_getgroups)        /* 80 */
451         .long SYMBOL_NAME(sys_setgroups)
452         .long SYMBOL_NAME(old_select)
453         .long SYMBOL_NAME(sys_symlink)
454         .long SYMBOL_NAME(sys_lstat)
455         .long SYMBOL_NAME(sys_readlink)         /* 85 */
456         .long SYMBOL_NAME(sys_uselib)
457         .long SYMBOL_NAME(sys_swapon)
458         .long SYMBOL_NAME(sys_reboot)
459         .long SYMBOL_NAME(old_readdir)
460         .long SYMBOL_NAME(old_mmap)             /* 90 */
461         .long SYMBOL_NAME(sys_munmap)
462         .long SYMBOL_NAME(sys_truncate)
463         .long SYMBOL_NAME(sys_ftruncate)
464         .long SYMBOL_NAME(sys_fchmod)
465         .long SYMBOL_NAME(sys_fchown)           /* 95 */
466         .long SYMBOL_NAME(sys_getpriority)
467         .long SYMBOL_NAME(sys_setpriority)
468         .long SYMBOL_NAME(sys_ni_syscall)                               /* old profil syscall holder */
469         .long SYMBOL_NAME(sys_statfs)
470         .long SYMBOL_NAME(sys_fstatfs)          /* 100 */
471         .long SYMBOL_NAME(sys_ioperm)
472         .long SYMBOL_NAME(sys_socketcall)
473         .long SYMBOL_NAME(sys_syslog)
474         .long SYMBOL_NAME(sys_setitimer)
475         .long SYMBOL_NAME(sys_getitimer)        /* 105 */
476         .long SYMBOL_NAME(sys_newstat)
477         .long SYMBOL_NAME(sys_newlstat)
478         .long SYMBOL_NAME(sys_newfstat)
479         .long SYMBOL_NAME(sys_uname)
480         .long SYMBOL_NAME(sys_iopl)             /* 110 */
481         .long SYMBOL_NAME(sys_vhangup)
482         .long SYMBOL_NAME(sys_idle)
483         .long SYMBOL_NAME(sys_vm86old)
484         .long SYMBOL_NAME(sys_wait4)
485         .long SYMBOL_NAME(sys_swapoff)          /* 115 */
486         .long SYMBOL_NAME(sys_sysinfo)
487         .long SYMBOL_NAME(sys_ipc)
488         .long SYMBOL_NAME(sys_fsync)
489         .long SYMBOL_NAME(sys_sigreturn)
490         .long SYMBOL_NAME(sys_clone)            /* 120 */
491         .long SYMBOL_NAME(sys_setdomainname)
492         .long SYMBOL_NAME(sys_newuname)
493         .long SYMBOL_NAME(sys_modify_ldt)
494         .long SYMBOL_NAME(sys_adjtimex)
495         .long SYMBOL_NAME(sys_mprotect)         /* 125 */
496         .long SYMBOL_NAME(sys_sigprocmask)
497         .long SYMBOL_NAME(sys_create_module)
498         .long SYMBOL_NAME(sys_init_module)
499         .long SYMBOL_NAME(sys_delete_module)
500         .long SYMBOL_NAME(sys_get_kernel_syms)  /* 130 */
501         .long SYMBOL_NAME(sys_quotactl)
502         .long SYMBOL_NAME(sys_getpgid)
503         .long SYMBOL_NAME(sys_fchdir)
504         .long SYMBOL_NAME(sys_bdflush)
505         .long SYMBOL_NAME(sys_sysfs)            /* 135 */
506         .long SYMBOL_NAME(sys_personality)
507         .long SYMBOL_NAME(sys_ni_syscall)       /* for afs_syscall */
508         .long SYMBOL_NAME(sys_setfsuid)
509         .long SYMBOL_NAME(sys_setfsgid)
510         .long SYMBOL_NAME(sys_llseek)           /* 140 */
511         .long SYMBOL_NAME(sys_getdents)
512         .long SYMBOL_NAME(sys_select)
513         .long SYMBOL_NAME(sys_flock)
514         .long SYMBOL_NAME(sys_msync)
515         .long SYMBOL_NAME(sys_readv)            /* 145 */
516         .long SYMBOL_NAME(sys_writev)
517         .long SYMBOL_NAME(sys_getsid)
518         .long SYMBOL_NAME(sys_fdatasync)
519         .long SYMBOL_NAME(sys_sysctl)
520         .long SYMBOL_NAME(sys_mlock)            /* 150 */
521         .long SYMBOL_NAME(sys_munlock)
522         .long SYMBOL_NAME(sys_mlockall)
523         .long SYMBOL_NAME(sys_munlockall)
524         .long SYMBOL_NAME(sys_sched_setparam)
525         .long SYMBOL_NAME(sys_sched_getparam)   /* 155 */
526         .long SYMBOL_NAME(sys_sched_setscheduler)
527         .long SYMBOL_NAME(sys_sched_getscheduler)
528         .long SYMBOL_NAME(sys_sched_yield)
529         .long SYMBOL_NAME(sys_sched_get_priority_max)
530         .long SYMBOL_NAME(sys_sched_get_priority_min)  /* 160 */
531         .long SYMBOL_NAME(sys_sched_rr_get_interval)
532         .long SYMBOL_NAME(sys_nanosleep)
533         .long SYMBOL_NAME(sys_mremap)
534         .long SYMBOL_NAME(sys_setresuid)
535         .long SYMBOL_NAME(sys_getresuid)        /* 165 */
536         .long SYMBOL_NAME(sys_vm86)
537         .long SYMBOL_NAME(sys_query_module)
538         .long SYMBOL_NAME(sys_poll)
539         .long SYMBOL_NAME(sys_nfsservctl)
540         .long SYMBOL_NAME(sys_setresgid)        /* 170 */
541         .long SYMBOL_NAME(sys_getresgid)
542         .long SYMBOL_NAME(sys_prctl)
543         .long SYMBOL_NAME(sys_rt_sigreturn)
544         .long SYMBOL_NAME(sys_rt_sigaction)
545         .long SYMBOL_NAME(sys_rt_sigprocmask)   /* 175 */
546         .long SYMBOL_NAME(sys_rt_sigpending)
547         .long SYMBOL_NAME(sys_rt_sigtimedwait)
548         .long SYMBOL_NAME(sys_rt_sigqueueinfo)
549         .long SYMBOL_NAME(sys_rt_sigsuspend)
550         .long SYMBOL_NAME(sys_pread)            /* 180 */
551         .long SYMBOL_NAME(sys_pwrite)
552         .long SYMBOL_NAME(sys_chown)
553         .long SYMBOL_NAME(sys_getcwd)
554         .long SYMBOL_NAME(sys_capget)
555         .long SYMBOL_NAME(sys_capset)           /* 185 */
556         .long SYMBOL_NAME(sys_sigaltstack)
557         .long SYMBOL_NAME(sys_sendfile)
558         .long SYMBOL_NAME(sys_ni_syscall)               /* streams1 */
559         .long SYMBOL_NAME(sys_ni_syscall)               /* streams2 */
560         
561         .rept NR_syscalls-187
562                 .long SYMBOL_NAME(sys_ni_syscall)
563         .endr