aboutsummaryrefslogtreecommitdiff
path: root/disas/nanomips.h
blob: c56fc32b1e9a365e4e48491e48ed19a61010fd86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 *  Header file for nanoMIPS disassembler component of QEMU
 *
 *  Copyright (C) 2018  Wave Computing, Inc.
 *  Copyright (C) 2018  Matthew Fortune <matthew.fortune@mips.com>
 *  Copyright (C) 2018  Aleksandar Markovic <amarkovic@wavecomp.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

#ifndef DISAS_NANOMIPS_H
#define DISAS_NANOMIPS_H

#include <string>

typedef int64_t int64;
typedef uint64_t uint64;
typedef uint32_t uint32;
typedef uint16_t uint16;
typedef uint64_t img_address;

enum TABLE_ENTRY_TYPE {
    instruction,
    call_instruction,
    branch_instruction,
    return_instruction,
    reserved_block,
    pool,
};

enum TABLE_ATTRIBUTE_TYPE {
    MIPS64_    = 0x00000001,
    XNP_       = 0x00000002,
    XMMS_      = 0x00000004,
    EVA_       = 0x00000008,
    DSP_       = 0x00000010,
    MT_        = 0x00000020,
    EJTAG_     = 0x00000040,
    TLBINV_    = 0x00000080,
    CP0_       = 0x00000100,
    CP1_       = 0x00000200,
    CP2_       = 0x00000400,
    UDI_       = 0x00000800,
    MCU_       = 0x00001000,
    VZ_        = 0x00002000,
    TLB_       = 0x00004000,
    MVH_       = 0x00008000,
    ALL_ATTRIBUTES = 0xffffffffull,
};

typedef struct Dis_info {
  img_address m_pc;
} Dis_info;

typedef bool (*conditional_function)(uint64 instruction);
typedef std::string (*disassembly_function)(uint64 instruction,
                                            Dis_info *info);

typedef struct Pool {
    TABLE_ENTRY_TYPE     type;
    const struct Pool    *next_table;
    int                  next_table_size;
    int                  instructions_size;
    uint64               mask;
    uint64               value;
    disassembly_function disassembly;
    conditional_function condition;
    uint64               attributes;
} Pool;

class NMD
{
public:

    int Disassemble(const uint16 *data, std::string & dis,
                    TABLE_ENTRY_TYPE & type, Dis_info *info);

private:

    uint64 extract_op_code_value(const uint16 *data, int size);
    int Disassemble(const uint16 *data, std::string & dis,
                    TABLE_ENTRY_TYPE & type, const Pool *table, int table_size,
                    Dis_info *info);
};

#endif