SuperH编译器提供了一个软中断函数trapa_svc(),该函数为可变参数,如下:
int trapa_svc(int trap_no, int index, type1 para1, type2 para2, type2 para3, type4 para4);
描述:系统调用
when trapa_svc is executed, index is specified in R0,
...and para1 to para4 in R4 to R7, respectively.
...Then, TRAPA #trap_no is executed.
; system_call为软中断处理程序
_system_call:
MOVML.L R14,@-R15
MOV.L #sys_call_table, R10 ; get the address of the function table
SHLL2 R0 ; index = index * 4
ADD R0,R10 ; element address = sys_call_table + index * 4
MOV.L @R10,R10 ; get the address of the corresponding function in table
JSR @R10 ; call the corresponding routine
NOP
MOVML.L @R15+,R14
RTE ;中断返回,切换到用户模式
NOP
; 函数指针数组,4字节对齐
.section D,DATA,ALIGN=4
sys_call_table:
.DATA.L _sys_fun0 ; index 0
.DATA.L _sys_fun1 ; index 1
.DATA.L _sys_fun2 ; index 2
.DATA.L _sys_fun3 ; index 3
.DATA.L _sys_fun4 ; index 4
.DATA.L _sys_fun5 ; index 5
.DATA.L _sys_fun6 ; index 6