1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu ARM Architecture Reference Manual- P11 pptx

30 428 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Thumb Instruction Set and Exception-Generating Instructions
Trường học ARM Limited
Chuyên ngành Computer Architecture
Thể loại Reference Manual
Năm xuất bản 2000
Định dạng
Số trang 30
Dung lượng 358,3 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

6.8 Undefined instruction spaceThe following instructions are UNDEFINED in the Thumb instruction set: In general, these instructions can be used to extend the Thumb instruction set in th

Trang 1

6.6.3 List of Load and Store Multiple instructions

The following instructions follow the formats shown above

LDMIA Load Multiple See LDMIA on page A7-40.

POP Pop Multiple See POP on page A7-75.

PUSH Push Multiple See PUSH on page A7-78.

STMIA Store Multiple See STMIA on page A7-84.

Trang 2

which User mode code can make calls to privileged Operating System code.

• The Breakpoint (BKPT) instruction is used for software breakpoints in T variants of ARM architecture versions 5 and above Its default behavior is to cause a Prefetch Abort exception to occur

(see Prefetch Abort (instruction fetch memory abort) on page A2-16) A debug monitor program that

has previously been installed on the Prefetch Abort vector can handle this exception

If debug hardware is present in the system, it is allowed to override this default behavior Details of whether and how this happens are IMPLEMENTATION DEFINED

or breakpoint to the handler

6.7.2 List of exception-generating instructions

BKPT Breakpoint See BKPT on page A7-24.

SWI Software Interrupt See SWI on page A7-102.

Trang 3

6.8 Undefined instruction space

The following instructions are UNDEFINED in the Thumb instruction set:

In general, these instructions can be used to extend the Thumb instruction set in the future However, it is intended that the following group of instructions will not be used in this manner:

Use one of these instructions if you want to use an undefined instruction for software purposes, with minimal risk that future hardware will treat it as a defined instruction

Trang 5

Thumb Instructions

This chapter describes the syntax and usage of every Thumb instruction, in the section:

Alphabetical list of Thumb instructions on page A7-2

Thumb instructions and architecture versions on page A7-104.

Trang 6

7.1 Alphabetical list of Thumb instructions

Every Thumb instruction is listed on the following pages Each instruction description shows:

• the instruction encoding

• the instruction syntax

• the versions of the ARM architecture where the instruction is valid

• any exceptions that might apply

• a pseudo-code specification of how the instruction operates

• notes on usage and special cases

• the equivalent ARM instruction encoding

7.1.1 General notes

These notes explain the types of information and abbreviations used on the instruction pages

Syntax abbreviations

The following abbreviations are used in the instruction pages:

immed_<n> This is an <n>-bit immediate value For example, an 8-bit immediate value is represented

by:

immed_8signed_immed_<n>

This is a signed immediate For example, an 8-bit signed immediate is represented by:signed_immed_8

Architecture version

For the convenience of the reader, this section describes the version of the ARM instruction set that the instruction is associated with, not the version of the Thumb instruction set There have been two versions

of the Thumb instruction set architecture to date:

THUMBv1 This is used in T variants of version 4 of the ARM instruction set architecture

THUMBv2 This is used in T variants of version 5 and above of the ARM instruction set architecture.Instructions which are described as being in all T variants are therefore present in both THUMBv1 and THUMBv2, while those that are described as being in T variants of version 5 and above are in THUMBv2 only

Trang 7

Equivalent ARM syntax and encoding

This section shows the syntax and encoding of an equivalent ARM instruction When no precise equivalent

is available, a close equivalent is shown and the reasons why it is not a precise equivalent are explained

A common reason for the instruction not being a precise equivalent is that it reads the value of the PC This produces the instruction’s own address plus N, where N is 8 for ARM instructions and 4 for Thumb instructions This difference can often be compensated for by adjusting an immediate constant in the equivalent ARM instruction

