//
// 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.

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.CPU
{
  public class SmcRiscV32_ControlBlock : IDoubleWordPeripheral, IKnownSize
  {
    public SmcRiscV32_ControlBlock(RiscV32 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 RiscV32 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,
    }
  }
}
