--- nono/m680x0/testea.cpp 2026/04/29 17:04:28 1.1 +++ nono/m680x0/testea.cpp 2026/04/29 17:05:40 1.1.1.5 @@ -1,17 +1,44 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // -#include "m68030ea.cpp" +#include "mpu680x0.h" -uint16 g_fetch[5]; -int g_fetch_ptr; +class MPU680x0Test : public MPU680x0Device +{ + public: + MPU680x0Test() { } + ~MPU680x0Test() override { } + void test_ea_ix(); + void test_ea_ix2(); + + uint32 fetch_2() override; + uint32 fetch_4() override; + uint32 read_data(busaddr addr) override; + void write_data(busaddr addr, uint32 data) override; + + bool TranslateRead() override { return true; } + bool TranslateWrite() override { return true; } + busaddr TranslatePeek(busaddr) override { return busaddr(0); } + void CalcStat() override { } + bool ops_movec_rc_rn_cpu(uint, uint) override { return true; } + bool ops_movec_rn_rc_cpu(uint, uint) override { return true; } + void ops_mmu30() override { } + void ops_mmu40_pflush() override { } + void ResetMMU() override { } + void ResetCache() override { } + void SetCACR(uint32) override { } +}; + +static uint16 g_fetch[5]; +static int g_fetch_ptr; // ダミーのフェッチルーチン // グローバル変数 g_fetch[] で指定された値を順に返す uint32 -m68030_fetch_16(m68kcpu *cpu) +MPU680x0Test::fetch_2() { uint16 data; @@ -23,27 +50,71 @@ m68030_fetch_16(m68kcpu *cpu) } uint32 -m68030_fetch_32(m68kcpu *cpu) +MPU680x0Test::fetch_4() { uint32 data; - data = m68030_fetch_16(cpu) << 16; - data |= m68030_fetch_16(cpu); + data = fetch_2() << 16; + data |= fetch_2(); return data; } -uint32 m68030_read_8(m68kcpu *cpu, uint32 ea) { return 0; } -uint32 m68030_read_16(m68kcpu *cpu, uint32 ea) { return 0; } + // ダミーリード // アドレスを2倍にして返す。 // メモリ間接の post index、pre index を演算だけで判別するため。 -uint32 m68030_read_32(m68kcpu *cpu, uint32 ea) { - return ea << 1; +uint32 +MPU680x0Test::read_data(busaddr laddr) +{ + if (laddr.GetSize() == 4) { + return laddr.Addr() << 1; + } + return 0; } -void m68030_write_8(m68kcpu *cpu, uint32 ea, uint32 data) { } -void m68030_write_16(m68kcpu *cpu, uint32 ea, uint32 data) { } -void m68030_write_32(m68kcpu *cpu, uint32 ea, uint32 data) { } + void -panic(const char *func, const char *fmt, ...) +MPU680x0Test::write_data(busaddr laddr, uint32 data) +{ +} + +// リンクを通すためのダミー。 +Object::Object(uint) { } +Object::~Object() { } +Device::Device(uint) : inherited(0) { } +Device::~Device() { } +MPUDevice::MPUDevice(uint) : inherited(0) { } +MPUDevice::~MPUDevice() { } +MainMPUDevice::MainMPUDevice() : inherited(0) { } +MainMPUDevice::~MainMPUDevice() { } +MPU680x0Device::MPU680x0Device() { } +MPU680x0Device::~MPU680x0Device() { } +Event::Event(Device *) { } +Event::~Event() { } +BranchHistory::BranchHistory(uint) : inherited(0) { } +BranchHistory::~BranchHistory() { } +BranchHistory_m680x0::BranchHistory_m680x0(uint) : inherited(0) { } +BranchHistory_m680x0::~BranchHistory_m680x0() { } +void Object::SetLogLevel(int) { } +void Object::putlogn(const char *, ...) const { } +void Device::putlogn(const char *, ...) const { } +bool Device::Create() { return true; } +bool Device::Create2() { return true; } +bool Device::Init() { return true; } +void Device::ResetHard(bool) { } +bool Device::Apply() { return true; } +void Device::PowerOff() { } +bool MPUDevice::Init() { return true; } +void MPUDevice::PowerOff() { } +bool MainMPUDevice::Init() { return true; } +bool MPU680x0Device::Init() { return true; } +void MPU680x0Device::ResetHard(bool) { } +void MPU680x0Device::Interrupt(int) { } +void MPU680x0Device::SetTrace(bool) { } +std::string BranchHistory::FormatHeader() const { return ""; } +std::string BranchHistory::FormatEntry(const BranchEntry&) { return ""; } +std::string BranchHistory_m680x0::FormatEntry(const BranchEntry&) { return ""; } + +void +panic_func(const char *func, const char *fmt, ...) { va_list ap; printf("panic: %s:", func); @@ -53,13 +124,13 @@ panic(const char *func, const char *fmt, abort(); } -m68kcpu *cpu; -int tested; -int failed; +static MPU680x0Test *cpu; +static int tested; +static int failed; // 拡張 EA の全組み合わせを試す網羅テスト void -test_ea_ix() +MPU680x0Test::test_ea_ix() { uint32 ea; struct { @@ -74,7 +145,7 @@ test_ea_ix() }; uint32 An = 0x00010000; - RegD(1) = 0x00100010; + cpu->reg.D[1] = 0x00100010; for (int i = 0; i < countof(table); i++) { g_fetch_ptr = 0; @@ -109,7 +180,7 @@ test_ea_ix() tested++; printf("test_ea_ix[0x%04x] %-20s ", table[i].ext, table[i].name); - ea = internal_ea_ix(cpu, An); + ea = internal_ea_ix(An); if (table[i].exp_pc != g_fetch_ptr) { printf("FAILED! pc expects %d but %d\n", table[i].exp_pc, g_fetch_ptr); @@ -134,12 +205,12 @@ test_ea_ix() } } -const char *scalestr[] = { +static const char *scalestr[] = { "", "*2", "*4", "*8" }; // 拡張 EA Full format の指定パターンのテストを生成する。 -void +static void make_ea_ix_full(int wl, int scale, int bs, int is, int bdsz, int iis) { uint32 data; @@ -251,7 +322,7 @@ make_ea_ix_full(int wl, int scale, int b } // 拡張 EA 全パターンのテストを生成する。 -void +static void make_ea_ix() { // Brief format @@ -293,7 +364,7 @@ make_ea_ix() // 符号拡張のテスト。 // 符号拡張が起きるのは xn.W, bd.W, od.W の3か所。 void -test_ea_ix2() +MPU680x0Test::test_ea_ix2() { struct { uint16 ext; // 拡張ワード @@ -306,7 +377,7 @@ test_ea_ix2() }; uint32 An = 0x00011110; - RegD(1) = 0x0000fff0; // -0x0010.W + cpu->reg.D[1] = 0x0000fff0; // -0x0010.W for (int i = 0; i < countof(table); i++) { g_fetch[0] = table[i].ext; g_fetch[1] = 0xff00; // -0x0100.W @@ -315,7 +386,7 @@ test_ea_ix2() tested++; printf("test_ea_ix2[0x%04x] %-20s ", table[i].ext, table[i].name); - uint32 ea = internal_ea_ix(cpu, An); + uint32 ea = internal_ea_ix(An); if (table[i].exp_ea != ea) { printf("FAILED! ea expects %08x but %08x\n", table[i].exp_ea, ea); @@ -337,10 +408,7 @@ test_ea_ix2() int main(int ac, char *av[]) { - // 本当はコンストラクタを呼ぶべきだが、そうすると必要なオブジェクトが - // 芋づる式に増えて正しく解決するのは面倒。ここのテストではとりあえず - // 存在しててアクセスできればいい程度なのでこれで誤魔化してある。 - cpu = (m68kcpu *)calloc(sizeof(*cpu), 1); + cpu = new MPU680x0Test(); // 引数が何かあればテストパターン生成、なければテスト。 // XXX そのうち整備する。 @@ -350,8 +418,8 @@ main(int ac, char *av[]) tested = 0; failed = 0; - test_ea_ix(); - test_ea_ix2(); + cpu->test_ea_ix(); + cpu->test_ea_ix2(); printf("RESULT: %d tested, %d success", tested, tested - failed); if (failed > 0)