Skip to content

Commit

Permalink
[TMS7000] Add TMS7000 disassembler support
Browse files Browse the repository at this point in the history
  • Loading branch information
tgtakaoka committed Sep 7, 2023
1 parent cffaa46 commit 966f974
Show file tree
Hide file tree
Showing 38 changed files with 2,279 additions and 37 deletions.
6 changes: 3 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ usage: dis -C <CPU> [-o <output>] [-l <list>] <input>
MC68HC05 MC6809 HD6309 MOS6502 R65C02 G65SC02 W65C02S
W65C816S i8039 i8048 i80C39 i80C48 MSM80C39 MSM80C48 i8051
i8080 i8085 V30EMU Z80 Z8 Z86C Z88 TLCS90 INS8060 INS8070
CDP1802 CDP1804 CDP1804A SCN2650 F3850 TMS32010 TMS32015
i8086 i80186 V30 i8096 MC68000 TMS9900 TMS9995 TMS99105
Z8001 Z8002 NS32032 MN1610 MN1613 MN1613A
CDP1802 CDP1804 CDP1804A SCN2650 F3850 TMS7000 TMS32010
TMS32015 i8086 i80186 V30 i8096 MC68000 TMS9900 TMS9995
TMS99105 Z8001 Z8002 NS32032 MN1610 MN1613 MN1613A
-o <output> : output file
-l <list> : list file
<input> : file can be Motorola S-Record or Intel HEX format
Expand Down
28 changes: 14 additions & 14 deletions cli/build.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,37 @@ build asm: link asm.o asm_commander.o file_reader.o file_printer.o $
asm_z8000.o asm_ns32000.o asm_mn1610.o $
reg_mc6809.o reg_mc6800.o reg_mc6805.o reg_mos6502.o reg_i8048.o reg_i8051.o reg_i8080.o $
reg_i8096.o reg_z80.o reg_z8.o reg_tlcs90.o reg_ins8060.o reg_ins8070.o reg_cdp1802.o $
reg_scn2650.o reg_f3850.o reg_i8086.o reg_tms9900.o reg_tms32010.o reg_mc68000.o reg_z8000.o $
reg_ns32000.o reg_mn1610.o $
reg_scn2650.o reg_f3850.o reg_i8086.o reg_tms7000.o reg_tms9900.o reg_tms32010.o reg_mc68000.o $
reg_z8000.o reg_ns32000.o reg_mn1610.o $
table_mc6809.o table_mc6800.o table_mc6805.o table_mos6502.o table_i8048.o table_i8051.o $
table_i8080.o table_i8096.o table_z80.o table_z8.o table_tlcs90.o table_ins8060.o $
table_ins8070.o table_cdp1802.o table_scn2650.o table_f3850.o table_i8086.o table_tms9900.o $
table_tms32010.o table_mc68000.o table_z8000.o table_ns32000.o table_mn1610.o $
table_ins8070.o table_cdp1802.o table_scn2650.o table_f3850.o table_i8086.o table_tms7000.o $
table_tms9900.o table_tms32010.o table_mc68000.o table_z8000.o table_ns32000.o table_mn1610.o $
text_common.o text_mc6809.o text_mc6800.o text_mc6805.o text_mos6502.o text_i8048.o $
text_i8051.o text_i8080.o text_i8096.o text_z80.o text_z8.o text_tlcs90.o text_ins8060.o $
text_ins8070.o text_cdp1802.o text_scn2650.o text_f3850.o text_i8086.o text_tms9900.o $
text_tms32010.o text_mc68000.o text_z8000.o text_ns32000.o text_mn1610.o
text_ins8070.o text_cdp1802.o text_scn2650.o text_f3850.o text_i8086.o text_tms7000.o $
text_tms9900.o text_tms32010.o text_mc68000.o text_z8000.o text_ns32000.o text_mn1610.o

