RISCVvirtMachine.cc Source File

Back to the index.

RISCVvirtMachine.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Anders Gavare. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  *
28  * RISC-V "virt" machine
29  *
30  * The idea is to mimic the "virt" machine in QEMU, to be able to run code
31  * such as FreeBSD/riscv build for that machine.
32  *
33  * [VIRT_DEBUG] = { 0x0, 0x100 },
34  * [VIRT_MROM] = { 0x1000, 0x11000 },
35  * [VIRT_TEST] = { 0x100000, 0x1000 },
36  * [VIRT_CLINT] = { 0x2000000, 0x10000 },
37  * [VIRT_PLIC] = { 0xc000000, 0x4000000 },
38  * [VIRT_UART0] = { 0x10000000, 0x100 },
39  * [VIRT_VIRTIO] = { 0x10001000, 0x1000 },
40  * [VIRT_DRAM] = { 0x80000000, 0x0 },
41  * [VIRT_PCIE_MMIO] = { 0x40000000, 0x40000000 },
42  * [VIRT_PCIE_PIO] = { 0x03000000, 0x00010000 },
43  * [VIRT_PCIE_ECAM] = { 0x30000000, 0x10000000 }
44  */
45 
47 #include "ComponentFactory.h"
48 #include "GXemul.h"
49 
50 
52 {
53  // Defaults:
55  settings["cpu"] = "RV64G";
56  settings["ram"] = "0x80000000"; // 2 GB
57  settings["ncpus"] = "1";
58 
60  return NULL;
61 
62 
65  if (machine.IsNULL())
66  return NULL;
67 
68  machine->SetVariableValue("template", "\"riscv-virt\"");
69 
70 
71  refcount_ptr<Component> mainbus =
73  if (mainbus.IsNULL())
74  return NULL;
75 
76  machine->AddChild(mainbus);
77 
78 
80  if (ram.IsNULL())
81  return NULL;
82 
83  ram->SetVariableValue("memoryMappedSize", settings["ram"]);
84  ram->SetVariableValue("memoryMappedBase", "0x80000000");
85  mainbus->AddChild(ram);
86 
87 
88  int ncpus;
89  stringstream tmpss3;
90  tmpss3 << settings["ncpus"];
91  tmpss3 >> ncpus;
92  if (ncpus < 1) {
93  if (args.gxemul != NULL)
94  args.gxemul->GetUI()->ShowDebugMessage("nr of cpus must be more than 0.");
95  return NULL;
96  }
97 
98  for (int i=0; i<ncpus; ++i) {
100  ComponentFactory::CreateComponent("riscv_cpu(model=" + settings["cpu"] + ")", args.gxemul);
101  if (cpu.IsNULL())
102  return NULL;
103 
104  if (i > 0)
105  cpu->SetVariableValue("paused", "true");
106 
107  mainbus->AddChild(cpu);
108  }
109 
110  return machine;
111 }
112 
113 
114 string RISCVvirtMachine::GetAttribute(const string& attributeName)
115 {
116  if (attributeName == "template")
117  return "yes";
118 
119  if (attributeName == "machine")
120  return "yes";
121 
122  if (attributeName == "description")
123  return "RISC-V virt machine.";
124 
125  return "";
126 }
127 
refcount_ptr::IsNULL
bool IsNULL() const
Checks whether or not an object is referenced by the reference counted pointer.
Definition: refcount_ptr.h:218
ComponentFactory::GetCreationArgOverrides
static bool GetCreationArgOverrides(ComponentCreationSettings &settings, const ComponentCreateArgs &createArgs)
Get override arguments for component creation.
Definition: ComponentFactory.cc:151
RISCVvirtMachine::GetAttribute
static string GetAttribute(const string &attributeName)
Gets a Component attribute value.
Definition: RISCVvirtMachine.cc:114
Component::AddChild
void AddChild(refcount_ptr< Component > childComponent, size_t insertPosition=(size_t) -1)
Adds a reference to a child component.
Definition: Component.cc:595
ComponentFactory.h
RISCVvirtMachine.h
refcount_ptr< Component >
UI::ShowDebugMessage
virtual void ShowDebugMessage(const string &msg)=0
Shows a debug message.
machine
Definition: machine.h:97
RISCVvirtMachine::Create
static refcount_ptr< Component > Create(const ComponentCreateArgs &args)
Creates a "riscv-virt" Component tree.
Definition: RISCVvirtMachine.cc:51
ComponentFactory::CreateComponent
static refcount_ptr< Component > CreateComponent(const string &componentNameAndOptionalArgs, GXemul *gxemul=NULL)
Creates a component given a short component name.
Definition: ComponentFactory.cc:87
Component::SetVariableValue
bool SetVariableValue(const string &name, const string &expression)
Sets a variable to a new value.
Definition: Component.cc:1030
ComponentCreateArgs::gxemul
GXemul * gxemul
Definition: Component.h:50
settings
Definition: settings.cc:57
ComponentCreationSettings
map< string, string > ComponentCreationSettings
Definition: Component.h:46
GXemul::GetUI
UI * GetUI()
Gets a pointer to the GXemul instance' active UI.
Definition: GXemul.cc:653
cpu
Definition: cpu.h:326
ComponentCreateArgs
Definition: Component.h:49
GXemul.h

Generated on Tue Aug 25 2020 19:25:06 for GXemul by doxygen 1.8.18