In the equivalent instruction encodings, named fields and bits must be filled in with the corresponding fields and bits from the Thumb instruction, or in a few cases with values derived from the Thumb instruction as described in the text

The ARM instruction fields are normally the same length as the corresponding Thumb instruction fields, with one important exception Thumb register fields are normally 3 bits long, whereas ARM register fields are normally 4 bits long In these cases, the Thumb register field must be extended with a high-order 0 when substituted into the ARM register field, so that the ARM instruction refers to the correct one of R0 to R7

Trang 8

<Rd> Holds the first value for the addition, and is the destination register for the operation.

<Rm> Specifies the register that contains the second operand for the addition

Z Flag = if Rd == 0 then 1 else 0

C Flag = CarryFrom(Rd + Rm + C Flag)

V Flag = OverflowFrom(Rd + Rm + C Flag)

Equivalent ARM syntax and encoding

Trang 9

<Rd> Is the destination register for the completed operation.

<Rn> Specifies the register that contains the operand for the addition

<immed_3> Specifies a 3-bit immediate value that is added to the value of <Rn>

Z Flag = if Rd == 0 then 1 else 0

C Flag = CarryFrom(Rn + immed_3)

V Flag = OverflowFrom(Rn + immed_3)

Equivalent ARM syntax and encoding

Trang 10

Z Flag = if Rd == 0 then 1 else 0

C Flag = CarryFrom(Rd + immed_8)

V Flag = OverflowFrom(Rd + immed_8)

Equivalent ARM syntax and encoding

Trang 11

<Rd> Is the destination register for the completed operation.

<Rn> Specifies the register containing the first value for the addition

<Rm> Specifies the register containing the second value for the addition

Trang 12

<Rd> Specifies the register containing the first value, and is also the destination register It can be

any of R0 to R15 The register number is encoded in the instruction in H1 (most significant bit) and Rd (remaining three bits)

<Rm> Specifies the register containing the second value It can be any of R0 to R15 Its number is

encoded in the instruction in H2 (most significant bit) and Rm (remaining three bits)

UNPREDICTABLE

Trang 13

Equivalent ARM syntax and encoding

A close equivalent is:

ADD <Rd>, <Rd>, <Rm>

There are slight differences when the instruction accesses the PC, because of the different definitions of the

PC when executing ARM and Thumb code

31 30 29 28 27 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 3 2 0

1 1 1 0 0 0 0 0 1 0 0 0 H1 Rd H1 Rd 0 0 0 0 0 0 0 0 H2 Rm

Trang 14

7.1.7 ADD (5)

This form of ADD adds an immediate value to the PC and writes the resulting PC-relative address to a destination register The immediate can be any multiple of 4 in the range 0 to 1020 The condition codes are not affected

Syntax

ADD <Rd>, PC, #<immed_8> * 4where:

<Rd> Is the destination register for the completed operation

PC Indicates PC-relative addressing

<immed_8> Specifies an 8-bit immediate value that is quadrupled and added to the value of the PC

Equivalent ARM syntax and encoding

A close equivalent is:

Trang 15

7.1.8 ADD (6)

This form of ADD adds an immediate value to the SP and writes the resulting SP-relative address to a destination register The immediate can be any multiple of 4 in the range 0 to 1020 The condition codes are not affected

Syntax

ADD <Rd>, SP, #<immed_8> * 4where:

<Rd> Is the destination register for the completed operation

SP Indicates SP-relative addressing

<immed_8> Specifies an 8-bit immediate value that is quadrupled and added to the value of the SP

Trang 16

7.1.9 ADD (7)

This form of ADD increments the SP by four times a 7-bit immediate (that is, by a multiple of 4 in the range

0 to 508) The condition codes are not affected

Syntax

ADD SP, #<immed_7> * 4where:

SP Contains the first operand for the addition SP is also the destination register for the

Equivalent ARM syntax and encoding

Trang 17

