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

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.13! root        8: // MPU (共通部分)
1.1.1.9   root        9: //
1.1.1.2   root       10: 
1.1.1.11  root       11: // Device
                     12: //    |  +-----------+
1.1.1.13! root       13: //    +--| MPUDevice | (全 MPU の共通部)
        !            14: //       +-----------+
        !            15: //         |
        !            16: //         |  +---------------+
        !            17: //         +--| MainMPUDevice | (680x0/88xx0 の共通部)
        !            18: //         |  +---------------+
        !            19: //         |    |
        !            20: //         |    +-- MPU680x0Device
        !            21: //         |    +-- MPU88xx0Device
        !            22: //         |
        !            23: //         +-- MPU64180Device
1.1.1.11  root       24: 
1.1       root       25: #include "mpu.h"
1.1.1.5   root       26: #include "config.h"
1.1.1.11  root       27: #include "debugger.h"
                     28: #include "mainbus.h"
1.1.1.9   root       29: #include "scheduler.h"
1.1.1.11  root       30: #include "syncer.h"
1.1       root       31: 
1.1.1.13! root       32: //
        !            33: // 全 MPU 共通
        !            34: //
        !            35: 
1.1       root       36: // コンストラクタ
1.1.1.13! root       37: MPUDevice::MPUDevice(uint objid_)
        !            38:        : inherited(objid_)
1.1       root       39: {
                     40: }
                     41: 
                     42: // デストラクタ
                     43: MPUDevice::~MPUDevice()
                     44: {
                     45: }
1.1.1.4   root       46: 
1.1.1.11  root       47: // 初期化
1.1.1.5   root       48: bool
                     49: MPUDevice::Init()
                     50: {
1.1.1.11  root       51:        if (inherited::Init() == false) {
                     52:                return false;
                     53:        }
                     54: 
                     55:        debugger = GetDebugger();
1.1.1.13! root       56: 
        !            57:        // パラメータは継承側でセットしている。
        !            58:        scheduler->RegistEvent(exec_event);
        !            59: 
        !            60:        return true;
        !            61: }
        !            62: 
        !            63: void
        !            64: MPUDevice::PowerOff()
        !            65: {
        !            66:        scheduler->StopEvent(exec_event);
        !            67: }
        !            68: 
        !            69: 
        !            70: //
        !            71: // メイン MPU (680x0/88xx0) 共通部
        !            72: //
        !            73: 
        !            74: // コンストラクタ
        !            75: MainMPUDevice::MainMPUDevice()
        !            76:        : inherited(OBJ_MPU)
        !            77: {
        !            78: }
        !            79: 
        !            80: // デストラクタ
        !            81: MainMPUDevice::~MainMPUDevice()
        !            82: {
        !            83: }
        !            84: 
        !            85: // 初期化
        !            86: bool
        !            87: MainMPUDevice::Init()
        !            88: {
        !            89:        if (inherited::Init() == false) {
        !            90:                return false;
        !            91:        }
        !            92: 
1.1.1.11  root       93:        mainbus = GetMainbusDevice();
                     94:        syncer = GetSyncer();
                     95: 
1.1.1.5   root       96:        // MPU クロック
                     97:        const ConfigItem& item = gConfig->Find("mpu-clock");
1.1.1.13! root       98: 
        !            99: #if 1
        !           100:        int val;
        !           101:        if (item.TryFixedDecimal(&val, 3) == false) {
        !           102:                item.Err();
        !           103:                return false;
        !           104:        }
        !           105:        clock_khz = (uint)val;
        !           106: #else
1.1.1.5   root      107:        const std::string& val = item.AsString();
                    108:        if (val.empty()) {
                    109:                item.Err();
                    110:                return false;
                    111:        }
                    112:        // 文字列を double に変換
                    113:        char *end;
                    114:        errno = 0;
                    115:        double f = strtod(val.c_str(), &end);
                    116:        if (end == val.c_str() || end[0] != '\0' || errno == ERANGE) {
                    117:                item.Err();
                    118:                return false;
                    119:        }
                    120:        // 設定の "mpu-clock" は MHz 単位だが、変数 clock_khz は kHz 単位。
1.1.1.13! root      121:        clock_khz = (uint)(f * 1000 + 0.9);
        !           122: #endif
1.1.1.7   root      123:        // 1MHz 未満はエラー。実際 10MHz 未満でもいい気がするけど
1.1.1.5   root      124:        if (clock_khz < 1000) {
                    125:                item.Err();
                    126:                return false;
                    127:        }
1.1.1.9   root      128:        clock_nsec = 1000 * 1000 / clock_khz;
1.1.1.5   root      129: 
1.1.1.13! root      130:        scheduler->ConnectMessage(MessageID::MPU_TRACE_MAIN, this,
        !           131:                ToMessageCallback(&MainMPUDevice::TraceMessage));
1.1.1.8   root      132: 
1.1.1.13! root      133:        exec_event.SetName("MPU Execute");
        !           134: 
        !           135:        return true;
1.1.1.9   root      136: }
                    137: 
                    138: // MPU トレース状態設定要求メッセージ
                    139: void
1.1.1.13! root      140: MainMPUDevice::TraceMessage(MessageID msgid, uint32 arg)
1.1.1.9   root      141: {
1.1.1.10  root      142:        // リセット中は SetTrace しない
                    143:        if (resetting) {
                    144:                return;
                    145:        }
                    146: 
1.1.1.9   root      147:        // デバッガから MPU のトレース状態を設定してくれと言われた
                    148:        SetTrace((bool)arg);
                    149: }
                    150: 
1.1.1.8   root      151: // Round Mode (モニタ表示用)
                    152: /*static*/ const char * const
1.1.1.13! root      153: MainMPUDevice::rmstr[4] = {
1.1.1.8   root      154:        "Near",
                    155:        "Zero",
                    156:        "Minus",
                    157:        "Plus",
                    158: };

unix.superglobalmegacorp.com

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