?? asm.s
字號:
/** linux/kernel/asm.s** (C) 1991 Linus Torvalds*//** asm.s contains the low-level code for most hardware faults.* page_exception is handled by the mm, so that isn't here. This* file also handles (hopefully) fpu-exceptions due to TS-bit, as* the fpu must be properly saved/resored. This hasn't been tested.eax = -1系統中斷調用(eax=調用號)ebx,ecx,edx 中放有調用參數調用號超范圍?中斷返回寄存器入棧ds,es 指向內核代碼段fs 指向局部數據段(用戶數據)調用對應的C 處理函數任務狀態?調用schedule() 時間片=0?初始任務?彈出入棧的寄存器超級用戶程序?用戶堆棧?根據進程信號位圖取進程的最小信號量,調用do signal()*/5.3 asm.s 程序/** asm.s 程序中包括大部分的硬件故障(或出錯)處理的底層次代碼。頁異常是由內存管理程序* mm 處理的,所以不在這里。此程序還處理(希望是這樣)由于TS-位而造成的fpu 異常,* 因為fpu 必須正確地進行保存/恢復處理,這些還沒有測試過。*/# 本代碼文件主要涉及對Intel 保留的中斷int0--int16 的處理(int17-int31 留作今后使用)。# 以下是一些全局函數名的聲明,其原形在traps.c 中說明。.globl _divide_error,_debug,_nmi,_int3,_overflow,_bounds,_invalid_op.globl _double_fault,_coprocessor_segment_overrun.globl _invalid_TSS,_segment_not_present,_stack_segment.globl _general_protection,_coprocessor_error,_irq13,_reserved# int0 -- (下面這段代碼的含義參見圖4.1(a))。# 下面是被零除出錯(divide_error)處理代碼。標號'_divide_error'實際上是C 語言函# 數divide_error()編譯后所生成模塊中對應的名稱。'_do_divide_error'函數在traps.c 中。_divide_error:pushl $_do_divide_error # 首先把將要調用的函數地址入棧。這段程序的出錯號為0。no_error_code: # 這里是無出錯號處理的入口處,見下面第55 行等。xchgl %eax,(%esp) # _do_divide_error 的地址 ?? eax,eax 被交換入棧。pushl %ebxpushl %ecxpushl %edxpushl %edipushl %esipushl %ebppush %ds # !!16 位的段寄存器入棧后也要占用4 個字節。push %espush %fspushl $0 # "error code" # 將出錯碼入棧。lea 44(%esp),%edx # 取原調用返回地址處堆棧指針位置,并壓入堆棧。pushl %edxmovl $0x10,%edx # 內核代碼數據段選擇符。mov %dx,%dsmov %dx,%esmov %dx,%fscall *%eax # 調用C 函數do_divide_error()。addl $8,%esp # 讓堆棧指針重新指向寄存器fs 入棧處。pop %fspop %espop %dspopl %ebppopl %esipopl %edipopl %edxpopl %ecxpopl %ebxpopl %eax # 彈出原來eax 中的內容。iret# int1 -- debug 調試中斷入口點。處理過程同上。_debug:5.3 asm.s 程序pushl $_do_int3 # _do_debug C 函數指針入棧。以下同。jmp no_error_code# int2 -- 非屏蔽中斷調用入口點。_nmi:pushl $_do_nmijmp no_error_code# int3 -- 同_debug。_int3:pushl $_do_int3jmp no_error_code# int4 -- 溢出出錯處理中斷入口點。_overflow:pushl $_do_overflowjmp no_error_code# int5 -- 邊界檢查出錯中斷入口點。_bounds:pushl $_do_boundsjmp no_error_code# int6 -- 無效操作指令出錯中斷入口點。_invalid_op:pushl $_do_invalid_opjmp no_error_code# int9 -- 協處理器段超出出錯中斷入口點。_coprocessor_segment_overrun:pushl $_do_coprocessor_segment_overrunjmp no_error_code# int15 – 保留。_reserved:pushl $_do_reservedjmp no_error_code# int45 -- ( = 0x20 + 13 ) 數學協處理器(Coprocessor)發出的中斷。# 當協處理器執行完一個操作時就會發出IRQ13 中斷信號,以通知CPU 操作完成。_irq13:pushl %eaxxorb %al,%al # 80387 在執行計算時,CPU 會等待其操作的完成。outb %al,$0xF0 # 通過寫0xF0 端口,本中斷將消除CPU 的BUSY 延續信號,并重新# 激活80387 的處理器擴展請求引腳PEREQ。該操作主要是為了確保# 在繼續執行80387 的任何指令之前,響應本中斷。movb $0x20,%aloutb %al,$0x20 # 向8259 主中斷控制芯片發送EOI(中斷結束)信號。jmp 1f # 這兩個跳轉指令起延時作用。1: jmp 1f1: outb %al,$0xA0 # 再向8259 從中斷控制芯片發送EOI(中斷結束)信號。popl %eaxjmp _coprocessor_error # _coprocessor_error 原來在本文件中,現在已經放到5.3 asm.s 程序# (kernel/system_call.s, 131)# 以下中斷在調用時會在中斷返回地址之后將出錯號壓入堆棧,因此返回時也需要將出錯號彈出。# int8 -- 雙出錯故障。(下面這段代碼的含義參見圖4.1(b))。_double_fault:pushl $_do_double_fault # C 函數地址入棧。error_code:xchgl %eax,4(%esp) # error code <-> %eax,eax 原來的值被保存在堆棧上。xchgl %ebx,(%esp) # &function <-> %ebx,ebx 原來的值被保存在堆棧上。pushl %ecxpushl %edxpushl %edipushl %esipushl %ebppush %dspush %espush %fspushl %eax # error code # 出錯號入棧。lea 44(%esp),%eax # offset # 程序返回地址處堆棧指針位置值入棧。pushl %eaxmovl $0x10,%eax # 置內核數據段選擇符。mov %ax,%dsmov %ax,%esmov %ax,%fscall *%ebx # 調用相應的C 函數,其參數已入棧。addl $8,%esp # 堆棧指針重新指向棧中放置fs 內容的位置。pop %fspop %espop %dspopl %ebppopl %esipopl %edipopl %edxpopl %ecxpopl %ebxpopl %eaxiret# int10 -- 無效的任務狀態段(TSS)。_invalid_TSS:pushl $_do_invalid_TSSjmp error_code# int11 -- 段不存在。_segment_not_present:pushl $_do_segment_not_presentjmp error_code# int12 -- 堆棧段錯誤。_stack_segment:pushl $_do_stack_segmentjmp error_code5.3 asm.s 程序# int13 -- 一般保護性出錯。_general_protection:pushl $_do_general_protectionjmp error_code# int7 -- 設備不存在(_device_not_available)在(kernel/system_call.s,148)# int14 -- 頁錯誤(_page_fault)在(mm/page.s,14)# int16 -- 協處理器錯誤(_coprocessor_error)在(kernel/system_call.s,131)# 時鐘中斷int 0x20 (_timer_interrupt)在(kernel/system_call.s,176)# 系統調用int 0x80 (_system_call)在(kernel/system_call.s,80)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -