Skip to content

Commit

Permalink
Fixed ram mirroring in IDA 9.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
lab313ru committed Oct 22, 2024
1 parent 9bf74bf commit a0c1c6d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
8 changes: 4 additions & 4 deletions Gensida/gensida.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_32\;$(IDA_SDK)\lib\x64_win_qt\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_64\;$(IDA_SDK)\lib\x64_win_qt\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ida.lib;ws2_32.lib;Crypt32.lib;Iphlpapi.lib;WinMM.lib;Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent />
Expand All @@ -143,7 +143,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_32\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_64\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ida.lib;ws2_32.lib;Crypt32.lib;Iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent />
Expand All @@ -166,7 +166,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_32\;$(IDA_SDK)\lib\x64_win_qt\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_64\;$(IDA_SDK)\lib\x64_win_qt\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ida.lib;ws2_32.lib;Crypt32.lib;Iphlpapi.lib;WinMM.lib;Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent />
Expand All @@ -189,7 +189,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_32\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_64\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ida.lib;ws2_32.lib;Crypt32.lib;Iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent />
Expand Down
41 changes: 23 additions & 18 deletions Gensida/ida/ida_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ static void print_insn(insn_t* insn)
}
}

static __inline ea_t dw_ea(ea_t addr) {
return (addr & 0xFFFFFFFF);
}

