����8-1 linux/kernel/asm.s


  1 /*

  2  *  linux/kernel/asm.s

  3  *

  4  *  (C) 1991  Linus Torvalds

  5  */

  6

  7 /*

  8  * asm.s contains the low-level code for most hardware faults.

  9  * page_exception is handled by the mm, so that isn't here. This

 10  * file also handles (hopefully) fpu-exceptions due to TS-bit, as

 11  * the fpu must be properly saved/resored. This hasn't been tested.

 12  */

    /*

     * asm.s�����а����󲿷ֵ�Ӳ�����ϣ�������������ĵײ�δ��롣ҳ�쳣���ڴ��������

     * mm���������Բ�������˳��򻹴�����ϣ��������������TS-λ����ɵ�fpu�쳣����Ϊ

     * fpu������ȷ�ؽ��б���/�ָ���������Щ��û�в��Թ���

     */

 13

    # �������ļ���Ҫ�漰��Intel�����ж�int0--int16�Ĵ�����int17-int31�������ʹ�ã���

    # ������һЩȫ�ֺ���������������ԭ����traps.c��˵����

 14 .globl _divide_error,_debug,_nmi,_int3,_overflow,_bounds,_invalid_op

 15 .globl _double_fault,_coprocessor_segment_overrun

 16 .globl _invalid_TSS,_segment_not_present,_stack_segment

 17 .globl _general_protection,_coprocessor_error,_irq13,_reserved

 18 .globl _alignment_check

 19

    # ������γ������޳����ŵ������

    # int0 -- ��������������������  ���ͣ����󣻳����ţ��ޡ�

    # ��ִ��DIV��IDIVָ��ʱ����������0��CPU�ͻ��������쳣����EAX����AX��AL������

    # ����һ���Ϸ��������Ľ��ʱ��Ҳ���������쳣��21�б��'_do_divide_error'ʵ������

    # C���Ժ���do_divide_error()�����������ģ���ж�Ӧ�����ơ�����'do_divide_error'��

    # traps.c��ʵ�֣���101�п�ʼ����

 20 _divide_error:

 21         pushl $_do_divide_error    # ���Ȱѽ�Ҫ���õĺ�����ַ��ջ��

 22 no_error_code:                     # �������޳����Ŵ�������ڴ����������56�еȡ�

 23         xchgl %eax,(%esp)          # _do_divide_error�ĵ�ַ �� eax��eax��������ջ��

 24         pushl %ebx

 25         pushl %ecx

 26         pushl %edx

 27         pushl %edi

 28         pushl %esi

 29         pushl %ebp

 30         push %ds                   # ����16λ�ĶμĴ�����ջ��ҲҪռ��4���ֽڡ�

 31         push %es

 32         push %fs

 33         pushl $0                   # "error code"   # ����ֵ0��Ϊ��������ջ��

 34         lea 44(%esp),%edx          # ȡ��Ч��ַ����ջ��ԭ���÷��ص�ַ����ջָ��λ�ã�

 35         pushl %edx                 # ��ѹ���ջ��

 36         movl $0x10,%edx            # ��ʼ���μĴ���ds��es��fs�������ں����ݶ�ѡ�����

 37         mov %dx,%ds

 38         mov %dx,%es

 39         mov %dx,%fs

    # �����ϵ�'*'�ű�ʾ���ò�����ָ����ַ���ĺ�������Ϊ��ӵ��á����ĺ����ǵ������𱾴�

    # �쳣��C��������������do_divide_error()�ȡ���41���ǽ���ջָ���8�൱��ִ������pop

    # ������������������������ջ������C����������33�к�35����ջ��ֵ�����ö�ջָ������

    # ָ��Ĵ���fs��ջ����

 40         call *%eax

 41         addl $8,%esp

 42         pop %fs

 43         pop %es

 44         pop %ds

 45         popl %ebp

 46         popl %esi

 47         popl %edi

 48         popl %edx

 49         popl %ecx

 50         popl %ebx

 51         popl %eax                  # ����ԭ��eax�е����ݡ�

 52         iret

 53

    # int1 -- debug�����ж���ڵ㡣��������ͬ�ϡ����ͣ�����/���壨Fault/Trap�����޴���š�

    # ��eflags��TF��־��λʱ���������жϡ�������Ӳ���ϵ㣨���ݣ����壬���룺���󣩣�����

    # ������ָ�������������񽻻����壬���ߵ��ԼĴ���������Ч�����󣩣�CPU�ͻ�������쳣��

 54 _debug:

 55         pushl $_do_int3         # _do_debug  # C����ָ����ջ������ͬ��

 56         jmp no_error_code

 57

    # int2 -- �������жϵ�����ڵ㡣  ���ͣ����壻�޴���š�

    # ���ǽ��еı�����̶��ж�������Ӳ���жϡ�ÿ�����յ�һ��NMI�źţ�CPU�ڲ��ͻ�����ж�

    # ����2����ִ�б�׼�ж�Ӧ�����ڣ���˺ܽ�ʡʱ�䡣NMIͨ������Ϊ��Ϊ��Ҫ��Ӳ���¼�ʹ�á�

    # ��CPU�յ�һ�� NMI �źŲ��ҿ�ʼִ�����жϴ�������ʱ��������е�Ӳ���ж϶��������ԡ�

 58 _nmi:

 59         pushl $_do_nmi

 60         jmp no_error_code

 61

    # int3 -- �ϵ�ָ�������жϵ���ڵ㡣  ���ͣ����壻�޴���š�

    # ��int 3 ָ���������жϣ���Ӳ���ж��޹ء���ָ��ͨ���ɵ�ʽ�����뱻��ʽ����Ĵ����С�

    # ��������ͬ_debug��

 62 _int3:

 63         pushl $_do_int3

 64         jmp no_error_code

 65

    # int4 -- ������������ж���ڵ㡣  ���ͣ����壻�޴���š�

    # EFLAGS��OF��־��λʱCPUִ��INTOָ��ͻ��������жϡ�ͨ�����ڱ����������������������

 66 _overflow:

 67         pushl $_do_overflow

 68         jmp no_error_code

 69

    # int5 -- �߽�������ж���ڵ㡣  ���ͣ������޴���š�

    # ������������Ч��Χ����ʱ�������жϡ���BOUNDָ�����ʧ�ܾͻ�������жϡ�BOUNDָ����

    # 3���������������1��������������֮�䣬�Ͳ����쳣5��

 70 _bounds:

 71         pushl $_do_bounds

 72         jmp no_error_code

 73

    # int6 -- ��Ч����ָ������ж���ڵ㡣  ���ͣ������޴���š�

    # CPU ִ�л�����⵽һ����Ч�IJ������������жϡ�

 74 _invalid_op:

 75         pushl $_do_invalid_op

 76         jmp no_error_code

 77

    # int9 -- Э�������γ��������ж���ڵ㡣  ���ͣ��������޴���š�

    # ���쳣�����ϵ�ͬ��Э������������������Ϊ�ڸ���ָ�������̫��ʱ�����Ǿ������������

    # ���ػ򱣴泬�����ݶεĸ���ֵ��

 78 _coprocessor_segment_overrun:

 79         pushl $_do_coprocessor_segment_overrun

 80         jmp no_error_code

 81

    # int15 �C ����Intel�����жϵ���ڵ㡣

 82 _reserved:

 83         pushl $_do_reserved

 84         jmp no_error_code

 85

    # int45 -- (0x20 + 13) Linux���õ���ѧЭ������Ӳ���жϡ�

    # ��Э������ִ����һ������ʱ�ͻᷢ��IRQ13�ж��źţ���֪ͨCPU������ɡ�80387��ִ��

    # ����ʱ��CPU��ȴ��������ɡ�����89����0xF0��Э�����˿ڣ�������æ��������ͨ��д

    # �ö˿ڣ����жϽ�����CPU��BUSY�����źţ������¼���80387�Ĵ�������չ��������PEREQ��

    # �ò�����Ҫ��Ϊ��ȷ���ڼ���ִ��80387���κ�ָ��֮ǰ��CPU��Ӧ���жϡ�

 86 _irq13:

 87         pushl %eax

 88         xorb %al,%al

 89         outb %al,$0xF0

 90         movb $0x20,%al

 91         outb %al,$0x20             # ��8259���жϿ���оƬ����EOI���жϽ������źš�

 92         jmp 1f                     # ��������תָ������ʱ���á�

 93 1:      jmp 1f

 94 1:      outb %al,$0xA0             # ����8259���жϿ���оƬ����EOI���жϽ������źš�

 95         popl %eax

 96         jmp _coprocessor_error     # �ú���ԭ�ڱ������У����ѷŵ�system_call.s�С�

 97

    # �����ж��ڵ���ʱCPU�����жϷ��ص�ַ֮�󽫳�����ѹ���ջ����˷���ʱҲ��Ҫ��������

    # �������μ�ͼ5.3(b)����

 

    # int8 -- ˫�������ϡ�  ���ͣ��������д����롣

    # ͨ����CPU�ڵ���ǰһ���쳣�Ĵ���������ּ�⵽һ���µ��쳣ʱ���������쳣�ᱻ���еؽ���

    # ��������Ҳ���������ٵ������CPU���ܽ��������Ĵ��д�����������ʱ�ͻ��������жϡ�

 98 _double_fault:

 99         pushl $_do_double_fault    # C������ַ��ջ��

