我们平时使用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表找到中断回调并调用。
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表找到中断回调并调用。
评论