|
|
1.1 root 1: //
2: // nono
1.1.1.2 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
1.1.1.9 root 7: //
8: // デバッガ (内部用)
9: //
10:
1.1 root 11: #pragma once
12:
1.1.1.11 root 13: #include "debugger_defs.h"
1.1.1.12 root 14: #include "bus.h"
1.1.1.2 root 15:
1.1.1.12 root 16: class IODevice;
1.1 root 17:
1.1.1.11 root 18: enum class CPUState
1.1.1.5 root 19: {
1.1.1.11 root 20: Normal = 0,
21: Stop, // STOP 命令など割り込み待ち状態
22: Halt, // ホールト、リセットなど非動作状態
1.1 root 23: };
24:
1.1.1.9 root 25: // デバッガの CPU 依存部分
26: class DebuggerMD
1.1 root 27: {
1.1.1.5 root 28: public:
1.1.1.11 root 29: DebuggerMD(Debugger *parent_, CPUArch arch_);
1.1.1.9 root 30: virtual ~DebuggerMD();
31:
1.1.1.11 root 32: // CPU の実行状態を返す。
33: virtual CPUState GetCPUState() const = 0;
1.1.1.9 root 34: // 特権モードなら true を返す
35: virtual bool IsSuper() const = 0;
36: // MMU が有効なら true を返す
37: virtual bool MMUEnabled() const = 0;
38:
39: // アドレス変換をする。
40: // MMUEnabled() が true であることは呼び出し側が確認すること。
1.1.1.13 root 41: // 変換出来なければ BusAddr::BusErr を返す。
42: // テーブルサーチを行ったら BusAddr::TableSearched を立てる。
1.1.1.12 root 43: virtual busaddr TranslateAddr(busaddr laddr) const = 0;
1.1.1.9 root 44:
45: // 現在の命令先頭アドレスを返す
46: virtual uint32 GetPC() const = 0;
47:
1.1.1.15! root 48: // 現在の命令の直後の命令アドレスを返す。
! 49: virtual uint32 GetNextPC();
! 50:
! 51: // 最後に発生したベクタを取得し、リセットする
! 52: virtual int32 GetAndResetLastVector() = 0;
! 53:
1.1.1.9 root 54: // ステップアウトを設定する
55: virtual void SetStepOut() = 0;
56: // ステップアウトなら true を返す
57: virtual bool IsStepOut() const = 0;
58:
59: // この命令がステップイン出来るなら true を返す (cmd_n 用)
60: virtual bool IsOpStepIn(DebuggerMemoryStream& mem) = 0;
61:
62: // name で示されるのレジスタの値を返す。
63: // メモリダンプで指定するケースを想定しているので、明らかにアドレスでは
64: // ないレジスタは含まなくてよい (m680x0 の SR など)。ただし Dn は含めて
65: // よい。また m680x0 の SRP/CRP は下位32ビットでよい。
66: // name が正しくない場合は (uint64)-1 を返す。
67: virtual uint64 GetRegAddr(const char *name) const = 0;
68:
69: // 現在のレジスタセットを内部にバックアップする
70: virtual void BackupRegs() = 0;
71:
72: // レジスタ表示系のコマンドを実行。処理すれば true を返す。
73: virtual bool ShowRegister(FILE *, const std::vector<std::string>& args) = 0;
74: // レジスタ表示系コマンドのヘルプ一覧を取得
75: virtual const HelpMessages& GetHelpListReg() const = 0;
76: // レジスタ表示系コマンドのヘルプメッセージを取得
77: virtual const HelpMessages& GetHelpReg() const = 0;
78:
79: // 直近の命令でアクセスした laddr が一致したら true を返す
80: // 1 命令で複数にアクセスする場合を考慮して、md 側で判断する
81: virtual bool CheckLEA(uint32 laddr) = 0;
82:
83: // mem.laddr の位置の命令を一つ逆アセンブルする。
1.1.1.11 root 84: virtual std::string Disassemble(DebuggerMemoryStream& mem) = 0;
85:
1.1.1.14 root 86: // ニーモニックに対応する機械語文字列を返す。(cmd_bi 用)
87: virtual std::string ParseInst(const std::string&) const = 0;
88:
1.1.1.15! root 89: // 例外フレームを表示する。
! 90: virtual void PrintExceptionFrame(FILE *, busaddr);
! 91:
1.1.1.11 root 92: // 機種名を取得する
93: const std::string& GetName() const { return name; }
94:
95: // この CPU のバスを返す
1.1.1.12 root 96: IODevice *GetBus() const { return bus; }
1.1.1.11 root 97: // このバスの論理アドレス幅 (ビット数) を返す
98: int GetLASize() const { return lasize; }
99: // このバスの物理アドレス幅 (ビット数) を返す
100: int GetPASize() const { return pasize; }
1.1.1.9 root 101:
102: // 機種
1.1.1.11 root 103: CPUArch arch {};
1.1.1.9 root 104:
105: // 最短の1命令のバイト数
106: uint inst_bytes {};
1.1.1.11 root 107:
1.1.1.9 root 108: protected:
109: Debugger *parent {}; // 親クラス
110:
1.1.1.11 root 111: std::string name {}; // 機種名
1.1 root 112:
1.1.1.12 root 113: IODevice *bus {}; // 対応する外部バス
114: int lasize {}; // バスの論理アドレス幅
115: int pasize {}; // バスの物理アドレス幅
1.1 root 116: };
117:
118: #define NORM "\x1b[0m"
119: #define BOLD "\x1b[1m"
120: #define BOLDIF(n) ((n) ? BOLD : "")
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.