<Rd> Specifies the register containing the first operand, and is also the destination register.

<Rm> Specifies the register containing the second operand

Trang 18

<Rd> Is the destination register for the completed operation.

<Rm> Specifies the register that contains the value to be shifted

<immed_5> Specifies the shift amount, in the range 1 to 32 Shifts by 1 to 31 are encoded directly

in immed_5 A shift by 32 is encoded as immed_5 == 0

Rd = 0xFFFFFFFF else /* immed_5 > 0 */

Trang 19

Equivalent ARM syntax and encoding

MOVS <Rd>, <Rm>, ASR #<immed_5>

31 30 29 28 27 26 25 24 23 22 21 20 19 16 15 12 11 7 6 5 4 3 0

Trang 21

Equivalent ARM syntax and encoding

MOVS <Rd>, <Rd>, ASR <Rs>

31 30 29 28 27 26 25 24 23 22 21 20 19 16 15 12 11 8 7 6 5 4 3 0

Trang 22

<cond> Is the condition under which the instruction is executed The conditions are defined in The

condition field on page A3-5.

<target_address>

Specifies the address to branch to The branch target address is calculated by:

1 Shifting the 8-bit signed offset field of the instruction left by one bit

2 Sign-extending the result to 32 bits

3 Adding this to the contents of the PC (which contains the address of the branch instruction plus 4)

The instruction can therefore specify a branch of approximately ±256 bytes

Trang 23

To calculate the correct value of signed_immed_8, the assembler (or other toolkit component) needs to:

1 Form the base address for the branch This is the address of the branch instruction, plus 4 In other words, the base address is equal to the PC value read by that instruction

2 Subtract the base address from the target address to form a byte offset This offset is always even, because all Thumb instructions are halfword-aligned

3 If the byte offset is outside the range -256 to +254, use an alternative code-generation strategy or produce an error as appropriate

4 Otherwise, set the signed_immed_8 field of the instruction to the byte offset divided by 2

Notes Memory bounds Branching backwards past location zero and forwards over the end of the 32-bit

address space is UNPREDICTABLE

AL condition If the condition field indicates AL (0b1110), the instruction is instead UNDEFINED

When an unconditional branch is required, use the unconditional Branch instruction

described in B (2) on page A7-20.

NV condition If the condition field indicates NV (0b1111), the instruction is a SWI instead (see

SWI on page A7-102).

Equivalent ARM syntax and encoding

A close equivalent is:

B<cond> <target_address>

This differs from the Thumb instruction, because the offset in the ARM instruction is shifted left by 2 before being added to the PC, whereas the offset in the Thumb instruction is shifted left by 1 Also, the PC values read by the ARM and Thumb instructions are different

cond 1 0 1 0 sign extension of signed_immed_8 signed_immed_8

Trang 24

Specifies the address to branch to The branch target address is calculated by:

1 Shifting the 11-bit signed offset of the instruction left one bit

2 Sign-extending the result to 32 bits

3 Adding this to the contents of the PC (which contains the address of the branch instruction plus 4)

The instruction can therefore specify a branch of approximately ±2048 bytes

To calculate the correct value of signed_immed_11, the assembler (or other toolkit component) needs to:

1 Form the base address for the branch This is the address of the branch instruction, plus 4 In other words, the base address is equal to the PC value read by that instruction

2 Subtract the base address from the target address to form a byte offset This offset is always even,

Trang 25

Notes Memory bounds Branching backwards past location zero and forwards over the end of the 32-bit

address space is UNPREDICTABLE

Equivalent ARM syntax and encoding

A close equivalent is:

B <target_address>

This differs from the Thumb instruction, because the offset in the ARM instruction is shifted left by 2 before being added to the PC, whereas the offset in the Thumb instruction is shifted left by 1 Also, the PC values read by the ARM and Thumb instructions are different

1 1 1 0 1 0 1 0 sign extension of signed_immed_11 signed_immed_11

