1 /* Definitions to support the main driver program.  -*- C++ -*-
2    Copyright 2001, 2003 Brian R. Gaeke.
3    Copyright 2002, 2003 Paul Twohey.
4 
5 This file is part of VMIPS.
6 
7 VMIPS is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2 of the License, or (at your
10 option) any later version.
11 
12 VMIPS is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License along
18 with VMIPS; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
20 
21 #ifndef _VMIPS_H_
22 #define _VMIPS_H_
23 
24 #include "types.h"
25 #include <cstdio>
26 #include <new>
27 
28 class Mapper;
29 class CPU;
30 class IntCtrl;
31 class Options;
32 class MemoryModule;
33 class Debug;
34 class Clock;
35 class ClockDevice;
36 class HaltDevice;
37 class SpimConsoleDevice;
38 class TerminalController;
39 class DECRTCDevice;
40 class DECCSRDevice;
41 class DECStatDevice;
42 class DECSerialDevice;
43 class TestDev;
44 class Disassembler;
45 class Interactor;
46 
47 long timediff(struct timeval *after, struct timeval *before);
48 
49 class vmips
50 {
51 public:
52 	// Machine states
53 	enum { HALT, RUN, DEBUG, INTERACT };
54 
55 	Mapper		*physmem;
56 	CPU		*cpu;
57 	IntCtrl		*intc;
58 	Options		*opt;
59 	MemoryModule	*memmod;
60 	Debug	*dbgr;
61 	Disassembler	*disasm;
62 	bool		host_bigendian;
63 
64 	int			state;
halted()65 	bool halted() const { return (state == HALT); }
66 
67 	Clock		*clock;
68 	ClockDevice	*clock_device;
69 	HaltDevice	*halt_device;
70 	SpimConsoleDevice	*spim_console;
71 	DECRTCDevice	*decrtc_device;
72 	DECCSRDevice	*deccsr_device;
73 	DECStatDevice	*decstat_device;
74 	DECSerialDevice	*decserial_device;
75 	TestDev		*test_device;
76 
77 	/* Cached versions of options: */
78 	bool		opt_bootmsg;
79 	bool		opt_clockdevice;
80 	bool		opt_debug;
81 	bool		opt_dumpcpu;
82 	bool		opt_dumpcp0;
83 	bool		opt_haltdevice;
84 	bool		opt_haltdumpcpu;
85 	bool		opt_haltdumpcp0;
86 	bool		opt_instcounts;
87 	bool		opt_memdump;
88 	bool		opt_realtime;
89 	bool		opt_decrtc;
90 	bool		opt_deccsr;
91 	bool		opt_decstat;
92 	bool		opt_decserial;
93 	bool		opt_spimconsole;
94 	bool		opt_testdev;
95 	uint32		opt_clockspeed;
96 	uint32		clock_nanos;
97 	uint32		opt_clockintr;
98 	uint32		opt_clockdeviceirq;
99 	uint32		opt_loadaddr;
100 	uint32		opt_memsize;
101 	uint32		opt_timeratio;
102 	char		*opt_image;
103 	char		*opt_execname;
104 	char		*opt_memdumpfile;
105 	char		*opt_ttydev;
106 	char		*opt_ttydev2;
107 
108 private:
109 	uint32	num_instrs;
110 	Interactor *interactor;
111 
112 	/* If boot messages are enabled with opt_bootmsg, print MSG as a
113 	   printf(3) style format string for the remaing arguments. */
114 	virtual void boot_msg( const char *msg, ... );
115 
116 	/* Initialize the SPIM-compatible console device and connect it to
117 	   configured terminal lines. */
118 	virtual bool setup_spimconsole();
119 
120 	/* Initialize the test-only device. */
121 	virtual bool setup_testdev();
122 
123 	/* Initialize the clock device if it is configured. Return true if
124 	   there are no initialization problems, otherwise return false. */
125 	virtual bool setup_clockdevice();
126 
127 	/* Initialize the DEC RTC if it is configured. Return true if
128 	   there are no initialization problems, otherwise return false. */
129 	virtual bool setup_decrtc();
130 
131 	/* Initialize the DEC CSR if it is configured. Return true if
132 	   there are no initialization problems, otherwise return false. */
133 	virtual bool setup_deccsr();
134 
135 	/* Initialize the DEC status registers if configured. Return true if
136 	   there are no initialization problems, otherwise return false. */
137 	virtual bool setup_decstat();
138 
139 	/* Initialize the DEC serial device if it is configured. Return true if
140 	   there are no initialization problems, otherwise return false. */
141 	virtual bool setup_decserial();
142 
143 	virtual bool setup_rom();
144 
145 	virtual bool setup_exe();
146 
147 	bool load_elf (FILE *fp);
148 	bool load_ecoff (FILE *fp);
149 	char *translate_to_host_ram_pointer (uint32 vaddr);
150 
151 	virtual bool setup_ram();
152 
153 	virtual bool setup_clock();
154 
155 	/* Connect the file or device named NAME to line number L of
156 	   console device C, or do nothing if NAME is "off".  */
157 	virtual void setup_console_line(int l, char *name,
158 		TerminalController *c, const char *c_name);
159 
160 	/* Initialize the halt device if it is configured. */
161 	bool setup_haltdevice();
162 
163 public:
164 	void refresh_options(void);
165 	vmips(int argc, char **argv);
166 
167 	/* Cleanup after we are done. */
168 	virtual ~vmips();
169 
170 	void setup_machine(void);
171 
172 	/* Attention key was pressed. */
173 	void attn_key(void);
174 
175 	/* Halt the simulation. */
176 	void halt(void);
177 
178 	/* Interact with user. */
179 	bool interact(void);
180 
181 	int host_endian_selftest(void);
182 
183 	void dump_cpu_info(bool dumpcpu, bool dumpcp0);
184 
185 	void step(void);
186 	int run(void);
187 };
188 
189 extern vmips *machine;
190 
191 #endif /* _VMIPS_H_ */
192