build dis: link dis.o dis_commander.o file_reader.o file_printer.o $
error_reporter.o option_base.o str_buffer.o str_scanner.o value_formatter.o $
bin_memory.o bin_decoder.o bin_encoder.o list_formatter.o intel_hex.o moto_srec.o $
config_base.o reg_base.o dis_driver.o dis_formatter.o $
dis_base.o dis_mc6809.o dis_mc6800.o dis_mc6805.o dis_mos6502.o dis_i8048.o dis_i8051.o $
dis_i8080.o dis_i8096.o dis_z80.o dis_z8.o dis_tlcs90.o dis_ins8060.o dis_ins8070.o $
dis_cdp1802.o dis_scn2650.o dis_f3850.o dis_i8086.o dis_tms9900.o dis_tms32010.o dis_mc68000.o $
dis_z8000.o dis_ns32000.o dis_mn1610.o $
dis_cdp1802.o dis_scn2650.o dis_f3850.o dis_i8086.o dis_tms7000.o dis_tms9900.o dis_tms32010.o $
dis_mc68000.o dis_z8000.o dis_ns32000.o dis_mn1610.o $
reg_mc6809.o reg_mc6800.o reg_mc6805.o reg_mos6502.o reg_i8048.o reg_i8051.o reg_i8080.o $
reg_i8096.o reg_z80.o reg_z8.o reg_tlcs90.o reg_ins8060.o reg_ins8070.o reg_cdp1802.o $
reg_scn2650.o reg_f3850.o reg_i8086.o reg_tms9900.o reg_tms32010.o reg_mc68000.o reg_z8000.o $
reg_ns32000.o reg_mn1610.o $
reg_scn2650.o reg_f3850.o reg_i8086.o reg_tms7000.o reg_tms9900.o reg_tms32010.o reg_mc68000.o $
reg_z8000.o reg_ns32000.o reg_mn1610.o $
table_mc6809.o table_mc6800.o table_mc6805.o table_mos6502.o table_i8048.o table_i8051.o $
table_i8080.o table_i8096.o table_z80.o table_z8.o table_tlcs90.o table_ins8060.o $
table_ins8070.o table_cdp1802.o table_scn2650.o table_f3850.o table_i8086.o table_tms9900.o $
table_tms32010.o table_mc68000.o table_z8000.o table_ns32000.o table_mn1610.o $
table_ins8070.o table_cdp1802.o table_scn2650.o table_f3850.o table_i8086.o table_tms7000.o $
table_tms9900.o table_tms32010.o table_mc68000.o table_z8000.o table_ns32000.o table_mn1610.o $
text_common.o text_mc6809.o text_mc6800.o text_mc6805.o text_mos6502.o text_i8048.o $
text_i8051.o text_i8080.o text_i8096.o text_z80.o text_z8.o text_tlcs90.o text_ins8060.o $
text_ins8070.o text_cdp1802.o text_scn2650.o text_f3850.o text_i8086.o text_tms9900.o $
text_tms32010.o text_mc68000.o text_z8000.o text_ns32000.o text_mn1610.o
text_ins8070.o text_cdp1802.o text_scn2650.o text_f3850.o text_i8086.o text_tms7000.o $
text_tms9900.o text_tms32010.o text_mc68000.o text_z8000.o text_ns32000.o text_mn1610.o

build cli: phony asm dis

