📄 semalib.s
字号:
* STATUS semTake* (* SEM_ID semId, /@ semaphore ID to give @/* int timeout /@ timeout in ticks @/* )*/ .balign 16,0x90FUNC_LABEL(semTake) movl SP_ARG1(%esp),%ecx /* semId goes into %ecx */ testl $1,%ecx /* is it a global semId */ jne semTakeGlobal /* if LSB is 1, its a global sem */#ifdef WV_INSTRUMENTATION /* * windview instrumentation - BEGIN * semTake: object status class */ cmpl $0,FUNC(evtAction) /* is WindView on? */ je noSemTakeEvt cmpl $FUNC(semClass),(%ecx) /* check validity */ je objOkTake cmpl $FUNC(semInstClass),(%ecx) /* check validity */ jne noSemTakeEvt /* invalid semaphore */objOkTake: movl $ WV_CLASS_3_ON,%eax andl FUNC(wvEvtClass),%eax /* is event collection on? */ cmpl $ WV_CLASS_3_ON,%eax /* is event collection on? */ jne trgCheckSemTake pushl %eax pushl %ecx /* semId */ pushl %edx /* is this semaphore object instrumented? */ movl (%ecx),%eax /* %ecx - semId */ cmpl $0,SEM_INST_RTN(%eax) /* event routine attached? */ je trgNoSemTake /* log event for this object */ pushl $0 pushl $0 movl $0,%edx movw SEM_RECURSE(%ecx),%dx /* recursively called */ pushl %edx movl SEM_STATE(%ecx),%edx /* state/count/owner */ pushl %edx pushl %ecx /* semId */ pushl $ 3 /* number of paramters */ pushl $ EVENT_SEMTAKE /* EVENT_SEMTAKE, event id */ movl SEM_INST_RTN(%eax),%edx /* get logging routine */ call *%edx /* call routine */ addl $28,%esptrgNoSemTake: popl %edx popl %ecx /* semId */ popl %eaxtrgCheckSemTake: movl $ TRG_CLASS_3,%eax orl $ TRG_ON,%eax cmpl FUNC(trgEvtClass),%eax /* any trigger? */ jne noSemTakeEvt movl FUNC(_func_trgCheck),%eax /* triggering routine */ cmpl $0,%eax je noSemTakeEvt pushl %ecx /* semId */ pushl %edx pushl $ 0 /* 0 */ pushl $ 0 /* 0 */ movl $0,%edx movw SEM_RECURSE(%ecx),%dx /* recursively called */ pushl %edx movl SEM_STATE(%ecx),%edx /* state/count/owner */ pushl %edx pushl %ecx /* semId */ pushl %ecx /* objId */ pushl $ TRG_CLASS3_INDEX /* TRG_CLASS3_INDEX */ pushl $ EVENT_SEMTAKE /* EVENT_SEMTAKE, event id */ call *%eax /* call triggering routine */ addl $32,%esp popl %edx popl %ecx /* semId */noSemTakeEvt: /* windview instrumentation - END */#endif /* WV_INSTRUMENTATION */ movb SEM_TYPE(%ecx),%dl /* get semaphore class into %edx */ andl $ SEM_TYPE_MASK,%edx /* mask %edx to sane value */ jne semTakeNotBinary /* optimize binary semaphore %edx==0 */ /* * BINARY SEMAPHORE OPTIMIZATION * assumptions are: * - %ecx = semId (%ecx is a volatile register) */FUNC_LABEL(semBTake) cmpl $0, FUNC(intCnt) /* is it in ISR? */ jne FUNC(semIntRestrict) /* yes: let C do the work */ pushfl /* save IF in EFLAGS */ cli /* LOCK INTERRUPTS */ cmpl $FUNC(semClass),(%ecx) /* check validity */#ifdef WV_INSTRUMENTATION je objOkBTake /* object is okay */ /* windview - check the validity of instrumented class */ cmpl $FUNC(semInstClass),(%ecx) /* check validity */ jne semIsInvalidUnlock /* semaphore id error */objOkBTake:#else jne semIsInvalidUnlock /* invalid semaphore */#endif /* WV_INSTRUMENTATION */ movl SEM_STATE(%ecx),%eax /* test for owner */ testl %eax,%eax /* is the sem owned? */ jne FUNC(semQPut) /* if sem is owned we block */ movl FUNC(taskIdCurrent),%edx movl %edx,SEM_STATE(%ecx) /* set the owner */ popfl /* UNLOCK INTERRUPTS */ ret /* %eax is still 0 for OK */ .balign 16,0x90semTakeNotBinary: movl FUNC(semTakeTbl)(,%edx,4),%edx jmp *%edx /* invoke take rtn, it will ret */ .balign 16,0x90semTakeGlobal: addl FUNC(smObjPoolMinusOne),%ecx /* convert id to local addr */ movb 7(%ecx),%dl /* get semaphore type in %dl */ /* offset 7 is used as the type * is stored in network order */ andl $ SEM_TYPE_MASK,%edx /* mask %edx to MAX_SEM_TYPE */ movl FUNC(semTakeTbl)(,%edx,4),%edx /* %edx is the take rtn. */ pushl SP_ARG2(%esp) /* push timeout */ pushl %ecx /* push converted semId */ call *%edx /* call appropriate take rtn. */ addl $8,%esp /* clean up */ ret/********************************************************************************* semQGet - unblock a task from the semaphore queue head** INTERNAL* assumptions are:* - %ecx = semId (%ecx is a volatile register)* - (%esp + 0x0) = EFLAGS* - (%esp + 0x4) = retAddr* - (%esp + 0x8) = semId*/ .balign 16,0x90FUNC_LABEL(semQGet) movl $1,FUNC(kernelState) /* KERNEL ENTER */#ifdef WV_INSTRUMENTATION /* * windview instrumentation - BEGIN * semGive: task transition state class */ cmpl $0,FUNC(evtAction) /* is WindView on? */ je noSemQGetEvt movl $ WV_CLASS_2_ON,%eax andl FUNC(wvEvtClass),%eax /* is event collection on? */ cmpl $ WV_CLASS_2_ON,%eax /* is event collection on? */ jne trgCheckSemQGet movl FUNC(_func_evtLogM1),%edx /* event log routine */ cmpl $0,%edx je noSemQGetEvt pushl %ecx /* push semId */ pushl $ EVENT_OBJ_SEMGIVE /* EVENT_OBJ_SEMGIVE */ call *%edx /* call event log routine */ addl $4,%esp /* restore stack pointer */ popl %ecx /* pop semId */trgCheckSemQGet: movl $ TRG_CLASS_2,%eax orl $ TRG_ON,%eax cmpl FUNC(trgEvtClass),%eax /* any trigger? */ jne noSemQGetEvt movl FUNC(_func_trgCheck),%edx /* triggering routine */ cmpl $0,%edx je noSemQGetEvt xorl %eax, %eax /* Clear %eax */ pushl %ecx /* semId */ pushl %eax /* 0 */ pushl %eax /* 0 */ pushl %eax /* 0 */ pushl %eax /* 0 */ pushl %ecx /* push semId */ pushl %ecx /* objId */ pushl $ TRG_CLASS2_INDEX /* TRG_CLASS3_INDEX */ pushl $ EVENT_OBJ_SEMGIVE /* EVENT_OBJ_SEMGIVE */ call *%edx /* call triggering routine */ addl $32,%esp popl %ecx /* semId */noSemQGetEvt: /* windview instrumentation - END */#endif /* WV_INSTRUMENTATION */ popfl /* UNLOCK INTERRUPTS */ leal SEM_Q_HEAD(%ecx),%edx pushl %edx /* push the pointer to qHead */ call FUNC(windPendQGet) /* unblock someone */ addl $4,%esp /* clean up */ call FUNC(windExit) /* KERNEL EXIT */ ret /* windExit sets %eax *//********************************************************************************* semQPut - block current task on the semaphore queue head** INTERNAL* assumptions are:* - %ecx = semId (%ecx is a volatile register)* - (%esp + 0x0) = EFLAGS* - (%esp + 0x4) = retAddr* - (%esp + 0x8) = semId* - (%esp + 0xc) = timeout*/ .balign 16,0x90FUNC_LABEL(semQPut) movl $1,FUNC(kernelState) /* KERNEL ENTER */#ifdef WV_INSTRUMENTATION /* * windview instrumentation - BEGIN * semTake: task transition state class */ cmpl $0,FUNC(evtAction) /* is WindView on? */ je noSemQPutEvt movl $ WV_CLASS_2_ON,%eax andl FUNC(wvEvtClass),%eax /* is event collection on? */ cmpl $ WV_CLASS_2_ON,%eax /* is event collection on? */ jne trgCheckSemQPut movl FUNC(_func_evtLogM1),%edx /* call event log routine */ cmpl $0,%edx je trgCheckSemQPut pushl %ecx /* push semId */ pushl $ EVENT_OBJ_SEMTAKE /* EVENT_OBJ_SEMTAKE */ call *%edx addl $4,%esp /* restore stack pointer */ popl %ecx /* pop semId */trgCheckSemQPut: movl $ TRG_CLASS_2,%eax orl $ TRG_ON,%eax cmpl FUNC(trgEvtClass),%eax /* any trigger? */ jne noSemQPutEvt movl FUNC(_func_trgCheck),%edx /* triggering routine */ cmpl $0,%edx je noSemQPutEvt pushl %ecx /* semId */ pushl $ 0 /* 0 */ pushl $ 0 /* 0 */ pushl $ 0 /* 0 */ pushl $ 0 /* 0 */ pushl %ecx /* push semId */ pushl %ecx /* objId */ pushl $ TRG_CLASS2_INDEX /* TRG_CLASS3_INDEX */ pushl $ EVENT_OBJ_SEMTAKE /* EVENT_OBJ_SEMTAKE */ call *%edx /* call triggering routine */ addl $32,%esp popl %ecx /* semId */noSemQPutEvt: /* windview instrumentation - END */#endif /* WV_INSTRUMENTATION */ popfl /* UNLOCK INTERRUPTS */ pushl SP_ARG2(%esp) /* push the timeout */ leal SEM_Q_HEAD(%ecx),%eax pushl %eax /* push the &semId->qHead */ call FUNC(windPendQPut) /* block on the semaphore */ addl $8,%esp /* tidy up */ testl %eax,%eax /* if (windPendQPut() != OK) */ jne semQPutFail /* put failed */ call FUNC(windExit) /* else KERNEL EXIT */ testl %eax,%eax /* if (windExit() != OK) */ jne semWindExitNotOk /* RESTART */ ret /* done */ .balign 16,0x90semWindExitNotOk: cmpl $1,%eax /* check for RESTART retVal */ je semRestart ret /* EAX = ERROR */ .balign 16,0x90semQPutFail: call FUNC(windExit) /* KERNEL EXIT */ movl $-1,%eax /* return ERROR */ ret /* return to sender */ .balign 16,0x90semRestart: pushl SP_ARG2(%esp) /* push the timeout */ movl FUNC(_func_sigTimeoutRecalc),%eax call *%eax /* recalc the timeout */ addl $4,%esp /* clean up */ movl %eax,SP_ARG2(%esp) /* and store it */ jmp FUNC(semTake) /* start the whole thing over *//********************************************************************************* semOTake - VxWorks 4.x semTake** Optimized version of semOTake. This inserts the necessary argument of* WAIT_FOREVER for semBTake.*/ .balign 16,0x90FUNC_LABEL(semOTake) pushl $-1 /* push WAIT_FOREVER on stack */ movl SP_ARG1+4(%esp),%ecx /* put semId in %ecx */ pushl %ecx /* put semId on stack */ call FUNC(semBTake) /* do semBTake */ addl $8,%esp /* cleanup */ ret /********************************************************************************* semClear - VxWorks 4.x semClear** Optimized version of semClear. This inserts the necessary argument of* NO_WAIT for semBTake().*/ .balign 16,0x90FUNC_LABEL(semClear) pushl $0 /* push NO_WAIT on stack */ movl SP_ARG1+4(%esp),%ecx /* put semId in %ecx */ pushl %ecx /* put semId on stack */ call FUNC(semBTake) /* do semBTake */ addl $8,%esp /* cleanup */ ret#endif /* !PORTABLE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -