新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > ARM linux系統(tǒng)調(diào)用的實現(xiàn)原理

ARM linux系統(tǒng)調(diào)用的實現(xiàn)原理

作者: 時間:2011-06-02 來源:網(wǎng)絡(luò) 收藏
源程序:

本文引用地址:http://butianyuan.cn/article/150660.htm

  ENTRY(vector_swi)

  save_user_regs

  zero_fp

  get_scno //將[lr,#-4]中的中斷號轉(zhuǎn)儲到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的內(nèi)容

  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

  //執(zhí)行sys_open函數(shù)

  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, #SWI_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

  adrcond reg, label

  .endm

  //對應(yīng)反匯編:

  //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

linux操作系統(tǒng)文章專題:linux操作系統(tǒng)詳解(linux不再難懂)

上一頁 1 2 下一頁

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