跳至主要内容

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.

Personalized Google Home

Using your google account, you can create a personalized homepage. You can customize several modules, including various news, gmail, bookmarks. This service is similar to what http://www.netvibes.com/ provides. The drawback is the inconvenience of bookmark module. It doesn't provide grouping while netvibes provide tags to implement this. Wishing google will improve this defect in the near future. Meanwhile, the Live plan of Microsoft is also going on. MS presents several several servicies to counterattack google's counterparts. Virtual Earth (see http://preview.local.live.com ) is a recent service. It provides map service just like google earth, provides a virtual tour better than google. Imaging driving a car in the map and seeing everything real, maybe you can do a virtual europe tour now. Seems interesting. MS also provides a customized home, you can log into www.live.com via your msn accounts. I haven't tried that yet.