Trang 26

7.1.15 BIC

The BIC (Bit Clear) instruction performs a bitwise AND of the value of one register and the bitwise inverse

of the value of another register The condition code flags are updated, based on the result

Trang 27

Equivalent ARM syntax and encoding

BICS <Rd>, <Rd>, <Rm>

31 30 29 28 27 26 25 24 23 22 21 20 19 16 15 12 11 10 9 8 7 6 5 4 3 0

Trang 28

7.1.16 BKPT

The BKPT (Breakpoint) instruction causes a software breakpoint to occur This breakpoint can be handled

by an exception handler installed on the prefetch abort vector In implementations which also include debug hardware, the hardware can optionally override this behavior and handle the breakpoint itself When this occurs, the prefetch abort vector is not entered

Syntax

BKPT <immed_8>

where:

<immed_8> Is an 8-bit immediate value, which is placed in bits[7:0] of the instruction This value is

ignored by the ARM hardware, but can be used by a debugger to store additional information about the breakpoint

CPSR[4:0] = 0b10111 /* Enter Abort mode */

CPSR[5] = 0 /* Execute in ARM state */

/* CPSR[6] is unchanged */

CPSR[7] = 1 /* Disable normal interrupts */

if high vectors configured then

PC = 0xFFFF000C else

PC = 0x0000000C

Trang 29

as a result of a BKPT instruction or as a result of a real prefetch abort, and branches to debug code or prefetch abort code accordingly Otherwise, the prefetch abort handler just branches straight to debug code.

When used in this manner, the BKPT instruction must be avoided within abort handlers, as it corrupts R14_abt and SPSR_abt For the same reason, it must also be avoided within FIQ handlers, as an FIQ interrupt can occur within an abort handler

• Debug hardware overrides the normal behavior of the BKPT instruction and handles the software breakpoint itself When finished, it typically either resumes execution at the instruction following the BKPT, or replaces the BKPT in memory with another instruction and resumes execution at that instruction

When BKPT is used in this manner, R14_abt and SPSR_abt are not corrupted, and so the above restrictions about its use in abort and FIQ handlers do not apply

Notes Hardware override Debug hardware in an implementation is specifically permitted to override the

normal behavior of the BKPT instruction Because of this, software must not use this instruction for purposes other than those permitted by the debug system being used (if any) In particular, software cannot rely on the Prefetch Abort exception occurring, unless either there is guaranteed to be no debug hardware in the system

or the debug system specifies that it will occur

For more information, consult the documentation for the debug system being used

Equivalent ARM syntax and encoding

Trang 30

• a POP instruction that loads the PC

This form of the BLX (Branch with Link and Exchange instruction set) instruction provides an unconditional subroutine call to an ARM routine The return from subroutine is typically performed by a BX LRinstruction, or an LDR or LDM instruction that loads the PC

To allow for a reasonably large offset to the target subroutine, each of these two instructions is automatically translated by the assembler into a sequence of two 16-bit Thumb instructions:

• The first Thumb instruction has H == 10 and supplies the high part of the branch offset This instruction sets up for the subroutine call and is shared between the BL and BLX forms

• The second Thumb instruction has H == 11 (for BL) or H == 01 (for BLX) It supplies the low part

of the branch offset and causes the subroutine call to take place

Syntax

BL <target_addr>

BLX <target_addr>

where:

<target_addr> Specifies the address to branch to The branch target address is calculated by:

1 Shifting the offset_11 field of the first instruction left twelve bits

2 Sign-extending the result to 32 bits

3 Adding this to the contents of the PC (which contains the address of the first instruction plus 4)

4 Adding twice the offset_11 field of the second instruction For BLX, the resulting address is forced to be word-aligned by clearing bit[1]

The instruction can therefore specify a branch of approximately ±4MB

Architecture version

Ngày đăng: 22/01/2014, 00:20

TỪ KHÓA LIÊN QUAN