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
32 isr_template FAULT_DIVISION_ERROR
33 isr_template FAULT_GENERAL_PROTECTION, no_error_code=0
34 isr_template FAULT_PAGE_FAULT, no_error_code=0
35 isr_template FAULT_STACK_SEG_FAULT, no_error_code=0
37 isr_template LUNAIX_SYS_PANIC
38 isr_template LUNAIX_SYS_CALL
39 isr_template LUNAIX_SCHED
41 isr_template APIC_ERROR_IV
42 isr_template APIC_LINT0_IV
43 isr_template APIC_TIMER_IV
44 isr_template APIC_SPIV_IV
45 isr_template RTC_TIMER_IV
47 isr_template PC_KBD_IV
48 isr_template AHCI_HBA_IV
52 Stack layout (layout of struct isr_param)
55 eflags > offset = 48 + 16 = 64
59 vector > offset = 28 + 16 + 4 = 48
64 ds > offset = 7 * 4 = 28
73 las: Least Significant Address
74 msa: Most Significant Address
93 movl 60(%esp), %eax /* 取出 %cs */
94 andl $0x3, %eax /* 判断 RPL */
97 movw $KDATA_SEG, %ax /* 如果从用户模式转来,则切换至内核数据段 */
103 # 保存用户栈顶指针。这是因为我们允许系统调用内进行上下文切换,而这样一来,我们就失去了用户栈的信息,
104 # 这样一来,就无法设置信号上下文。这主要是为了实现了pause()而做的准备
105 movl (__current), %eax
106 movl 68(%esp), %ebx # 取出esp
107 movl %ebx, 84(%eax) # 存入__current->ustack_top
111 andl $0xfffffff0, %esp
123 #ifdef __ASM_INTR_DIAGNOSIS
124 movl %eax, (debug_resv + 8)
126 movl %eax, (debug_resv + 4)
147 #ifdef __ASM_INTR_DIAGNOSIS
149 movl %eax, debug_resv
151 # 处理TSS.ESP的一些边界条件。如果是正常iret(即从内核模式*优雅地*退出)
152 # 那么TSS.ESP0应该为iret进行弹栈后,%esp的值。
153 # 所以这里的边界条件是:如返回用户模式,iret会额外弹出8个字节(ss,esp)
160 movl %eax, (_tss + 4)
167 # arg1: 目标进程PCB地址 (next
171 movl 88(%eax), %ecx # __current->pagetable
172 movl 88(%ebx), %eax # next->pagetable
174 cmpl %ecx, %eax # if(next->pagtable != __current->pagetable) {
176 movl %eax, %cr3 # cpu_lcr3(next->pagetable)
179 movl %ebx, __current # __current = next
181 # 我们已经处在了新的地址空间,为了避免影响其先前的栈布局
183 movl $tmp_stack, %esp
184 call signal_dispatch # kernel/signal.c
186 test %eax, %eax # do we have signal to handle?
193 .global handle_signal
195 # 注意1:任何对proc_sig的布局改动,都须及时的保证这里的一致性!
196 # 注意2:handle_signal在调用之前,须确保proc_sig已经写入用户栈!
197 leal 8(%eax), %ebx # arg1 in %eax: addr of proc_sig structure in user stack
199 pushl $UDATA_SEG # proc_sig->prev_context.ss
201 pushl 64(%ebx) # proc_sig->prev_context.eflags
202 pushl $UCODE_SEG # cs
203 pushl $sig_wrapper # eip for sig wrapper
205 movw $UDATA_SEG, %cx # switch data seg to user mode
214 sig_wrapper: # in user mode
216 and $0xfffffff0, %esp
218 pushl %eax # Addr to proc_sig structure
219 pushl 4(%eax) # proc_sig->sig_num ---- 16 bytes aligned
221 call (%eax) # invoke signal handler
223 # invoke the sigreturn syscall to exit the signal wrapper
224 movl $__SYSCALL_sigreturn, %eax