TianoCore EDK2 master
Loading...
Searching...
No Matches
ThumbDisassembler.c File Reference
#include <Base.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/PrintLib.h>

Go to the source code of this file.

Data Structures

struct  THUMB_INSTRUCTIONS
 

Macros

#define LOAD_STORE_FORMAT1   1
 
#define LOAD_STORE_FORMAT1_H   101
 
#define LOAD_STORE_FORMAT1_B   111
 
#define LOAD_STORE_FORMAT2   2
 
#define LOAD_STORE_FORMAT3   3
 
#define LOAD_STORE_FORMAT4   4
 
#define LOAD_STORE_MULTIPLE_FORMAT1   5
 
#define PUSH_FORMAT   6
 
#define POP_FORMAT   106
 
#define IMMED_8   7
 
#define CONDITIONAL_BRANCH   8
 
#define UNCONDITIONAL_BRANCH   9
 
#define UNCONDITIONAL_BRANCH_SHORT   109
 
#define BRANCH_EXCHANGE   10
 
#define DATA_FORMAT1   11
 
#define DATA_FORMAT2   12
 
#define DATA_FORMAT3   13
 
#define DATA_FORMAT4   14
 
#define DATA_FORMAT5   15
 
#define DATA_FORMAT6_SP   16
 
#define DATA_FORMAT6_PC   116
 
#define DATA_FORMAT7   17
 
#define DATA_FORMAT8   19
 
#define CPS_FORMAT   20
 
#define ENDIAN_FORMAT   21
 
#define DATA_CBZ   22
 
#define ADR_FORMAT   23
 
#define IT_BLOCK   24
 
#define B_T3   200
 
#define B_T4   201
 
#define BL_T2   202
 
#define POP_T2   203
 
#define POP_T3   204
 
#define STM_FORMAT   205
 
#define LDM_REG_IMM12_SIGNED   206
 
#define LDM_REG_IMM12_LSL   207
 
#define LDM_REG_IMM8   208
 
#define LDM_REG_IMM12   209
 
#define LDM_REG_INDIRECT_LSL   210
 
#define LDM_REG_IMM8_SIGNED   211
 
#define LDRD_REG_IMM8   212
 
#define LDREXB   213
 
#define LDREXD   214
 
#define SRS_FORMAT   215
 
#define RFE_FORMAT   216
 
#define LDRD_REG_IMM8_SIGNED   217
 
#define ADD_IMM12   218
 
#define ADD_IMM5   219
 
#define ADR_THUMB2   220
 
#define CMN_THUMB2   221
 
#define ASR_IMM5   222
 
#define ASR_3REG   223
 
#define BFC_THUMB2   224
 
#define CDP_THUMB2   225
 
#define THUMB2_NO_ARGS   226
 
#define THUMB2_2REGS   227
 
#define ADD_IMM5_2REG   228
 
#define CPD_THUMB2   229
 
#define THUMB2_4REGS   230
 
#define ADD_IMM12_1REG   231
 
#define THUMB2_IMM16   232
 
#define MRC_THUMB2   233
 
#define MRRC_THUMB2   234
 
#define THUMB2_MRS   235
 
#define THUMB2_MSR   236
 

Functions

CHAR8 * ThumbMRegList (UINT32 RegBitMask)
 
UINT32 SignExtend32 (IN UINT32 Data, IN UINT32 TopBit)
 
UINT32 PcAlign4 (IN UINT32 Data)
 
VOID DisassembleThumbInstruction (IN UINT16 **OpCodePtrPtr, OUT CHAR8 *Buf, OUT UINTN Size, OUT UINT32 *ItBlock, IN BOOLEAN Extended)
 
VOID DisassembleArmInstruction (IN UINT32 **OpCodePtr, OUT CHAR8 *Buf, OUT UINTN Size, IN BOOLEAN Extended)
 
VOID DisassembleInstruction (IN UINT8 **OpCodePtr, IN BOOLEAN Thumb, IN BOOLEAN Extended, IN OUT UINT32 *ItBlock, OUT CHAR8 *Buf, OUT UINTN Size)
 

Variables

CHAR8 * gCondition []
 
CHAR8 * gReg []
 
THUMB_INSTRUCTIONS gOpThumb []
 
THUMB_INSTRUCTIONS gOpThumb2 []
 
CHAR8 * gShiftType []
 
CHAR8 mThumbMregListStr [4 *15+1]
 

