Annotation of nono/vm/mpu.cpp, revision 1.1.1.12

1.1       root        1: //
                      2: // nono
1.1.1.3   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
1.1.1.9   root        7: //
1.1.1.11  root        8: // メイン MPU (680x0/88xx0) 共通部
1.1.1.9   root        9: //
1.1.1.2   root       10: 
1.1.1.11  root       11: // Device
                     12: //    |  +-----------+
                     13: //    +--| MPUDevice | (680x0/88xx0 の共通部)
                     14: //    |  +-----------+
                     15: //    |     |
                     16: //    |     +-- MPU680x0Device
                     17: //    |     +-- MPU88xx0Device
                     18: //    |
                     19: //    +-------- MPU64180Device
                     20: 
1.1       root       21: #include "mpu.h"
1.1.1.5   root       22: #include "config.h"
1.1.1.11  root       23: #include "debugger.h"
                     24: #include "mainbus.h"
1.1.1.9   root       25: #include "scheduler.h"
1.1.1.11  root       26: #include "syncer.h"
1.1       root       27: 
                     28: // コンストラクタ
1.1.1.11  root       29: MPUDevice::MPUDevice()
                     30:        : inherited(OBJ_MPU)
1.1       root       31: {
1.1.1.9   root       32:        exec_event.Regist("MPU Execute");
1.1       root       33: }
                     34: 
                     35: // デストラクタ
                     36: MPUDevice::~MPUDevice()
                     37: {
                     38: }
1.1.1.4   root       39: 
1.1.1.11  root       40: // 初期化
1.1.1.5   root       41: bool
                     42: MPUDevice::Init()
                     43: {
1.1.1.11  root       44:        if (inherited::Init() == false) {
                     45:                return false;
                     46:        }
                     47: 
                     48:        debugger = GetDebugger();
                     49:        mainbus = GetMainbusDevice();
                     50:        syncer = GetSyncer();
                     51: 
                     52:        scheduler->ConnectMessage(MessageID::MPU_TRACE_MAIN, this,
1.1.1.9   root       53:                ToMessageCallback(&MPUDevice::TraceMessage));
                     54: 
1.1.1.5   root       55:        // MPU クロック
                     56:        const ConfigItem& item = gConfig->Find("mpu-clock");
                     57:        const std::string& val = item.AsString();
                     58:        if (val.empty()) {
                     59:                item.Err();
                     60:                return false;
                     61:        }
                     62:        // 文字列を double に変換
                     63:        char *end;
                     64:        errno = 0;
                     65:        double f = strtod(val.c_str(), &end);
                     66:        if (end == val.c_str() || end[0] != '\0' || errno == ERANGE) {
                     67:                item.Err();
                     68:                return false;
                     69:        }
                     70:        // 設定の "mpu-clock" は MHz 単位だが、変数 clock_khz は kHz 単位。
                     71:        clock_khz = (int)(f * 1000);
1.1.1.7   root       72:        // 1MHz 未満はエラー。実際 10MHz 未満でもいい気がするけど
1.1.1.5   root       73:        if (clock_khz < 1000) {
                     74:                item.Err();
                     75:                return false;
                     76:        }
1.1.1.9   root       77:        clock_nsec = 1000 * 1000 / clock_khz;
1.1.1.5   root       78: 
                     79:        return true;
                     80: }
1.1.1.8   root       81: 
1.1.1.9   root       82: void
                     83: MPUDevice::PowerOff()
                     84: {
1.1.1.11  root       85:        scheduler->StopEvent(exec_event);
1.1.1.9   root       86: }
                     87: 
                     88: // MPU トレース状態設定要求メッセージ
                     89: void
                     90: MPUDevice::TraceMessage(MessageID msgid, uint32 arg)
                     91: {
1.1.1.10  root       92:        // リセット中は SetTrace しない
                     93:        if (resetting) {
                     94:                return;
                     95:        }
                     96: 
1.1.1.9   root       97:        // デバッガから MPU のトレース状態を設定してくれと言われた
                     98:        SetTrace((bool)arg);
                     99: }
                    100: 
1.1.1.8   root      101: // Round Mode (モニタ表示用)
                    102: /*static*/ const char * const
                    103: MPUDevice::rmstr[4] = {
                    104:        "Near",
                    105:        "Zero",
                    106:        "Minus",
                    107:        "Plus",
                    108: };

unix.superglobalmegacorp.com

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