blob: 005aae512140154814053d435c5fd051fc81aee9 [file] [log] [blame]
Jason Molenda0dfb84c2018-09-07 01:28:48 +00001//===-- TestArmv7Disassembly.cpp ------------------------------------*- C++
2//-*-===//
3
4//
5// The LLVM Compiler Infrastructure
6//
7// This file is distributed under the University of Illinois Open Source
8// License. See LICENSE.TXT for details.
9//
10//===----------------------------------------------------------------------===//
11
12#include "gtest/gtest.h"
13
14#include "lldb/Core/Address.h"
15#include "lldb/Core/Disassembler.h"
16#include "lldb/Utility/ArchSpec.h"
17#include "lldb/Target/ExecutionContext.h"
18
19#include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h"
20#include "llvm/Support/TargetSelect.h"
21
22using namespace lldb;
23using namespace lldb_private;
24
25class TestArmv7Disassembly : public testing::Test {
26public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29
30 // virtual void SetUp() override { }
31 // virtual void TearDown() override { }
32
33protected:
34};
35
36void TestArmv7Disassembly::SetUpTestCase() {
37 llvm::InitializeAllTargets();
38 llvm::InitializeAllAsmPrinters();
39 llvm::InitializeAllTargetMCs();
40 llvm::InitializeAllDisassemblers();
41 DisassemblerLLVMC::Initialize();
42}
43
44void TestArmv7Disassembly::TearDownTestCase() {
45 DisassemblerLLVMC::Terminate();
46}
47
48TEST_F(TestArmv7Disassembly, TestCortexFPDisass) {
49 ArchSpec arch("armv7em--");
50
Raphael Isemannb658f1d2018-09-11 12:45:22 +000051 const unsigned num_of_instructions = 3;
Jason Molenda0dfb84c2018-09-07 01:28:48 +000052 uint8_t data[] = {
53 0x00, 0xee, 0x10, 0x2a, // 0xee002a10 : vmov s0, r2
54 0xb8, 0xee, 0xc0, 0x0b, // 0xeeb80bc0 : vcvt.f64.s32 d0, s0
55 0xb6, 0xee, 0x00, 0x0a, // 0xeeb60a00 : vmov.f32 s0, #5.000000e-01
56 };
57
58 // these can be disassembled by hand with llvm-mc, e.g.
59 //
60 // 0x00, 0xee, 0x10, 0x2a, // 0xee002a10 : vmov s0, r2
61 //
62 // echo 0x00 0xee 0x10 0x2a | llvm-mc -arch thumb -disassemble -mattr=+fp-armv8
63 // vmov s0, r2
64
65 DisassemblerSP disass_sp;
66 Address start_addr(0x100);
67 disass_sp = Disassembler::DisassembleBytes(arch, nullptr, nullptr, start_addr,
68 &data, sizeof (data), num_of_instructions, false);
69
70 ASSERT_NE (nullptr, disass_sp.get());
71 if (disass_sp) {
72 const InstructionList inst_list (disass_sp->GetInstructionList());
73 EXPECT_EQ (num_of_instructions, inst_list.GetSize());
74
75 InstructionSP inst_sp;
76 const char *mnemonic;
77 ExecutionContext exe_ctx (nullptr, nullptr, nullptr);
78 inst_sp = inst_list.GetInstructionAtIndex (0);
79 mnemonic = inst_sp->GetMnemonic(&exe_ctx);
80 ASSERT_STREQ ("vmov", mnemonic);
81
82 inst_sp = inst_list.GetInstructionAtIndex (1);
83 mnemonic = inst_sp->GetMnemonic(&exe_ctx);
84 ASSERT_STREQ ("vcvt.f64.s32", mnemonic);
85
86 inst_sp = inst_list.GetInstructionAtIndex (2);
87 mnemonic = inst_sp->GetMnemonic(&exe_ctx);
88 ASSERT_STREQ ("vmov.f32", mnemonic);
89 }
90}