Detailed Description

Thumb Disassembler. Still a work in progress.

Wrong output is a bug, so please fix it. Hex output means there is not yet an entry or a decode bug. gOpThumb[] are Thumb 16-bit, and gOpThumb2[] work on the 32-bit 16-bit stream of Thumb2 instruction. Then there are big case statements to print everything out. If you are adding instructions try to reuse existing case entries if possible.

Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
Copyright (c) 2021, Arm Limited. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file ThumbDisassembler.c.

Macro Definition Documentation

◆ ADD_IMM12

#define ADD_IMM12   218

Definition at line 76 of file ThumbDisassembler.c.

◆ ADD_IMM12_1REG

#define ADD_IMM12_1REG   231

Definition at line 89 of file ThumbDisassembler.c.

◆ ADD_IMM5

#define ADD_IMM5   219

Definition at line 77 of file ThumbDisassembler.c.

◆ ADD_IMM5_2REG

#define ADD_IMM5_2REG   228

Definition at line 86 of file ThumbDisassembler.c.

◆ ADR_FORMAT

#define ADR_FORMAT   23

Definition at line 54 of file ThumbDisassembler.c.

◆ ADR_THUMB2

#define ADR_THUMB2   220

Definition at line 78 of file ThumbDisassembler.c.

◆ ASR_3REG

#define ASR_3REG   223

Definition at line 81 of file ThumbDisassembler.c.

◆ ASR_IMM5

#define ASR_IMM5   222

Definition at line 80 of file ThumbDisassembler.c.

◆ B_T3

#define B_T3   200

Definition at line 58 of file ThumbDisassembler.c.

◆ B_T4

#define B_T4   201

Definition at line 59 of file ThumbDisassembler.c.

◆ BFC_THUMB2

#define BFC_THUMB2   224

Definition at line 82 of file ThumbDisassembler.c.

◆ BL_T2

#define BL_T2   202

Definition at line 60 of file ThumbDisassembler.c.

◆ BRANCH_EXCHANGE

#define BRANCH_EXCHANGE   10

Definition at line 41 of file ThumbDisassembler.c.

◆ CDP_THUMB2

#define CDP_THUMB2   225

Definition at line 83 of file ThumbDisassembler.c.

◆ CMN_THUMB2

#define CMN_THUMB2   221

Definition at line 79 of file ThumbDisassembler.c.

◆ CONDITIONAL_BRANCH

#define CONDITIONAL_BRANCH   8

Definition at line 38 of file ThumbDisassembler.c.

◆ CPD_THUMB2

#define CPD_THUMB2   229

Definition at line 87 of file ThumbDisassembler.c.

◆ CPS_FORMAT

#define CPS_FORMAT   20

Definition at line 51 of file ThumbDisassembler.c.

◆ DATA_CBZ

#define DATA_CBZ   22

Definition at line 53 of file ThumbDisassembler.c.

◆ DATA_FORMAT1

#define DATA_FORMAT1   11

Definition at line 42 of file ThumbDisassembler.c.

◆ DATA_FORMAT2

#define DATA_FORMAT2   12

Definition at line 43 of file ThumbDisassembler.c.

◆ DATA_FORMAT3

#define DATA_FORMAT3   13

Definition at line 44 of file ThumbDisassembler.c.

◆ DATA_FORMAT4

#define DATA_FORMAT4   14

Definition at line 45 of file ThumbDisassembler.c.

◆ DATA_FORMAT5

#define DATA_FORMAT5   15

Definition at line 46 of file ThumbDisassembler.c.

◆ DATA_FORMAT6_PC

#define DATA_FORMAT6_PC   116

Definition at line 48 of file ThumbDisassembler.c.

◆ DATA_FORMAT6_SP

#define DATA_FORMAT6_SP   16

Definition at line 47 of file ThumbDisassembler.c.

◆ DATA_FORMAT7

#define DATA_FORMAT7   17

Definition at line 49 of file ThumbDisassembler.c.

◆ DATA_FORMAT8

#define DATA_FORMAT8   19

Definition at line 50 of file ThumbDisassembler.c.

◆ ENDIAN_FORMAT

#define ENDIAN_FORMAT   21

Definition at line 52 of file ThumbDisassembler.c.

◆ IMMED_8

#define IMMED_8   7

Definition at line 37 of file ThumbDisassembler.c.

