summaryrefslogtreecommitdiffstats
path: root/src/core/debugger/gdbstub_arch.h
blob: 2540d64566011bb86d066b1a70dd635695c21d16 (plain) (blame)
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
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <string>

#include "common/common_types.h"

namespace Kernel {
class KThread;
}

namespace Core {

class GDBStubArch {
public:
    virtual ~GDBStubArch() = default;
    virtual std::string GetTargetXML() const = 0;
    virtual std::string RegRead(const Kernel::KThread* thread, size_t id) const = 0;
    virtual void RegWrite(Kernel::KThread* thread, size_t id, std::string_view value) const = 0;
    virtual std::string ReadRegisters(const Kernel::KThread* thread) const = 0;
    virtual void WriteRegisters(Kernel::KThread* thread, std::string_view register_data) const = 0;
    virtual std::string ThreadStatus(const Kernel::KThread* thread, u8 signal) const = 0;
    virtual u32 BreakpointInstruction() const = 0;
};

class GDBStubA64 final : public GDBStubArch {
public:
    std::string GetTargetXML() const override;
    std::string RegRead(const Kernel::KThread* thread, size_t id) const override;
    void RegWrite(Kernel::KThread* thread, size_t id, std::string_view value) const override;
    std::string ReadRegisters(const Kernel::KThread* thread) const override;
    void WriteRegisters(Kernel::KThread* thread, std::string_view register_data) const override;
    std::string ThreadStatus(const Kernel::KThread* thread, u8 signal) const override;
    u32 BreakpointInstruction() const override;

private:
    static constexpr u32 LR_REGISTER = 30;
    static constexpr u32 SP_REGISTER = 31;
    static constexpr u32 PC_REGISTER = 32;
    static constexpr u32 PSTATE_REGISTER = 33;
    static constexpr u32 Q0_REGISTER = 34;
    static constexpr u32 FPSR_REGISTER = 66;
    static constexpr u32 FPCR_REGISTER = 67;
};

class GDBStubA32 final : public GDBStubArch {
public:
    std::string GetTargetXML() const override;
    std::string RegRead(const Kernel::KThread* thread, size_t id) const override;
    void RegWrite(Kernel::KThread* thread, size_t id, std::string_view value) const override;
    std::string ReadRegisters(const Kernel::KThread* thread) const override;
    void WriteRegisters(Kernel::KThread* thread, std::string_view register_data) const override;
    std::string ThreadStatus(const Kernel::KThread* thread, u8 signal) const override;
    u32 BreakpointInstruction() const override;

private:
    static constexpr u32 SP_REGISTER = 13;
    static constexpr u32 LR_REGISTER = 14;
    static constexpr u32 PC_REGISTER = 15;
    static constexpr u32 CPSR_REGISTER = 25;
    static constexpr u32 D0_REGISTER = 32;
    static constexpr u32 Q0_REGISTER = 64;
    static constexpr u32 FPSCR_REGISTER = 80;
};

} // namespace Core