OpenCores
URL https://opencores.org/ocsvn/lxp32/lxp32/trunk

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [tools/] [src/] [lxp32dump/] [disassembler.h] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 ring0_mipt
/*
2
 * Copyright (c) 2016 by Alex I. Kuznetsov.
3
 *
4
 * Part of the LXP32 CPU IP core.
5
 *
6
 * This module defines the Disassembler class which disassembles
7
 * LXP32 executable code.
8
 */
9
 
10
#ifndef DISASSEMBLER_H_INCLUDED
11
#define DISASSEMBLER_H_INCLUDED
12
 
13
#include <iostream>
14
#include <type_traits>
15
#include <cstdint>
16
 
17
class Disassembler {
18
public:
19
        enum Format {Bin,Textio,Dec,Hex};
20
        typedef std::uint32_t Word;
21
private:
22
        class Operand {
23
        public:
24
                enum Type {Register,Direct};
25
        private:
26
                Type _type;
27
                int _value;
28
        public:
29
                Operand(Type t,int value);
30
                Type type() const;
31
                int value() const;
32
        };
33
 
34
        std::istream &_is;
35
        std::ostream &_os;
36
        Format _fmt;
37
        bool _preferAliases;
38
        int _lineNumber;
39
        Word _pos;
40
public:
41
        Disassembler(std::istream &is,std::ostream &os);
42
        void setFormat(Format fmt);
43
        void setBase(Word base);
44
        void setPreferAliases(bool b);
45
        void dump();
46
 
47
        template <typename T> static std::string hex(const T &w) {
48
                static_assert(std::is_integral<T>::value,"Argument must be of integral type");
49
                const char *hexstr="0123456789ABCDEF";
50
                std::string res;
51
 
52
                res.reserve(sizeof(T)*2);
53
 
54
                for(int i=sizeof(T)*8-4;i>=0;i-=4) {
55
                        res.push_back(hexstr[(w>>i)&0x0F]);
56
                }
57
                return res;
58
        }
59
private:
60
        bool getWord(Word &w);
61
        std::string str(const Operand &op);
62
        static Operand decodeRd1Operand(Word w);
63
        static Operand decodeRd2Operand(Word w);
64
        static Operand decodeDstOperand(Word w);
65
 
66
        std::string decodeSimpleInstruction(const std::string &op,Word w);
67
        std::string decodeAdd(Word w);
68
        std::string decodeAnd(Word w);
69
        std::string decodeCall(Word w);
70
        std::string decodeCjmpxx(Word w);
71
        std::string decodeDivs(Word w);
72
        std::string decodeDivu(Word w);
73
        std::string decodeHlt(Word w);
74
        std::string decodeJmp(Word w);
75
        std::string decodeLc(Word w,bool &valid,Word &operand);
76
        std::string decodeLcs(Word w);
77
        std::string decodeLsb(Word w);
78
        std::string decodeLub(Word w);
79
        std::string decodeLw(Word w);
80
        std::string decodeMods(Word w);
81
        std::string decodeModu(Word w);
82
        std::string decodeMul(Word w);
83
        std::string decodeNop(Word w);
84
        std::string decodeOr(Word w);
85
        std::string decodeSb(Word w);
86
        std::string decodeSl(Word w);
87
        std::string decodeSrs(Word w);
88
        std::string decodeSru(Word w);
89
        std::string decodeSub(Word w);
90
        std::string decodeSw(Word w);
91
        std::string decodeXor(Word w);
92
        std::string decodeWord(Word w);
93
};
94
 
95
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.