2021-03-12 12:07:24 -07:00
|
|
|
/*
|
2023-11-03 17:21:46 -06:00
|
|
|
Copyright 2016-2023 melonDS team
|
2021-03-12 12:07:24 -07:00
|
|
|
|
|
|
|
This file is part of melonDS.
|
|
|
|
|
|
|
|
melonDS 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 3 of the License, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/.
|
|
|
|
*/
|
|
|
|
|
2019-06-21 17:28:32 -06:00
|
|
|
#ifndef ARMINSTRINFO_H
|
|
|
|
#define ARMINSTRINFO_H
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
2023-11-25 10:32:09 -07:00
|
|
|
namespace melonDS::ARMInstrInfo
|
2019-06-21 17:28:32 -06:00
|
|
|
{
|
|
|
|
|
|
|
|
// Instruction kinds, for faster dispatch
|
|
|
|
|
|
|
|
#define ak_ALU(n) \
|
|
|
|
ak_##n##_REG_LSL_IMM, \
|
|
|
|
ak_##n##_REG_LSR_IMM, \
|
|
|
|
ak_##n##_REG_ASR_IMM, \
|
|
|
|
ak_##n##_REG_ROR_IMM, \
|
|
|
|
\
|
|
|
|
ak_##n##_REG_LSL_REG, \
|
|
|
|
ak_##n##_REG_LSR_REG, \
|
|
|
|
ak_##n##_REG_ASR_REG, \
|
|
|
|
ak_##n##_REG_ROR_REG, \
|
|
|
|
\
|
|
|
|
ak_##n##_IMM, \
|
|
|
|
\
|
|
|
|
ak_##n##_REG_LSL_IMM_S, \
|
|
|
|
ak_##n##_REG_LSR_IMM_S, \
|
|
|
|
ak_##n##_REG_ASR_IMM_S, \
|
|
|
|
ak_##n##_REG_ROR_IMM_S, \
|
|
|
|
\
|
|
|
|
ak_##n##_REG_LSL_REG_S, \
|
|
|
|
ak_##n##_REG_LSR_REG_S, \
|
|
|
|
ak_##n##_REG_ASR_REG_S, \
|
|
|
|
ak_##n##_REG_ROR_REG_S, \
|
|
|
|
\
|
|
|
|
ak_##n##_IMM_S \
|
|
|
|
|
|
|
|
#define ak_Test(n) \
|
|
|
|
ak_##n##_REG_LSL_IMM, \
|
|
|
|
ak_##n##_REG_LSR_IMM, \
|
|
|
|
ak_##n##_REG_ASR_IMM, \
|
|
|
|
ak_##n##_REG_ROR_IMM, \
|
|
|
|
\
|
|
|
|
ak_##n##_REG_LSL_REG, \
|
|
|
|
ak_##n##_REG_LSR_REG, \
|
|
|
|
ak_##n##_REG_ASR_REG, \
|
|
|
|
ak_##n##_REG_ROR_REG, \
|
|
|
|
\
|
|
|
|
ak_##n##_IMM
|
|
|
|
|
|
|
|
#define ak_WB_LDRSTR(n) \
|
|
|
|
ak_##n##_REG_LSL, \
|
|
|
|
ak_##n##_REG_LSR, \
|
|
|
|
ak_##n##_REG_ASR, \
|
|
|
|
ak_##n##_REG_ROR, \
|
|
|
|
\
|
|
|
|
ak_##n##_IMM, \
|
|
|
|
\
|
|
|
|
ak_##n##_POST_REG_LSL, \
|
|
|
|
ak_##n##_POST_REG_LSR, \
|
|
|
|
ak_##n##_POST_REG_ASR, \
|
|
|
|
ak_##n##_POST_REG_ROR, \
|
|
|
|
\
|
|
|
|
ak_##n##_POST_IMM
|
|
|
|
|
|
|
|
#define ak_HD_LDRSTR(n) \
|
|
|
|
ak_##n##_REG, \
|
|
|
|
ak_##n##_IMM, \
|
|
|
|
\
|
|
|
|
ak_##n##_POST_REG, \
|
|
|
|
ak_##n##_POST_IMM
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ak_ALU(AND),
|
|
|
|
ak_ALU(EOR),
|
|
|
|
ak_ALU(SUB),
|
|
|
|
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|
tk_LDRB_REG,
|
|
|
|
tk_STRH_REG,
|
|
|
|
tk_LDRSB_REG,
|
|
|
|
tk_LDRH_REG,
|
|
|
|
tk_LDRSH_REG,
|
|
|
|
tk_STR_IMM,
|
|
|
|
tk_LDR_IMM,
|
|
|
|
tk_STRB_IMM,
|
|
|
|
tk_LDRB_IMM,
|
|
|
|
tk_STRH_IMM,
|
|
|
|
tk_LDRH_IMM,
|
|
|
|
tk_STR_SPREL,
|
|
|
|
tk_LDR_SPREL,
|
|
|
|
|
|
|
|
tk_PUSH,
|
|
|
|
tk_POP,
|
|
|
|
tk_LDMIA,
|
|
|
|
tk_STMIA,
|
2022-03-06 13:21:50 -07:00
|
|
|
|
2019-06-21 17:28:32 -06:00
|
|
|
tk_BCOND,
|
|
|
|
tk_BX,
|
|
|
|
tk_BLX_REG,
|
|
|
|
tk_B,
|
|
|
|
tk_BL_LONG_1,
|
|
|
|
tk_BL_LONG_2,
|
|
|
|
tk_UNK,
|
|
|
|
tk_SVC,
|
|
|
|
|
2019-09-08 06:48:20 -06:00
|
|
|
// not a real instruction
|
|
|
|
tk_BL_LONG,
|
|
|
|
|
2019-06-21 17:28:32 -06:00
|
|
|
tk_Count
|
|
|
|
};
|
|
|
|
|
2019-08-25 04:28:48 -06:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
flag_N = 1 << 3,
|
|
|
|
flag_Z = 1 << 2,
|
|
|
|
flag_C = 1 << 1,
|
|
|
|
flag_V = 1 << 0,
|
|
|
|
};
|
|
|
|
|
2019-10-02 17:10:59 -06:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
special_NotSpecialAtAll = 0,
|
|
|
|
special_WriteMem,
|
2020-06-14 13:04:25 -06:00
|
|
|
special_LoadMem,
|
2019-10-16 15:39:12 -06:00
|
|
|
special_WaitForInterrupt,
|
|
|
|
special_LoadLiteral
|
2019-10-02 17:10:59 -06:00
|
|
|
};
|
|
|
|
|
2019-06-21 17:28:32 -06:00
|
|
|
struct Info
|
|
|
|
{
|
2019-10-18 05:29:17 -06:00
|
|
|
u16 DstRegs, SrcRegs, NotStrictlyNeeded;
|
2019-06-21 17:28:32 -06:00
|
|
|
u16 Kind;
|
|
|
|
|
2019-10-02 17:10:59 -06:00
|
|
|
u8 SpecialKind;
|
|
|
|
|
2019-08-25 04:28:48 -06:00
|
|
|
u8 ReadFlags;
|
|
|
|
// lower 4 bits - set always
|
|
|
|
// upper 4 bits - might set flag
|
|
|
|
u8 WriteFlags;
|
|
|
|
|
2019-07-21 09:28:16 -06:00
|
|
|
bool EndBlock;
|
2019-10-02 17:10:59 -06:00
|
|
|
bool Branches() const
|
2019-06-21 17:28:32 -06:00
|
|
|
{
|
|
|
|
return DstRegs & (1 << 15);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-11-18 08:40:54 -07:00
|
|
|
Info Decode(bool thumb, u32 num, u32 instr, bool literaloptimizations);
|
2019-06-21 17:28:32 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-03-06 13:21:50 -07:00
|
|
|
#endif
|