1 #ifndef MACHINE_H 2 #define MACHINE_H 3 4 /* 5 * Copyright (C) 2005-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 #include <sys/types.h> 32 33 #include "symbol.h" 34 35 struct cpu_family; 36 struct diskimage; 37 struct emul; 38 struct fb_window; 39 struct machine_arcbios; 40 struct machine_pmax; 41 struct memory; 42 struct of_data; 43 struct settings; 44 45 46 /* TODO: This should probably go away... */ 47 struct isa_pic_data { 48 struct pic8259_data *pic1; 49 struct pic8259_data *pic2; 50 51 int *pending_timer_interrupts; 52 int last_int; 53 }; 54 55 struct breakpoints { 56 int n; 57 58 /* Arrays, with one element for each entry: */ 59 char **string; 60 uint64_t *addr; 61 }; 62 63 struct statistics { 64 char *filename; 65 FILE *file; 66 int enabled; 67 char *fields; /* "vpi" etc. */ 68 }; 69 70 struct tick_functions { 71 int n_entries; 72 73 /* Arrays, with one element for each entry: */ 74 int *ticks_till_next; 75 int *ticks_reset_value; 76 void (**f)(struct cpu *, void *); 77 void **extra; 78 }; 79 80 struct x11_md { 81 /* X11/framebuffer stuff: */ 82 int in_use; 83 int scaledown; 84 int scaleup; 85 int n_display_names; 86 char **display_names; 87 int current_display_name_nr; /* updated by x11.c */ 88 89 int n_fb_windows; 90 struct fb_window **fb_windows; 91 }; 92 93 94 /* 95 * The machine struct: 96 */ 97 struct machine { 98 /* Pointer back to the emul struct we are in: */ 99 struct emul *emul; 100 101 /* Settings: */ 102 struct settings *settings; 103 104 /* Name as choosen by the user: */ 105 const char *name; 106 107 /* Full "path" to the machine, e.g. "machine[0]": */ 108 char *path; 109 110 int arch; /* ARCH_MIPS, ARCH_PPC, .. */ 111 int machine_type; /* MACHINE_PMAX, .. */ 112 int machine_subtype; /* MACHINE_DEC_3MAX_5000, .. */ 113 114 /* Name set by code in src/machines/machine_*.c: */ 115 const char *machine_name; 116 117 /* The serial number is mostly used when emulating multiple machines 118 in a network. nr_of_nics is the current nr of network cards, which 119 is useful when emulating multiple cards in one machine: */ 120 int serial_nr; 121 int nr_of_nics; 122 123 /* TODO: How about multiple cpu familys in one machine? */ 124 struct cpu_family *cpu_family; 125 126 struct memory *memory; 127 128 int main_console_handle; 129 130 /* Tick functions (e.g. hardware devices): */ 131 struct tick_functions tick_functions; 132 133 char *cpu_name; /* TODO: remove this, there could be several 134 cpus with different names in a machine */ 135 int byte_order_override; 136 int bootstrap_cpu; 137 int use_random_bootstrap_cpu; 138 int start_paused; 139 int ncpus; 140 struct cpu **cpus; 141 142 struct diskimage *first_diskimage; 143 144 struct symbol_context symbol_context; 145 146 int random_mem_contents; 147 uint32_t physical_ram_in_mb; 148 int memory_offset_in_mb; 149 int prom_emulation; 150 int register_dump; 151 int arch_pagesize; 152 153 int bootdev_type; 154 int bootdev_id; 155 char *bootstr; 156 char *bootarg; 157 158 /* Breakpoints: */ 159 struct breakpoints breakpoints; 160 161 int halt_on_nonexistant_memaccess; 162 int instruction_trace; 163 int show_nr_of_instructions; 164 int show_trace_tree; 165 int emulated_hz; 166 int allow_instruction_combinations; 167 int force_netboot; 168 int slow_serial_interrupts_hack_for_linux; 169 uint64_t file_loaded_end_addr; 170 char *boot_kernel_filename; 171 char *boot_string_argument; 172 int exit_without_entering_debugger; 173 int n_gfx_cards; 174 175 /* Instruction statistics: */ 176 struct statistics statistics; 177 178 /* X11/framebuffer stuff (per machine): */ 179 struct x11_md x11_md; 180 181 /* Machine-dependent: (PROM stuff, etc.) */ 182 union { 183 struct machine_arcbios *arc; 184 struct machine_pmax *pmax; 185 struct of_data *of_data; 186 } md; 187 188 /* Bus-specific interrupt data: */ 189 /* TODO: Remove! */ 190 struct isa_pic_data isa_pic_data; 191 }; 192 193 194 /* Tick function "prototype": */ 195 #define DEVICE_TICK(x) void dev_ ## x ## _tick(struct cpu *cpu, void *extra) 196 197 198 /* 199 * Machine emulation types: 200 */ 201 202 #define ARCH_NOARCH 0 203 #define ARCH_MIPS 1 204 #define ARCH_PPC 2 205 #define ARCH_ALPHA 4 206 #define ARCH_ARM 5 207 #define ARCH_SH 6 208 #define ARCH_M88K 7 209 210 /* MIPS: */ 211 #define MACHINE_BAREMIPS 1000 212 #define MACHINE_TESTMIPS 1001 213 #define MACHINE_PMAX 1002 214 #define MACHINE_COBALT 1003 215 #define MACHINE_HPCMIPS 1004 216 #define MACHINE_PS2 1005 217 #define MACHINE_SGI 1006 218 #define MACHINE_ARC 1007 219 #define MACHINE_EVBMIPS 1008 220 #define MACHINE_ALGOR 1009 221 #define MACHINE_VOCORE 1010 222 223 /* PPC: */ 224 #define MACHINE_BAREPPC 2000 225 #define MACHINE_TESTPPC 2001 226 #define MACHINE_PMPPC 2002 227 #define MACHINE_PREP 2003 228 #define MACHINE_MACPPC 2004 229 #define MACHINE_MVMEPPC 2005 230 231 /* Alpha: */ 232 #define MACHINE_BAREALPHA 4000 233 #define MACHINE_TESTALPHA 4001 234 #define MACHINE_ALPHA 4002 235 236 /* ARM: */ 237 #define MACHINE_BAREARM 5000 238 #define MACHINE_TESTARM 5001 239 #define MACHINE_CATS 5002 240 #define MACHINE_HPCARM 5003 241 #define MACHINE_NETWINDER 5004 242 #define MACHINE_IQ80321 5005 243 #define MACHINE_IYONIX 5006 244 #define MACHINE_RPI 5007 245 #define MACHINE_ANDROIDARM 5008 246 247 /* SH: */ 248 #define MACHINE_BARESH 6000 249 #define MACHINE_TESTSH 6001 250 #define MACHINE_HPCSH 6002 251 #define MACHINE_DREAMCAST 6003 252 #define MACHINE_LANDISK 6004 253 254 /* M88K: */ 255 #define MACHINE_BAREM88K 7000 256 #define MACHINE_TESTM88K 7001 257 #define MACHINE_MVME88K 7002 258 #define MACHINE_LUNA88K 7003 259 260 /* Other "pseudo"-machines: */ 261 #define MACHINE_NONE 0 262 263 /* DEC: */ 264 #define MACHINE_DEC_PMAX_3100 1 265 #define MACHINE_DEC_3MAX_5000 2 266 #define MACHINE_DEC_3MIN_5000 3 267 #define MACHINE_DEC_3MAXPLUS_5000 4 268 #define MACHINE_DEC_5800 5 269 #define MACHINE_DEC_5400 6 270 #define MACHINE_DEC_MAXINE_5000 7 271 #define MACHINE_DEC_5500 11 272 #define MACHINE_DEC_MIPSMATE_5100 12 273 274 #define DEC_PROM_CALLBACK_STRUCT 0xffffffffbfc04000ULL 275 #define DEC_PROM_EMULATION 0xffffffffbfc08000ULL 276 #define DEC_PROM_INITIAL_ARGV (INITIAL_STACK_POINTER + 0x80) 277 #define DEC_PROM_STRINGS 0xffffffffbfc20000ULL 278 #define DEC_PROM_TCINFO 0xffffffffbfc2c000ULL 279 #define DEC_MEMMAP_ADDR 0xffffffffbfc30000ULL 280 281 /* HPCmips: */ 282 #define MACHINE_HPCMIPS_CASIO_BE300 1 283 #define MACHINE_HPCMIPS_CASIO_E105 2 284 #define MACHINE_HPCMIPS_NEC_MOBILEPRO_770 3 285 #define MACHINE_HPCMIPS_NEC_MOBILEPRO_780 4 286 #define MACHINE_HPCMIPS_NEC_MOBILEPRO_800 5 287 #define MACHINE_HPCMIPS_NEC_MOBILEPRO_880 6 288 #define MACHINE_HPCMIPS_AGENDA_VR3 7 289 #define MACHINE_HPCMIPS_IBM_WORKPAD_Z50 8 290 291 /* HPCarm: */ 292 #define MACHINE_HPCARM_IPAQ 1 293 #define MACHINE_HPCARM_JORNADA720 2 294 #define MACHINE_HPCARM_JORNADA728 3 295 296 /* HPCsh: */ 297 #define MACHINE_HPCSH_JORNADA680 1 298 #define MACHINE_HPCSH_JORNADA690 2 299 300 /* SGI and ARC: */ 301 #define MACHINE_ARC_JAZZ_PICA 1 302 #define MACHINE_ARC_JAZZ_MAGNUM 2 303 304 /* Algor: */ 305 #define MACHINE_ALGOR_P4032 1 306 #define MACHINE_ALGOR_P5064 2 307 308 /* EVBMIPS: */ 309 #define MACHINE_EVBMIPS_MALTA 1 310 #define MACHINE_EVBMIPS_MALTA_BE 2 311 312 /* PReP: */ 313 #define MACHINE_PREP_IBM6050 1 314 #define MACHINE_PREP_MVME2400 2 315 316 /* MacPPC: TODO: Real model names */ 317 #define MACHINE_MACPPC_G3 1 318 #define MACHINE_MACPPC_G4 2 319 #define MACHINE_MACPPC_G5 3 320 321 /* MVMEPPC */ 322 #define MACHINE_MVMEPPC_1600 1 323 #define MACHINE_MVMEPPC_2100 2 324 #define MACHINE_MVMEPPC_5500 3 325 326 /* MVME88K */ 327 #define MACHINE_MVME88K_187 1 328 #define MACHINE_MVME88K_188 2 329 #define MACHINE_MVME88K_197 3 330 331 /* LUNA88K */ 332 #define MACHINE_LUNA_88K 1 333 #define MACHINE_LUNA_88K2 2 334 335 /* Android ARM */ 336 #define MACHINE_ANDROIDARM_SONYXPERIAMINI 1 337 #define MACHINE_ANDROIDARM_FINOWX5AIR 2 338 339 340 /* For the automachine system: */ 341 struct machine_entry_subtype { 342 int machine_subtype;/* Old-style subtype */ 343 const char *name; /* Official name */ 344 int n_aliases; 345 char **aliases; /* Aliases */ 346 }; 347 348 struct machine_entry { 349 struct machine_entry *next; 350 351 /* Machine type: */ 352 int arch; 353 int machine_type; /* Old-style type */ 354 const char *name; /* Official name */ 355 int n_aliases; 356 char **aliases; /* Aliases */ 357 358 void (*setup)(struct machine *, struct cpu *); 359 void (*set_default_cpu)(struct machine *); 360 void (*set_default_ram)(struct machine *); 361 362 /* Machine subtypes: */ 363 int n_subtypes; 364 struct machine_entry_subtype **subtype; 365 }; 366 367 #define MACHINE_SETUP_TYPE(n) void (*n)(struct machine *, struct cpu *) 368 #define MACHINE_SETUP(x) void machine_setup_ ## x(struct machine *machine, \ 369 struct cpu *cpu) 370 #define MACHINE_DEFAULT_CPU(x) void machine_default_cpu_ ## x(struct machine *machine) 371 #define MACHINE_DEFAULT_RAM(x) void machine_default_ram_ ## x(struct machine *machine) 372 #define MACHINE_REGISTER(x) void machine_register_ ## x(void) 373 #define MR_DEFAULT(x,name,arch,type) struct machine_entry \ 374 *me = machine_entry_new(name,arch,type); \ 375 me->setup = machine_setup_ ## x; \ 376 me->set_default_cpu = machine_default_cpu_ ## x; \ 377 machine_entry_register(me, arch); 378 void automachine_init(void); 379 380 381 /* machine.c: */ 382 struct machine *machine_new(char *name, struct emul *emul, int id); 383 void machine_destroy(struct machine *machine); 384 int machine_name_to_type(char *stype, char *ssubtype, 385 int *type, int *subtype, int *arch); 386 void machine_add_breakpoint_string(struct machine *machine, char *str); 387 void machine_add_tickfunction(struct machine *machine, 388 void (*func)(struct cpu *, void *), void *extra, int clockshift); 389 void machine_statistics_init(struct machine *, char *fname); 390 void machine_register(char *name, MACHINE_SETUP_TYPE(setup)); 391 void machine_setup(struct machine *); 392 void machine_memsize_fix(struct machine *); 393 void machine_default_cputype(struct machine *); 394 void machine_dumpinfo(struct machine *); 395 int machine_run(struct machine *machine); 396 void machine_list_available_types_and_cpus(void); 397 struct machine_entry *machine_entry_new(const char *name, 398 int arch, int oldstyle_type); 399 void machine_entry_add_alias(struct machine_entry *me, const char *name); 400 void machine_entry_add_subtype(struct machine_entry *me, const char *name, 401 int oldstyle_subtype, ...); 402 void machine_entry_register(struct machine_entry *me, int arch); 403 void machine_init(void); 404 405 406 #endif /* MACHINE_H */ 407