跳至主要内容

VxWorks对中断的处理

我们平时使用intConnect调用挂接中断向量实际是将中断处理函数连接到vxworks内部的一个中断向量表,以MIPS为例,这个表为excBsrTbl,前几项与MIPS处理器的定义相同,但在后面保留了许多向量作为扩展使用。

intConnect为用户提供的回调函数与指针分配一小块内存(通过intHandlerCreate),并调用intVecSet将它设置到excBsrTbl中去。
intHandlerCreate用4条指令包装了用户函数,为原本不支持参数的中断处理函数提供了参数传递的功能。
FUNCPTR intHandlerCreate
(
FUNCPTR routine, /* routine to be called */
int parameter /* parameter to be passed to routine */
)
{
FAST UINT * pCode; /* pointer to newly synthesized code */

pCode = (UINT *) malloc (sizeof (intConnectCode));

if (pCode != NULL)
{
/* copy intConnectCode into new code area */

bcopy ((char *)intConnectCode, (char *)pCode, sizeof (intConnectCode));

/* set the addresses & instructions */

pCode [0] |= HI_WORD (routine);
pCode [1] |= HI_WORD (parameter);
pCode [2] |= LO_WORD (routine);
pCode [4] |= LO_WORD (parameter);
}

/*
* Flush the cache so we don't get instruction
* cache hits to wrong vector
*/

CACHE_TEXT_UPDATE ((void *) pCode, sizeof (intConnectCode));

return ((FUNCPTR)pCode);
}

封装代码与体系结构相关,下面是MIPS的代码,从注释中容易得知其作用,实现利用了指令的二进制编码形式,是一个较为巧妙的思想。
LOCAL UINT intConnectCode [] = /* intConnect stub */
{
/*
* 0x0: 3c08xxxx lui t0,xxxx * msh routine address
* 0x4: 3c04yyyy lui a0,yyyy * msh parameter load
* 0x8: 3508zzzz ori t0,t0,zzzz * lsh routine address
* 0xc: 01000008 jr t0 * jump to routine
* 0x10: 3484pppp ori a0,a0,pppp * lsh load in BD slot
*/
0x3c080000, /* msh routine address runtime load */
0x3c040000, /* msh parameter load runtime load */
0x35080000, /* lsh routine address runtime load */
0x01000008, /* jump to routine */
0x34840000, /* lsh load in BD slot runtime load */
};

然而MIPS异常0代表中断,又如何支持多个中断?这是由于vxworks提供了一个excIntStub中断处理函数作为异常0处理函数,然后根据中断位来分发中断。
这里涉及到两个表:sysHashOrder, IntPrioTable。sysHashOrder表是一个哈希表实现,在多个中断Pending情况下,两个表联合确定最高优先级的中断及该中断的信息。

vxworks提供了两个默认的哈希表,ffsMsbTbl和ffsLsbTbl,它们分别代表高位高先级和高位低先级,对于XLR,我们使用ffsMsbTbl,请看定义:
UINT8 ffsMsbTbl [256] =
{
0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
};
MIPS一共有8个中断位。当多个中断来临时,假定最高位为N,那么2^N范围内的中断都取第N个中断为下一个处理的中断,按这种方式便可以将该表定义出来。
数组的值是对IntPrioTable的索引,在XLR中,定义如下:
PRIO_TABLE intPrioTable[8] =
{
{CAUSE_SW1,(ULONG) IV_XLR(IV_SW0), 0x0100, 0}, /* sw trap 0 */
{CAUSE_SW2,(ULONG) IV_XLR(IV_SW1), 0x0200, 0}, /* sw trap 1 */
{CAUSE_IP3,(ULONG) IV_XLR(IV_HW0), 0x0400, 0}, /* Uart0 */
{CAUSE_IP4,(ULONG) IV_XLR(IV_HW1), 0x0800, 0}, /* Hardware int 1 */
{CAUSE_IP5,(ULONG) IV_XLR(IV_HW2), 0x1000, 0}, /* PCIX */
{CAUSE_IP6,(ULONG) IV_XLR(IV_HW3), 0x2000, 0}, /* Demultiplex */
{CAUSE_IP7,(ULONG) IV_XLR(IV_HW4), 0x4000, 0}, /* Hardware int 4 */
{CAUSE_IP8,(ULONG) IV_XLR(IV_HW5), 0x8000, 0} /* Compare(Timer 0) */
};
IntPrioTable表提供了异常向量,中断向量,掩码等信息,有了中断向量,vxworks便可以通过excBsrTbl表找到中断回调并调用。

评论

此博客中的热门博文

反转剧

这两天明显感到天气转冷,呱呱的家里也已经下起了大雪,南京则是阴冷潮湿,让人没有了出行的欲望。没想到躲在被子里看反转剧也成了度过寒冬的一剂良药。在PPLive越来越让人失望的时候,PPStream横空出世,虽然广告仍是少不了的主题,但从视频质量和播放连续性上来说都超过PPLive,实为居家必备之良品(由此可见,新事物一定会战胜旧事物......)。韩国的反转剧最近似乎比较流行,称之为反转剧就在于其结果总是让人出乎意料,不合常理,其间又不乏各种搞怪搞笑的镜头,各种当红帅哥美女也一定让DDMM们爱不释手,20~30分钟一集的剧情一改韩剧拖沓的风貌,想看就看,容易切入。 反转剧,今天你看了吗?

from cpp to java

when i start to study java with a cpp background, i find it is very difficult to convert my mind. i always think how some features in cpp was implemented in java, this give me a little reject to java language. though java is born from c, i think they still have different applicable domains, so try to study both is good for me, and java is a pure OO language, i believe it will give me a better understanding on OOD.

低谷

近段时间,小猪的身体不好,连续好几个周末游走于各个医院,两人的心情也坏到了极点。现在的小猪已俨然成为一个药罐子,不再提当年之勇。这个周末又发起烧来,像一滩烂泥似地躺在床上,真是祸不单行。 而我呢,由于前任离职的缘故,现在出奇地忙,每天就像打仗似地,压得人喘不过气来,工作与家庭,真有些夹缝中求生存的感觉,两头都要兼顾,我想这一次我们是真的走到一个低谷了吧。 希望这一切都会过去,一切都能圆满地解决。