Expand Down
3 changes: 3 additions & 0 deletions cli/dis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "dis_scn2650.h"
#include "dis_tlcs90.h"
#include "dis_tms32010.h"
#include "dis_tms7000.h"
#include "dis_tms9900.h"
#include "dis_z8.h"
#include "dis_z80.h"
Expand Down Expand Up @@ -61,6 +62,7 @@ i8086::DisI8086 dis8086;
i8096::DisI8096 dis8096;
tlcs90::DisTlcs90 dis90;
tms32010::DisTms32010 dis32010;
tms7000::DisTms7000 dis7000;
tms9900::DisTms9900 dis9900;
mc68000::DisMc68000 dis68000;
z8000::DisZ8000 disz8000;
Expand All @@ -83,6 +85,7 @@ Disassembler *disassemblers[] = {
&dis1802,
&dis2650,
&dis3850,
&dis7000,
&dis32010,
&dis8086,
&dis8096,
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ url=https://github.com/tgtakaoka/libasm
architectures=*
license=Apache-2.0
dot_a_linkage=true
includes=asm_mc6809.h,dis_mc6809.h,asm_mc6800.h,dis_mc6800.h,asm_mc6805.h,dis_mc6805.h,asm_mos6502.h,dis_mos6502.h,asm_i8048.h,dis_i8048.h,asm_i8051.h,dis_i8051.h,asm_i8080.h,dis_i8080.h,asm_z80.h,dis_z80.h,asm_z8.h,dis_z8.h,asm_tlcs90.h,dis_tlcs90.h,asm_ins8060.h,dis_ins8060.h,asm_ins8070.h,dis_ins8070.h,asm_cdp1802.h,dis_cdp1802.h,asm_scn2650.h,dis_scn2650.h,asm_f3850.h,dis_f3850.h,asm_tms32010.h,dis_tms32010.h,asm_tms9900.h,dis_tms9900.h,asm_i8086.h,dis_i8086.h,asm_i8096.h,dis_i8096.h,asm_mc68000.h,dis_mc68000.h,asm_z8000.h,dis_z8000.h,asm_ns32000.h,dis_ns32000.h,asm_mn1610.h,dis_mn1610.h
includes=asm_mc6809.h,dis_mc6809.h,asm_mc6800.h,dis_mc6800.h,asm_mc6805.h,dis_mc6805.h,asm_mos6502.h,dis_mos6502.h,asm_i8048.h,dis_i8048.h,asm_i8051.h,dis_i8051.h,asm_i8080.h,dis_i8080.h,asm_z80.h,dis_z80.h,asm_z8.h,dis_z8.h,asm_tlcs90.h,dis_tlcs90.h,asm_ins8060.h,dis_ins8060.h,asm_ins8070.h,dis_ins8070.h,asm_cdp1802.h,dis_cdp1802.h,asm_scn2650.h,dis_scn2650.h,asm_f3850.h,dis_f3850.h,dis_tms7000.h,asm_tms32010.h,dis_tms32010.h,asm_tms9900.h,dis_tms9900.h,asm_i8086.h,dis_i8086.h,asm_i8096.h,dis_i8096.h,asm_mc68000.h,dis_mc68000.h,asm_z8000.h,dis_z8000.h,asm_ns32000.h,dis_ns32000.h,asm_mn1610.h,dis_mn1610.h
3 changes: 3 additions & 0 deletions src/Makefile.arch
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ARCHS = \
scn2650 \
tlcs90 \
tms32010 \
tms7000 \
tms9900 \
z8 \
z80 \
Expand Down Expand Up @@ -65,6 +66,7 @@ TGT_ns32000 = ns32000 ns32k
TGT_scn2650 = scn2650
TGT_tlcs90 = tlcs90
TGT_tms32010 = tms32010
TGT_tms7000 = tms7000
TGT_tms9900 = tms9900 tms9995 tms99105
TGT_z8000 = z8001 z8002 z8k1 z8k2
TGT_z80 = z80 i8080_z80syn i8085_z80syn v30emu_z80syn
Expand Down Expand Up @@ -110,6 +112,7 @@ CPU_r65c02 = 65C02
CPU_scn2650 = 2650
CPU_tlcs90 = TLCS90
CPU_tms32010 = 32010
CPU_tms7000 = TMS7000
CPU_tms9900 = TMS9900
CPU_tms99105 = TMS99105
CPU_tms9995 = TMS9995
Expand Down
44 changes: 44 additions & 0 deletions src/config_tms7000.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2023 Tadashi G. Takaoka
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef __CONFIG_TMS7000_H__
#define __CONFIG_TMS7000_H__

#include "config_base.h"

namespace libasm {
namespace tms7000 {

enum CpuType : uint8_t {
TMS7000,
};

struct Config
: public ConfigImpl<CpuType, ADDRESS_16BIT, ADDRESS_BYTE, OPCODE_8BIT, ENDIAN_BIG, 4, 5> {
Config(const InsnTable<CpuType> &table) : ConfigImpl(table, TMS7000) {}
};

} // namespace tms7000
} // namespace libasm

#endif // __CONFIG_TMS7000_H__

// Local Variables:
// mode: c++
// c-basic-offset: 4
// tab-width: 4
// End:
// vim: set ft=cpp et ts=4 sw=4:
159 changes: 159 additions & 0 deletions src/dis_tms7000.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* Copyright 2023 Tadashi G. Takaoka
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "dis_tms7000.h"

#include "reg_tms7000.h"
#include "table_tms7000.h"
#include "text_tms7000.h"

namespace libasm {
namespace tms7000 {

using namespace reg;
using namespace text::tms7000;

namespace {
const char TEXT_IDXB[] PROGMEM = "(B)";
}

DisTms7000::DisTms7000() : Disassembler(_hexFormatter, '$'), Config(TABLE) {
reset();
}

void DisTms7000::reset() {
Disassembler::reset();
}

Error DisTms7000::decodeRegister(DisInsn &insn, StrBuffer &out) {
const auto regno = insn.readByte();
if (regno < 2) {
out.letter('A' + regno);
} else {
outRegName(out, REG_RN, regno);
}
return setError(insn);
}

Error DisTms7000::decodeImmediate(DisInsn &insn, StrBuffer &out, AddrMode mode) {
out.letter('%');
if (mode == M_IM8) {
outHex(out, insn.readByte(), 8);
} else if (mode == M_IM16) {
outHex(out, insn.readUint16(), 16);
} else {
outHex(out, insn.readUint16(), 16).text_P(TEXT_IDXB);
}
return setError(insn);
}

Error DisTms7000::decodeAbsolute(DisInsn &insn, StrBuffer &out, AddrMode mode) {
const auto addr = insn.readUint16();
const auto label = lookup(addr);
if (label) {
out.letter('@').rtext(label);
} else {
outAbsAddr(out.letter('@'), addr, 16);
}
if (mode == M_IDXB)
out.text_P(TEXT_IDXB);
return setError(insn);
}

Error DisTms7000::decodeRelative(DisInsn &insn, StrBuffer &out, AddrMode mode) {
int16_t delta = static_cast<int8_t>(insn.readByte());
const auto base = insn.address() + insn.length();
const auto target = branchTarget(base, delta);
outRelAddr(out, target, insn.address(), 8);
return setErrorIf(insn);
}

Error DisTms7000::decodeOperand(DisInsn &insn, StrBuffer &out, AddrMode mode) {
switch (mode) {
case M_A:
outRegName(out, REG_A);
break;
case M_B:
outRegName(out, REG_B);
break;
case M_ST:
outRegName(out, REG_ST);
break;
case M_RN:
return decodeRegister(insn, out);
case M_PN:
outRegName(out, REG_PN, insn.readByte());
break;
case M_IM8:
case M_IM16:
case M_BIMM:
return decodeImmediate(insn, out, mode);
case M_ABS:
case M_IDXB:
return decodeAbsolute(insn, out, mode);
case M_INDR:
outRegName(out.letter('*'), REG_RN, insn.readByte());
break;
case M_REL:
return decodeRelative(insn, out, mode);
case M_TRAP:
outDec(out, 0x1F - (insn.opCode() & 0x1F), 5);
break;
default:
break;
}
return setErrorIf(insn);
}

Error DisTms7000::decodeImpl(DisMemory &memory, Insn &_insn, StrBuffer &out) {
DisInsn insn(_insn, memory);
const Config::opcode_t opCode = insn.readByte();
if (setError(insn))
return getError();
insn.setOpCode(opCode);

if (TABLE.searchOpCode(cpuType(), insn, out))
return setError(insn);

const auto src = insn.src();
if (src == M_NONE)
return setOK();
if (decodeOperand(insn, out, src))
return getError();

const auto dst = insn.dst();
if (dst == M_NONE)
return setOK();
out.comma();
if (decodeOperand(insn, out, dst))
return getError();

const auto ext = insn.ext();
if (ext == M_NONE)
return setOK();
out.comma();
return decodeOperand(insn, out, ext);
}

} // namespace tms7000
} // namespace libasm

// Local Variables:
// mode: c++
// c-basic-offset: 4
// tab-width: 4
// End:
// vim: set ft=cpp et ts=4 sw=4:
56 changes: 56 additions & 0 deletions src/dis_tms7000.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2023 Tadashi G. Takaoka
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef __DIS_TMS7000_H__
#define __DIS_TMS7000_H__

#include "config_tms7000.h"
#include "dis_base.h"
#include "insn_tms7000.h"

namespace libasm {
namespace tms7000 {

struct DisTms7000 final : Disassembler, Config {
DisTms7000();

void reset() override;

private:
const PrefixHexFormatter _hexFormatter{HexFormatter::LESS};

Error decodeRegister(DisInsn &insn, StrBuffer &out);
Error decodeImmediate(DisInsn &insn, StrBuffer &out, AddrMode mode);
Error decodeAbsolute(DisInsn &insn, StrBuffer &out, AddrMode mode);
Error decodeRelative(DisInsn &insn, StrBuffer &out, AddrMode mode);
Error decodeOperand(DisInsn &insn, StrBuffer &out, AddrMode mode);

Error decodeImpl(DisMemory &memory, Insn &insn, StrBuffer &out) override;
const ConfigBase &config() const override { return *this; }
ConfigSetter &configSetter() override { return *this; }
};

} // namespace tms7000
} // namespace libasm

#endif // __DIS_TMS7000_H__

// Local Variables:
// mode: c++
// c-basic-offset: 4
// tab-width: 4
// End:
// vim: set ft=cpp et ts=4 sw=4:
Loading

0 comments on commit 966f974

Please sign in to comment.