100 error_code:

101         xchgl %eax,4(%esp)         # error code <-> %eax��eaxԭ����ֵ�������ڶ�ջ�ϡ�

102         xchgl %ebx,(%esp)          # &function <-> %ebx��ebxԭ����ֵ�������ڶ�ջ�ϡ�

103         pushl %ecx

104         pushl %edx

105         pushl %edi

106         pushl %esi

107         pushl %ebp

108         push %ds

109         push %es

110         push %fs

111         pushl %eax                 # error code   # ��������ջ��

112         lea 44(%esp),%eax          # offset       # ���򷵻ص�ַ����ջָ��λ��ֵ��ջ��

113         pushl %eax

114         movl $0x10,%eax            # ���ں����ݶ�ѡ�����

115         mov %ax,%ds

116         mov %ax,%es

117         mov %ax,%fs

118         call *%ebx                 # ��ӵ��ã�������Ӧ��C���������������ջ��

119         addl $8,%esp               # ������ջ��2������C�����IJ�����

120         pop %fs

121         pop %es

122         pop %ds

123         popl %ebp

124         popl %esi

125         popl %edi

126         popl %edx

127         popl %ecx

128         popl %ebx

129         popl %eax

130         iret

131

    # int10 -- ��Ч������״̬��(TSS)��  ���ͣ������г����롣

    # CPU��ͼ�л���һ�����̣����ý��̵�TSS��Ч������TSS����һ�����������쳣��������TSS

    # ���ȳ���104�ֽ�ʱ������쳣�ڵ�ǰ�����в���������л�����ֹ������������ᵼ�����л�

    # ����������в������쳣��

