At91rm9200处理器对应的linux2.4.19内核系统调用对应的软中断定义如下:
#if defined(__thumb__) //thumb模式
#define __syscall(name)/
"push {r7}/n/t" /
"mov r7, #" __sys1(__NR_##name) "/n/t" /
"swi 0/n/t" /
"pop {r7}"
#else //arm模式
#define __syscall(name) "swi/t" __sys1(__NR_##name) "/n/t"
#endif
#define __sys2(x) #x
#define __sys1(x) __sys2(x)
#define __NR_SYSCALL_BASE 0x900000 //此为OS_NUMBER << 20运算值
#define __NR_open (__NR_SYSCALL_BASE+ 5) //0x900005
举一个例子来说:open系统调用,库函数最终会调用__syscall (open),宏展开之后为swi #__NR_open,即,swi #0x900005触发中断,中断号0x900005存放在[lr,#-4]地址中,处理器跳转到arch/arm/kernel/entry- common.S中vector_swi读取[lr,#-4]地址中的中断号,之后查询arch/arm/kernel/entry-common.S中的sys_call_table系统调用表,该表内容在arch/arm/kernel/calls.S中定义,__NR_open在表中对应的顺序号为
__syscall_start:
...
.long SYMBOL_NAME(sys_open) //第5个
...
将sys_call_table[5]中内容传给pc,系统进入sys_open函数,处理实质的open动作
注:用到的一些函数数据所在文件,如下所示
arch/arm/kernel/calls.S声明了系统调用函数
include/asm-arm/unistd.h定义了系统调用的调用号规则
vector_swi定义在arch/arm/kernel/entry-common.S
vector_IRQ定义在arch/arm/kernel/entry-armv.S
vector_FIQ定义在arch/arm/kernel/entry-armv.S
arch/arm/kernel/entry-common.S中对sys_call_table进行了定义:
.type sys_call_table, #object
ENTRY(sys_call_table)
#include "calls.S" //将calls.S中的内容顺序链接到这里
源程序:
ENTRY(vector_swi)
save_user_regs
zero_fp
get_scno //将[lr,#-4]中的中断号转储到scno(r7)
arm710_bug_check scno, ip
#ifdef CONFIG_ALIGNMENT_TRAP
ldr ip, __cr_alignment
ldr ip, [ip]
mcr p15, 0, ip, c1, c0 @ update control register
#endif
enable_irq ip
str r4, [sp, #-S_OFF]! @ push fifth arg
get_current_task tsk
ldr ip, [tsk, #TSK_PTRACE] @ check for syscall tracing
bic scno, scno, #0xff000000 @ mask off SWI op-code
//#define OS_NUMBER 9[entry-header.S]
//所以对于上面示例中open系统调用号scno=0x900005
//eor scno,scno,#0x900000
//之后scno=0x05
eor scno, scno, #OS_NUMBER << 20 @ check OS number
//sys_call_table项为calls.S的内容
adr tbl, sys_call_table @ load syscall table pointer
tst ip, #PT_TRACESYS @ are we tracing syscalls?
bne __sys_trace
adrsvc al, lr, ret_fast_syscall @ return address
cmp scno, #NR_syscalls @ check upper syscall limit
//执行sys_open函数
ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
add r1, sp, #S_OFF
2: mov why, #0 @ no longer a real syscall
cmp scno, #ARMSWI_OFFSET
eor r0, scno, #OS_NUMBER << 20 @ put OS number back
bcs SYMBOL_NAME(arm_syscall)
b SYMBOL_NAME(sys_ni_syscall) @ not private func
/*
* This is the really slow path. We're going to be doing
* context switches, and waiting for our parent to respond.
*/
__sys_trace:
add r1, sp, #S_OFF
mov r0, #0 @ trace entry [IP = 0]
bl SYMBOL_NAME(syscall_trace)
/*
//2007-07-01 gliethttp [entry-header.S]
//Like adr, but force SVC mode (if required)
.macro adrsvc, cond, reg, label
adr/cond /reg, /label
.endm
//对应反汇编:
//add lr, pc, #16 ; lr = __sys_trace_return
*/
adrsvc al, lr, __sys_trace_return @ return address
add r1, sp, #S_R0 + S_OFF @ pointer to regs
cmp scno, #NR_syscalls @ check upper syscall limit
ldmccia r1, {r0 - r3} @ have to reload r0 - r3
ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
b 2b
__sys_trace_return:
str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
mov r1, sp
mov r0, #1 @ trace exit [IP = 1]
bl SYMBOL_NAME(syscall_trace)
b ret_disable_irq
.align 5
#ifdef CONFIG_ALIGNMENT_TRAP
.type __cr_alignment, #object
__cr_alignment:
.word SYMBOL_NAME(cr_alignment)
#endif
.type sys_call_table, #object
ENTRY(sys_call_table)
#include "calls.S"
上一篇:ARM Linux中断向量表搬移设计过程
下一篇:Ubuntu9.10在ARM上建立NFS服务
推荐阅读最新更新时间:2024-03-16 14:57
设计资源 培训 开发板 精华推荐
- PC产业驶入创新超车道,英特尔蓉城撬动AI新引擎
- 与产业聚力共赢,英特尔举行新质生产力技术生态大会
- “新”享5G-A万兆网络前沿体验 高通携手产业伙伴亮相第二届链博会
- 英飞凌推出符合ASIL-D标准的新型汽车制动系统和电动助力转向系统三相栅极驱动器 IC
- 南芯科技推出80V升降压转换器,持续深耕工业储能市场
- 法雷奥与罗姆联合开发新一代功率电子领域
- 贸泽电子开售能为电动汽车牵引逆变器提供可扩展性能的 英飞凌HybridPACK Drive G2模块
- 德州仪器新型 MCU 可实现边缘 AI 和先进的实时控制, 提高系统效率、安全性和可持续性
- 瑞萨推出高性能四核应用处理器, 增强工业以太网与多轴电机控制解决方案阵容
- 研华全新模块化电脑SOM-6833助力5G路测设备升级