Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2929359
  • 博文数量: 401
  • 博客积分: 12926
  • 博客等级: 上将
  • 技术积分: 4588
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-22 14:51
文章分类

全部博文(401)

文章存档

2015年(16)

2014年(4)

2013年(12)

2012年(82)

2011年(98)

2010年(112)

2009年(77)

分类: 嵌入式

2012-04-09 23:26:15

EABI /**/ bk.view.expFlag=false;baikeViewInfo={id:"3547622",editable:"true",title:"EABI",expIndex:"0",subLen:"1",isMulit:false};
  内核里面谈EABI,OABI,其实相对于系统调用的方式,当然我们所说的系统限于arm系统。
  关于EABI
  什么是EABI?
  Embedded application binary interface, 即嵌入式应用二进制接口,是描述可连接目标代码,库目标代码,可执行文件影像,如何连接,执行和调试,以及目标代码生成过程,和c, c++语言接口的规范,是编译连接工具的基础规范,也是研究它们工作原理的基础,可惜arm的EABI迄今为止没有完全订好。作为EABI的组成部分有过程调用规范,可执行文件格式规范,c/c++ ABI规范和调试格式规范。
  EABI ,说的是这样的一种新的系统调用方式
  mov r7, #num
  swi 0x0
  原来的系统调用方式是这样,
  swi (#num | 0x900000) (0x900000是个magic值)
  也就是说原来的调用方式(Old ABI)是通过跟随在swi指令中的调用号来进行的,现在的是根据r7中的值。
  现在看两个宏,一个是
  CONFIG_OABI_COMPAT 意思是说和old ABI兼容
  另一个是
  CONFIG_AEABI 意思是说指定现在的方式为EABI
  这两个宏可以同时配置,也可以都不配,也可以配置任何一种。
  我说一下内核是怎么处理这一问题的。
  我们知道,sys_call_table 在内核中是个跳转表,这个表中存储的是一系列的函数指针,这些指针就是系统调用函数的指针,如(sys_open).系统调用是根据一个调用号(通常就是表的索引)找到实际该调用内核哪个函数,然后运行该函数完成的。
  首先,对于old ABI,内核给出的处理是给它建立一个单独的system calltable,叫sys_oabi_call_table,这样,兼容方式下就会有两个system call table, 以oldABI方式的系统调用会执行old_syscall_table表中的系统调用函数,EABI方式的系统调用会用sys_call_table中的函数指针。
  配置无外乎以下4中
  第一 两个宏都配置 行为就是上面说的那样
  第二 只配置CONFIG_OABI_COMPAT , 那么以old ABI方式调用的会用sys_oabi_call_table,以EABI方式调用的 用sys_call_table,和1实质相同,只是情况1更加明确。
  第三 只配置CONFIG_AEABI 系统中不存在 sys_oabi_call_table, 对old ABI方式调用不兼容。只能 以EABI方式调用,用sys_call_table
  第四 两个都没有配置 系统默认会只允许old ABI方式,但是不存在old_syscall_table,最终会通过sys_call_table 完成函数调用
  可以参考下面的代码
  对我们的项目比较有用。
  .align 5
  ENTRY(vector_swi)
  sub sp, sp, #S_FRAME_SIZE
  stmia sp, {r0 - r12} @ Calling r0 - r12
  add r8, sp, #S_PC
  stmdb r8, {sp, lr}^ @ Calling sp, lr
  mrs r8, spsr @ called from non-FIQ mode, so ok.
  str lr, [sp, #S_PC] @ Save calling PC
  str r8, [sp, #S_PSR] @ Save CPSR
  str r0, [sp, #S_OLD_R0] @ Save OLD_R0
  zero_fp
  /*
  * Get the system call number.
  */
  #if defined(CONFIG_OABI_COMPAT)
  /*
  * If we have CONFIG_OABI_COMPAT then we need to look at the swi
  * value to determine if it is an EABI or an old ABI call.
  */
  #ifdef CONFIG_ARM_THUMB
  tst r8, #PSR_T_BIT
  movne r10, #0 @ no thumb OABI emulation
  ldreq r10, [lr, #-4] @ get SWI instruction
  #else
  ldr r10, [lr, #-4] @ get SWI instruction
  A710( and ip, r10, #0x0f000000 @ check for SWI )
  A710( teq ip, #0x0f000000 )
  A710( bne .Larm710bug )
  #endif
  #elif defined(CONFIG_AEABI)
  /*
  * Pure EABI user space always put syscall number into scno (r7).
  */
  A710( ldr ip, [lr, #-4] @ get SWI instruction )
  A710( and ip, ip, #0x0f000000 @ check for SWI )
  A710( teq ip, #0x0f000000 )
  A710( bne .Larm710bug )
  #elif defined(CONFIG_ARM_THUMB)
  /* Legacy ABI only, possibly thumb mode. */
  tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
  addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
  ldreq scno, [lr, #-4]
  #else
  /* Legacy ABI only. */
  ldr scno, [lr, #-4] @ get SWI instruction
  A710( and ip, scno, #0x0f000000 @ check for SWI )
  A710( teq ip, #0x0f000000 )
  A710( bne .Larm710bug )
  #endif
  #ifdef CONFIG_ALIGNMENT_TRAP
  ldr ip, __cr_alignment
  ldr ip, [ip]
  mcr p15, 0, ip, c1, c0 @ update control register
  #endif
  enable_irq
  get_thread_info tsk
  adr tbl, sys_call_table @ load syscall table pointer
  ldr ip, [tsk, #TI_FLAGS] @ check for syscall tracing
  #if defined(CONFIG_OABI_COMPAT)
  /*
  * If the swi argument is zero, this is an EABI call and we do nothing.
  *
  * If this is an old ABI call, get the syscall number into scno and
  * get the old ABI syscall table address.
  */
  bics r10, r10, #0xff000000
  eorne scno, r10, #__NR_OABI_SYSCALL_BASE
  ldrne tbl, =sys_oabi_call_table
  #elif !defined(CONFIG_AEABI)
  bic scno, scno, #0xff000000 @ mask off SWI op-code
  eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
  #endif
  stmdb sp!, {r4, r5} @ push fifth and sixth args
  tst ip, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
  bne __sys_trace
  cmp scno, #NR_syscalls @ check upper syscall limit
  adr lr, ret_fast_syscall @ return address
  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, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
  eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
  bcs arm_syscall
  b 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:
  mov r2, scno
  add r1, sp, #S_OFF
  mov r0, #0 @ trace entry [IP = 0]
  bl syscall_trace
  adr lr, __sys_trace_return @ return address
  mov scno, r0 @ syscall number (possibly new)
  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
阅读(1583) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~