ecos中断分析.docx

上传人:b****7 文档编号:9623972 上传时间:2023-02-05 格式:DOCX 页数:10 大小:20.47KB
下载 相关 举报
ecos中断分析.docx_第1页
第1页 / 共10页
ecos中断分析.docx_第2页
第2页 / 共10页
ecos中断分析.docx_第3页
第3页 / 共10页
ecos中断分析.docx_第4页
第4页 / 共10页
ecos中断分析.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

ecos中断分析.docx

《ecos中断分析.docx》由会员分享,可在线阅读,更多相关《ecos中断分析.docx(10页珍藏版)》请在冰豆网上搜索。

ecos中断分析.docx

ecos中断分析

eCos学习笔记之中断处理代码分析

2006-07-2411:

06

中断处理代码分析:

.macro   hal_vectors_init//中断向量初始化,packages/hal/mips/ref4955/v2_0/include/platform.inc

       #Ifwedon~tplaynicewithaROMmonitor,copytherequired

       #vectorsintotheproperlocation.

   la   t0,0x80000000      #destaddr//有些MIPS变种不需要处理tlb的异常

   la   t1,utlb_vector      #sourceaddr

   la   t3,utlb_vector_end   #enddestaddr

1:

   

   lw   v0,0(t1)      #getword

   addi   t1,t1,4

   sw   v0,0(t0)      #writeword

   addi   t0,t0,4

   bne   t1,t3,1b

   nop

   la   t0,0x80000180      #destaddr//将other_vector拷贝到0x80000180处,完成中断向量的安装

   la   t1,other_vector      #sourceaddr

   la   t3,other_vector_end   #enddestaddr

1:

   

   lw   v0,0(t1)      #getword

   addi   t1,t1,4

   sw   v0,0(t0)      #writeword

   addi   t0,t0,4

   bne   t1,t3,1b

   nop

   .endm

   

.section".other_vector","ax"//中断处理代码安装的位置

   #Commonvectorat0x80000080or0xBFC00180

   

FUNC_START(other_vector)//MIPS异常处理程序的入口,packages/hal/mips/arch/v2_0/src/vectors.S

   mfc0   k0,cause      #K0=exceptioncause//读取cause寄存器

   nop

   andi   k0,k0,0x7F      #isolateexceptioncode//取cause寄存器中的ExcCode值

   la   k1,hal_vsr_table   #addressofVSRtable//取VSR表的基地址

   add   k1,k1,k0      #offsetofVSRentry//根据ExcCode值取得VSR表的入口地址

   lw   k1,0(k1)      #k1=pointertoVSR//取得VSR表中对应处理程序的地址

   jr   k1         #gothere//跳转执行

   nop            #(delayslot)

FUNC_END(other_vector)

##VSRtable.

##ThemaininterruptcodeindirectsthroughheretofindtheVSR

##toexecuteforeacharchitecturedefinedinterrupt.

##Thisisonlyusedforsimulatedtargets,onrealtargetsafixedlocationVSR

##tableisnowallocatedat0x80000100.

#ifndefCYG_HAL_MIPS_VSR_TABLE_DEFINED

   

##   .section".vsr_table","a"//VSR表

   

   .data//VSR表在data段中

         

   .globl   hal_vsr_table

hal_vsr_table:

   

   .long   __default_interrupt_vsr   //定义了64个interrupt入口

   .rept   63

   .long   __default_exception_vsr   

   .endr

#endif   

##DefaultinterruptVSR.

##SavesmachinestateandcallsappropriateISR.Whendone,calls

##interrupt_end()tofinishupandpossiblyreschedule.   

FUNC_START(__default_interrupt_vsr)//缺省的中断处理程序

   

   #WeenterherewithalloftheCPUstatestill

   #initsregistersexcept:

   #K0=vectorindex

   #K1=addressofthisfunction

   move   k1,sp         #K1=originalSP//保存原始SP

      

   addi   sp,sp,-mips_exception_decrement//分配stack空间

            #spaceforregisters+safetymargin

   sw   k0,mipsreg_vector(sp)   #storevector//将异常类型(即ExcCode值)存入堆栈

   #storeGPRs//保存通用寄存器

   .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   19,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

   #K1containsoriginalSP

   ssp   k1,sp         #storeinregdump   //保存原始SP到新的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_savesp//保存浮点寄存器,packages/hal/mips/arch/v2_0/include/arch.inc,如果处理器没有fpu则该宏为空,Lupine没有浮点寄存器

      //到此为止处理器的状态已经保存到栈上了

   #Themachinestateisnowallsavedonthestack.

   #LoadGlobalPointerregister.

   la   gp,_gp//加载gp指针

   

#ifdefCYGFUN_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            #savepointertosavedstate//取sp指针,留做后用

#ifdefCYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK//如果中断使用独立堆栈

   la   a0,__interrupt_stack      #a0=stacktop//栈顶指针

   la   a1,__interrupt_stack_base   #a1=stackbase//栈基址,定义如下:

                      .bss

     .balign16

                 .globalcyg_interrupt_stack_base

                      cyg_interrupt_stack_base

                  __interrupt_stack_base:

                     .reptCYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE//stack的大小

                 .byte0

                 .endr

   sub   a3,sp,a1         #a3=sp-base//现在的sp是否比__interrupt_stack_base小

   bltz   a3,1f            #notonistackif<0

   nop               #delayslot

   sub   t0,a0,sp         #t0=top-sp//现在的sp是否比__interrupt_stack大

   bgtz   t0,8f            #alreadyonistackif>0

   nop               #delayslot

