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 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, size_t maxlen,
92  unsigned char *instruction, vector<string>& result);
93 
94 
95  /********************************************************************/
96 
97  static void RunUnitTests(int& nSucceeded, int& nFailures);
98 
99 protected:
100  virtual bool CheckVariableWrite(StateVariable& var, const string& oldValue);
101 
102  virtual bool VirtualToPhysical(uint64_t vaddr, uint64_t& paddr, bool& writable);
103 
104  virtual string VirtualAddressAsString(uint64_t vaddr)
105  {
106  stringstream ss;
107  ss.flags(std::ios::hex | std::ios::showbase | std::ios::right);
108  ss << (uint32_t)vaddr;
109  return ss.str();
110  }
111 
112  virtual uint64_t PCtoInstructionAddress(uint64_t pc);
113 
114  virtual int FunctionTraceArgumentCount();
115  virtual int64_t FunctionTraceArgument(int n);
116  virtual bool FunctionTraceReturnImpl(int64_t& retval);
117 
118  virtual int GetDyntransICshift() const;
120 
121  virtual void ShowRegisters(GXemul* gxemul, const vector<string>& arguments) const;
122 
123 private:
124  DECLARE_DYNTRANS_INSTR(b);
125  DECLARE_DYNTRANS_INSTR(lda_displacement);
126  DECLARE_DYNTRANS_INSTR(mov_lit_reg);
127  DECLARE_DYNTRANS_INSTR(sysctl);
128 
129  void Translate(uint32_t iword, uint32_t iword2, struct DyntransIC* ic);
130  DECLARE_DYNTRANS_INSTR(ToBeTranslated);
131 
132 private:
133  /*
134  * State:
135  */
136  string m_model;
137 
138  uint32_t m_r[N_I960_REGS]; // r and g registers
139 
140  // NOTE: The i960 "ip" register is m_pc.
141 
142  uint32_t m_i960_ac; // Arithmetic control
143  uint32_t m_i960_pc; // Process control
144  uint32_t m_i960_tc; // Trace control
145 
146  uint32_t m_nr_of_valid_sfrs; // depends on model
147  uint32_t m_sfr[N_I960_SFRS];
148 };
149 
150 
151 #endif // I960_CPUCOMPONENT_H
I960_CPUComponent::FunctionTraceReturnImpl
virtual bool FunctionTraceReturnImpl(int64_t &retval)
Definition: I960_CPUComponent.cc:287
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:275
GXemul
The main emulator class.
Definition: GXemul.h:54
StateVariable
StateVariables make up the persistent state of Component objects.
Definition: StateVariable.h:67
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:85
I960_CPUComponent::GetDyntransICshift
virtual int GetDyntransICshift() const
Definition: I960_CPUComponent.cc:294
I960_CPUComponent::CheckVariableWrite
virtual bool CheckVariableWrite(StateVariable &var, const string &oldValue)
Checks whether a write to a variable is OK.
Definition: I960_CPUComponent.cc:231
I960_CPUComponent::PCtoInstructionAddress
virtual uint64_t PCtoInstructionAddress(uint64_t pc)
Convert PC value to instuction address.
Definition: I960_CPUComponent.cc:316
DyntransIC
A dyntrans instruction call.
Definition: CPUDyntransComponent.h:50
I960_CPUComponent
A Component representing an Intel i960 processor.
Definition: I960_CPUComponent.h:71
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:307
I960_CPUComponent::ShowRegisters
virtual void ShowRegisters(GXemul *gxemul, const vector< string > &arguments) const
Definition: I960_CPUComponent.cc:239
I960_CPUComponent::DisassembleInstruction
virtual size_t DisassembleInstruction(uint64_t vaddr, size_t maxlen, unsigned char *instruction, vector< string > &result)
Disassembles an instruction into readable strings.
Definition: I960_CPUComponent.cc:322
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:219
I960_CPUComponent::FunctionTraceArgument
virtual int64_t FunctionTraceArgument(int n)
Definition: I960_CPUComponent.cc:281
I960_CPUComponent::GetDyntransToBeTranslated
virtual void(*)(CPUDyntransComponent *, DyntransIC *) GetDyntransToBeTranslated()
Definition: I960_CPUComponent.h:119
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:104
ComponentCreateArgs
Definition: Component.h:48
I960_CPUComponent::GetAttribute
static string GetAttribute(const string &attributeName)
Definition: I960_CPUComponent.cc:770

Generated on Tue Mar 24 2020 14:04:48 for GXemul by doxygen 1.8.17