static void print_op(ea_t ea, op_t* op)
{
if (my_dbg)
Expand Down Expand Up @@ -169,7 +173,7 @@ static void print_op(ea_t ea, op_t* op)
else
msg("reg_phrase=%x, ", op->phrase);

msg("addr=%x, ", op->addr);
msg("addr=%x, ", dw_ea(op->addr));

msg("value=%x, ", op->value);

Expand Down Expand Up @@ -994,7 +998,7 @@ static ssize_t idaapi hook_disasm(void* user_data, int notification_code, va_lis

if (insn->itype == M68K_linea || insn->itype == M68K_linef)
{
insn->add_cref(insn->Op1.addr, 0, fl_CN);
insn->add_cref(dw_ea(insn->Op1.addr), 0, fl_CN);
insn->add_cref(insn->ea + insn->size, insn->Op1.offb, fl_F);
return 1;
}
Expand Down Expand Up @@ -1050,17 +1054,18 @@ struct m68k_events_visitor_t : public post_event_visitor_t
case o_near:
case o_mem:
{
if (op.addr >= 0xFFFF0000 && op.addr <= 0xFFFFFFFF) {
op.addr &= 0xFFFFFF;
ea_t op_addr = dw_ea(op.addr);
if (op_addr >= 0xFFFF0000 && op_addr <= 0xFFFFFFFF) {
op.addr = op_addr & 0xFFFFFF;
}

if ((op.addr & 0xFFE00000) == 0xE00000) { // RAM mirrors
op.addr |= 0x1F0000;
if ((op_addr & 0xFFE00000) == 0xE00000) { // RAM mirrors
op.addr = op_addr | 0x1F0000;
}

if ((op.addr >= 0xC00000 && op.addr <= 0xC0001F) ||
(op.addr >= 0xC00020 && op.addr <= 0xC0003F)) { // VDP mirrors
op.addr &= 0xC000FF;
if ((op_addr >= 0xC00000 && op_addr <= 0xC0001F) ||
(op_addr >= 0xC00020 && op_addr <= 0xC0003F)) { // VDP mirrors
op.addr = op_addr & 0xC000FF;
}

if (out->itype == 0x75 && op.n == 0 && op.phrase == 9 && out->size == 6) { // jsr (label).l
Expand All @@ -1071,9 +1076,9 @@ struct m68k_events_visitor_t : public post_event_visitor_t
}
else if ((out->itype == 0x76 || out->itype == 0x75 || out->itype == 0x74) && op.n == 0 &&
(op.phrase == 0x09 || op.phrase == 0x0A) &&
(op.addr != 0 && op.addr <= 0xA00000) &&
(op_addr != 0 && op_addr <= 0xA00000) &&
(op.specflag1 == 2 || op.specflag1 == 3)) { // lea table(pc),Ax; jsr func(pc); jmp label(pc)
short diff = op.addr - out->ea;
short diff = op_addr - out->ea;
if (diff >= SHRT_MIN && diff <= SHRT_MAX)
{
out->Op1.type = o_displ;
Expand Down Expand Up @@ -1112,10 +1117,10 @@ struct m68k_events_visitor_t : public post_event_visitor_t
if ((insn->itype == 0x76 || insn->itype == 0x75 || insn->itype == 0x74) &&
insn->Op1.phrase == 0x5B && insn->Op1.specflag1 == 0x10) // lea table(pc),Ax; jsr func(pc); jmp label(pc)
{
short diff = insn->Op1.addr - insn->ea;
short diff = dw_ea(insn->Op1.addr) - insn->ea;
if (diff >= SHRT_MIN && diff <= SHRT_MAX)
{
insn->add_dref(insn->Op1.addr, insn->Op1.offb, dr_O);
insn->add_dref(dw_ea(insn->Op1.addr), insn->Op1.offb, dr_O);

if (insn->itype != 0x74) {
insn->add_cref(insn->ea + insn->size, 0, fl_F);
Expand Down Expand Up @@ -1191,7 +1196,7 @@ struct m68k_events_visitor_t : public post_event_visitor_t
switch (op.type)
{
case o_mem:
case o_near: opinf->ea = op.addr; break;
case o_near: opinf->ea = dw_ea(op.addr); break;
case o_imm: opinf->ea = op.value; break;
}

Expand Down Expand Up @@ -1266,7 +1271,7 @@ struct m68k_events_visitor_t : public post_event_visitor_t
if (main_reg_idx != R_PC)
main_reg = getreg(dbg->regs(main_reg_idx).name, regvalues);

ea_t addr = (ea_t)main_reg.ival + op.addr + (ea_t)add_reg.ival;
ea_t addr = (ea_t)main_reg.ival + dw_ea(op.addr) + (ea_t)add_reg.ival;
opinf->ea = addr;
size_t read_size = 0;

Expand Down Expand Up @@ -1309,7 +1314,7 @@ struct m68k_events_visitor_t : public post_event_visitor_t

if (
op->type == o_displ && assembler != out_asm_t::asm_asm68k &&
(((op->phrase == 0x0A) || (op->phrase == 0x0B) || (op->phrase == 0x08) || (op->phrase == 0x09)) && op->addr == 0)
(((op->phrase == 0x0A) || (op->phrase == 0x0B) || (op->phrase == 0x08) || (op->phrase == 0x09)) && dw_ea(op->addr) == 0)
) {
qstring tmp;

Expand Down Expand Up @@ -1900,9 +1905,9 @@ struct smd_constant_action_t : public action_handler_t
do_cmt_sr_ccr_reg_const(ea, value);
}
else if (out.Op1.type == o_imm && out.Op2.type == o_mem &&
(out.Op2.addr == 0xA11200 || out.Op2.addr == 0xA11100))
(dw_ea(out.Op2.addr) == 0xA11200 || dw_ea(out.Op2.addr) == 0xA11100))
{
do_cmt_z80_bus_command(ea, out.Op2.addr, value);
do_cmt_z80_bus_command(ea, dw_ea(out.Op2.addr), value);
}
else if (is_call16_const_cmd(value))
{
Expand Down
2 changes: 1 addition & 1 deletion Gensida/ida/paintform_moc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*****************************************************************************/

#include <memory>
#include "C:\git\smd_ida_tools2\Gensida\ida\paintform.h"
#include "C:\dev\smd_ida_tools2\Gensida\ida\paintform.h"
#include <QtCore/qbytearray.h>
#include <QtCore/qmetatype.h>
#if !defined(Q_MOC_OUTPUT_REVISION)
Expand Down
4 changes: 2 additions & 2 deletions sega_roms_loader/sega_roms_ldr.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<Link>
<GenerateDebugInformation>false</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_32\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_64\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ida.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
Expand All @@ -85,7 +85,7 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_32\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_64\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ida.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
Expand Down
4 changes: 2 additions & 2 deletions z80_loader/z80_loader.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_32\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_64\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ida.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
<ImportLibrary>$(Configuration)\$(TargetName).lib</ImportLibrary>
Expand All @@ -86,7 +86,7 @@
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_32\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>$(IDA_SDK)\lib\x64_win_vc_64\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ida.lib</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
<ImportLibrary>$(Configuration)\$(TargetName).lib</ImportLibrary>
Expand Down

0 comments on commit a0c1c6d

Please sign in to comment.