//
// Copyright (c) 2023 Google LLC
//
// 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
//
//     https://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.

// XXX need to refactor Mpact to share/reuse SmcRiscv32.cs

using System;
using System.Collections.Generic;
using Antmicro.Renode.Core.Structure.Registers;
using Antmicro.Renode.Core;
using Antmicro.Renode.Logging;
using Antmicro.Renode.Peripherals.Bus;

namespace Antmicro.Renode.Peripherals.MpactCPU
{
  public class SmcCheriot_ControlBlock : IDoubleWordPeripheral, IKnownSize
  {
    public SmcCheriot_ControlBlock(MpactCheriotCPU cpu, long pc)
    {
      this.cpu = cpu;
      this.startPC = pc;
      DefineRegisters();
      Reset();
    }

    public void Reset() // IPeripheral
    {
    }

    public uint ReadDoubleWord(long addr) // IDoubleWordPeripheral
    {
      return RegistersCollection.Read(addr);
    }

    public void WriteDoubleWord(long addr, uint value) // IDoubleWordPeripheral
    {
      RegistersCollection.Write(addr, value);
    }

    public long Size => 0x8;
    private MpactCheriotCPU cpu;
    private long startPC;

    public DoubleWordRegisterCollection RegistersCollection { get; private set; }
    private void DefineRegisters() {
      var registerDictionary = new Dictionary<long, DoubleWordRegister>
      {{(long)Registers.BootEnRegwen, new DoubleWordRegister(this)
        .WithReservedBits(0, 31)
      },
      {(long)Registers.BootEnCtrl, new DoubleWordRegister(this)
        .WithFlag(0, FieldMode.Write, writeCallback: (_, val) => {
          if (val) {
            this.Log(LogLevel.Noisy, "Starting SMC at 0x{0:X}", this.startPC);
            cpu.PC = this.startPC;
            cpu.IsHalted = false;
          } else {
            this.Log(LogLevel.Noisy, "Stopping SMC");
            cpu.PC = 0;
            cpu.IsHalted = true;
          }
        })
      }};
      RegistersCollection = new DoubleWordRegisterCollection(this, registerDictionary);
    }
    public enum Registers {
       BootEnRegwen = 0x0,
       BootEnCtrl = 0x4,
    }
  }
}
