2 #include <arch/x86/interrupts.h>
3 #include <lunaix/common.h>
4 #include <lunaix/syscall.h>
5 #define __ASM_INTR_DIAGNOSIS
7 .macro isr_template vector, no_error_code=1
8 .global _asm_isr\vector
9 .type _asm_isr\vector, @function
18 #ifdef __ASM_INTR_DIAGNOSIS
26 isr_template FAULT_DIVISION_ERROR
27 isr_template FAULT_GENERAL_PROTECTION, no_error_code=0
28 isr_template FAULT_PAGE_FAULT, no_error_code=0
30 isr_template LUNAIX_SYS_PANIC
31 isr_template LUNAIX_SYS_CALL
33 isr_template APIC_ERROR_IV
34 isr_template APIC_LINT0_IV
35 isr_template APIC_TIMER_IV
36 isr_template APIC_SPIV_IV
37 isr_template RTC_TIMER_IV
38 isr_template PC_KBD_IV
42 Stack layout (layout of struct isr_param)
45 eflags > offset = 48 + 16 = 64
49 vector > offset = 28 + 16 + 4 = 48
54 ds > offset = 7 * 4 = 28
63 las: Least Significant Address
64 msa: Most Significant Address
83 movl 60(%esp), %eax /* 取出 %cs */
84 andl $0x3, %eax /* 判断 RPL */
87 movw $KDATA_SEG, %ax /* 如果从用户模式转来,则切换至内核数据段 */
93 # 保存用户栈顶指针。这是因为我们允许系统调用内进行上下文切换,而这样一来,我们就失去了用户栈的信息,
94 # 这样一来,就无法设置信号上下文。这主要是为了实现了pause()而做的准备
95 movl (__current), %eax
96 movl 68(%esp), %ebx # 取出esp
97 movl %ebx, 84(%eax) # 存入__current->ustack_top
101 andl $0xfffffff0, %esp
130 #ifdef __ASM_INTR_DIAGNOSIS
133 movl %eax, debug_resv
141 # arg1: 目标进程PCB地址 (next)
144 call signal_dispatch # kernel/signal.c
148 movl 88(%eax), %ebx # __current->pagetable
149 movl 88(%ecx), %eax # next->pagetable
151 cmpl %ebx, %eax # if(next->pagtable != __current->pagetable) {
153 movl %eax, %cr3 # cpu_lcr3(next->pagetable)
156 movl %ecx, __current # __current = next
158 test %edx, %edx # do we have signal to handle?
166 .global handle_signal
168 # 注意1:任何对proc_sig的布局改动,都须及时的保证这里的一致性!
169 # 注意2:handle_signal在调用之前,须确保proc_sig已经写入用户栈!
170 leal 8(%eax), %ebx # arg1 in %eax: addr of proc_sig structure in user stack
172 pushl 72(%ebx) # proc_sig->prev_context.ss
174 pushl 64(%ebx) # proc_sig->prev_context.eflags
175 pushl $UCODE_SEG # cs
176 pushl $sig_wrapper # eip for sig wrapper
178 movw $UDATA_SEG, %cx # switch data seg to user mode
186 sig_wrapper: # in user mode
188 and $0xfffffff0, %esp
190 pushl %eax # Addr to proc_sig structure
191 pushl 4(%eax) # proc_sig->sig_num ---- 16 bytes aligned
193 call (%eax) # invoke signal handler
195 # invoke the sigreturn syscall to exit the signal wrapper
196 movl $__SYSCALL_sigreturn, %eax