2009. 3. 7. 13:36

ARM에서의 Veneer, Veneer code

Veneer 사전적인 의미는 합판 이라는 의미입니다.
(어릴때 가끔씩 베니어 합판이라는 용어를 들은 적도 있는 것 같습니다.)

처음 ARM에서 veneer 란 용어를 접했을때 제일 먼저 찾아본것이 사전인데
ARM에서 의도하는 바와는 좀 다르더군요.

사실 veneer에 대해서 몰라도 동작자체가 잘 안되고 하는 것은 아니지만,
아마도 ARM을 공부하는 사람이라면 기본적으로 알아야 겠지요. 더구나 디버깅을 잘하려면 말이죠.
인터넷에서는 위에서 말한 합판이라는 용어가 같은 단어라 참 찾기도 애매합니다.
그래서 ARM Manual을 뒤져서 정리했습니다.


Veneer에 대해서 ADS(Arm Development Suite) 에서는 다음과 같이 설명하고 있습니다.

Veneer
A small block of code used with subroutine calls when there is a requirement to change processor state or branch to an address that cannot be reached in the current processor state.

Veneer generation
armlink must generate veneers when:
  ● branch involves change of state between ARM state and Thumb state
  ● branch involves a destination beyond the branching range of the current state.
A veneer can extend the range of branch and change processor state. armlink combines long branch capability into the state change capability. All interworking veneers are also long branch veneers.
The following veneer types handle different branching requirements. The linker generates position-independent versions of the veneers if required:

ARM to ARM
    Long branch capability.
ARM to Thumb
    Long branch capability and interworking capability.
Thumb to ARM
    Long branch capability and interworking capability.
Thumb to Thumb
    Long branch capability.

armlink creates one input section called Veneer$$Code for each veneer. A veneer is generated only if no other existing veneer can satisfy the requirements. If two input sections contain a long branch to the same destination, only one veneer is generated if the veneer can be reached by both sections.
All veneers cannot be collected into one input section because the resulting veneer input section might not to be within range of other input sections. If the sections are not within addressing range, long branching is not possible.


결국 가장 veneer code를 사용하는 목적은 두가지로 정리됩니다.
  1. branch 시에 ARM mode와 Thumb mode 간의 상태변환이 필요할때.
  2. branch 시에 branch 하는 대상 address가 access 가능한 range를 벗어나 확장이 필요할때(if long branch is needed)
** 참고로 이 두가지에 모두 해당하는 상황도 있습니다.

이제 위의 두가지 경우에 대해서 좀더 자세히 살펴보면

1. ARM Thumb state transition
ARM instruction은 32bit 이고 Thumb instruction은 16bit입니다. 그래서 ARM instruction으로 작성된 함수에서 Thumb instruction으로 작성된 함수를 호출할 경우에는 반드시 상태 변환이 필요합니다.
다음에 좋은 예가 있습니다.
아래를 보면, $Ven$AT$$ThumbFunc 를 호출하는 부분이 있습니다. 이것을 쫓아가 보면
0x0A001028 에 있는 값을 r12에 저장하고, bx 를 사용하여 r12에 저장된 주소를 분기하고 있습니다.
bx 는 branch 후 state를 바꾸게 되는데, address가 홀수이면 ARM->Thumb으로 짝수이면, Thumb->ARM으로 변경합니다.
결국 아래 부분은 0x0A00101D가 홀수 address이므로 branch 후 ARM->Thumb으로 state를 바꾸게 됩니다.

여담으로 linker가 생성하는 심볼인 $Ven$AT$$ThumbFunc 는 AT가 ARM->Thumb으로 변환함을 의미합니다.
그밖에 AA,TA,TT 가 있습니다. 지금 아래 예제에는 없지만, long branch 를 나타내는 부분도 있습니다.
참고로 ARM에서의 veneer 관련 symbol naming및 의미입니다.
    ${Ven|other}${AA|AT|TA|TT}${I|L|S}[$PI]$$symbol_name
    AA : ARM to ARM
    AT : ARM to Thumb
    TA : Thumb to ARM
    TT : Thumb to Thumb
     I : Inline
    L : Long branch
    S : Short reach
    PI : Position Independent

	   ARMFunc
