blob: defca407e8fcc265c807f5eb8d92ebdb2024adae [file] [log] [blame]
//
// 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,
}
}
}