1:

   

   move   sp,a0            #switchtoistack//notonistack

8:

   addi   sp,sp,-8         #spaceforoldSP//onistack,为保存现在的sp留出空间

                  #(8tokeepdwordalignment!

   sw   s0,0(sp)         #saveoldSPonstack//保存现在的sp

#endif

         

   subu   sp,sp,mips_stack_frame_size   #makeanullframe    //做一个空的栈帧(32bytes)

   #Needtosetupbackpointersetc.?

?

?

   #Decodeexternalinterruptviainterruptcontroller

   hal_intc_decode   s2//根据cause寄存器的IP位解码,返回IP号,packages/hal/mips/tx39/v2_0/include/variant.inc

   #Here,s2containsthenumberoftheinterruptbeingserviced,

   #weneedtoderivefromthatthevectornumbertocallintheISR

   #table.

   

   hal_intc_translates2,s1//packages/hal/mips/tx39/v2_0/include/variant.inc

   

   #Heres1isthenumberofthevectortobecalledands2is

   #thenumberoftheinterruptbeingserviced.

   hal_diag_intr_start//中断诊断程序,可以不实现,packages/hal/mips/vrc437x/v2_0/include/platform.inc

      

#ifdefined(CYGPKG_KERNEL_INSTRUMENT)&&defined(CYGDBG_KERNEL_INSTRUMENT_INTR)

   #Callcyg_instrumenttorecordthatthisinterruptisbeingraised.//记录程序

      

   li   a0,0x0301         #a0=type=INTR,RAISE

   move   a1,s1            #a1=vectornumber

   jal   cyg_instrument         #callinstrumentfunction

    move   a2,s2            #a2=interruptnumber

#endif

#ifdefined(CYGDBG_HAL_MIPS_DEBUG_GDB_CTRLC_SUPPORT)

   #IfwearesupportingCtrl-CinterruptsfromGDB,wemustsquirrel

   #awayapointertothesaveinterruptstateheresothatwecan

   #plantabreakpointatsomelatertime.

   

   .extern   hal_saved_interrupt_state//使用GDBstub调试时,用于保存中断状态

   la   v0,hal_saved_interrupt_state

   sw   s0,0(v0)//s0是sp指针

   

#endif

   

   sll   s1,s1,2            #s1=byteoffsetofvector//根据中断向量号计算中断向量偏移

   //在此之前都是禁用中断的

   hal_cpu_except_enable         #reenableexceptions//启用中断,packages/hal/mips/arch/v2_0/include/arch.inc

   la   t2,hal_interrupt_handlers   #handlertable//加载中断处理程序表,如果未定以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         #addressofISRptr//根据中断向量号计算在中断处理程序表中的偏移

   lw   t2,0(t2)         #ISRpointer//取中断处理程序地址

   la   a1,hal_interrupt_data      #datatable//加载中断处理程序数据表,定义位置与hal_interrupts_handlers一样

   add   a1,a1,s1         #addressofdataptr//计算中断处理程序数据偏移

   lw   a1,0(a1)         #Datapointer//将中断处理程序数据地址存入a1,作为参数

   move   a0,s2            #passinterruptnumber//将中断号存入a0寄存器,作为参数

   jalr   t2            #callISRviat2//调用具体的中断处理程序,有两个参数,分别是中断向量号和中断处理程序数据

   nop               #(delayslot)

#ifdefCYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK

   #Ifwearereturningfromthelastnestedinterrupt,moveback

   #tothethreadstack.interrupt_end()mustbecalledonthe

   #threadstacksinceitpotentiallycausesacontextswitch.

   #Sincewehavearrangedforthetopofstacklocationto

   #containthespweneedtogobacktohere,justpopitoff

   #andputitinSP.

   

   lw   sp,mips_stack_frame_size(sp)   #sp=*sp

   subu   sp,sp,mips_stack_frame_size   #makeanullframe      

#endif

   

#ifdefCYGFUN_HAL_COMMON_KERNEL_SUPPORT

   #Weonlyneedtocall_interrupt_end()whenthereisakernel

   #presenttodoanytidyingup.

   

   #Onreturnv0bit1willindicatewhetheraDSRis

   #tobeposted.Passthistogetherwithapointerto

   #theinterruptobjectwehavejustusedtothe

   #interrupttidyuproutine.

   #Notethats0,s1ands2aredefinedtobepreservedacross

   #callsbythecallingconvention,sotheystillcontain

   #theregisterdump,thevectoroffsetandtheinterruptnumber

   #respectively.

   move   s2,v0//临时保存中断处理程序的返回值

      

   la   a1,hal_interrupt_objects   #interruptobjecttable//取中断对象,定义位置与hal_interrupt_handlers一样,将地址存入a1,用作参数

   add   a1,a1,s1         #addressofobjectptr

   lw   a1,0(a1)         #a1=objectptr

   move   a2,s0            #arg3=savedregisterdump//堆栈指针存入a2,作为参数

   

   .extern   interrupt_end

   jal   interrupt_end         #callintoCtofinishoff//调用interrupt_end做后面的处理(挂起DSR,解锁调度器,执行DSR),有三个参数,分别是ISR返回值,中断对象,堆栈指针,此处可能导致线程上下文切换

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

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

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