ImageVerifierCode 换一换
格式:DOCX , 页数:10 ,大小:20.47KB ,
资源ID:9623972      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9623972.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(ecos中断分析.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

ecos中断分析.docx

1、ecos中断分析eCos学习笔记之中断处理代码分析2006-07-24 11:06中断处理代码分析:.macro hal_vectors_init /中断向量初始化,packages/hal/mips/ref4955/v2_0/include/platform.inc # If we dont play nice with a ROM monitor, copy the required # vectors into the proper location. la t0,0x80000000 # dest addr /有些MIPS变种不需要处理tlb的异常 la t1,utlb_vector

2、# source addr la t3,utlb_vector_end # end dest addr1: lw v0,0(t1) # get word addi t1,t1,4 sw v0,0(t0) # write word addi t0,t0,4 bne t1,t3,1b nop la t0,0x80000180 # dest addr /将other_vector拷贝到0x80000180处,完成中断向量的安装 la t1,other_vector # source addr la t3,other_vector_end # end dest addr1: lw v0,0(t1) #

3、 get word addi t1,t1,4 sw v0,0(t0) # write word addi t0,t0,4 bne t1,t3,1b nop .endm .section .other_vector,ax /中断处理代码安装的位置 # Common vector at 0x80000080 or 0xBFC00180 FUNC_START(other_vector) /MIPS异常处理程序的入口,packages/hal/mips/arch/v2_0/src/vectors.S mfc0 k0,cause # K0 = exception cause /读取cause寄存器 no

4、p andi k0,k0,0x7F # isolate exception code /取cause寄存器中的ExcCode值 la k1,hal_vsr_table # address of VSR table /取VSR表的基地址 add k1,k1,k0 # offset of VSR entry /根据ExcCode值取得VSR表的入口地址 lw k1,0(k1) # k1 = pointer to VSR /取得VSR表中对应处理程序的地址 jr k1 # go there /跳转执行 nop # (delay slot)FUNC_END(other_vector)# VSR tab

5、le.# The main interrupt code indirects through here to find the VSR# to execute for each architecture defined interrupt.# This is only used for simulated targets, on real targets a fixed location VSR# table is now allocated at 0x80000100.#ifndef CYG_HAL_MIPS_VSR_TABLE_DEFINED # .section .vsr_table,a

6、 /VSR表 .data /VSR表在data段中 .globl hal_vsr_tablehal_vsr_table: .long _default_interrupt_vsr /定义了64个interrupt入口 .rept 63 .long _default_exception_vsr .endr#endif # Default interrupt VSR.# Saves machine state and calls appropriate ISR. When done, calls# interrupt_end() to finish up and possibly reschedu

7、le. FUNC_START(_default_interrupt_vsr) /缺省的中断处理程序 # We enter here with all of the CPU state still # in its registers except: # K0 = vector index # K1 = address of this function move k1,sp # K1 = original SP /保存原始SP addi sp,sp,-mips_exception_decrement /分配stack空间 # space for registers + safety margin

8、 sw k0,mipsreg_vector(sp) # store vector /将异常类型(即ExcCode值)存入堆栈 # store GPRs /保存通用寄存器 .set noat sgpr 0,sp sgpr 1,sp sgpr 2,sp sgpr 3,sp sgpr 4,sp sgpr 5,sp sgpr 6,sp sgpr 7,sp sgpr 8,sp sgpr 9,sp sgpr 10,sp sgpr 11,sp sgpr 12,sp sgpr 13,sp sgpr 14,sp sgpr 15,sp sgpr 16,sp sgpr 17,sp sgpr 18,sp sgpr 1

9、9,sp sgpr 20,sp sgpr 21,sp sgpr 22,sp sgpr 23,sp sgpr 24,sp sgpr 25,sp# sgpr 26,sp # = K0# sgpr 27,sp # = K1 sgpr 28,sp # = GP# sgpr 29,sp # = SP sgpr 30,sp # = FP sgpr 31,sp # = RA .set at mfhi a0 /保存hi和lo寄存器 mflo a1 shi a0,sp slo a1,sp # K1 contains original SP ssp k1,sp # store in reg dump /保存原始S

10、P到新的stack中的特殊位置上 mfc0 t1,status /保存status,cachectrl和epc寄存器 mfc0 t2,cachectrl mvafc0 t3,epc sw t1,mipsreg_sr(sp) sw t2,mipsreg_cachectrl(sp) sva t3,mipsreg_pc(sp) /epc寄存器 hal_fpu_save sp /保存浮点寄存器,packages/hal/mips/arch/v2_0/include/arch.inc,如果处理器没有fpu则该宏为空,Lupine没有浮点寄存器 /到此为止处理器的状态已经保存到栈上了 # The mach

11、ine state is now all saved on the stack. # Load Global Pointer register. la gp,_gp /加载gp指针 #ifdef CYGFUN_HAL_COMMON_KERNEL_SUPPORT .extern cyg_scheduler_sched_lock la v0,cyg_scheduler_sched_lock /锁住调度器 lw a0,0(v0) addi a0,a0,1 sw a0,0(v0)#endif move s0,sp # save pointer to saved state /取sp指针,留做后用#if

12、def CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK /如果中断使用独立堆栈 la a0,_interrupt_stack # a0 = stack top /栈顶指针 la a1,_interrupt_stack_base # a1 = stack base /栈基址,定义如下: .bss .balign 16 .global cyg_interrupt_stack_base cyg_interrupt_stack_base _interrupt_stack_base: .rept CYGNUM_HAL_COMMON_INTERRUPTS_

13、STACK_SIZE /stack的大小 .byte 0 .endr sub a3,sp,a1 # a3 = sp - base /现在的sp是否比_interrupt_stack_base小 bltz a3,1f # not on istack if 0 nop # delay slot1: move sp,a0 # switch to istack /not on istack8: addi sp,sp,-8 # space for old SP /on istack,为保存现在的sp留出空间 # (8 to keep dword alignment!) sw s0,0(sp) # sav

14、e old SP on stack /保存现在的sp#endif subu sp,sp,mips_stack_frame_size # make a null frame /做一个空的栈帧(32bytes) # Need to set up back pointers etc. ? # Decode external interrupt via interrupt controller hal_intc_decode s2 /根据cause寄存器的IP位解码,返回IP号,packages/hal/mips/tx39/v2_0/include/variant.inc # Here, s2 con

15、tains the number of the interrupt being serviced, # we need to derive from that the vector number to call in the ISR # table. hal_intc_translate s2,s1 /packages/hal/mips/tx39/v2_0/include/variant.inc # Here s1 is the number of the vector to be called and s2 is # the number of the interrupt being ser

16、viced. hal_diag_intr_start /中断诊断程序,可以不实现,packages/hal/mips/vrc437x/v2_0/include/platform.inc #if defined(CYGPKG_KERNEL_INSTRUMENT) & defined(CYGDBG_KERNEL_INSTRUMENT_INTR) # Call cyg_instrument to record that this interrupt is being raised. /记录程序 li a0,0x0301 # a0 = type = INTR,RAISE move a1,s1 # a1

17、 = vector number jal cyg_instrument # call instrument function move a2,s2 # a2 = interrupt number#endif#if defined(CYGDBG_HAL_MIPS_DEBUG_GDB_CTRLC_SUPPORT) # If we are supporting Ctrl-C interrupts from GDB, we must squirrel # away a pointer to the save interrupt state here so that we can # plant a b

18、reakpoint at some later time. .extern hal_saved_interrupt_state /使用GDB stub调试时,用于保存中断状态 la v0,hal_saved_interrupt_state sw s0,0(v0) /s0是sp指针 #endif sll s1,s1,2 # s1 = byte offset of vector /根据中断向量号计算中断向量偏移 /在此之前都是禁用中断的 hal_cpu_except_enable # reenable exceptions /启用中断,packages/hal/mips/arch/v2_0/inc

19、lude/arch.inc la t2,hal_interrupt_handlers # handler table /加载中断处理程序表,如果未定以CYG_HAL_MIPS_ISR_TABLES_DEFINED,该表在packages/hal/mips/arch/v2_0/src/vectors.S中,否则根据platform不同有不同定义,如packages/hal/mips/tx39/v2_0/src/variant.S add t2,t2,s1 # address of ISR ptr /根据中断向量号计算在中断处理程序表中的偏移 lw t2,0(t2) # ISR pointer /

20、取中断处理程序地址 la a1,hal_interrupt_data # data table /加载中断处理程序数据表,定义位置与hal_interrupts_handlers一样 add a1,a1,s1 # address of data ptr /计算中断处理程序数据偏移 lw a1,0(a1) # Data pointer /将中断处理程序数据地址存入a1,作为参数 move a0,s2 # pass interrupt number /将中断号存入a0寄存器,作为参数 jalr t2 # call ISR via t2 /调用具体的中断处理程序,有两个参数,分别是中断向量号和中断处

21、理程序数据 nop # (delay slot)#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK # If we are returning from the last nested interrupt, move back # to the thread stack. interrupt_end() must be called on the # thread stack since it potentially causes a context switch. # Since we have arranged for the t

22、op of stack location to # contain the sp we need to go back to here, just pop it off # and put it in SP. lw sp,mips_stack_frame_size(sp) # sp = *sp subu sp,sp,mips_stack_frame_size # make a null frame #endif #ifdef CYGFUN_HAL_COMMON_KERNEL_SUPPORT # We only need to call _interrupt_end() when there i

23、s a kernel # present to do any tidying up. # On return v0 bit 1 will indicate whether a DSR is # to be posted. Pass this together with a pointer to # the interrupt object we have just used to the # interrupt tidy up routine. # Note that s0, s1 and s2 are defined to be preserved across # calls by the

24、 calling convention, so they still contain # the register dump, the vector offset and the interrupt number # respectively. move s2,v0 /临时保存中断处理程序的返回值 la a1,hal_interrupt_objects # interrupt object table /取中断对象,定义位置与hal_interrupt_handlers一样,将地址存入a1,用作参数 add a1,a1,s1 # address of object ptr lw a1,0(a1) # a1 = object ptr move a2,s0 # arg3 = saved register dump /堆栈指针存入a2,作为参数 .extern interrupt_end jal interrupt_end # call into C to finish off /调用interrupt_end做后面的处理(挂起DSR,解锁调度器,执行DSR),有三个参数,分别是ISR返回值,中断对象,堆栈指针,此处可能导致线程上下文切换

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1