◆ IT_BLOCK

#define IT_BLOCK   24

Definition at line 55 of file ThumbDisassembler.c.

◆ LDM_REG_IMM12

#define LDM_REG_IMM12   209

Definition at line 67 of file ThumbDisassembler.c.

◆ LDM_REG_IMM12_LSL

#define LDM_REG_IMM12_LSL   207

Definition at line 65 of file ThumbDisassembler.c.

◆ LDM_REG_IMM12_SIGNED

#define LDM_REG_IMM12_SIGNED   206

Definition at line 64 of file ThumbDisassembler.c.

◆ LDM_REG_IMM8

#define LDM_REG_IMM8   208

Definition at line 66 of file ThumbDisassembler.c.

◆ LDM_REG_IMM8_SIGNED

#define LDM_REG_IMM8_SIGNED   211

Definition at line 69 of file ThumbDisassembler.c.

◆ LDM_REG_INDIRECT_LSL

#define LDM_REG_INDIRECT_LSL   210

Definition at line 68 of file ThumbDisassembler.c.

◆ LDRD_REG_IMM8

#define LDRD_REG_IMM8   212

Definition at line 70 of file ThumbDisassembler.c.

◆ LDRD_REG_IMM8_SIGNED

#define LDRD_REG_IMM8_SIGNED   217

Definition at line 75 of file ThumbDisassembler.c.

◆ LDREXB

#define LDREXB   213

Definition at line 71 of file ThumbDisassembler.c.

◆ LDREXD

#define LDREXD   214

Definition at line 72 of file ThumbDisassembler.c.

◆ LOAD_STORE_FORMAT1

#define LOAD_STORE_FORMAT1   1

Definition at line 28 of file ThumbDisassembler.c.

◆ LOAD_STORE_FORMAT1_B

#define LOAD_STORE_FORMAT1_B   111

Definition at line 30 of file ThumbDisassembler.c.

◆ LOAD_STORE_FORMAT1_H

#define LOAD_STORE_FORMAT1_H   101

Definition at line 29 of file ThumbDisassembler.c.

◆ LOAD_STORE_FORMAT2

#define LOAD_STORE_FORMAT2   2

Definition at line 31 of file ThumbDisassembler.c.

◆ LOAD_STORE_FORMAT3

#define LOAD_STORE_FORMAT3   3

Definition at line 32 of file ThumbDisassembler.c.

◆ LOAD_STORE_FORMAT4

#define LOAD_STORE_FORMAT4   4

Definition at line 33 of file ThumbDisassembler.c.

◆ LOAD_STORE_MULTIPLE_FORMAT1

#define LOAD_STORE_MULTIPLE_FORMAT1   5

Definition at line 34 of file ThumbDisassembler.c.

◆ MRC_THUMB2

#define MRC_THUMB2   233

Definition at line 91 of file ThumbDisassembler.c.

◆ MRRC_THUMB2

#define MRRC_THUMB2   234

Definition at line 92 of file ThumbDisassembler.c.

◆ POP_FORMAT

#define POP_FORMAT   106

Definition at line 36 of file ThumbDisassembler.c.

◆ POP_T2

#define POP_T2   203

Definition at line 61 of file ThumbDisassembler.c.

◆ POP_T3

#define POP_T3   204

Definition at line 62 of file ThumbDisassembler.c.

◆ PUSH_FORMAT

#define PUSH_FORMAT   6

Definition at line 35 of file ThumbDisassembler.c.

◆ RFE_FORMAT

#define RFE_FORMAT   216

Definition at line 74 of file ThumbDisassembler.c.

◆ SRS_FORMAT

#define SRS_FORMAT   215

Definition at line 73 of file ThumbDisassembler.c.

◆ STM_FORMAT

#define STM_FORMAT   205

Definition at line 63 of file ThumbDisassembler.c.

◆ THUMB2_2REGS

#define THUMB2_2REGS   227

Definition at line 85 of file ThumbDisassembler.c.

◆ THUMB2_4REGS

#define THUMB2_4REGS   230

Definition at line 88 of file ThumbDisassembler.c.

◆ THUMB2_IMM16

#define THUMB2_IMM16   232

Definition at line 90 of file ThumbDisassembler.c.

◆ THUMB2_MRS

#define THUMB2_MRS   235

Definition at line 93 of file ThumbDisassembler.c.

◆ THUMB2_MSR

