File:  [Isaki's NoNo m68k/m88k emulator] / nono / vm / mpu.h
Revision 1.1.1.18 (vendor branch): download - view: text, annotated - select for diffs
Wed Apr 29 17:05:59 2026 UTC (3 months ago) by root
Branches: MAIN, Isaki
CVS tags: v027, HEAD
nono 1.7.0

//
// nono
// Copyright (C) 2020 nono project
// Licensed under nono-license.txt
//

//
// MPU 共通部
//

#pragma once

#include "device.h"
#include "message.h"
#include "event.h"
#include <vector>

class Debugger;
class MainbusDevice;
class Syncer;

// 全 MPU の共通部
class MPUDevice : public Device
{
	using inherited = Device;
 public:
	explicit MPUDevice(uint objid_);
	~MPUDevice() override;

	bool Init() override;
	void ResetHard(bool poweron) override;
	void PowerOff() override;

	// 現在実行中の命令の PC を取得
	virtual uint32 GetPPC() const = 0;

	// 最後に発生した例外ベクタを取得し、同時にクリアする
	int32 GetAndResetLastVector();

	// exec イベントの回数
	uint64 GetExecCount() const { return exec_event->count; }

 protected:
	// 1命令実行イベント
	Event *exec_event {};

	Debugger *debugger {};

	// 最後に発生した例外ベクタ。起きてなければ -1。
	int32 last_vector {};
};

// メイン MPU (680x0/88xxx0) 共通部
class MainMPUDevice : public MPUDevice
{
	using inherited = MPUDevice;
 protected:
	// CPU の実行状態
	static const uint32 CPU_STATE_NORMAL	= 0;
	static const uint32 CPU_STATE_STOP		= 1;
	static const uint32 CPU_STATE_HALT		= 2;

 public:
	MainMPUDevice();
	~MainMPUDevice() override;

	bool Init() override;

	// 現在の VBR を取得
	virtual uint32 GetVBR() const = 0;

	// CPU の実行状態 (uint32) を返す。
	uint32 GetState() const noexcept { return cpu_state; }

	// MPU 名を取得する。("MC68030" みたいなやつ、ログ名とは別)
	virtual const char *GetMPUName() const = 0;

	// MPU クロック [kHz] を取得する。
	uint GetClockSpeed() const { return clock_khz; }

	// MPU クロック [tsec] を取得する。
	uint64 GetClock_tsec() const { return clock_tsec; }

	// 割り込み発生を MPU に通知
	virtual void Interrupt(int level) = 0;

	// デバイスが CI (キャッシュ禁止) をセットする。
	virtual void SetCI() = 0;

	// 例外カウンタ
	std::vector<uint64> excep_counter {};

 protected:
	void TraceMessage(MessageID, uint32);
	virtual void SetTrace(bool enable) = 0;

	// CPU の状態
	void ChangeState(uint32 new_state);

	// CPU の実行状態
	uint32 cpu_state {};

	uint clock_khz {};		// MPU クロック [kHz]
	uint64 clock_tsec {};	// MPU クロック [tsec]

	bool resetting {};		// リセット処理中フラグ

	// キャッシュを強制的に無効にする。テスト用。
	bool force_disable_dcache {};
	bool force_disable_icache {};

	MainbusDevice *mainbus {};
	Syncer *syncer {};

	// Round Mode (モニタ表示用)
	static const char * const rmstr[4];
};

inline MainMPUDevice *GetMPUDevice() {
	return Object::GetObject<MainMPUDevice>(OBJ_MPU);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.