132 _invalid_TSS:

133         pushl $_do_invalid_TSS

134         jmp error_code

135

    # int11 -- �β����ڡ�  ���ͣ������г����롣

    # �����õĶβ����ڴ��С����������б�־ָ���β����ڴ��С�

136 _segment_not_present:

137         pushl $_do_segment_not_present

138         jmp error_code

139

    # int12 -- ��ջ�δ���  ���ͣ������г����롣

    # ָ�������ͼ������ջ�η�Χ�����߶�ջ�β����ڴ��С������쳣11��13����������Щ����

    # ϵͳ������������쳣��ȷ��ʲôʱ��Ӧ��Ϊ�����������ջ�ռ䡣

140 _stack_segment:

141         pushl $_do_stack_segment

142         jmp error_code

143

    # int13 -- һ�㱣���Գ�����  ���ͣ������г����롣

    # �����Dz������κ�������Ĵ�����һ���쳣����ʱû�ж�Ӧ�Ĵ���������0--16����ͨ����

    # ��鵽���ࡣ

144 _general_protection:

145         pushl $_do_general_protection

146         jmp error_code

147

    # int17 -- �߽�����������

    # ���������ڴ�߽���ʱ������Ȩ��3���û��������ݷDZ߽����ʱ��������쳣��

148 _alignment_check:

149         pushl $_do_alignment_check

150         jmp error_code

151

    # int7 -- �豸�����ڣ�_device_not_available����kernel/sys_call.s��158�С�

    # int14 -- ҳ����_page_fault����mm/page.s��14�С�

    # int16 -- Э����������_coprocessor_error����kernel/sys_call.s��140�С�

    # ʱ���ж�int 0x20��_timer_interrupt����kernel/sys_call.s��189�С�

    # ϵͳ����int 0x80��_system_call����kernel/sys_call.s��84�С