I960_CPUComponent.h Source File

Back to the index.

I960_CPUComponent.h
Go to the documentation of this file.
1 #ifndef I960_CPUCOMPONENT_H
2 #define I960_CPUCOMPONENT_H
3 
4 /*
5  * Copyright (C) 2018-2019 Anders Gavare. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  * derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 // COMPONENT(i960_cpu)
32 
33 
34 #include "CPUDyntransComponent.h"
35 
36 
37 #define N_I960_REGS 32
38 #define N_I960_SFRS 32
39 
40 
41 /*
42 Register conventions according to
43 https://people.cs.clemson.edu/~mark/subroutines/i960.html
44 */
45 
46 static const char* i960_regnames[N_I960_REGS] = {
47  "pfp", // r0 = previous frame pointer
48  "sp", // r1 = stack pointer
49  "rip", // r2 = return instruction pointer
50  "r3", "r4", "r5", "r6", "r7",
51  "r8", "r9", "r10", "r11", "r12",
52  "r13", "r14", "r15",
53 
54  "g0", "g1", "g2", "g3", // parameters 0-3; return words 0-3
55  "g4", "g5", "g6", "g7", // parameters 4-7; temporaries
56  "g8", "g9", "g10", "g11", "g12", // preserved accross call
57  "g13", // structure return pointer
58  "g14", // argument block pointer; leaf return address (HW)
59  "fp" // g15 = frame pointer (16-byte aligned HW)
60 };
61 
62 #define I960_G0 16 // offset to first parameter register
63 
64 
65 /***********************************************************************/
66 
67 
68 /**
69  * \brief A Component representing an Intel i960 processor.
70  */
72  : public CPUDyntransComponent
73 {
74 public:
75  /**
76  * \brief Constructs a I960_CPUComponent.
77  */
79 
80  /**
81  * \brief Creates a I960_CPUComponent.
82  */
84 
85  static string GetAttribute(const string& attributeName);
86 
87  virtual void ResetState();
88 
89  virtual bool PreRunCheckForComponent(GXemul* gxemul);
90 
91  virtual size_t DisassembleInstruction(uint64_t vaddr, vector<string>& result);
92 
93 
94  /********************************************************************/
95 
96  static void RunUnitTests(int& nSucceeded, int& nFailures);
97 
98 protected:
99  virtual bool CheckVariableWrite(StateVariable& var, const string& oldValue);
100 
101  virtual bool VirtualToPhysical(uint64_t vaddr, uint64_t& paddr, bool& writable);
102 
103  virtual string VirtualAddressAsString(uint64_t vaddr)
104  {
105  stringstream ss;
106  ss.flags(std::ios::hex | std::ios::showbase | std::ios::right);
107  ss << (uint32_t)vaddr;
108  return ss.str();
109  }
110 
111  virtual uint64_t PCtoInstructionAddress(uint64_t pc);
112 
113  virtual int FunctionTraceArgumentCount();
114  virtual int64_t FunctionTraceArgument(int n);
115  virtual bool FunctionTraceReturnImpl(int64_t& retval);
116 
117  virtual int GetDyntransICshift() const;
119 
120  virtual void ShowRegisters(GXemul* gxemul, const vector<string>& arguments) const;
121 
122 private:
123  DECLARE_DYNTRANS_INSTR(b);
124  DECLARE_DYNTRANS_INSTR(lda_displacement);
125 
126  DECLARE_DYNTRANS_INSTR(mov_lit_reg);
127  DECLARE_DYNTRANS_INSTR(mov_reg_reg);
128 
129  DECLARE_DYNTRANS_INSTR(sysctl);
130 
131  void Translate(uint32_t iword, uint32_t iword2, struct DyntransIC* ic);
132  DECLARE_DYNTRANS_INSTR(ToBeTranslated);
133 
134 private:
135  /*
136  * State:
137  */
138  string m_model;
139 
140  uint32_t m_r[N_I960_REGS]; // r and g registers
141 
142  // NOTE: The i960 "ip" register is m_pc.
143 
144  uint32_t m_i960_ac; // Arithmetic control
145  uint32_t m_i960_pc; // Process control
146  uint32_t m_i960_tc; // Trace control
147 
148  uint32_t m_nr_of_valid_sfrs; // depends on model
149  uint32_t m_sfr[N_I960_SFRS];
150 };
151 
152 
153 #endif // I960_CPUCOMPONENT_H
I960_CPUComponent::DisassembleInstruction
virtual size_t DisassembleInstruction(uint64_t vaddr, vector< string > &result)
Disassembles an instruction into readable strings.
Definition: I960_CPUComponent.cc:326
I960_CPUComponent::FunctionTraceReturnImpl
virtual bool FunctionTraceReturnImpl(int64_t &retval)
Definition: I960_CPUComponent.cc:291
I960_CPUComponent::Create
static refcount_ptr< Component > Create(const ComponentCreateArgs &args)
Creates a I960_CPUComponent.
Definition: I960_CPUComponent.cc:159
I960_CPUComponent::FunctionTraceArgumentCount
virtual int FunctionTraceArgumentCount()
Definition: I960_CPUComponent.cc:279
GXemul
The main emulator class.
Definition: GXemul.h:55
StateVariable
StateVariables make up the persistent state of Component objects.
Definition: StateVariable.h:69
N_I960_SFRS
#define N_I960_SFRS
Definition: I960_CPUComponent.h:38
refcount_ptr< Component >
I960_CPUComponent::RunUnitTests
static void RunUnitTests(int &nSucceeded, int &nFailures)
N_I960_REGS
#define N_I960_REGS
Definition: I960_CPUComponent.h:37
CPUDyntransComponent
A base-class for processors Component implementations that use dynamic translation.
Definition: CPUDyntransComponent.h:91
I960_CPUComponent::GetDyntransICshift
virtual int GetDyntransICshift() const
Definition: I960_CPUComponent.cc:298
I960_CPUComponent::CheckVariableWrite
virtual bool CheckVariableWrite(StateVariable &var, const string &oldValue)
Checks whether a write to a variable is OK.
Definition: I960_CPUComponent.cc:235
I960_CPUComponent::PCtoInstructionAddress
virtual uint64_t PCtoInstructionAddress(uint64_t pc)
Convert PC value to instuction address.
Definition: I960_CPUComponent.cc:320
DyntransIC
Definition: CPUDyntransComponent.h:55
I960_CPUComponent
A Component representing an Intel i960 processor.
Definition: I960_CPUComponent.h:73
ic
struct arm_instr_call * ic
Definition: tmp_arm_multi.cc:50
CPUDyntransComponent.h
I960_CPUComponent::VirtualToPhysical
virtual bool VirtualToPhysical(uint64_t vaddr, uint64_t &paddr, bool &writable)
Virtual to physical address translation (MMU).
Definition: I960_CPUComponent.cc:311
I960_CPUComponent::ShowRegisters
virtual void ShowRegisters(GXemul *gxemul, const vector< string > &arguments) const
Definition: I960_CPUComponent.cc:243
I960_CPUComponent::ResetState
virtual void ResetState()
Resets the state variables of this component.
Definition: I960_CPUComponent.cc:198
I960_CPUComponent::PreRunCheckForComponent
virtual bool PreRunCheckForComponent(GXemul *gxemul)
Checks the state of this component, before starting execution.
Definition: I960_CPUComponent.cc:223
I960_CPUComponent::FunctionTraceArgument
virtual int64_t FunctionTraceArgument(int n)
Definition: I960_CPUComponent.cc:285
I960_CPUComponent::GetDyntransToBeTranslated
virtual void(*)(CPUDyntransComponent *, DyntransIC *) GetDyntransToBeTranslated()
Definition: I960_CPUComponent.h:118
I960_CPUComponent::I960_CPUComponent
I960_CPUComponent()
Constructs a I960_CPUComponent.
Definition: I960_CPUComponent.cc:131
I960_CPUComponent::VirtualAddressAsString
virtual string VirtualAddressAsString(uint64_t vaddr)
Format a virtual address as a displayable string.
Definition: I960_CPUComponent.h:103
ComponentCreateArgs
Definition: Component.h:49
I960_CPUComponent::GetAttribute
static string GetAttribute(const string &attributeName)
Definition: I960_CPUComponent.cc:767

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