2
Copyright (C) 1998-2003 T. Scott Dattalo
4
This file is part of the libgpsim library of gpsim
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2.1 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library; if not, see
18
<http://www.gnu.org/licenses/lgpl-2.1.html>.
20
/****************************************************************
22
* Modified 2018 by Santiago Gonzalez santigoro@gmail.com *
24
*****************************************************************/
26
#ifndef __PROCESSOR_H__
27
#define __PROCESSOR_H__
29
#include "gpsim_classes.h"
30
#include "pic-instructions.h"
31
#include "registers.h"
33
#include "cpu_clock.h"
35
class ProcessorConstructor;
37
class Processor : public CpuClock
40
Processor(const char* _name=0, const char *_desc=0 );
45
QHash<int, IOPIN*> m_pinList;
46
int get_pin_count() { return m_pinList.size(); }
47
void assign_pin( int n, IOPIN* pin ) { m_pinList[n] = pin; }
48
void destroy_pin( int n );
49
IOPIN* get_pin( int i ) { return m_pinList.value(i); }
51
Register** registers; /// Processor RAM
52
Register** register_bank;/// Currently selected RAM bank
55
Instruction** program_memory;/// Program memory - where instructions are stored.
56
BadInstruction bad_instruction; // Processor's 'bad_instruction' object
57
virtual Instruction* ConstructInvalidInstruction(Processor* cpu, uint address, uint new_opcode)
58
{ return new BadInstruction( cpu, address, new_opcode ); }
63
Program_Counter* pc; // Program Counter
65
// Creation and manipulation of registers
66
void resetRegisters( RESET_TYPE r );
67
void create_invalid_registers ();
68
void add_file_registers( uint start_address, uint end_address, uint alias_offset);
69
void delete_file_registers( uint start_address, uint end_address, bool bRemoveWithoutDelete=false);
70
void alias_file_registers( uint start_address, uint end_address, uint alias_offset);
72
virtual void init_register_memory(uint memory_size);
73
virtual uint register_memory_size () const = 0;
75
virtual uint CalcJumpAbsoluteAddress( uint uInstAddr, uint uDestAddr) { return uDestAddr; }
76
virtual uint CalcCallAbsoluteAddress( uint uInstAddr, uint uDestAddr) { return uDestAddr; }
78
// Creation and manipulation of Program Memory
79
virtual void init_program_memory( uint memory_size );
80
virtual void init_program_memory( uint address, uint value );
81
virtual void init_program_memory_at_index(uint address, uint value );
82
virtual void init_program_memory_at_index(uint address, const unsigned char* , int nBytes);
84
virtual uint program_memory_size(void) const {return 0;}
85
virtual uint program_address_limit(void) const { return map_pm_index2address(program_memory_size());}
86
virtual uint get_program_memory_at_address( uint address );
87
virtual void set_out_of_range_pm( uint address, uint value );
89
virtual int map_rm_address2index( int address ) { return address;}
90
virtual int map_rm_index2address( int index ) { return index;}
91
virtual int map_pm_address2index( int address ) const { return address;}
92
virtual int map_pm_index2address( int index ) const { return index;}
94
virtual Instruction* disasm( uint address,uint inst)=0; // Symbolic debugging
97
void stepCpuClock(){ m_phaseCurr = m_phaseCurr->advance(); }
100
if( pc->value < program_memory_size()) program_memory[pc->value]->execute();
103
//cout << "Program counter not valid " << hex << pc->value << endl;
107
virtual void exit_sleep() { fputs("RRR exit_sleep\n", stderr); }
108
virtual void interrupt(void) = 0 ;
110
bool getBrkOnBadRegRead() { return m_BrkOnBadRegRead; }
111
bool getBrkOnBadRegWrite() { return m_BrkOnBadRegWrite; }
113
// Configuration control
114
virtual bool set_config_word( uint address, uint cfg_word)=0;
115
virtual uint get_config_word( uint address ) = 0;
116
virtual uint config_word_address( void ) {return 0;}
117
virtual int get_config_index( uint address )=0;
119
virtual void reset(RESET_TYPE r) = 0; // Processor reset
121
virtual double get_Vdd() { return m_vdd; }
122
virtual void set_Vdd( double v ) { m_vdd = v; update_vdd();}
123
virtual void update_vdd();
126
virtual void create( void ) = 0;
127
static Processor* construct( void );
128
ProcessorConstructor* m_pConstructorObject;
134
//-------------------------------------------------------------------
135
// ProcessorConstructor -- a class to handle all of gpsim's supported processors
137
class ProcessorConstructor
140
typedef Processor* (*tCpuContructor) (const char* _name);
142
ProcessorConstructor( tCpuContructor _cpu_constructor,
143
const char* name1, const char* name2,
144
const char* name3=0, const char* name4=0);
146
virtual ~ProcessorConstructor(){}
148
virtual Processor* ConstructProcessor( const char* opt_name=0 );
150
static list <ProcessorConstructor*>* GetList();
151
static list<ProcessorConstructor*>* processor_list;
152
static Processor* CreatePic( const char* type );
154
#define nProcessorNames 4 // The processor name (plus upto three aliases).
155
const char* names[nProcessorNames];
158
tCpuContructor cpu_constructor; // A pointer to a function that when called will construct a processor