0x0A001000:	mov	r0,#1
0x0A001004:	bl	$Ven$AT$$ThumbFunc
0x0A001008:	mov	r2,#3
0x0A00100C:	mov	r0,#0x18
0x0A001010:	ldr	r1,0x0A001018 ; =#0x0A020013
0x0A001014:	mov	r0,#0
0x0A001018:	dcd	0x0A020013
	   ThumbFunc
0x0A00101C:	mov	r0,#1
0x0A00101E:	bx	r14	
	   $Ven$AT$$ThumbFunc
0x0A001020:	ldr	r12,0x0A001028 ; = #0x0A00101D
0x0A001024:	bx	r12
0x0A001028:	dcd	0x0A00101D
0x0A00102C:	dcd	0x0A00331F
0x0A001030:	dcd	0x007F2E00
0x0A001034:	dcd	0xA703031F
0x0A001038:	dcd	0xA703032E



2.Long branch out of range
다음을 보면 range를 벗어나 확장이 필요한 경우(out of range)에 대한 적절한 설명이 있습니다. 역시 ARM manual입니다.

Machine-level B and BL instructions have a range of ± 32Mb from the address of the current instruction. However, you can use these instructions even if label is out of range. Often you do not know where label is placed by the linker. When necessary, the ARM linker adds code to allow longer branches (see The ARM linker chapter in Linker and Utilities Guide). The added code is called a veneer.

address range가 32Mb 정도이고 이것을 벗어나는 address일경우에는 veneer를 쓴다는 이야기입니다.
(이것은 register의 크기가 4byte, 즉 32bit 이기 때문입니다.)
하지만 이것도 ARM mode에서의 이야기이고, Thumb mode에서는 16bit입니다.
간단한 내용으로 따로 예제는 들지 않지만, 위와 비슷합니다.

출처 : 직접 작성
References
  http://www.arm.com
  ADS Manual
  Elf for ARM architecture

2009. 2. 1. 14:06
I2C Bus Interface
  - 1. Introduction

-------------------------------------------------------------------------------------
1. I2C, I2C(IIC) Bus Interface

  간단히 말해 통신방식의 하나로서, 주로 주변장치(Peripheral)와 통신/제어 용으로 많이 사용합니다.
  SCLK, SDATA 두개의 line을 사용하는 동기식 직렬통신(Synchoronous Serial Communication)의 하나입니다.
  비슷한 방식 통신 방식에는 UART, SPI 등이 있습니다.

  사실 별 신경쓰지 않고 있는 IIC, I2C 이 이름은 Inter-IC의 약자이다. IC는 Intergrated Circuit의 약자이다.
  어느 사이트에서 이 이름의 발음을 나름 쉽고 재미있게 표현했다.
  "eye-squared-see" 물론 이것은 발음상의 이야기이다

  통신 방식의 하나이지만, 앞서 말한 Inter-IC에서 보듯이, 주 목적이 제어입니다.
  
  여담으로 말하자면, 처음 고안한 회사가 Philips(현 NXP) 입니다.
  실제 이 회사 사이트에 가면 i2c specification을 얻을 수 있습니다.
  다음 링크를 참조하세요
  http://www.nxp.com/acrobat_download/literature/9398/39340011.pdf

2. 기본적인 구성 및 통신 방식 
   * 기본적인 구성
     - SCL : Serial Clock
     - SDA : Serial Data
     - 이 두 SCL, SDA로 Send, Recieve를 모두 수행합니다.

   *  Transferring bit/bytes

   * 기본적인 특징 및 통신 방식
     - Master Slave Relationship
       모든 I2C 장치들은 Master와 Slave간의 통신입니다.
       사실 이둘을 어떻게 구분하느냐는 것은 간단히 Clock generation을 누가 하느냐라고 보면 됩니다.

     - Single Master, Multiple Slave
       하나의 Master에 여러개의 Slave가 연결될 수 있습니다.
       이런 특징과 더불어 Slave device는 device고유의 Slave address를 가지고 이를 통해 각각의 Slave와 통신합니다.

     - Communication Protocol
       ▷ Slave Address를 지정
       ▷ I2C의 구성에서 보듯이 Read/Write에 대한 전용 line이 없고 통신 프로토콜 상에서 Read/Write를 결정.
       ▷ ACK(Acknowledgement), NACK(Non-Acknowledgement)
         [Slave Address][R/W][NACK/ACK]  [DATA][NACK/ACK]



--------------------------------------------------------------------------------------------------------
출처 : 직접 작성