#define THUMB2_MSR   236

Definition at line 94 of file ThumbDisassembler.c.

◆ THUMB2_NO_ARGS

#define THUMB2_NO_ARGS   226

Definition at line 84 of file ThumbDisassembler.c.

◆ UNCONDITIONAL_BRANCH

#define UNCONDITIONAL_BRANCH   9

Definition at line 39 of file ThumbDisassembler.c.

◆ UNCONDITIONAL_BRANCH_SHORT

#define UNCONDITIONAL_BRANCH_SHORT   109

Definition at line 40 of file ThumbDisassembler.c.

Function Documentation

◆ DisassembleArmInstruction()

VOID DisassembleArmInstruction ( IN UINT32 **  OpCodePtr,
OUT CHAR8 *  Buf,
OUT UINTN  Size,
IN BOOLEAN  Extended 
)

Place a disassembly of **OpCodePtr into buffer, and update OpCodePtr to point to next instruction.

We cheat and only decode instructions that access memory. If the instruction is not found we dump the instruction in hex.

Parameters
OpCodePtrPointer to pointer of ARM instruction to disassemble.
BufBuffer to sprintf disassembly into.
SizeSize of Buf in bytes.
ExtendedTRUE dump hex for instruction too.

Definition at line 154 of file ArmDisassembler.c.

◆ DisassembleInstruction()

VOID DisassembleInstruction ( IN UINT8 **  OpCodePtr,
IN BOOLEAN  Thumb,
IN BOOLEAN  Extended,
IN OUT UINT32 *  ItBlock,
OUT CHAR8 *  Buf,
OUT UINTN  Size 
)

Place a disassembly of **OpCodePtr into buffer, and update OpCodePtr to point to next instruction.

We cheat and only decode instructions that access memory. If the instruction is not found we dump the instruction in hex.

Parameters
OpCodePtrPtrPointer to pointer of ARM Thumb instruction to disassemble.
ThumbTRUE for Thumb(2), FALSE for ARM instruction stream
ExtendedTRUE dump hex for instruction too.
ItBlockSize of IT Block
BufBuffer to sprintf disassembly into.
SizeSize of Buf in bytes.

Definition at line 1059 of file ThumbDisassembler.c.

◆ DisassembleThumbInstruction()

VOID DisassembleThumbInstruction ( IN UINT16 **  OpCodePtrPtr,
OUT CHAR8 *  Buf,
OUT UINTN  Size,
OUT UINT32 *  ItBlock,
IN BOOLEAN  Extended 
)

Place a disassembly of **OpCodePtr into buffer, and update OpCodePtr to point to next instruction.

We cheat and only decode instructions that access memory. If the instruction is not found we dump the instruction in hex.

Parameters
OpCodePtrPtrPointer to pointer of ARM Thumb instruction to disassemble.
BufBuffer to sprintf disassembly into.
SizeSize of Buf in bytes.
ExtendedTRUE dump hex for instruction too.

Definition at line 472 of file ThumbDisassembler.c.

◆ PcAlign4()

UINT32 PcAlign4 ( IN UINT32  Data)

Definition at line 451 of file ThumbDisassembler.c.

◆ SignExtend32()

UINT32 SignExtend32 ( IN UINT32  Data,
IN UINT32  TopBit 
)

Definition at line 428 of file ThumbDisassembler.c.

◆ ThumbMRegList()

CHAR8 * ThumbMRegList ( UINT32  RegBitMask)

Definition at line 384 of file ThumbDisassembler.c.

Variable Documentation

◆ gCondition

CHAR8* gCondition[]
extern

Definition at line 16 of file ArmDisassembler.c.

◆ gOpThumb

THUMB_INSTRUCTIONS gOpThumb[]

Definition at line 103 of file ThumbDisassembler.c.

◆ gOpThumb2

THUMB_INSTRUCTIONS gOpThumb2[]

Definition at line 204 of file ThumbDisassembler.c.

◆ gReg

CHAR8* gReg[]
extern

Definition at line 37 of file ArmDisassembler.c.

◆ gShiftType

CHAR8* gShiftType[]
Initial value:
= {
"LSL",
"LSR",
"ASR",
"ROR"
}

Definition at line 374 of file ThumbDisassembler.c.

◆ mThumbMregListStr

CHAR8 mThumbMregListStr[4 *15+1]

Definition at line 381 of file ThumbDisassembler.c.